]> code.citadel.org Git - citadel.git/blobdiff - webcit/webcit.c
* Made the frames stuff less dependent on the HTML TARGET= directive
[citadel.git] / webcit / webcit.c
index dfd9865ff02a70d7cd64c87eecdc3d5b8b8f12f9..b82dd2d81795e16dac28faee10cda97ce3792cd6 100644 (file)
@@ -9,7 +9,9 @@
  */
 
 #include <stdlib.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <stdio.h>
 #include <ctype.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <stdarg.h>
 #include "webcit.h"
+#include "child.h"
+#include "mime_parser.h"
 
 int wc_session;
-char wc_host[256];
-char wc_port[256];
 char wc_username[256];
 char wc_password[256];
 char wc_roomname[256];
@@ -28,15 +30,23 @@ int TransactionCount = 0;
 int connected = 0;
 int logged_in = 0;
 int axlevel;
+char *ExpressMessages = NULL;
+int noframes = 0;
 
 struct webcontent *wlist = NULL;
 struct webcontent *wlast = NULL;
 
 struct urlcontent *urlstrings = NULL;
 
+static const char *defaulthost = DEFAULT_HOST;
+static const char *defaultport = DEFAULT_PORT;
+
+int upload_length = 0;
+char *upload;
+
 
-void unescape_input(buf)
-char buf[]; {
+void unescape_input(char *buf)
+{
        int a,b;
        char hex[3];
 
@@ -71,7 +81,7 @@ void addurls(char *url) {
                strncpy(buf,up,255);
                b = (-1);
                for (a=255; a>=0; --a) if (buf[a]=='=') b=a;
-               if (b<0) goto DONE;
+               if (b<0) return;
                buf[b]=0;
        
                u = (struct urlcontent *)malloc(sizeof(struct urlcontent));
@@ -88,25 +98,24 @@ void addurls(char *url) {
                for (a=0; a<strlen(up); ++a) {
                        if (!strncmp(ptr,"&",1)) {
                                b=a;
-                               goto FOUNDIT;
+                               break;
                                }
                        ++ptr;
                        }
-FOUNDIT:       ptr = up;
+               ptr = up;
                for (a=0; a<b; ++a) ++ptr;
                strcpy(ptr,"");
                
-               u->url_data = malloc(strlen(up));
+               u->url_data = malloc(strlen(up)+1);
                strcpy(u->url_data, up);
+               u->url_data[b] = 0;
                unescape_input(u->url_data);
-
                up = ptr;
                ++up;
                }
-DONE:
        }
 
-void free_urls() {
+void free_urls(void) {
        struct urlcontent *u;
 
        while (urlstrings != NULL) {
@@ -117,6 +126,17 @@ void free_urls() {
                }
        }
 
+/*
+ * Diagnostic function to display the contents of all variables
+ */
+void dump_vars(void) {
+       struct urlcontent *u;
+
+       for (u = urlstrings; u != NULL; u = u->next) {
+               wprintf("%38s = %s\n", u->url_key, u->url_data);
+               }
+       }
+
 char *bstr(char *key) {
        struct urlcontent *u;
 
@@ -145,10 +165,9 @@ void wprintf(const char *format, ...) {
                va_start(arg_ptr, format);   
                vsprintf(wptr->w_data, format, arg_ptr);   
                va_end(arg_ptr);   
-  
        }
 
-int wContentLength() {
+int wContentLength(void) {
        struct webcontent *wptr;
        int len = 0;
 
@@ -159,7 +178,7 @@ int wContentLength() {
        return(len);
        }
 
-void wDumpContent() {
+void wDumpContent(void) {
        struct webcontent *wptr;
 
        printf("Content-type: text/html\n");
@@ -176,9 +195,8 @@ void wDumpContent() {
        }
 
 
-void escputs1(strbuf,nbsp)
-char strbuf[];
-int nbsp; {
+void escputs1(char *strbuf, int nbsp)
+{
        int a;
 
        for (a=0; a<strlen(strbuf); ++a) {
@@ -198,15 +216,15 @@ int nbsp; {
                }
        }
 
-void escputs(strbuf)
-char *strbuf; {
+void escputs(char *strbuf)
+{
        escputs1(strbuf,0);
        }
 
 
 
-char *urlesc(strbuf)
-char strbuf[]; {
+char *urlesc(char *strbuf)
+{
        int a,b,c;
         char *ec = " #&;`'|*?-~<>^()[]{}$\\";
        static char outbuf[512];
@@ -225,83 +243,103 @@ char strbuf[]; {
        return(outbuf);
        }
 
-void urlescputs(strbuf)
-char strbuf[]; {
+void urlescputs(char *strbuf)
+{
        wprintf("%s",urlesc(strbuf));
        }
 
 
+void getz(char *buf) {
+       bzero(buf, 256);
+       if (fgets(buf, 256, stdin) == NULL) strcpy(buf, "");
+       else {
+               while ((strlen(buf)>0)&&(!isprint(buf[strlen(buf)-1])))
+                       buf[strlen(buf)-1] = 0;
+               }
+       }
+
 /*
- * Look for URL's embedded in a buffer and make them linkable.  We use a
- * target window in order to keep the BBS session in its own window.
+ * 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 url(buf)
-char buf[]; {
+void output_headers(int print_standard_html_head, char *target) {
 
-       int pos;
-       int start,end;
-       char ench;
-       char urlbuf[256];
-       char outbuf[256];
+       static char *unset = "; expires=28-May-1971 18:10:00 GMT";
+       char cookie[256];
 
-       start = (-1);
-       end = strlen(buf);
-       ench = 0;
+       printf("Server: %s\n", SERVER);
+       printf("Connection: close\n");
 
-       for (pos=0; pos<strlen(buf); ++pos) {
-               if (!strncasecmp(&buf[pos],"http://",7)) start = pos;
-               if (!strncasecmp(&buf[pos],"ftp://",6)) start = pos;
+       if ( (strlen(target)>0) && (noframes == 0) ) {
+               printf("Window-target: %s\n", target);
                }
 
-       if (start<0) return;
 
-       if ((start>0)&&(buf[start-1]=='<')) ench = '>';
-       if ((start>0)&&(buf[start-1]=='[')) ench = ']';
-       if ((start>0)&&(buf[start-1]=='(')) ench = ')';
-       if ((start>0)&&(buf[start-1]=='{')) ench = '}';
-
-       for (pos=strlen(buf); pos>start; --pos) {
-               if ((buf[pos]==' ')||(buf[pos]==ench)) end = pos;
+       if (print_standard_html_head > 0) {
+               printf("Pragma: no-cache\n");
+               printf("Cache-Control: no-store\n");
                }
 
-       strncpy(urlbuf,&buf[start],end-start);
-       urlbuf[end-start] = 0;
-
+       stuff_to_cookie(cookie, wc_session, wc_username, wc_password, wc_roomname);
+       if (print_standard_html_head==2) {
+               printf("X-WebCit-Session: close\n");
+               printf("Set-cookie: webcit=%s\n", unset);
+               }
+       else {
+               printf("Set-cookie: webcit=%s\n", cookie);
+               }
+
+       if (print_standard_html_head > 0) {
+               wprintf("<HTML><HEAD><TITLE>");
+               escputs("WebCit");       /* FIX -- add BBS name here */
+               wprintf("</TITLE></HEAD>");
+               if (ExpressMessages != NULL) {
+                       wprintf("<SCRIPT language=\"javascript\">\n");
+                       wprintf("function ExpressMessage() {\n");
+                       wprintf(" alert(\"");
+                       escputs(ExpressMessages);
+                       wprintf("\")\n");
+                       wprintf(" }\n </SCRIPT>\n");
+                       }
+               wprintf("<BODY ");
+               if (ExpressMessages != NULL) {
+                       wprintf("onload=\"ExpressMessage()\" ");
+                       free(ExpressMessages);
+                       ExpressMessages = NULL;
+                       }
+               wprintf("BACKGROUND=\"/image&name=background\" TEXT=\"#000000\" LINK=\"#004400\">\n");
+               }
 
-       strncpy(outbuf,buf,start);
-       sprintf(&outbuf[start],"%cA HREF=%c%s%c TARGET=%c%s%c%c%s%c/A%c", 
-               LB,QU,urlbuf,QU,QU,TARGET,QU,RB,urlbuf,LB,RB);
-       strcat(outbuf,&buf[end]);
-       strcpy(buf,outbuf);
        }
 
 
 
 
-void getz(char *buf) {
-       if (fgets(buf, 256, stdin) == NULL) strcpy(buf, "");
-       else {
-               while ((strlen(buf)>0)&&(!isprint(buf[strlen(buf)-1])))
-                       buf[strlen(buf)-1] = 0;
+void check_for_express_messages() {
+       char buf[256];
+
+       serv_puts("PEXP");
+       serv_gets(buf);
+       if (buf[0]=='1') {
+               while (serv_gets(buf), strcmp(buf, "000")) {
+                       if (ExpressMessages == NULL) {
+                               ExpressMessages = malloc(strlen(buf) + 4);
+                               strcpy(ExpressMessages, "");
+                               }
+                       else {
+                               ExpressMessages = realloc(ExpressMessages,
+                                (strlen(ExpressMessages) + strlen(buf) + 4) );
+                               }
+                       strcat(ExpressMessages, buf);
+                       strcat(ExpressMessages, "\\n");
+                       }
                }
        }
 
-/*
- * Output all that important stuff that the browser will want to see
- */
-void output_headers() {
-       printf("Server: %s\n", SERVER);
-       printf("Connection: close\n");
-       printf("Set-cookie: wc_session=%d\n", wc_session);
-       if (strlen(wc_host)>0) printf("Set-cookie: wc_host=%s\n", wc_host);
-       if (strlen(wc_port)>0) printf("Set-cookie: wc_port=%s\n", wc_port);
-       if (strlen(wc_username)>0) printf("Set-cookie: wc_username=%s\n",
-               wc_username);
-       if (strlen(wc_password)>0) printf("Set-cookie: wc_password=%s\n",
-               wc_password);
-       if (strlen(wc_roomname)>0) printf("Set-cookie: wc_roomname=%s\n",
-               wc_roomname);
-       }
+
+
 
 void output_static(char *what) {
        char buf[256];
@@ -313,7 +351,7 @@ void output_static(char *what) {
        fp = fopen(buf, "rb");
        if (fp == NULL) {
                printf("HTTP/1.0 404 %s\n", strerror(errno));
-               output_headers();
+               output_headers(0, "");
                printf("Content-Type: text/plain\n");
                sprintf(buf, "%s: %s\n", what, strerror(errno));
                printf("Content-length: %d\n", strlen(buf));
@@ -322,10 +360,12 @@ void output_static(char *what) {
                }
        else {
                printf("HTTP/1.0 200 OK\n");
-               output_headers();
+               output_headers(0, "");
 
                if (!strncasecmp(&what[strlen(what)-4], ".gif", 4))
                        printf("Content-type: image/gif\n");
+               else if (!strncasecmp(&what[strlen(what)-4], ".jpg", 4))
+                       printf("Content-type: image/jpeg\n");
                else if (!strncasecmp(&what[strlen(what)-5], ".html", 5))
                        printf("Content-type: text/html\n");
                else
@@ -333,23 +373,132 @@ void output_static(char *what) {
 
                fstat(fileno(fp), &statbuf);
                bytes = statbuf.st_size;
-               printf("Content-length: %d\n", bytes);
+               printf("Content-length: %ld\n", (long)bytes);
                printf("\n");
                while (bytes--) {
                        putc(getc(fp), stdout);
                        }
+               fflush(stdout);
                fclose(fp);
                }
        }
 
-static const char *defaulthost = DEFAULT_HOST;
-static const char *defaultport = DEFAULT_PORT;
+void output_image() {
+       char buf[256];
+       char xferbuf[4096];
+       off_t bytes;
+       off_t thisblock;
+       off_t accomplished = 0L;
 
-void session_loop() {
+
+       serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
+       serv_gets(buf);
+       if (buf[0]=='2') {
+               bytes = extract_long(&buf[4], 0);
+               printf("HTTP/1.0 200 OK\n");
+               output_headers(0, "");
+               printf("Content-type: image/gif\n");
+               printf("Content-length: %ld\n", bytes);
+               printf("\n");
+
+               while (bytes > (off_t)0) {
+                       thisblock = (off_t)sizeof(xferbuf);
+                       if (thisblock > bytes) thisblock = bytes;
+                       serv_printf("READ %ld|%ld", accomplished, thisblock);
+                       serv_gets(buf);
+                       if (buf[0]=='6') thisblock = extract_long(&buf[4],0);
+                       serv_read(xferbuf, (int)thisblock);
+                       fwrite(xferbuf, thisblock, 1, stdout);
+                       bytes = bytes - thisblock;
+                       accomplished = accomplished + thisblock;
+                       }
+               fflush(stdout);
+               serv_puts("CLOS");
+               serv_gets(buf);
+               }
+       else {
+               printf("HTTP/1.0 404 %s\n", strerror(errno));
+               output_headers(0, "");
+               printf("Content-Type: text/plain\n");
+               sprintf(buf, "Error retrieving image\n");
+               printf("Content-length: %d\n", strlen(buf));
+               printf("\n");
+               fwrite(buf, strlen(buf), 1, stdout);
+               }
+
+       }
+
+
+/*
+ * Convenience functions to display a page containing only a string
+ */
+void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext) {
+        printf("HTTP/1.0 200 OK\n");
+        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();
+       }
+
+void display_error(char *errormessage) {
+       convenience_page("770000", "Error", errormessage);
+       }
+
+void display_success(char *successmessage) {
+       convenience_page("007700", "OK", successmessage);
+       }
+
+
+
+void extract_action(char *actbuf, char *cmdbuf) {
+       int i;
+
+       strcpy(actbuf, cmdbuf);
+       if (!strncasecmp(actbuf, "GET /", 5)) strcpy(actbuf, &actbuf[5]);
+       if (!strncasecmp(actbuf, "PUT /", 5)) strcpy(actbuf, &actbuf[5]);
+       if (!strncasecmp(actbuf, "POST /", 6)) strcpy(actbuf, &actbuf[6]);
+
+       for (i=0; i<strlen(actbuf); ++i) {
+               if (actbuf[i]==' ') { actbuf[i]=0; i=0; }
+               if (actbuf[i]=='/') { actbuf[i]=0; i=0; }
+               if (actbuf[i]=='?') { actbuf[i]=0; i=0; }
+               if (actbuf[i]=='&') { actbuf[i]=0; i=0; }
+               }
+       }
+
+
+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];
        char buf[256];
        int a, b;
        int ContentLength = 0;
+       char ContentType[512];
        char *content;
 
        /* We stuff these with the values coming from the client cookies,
@@ -360,6 +509,7 @@ void session_loop() {
        char c_username[256];
        char c_password[256];
        char c_roomname[256];
+       char cookie[256];
 
        strcpy(c_host, defaulthost);
        strcpy(c_port, defaultport);
@@ -367,26 +517,27 @@ void session_loop() {
        strcpy(c_password, "");
        strcpy(c_roomname, "");
 
+       upload_length = 0;
+       upload = NULL;
+
        getz(cmd);
+       extract_action(action, cmd);
 
        do {
                getz(buf);
 
-               if (!strncasecmp(buf, "Cookie: wc_host=", 16))
-                       strcpy(c_host, &buf[16]);
-               if (!strncasecmp(buf, "Cookie: wc_port=", 16))
-                       strcpy(c_port, &buf[16]);
-               if (!strncasecmp(buf, "Cookie: wc_username=", 20))
-                       strcpy(c_username, &buf[20]);
-               if (!strncasecmp(buf, "Cookie: wc_password=", 20))
-                       strcpy(c_password, &buf[20]);
-               if (!strncasecmp(buf, "Cookie: wc_roomname=", 20))
-                       strcpy(c_roomname, &buf[20]);
+               if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
+                       strcpy(cookie, &buf[15]);
+                       cookie_to_stuff(cookie, NULL,
+                                       c_username, c_password, c_roomname);
+                       }
 
                if (!strncasecmp(buf, "Content-length: ", 16)) {
                        ContentLength = atoi(&buf[16]);
                        }
-
+               if (!strncasecmp(buf, "Content-type: ", 14)) {
+                       strcpy(ContentType, &buf[14]);
+                       }
                } while(strlen(buf)>0);
 
        ++TransactionCount;
@@ -394,27 +545,44 @@ void session_loop() {
        if (ContentLength > 0) {
                content = malloc(ContentLength+1);
                fread(content, ContentLength, 1, stdin);
+
                content[ContentLength] = 0;
-               addurls(content);
+
+               if (!strncasecmp(ContentType,
+                  "application/x-www-form-urlencoded", 33)) {
+                       addurls(content);
+                       }
+               else if (!strncasecmp(ContentType, "multipart", 9)) {
+                       mime_parser(content, ContentLength, ContentType,
+                                       *upload_handler);
+                       }
                }
        else {
                content = NULL;
                }
 
+       /* If there are variables in the URL, we must grab them now */  
+       for (a=0; a<strlen(cmd); ++a) if ((cmd[a]=='?')||(cmd[a]=='&')) {
+               for (b=a; b<strlen(cmd); ++b) if (isspace(cmd[b])) cmd[b]=0;
+               addurls(&cmd[a+1]);
+               cmd[a] = 0;
+               }
+
        /*
         * If we're not connected to a Citadel server, try to hook up the
         * connection now.  Preference is given to the host and port specified
         * by browser cookies, if cookies have been supplied.
         */
        if (!connected) {
+               if (strlen(bstr("host"))>0) strcpy(c_host, bstr("host"));
+               if (strlen(bstr("port"))>0) strcpy(c_port, bstr("port"));
                serv_sock = connectsock(c_host, c_port, "tcp");
                connected = 1;
                serv_gets(buf); /* get the server welcome message */
-               strcpy(wc_host, c_host);
-               strcpy(wc_port, c_port);
                get_serv_info();
                }
 
+       check_for_express_messages();
 
        /*
         * If we're not logged in, but we have username and password cookies
@@ -444,80 +612,320 @@ void session_loop() {
                        }
                }
 
-       /* If there are variables in the URL, we must grab them now */  
-       for (a=0; a<strlen(cmd); ++a) if (cmd[a]=='?') {
-               for (b=a; b<strlen(cmd); ++b) if (isspace(cmd[b])) cmd[b]=0;
-               addurls(&cmd[a+1]);
-               cmd[a] = 0;
-               }
-
-       if (!strncasecmp(cmd, "GET /static/", 12)) {
+       if (!strcasecmp(action, "static")) {
                strcpy(buf, &cmd[12]);
                for (a=0; a<strlen(buf); ++a) if (isspace(buf[a])) buf[a]=0;
                output_static(buf);
                }
 
+       else if (!strcasecmp(action, "image")) {
+               output_image();
+               }
 
-       else if ((!logged_in)&&(!strncasecmp(cmd, "POST /login", 11))) {
+       else if ((!logged_in)&&(!strcasecmp(action, "login"))) {
                do_login();
                }
 
        else if (!logged_in) {
-               display_login();
+               display_login(NULL);
                }
 
        /* Various commands... */
        
-       else if (!strncasecmp(cmd, "GET /do_welcome", 15)) {
+       else if (!strcasecmp(action, "do_welcome")) {
                do_welcome();
                }
 
-       else if (!strncasecmp(cmd, "GET /display_main_menu", 22)) {
+       else if (!strcasecmp(action, "display_main_menu")) {
                display_main_menu();
                }
 
-       else if (!strncasecmp(cmd, "GET /advanced", 13)) {
+       else if (!strcasecmp(action, "advanced")) {
                display_advanced_menu();
                }
 
-       else if (!strncasecmp(cmd, "GET /whobbs", 11)) {
+       else if (!strcasecmp(action, "whobbs")) {
                whobbs();
                }
 
-       else if (!strncasecmp(cmd, "GET /knrooms", 12)) {
+       else if (!strcasecmp(action, "knrooms")) {
                list_all_rooms_by_floor();
                }
 
-       else if (!strncasecmp(cmd, "GET /gotonext", 13)) {
+       else if (!strcasecmp(action, "gotonext")) {
                slrp_highest();
                gotonext();
                }
 
-       else if (!strncasecmp(cmd, "GET /skip", 9)) {
+       else if (!strcasecmp(action, "skip")) {
                gotonext();
                }
 
-       else if (!strncasecmp(cmd, "GET /ungoto", 11)) {
+       else if (!strcasecmp(action, "ungoto")) {
                ungoto();
                }
 
-       else if (!strncasecmp(cmd, "GET /dotgoto", 12)) {
+       else if (!strcasecmp(action, "dotgoto")) {
                slrp_highest();
-               dotgoto();
+               gotoroom(bstr("room"), 1);
                }
 
-       else if (!strncasecmp(cmd, "GET /termquit", 13)) {
+       else if (!strcasecmp(action, "termquit")) {
                do_logout();
                }
 
+       else if (!strcasecmp(action, "readnew")) {
+               readloop("readnew");
+               }
+
+       else if (!strcasecmp(action, "readold")) {
+               readloop("readold");
+               }
+
+       else if (!strcasecmp(action, "readfwd")) {
+               readloop("readfwd");
+               }
+
+       else if (!strcasecmp(action, "display_enter")) {
+               display_enter();
+               }
+
+       else if (!strcasecmp(action, "post")) {
+               post_message();
+               }
+
+       else if (!strcasecmp(action, "confirm_delete_msg")) {
+               confirm_delete_msg();
+               }
+
+       else if (!strcasecmp(action, "delete_msg")) {
+               delete_msg();
+               }
+
+       else if (!strcasecmp(action, "confirm_move_msg")) {
+               confirm_move_msg();
+               }
+
+       else if (!strcasecmp(action, "move_msg")) {
+               move_msg();
+               }
+
+       else if (!strcasecmp(action, "userlist")) {
+               userlist();
+               }
+
+       else if (!strcasecmp(action, "showuser")) {
+               showuser();
+               }
+
+       else if (!strcasecmp(action, "display_page")) {
+               display_page();
+               }
+
+       else if (!strcasecmp(action, "page_user")) {
+               page_user();
+               }
+
+       else if (!strcasecmp(action, "chat")) {
+               do_chat();
+               }
+
+       else if (!strcasecmp(action, "display_private")) {
+               display_private("", 0);
+               }
+
+       else if (!strcasecmp(action, "goto_private")) {
+               goto_private();
+               }
+
+       else if (!strcasecmp(action, "zapped_list")) {
+               zapped_list();
+               }
+
+       else if (!strcasecmp(action, "display_zap")) {
+               display_zap();
+               }
+
+       else if (!strcasecmp(action, "zap")) {
+               zap();
+               }
+
+       else if (!strcasecmp(action, "display_entroom")) {
+               display_entroom();
+               }
+
+       else if (!strcasecmp(action, "entroom")) {
+               entroom();
+               }
+
+       else if (!strcasecmp(action, "display_editroom")) {
+               display_editroom();
+               }
+
+       else if (!strcasecmp(action, "editroom")) {
+               editroom();
+               }
+
+       else if (!strcasecmp(action, "display_editinfo")) {
+               display_edit("Room info", "EINF 0", "RINF", "/editinfo");
+               }
+
+       else if (!strcasecmp(action, "editinfo")) {
+               save_edit("Room info", "EINF 1", 1);
+               }
+
+       else if (!strcasecmp(action, "display_editbio")) {
+               sprintf(buf, "RBIO %s", wc_username);
+               display_edit("Your bio", "NOOP", buf, "editbio");
+               }
+
+       else if (!strcasecmp(action, "editbio")) {
+               save_edit("Your bio", "EBIO", 0);
+               }
+
+       else if (!strcasecmp(action, "confirm_delete_room")) {
+               confirm_delete_room();
+               }
+
+       else if (!strcasecmp(action, "delete_room")) {
+               delete_room();
+               }
+
+       else if (!strcasecmp(action, "validate")) {
+               validate();
+               }
+
+       else if (!strcasecmp(action, "display_editpic")) {
+               display_graphics_upload("your photo",
+                                       "UIMG 0|_userpic_",
+                                       "/editpic");
+               }
+
+       else if (!strcasecmp(action, "editpic")) {
+               do_graphics_upload("UIMG 1|_userpic_");
+               }
+
+       else if (!strcasecmp(action, "display_editroompic")) {
+               display_graphics_upload("the graphic for this room",
+                                       "UIMG 0|_roompic_",
+                                       "/editroompic");
+               }
+
+       else if (!strcasecmp(action, "editroompic")) {
+               do_graphics_upload("UIMG 1|_roompic_");
+               }
+
+       else if (!strcasecmp(action, "select_floor_to_edit_pic")) {
+               select_floor_to_edit_pic();
+               }
+
+       else if (!strcasecmp(action, "display_editfloorpic")) {
+               sprintf(buf, "UIMG 0|_floorpic_|%s",
+                       bstr("which_floor"));
+               display_graphics_upload("the graphic for this floor",
+                                       buf,
+                                       "/editfloorpic");
+               }
+
+       else if (!strcasecmp(action, "editfloorpic")) {
+               sprintf(buf, "UIMG 1|_floorpic_|%s",
+                       bstr("which_floor"));
+               do_graphics_upload(buf);
+               }
+
+       else if (!strcasecmp(action, "display_reg")) {
+               display_reg(0);
+               }
+
+       else if (!strcasecmp(action, "register")) {
+               register_user();
+               }
+
+       else if (!strcasecmp(action, "display_changepw")) {
+               display_changepw();
+               }
+
+       else if (!strcasecmp(action, "changepw")) {
+               changepw();
+               }
+
+       else if (!strcasecmp(action, "display_edit_node")) {
+               display_edit_node();
+               }
+
+       else if (!strcasecmp(action, "display_netconf")) {
+               display_netconf();
+               }
+
+       else if (!strcasecmp(action, "display_confirm_unshare")) {
+               display_confirm_unshare();
+               }
+
+       else if (!strcasecmp(action, "display_confirm_delete_node")) {
+               display_confirm_delete_node();
+               }
+
+       else if (!strcasecmp(action, "delete_node")) {
+               delete_node();
+               }
+
+       else if (!strcasecmp(action, "unshare")) {
+               unshare();
+               }
+
+       else if (!strcasecmp(action, "display_add_node")) {
+               display_add_node();
+               }
+
+       else if (!strcasecmp(action, "add_node")) {
+               add_node();
+               }
+
+       else if (!strcasecmp(action, "display_share")) {
+               display_share();
+               }
+
+       else if (!strcasecmp(action, "share")) {
+               share();
+               }
+
+       else if (!strcasecmp(action, "terminate_session")) {
+               terminate_session();
+               }
+
+       else if (!strcasecmp(action, "edit_me")) {
+               edit_me();
+               }
+
+       else if (!strcasecmp(action, "display_siteconfig")) {
+               display_siteconfig();
+               }
+
+       else if (!strcasecmp(action, "siteconfig")) {
+               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();
+               output_headers(1, "");
        
-               wprintf("<HTML><HEAD><TITLE>WebCit</TITLE></HEAD><BODY>\n");
-               wprintf("TransactionCount is %d<HR>\n", TransactionCount);
-               wprintf("You're in session %d<BR>\n", wc_session);
+               wprintf("TransactionCount is %d<BR>\n", TransactionCount);
+               wprintf("You're in session %d<HR>\n", wc_session);
+               wprintf("Command: <BR><PRE>\n");
+               escputs(cmd);
+               wprintf("</PRE><HR>\n");
+               wprintf("Variables: <BR><PRE>\n");
+               dump_vars();
+               wprintf("</PRE><HR>\n");
                wprintf("</BODY></HTML>\n");
                wDumpContent();
                }
@@ -528,6 +936,10 @@ void session_loop() {
                content = NULL;
                }
        free_urls();
+       if (upload_length > 0) {
+               free(upload);
+               upload_length = 0;
+               }
        }
 
 int main(int argc, char *argv[]) {
@@ -546,8 +958,6 @@ int main(int argc, char *argv[]) {
                        defaultport = argv[3];
                }
 
-       strcpy(wc_host, "");
-       strcpy(wc_port, "");
        strcpy(wc_username, "");
        strcpy(wc_password, "");
        strcpy(wc_roomname, "");