]> code.citadel.org Git - citadel.git/blobdiff - webcit/webcit.c
Got it!
[citadel.git] / webcit / webcit.c
index 03bc0a053b5c2ccfad52d5cdf04521b40d4b9265..3e439f57d329b58067a730ca9097aeedd596db06 100644 (file)
@@ -288,12 +288,30 @@ void urlescputs(char *strbuf)
 }
 
 
+
+
+/*
+ * Get a line of text from the webserver (which originally came from the
+ * user's browser), checking for sanity etc.
+ */
 char *getz(char *buf)
 {
+       int e = 0;
+
        bzero(buf, 256);
+
+       /* If fgets() fails, it's because the webserver crashed, so kill off
+        * the session too.
+        */
        if (fgets(buf, 256, stdin) == NULL) {
-               strcpy(buf, "");
-               return NULL;
+               e = errno;
+               fprintf(stderr, "webcit: exit code %d (%s)\n",
+                       e, strerror(e));
+               fflush(stderr);
+               exit(e);
+               
+       /* Otherwise, strip out nonprintables and resume our happy day.
+        */
        } else {
                while ((strlen(buf) > 0) && (!isprint(buf[strlen(buf) - 1])))
                        buf[strlen(buf) - 1] = 0;
@@ -301,13 +319,15 @@ char *getz(char *buf)
        }
 }
 
+
+
 /*
  * Output all that important stuff that the browser will want to see
  *
  * If print_standard_html_head is nonzero, we also get some standard HTML
  * headers.  If it's set to 2, the session is considered to be closing.
  */
-void output_headers(int print_standard_html_head, char *target)
+void output_headers(int print_standard_html_head)
 {
 
        static char *unset = "; expires=28-May-1971 18:10:00 GMT";
@@ -316,9 +336,6 @@ void output_headers(int print_standard_html_head, char *target)
        printf("Server: %s\n", SERVER);
        printf("Connection: close\n");
 
-       if ((strlen(target) > 0) && (noframes == 0)) {
-               printf("Window-target: %s\n", target);
-       }
        if (print_standard_html_head > 0) {
                printf("Pragma: no-cache\n");
                printf("Cache-Control: no-store\n");
@@ -392,7 +409,7 @@ void output_static(char *what)
        fp = fopen(buf, "rb");
        if (fp == NULL) {
                printf("HTTP/1.0 404 %s\n", strerror(errno));
-               output_headers(0, "");
+               output_headers(0);
                printf("Content-Type: text/plain\n");
                sprintf(buf, "%s: %s\n", what, strerror(errno));
                printf("Content-length: %d\n", strlen(buf));
@@ -400,7 +417,7 @@ void output_static(char *what)
                fwrite(buf, strlen(buf), 1, stdout);
        } else {
                printf("HTTP/1.0 200 OK\n");
-               output_headers(0, "");
+               output_headers(0);
 
                if (!strncasecmp(&what[strlen(what) - 4], ".gif", 4))
                        printf("Content-type: image/gif\n");
@@ -437,7 +454,7 @@ void output_image()
        if (buf[0] == '2') {
                bytes = extract_long(&buf[4], 0);
                printf("HTTP/1.0 200 OK\n");
-               output_headers(0, "");
+               output_headers(0);
                printf("Content-type: image/gif\n");
                printf("Content-length: %ld\n", (long) bytes);
                printf("\n");
@@ -460,7 +477,7 @@ void output_image()
                serv_gets(buf);
        } else {
                printf("HTTP/1.0 404 %s\n", strerror(errno));
-               output_headers(0, "");
+               output_headers(0);
                printf("Content-Type: text/plain\n");
                sprintf(buf, "Error retrieving image\n");
                printf("Content-length: %d\n", strlen(buf));
@@ -477,7 +494,7 @@ void output_image()
 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
 {
        printf("HTTP/1.0 200 OK\n");
-       output_headers(1, "bottom");
+       output_headers(1);
        wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=%s><TR><TD>", titlebarcolor);
        wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
        wprintf("<B>%s</B>\n", titlebarmsg);
@@ -557,7 +574,7 @@ void upload_handler(char *name, char *filename, char *encoding,
 }
 
 
-void session_loop(char *browser_host, int bd_use_frames)
+void session_loop(char *browser_host)
 {
        char cmd[256];
        char action[256];
@@ -845,7 +862,7 @@ void session_loop(char *browser_host, int bd_use_frames)
        /* When all else fails... */
        else {
                printf("HTTP/1.0 200 OK\n");
-               output_headers(1, "");
+               output_headers(1);
 
                wprintf("TransactionCount is %d<BR>\n", TransactionCount);
                wprintf("You're in session %d<HR>\n", wc_session);
@@ -874,7 +891,7 @@ int main(int argc, char *argv[])
 {
 
        char browser[256];
-       int bd_use_frames;
+       int bd;
 
        if (argc != 6) {
                fprintf(stderr,
@@ -891,9 +908,13 @@ int main(int argc, char *argv[])
        strcpy(wc_roomname, "");
 
        strcpy(browser, argv[5]);
-       bd_use_frames = browser_braindamage_check(browser);
+       bd = browser_braindamage_check(browser);
+       if (bd == B_NO)
+               noframes = 1;
+       else
+               noframes = 0;
 
        while (1) {
-               session_loop(argv[4], bd_use_frames);
+               session_loop(argv[4]);
        }
 }