From f923045e1b4d66c66453b2f4f30ebd7f4ed6cef5 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 16 Jul 2002 03:23:37 +0000 Subject: [PATCH] * Display HTML messages as HTML. (Wow!) --- webcit/ChangeLog | 4 +++ webcit/Makefile.in | 4 +-- webcit/html2html.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++ webcit/messages.c | 10 +++++- webcit/webcit.h | 1 + 5 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 webcit/html2html.c diff --git a/webcit/ChangeLog b/webcit/ChangeLog index 2698e1797..f5121cbf4 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -1,4 +1,7 @@ $Log$ +Revision 323.47 2002/07/16 03:23:37 ajc +* Display HTML messages as HTML. (Wow!) + Revision 323.46 2002/07/13 04:39:59 ajc * Handle multipart/alternative in a nicer way, giving us the opportunity to output HTML instead of converting to text/plain and back. (Not finished.) @@ -862,3 +865,4 @@ Sun Dec 6 19:50:55 EST 1998 Art Cancro 1998-12-03 Nathan Bryant * webserver.c: warning fix + diff --git a/webcit/Makefile.in b/webcit/Makefile.in index beb446a2b..2e4883312 100644 --- a/webcit/Makefile.in +++ b/webcit/Makefile.in @@ -26,13 +26,13 @@ webserver: webserver.o context_loop.o tools.o \ cookie_conversion.o locate_host.o \ webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o \ roomops.o messages.o userlist.o paging.o sysmsgs.o useredit.o \ - vcard.o vcard_edit.o preferences.o \ + vcard.o vcard_edit.o preferences.o html2html.o \ mime_parser.o graphics.o netconf.o siteconfig.o subst.o $(LIBOBJS) $(CC) webserver.o context_loop.o tools.o cookie_conversion.o \ webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o \ roomops.o messages.o userlist.o paging.o sysmsgs.o useredit.o \ locate_host.o siteconfig.o subst.o vcard.o vcard_edit.o \ - mime_parser.o graphics.o netconf.o preferences.o \ + mime_parser.o graphics.o netconf.o preferences.o html2html.o \ $(LIBOBJS) $(LIBS) -o webserver strip webserver diff --git a/webcit/html2html.c b/webcit/html2html.c new file mode 100644 index 000000000..fb7790530 --- /dev/null +++ b/webcit/html2html.c @@ -0,0 +1,78 @@ +/* + * $Id$ + * + * Output an HTML message, modifying it slightly to make sure it plays nice + * with the rest of our web framework. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "webcit.h" +#include "vcard.h" + + +/* + * Here we go. Please note that the buffer may be changed by this function! + */ +void output_text_html(char *partbuf, int total_length) { + + char *ptr; + char *msgstart; + char *msgend; + + ptr = partbuf; + msgstart = partbuf; + msgend = &partbuf[total_length]; + + while (ptr < msgend) { + + /* Advance to next tag */ + ptr = strchr(ptr, '<'); + ++ptr; + + /* Any of these tags cause everything up to and including + * the tag to be removed. + */ + if ( (!strncasecmp(ptr, "HTML", 4)) + ||(!strncasecmp(ptr, "HEAD", 4)) + ||(!strncasecmp(ptr, "/HEAD", 5)) + ||(!strncasecmp(ptr, "BODY", 4)) ) { + ptr = strchr(ptr, '>'); + ++ptr; + msgstart = ptr; + } + + /* Any of these tags cause everything including and following + * the tag to be removed. + */ + if ( (!strncasecmp(ptr, "/HTML", 5)) + ||(!strncasecmp(ptr, "/BODY", 5)) ) { + --ptr; + msgend = ptr; + strcpy(ptr, ""); + + } + + ++ptr; + } + + write(WC->http_sock, msgstart, strlen(msgstart)); +} + diff --git a/webcit/messages.c b/webcit/messages.c index 1ffad7c36..8e7c1237f 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -235,12 +235,17 @@ void output_chosen_part(long msgnum, char *multipart_chosen) { strcpy(content_type, "text/plain"); } - partbuf = malloc(total_length); + partbuf = malloc(total_length + 1); if (partbuf == NULL) { wprintf("Memory allocation error

"); return; } + partbuf[total_length] = 0; /* Give it a nice null terminator */ + + /* FIXME ... add something to make this die if we + * lose the server connection. + */ while (downloaded_length < total_length) { if ((total_length - downloaded_length) < 4096) { block_length = total_length - downloaded_length; @@ -263,6 +268,9 @@ void output_chosen_part(long msgnum, char *multipart_chosen) { if (!strcasecmp(content_type, "text/plain")) { output_text_plain(partbuf, total_length); } + if (!strcasecmp(content_type, "text/html")) { + output_text_html(partbuf, total_length); + } else { wprintf("Unknown content type %s

\n", content_type); diff --git a/webcit/webcit.h b/webcit/webcit.h index b6ac6a376..7ca0b51c8 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -314,3 +314,4 @@ char *safestrncpy(char *dest, const char *src, size_t n); void display_addressbook(long msgnum, char alpha); void offer_start_page(void); void change_start_page(void); +void output_text_html(char *partbuf, int total_length); -- 2.30.2