* fix freeing.. well, most of it
authorWilfried Göesgens <willi@citadel.org>
Wed, 5 Nov 2008 22:07:28 +0000 (22:07 +0000)
committerWilfried Göesgens <willi@citadel.org>
Wed, 5 Nov 2008 22:07:28 +0000 (22:07 +0000)
* fix iconverting if operating on a buffer in html2html
* strip contenttype attributes before looking up the renderer

webcit/html2html.c
webcit/messages.c
webcit/webserver.c

index bfa53709cc5ab8994092d9419c85aa0c178518c8..cab626d3ee48e618ddb05f097553a43f26e36be6 100644 (file)
@@ -139,6 +139,7 @@ void output_html(const char *supplied_charset, int treat_as_wiki, int msgnum, St
        }
        else {
                content_length = StrLength(Source);
+               free(msg);
                msg = (char*) ChrPtr(Source);/* TODO: remove cast */
                buffer_length = content_length;
        }
@@ -234,6 +235,10 @@ void output_html(const char *supplied_charset, int treat_as_wiki, int msgnum, St
                strcpy(msg, msgstart);
        }
 
+       /** Now go through the message, parsing tags as necessary. */
+       converted_msg = NewStrBufPlain(NULL, content_length + 8192);
+
+
        /** Convert foreign character sets to UTF-8 if necessary. */
 #ifdef HAVE_ICONV
        if ( (strcasecmp(charset, "us-ascii"))
@@ -247,19 +252,30 @@ void output_html(const char *supplied_charset, int treat_as_wiki, int msgnum, St
                                __FILE__, __LINE__, strerror(errno));
                }
        }
