]> 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 eca88bfe9cec46bb7854a5f5d849ce8f9d46ba8a..54ffe46b59aab31231c4caa79fccd8b08175b180 100644 (file)
@@ -37,9 +37,8 @@ void WebcitAddUrlHandler(const char * UrlString, long UrlSLen, WebcitHandlerFunc
        Put(HandlerHash, UrlString, UrlSLen, NewHandler, NULL);
 }
 
-/**   
- * \brief remove escaped strings from i.e. the url string (like %20 for blanks)
- * \param buf the buffer to examine
+/*   
+ * remove escaped strings from i.e. the url string (like %20 for blanks)
  */
 long unescape_input(char *buf)
 {
@@ -91,30 +90,25 @@ void free_url(void *U)
        free(u);
 }
 
-/**
- * \brief Extract variables from the URL.
- * \param url URL supplied by the HTTP parser
+/*
+ * 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 todo now? */
-               n = -n;
+       buf = (char*) malloc (ulen + 1);
+       memcpy(buf, url, ulen);
+       buf[ulen] = '\0';
+       eptr = buf + ulen;
        up = buf;
-//     while ((up < eptr) && (*up != '?') && (*up != '&'))
-//             up++;
        while (!IsEmptyStr(up)) {
                aptr = up;
                while ((aptr < eptr) && (*aptr != '\0') && (*aptr != '='))
@@ -145,22 +139,22 @@ 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
        }
 }
 
-/**
- * \brief free urlstring memory
+/*
+ * free urlstring memory
  */
 void free_urls(void)
 {
        DeleteHash(&WC->urlstrings);
 }
 
-/**
- * \brief Diagnostic function to display the contents of all variables
+/*
+ * Diagnostic function to display the contents of all variables
  */
 
 void dump_vars(void)
@@ -179,9 +173,8 @@ void dump_vars(void)
        }
 }
 
-/**
- * \brief Return the value of a variable supplied to the current web page (from the url or a form)
- * \param key The name of the variable we want
+/*
+ * Return the value of a variable supplied to the current web page (from the url or a form)
  */
 
 const char *XBstr(char *key, size_t keylen, size_t *len)
@@ -326,10 +319,8 @@ int YESBSTR(char *key)
                return (0);
 }
 
-/**
- * \brief web-printing funcion. uses our vsnprintf wrapper
- * \param format printf format string 
- * \param ... the varargs to put into formatstring
+/*
+ * web-printing funcion. uses our vsnprintf wrapper
  */
 void wprintf(const char *format,...)
 {
@@ -344,12 +335,13 @@ void wprintf(const char *format,...)
 }
 
 
-/**
- * \brief wrap up an HTTP session, closes tags, etc.
- * \todo multiline params?
- * \param print_standard_html_footer should be set to 0 to transmit only, 1 to
- * append the main menu and closing tags, or 2 to
- * append the closing tags only.
+/*
+ * wrap up an HTTP session, closes tags, etc.
+ *
+ * print_standard_html_footer should be set to:
+ * 0 to transmit only,
+ * 1 to append the main menu and closing tags,
+ * 2 to append the closing tags only.
  */
 void wDumpContent(int print_standard_html_footer)
 {
@@ -365,12 +357,13 @@ void wDumpContent(int print_standard_html_footer)
 }
 
 
-/**
- * \brief Copy a string, escaping characters which have meaning in HTML.  
- * \param target target buffer
- * \param strbuf source buffer
- * \param nbsp If nonzero, spaces are converted to non-breaking spaces.
- * \param nolinebreaks if set, linebreaks are removed from the string.
+/*
+ * Copy a string, escaping characters which have meaning in HTML.  
+ *
+ * target              target buffer
+ * strbuf              source buffer
+ * nbsp                        If nonzero, spaces are converted to non-breaking spaces.
+ * nolinebreaks                if set, linebreaks are removed from the string.
  */
 long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks)
 {
@@ -436,12 +429,6 @@ long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks)
        return (bptr - target);
 }
 
