]> code.citadel.org Git - citadel.git/blobdiff - webcit/webcit.c
* close sockets on error, and abort execution
[citadel.git] / webcit / webcit.c
index e2d17f406c9e648ed09861092cd837bfe068dc07..7e3080bcec5fce19606bdf5d71b33c86639d975c 100644 (file)
@@ -613,6 +613,8 @@ void msgescputs1( char *strbuf)
 {
        StrBuf *OutBuf = NewStrBuf();
 
+       if ((strbuf == NULL) || IsEmptyStr(strbuf))
+               return;
        StrMsgEscAppend(OutBuf, NULL, strbuf);
        StrEscAppend(WC->WBuf, OutBuf, NULL, 0, 0);
 }
@@ -621,7 +623,8 @@ void msgescputs1( char *strbuf)
  * print a string to the client after cleaning it with msgesc()
  */
 void msgescputs(char *strbuf) {
-       StrMsgEscAppend(WC->WBuf, NULL, strbuf);
+       if ((strbuf != NULL) && !IsEmptyStr(strbuf))
+               StrMsgEscAppend(WC->WBuf, NULL, strbuf);
 }
 
 
@@ -953,13 +956,11 @@ void mimepart(const char *msgnum, const char *partnum, int force_download)
        char buf[256];
        off_t bytes;
        char content_type[256];
-       char *content = NULL;
        
        serv_printf("OPNA %s|%s", msgnum, partnum);
        serv_getln(buf, sizeof buf);
        if (buf[0] == '2') {
                bytes = extract_long(&buf[4], 0);
-               content = malloc(bytes + 2);
                if (force_download) {
                        strcpy(content_type, "application/octet-stream");
                }
@@ -979,7 +980,6 @@ void mimepart(const char *msgnum, const char *partnum, int force_download)
                wprintf(_("An error occurred while retrieving this part: %s\n"), &buf[4]);
                end_burst();
        }
-
 }
 
 
@@ -1008,7 +1008,6 @@ char *load_mimepart(long msgnum, char *partnum)
        else {
                return(NULL);
        }
-
 }
 
 
@@ -1050,6 +1049,7 @@ void blank_page(void) {
 void url_do_template(void) {
        const StrBuf *Tmpl = sbstr("template");
        begin_burst();
+       output_headers(1, 0, 0, 0, 1, 0);
        DoTemplate(ChrPtr(Tmpl), StrLength(Tmpl), NULL, NULL);
        end_burst();
 }
@@ -1186,14 +1186,14 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
  * Convenience functions to wrap around asynchronous ajax responses
  */
 void begin_ajax_response(void) {
+       struct wcsession *WCC = WC;
+
+       FlushStrBuf(WCC->HBuf);
         output_headers(0, 0, 0, 0, 0, 0);
 
         hprintf("Content-type: text/html; charset=UTF-8\r\n"
                 "Server: %s\r\n"
                 "Connection: close\r\n"
-                "Pragma: no-cache\r\n"
-                "Cache-Control: no-cache\r\n"
-               "Expires: -1\r\n"
                ,
                 PACKAGE_STRING);
         begin_burst();
@@ -1272,7 +1272,6 @@ void seconds_since_last_gexp(void)
 {
        char buf[256];
 
-       begin_ajax_response();
        if ( (time(NULL) - WC->last_pager_check) < 30) {
                wprintf("NO\n");
        }
@@ -1286,7 +1285,6 @@ void seconds_since_last_gexp(void)
                        wprintf("NO");
                }
        }
-       end_ajax_response();
 }
 
 /**
@@ -1466,7 +1464,7 @@ void session_loop(struct httprequest *req)
                body_start = strlen(content);
 
                /** Read the entire input data at once. */
-               client_read(WCC->http_sock, &content[body_start], ContentLength);
+               client_read(&WCC->http_sock, &content[body_start], ContentLength);
 
                if (!strncasecmp(ContentType, "application/x-www-form-urlencoded", 33)) {
                        StrBuf *Content;
@@ -1501,6 +1499,7 @@ void session_loop(struct httprequest *req)
                        //cmd[len - a] = '\0';
                        Params = _NewConstStrBuf(&cmd[a + 1], len - a);
                        addurls(Params);
+                       FreeStrBuf(&Params);
                        cmd[a] = 0;
                        len = a - 1;
                }
@@ -1793,9 +1792,9 @@ void diagnostics(void)
        output_headers(1, 1, 1, 0, 0, 0);
        wprintf("Session: %d<hr />\n", WC->wc_session);
        wprintf("Command: <br /><PRE>\n");
-       escputs(WC->UrlFragment1);
+       StrEscPuts(WC->UrlFragment1);
        wprintf("<br />\n");
-       escputs(WC->UrlFragment2);
+       StrEscPuts(WC->UrlFragment2);
        wprintf("</PRE><hr />\n");
        wprintf("Variables: <br /><PRE>\n");
        dump_vars();
@@ -1815,6 +1814,31 @@ void download_mimepart(void) {
                 1);
 }
 
+
+int ConditionalImportantMesage(WCTemplateToken *Tokens, void *Context)
+{
+       struct wcsession *WCC = WC;
+       if (WCC != NULL)
+               return (!IsEmptyStr(WCC->ImportantMessage));
+       else
+               return 0;
+}
+
+void tmplput_importantmessage(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context)
+{
+       struct wcsession *WCC = WC;
+       
+       if (WCC != NULL) {
+               StrEscAppend(Target, NULL, WCC->ImportantMessage, 0, 0);
+                       WCC->ImportantMessage[0] = '\0';
+       }
+}
+
+void tmplput_offer_start_page(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context)
+{
+       offer_start_page();
+}
+
 void 
 InitModule_WEBCIT
 (void)
@@ -1829,4 +1853,7 @@ InitModule_WEBCIT
        WebcitAddUrlHandler(HKEY("mimepart"), view_mimepart, NEED_URL);
        WebcitAddUrlHandler(HKEY("mimepart_download"), download_mimepart, NEED_URL);
        WebcitAddUrlHandler(HKEY("diagnostics"), diagnostics, NEED_URL);
+       RegisterConditional(HKEY("COND:IMPMSG"), 0, ConditionalImportantMesage);
+       RegisterNamespace("IMPORTANTMESSAGE", 0, 0, tmplput_importantmessage);
+       RegisterNamespace("OFFERSTARTPAGE", 0, 0, tmplput_offer_start_page);
 }