]> code.citadel.org Git - citadel.git/blobdiff - webcit/webcit.c
* New AJAX-based wholist refresh
[citadel.git] / webcit / webcit.c
index 57ecff156676d27dd4cec4f87f45b455f90e484f..adb2021de0c74f6c79a36e4b1cb5140597d33bbc 100644 (file)
@@ -363,7 +363,7 @@ void output_headers(        int do_httpheaders,     /* 1 = output HTTP headers
        httpdate(httpnow, time(NULL));
 
        if (do_httpheaders) {
-               wprintf("Content-type: text/html\r\n"
+               wprintf("Content-type: text/html; charset=utf-8\r\n"
                        "Server: %s / %s\n"
                        "Connection: close\r\n",
                        SERVER, serv_info.serv_software
@@ -455,7 +455,7 @@ void http_redirect(char *whichpage) {
        wprintf("HTTP/1.0 302 Moved Temporarily\n");
        wprintf("Location: %s\r\n", whichpage);
        wprintf("URI: %s\r\n", whichpage);
-       wprintf("Content-type: text/html\r\n\r\n");
+       wprintf("Content-type: text/html; charset=utf-8\r\n\r\n");
        wprintf("<html><body>\n");
        wprintf("you really want to be <A HREF=\"%s\">here</A> now\n",
                whichpage);
@@ -779,49 +779,15 @@ void display_success(char *successmessage)
 
 
 
-void extract_action(char *actbuf, char *cmdbuf)
-{
-       int i;
-
-       strcpy(actbuf, cmdbuf);
-
-       /*
-        * First strip out the http method
-        */
-       remove_token(actbuf, 0, ' ');
-       if (actbuf[0] == ' ') strcpy(actbuf, &actbuf[1]);
-       if (actbuf[0] == '/') strcpy(actbuf, &actbuf[1]);
-
-       /*
-        * Now kill invalid (for webcit) characters
-        */
-       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 *partnum, char *disp,
-                       void *content, char *cbtype, size_t length,
-                       char *encoding, void *userdata)
+                       void *content, char *cbtype, char *cbcharset,
+                       size_t length, char *encoding, void *userdata)
 {
        struct urlcontent *u;
 
+       lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n",
+               name, cbtype, length);
+
        /* Form fields */
        if ( (length > 0) && (strlen(cbtype) == 0) ) {
                u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
@@ -859,9 +825,12 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
  */
 void session_loop(struct httprequest *req)
 {
-       char cmd[SIZ];
-       char method[SIZ];
-       char action[SIZ];
+       char cmd[1024];
+       char method[128];
+       char action[128];
+       char arg1[128];
+       char arg2[128];
+       char arg3[128];
        char buf[SIZ];
        int a, b;
        int ContentLength = 0;
@@ -904,7 +873,27 @@ void session_loop(struct httprequest *req)
        safestrncpy(cmd, hptr->line, sizeof cmd);
        hptr = hptr->next;
        extract_token(method, cmd, 0, ' ', sizeof method);
-       extract_action(action, cmd);
+
+       /* Figure out the action */
+       extract_token(action, cmd, 1, '/', sizeof action);
+       if (strstr(action, "?")) *strstr(action, "?") = 0;
+       if (strstr(action, "&")) *strstr(action, "&") = 0;
+       if (strstr(action, " ")) *strstr(action, " ") = 0;
+
+       extract_token(arg1, cmd, 2, '/', sizeof arg1);
+       if (strstr(arg1, "?")) *strstr(arg1, "?") = 0;
+       if (strstr(arg1, "&")) *strstr(arg1, "&") = 0;
+       if (strstr(arg1, " ")) *strstr(arg1, " ") = 0;
+
+       extract_token(arg2, cmd, 3, '/', sizeof arg2);
+       if (strstr(arg2, "?")) *strstr(arg2, "?") = 0;
+       if (strstr(arg2, "&")) *strstr(arg2, "&") = 0;
+       if (strstr(arg2, " ")) *strstr(arg2, " ") = 0;
+
+       extract_token(arg3, cmd, 4, '/', sizeof arg3);
+       if (strstr(arg3, "?")) *strstr(arg3, "?") = 0;
+       if (strstr(arg3, "&")) *strstr(arg3, "&") = 0;
+       if (strstr(arg3, " ")) *strstr(arg3, " ") = 0;
 
        while (hptr != NULL) {
                safestrncpy(buf, hptr->line, sizeof buf);
@@ -980,9 +969,10 @@ void session_loop(struct httprequest *req)
                }
        }
 
+
        /* Static content can be sent without connecting to Citadel. */
        if (!strcasecmp(action, "static")) {
-               safestrncpy(buf, &cmd[12], sizeof buf);
+               safestrncpy(buf, arg1, sizeof buf);
                for (a = 0; a < strlen(buf); ++a)
                        if (isspace(buf[a]))
                                buf[a] = 0;
@@ -1081,14 +1071,15 @@ void session_loop(struct httprequest *req)
 
 
        /*
-        * If this isn't a GroupDAV session, it's an ordinary browser
-        * connecting to the user interface.  Only allow GET and POST
-        * methods.
+        * Automatically send requests with any method other than GET or
+        * POST to the GroupDAV code as well.
         */
        if ((strcasecmp(method, "GET")) && (strcasecmp(method, "POST"))) {
-               wprintf("HTTP/1.1 405 Method Not Allowed\r\n");
-               groupdav_common_headers();
-               wprintf("Content-Length: 0\r\n\r\n");
+               groupdav_main(req, ContentType, /* do GroupDAV methods */
+                       ContentLength, content+body_start);
+               if (!WC->logged_in) {
+                       WC->killthis = 1;       /* If not logged in, don't */
+               }                               /* keep the session active */
                goto SKIP_ALL_THIS_CRAP;
        }
 
@@ -1153,8 +1144,10 @@ void session_loop(struct httprequest *req)
                display_aide_menu();
        } else if (!strcasecmp(action, "display_main_menu")) {
                display_main_menu();
-       } else if (!strcasecmp(action, "whobbs")) {
-               whobbs();
+       } else if (!strcasecmp(action, "who")) {
+               who();
+       } else if (!strcasecmp(action, "who_inner_html")) {
+               who_inner_html();
        } else if (!strcasecmp(action, "knrooms")) {
                knrooms();
        } else if (!strcasecmp(action, "gotonext")) {