vsprintf(wbuf, format, arg_ptr);
va_end(arg_ptr);
- write(WC->http_sock, wbuf, strlen(wbuf));
+ client_write(wbuf, strlen(wbuf));
}
* Copy a string, escaping characters which have meaning in HTML. If
* nbsp is nonzero, spaces are converted to non-breaking spaces.
*/
-void stresc(char *target, char *strbuf, int nbsp)
+void stresc(char *target, char *strbuf, int nbsp, int nolinebreaks)
{
int a;
strcpy(target, "");
strcat(target, ">");
else if (strbuf[a] == QU)
strcat(target, "\"");
- else if ((strbuf[a] == 32) && (nbsp == 1)) {
+ else if ((strbuf[a] == 32) && (nbsp == 1))
strcat(target, " ");
- } else {
+ else if ((strbuf[a] == '\n') && (nolinebreaks))
+ strcat(target, ""); /* nothing */
+ else if ((strbuf[a] == '\r') && (nolinebreaks))
+ strcat(target, ""); /* nothing */
+ else
strncat(target, &strbuf[a], 1);
- }
}
}
-void escputs1(char *strbuf, int nbsp)
+void escputs1(char *strbuf, int nbsp, int nolinebreaks)
{
- char buf[1024];
- stresc(buf, strbuf, nbsp);
+ char *buf;
+
+ if (strbuf == NULL) return;
+ buf = malloc(2 * strlen(strbuf));
+ stresc(buf, strbuf, nbsp, nolinebreaks);
wprintf("%s", buf);
+ free(buf);
}
void escputs(char *strbuf)
{
- escputs1(strbuf, 0);
+ escputs1(strbuf, 0, 0);
}
/*
}
+/*
+ * Copy a string, escaping characters for JavaScript strings.
+ */
+void jsesc(char *target, char *strbuf)
+{
+ int a;
+ strcpy(target, "");
+
+ for (a = 0; a < strlen(strbuf); ++a) {
+ if (strbuf[a] == '<')
+ strcat(target, "[");
+ else if (strbuf[a] == '>')
+ strcat(target, "]");
+ else if (strbuf[a] == '\"')
+ strcat(target, """);
+ else if (strbuf[a] == '&')
+ strcat(target, "&;");
+ else if (strbuf[a] == '\'')
+ strcat(target, "\\'");
+ else {
+ strncat(target, &strbuf[a], 1);
+ }
+ }
+}
+
+void jsescputs(char *strbuf)
+{
+ char outbuf[SIZ];
+
+ jsesc(outbuf, strbuf);
+ wprintf("%s", outbuf);
+}
+
+/*
+ * Copy a string, escaping characters for message text hold
+ */
+void msgesc(char *target, char *strbuf)
+{
+ int a;
+ strcpy(target, "");
+
+ for (a = 0; a < strlen(strbuf); ++a) {
+ if (strbuf[a] == '\'')
+ strcat(target, "\\'");
+ else if (strbuf[a] == '\n')
+ strcat(target, " ");
+ else if (strbuf[a] == '\r')
+ strcat(target, " ");
+ else {
+ strncat(target, &strbuf[a], 1);
+ }
+ }
+}
+
+void msgescputs(char *strbuf) {
+ char *outbuf;
+
+ if (strbuf == NULL) return;
+ outbuf = malloc(2 * strlen(strbuf));
+ msgesc(outbuf, strbuf);
+ wprintf("%s", outbuf);
+ free(outbuf);
+}
+
+
/*
(long) length,
SERVER
);
- write(WC->http_sock, thing, (size_t)length);
+ client_write(thing, (size_t)length);
}
strcpy(content_type, "image/jpeg");
else if (!strncasecmp(&what[strlen(what) - 4], ".png", 4))
strcpy(content_type, "image/png");
+ else if (!strncasecmp(&what[strlen(what) - 4], ".ico", 4))
+ strcpy(content_type, "image/x-icon");
else if (!strncasecmp(&what[strlen(what) - 5], ".html", 5))
strcpy(content_type, "text/html");
+ else if (!strncasecmp(&what[strlen(what) - 4], ".htm", 4))
+ strcpy(content_type, "text/html");
else if (!strncasecmp(&what[strlen(what) - 4], ".wml", 4))
strcpy(content_type, "text/vnd.wap.wml");
else if (!strncasecmp(&what[strlen(what) - 5], ".wmls", 5))
else if (!strncasecmp(&what[strlen(what) - 6], ".wmlsc", 6))
strcpy(content_type, "application/vnd.wap.wmlscriptc");
else if (!strncasecmp(&what[strlen(what) - 5], ".wbmp", 5))
- wprintf("Content-type: image/vnd.wap.wbmp");
+ strcpy(content_type, "image/vnd.wap.wbmp");
+ else if (!strncasecmp(&what[strlen(what) - 3], ".js", 3))
+ strcpy(content_type, "text/javascript");
else
- wprintf("Content-type: application/octet-stream");
+ strcpy(content_type, "application/octet-stream");
fstat(fileno(fp), &statbuf);
bytes = statbuf.st_size;
char buf[SIZ];
int a, b;
int ContentLength = 0;
- int BytesRead;
+ int BytesRead = 0;
char ContentType[512];
char *content;
char *content_end;
ContentType, ContentLength);
body_start = strlen(content);
+/***** old version
BytesRead = 0;
while (BytesRead < ContentLength) {
a=read(WC->http_sock, &content[BytesRead+body_start],
if (a <= 0) BytesRead = ContentLength;
else BytesRead += a;
}
+*******/
+
+ /* Now we're daring and read it all at once. */
+ client_read(WC->http_sock, &content[BytesRead+body_start], ContentLength);
if (!strncasecmp(ContentType,
"application/x-www-form-urlencoded", 33)) {
edit_me();
} else if (!strcasecmp(action, "display_siteconfig")) {
display_siteconfig();
+ } else if (!strcasecmp(action, "chat_recv")) {
+ chat_recv();
+ } else if (!strcasecmp(action, "chat_send")) {
+ chat_send();
} else if (!strcasecmp(action, "page_popup")) {
page_popup();
} else if (!strcasecmp(action, "siteconfig")) {
} else if (!strcasecmp(action, "select_user_to_edit")) {
select_user_to_edit(NULL, NULL);
} else if (!strcasecmp(action, "display_edituser")) {
- display_edituser(NULL);
+ display_edituser(NULL, 0);
} else if (!strcasecmp(action, "edituser")) {
edituser();
} else if (!strcasecmp(action, "create_user")) {
display_customize_iconbar();
} else if (!strcasecmp(action, "commit_iconbar")) {
commit_iconbar();
+ } else if (!strcasecmp(action, "set_room_policy")) {
+ set_room_policy();
+ } else if (!strcasecmp(action, "display_inetconf")) {
+ display_inetconf();
+ } else if (!strcasecmp(action, "save_inetconf")) {
+ save_inetconf();
} else if (!strcasecmp(action, "diagnostics")) {
output_headers(1);