]> 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 258bdce1507f330a6c013dffe2c6591011e2de5c..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,7 +139,6 @@ void addurls(char *url)
                u->url_data[u->url_data_size] = '\0';
                up = bptr;
                ++up;
-
 #ifdef DEBUG_URLSTRINGS
                lprintf(9, "%s = [%ld]  %s\n", u->url_key, u->url_data_size, u->url_data); 
 #endif
@@ -647,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 {
@@ -1336,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;
@@ -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;
                }
@@ -1720,8 +1726,8 @@ void session_loop(struct httprequest *req)
                display_openid_login(NULL);
        } else if ((!WC->logged_in) && (!strcasecmp(action, "openid_login"))) {
                do_openid_login();
-       } else if ((!WC->logged_in) && (!strcasecmp(action, "finish_openid_login"))) {
-               finish_openid_login();
+       } else if (!strcasecmp(action, "finalize_openid_login")) {
+               finalize_openid_login();
        } else if (!WC->logged_in) {
                display_login(NULL);
        }
@@ -2082,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. */