-/**
- * \brief WHAT???
- * \param strbuf what???
- * \param nbsp If nonzero, spaces are converted to non-breaking spaces.
- * \param nolinebreaks if set, linebreaks are removed from the string.
- */ 
 void escputs1(char *strbuf, int nbsp, int nolinebreaks)
 {
        char *buf;
@@ -455,9 +442,8 @@ void escputs1(char *strbuf, int nbsp, int nolinebreaks)
        free(buf);
 }
 
-/** 
- * \brief static wrapper for ecsputs1
- * \param strbuf buffer to print escaped to client
+/* 
+ * static wrapper for ecsputs1
  */
 void escputs(char *strbuf)
 {
@@ -465,9 +451,8 @@ void escputs(char *strbuf)
 }
 
 
-/**
- * \brief urlescape buffer and print it to the client
- * \param strbuf buffer to urlescape
+/*
+ * urlescape buffer and print it to the client
  */
 void urlescputs(char *strbuf)
 {
@@ -478,10 +463,8 @@ void urlescputs(char *strbuf)
 }
 
 
-/**
- * \brief Copy a string, escaping characters for JavaScript strings.
- * \param target output string
- * \param strbuf input string
+/*
+ * Copy a string, escaping characters for JavaScript strings.
  */
 void jsesc(char *target, size_t tlen, char *strbuf)
 {
@@ -538,9 +521,8 @@ void jsesc(char *target, size_t tlen, char *strbuf)
        *tptr = '\0';
 }
 
-/**
- * \brief escape and print java script
- * \param strbuf the js code
+/*
+ * escape and print javascript
  */
 void jsescputs(char *strbuf)
 {
@@ -550,10 +532,8 @@ void jsescputs(char *strbuf)
        wprintf("%s", outbuf);
 }
 
