]> code.citadel.org Git - citadel.git/blobdiff - webcit/webcit.c
Added some glue code for attachment of an OpenID to
[citadel.git] / webcit / webcit.c
index 7887e0a18d4702f3dc87147adac8bb63e5588701..54ffe46b59aab31231c4caa79fccd8b08175b180 100644 (file)
@@ -93,23 +93,21 @@ void free_url(void *U)
 /*
  * Extract variables from the URL.
  */
-void addurls(char *url)
+void addurls(char *url, long ulen)
 {
        char *aptr, *bptr, *eptr;
        char *up;
-       char buf[SIZ] = "";
-       int len, n, keylen;
+       char *buf;
+       int len, keylen;
        urlcontent *u;
        struct wcsession *WCC = WC;
 
        if (WCC->urlstrings == NULL)
                WCC->urlstrings = NewHash(1, NULL);
-       eptr = buf + sizeof (buf);
-       up = url;
-       /** locate the = sign */
-       n = safestrncpy(buf, up, sizeof buf);
-       if (n < 0) /* hm, we exceeded the buffer... hmmm what to do now? */
-               n = -n;
+       buf = (char*) malloc (ulen + 1);
+       memcpy(buf, url, ulen);
+       buf[ulen] = '\0';
+       eptr = buf + ulen;
        up = buf;
        while (!IsEmptyStr(up)) {
                aptr = up;
@@ -141,9 +139,9 @@ void addurls(char *url)
                u->url_data[u->url_data_size] = '\0';
                up = bptr;
                ++up;
-/* uncomment the following line to see each parameter in the log
+#ifdef DEBUG_URLSTRINGS
                lprintf(9, "%s = [%ld]  %s\n", u->url_key, u->url_data_size, u->url_data); 
-*/
+#endif
        }
 }
 
@@ -646,10 +644,17 @@ void output_headers(      int do_httpheaders,     /* 1 = output HTTP headers
        }
 
        if (cache) {
+               char httpTomorow[128];
+
+               http_datestring(httpTomorow, sizeof httpTomorow, 
+                               time(NULL) + 60 * 60 * 24 * 2);
+
                wprintf("Pragma: public\r\n"
                        "Cache-Control: max-age=3600, must-revalidate\r\n"
-                       "Last-modified: %s\r\n",
-                       httpnow
+                       "Last-modified: %s\r\n"
+                       "Expires: %s\r\n",
+                       httpnow,
+                       httpTomorow
                );
        }
        else {
@@ -674,7 +679,7 @@ void output_headers(        int do_httpheaders,     /* 1 = output HTTP headers
        if (do_htmlhead) {
                begin_burst();
                if (!access("static.local/webcit.css", R_OK)) {
-                       svprintf("CSSLOCAL", WCS_STRING,
+                       svprintf(HKEY("CSSLOCAL"), WCS_STRING,
                           "<link href=\"static.local/webcit.css\" rel=\"stylesheet\" type=\"text/css\">"
                        );
                }
@@ -794,7 +799,7 @@ void print_menu_box(char* Title, char *Class, int nLines, ...)
        va_list arg_list;
        long i;
        
-       svprintf("BOXTITLE", WCS_STRING, Title);
+       svput("BOXTITLE", WCS_STRING, Title);
        do_template("beginbox");
        
        wprintf("<ul class=\"%s\">", Class);
@@ -1335,7 +1340,6 @@ void session_loop(struct httprequest *req)
        char pathname[1024];
        int a, b, nBackDots, nEmpty;
        int ContentLength = 0;
-       int BytesRead = 0;
        char ContentType[512];
        char *content = NULL;
        char *content_end = NULL;
@@ -1368,7 +1372,6 @@ void session_loop(struct httprequest *req)
 
        WC->upload_length = 0;
        WC->upload = NULL;
-       WC->vars = NULL;
        WC->is_wap = 0;
 
        hptr = req;
@@ -1452,18 +1455,21 @@ void session_loop(struct httprequest *req)
        }
 
        if (ContentLength > 0) {
-               content = malloc(ContentLength + SIZ);
-               memset(content, 0, ContentLength + SIZ);
-               snprintf(content,  ContentLength + SIZ, "Content-type: %s\n"
+               int BuffSize;
+
+               BuffSize = ContentLength + SIZ;
+               content = malloc(BuffSize);
+               memset(content, 0, BuffSize);
+               snprintf(content,  BuffSize, "Content-type: %s\n"
                                "Content-length: %d\n\n",
                                ContentType, ContentLength);
                body_start = strlen(content);
 
                /** Read the entire input data at once. */
-               client_read(WC->http_sock, &content[BytesRead+body_start], ContentLength);
+               client_read(WC->http_sock, &content[body_start], ContentLength);
 
                if (!strncasecmp(ContentType, "application/x-www-form-urlencoded", 33)) {
-                       addurls(&content[body_start]);
+                       addurls(&content[body_start], ContentLength);
                } else if (!strncasecmp(ContentType, "multipart", 9)) {
                        content_end = content + ContentLength + body_start;
                        mime_parser(content, content_end, *upload_handler, NULL, NULL, NULL, 0);
@@ -1487,7 +1493,7 @@ void session_loop(struct httprequest *req)
                                        len = b - 1;
                                }
                        }
-                       addurls(&cmd[a + 1]);
+                       addurls(&cmd[a + 1], len - a);
                        cmd[a] = 0;
                        len = a - 1;
                }
@@ -1710,17 +1716,23 @@ void session_loop(struct httprequest *req)
        } else if (!strcasecmp(action, "display_mime_icon")) {
                display_mime_icon();
 
-               /**
-                * All functions handled below this point ... make sure we log in
-                * before doing anything else!
-                */
+       /*
+        * 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) && (!strcasecmp(action, "display_openid_login"))) {
+               display_openid_login(NULL);
+       } else if ((!WC->logged_in) && (!strcasecmp(action, "openid_login"))) {
+               do_openid_login();
+       } else if (!strcasecmp(action, "finalize_openid_login")) {
+               finalize_openid_login();
        } else if (!WC->logged_in) {
                display_login(NULL);
        }
 
-       /**
+       /*
         * Various commands...
         */
 
@@ -2064,8 +2076,8 @@ void session_loop(struct httprequest *req)
                dump_vars();
                wprintf("</PRE><hr />\n");
                wDumpContent(1);
-       } else if (!strcasecmp(action, "updatenote")) {
-               updatenote();
+       } else if (!strcasecmp(action, "add_new_note")) {
+               add_new_note();
        } else if (!strcasecmp(action, "ajax_update_note")) {
                ajax_update_note();
        } else if (!strcasecmp(action, "display_room_directory")) {
@@ -2076,6 +2088,10 @@ void session_loop(struct httprequest *req)
                download_file(index[1]);
        } else if (!strcasecmp(action, "upload_file")) {
                upload_file();
+       } else if (!strcasecmp(action, "display_openids")) {
+               display_openids();
+       } else if (!strcasecmp(action, "openid_attach")) {
+               openid_attach();
        }
 
        /** When all else fais, display the main menu. */