]> code.citadel.org Git - citadel.git/blobdiff - webcit/webcit.c
* Removed the gzip compression stuff due to bugs in Internet Explorer.
[citadel.git] / webcit / webcit.c
index 12d6d5f33af26158805f93c145d95ecc473ca8b7..7707a6820dbb12c25eda5c668b158d13d98557ad 100644 (file)
@@ -74,7 +74,7 @@ void addurls(char *url)
        while (strlen(up) > 0) {
 
                /* locate the = sign */
-               strncpy(buf, up, 255);
+               safestrncpy(buf, up, sizeof buf);
                b = (-1);
                for (a = 255; a >= 0; --a)
                        if (buf[a] == '=')
@@ -295,7 +295,6 @@ void output_headers(int controlcode)
        int suppress_check = 0;
        char httpnow[SIZ];
        static int pageseq = 0;
-
        print_standard_html_head        =       controlcode & 0x03;
        refresh30                       =       ((controlcode & 0x04) >> 2);
        suppress_check                  =       ((controlcode & 0x08) >> 3);
@@ -305,11 +304,13 @@ void output_headers(int controlcode)
        httpdate(httpnow, time(NULL));
 
        if (print_standard_html_head > 0) {
-               wprintf("Content-type: text/html\n");
-               wprintf("Server: %s\n", SERVER);
-               wprintf("Connection: close\n");
-               wprintf("Pragma: no-cache\n");
-               wprintf("Cache-Control: no-store\n");
+               wprintf("Content-type: text/html\n"
+                       "Server: %s\n", SERVER
+               );
+               wprintf("Connection: close\n"
+                       "Pragma: no-cache\n"
+                       "Cache-Control: no-store\n"
+               );
        }
        stuff_to_cookie(cookie, WC->wc_session, WC->wc_username,
                        WC->wc_password, WC->wc_roomname);
@@ -324,6 +325,7 @@ void output_headers(int controlcode)
 
        if (print_standard_html_head > 0) {
                wprintf("\n");
+
                wprintf("<HTML><HEAD><TITLE>");
                escputs(serv_info.serv_humannode);
                wprintf("</TITLE>\n"
@@ -354,7 +356,7 @@ void output_headers(int controlcode)
                                "onload=\"launch_page_popup()\" ");
                        WC->HaveExpressMessages = 0;
                }
-               do_template("background.html");
+               do_template("background");
                clear_local_substs();
 
        if (print_standard_html_head == 1) {
@@ -401,6 +403,26 @@ void check_for_express_messages()
 
 
 
+/* 
+ * Output a piece of content to the web browser
+ */
+void http_transmit_thing(char *thing, size_t length, char *content_type) {
+       output_headers(0);
+       wprintf("Content-type: %s\n"
+               "Content-length: %ld\n"
+               "Server: %s\n"
+               "Connection: close\n"
+               "\n",
+               content_type,
+               (long) length,
+               SERVER
+       );
+       write(WC->http_sock, thing, (size_t)length);
+}
+
+
+
+
 void output_static(char *what)
 {
        char buf[4096];
@@ -408,6 +430,7 @@ void output_static(char *what)
        struct stat statbuf;
        off_t bytes;
        char *bigbuffer;
+       char content_type[SIZ];
 
        sprintf(buf, "static/%s", what);
        fp = fopen(buf, "rb");
@@ -417,42 +440,39 @@ void output_static(char *what)
                wprintf("\n");
                wprintf("Cannot open %s: %s\n", what, strerror(errno));
        } else {
-               output_headers(0);
-
                if (!strncasecmp(&what[strlen(what) - 4], ".gif", 4))
-                       wprintf("Content-type: image/gif\n");
+                       strcpy(content_type, "image/gif");
                else if (!strncasecmp(&what[strlen(what) - 4], ".txt", 4))
-                       wprintf("Content-type: text/plain\n");
+                       strcpy(content_type, "text/plain");
                else if (!strncasecmp(&what[strlen(what) - 4], ".css", 4))
-                       wprintf("Content-type: text/css\n");
+                       strcpy(content_type, "text/css");
                else if (!strncasecmp(&what[strlen(what) - 4], ".jpg", 4))
-                       wprintf("Content-type: image/jpeg\n");
+                       strcpy(content_type, "image/jpeg");
                else if (!strncasecmp(&what[strlen(what) - 4], ".png", 4))
-                       wprintf("Content-type: image/png\n");
+                       strcpy(content_type, "image/png");
                else if (!strncasecmp(&what[strlen(what) - 5], ".html", 5))
-                       wprintf("Content-type: text/html\n");
+                       strcpy(content_type, "text/html");
                else if (!strncasecmp(&what[strlen(what) - 4], ".wml", 4))
-                       wprintf("Content-type: text/vnd.wap.wml\n");
+                       strcpy(content_type, "text/vnd.wap.wml");
                else if (!strncasecmp(&what[strlen(what) - 5], ".wmls", 5))
-                       wprintf("Content-type: text/vnd.wap.wmlscript\n");
+                       strcpy(content_type, "text/vnd.wap.wmlscript");
                else if (!strncasecmp(&what[strlen(what) - 5], ".wmlc", 5))
-                       wprintf("Content-type: application/vnd.wap.wmlc\n");
+                       strcpy(content_type, "application/vnd.wap.wmlc");
                else if (!strncasecmp(&what[strlen(what) - 6], ".wmlsc", 6))
-                       wprintf("Content-type: application/vnd.wap.wmlscriptc\n");
+                       strcpy(content_type, "application/vnd.wap.wmlscriptc");
                else if (!strncasecmp(&what[strlen(what) - 5], ".wbmp", 5))
-                       wprintf("Content-type: image/vnd.wap.wbmp\n");
+                       wprintf("Content-type: image/vnd.wap.wbmp");
                else
-                       wprintf("Content-type: application/octet-stream\n");
+                       wprintf("Content-type: application/octet-stream");
 
                fstat(fileno(fp), &statbuf);
                bytes = statbuf.st_size;
                lprintf(3, "Static: %s, %ld bytes\n", what, bytes);
-               wprintf("Content-length: %ld\n", (long) bytes);
-               wprintf("\n");
                bigbuffer = malloc(bytes);
                fread(bigbuffer, bytes, 1, fp);
                fclose(fp);
-               write(WC->http_sock, bigbuffer, bytes);
+
+               http_transmit_thing(bigbuffer, (size_t)bytes, content_type);
                free(bigbuffer);
        }
        if (!strcasecmp(bstr("force_close_session"), "yes")) {
@@ -468,23 +488,20 @@ void output_static(char *what)
 void output_image()
 {
        char buf[SIZ];
-       char xferbuf[4096];
+       char *xferbuf = NULL;
        off_t bytes;
        off_t thisblock;
        off_t accomplished = 0L;
 
-       lprintf(5, "output_image() called\n");
        serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
        serv_gets(buf);
        if (buf[0] == '2') {
                bytes = extract_long(&buf[4], 0);
-               output_headers(0);
-               wprintf("Content-type: image/gif\n");
-               wprintf("Content-length: %ld\n", (long) bytes);
-               wprintf("\n");
+               xferbuf = malloc(bytes);
 
+               /* Read it from the server */
                while (bytes > (off_t) 0) {
-                       thisblock = (off_t) sizeof(xferbuf);
+                       thisblock = 4096;
                        if (thisblock > bytes) {
                                thisblock = bytes;
                        }
@@ -492,25 +509,37 @@ void output_image()
                        serv_gets(buf);
                        if (buf[0] == '6') {
                                thisblock = extract_long(&buf[4], 0);
-                               serv_read(xferbuf, (int) thisblock);
+                               serv_read(&xferbuf[accomplished],
+                                       (int) thisblock);
                        }
                        else {
-                               memset(xferbuf, 0, thisblock);
+                               memset(&xferbuf[accomplished], 0, thisblock);
                        }
-                       write(WC->http_sock, xferbuf, thisblock);
                        bytes = bytes - thisblock;
-                       accomplished = accomplished + thisblock;
+                       accomplished += thisblock;
                }
                serv_puts("CLOS");
                serv_gets(buf);
+
+               /* Write it to the browser */
+               http_transmit_thing(xferbuf, (size_t)accomplished,
+                                       "image/gif");
+
        } else {
                wprintf("HTTP/1.0 404 %s\n", &buf[4]);
                output_headers(0);
-               wprintf("Content-Type: text/plain\n");
-               wprintf("\n");
-               wprintf("Error retrieving image: %s\n", &buf[4]);
+               wprintf("Content-Type: text/plain\n"
+                       "\n"
+                       "Error retrieving image: %s\n",
+                       &buf[4]
+               );
        }
 
+       if (xferbuf) {
+               free(xferbuf);
+       }
+
+
 }
 
 /*
@@ -643,6 +672,55 @@ void blank_page(void) {
 }
 
 
+
+
+/*
+ * Offer to make any page the user's "start page."
+ */
+void offer_start_page(void) {
+       wprintf("<A HREF=\"/change_start_page?startpage=");
+       urlescputs(WC->this_page);
+       wprintf("\">"
+               "<FONT SIZE=-2 COLOR=#AAAAAA>Make this my start page</FONT>"
+               "</A>"
+       );
+}
+
+
+/* 
+ * Change the user's start page
+ */
+void change_start_page(void) {
+
+       if (bstr("startpage") == NULL) {
+               display_error("startpage set to null");
+               return;
+       }
+
+       set_preference("startpage", bstr("startpage"));
+
+       output_headers(3);
+       wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>");
+       wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+       wprintf("<B>New start page</B>\n");
+       wprintf("</FONT></TD></TR></TABLE>\n");
+
+       wprintf("<CENTER>"
+               "<font size=+2>Your start page has been changed.</font>"
+               "<BR><BR>\n"
+               "<I>(Note: this does not change your browser's home page. "
+               "It changes the page you begin on when you log on to ");
+       escputs(serv_info.serv_humannode);
+       wprintf(".)</I><BR><BR>"
+               "<a href = \"javascript:history.back()\">Back...</a>"
+               "</CENTER>");
+
+       wDumpContent(1);
+}
+
+
+
+
 void display_error(char *errormessage)
 {
        convenience_page("770000", "Error", errormessage);
@@ -714,6 +792,8 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
 }
 
 
+
+
 /*
  * Entry point for WebCit transaction
  */
@@ -751,6 +831,8 @@ void session_loop(struct httprequest *req)
        WC->upload_length = 0;
        WC->upload = NULL;
 
+       WC->is_wap = 0;
+
        hptr = req;
        if (hptr == NULL) return;
 
@@ -771,10 +853,17 @@ void session_loop(struct httprequest *req)
                        ContentLength = atoi(&buf[16]);
                }
                else if (!strncasecmp(buf, "Content-type: ", 14)) {
-                       strcpy(ContentType, &buf[14]);
+                       safestrncpy(ContentType, &buf[14], sizeof ContentType);
                }
                else if (!strncasecmp(buf, "User-agent: ", 12)) {
-                       strcpy(user_agent, &buf[12]);
+                       safestrncpy(user_agent, &buf[12], sizeof user_agent);
+               }
+               else if (!strncasecmp(buf, "Host: ", 6)) {
+                       safestrncpy(WC->http_host, &buf[6], sizeof WC->http_host);
+               }
+               /* Only WAP gateways explicitly name this content-type */
+               else if (strstr(buf, "text/vnd.wap.wml")) {
+                       WC->is_wap = 1;
                }
        }
 
@@ -803,8 +892,13 @@ void session_loop(struct httprequest *req)
                content = NULL;
        }
 
