You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Modelbahn/server/modelbahn-cgi.cc

65 lines
1.5 KiB

#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdarg.h>
#include <signal.h>
#include <UDPTCPNetwork.h>
#define UNIX_SOCKET_FILE "/tmp/modelbahn.socket"
#define LOG_FILE "/tmp/modelbahn-cgi.log"
#define BUFFERSIZE 64000
//extern char **environ;
int main (int argc, char **argv) {
int i, inlen;
FILE *logf;
char buffer[BUFFERSIZE+1];
char *ptr = NULL;
printf ("Content-type: text/html\n");
printf ("Expires: now\n");
printf ("Pragma: no-cache\n");
printf ("\n");
//
// open logfile for writing
logf = fopen(LOG_FILE, "a+");
if (logf == NULL) return 0;
fprintf (logf, "*************************************\n");
//
// read data
memset (buffer, 0x0, BUFFERSIZE+1);
// FIXME: fgets is wrong....
for (ptr = buffer, inlen = 0; inlen < BUFFERSIZE-1 && (fgets (ptr, BUFFERSIZE - inlen, stdin)) > 0;) {
inlen = strlen (buffer);
ptr = buffer+inlen;
}
if (inlen >= BUFFERSIZE-1) fprintf (logf, "read input puffer full.\n");
fprintf (logf, "read from stdin %d bytes\n", strlen(buffer));
//
// send data to server
UNIX u;
if (u.Connect(UNIX_SOCKET_FILE) != 1) return 0;
u.Write(buffer, strlen(buffer));
//
// read data and send back to the web server
do {
i = u.ReadTimeout(buffer, BUFFERSIZE-1, 1000);
buffer[i] = 0;
fprintf (logf, "read from server %d bytes\n", i);
printf ("%s", buffer);
} while (i == BUFFERSIZE-1);
u.Close();
fclose (logf);
return 0;
};