*
* \param supplied_charset the input charset as declared in the MIME headers
*/
-void output_html(char *supplied_charset, int treat_as_wiki, int msgnum) {
+void output_html(const char *supplied_charset, int treat_as_wiki, int msgnum, StrBuf *Source, StrBuf *Target) {
char buf[SIZ];
char *msg;
char *ptr;
size_t obuflen; /**< Length of output buffer */
char *osav; /**< Saved pointer to output buffer */
#endif
+ if (Target == NULL)
+ Target = WC->WBuf;
safestrncpy(charset, supplied_charset, sizeof charset);
msg = strdup("");
sprintf(new_window, "<a target=\"%s\" href=", TARGET);
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+ if (Source == NULL) while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
line_length = strlen(buf);
buffer_length = content_length + line_length + 2;
ptr = realloc(msg, buffer_length);
if (ptr == NULL) {
- wprintf("<b>");
- wprintf(_("realloc() error! couldn't get %d bytes: %s"),
+ StrBufAppendPrintf(Target, "<b>");
+ StrBufAppendPrintf(Target, _("realloc() error! couldn't get %d bytes: %s"),
buffer_length + 1,
strerror(errno));
- wprintf("</b><br /><br />\n");
+ StrBufAppendPrintf(Target, "</b><br /><br />\n");
while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
/** flush */
}
strcpy(&msg[content_length], "\n");
content_length += 1;
}
+ else {
+ content_length = StrLength(Source);
+ free(msg);
+ msg = (char*) ChrPtr(Source);/* TODO: remove cast */
+ buffer_length = content_length;
+ }
/** Do a first pass to isolate the message body */
ptr = msg + 1;
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"))
&& (strcasecmp(charset, ""))
) {
lprintf(9, "Converting %s to UTF-8\n", charset);
- ic = ctdl_iconv_open("UTF-8", charset);
+ ctdl_iconv_open("UTF-8", charset, &ic);
if (ic == (iconv_t)(-1) ) {
lprintf(5, "%s:%d iconv_open() failed: %s\n",
__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);
+ msg = (char*)ChrPtr(Source); //TODO: get rid of this.
+ }
}
+
#endif
/**
* terminated now.
*/
- /** Now go through the message, parsing tags as necessary. */
- converted_msg = NewStrBufPlain(NULL, content_length + 8192);
if (converted_msg == NULL) {
- wprintf("Error %d: %s<br />%s:%d", errno, strerror(errno), __FILE__, __LINE__);
+ StrBufAppendPrintf(Target, "Error %d: %s<br />%s:%d", errno, strerror(errno), __FILE__, __LINE__);
goto BAIL;
}
/** output_length = content_length; */
/** Output our big pile of markup */
- StrBufAppendBuf(WC->WBuf, converted_msg, 0);
+ StrBufAppendBuf(Target, converted_msg, 0);
BAIL: /** A little trailing vertical whitespace... */
- wprintf("<br /><br />\n");
+ StrBufAppendPrintf(Target, "<br /><br />\n");
/** Now give back the memory */
- if (converted_msg != NULL) free(converted_msg);
- if (msg != NULL) free(msg);
+ FreeStrBuf(&converted_msg);
+ if ((msg != NULL) && (Source == NULL)) free(msg);
}
/*@}*/