+       /* make a note of where we are in case the user wants to save it */
+       safestrncpy(WC->this_page, cmd, sizeof(WC->this_page));
+       remove_token(WC->this_page, 2, ' ');
+       remove_token(WC->this_page, 0, ' ');
+
        /* If there are variables in the URL, we must grab them now */
-       for (a = 0; a < strlen(cmd); ++a)
+       for (a = 0; a < strlen(cmd); ++a) {
                if ((cmd[a] == '?') || (cmd[a] == '&')) {
                        for (b = a; b < strlen(cmd); ++b)
                                if (isspace(cmd[b]))
@@ -812,6 +906,8 @@ void session_loop(struct httprequest *req)
                        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
@@ -845,6 +941,14 @@ void session_loop(struct httprequest *req)
                }
        }
 
+       /*
+        * Functions which can be performed without logging in
+        */
+       if (!strcasecmp(action, "listsub")) {
+               do_listsub();
+               goto SKIP_ALL_THIS_CRAP;
+       }
+
        check_for_express_messages();
 
        /*
@@ -881,12 +985,20 @@ void session_loop(struct httprequest *req)
                output_static(buf);
        } else if (!strcasecmp(action, "image")) {
                output_image();
+
+       /*
+        * All functions handled below this point ... make sure we log in
+        * before doing anything else!
+        */
        } else if ((!WC->logged_in) && (!strcasecmp(action, "login"))) {
                do_login();
        } else if (!WC->logged_in) {
                display_login(NULL);
        }
