]> code.citadel.org Git - citadel.git/blobdiff - webcit/webcit.c
* cut all left of webcit= from cookies
[citadel.git] / webcit / webcit.c
index 20b9342e2943e055232eb63b0f3378ff15e7c6a0..e03a8154595034ceb35ca213967f218433bf5caa 100644 (file)
@@ -767,6 +767,10 @@ void http_redirect(const char *whichpage) {
 void http_transmit_thing(const char *content_type,
                         int is_static) {
 
+       lprintf(9, "http_transmit_thing(%s)%s\n",
+               content_type,
+               (is_static ? " (static)" : "")
+       );
        output_headers(0, 0, 0, 0, 0, is_static);
 
        hprintf("Content-type: %s\r\n"
@@ -861,9 +865,7 @@ void output_static(char *what)
 
 
                close(fd);
-#ifndef TECH_PREVIEW
                lprintf(9, "output_static('%s')  %s\n", what, content_type);
-#endif
                http_transmit_thing(content_type, 1);
        }
        if (yesbstr("force_close_session")) {
@@ -1057,7 +1059,7 @@ 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);
+       DoTemplate(ChrPtr(Tmpl), StrLength(Tmpl), NULL, NULL, 0);
        end_burst();
 }
 
@@ -1066,7 +1068,7 @@ void url_do_template(void) {
 /*
  * Offer to make any page the user's "start page."
  */
-void offer_start_page(void) {
+void offer_start_page(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType) {
        wprintf("<a href=\"change_start_page?startpage=");
        urlescputs(WC->this_page);
        wprintf("\">");
@@ -1285,6 +1287,7 @@ void seconds_since_last_gexp(void)
                wprintf("NO\n");
        }
        else {
+               memset(buf, 5, 0);
                serv_puts("NOOP");
                serv_getln(buf, sizeof buf);
                if (buf[3] == '*') {
@@ -1330,7 +1333,8 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method
        char buf[SIZ];
        int a, nBackDots, nEmpty;
        int ContentLength = 0;
-       StrBuf *ContentType, *UrlLine;
+       StrBuf *ContentType = NULL;
+       StrBuf *UrlLine = NULL;
        StrBuf *content = NULL;
        const char *content_end = NULL;
        char browser_host[256];
@@ -1432,7 +1436,9 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method
        if ((follow_xff) &&
            GetHash(HTTPHeaders, HKEY("X-FORWARDED-HOST"), &vLine) &&
            (vLine != NULL)) {
-               safestrncpy(WCC->http_host, &buf[18], sizeof WCC->http_host);
+               safestrncpy(WCC->http_host, 
+                           ChrPtr((StrBuf*)vLine), 
+                           sizeof WCC->http_host);
        }
        if (IsEmptyStr(WCC->http_host) && 
            GetHash(HTTPHeaders, HKEY("HOST"), &vLine) &&
@@ -1466,7 +1472,7 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method
                body_start = StrLength(content);
 
                /** Read the entire input data at once. */
-               client_read(&WCC->http_sock, content, ReadBuf, ContentLength);
+               client_read(&WCC->http_sock, content, ReadBuf, ContentLength + body_start);
 
                if (!strncasecmp(ChrPtr(ContentType), "application/x-www-form-urlencoded", 33)) {
                        StrBufCutLeft(content, body_start);
@@ -1812,7 +1818,7 @@ void download_mimepart(void) {
 }
 
 
-int ConditionalImportantMesage(WCTemplateToken *Tokens, void *Context)
+int ConditionalImportantMesage(WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        struct wcsession *WCC = WC;
        if (WCC != NULL)
@@ -1821,7 +1827,7 @@ int ConditionalImportantMesage(WCTemplateToken *Tokens, void *Context)
                return 0;
 }
 
-void tmplput_importantmessage(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context)
+void tmplput_importantmessage(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        struct wcsession *WCC = WC;
        
@@ -1831,13 +1837,7 @@ void tmplput_importantmessage(StrBuf *Target, int nArgs, WCTemplateToken *Tokens
        }
 }
 
-void tmplput_offer_start_page(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context)
-{
-       offer_start_page();
-}
-
-
-int ConditionalBstr(WCTemplateToken *Tokens, void *Context)
+int ConditionalBstr(WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        if(Tokens->nParameters == 1)
                return HaveBstr(Tokens->Params[0]->Start, 
@@ -1848,7 +1848,7 @@ int ConditionalBstr(WCTemplateToken *Tokens, void *Context)
                              Tokens->Params[1]->Start) == 0;
 }
 
-void tmplput_bstr(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context)
+void tmplput_bstr(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        StrBufAppendBuf(Target, 
                        SBstr(Tokens->Params[0]->Start, 
@@ -1869,9 +1869,10 @@ 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);
-       RegisterConditional(HKEY("COND:BSTR"), 1, ConditionalBstr);
-       RegisterNamespace("BSTR", 1, 2, tmplput_bstr);
-       RegisterNamespace("IMPORTANTMESSAGE", 0, 0, tmplput_importantmessage);
-       RegisterNamespace("OFFERSTARTPAGE", 0, 0, tmplput_offer_start_page);
+
+       RegisterConditional(HKEY("COND:IMPMSG"), 0, ConditionalImportantMesage, CTX_NONE);
+       RegisterConditional(HKEY("COND:BSTR"), 1, ConditionalBstr, CTX_NONE);
+       RegisterNamespace("BSTR", 1, 2, tmplput_bstr, CTX_NONE);
+       RegisterNamespace("IMPORTANTMESSAGE", 0, 0, tmplput_importantmessage, CTX_NONE);
+       RegisterNamespace("OFFERSTARTPAGE", 0, 0, offer_start_page, CTX_NONE);
 }