]> code.citadel.org Git - citadel.git/blobdiff - webcit/webcit.c
* migrate message creation to templates (citing still missing)
[citadel.git] / webcit / webcit.c
index 6be92d017e03f751404335982f36bb0aed206e66..c4fd3648c431acc66e7a9bf098c6cb35c8ebf812 100644 (file)
@@ -390,14 +390,13 @@ void put_trailing_javascript(void) {
  * 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.
+ * 0           - to transmit only,
+ * nonzero     - to append the closing tags
  */
 void wDumpContent(int print_standard_html_footer)
 {
        if (print_standard_html_footer) {
-               wprintf("</div>\n");    /* end of "text" div */
+               wprintf("</div> <!-- end of 'content' div -->\n");
                svcallback("TRAILING_JAVASCRIPT", put_trailing_javascript);
                do_template("trailing", NULL);
        }
@@ -696,11 +695,6 @@ void output_headers(       int do_httpheaders,     /* 1 = output HTTP headers
 
        if (do_htmlhead) {
                begin_burst();
-               if (!access("static.local/webcit.css", R_OK)) {
-                       svprintf(HKEY("CSSLOCAL"), WCS_STRING,
-                          "<link href=\"static.local/webcit.css\" rel=\"stylesheet\" type=\"text/css\">"
-                       );
-               }
                do_template("head", NULL);
        }
 
@@ -957,32 +951,30 @@ void display_vcard_photo_img(void)
  * filename            Fake filename to give
  * force_download      Nonzero to force set the Content-Type: header to "application/octet-stream"
  */
-void postpart(const char *partnum, const char *filename, int force_download)
+void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
 {
+       void *vPart;
        char content_type[256];
-       int num = atoi(partnum);
-       struct wc_attachment *part = WC->first_attachment;
-
-       while(num && part) {
-               num--;
-               part=part->next;
-       }
+       wc_attachment *part;
        
-       if (part) {
+       if (GetHash(WC->attachments, SKEY(partnum), &vPart) &&
+           (vPart != NULL)) {
+               part = (wc_attachment*) vPart;
                if (force_download) {
                        strcpy(content_type, "application/octet-stream");
                }
                else {
-                       strncpy(content_type, part->content_type, sizeof content_type);
+                       strncpy(content_type, ChrPtr(part->content_type), sizeof content_type);
                }
                output_headers(0, 0, 0, 0, 0, 0);
                StrBufAppendBufPlain(WC->WBuf, part->data, part->length, 0);
                http_transmit_thing(content_type, 0);
        } else {
-               hprintf("HTTP/1.1 404 %s\n",partnum);
+               hprintf("HTTP/1.1 404 %s\n", ChrPtr(partnum));
                output_headers(0, 0, 0, 0, 0, 0);
                hprintf("Content-Type: text/plain\r\n");
-               wprintf(_("An error occurred while retrieving this part: %s/%s\n"), partnum, filename);
+               wprintf(_("An error occurred while retrieving this part: %s/%s\n"), 
+                       ChrPtr(partnum), ChrPtr(filename));
                end_burst();
        }
 }
@@ -1055,6 +1047,30 @@ char *load_mimepart(long msgnum, char *partnum)
        }
 }
 
+/*
+ * Read any MIME part of a message, from the server, into memory.
+ */
+void MimeLoadData(wc_mime_attachment *Mime)
+{
+       char buf[SIZ];
+       off_t bytes;
+//// TODO: is there a chance the contenttype is different  to the one we know? 
+       serv_printf("DLAT %ld|%s", Mime->msgnum, ChrPtr(Mime->PartNum));
+       serv_getln(buf, sizeof buf);
+       if (buf[0] == '6') {
+               bytes = extract_long(&buf[4], 0);
+
+               if (Mime->Data == NULL)
+                       Mime->Data = NewStrBufPlain(NULL, bytes);
+               StrBuf_ServGetBLOB(Mime->Data, bytes);
+
+       }
+       else {
+               FlushStrBuf(Mime->Data);
+               /// TODO XImportant message
+       }
+}
+
 
 /*
  * Convenience functions to display a page containing only a string
@@ -1638,6 +1654,7 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method
 
                        get_serv_info(browser_host, user_agent);
                        if (serv_info.serv_rev_level < MINIMUM_CIT_VERSION) {
+                               begin_burst();
                                wprintf(_("You are connected to a Citadel "
                                        "server running Citadel %d.%02d. \n"
                                        "In order to run this version of WebCit "
@@ -1648,6 +1665,7 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method
                                                MINIMUM_CIT_VERSION / 100,
                                                MINIMUM_CIT_VERSION % 100
                                        );
+                               end_burst();
                                end_webcit_session();
                                goto SKIP_ALL_THIS_CRAP;
                        }
@@ -1748,6 +1766,7 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method
                                        set_selected_language(ChrPtr(Lang));
                                        go_selected_language();         /* set locale */
                                }
+                               get_preference("default_header_charset", &WCC->DefaultCharset);
                        }
                }
        }
@@ -1857,14 +1876,14 @@ void download_mimepart(void) {
 }
 
 void view_postpart(void) {
-       postpart(ChrPtr(WC->UrlFragment1),
-                ChrPtr(WC->UrlFragment2),
+       postpart(WC->UrlFragment1,
+                WC->UrlFragment2,
                 0);
 }
 
 void download_postpart(void) {
-       postpart(ChrPtr(WC->UrlFragment1),
-                ChrPtr(WC->UrlFragment2),
+       postpart(WC->UrlFragment1,
+                WC->UrlFragment2,
                 1);
 }
 
@@ -1890,13 +1909,13 @@ void tmplput_importantmessage(StrBuf *Target, int nArgs, WCTemplateToken *Tokens
 
 int ConditionalBstr(WCTemplateToken *Tokens, void *Context, int ContextType)
 {
-       if(Tokens->nParameters == 1)
-               return HaveBstr(Tokens->Params[0]->Start, 
-                               Tokens->Params[0]->len);
+       if(Tokens->nParameters == 3)
+               return HaveBstr(Tokens->Params[2]->Start, 
+                               Tokens->Params[2]->len);
        else
-               return strcmp(Bstr(Tokens->Params[0]->Start, 
-                                  Tokens->Params[0]->len),
-                             Tokens->Params[1]->Start) == 0;
+               return strcmp(Bstr(Tokens->Params[2]->Start, 
+                                  Tokens->Params[2]->len),
+                             Tokens->Params[3]->Start) == 0;
 }
 
 void tmplput_bstr(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
@@ -1906,6 +1925,19 @@ void tmplput_bstr(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Cont
                              Tokens->Params[0]->len), 0);
 }
 
+
+void tmplput_csslocal(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       extern StrBuf *csslocal;
+       StrBufAppendBuf(Target, 
+                       csslocal, 0);
+}
+
+
+
+
+
+
 void 
 InitModule_WEBCIT
 (void)
@@ -1926,6 +1958,7 @@ InitModule_WEBCIT
        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("CSSLOCAL", 0, 0, tmplput_csslocal, CTX_NONE);
        RegisterNamespace("IMPORTANTMESSAGE", 0, 0, tmplput_importantmessage, CTX_NONE);
        RegisterNamespace("OFFERSTARTPAGE", 0, 0, offer_start_page, CTX_NONE);
 }