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) {
40 int buffer_length = 1;
42 int content_length = 0;
46 while (serv_gets(buf), strcmp(buf, "000")) {
47 line_length = strlen(buf);
48 buffer_length = content_length + line_length + 2;
49 msg = realloc(msg, buffer_length);
51 wprintf("<B>realloc() error! "
52 "couldn't get %d bytes: %s</B><BR><BR>\n",
57 strcpy(&msg[content_length], buf);
58 content_length += line_length;
59 strcpy(&msg[content_length], "\n");
65 msgend = &msg[content_length];
67 while (ptr < msgend) {
69 /* Advance to next tag */
70 ptr = strchr(ptr, '<');
71 if ((ptr == NULL) || (ptr >= msgend)) break;
73 if ((ptr == NULL) || (ptr >= msgend)) break;
75 /* Any of these tags cause everything up to and including
76 * the tag to be removed.
78 if ( (!strncasecmp(ptr, "HTML", 4))
79 ||(!strncasecmp(ptr, "HEAD", 4))
80 ||(!strncasecmp(ptr, "/HEAD", 5))
81 ||(!strncasecmp(ptr, "BODY", 4)) ) {
82 ptr = strchr(ptr, '>');
83 if ((ptr == NULL) || (ptr >= msgend)) break;
85 if ((ptr == NULL) || (ptr >= msgend)) break;
89 /* Any of these tags cause everything including and following
90 * the tag to be removed.
92 if ( (!strncasecmp(ptr, "/HTML", 5))
93 ||(!strncasecmp(ptr, "/BODY", 5)) ) {
103 write(WC->http_sock, msgstart, strlen(msgstart));
105 /* A little trailing vertical whitespace... */
106 wprintf("<BR><BR>\n");
108 /* Now give back the memory */