]> code.citadel.org Git - citadel.git/blobdiff - webcit/html2html.c
Created ctdl_iconv_open() wrapper around iconv_open()
[citadel.git] / webcit / html2html.c
index 00a2adcbb9301260c93462cac4515b6ea11dd3b2..05bc77a935f1ae189f98f7a1cce0037a6755bf14 100644 (file)
@@ -216,7 +216,7 @@ void output_html(char *supplied_charset, int treat_as_wiki) {
           && (strcasecmp(charset, ""))
        ) {
                lprintf(9, "Converting %s to UTF-8\n", charset);
-               ic = iconv_open("UTF-8", charset);
+               ic = ctdl_iconv_open("UTF-8", charset);
                if (ic == (iconv_t)(-1) ) {
                        lprintf(5, "%s:%d iconv_open() failed: %s\n",
                                __FILE__, __LINE__, strerror(errno));
@@ -237,15 +237,21 @@ void output_html(char *supplied_charset, int treat_as_wiki) {
        }
 #endif
 
-       /** FIXME At this point, shigerugo's messages are still clean.
-        *        Figure out what is mangling them below.
+       /**
+        *      At this point, the message has been stripped down to
+        *      only the content inside the <BODY></BODY> tags, and has
+        *      been converted to UTF-8 if it was originally in a foreign
+        *      character set.  The text is also guaranteed to be null
+        *      terminated now.
         */
 
        /** Now go through the message, parsing tags as necessary. */
        converted_msg = malloc(content_length);
        strcpy(converted_msg, "");
-       ptr = msgstart;
+       ptr = msg;
+       msgend = strchr(msg, 0);
        while (ptr < msgend) {
+
                /**
                 * Change mailto: links to WebCit mail, by replacing the
                 * link with one that points back to our mail room.  Due to
@@ -276,7 +282,6 @@ void output_html(char *supplied_charset, int treat_as_wiki) {
                                ptr = &ptr[8];
                        }
                        else if ( (treat_as_wiki) && (strncasecmp(ptr, "<a href=\"wiki?", 14)) ) {
-                               lprintf(9, "converting wiki link\n");
                                content_length += 64;
                                converted_msg = realloc(converted_msg, content_length);
                                sprintf(&converted_msg[output_length], "<a href=\"wiki?page=");
@@ -346,6 +351,10 @@ void output_html(char *supplied_charset, int treat_as_wiki) {
                }
        }
 
+       /**     uncomment these two lines to override conversion        */
+       /**     memcpy(converted_msg, msg, content_length);             */
+       /**     output_length = content_length;                         */
+
        /** Output our big pile of markup */
        client_write(converted_msg, output_length);