#include <signal.h>
#include "webcit.h"
#include "vcard.h"
+#include "webserver.h"
/*
- * Here we go. Please note that the buffer may be changed by this function!
*/
-void output_text_html(char *partbuf, int total_length) {
-
+void output_html(void) {
+ char buf[SIZ];
+ char *msg;
char *ptr;
char *msgstart;
char *msgend;
+ int buffer_length = 1;
+ int line_length = 0;
+ int content_length = 0;
+
+ msg = strdup("");
+
+ while (serv_gets(buf), strcmp(buf, "000")) {
+ line_length = strlen(buf);
+ buffer_length = content_length + line_length + 2;
+ msg = realloc(msg, buffer_length);
+ if (msg == NULL) {
+ wprintf("<B>realloc() error! "
+ "couldn't get %d bytes: %s</B><BR><BR>\n",
+ buffer_length + 1,
+ strerror(errno));
+ return;
+ }
+ strcpy(&msg[content_length], buf);
+ content_length += line_length;
+ strcpy(&msg[content_length], "\n");
+ content_length += 1;
+ }
- ptr = partbuf;
- msgstart = partbuf;
- msgend = &partbuf[total_length];
+ ptr = msg;
+ msgstart = msg;
+ msgend = &msg[content_length];
while (ptr < msgend) {
/* Advance to next tag */
ptr = strchr(ptr, '<');
+ if ((ptr == NULL) || (ptr >= msgend)) break;
++ptr;
+ if ((ptr == NULL) || (ptr >= msgend)) break;
/* Any of these tags cause everything up to and including
* the tag to be removed.
||(!strncasecmp(ptr, "/HEAD", 5))
||(!strncasecmp(ptr, "BODY", 4)) ) {
ptr = strchr(ptr, '>');
+ if ((ptr == NULL) || (ptr >= msgend)) break;
++ptr;
+ if ((ptr == NULL) || (ptr >= msgend)) break;
msgstart = ptr;
}
}
write(WC->http_sock, msgstart, strlen(msgstart));
+
+ /* A little trailing vertical whitespace... */
+ wprintf("<BR><BR>\n");
+
+ /* Now give back the memory */
+ free(msg);
+
}