8fdc8cb38de2840d06bec0d429c4f370cf4e2d07
[citadel.git] / webcit / html2html.c
1 /*
2  * $Id$
3  *
4  * Output an HTML message, modifying it slightly to make sure it plays nice
5  * with the rest of our web framework.
6  *
7  */
8
9 #include <ctype.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <stdio.h>
13 #include <fcntl.h>
14 #include <signal.h>
15 #include <sys/types.h>
16 #include <sys/wait.h>
17 #include <sys/socket.h>
18 #include <limits.h>
19 #include <netinet/in.h>
20 #include <netdb.h>
21 #include <string.h>
22 #include <pwd.h>
23 #include <errno.h>
24 #include <stdarg.h>
25 #include <pthread.h>
26 #include <signal.h>
27 #include "webcit.h"
28 #include "vcard.h"
29
30
31 /*
32  * Here we go.  Please note that the buffer may be changed by this function!
33  */
34 void output_text_html(char *partbuf, int total_length) {
35
36         char *ptr;
37         char *msgstart;
38         char *msgend;
39
40         ptr = partbuf;
41         msgstart = partbuf;
42         msgend = &partbuf[total_length];
43
44         while (ptr < msgend) {
45
46                 /* Advance to next tag */
47                 ptr = strchr(ptr, '<');
48                 ++ptr;
49
50                 /* Any of these tags cause everything up to and including
51                  * the tag to be removed.
52                  */     
53                 if ( (!strncasecmp(ptr, "HTML", 4))
54                    ||(!strncasecmp(ptr, "HEAD", 4))
55                    ||(!strncasecmp(ptr, "/HEAD", 5))
56                    ||(!strncasecmp(ptr, "BODY", 4)) ) {
57                         ptr = strchr(ptr, '>');
58                         ++ptr;
59                         msgstart = ptr;
60                 }
61
62                 /* Any of these tags cause everything including and following
63                  * the tag to be removed.
64                  */
65                 if ( (!strncasecmp(ptr, "/HTML", 5))
66                    ||(!strncasecmp(ptr, "/BODY", 5)) ) {
67                         --ptr;
68                         msgend = ptr;
69                         strcpy(ptr, "");
70                         
71                 }
72
73                 ++ptr;
74         }
75
76         write(WC->http_sock, msgstart, strlen(msgstart));
77
78         /* Close a bunch of tags that might have been opened */
79         wprintf("</I></B></FONT></TD></TR></TABLE></TT></PRE></A><BR>\n");
80 }
81