]> code.citadel.org Git - citadel.git/blobdiff - webcit/webcit.c
* wDumpContent() is now responsible for </BODY></HTML> most of the
[citadel.git] / webcit / webcit.c
index 0e56def6d4f6b83887a54f2aa7e9dce43163a49f..18c5f764e47fa20d9422c7469519d72fa9dfea98 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdarg.h>
 #include "webcit.h"
 #include "child.h"
+#include "mime_parser.h"
 
 int wc_session;
 char wc_username[256];
@@ -30,6 +31,7 @@ int connected = 0;
 int logged_in = 0;
 int axlevel;
 char *ExpressMessages = NULL;
+int noframes = 0;
 
 struct webcontent *wlist = NULL;
 struct webcontent *wlast = NULL;
@@ -176,9 +178,17 @@ int wContentLength(void) {
        return(len);
        }
 
-void wDumpContent(void) {
+void wDumpContent(int print_standard_html_footer) {
        struct webcontent *wptr;
 
+       if (print_standard_html_footer) {
+               if (noframes) {
+                       wprintf("<BR>");
+                       embed_main_menu();
+                       }
+               wprintf("</BODY></HTML>\n");
+               }
+
        printf("Content-type: text/html\n");
        printf("Content-length: %d\n", wContentLength());
        printf("\n");
@@ -262,7 +272,7 @@ void getz(char *buf) {
  * 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) {
+void output_headers(int print_standard_html_head, char *target) {
 
        static char *unset = "; expires=28-May-1971 18:10:00 GMT";
        char cookie[256];
@@ -270,7 +280,18 @@ void output_headers(int print_standard_html_head) {
        printf("Server: %s\n", SERVER);
        printf("Connection: close\n");
 
-       stuff_to_cookie(cookie, wc_session, wc_username, wc_password, wc_roomname);
+       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");
+               }
+
+       stuff_to_cookie(cookie, wc_session, wc_username, wc_password,
+                       wc_roomname, noframes);
        if (print_standard_html_head==2) {
                printf("X-WebCit-Session: close\n");
                printf("Set-cookie: webcit=%s\n", unset);
@@ -339,7 +360,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));
@@ -348,7 +369,7 @@ void output_static(char *what) {
                }
        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");
@@ -384,7 +405,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", bytes);
                printf("\n");
@@ -406,7 +427,7 @@ void output_image() {
                }
        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));
@@ -422,14 +443,19 @@ void output_image() {
  */
 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext) {
         printf("HTTP/1.0 200 OK\n");
-        output_headers(1);
+        output_headers(1, "bottom");
         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=%s><TR><TD>", titlebarcolor);
         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
         wprintf("<B>%s</B>\n", titlebarmsg);
         wprintf("</FONT></TD></TR></TABLE><BR>\n");
        escputs(messagetext);
-        wprintf("</BODY></HTML>\n");
-        wDumpContent();
+       
+       if (noframes) {
+               wprintf("<HR>\n");
+               embed_main_menu();
+               }
+
+        wDumpContent(1);
        }
 
 void display_error(char *errormessage) {
@@ -459,6 +485,27 @@ void extract_action(char *actbuf, char *cmdbuf) {
        }
 
 
+void upload_handler(char *name, char *filename, char *encoding,
+                       void *content, char *cbtype, size_t length) {
+
+       fprintf(stderr, "UPLOAD HANDLER CALLED\n");
+       fprintf(stderr, "    name = %s\n", name);
+       fprintf(stderr, "filename = %s\n", filename);
+       fprintf(stderr, "encoding = %s\n", encoding);
+       fprintf(stderr, "    type = %s\n", cbtype);
+       fprintf(stderr, "  length = %d\n", length);
+
+        if (strlen(name)>0) {
+                upload = malloc(length);
+                if (upload != NULL) {
+                        upload_length = length;
+                        memcpy(upload, content, length);
+                        }
+                }
+
+       }
+
+
 void session_loop(void) {
        char cmd[256];
        char action[256];
@@ -496,7 +543,8 @@ void session_loop(void) {
                if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
                        strcpy(cookie, &buf[15]);
                        cookie_to_stuff(cookie, NULL,
-                                       c_username, c_password, c_roomname);
+                                       c_username, c_password, c_roomname,
+                                       &noframes);
                        }
 
                if (!strncasecmp(buf, "Content-length: ", 16)) {
@@ -520,7 +568,8 @@ void session_loop(void) {
                        addurls(content);
                        }
                else if (!strncasecmp(ContentType, "multipart", 9)) {
-                       mime_parser(content, ContentLength, ContentType);
+                       mime_parser(content, ContentLength, ContentType,
+                                       *upload_handler);
                        }
                }
        else {
@@ -871,10 +920,18 @@ void session_loop(void) {
                siteconfig();
                }
 
+       else if (!strcasecmp(action, "display_generic")) {
+               display_generic();
+               }
+
+       else if (!strcasecmp(action, "do_generic")) {
+               do_generic();
+               }
+
        /* 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);
@@ -884,8 +941,7 @@ void session_loop(void) {
                wprintf("Variables: <BR><PRE>\n");
                dump_vars();
                wprintf("</PRE><HR>\n");
-               wprintf("</BODY></HTML>\n");
-               wDumpContent();
+               wDumpContent(1);
                }
 
        fflush(stdout);