-/**
- * \brief Copy a string, escaping characters for message text hold
- * \param target target buffer
- * \param strbuf source buffer
+/*
+ * Copy a string, escaping characters for message text hold
  */
 void msgesc(char *target, size_t tlen, char *strbuf)
 {
@@ -634,20 +614,20 @@ void msgescputs(char *strbuf) {
 
 
 
-/**
- * \brief Output all that important stuff that the browser will want to see
+/*
+ * Output HTTP headers and leading HTML for a page
  */
-void output_headers(   int do_httpheaders,     /**< 1 = output HTTP headers                          */
-                       int do_htmlhead,        /**< 1 = output HTML <head> section and <body> opener */
+void output_headers(   int do_httpheaders,     /* 1 = output HTTP headers                          */
+                       int do_htmlhead,        /* 1 = output HTML <head> section and <body> opener */
 
-                       int do_room_banner,     /**< 0=no, 1=yes,                                     
-                                                                * 2 = I'm going to embed my own, so don't open the 
-                                                                *     <div id="content"> either.                   
-                                                                */
+                       int do_room_banner,     /* 0=no, 1=yes,                                     
+                                                * 2 = I'm going to embed my own, so don't open the 
+                                                *     <div id="content"> either.                   
+                                                */
 
-                       int unset_cookies,      /**< 1 = session is terminating, so unset the cookies */
-                       int suppress_check,     /**< 1 = suppress check for instant messages          */
-                       int cache               /**< 1 = allow browser to cache this page             */
+                       int unset_cookies,      /* 1 = session is terminating, so unset the cookies */
+                       int suppress_check,     /* 1 = suppress check for instant messages          */
+                       int cache               /* 1 = allow browser to cache this page             */
 ) {
        char cookie[1024];
        char httpnow[128];
@@ -664,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 {
@@ -692,18 +679,18 @@ 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\">"
                        );
                }
                do_template("head");
        }
 
-       /** ICONBAR */
+       /* ICONBAR */
        if (do_htmlhead) {
 
 
-               /** check for ImportantMessages (these display in a div overlaying the main screen) */
+               /* check for ImportantMessages (these display in a div overlaying the main screen) */
                if (!IsEmptyStr(WC->ImportantMessage)) {
                        wprintf("<div id=\"important_message\">\n"
                                "<span class=\"imsg\">");
@@ -737,9 +724,8 @@ void output_headers(        int do_httpheaders,     /**< 1 = output HTTP headers
 }
 
 
-/**
- * \brief Generic function to do an HTTP redirect.  Easy and fun.
- * \param whichpage target url to 302 to
+/*
+ * Generic function to do an HTTP redirect.  Easy and fun.
  */
 void http_redirect(char *whichpage) {
        wprintf("HTTP/1.1 302 Moved Temporarily\n");
@@ -753,8 +739,8 @@ void http_redirect(char *whichpage) {
 
 
 
-/**
- * \brief Output a piece of content to the web browser
+/*
+ * Output a piece of content to the web browser using conformant HTTP and MIME semantics
  */
 void http_transmit_thing(char *thing, size_t length, const char *content_type,
                         int is_static) {
@@ -768,7 +754,7 @@ void http_transmit_thing(char *thing, size_t length, const char *content_type,
                PACKAGE_STRING);
 
 #ifdef HAVE_ZLIB
-       /** If we can send the data out compressed, please do so. */
+       /* If we can send the data out compressed, please do so. */
        if (WC->gzip_ok) {
                char *compressed_data = NULL;
                size_t compressed_len;
@@ -792,7 +778,7 @@ void http_transmit_thing(char *thing, size_t length, const char *content_type,
        }
 #endif
 
-       /** No compression ... just send it out as-is */
+       /* No compression ... just send it out as-is */
        wprintf("Content-length: %ld\r\n"
                "\r\n",
                (long) length
@@ -813,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);
@@ -948,6 +934,44 @@ void output_image()
        output_static(blank_gif);
 }
 
+/**
+  * \brief Extract an embedded photo from a vCard for display on the client
+  *
+  * \param msgnum
+  */
+void display_vcard_photo_img(char *msgnum_as_string)
+{
+       long msgnum = 0L;
+       char *vcard;
+       struct vCard *v;
+       char *xferbuf;
+    char *photosrc;
+       int decoded;
+       const char *contentType;
+
+       msgnum = atol(msgnum_as_string);
+       
+       vcard = load_mimepart(msgnum,"1");
+       v = vcard_load(vcard);
+       
+       photosrc = vcard_get_prop(v, "PHOTO", 1,0,0);
+       xferbuf = malloc(strlen(photosrc));
+       if (xferbuf == NULL) {
+               lprintf(5, "xferbuf malloc failed\n");
+               return;
+       }
+       memset(xferbuf, 1, SIZ);
+       decoded = CtdlDecodeBase64(
+               xferbuf,
+               photosrc,
+               strlen(photosrc));
+       contentType = GuessMimeType(xferbuf, decoded);
+       http_transmit_thing(xferbuf, decoded, contentType, 0);
+       free(v);
+       free(photosrc);
+       free(xferbuf);
+}
+
 /**
  * \brief Generic function to output an arbitrary MIME part from an arbitrary
  *        message number on the server.
@@ -1316,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;
@@ -1349,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;
@@ -1433,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);
@@ -1468,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;
                }
@@ -1691,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...
         */
 
@@ -1802,6 +1833,8 @@ void session_loop(struct httprequest *req)
                print_message(index[1]);
        } else if (!strcasecmp(action, "msgheaders")) {
                display_headers(index[1]);
+       } else if (!strcasecmp(action, "vcardphoto")) {
+               display_vcard_photo_img(index[1]);      
        } else if (!strcasecmp(action, "wiki")) {
                display_wiki_page();
        } else if (!strcasecmp(action, "display_enter")) {
@@ -2043,8 +2076,10 @@ 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")) {
                display_room_directory();
        } else if (!strcasecmp(action, "display_pictureview")) {
@@ -2053,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. */