* Display HTML messages as HTML. (Wow!)
authorArt Cancro <ajc@citadel.org>
Tue, 16 Jul 2002 03:23:37 +0000 (03:23 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 16 Jul 2002 03:23:37 +0000 (03:23 +0000)
webcit/ChangeLog
webcit/Makefile.in
webcit/html2html.c [new file with mode: 0644]
webcit/messages.c
webcit/webcit.h

index 2698e17971aae807c328b6b037382195ccadaedb..f5121cbf43424b7516a76acb8cd978c303ac1679 100644 (file)
@@ -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 <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
+
index beb446a2b34c6a2cc4f9476ce361e9ba247fd83c..2e488331287a7a2e7caab2846522ae51aacc3f11 100644 (file)
@@ -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 (file)
index 0000000..fb77905
--- /dev/null
@@ -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 <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));
+}
+
index 1ffad7c36bdce300f1df5f0f3ad84b9420f7e06b..8e7c1237f66107050948d1ad1a044d8facdb15ec 100644 (file)
@@ -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("<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;
@@ -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("<I>Unknown content type %s</I><BR><BR>\n",
                        content_type);
index b6ac6a3765e1c9ca2a3c75dec5e872b5fda08119..7ca0b51c83b97889242640a1b648776424df9c58 100644 (file)
@@ -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);