-       if (ic != (iconv_t)(-1) ) {
-               ibuf = msg;
-               ibuflen = content_length;
-               obuflen = content_length + (content_length / 2) ;
-               obuf = (char *) malloc(obuflen);
-               osav = obuf;
-               iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
-               content_length = content_length + (content_length / 2) - obuflen;
-               osav[content_length] = 0;
-               free(msg);
-               msg = osav;
-               iconv_close(ic);
+       if  (Source == NULL) {
+               if (ic != (iconv_t)(-1) ) {
+                       ibuf = msg;
+                       ibuflen = content_length;
+                       obuflen = content_length + (content_length / 2) ;
+                       obuf = (char *) malloc(obuflen);
+                       osav = obuf;
+                       iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
+                       content_length = content_length + (content_length / 2) - obuflen;
+                       osav[content_length] = 0;
+                       free(msg);
+                       msg = osav;
+                       iconv_close(ic);
+               }
+       }
+       else {
+               if (ic != (iconv_t)(-1) ) {
+                       StrBuf *Buf = NewStrBufPlain(NULL, StrLength(Source) + 8096);;
+                       StrBufConvert(Source, Buf, &ic);
+                       FreeStrBuf(&Buf);
+                       iconv_close(ic);
+               }
        }
+               
 #endif
 
        /**
@@ -270,8 +286,6 @@ void output_html(const char *supplied_charset, int treat_as_wiki, int msgnum, St
         *      terminated now.
         */
 
-       /** Now go through the message, parsing tags as necessary. */
-       converted_msg = NewStrBufPlain(NULL, content_length + 8192);
        if (converted_msg == NULL) {
                StrBufAppendPrintf(Target, "Error %d: %s<br />%s:%d", errno, strerror(errno), __FILE__, __LINE__);
                goto BAIL;
index 50b53ef3a32c97c8999d24fcfa22d006dd97e93b..473b1e04985e971f2782c86e026c1d47683572f0 100644 (file)
@@ -241,8 +241,23 @@ int summcmp_rdate(const void *s1, const void *s2) {
  * message index functions
  */
 
+void DestroyMimeParts(wc_mime_attachment *Mime)
+{
+       FreeStrBuf(&Mime->Name);
+       FreeStrBuf(&Mime->FileName);
+       FreeStrBuf(&Mime->PartNum);
+       FreeStrBuf(&Mime->Disposition);
+       FreeStrBuf(&Mime->ContentType);
+       FreeStrBuf(&Mime->Charset);
+       FreeStrBuf(&Mime->Data);
+}
 
-
+void DestroyMime(void *vMime)
+{
+       wc_mime_attachment *Mime = (wc_mime_attachment*)vMime;
+       DestroyMimeParts(Mime);
+       free(Mime);
+}
 
 void DestroyMessageSummary(void *vMsg)
 {
@@ -260,6 +275,14 @@ void DestroyMessageSummary(void *vMsg)
        FreeStrBuf(&Msg->Rfca);
        FreeStrBuf(&Msg->OtherNode);
 
+       FreeStrBuf(&Msg->reply_to);
+
+       DeleteHash(&Msg->Attachments);  /**< list of Accachments */
+       DeleteHash(&Msg->Submessages);
+       DeleteHash(&Msg->AttachLinks);
+
+       DestroyMimeParts(&Msg->MsgBody);
+
        free(Msg);
 }
 
@@ -472,22 +495,28 @@ void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundChars
 
        mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
        memset(mime, 0, sizeof(wc_mime_attachment));
-       Buf=NewStrBuf();
+       Buf = NewStrBuf();
 
        mime->Name = NewStrBuf();
        StrBufExtract_token(mime->Name, HdrLine, 0, '|');
+
        StrBufExtract_token(Buf, HdrLine, 1, '|');
        StrBuf_RFC822_to_Utf8(mime->FileName, Buf, WC->DefaultCharset, FoundCharset);
+
        mime->PartNum = NewStrBuf();
        StrBufExtract_token(mime->PartNum, HdrLine, 2, '|');
+
        mime->Disposition = NewStrBuf();
        StrBufExtract_token(mime->Disposition, HdrLine, 3, '|');
+
        mime->ContentType = NewStrBuf();
        StrBufExtract_token(mime->ContentType, HdrLine, 4, '|');
+
        mime->length = StrBufExtract_int(HdrLine, 5, '|');
 
        StrBufTrim(mime->Name);
        StrBufTrim(mime->FileName);
+
        if ( (StrLength(mime->FileName) == 0) && (StrLength(mime->Name) > 0) ) {
                StrBufAppendBuf(mime->FileName, mime->Name, 0);
        }
@@ -530,6 +559,9 @@ void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundChars
                Msg->cal_partnum_ref = mime;
        }
        /** end handler prep ***/
+
+       FreeStrBuf(&Buf);
+
 }
 void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
 {
@@ -1296,7 +1328,7 @@ void read_message(long msgnum, int printable_view, char *section) {
        StrBuf *Buf;
        StrBuf *Token;
        StrBuf *FoundCharset;
-       message_summary *Msg;
+       message_summary *Msg = NULL;
        headereval *Hdr;
        void *vHdr;
        char buf[SIZ];
@@ -1413,9 +1445,11 @@ void read_message(long msgnum, int printable_view, char *section) {
                        break;
                }
        }
-
-
-       if (GetHash(MimeRenderHandler, SKEY(Msg->MsgBody.ContentType), &vHdr) &&
+       
+       /* strip the bare contenttype, so we ommit charset etc. */
+       StrBufExtract_token(Buf, Msg->MsgBody.ContentType, 0, ';');
+       StrBufTrim(Buf);
+       if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
            (vHdr != NULL)) {
                RenderMimeFunc Render;
                Render = (RenderMimeFunc)vHdr;
@@ -1470,22 +1504,6 @@ void read_message(long msgnum, int printable_view, char *section) {
        if (nhdr == 1) {
                wprintf("****");
        }
-
-       if (StrLength(Msg->cccc)> 0) {
-               StrBuf *tmp;
-               tmp = Msg->cccc;
-               Msg->cccc = Buf;
-               StrBuf_RFC822_to_Utf8(Msg->cccc, tmp, WCC->DefaultCharset, FoundCharset);
-               Buf = tmp;
-       }
-       if (StrLength(Msg->subj)> 0) {
-               StrBuf *tmp;
-               tmp = Msg->subj;
-               Msg->subj = Buf;
-               StrBuf_RFC822_to_Utf8(Msg->subj, tmp, WCC->DefaultCharset, FoundCharset);
-               Buf = tmp;
-       }
-
        DoTemplate(HKEY("view_message"), NULL, Msg, CTX_MAILSUM);
 
 
@@ -1556,7 +1574,10 @@ void read_message(long msgnum, int printable_view, char *section) {
        if (num_attach_links > 0) {
                free(attach_links);
        }
+       DestroyMessageSummary(Msg);
        FreeStrBuf(&FoundCharset);
+       FreeStrBuf(&Token);
+       FreeStrBuf(&Buf);
 }
 
 
index db093ea4ca39fe988d7aebb24afacbb59bfd3641..a28e87f353c0deda683a4a7bbd05c5a844704d36 100644 (file)
@@ -27,6 +27,7 @@ int is_https = 0;             /* Nonzero if I am an HTTPS service */
 int follow_xff = 0;            /* Follow X-Forwarded-For: header */
 int home_specified = 0;                /* did the user specify a homedir? */
 int time_to_die = 0;            /* Nonzero if server is shutting down */
+int DisableGzip = 0;
 extern void *context_loop(int*);
 extern void *housekeeping_loop(void);
 extern pthread_mutex_t SessionListMutex;
@@ -271,7 +272,7 @@ long end_burst(void)
 
 #ifdef HAVE_ZLIB
        /* Perform gzip compression, if enabled and supported by client */
-       if ((WCC->gzip_ok) && CompressBuffer(WCC->WBuf))
+       if (!DisableGzip && (WCC->gzip_ok) && CompressBuffer(WCC->WBuf))
        {
                hprintf("Content-encoding: gzip\r\n");
        }
@@ -698,7 +699,6 @@ int main(int argc, char **argv)
 
        LoadZoneFiles();
 
-
 #ifdef DBG_PRINNT_HOOKS_AT_START
        dbg_PrintHash(HandlerHash, nix, NULL);
 #endif
@@ -716,9 +716,9 @@ int main(int argc, char **argv)
 
        /* Parse command line */
 #ifdef HAVE_OPENSSL
-       while ((a = getopt(argc, argv, "h:i:p:t:T:x:dD:cfs")) != EOF)
+       while ((a = getopt(argc, argv, "h:i:p:t:T:x:dD:cfsZ")) != EOF)
 #else
-       while ((a = getopt(argc, argv, "h:i:p:t:T:x:dD:cf")) != EOF)
+       while ((a = getopt(argc, argv, "h:i:p:t:T:x:dD:cfZ")) != EOF)
 #endif
                switch (a) {
                case 'h':
@@ -758,6 +758,9 @@ int main(int argc, char **argv)
                case 'T':
                        LoadTemplates = atoi(optarg);
                        break;
+               case 'Z':
+                       DisableGzip = 1;
+                       break;
                case 'x':
                        verbosity = atoi(optarg);
                        break;