-       /* Various commands... */
+
+       /*
+        * Various commands...
+        */
 
        else if (!strcasecmp(action, "do_welcome")) {
                do_welcome();
@@ -897,7 +1009,7 @@ void session_loop(struct httprequest *req)
        } else if (!strcasecmp(action, "whobbs")) {
                whobbs();
        } else if (!strcasecmp(action, "knrooms")) {
-               list_all_rooms_by_floor();
+               knrooms();
        } else if (!strcasecmp(action, "gotonext")) {
                slrp_highest();
                gotonext();
@@ -989,8 +1101,12 @@ void session_loop(struct httprequest *req)
                                        "/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, "delete_floor")) {
+               delete_floor();
+       } else if (!strcasecmp(action, "rename_floor")) {
+               rename_floor();
+       } else if (!strcasecmp(action, "create_floor")) {
+               create_floor();
        } else if (!strcasecmp(action, "display_editfloorpic")) {
                sprintf(buf, "UIMG 0|_floorpic_|%s",
                        bstr("which_floor"));
@@ -1047,7 +1163,7 @@ void session_loop(struct httprequest *req)
        } else if (!strcasecmp(action, "submit_vcard")) {
                submit_vcard();
        } else if (!strcasecmp(action, "select_user_to_edit")) {
-               select_user_to_edit(NULL);
+               select_user_to_edit(NULL, NULL);
        } else if (!strcasecmp(action, "display_edituser")) {
                display_edituser(NULL);
        } else if (!strcasecmp(action, "edituser")) {
@@ -1060,6 +1176,24 @@ void session_loop(struct httprequest *req)
                folders();
        } else if (!strcasecmp(action, "do_stuff_to_msgs")) {
                do_stuff_to_msgs();
+       } else if (!strcasecmp(action, "change_start_page")) {
+               change_start_page();
+       } else if (!strcasecmp(action, "display_floorconfig")) {
+               display_floorconfig(NULL);
+       } else if (!strcasecmp(action, "toggle_self_service")) {
+               toggle_self_service();
+#ifdef HAVE_ICAL_H
+       } else if (!strcasecmp(action, "display_edit_task")) {
+               display_edit_task();
+       } else if (!strcasecmp(action, "save_task")) {
+               save_task();
+       } else if (!strcasecmp(action, "display_edit_event")) {
+               display_edit_event();
+       } else if (!strcasecmp(action, "save_event")) {
+               save_event();
+#endif
+       } else if (!strcasecmp(action, "summary")) {
+               summary();
        } else if (!strcasecmp(action, "diagnostics")) {
                output_headers(1);
 
@@ -1088,4 +1222,5 @@ SKIP_ALL_THIS_CRAP:
                free(WC->upload);
                WC->upload_length = 0;
        }
+
 }