$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.)
1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
* webserver.c: warning fix
+
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
--- /dev/null
+/*
+ * $Id$
+ *
+ * Output an HTML message, modifying it slightly to make sure it plays nice
+ * with the rest of our web framework.
+ *
+ */
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/socket.h>
+#include <limits.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <string.h>
+#include <pwd.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <pthread.h>
+#include <signal.h>
+#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));
+}
+
strcpy(content_type, "text/plain");
}
- partbuf = malloc(total_length);
+ partbuf = malloc(total_length + 1);
if (partbuf == NULL) {
wprintf("<I>Memory allocation error</I><BR><BR>");
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;
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("<I>Unknown content type %s</I><BR><BR>\n",
content_type);
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);