4 * Output an HTML message, modifying it slightly to make sure it plays nice
5 * with the rest of our web framework.
15 #include <sys/types.h>
17 #include <sys/socket.h>
19 #include <netinet/in.h>
29 #include "webserver.h"
34 void output_html(void) {
47 while (serv_gets(buf), strcmp(buf, "000")) {
48 line_length = strlen(buf);
49 total_length = total_length + line_length + 1;
50 msg = realloc(msg, total_length + 1);
52 msgend[line_length++] = '\n' ;
53 msgend[line_length] = 0;
54 msgend = &msgend[line_length];
59 /* msgend is already set correctly */
61 while (ptr < msgend) {
63 /* Advance to next tag */
64 ptr = strchr(ptr, '<');
66 if ((ptr == NULL) || (ptr >= msgend)) break;
68 /* Any of these tags cause everything up to and including
69 * the tag to be removed.
71 if ( (!strncasecmp(ptr, "HTML", 4))
72 ||(!strncasecmp(ptr, "HEAD", 4))
73 ||(!strncasecmp(ptr, "/HEAD", 5))
74 ||(!strncasecmp(ptr, "BODY", 4)) ) {
75 ptr = strchr(ptr, '>');
76 if ((ptr == NULL) || (ptr >= msgend)) break;
78 if ((ptr == NULL) || (ptr >= msgend)) break;
82 /* Any of these tags cause everything including and following
83 * the tag to be removed.
85 if ( (!strncasecmp(ptr, "/HTML", 5))
86 ||(!strncasecmp(ptr, "/BODY", 5)) ) {
96 write(WC->http_sock, msgstart, strlen(msgstart));
98 /* A little trailing vertical whitespace... */
99 wprintf("<BR><BR>\n");
101 /* Now give back the memory */