for (a = 0; a <= b; ++a)
++up;
- /* locate the & sign */
+ /* locate "&" and "?" delimiters */
ptr = up;
b = strlen(up);
for (a = 0; a < strlen(up); ++a) {
- if (!strncmp(ptr, "&", 1)) {
+ if ( (ptr[0] == '&') || (ptr[0] == '?') ) {
b = a;
break;
}
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 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);
+}
+
+
/*
* 3 = HTTP and HTML headers, but no room banner
*
* Bit 2: Set to 1 to auto-refresh page every 30 seconds
- *
* Bit 3: suppress check for express messages
+ * Bit 4: Allow browser to cache this document
+ *
*/
void output_headers(int controlcode)
{
int print_standard_html_head = 0;
int refresh30 = 0;
int suppress_check = 0;
+ int cache = 0;
char httpnow[SIZ];
+ char onload_fcn[SIZ];
static int pageseq = 0;
print_standard_html_head = controlcode & 0x03;
refresh30 = ((controlcode & 0x04) >> 2);
suppress_check = ((controlcode & 0x08) >> 3);
+ cache = ((controlcode & 0x10) >> 4);
wprintf("HTTP/1.0 200 OK\n");
wprintf("Content-type: text/html\n"
"Server: %s\n", SERVER
);
- wprintf("Connection: close\n"
- "Pragma: no-cache\n"
- "Cache-Control: no-store\n"
- );
+ if (!cache)
+ wprintf("Connection: close\n"
+ "Pragma: no-cache\n"
+ "Cache-Control: no-store\n"
+ );
}
+
stuff_to_cookie(cookie, WC->wc_session, WC->wc_username,
WC->wc_password, WC->wc_roomname);
+
if (print_standard_html_head == 2) {
wprintf("Set-cookie: webcit=%s\n", unset);
} else {
else svprintf("REFRESHTAG", WCS_STRING,
"<META HTTP-EQUIV=\"refresh\" CONTENT=\"500363689;\">\n");
/* script for checking for pages (not always launched) */
+
+ sprintf(onload_fcn, "function onload_fcn() { \n");
+ if (!WC->outside_frameset_allowed) {
+ strcat(onload_fcn, " force_frameset(); \n");
+ }
+ if (!suppress_check) if (WC->HaveExpressMessages) {
+ strcat(onload_fcn, " launch_page_popup(); \n");
+ WC->HaveExpressMessages = 0;
+ }
+ strcat(onload_fcn, "} \n");
+
svprintf("PAGERSCRIPT", WCS_STRING,
"<SCRIPT LANGUAGE=\"JavaScript\">\n"
"function launch_page_popup() {\n"
"'toolbar=no,location=no,copyhistory=no,status=no,"
"scrollbars=yes,resizable=no,height=250,width=400');\n"
"}\n"
+ "function force_frameset() { \n"
+ " if (top.frames.length == 0) { \n"
+ " top.location.replace('/do_welcome'); \n"
+ " } \n"
+ "} \n"
+ "%s\n"
"</SCRIPT>\n",
- ++pageseq
+ ++pageseq,
+ onload_fcn
);
/* end script */
+
do_template("head");
clear_local_substs();
- if (!suppress_check) if (WC->HaveExpressMessages) {
- svprintf("extrabodyparms", WCS_STRING, "%s",
- "onload=\"launch_page_popup()\" ");
- WC->HaveExpressMessages = 0;
- }
+ svprintf("extrabodyparms", WCS_STRING, "%s",
+ "onload='onload_fcn();' ");
do_template("background");
clear_local_substs();
+ }
if (print_standard_html_head == 1) {
wprintf("<A NAME=\"TheTop\"></A>");
-
embed_room_banner(NULL);
-
- }
}
+
+ if (strlen(WC->ImportantMessage) > 0) {
+ do_template("beginbox_nt");
+ wprintf("<SPAN CLASS=\"errormsg\">"
+ "%s</SPAN><BR>\n", WC->ImportantMessage);
+ do_template("endbox");
+ strcpy(WC->ImportantMessage, "");
+ }
}
/*
* Output a piece of content to the web browser
*/
-void http_transmit_thing(char *thing, size_t length, char *content_type) {
- output_headers(0);
+void http_transmit_thing(char *thing, size_t length, char *content_type,
+ int is_static) {
+ output_headers(is_static ? 0x10 : 0x00);
wprintf("Content-type: %s\n"
"Content-length: %ld\n"
"Server: %s\n"
(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], ".wml", 4))
fread(bigbuffer, bytes, 1, fp);
fclose(fp);
- http_transmit_thing(bigbuffer, (size_t)bytes, content_type);
+ http_transmit_thing(bigbuffer, (size_t)bytes, content_type, 1);
free(bigbuffer);
}
if (!strcasecmp(bstr("force_close_session"), "yes")) {
serv_gets(buf);
/* Write it to the browser */
- http_transmit_thing(xferbuf, (size_t)bytes, "image/gif");
+ http_transmit_thing(xferbuf, (size_t)bytes, "image/gif", 0);
free(xferbuf);
} else {
read_server_binary(content, bytes);
serv_puts("CLOS");
serv_gets(buf);
- http_transmit_thing(content, bytes, content_type);
+ http_transmit_thing(content, bytes, content_type, 0);
free(content);
} else {
wprintf("HTTP/1.0 404 %s\n", &buf[4]);
}
+/*
+ * A template has been requested
+ */
+void url_do_template(void) {
+ do_template(bstr("template"));
+}
+
/*
void change_start_page(void) {
if (bstr("startpage") == NULL) {
- display_error("startpage set to null");
+ strcpy(WC->ImportantMessage,
+ "startpage set to null");
+ display_main_menu();
return;
}
-void display_error(char *errormessage)
-{
- convenience_page("770000", "Error", errormessage);
-}
-
void display_success(char *successmessage)
{
convenience_page("007700", "OK", successmessage);
{
struct urlcontent *u;
- lprintf(5, "UPLOAD HANDLER CALLED\n");
- lprintf(5, " name = %s\n", name);
- lprintf(5, " filename = %s\n", filename);
- lprintf(5, " encoding = %s\n", encoding);
- lprintf(5, " type = %s\n", cbtype);
- lprintf(5, " length = %ld\n", (long)length);
- lprintf(5, "disposition = %s\n", disp);
-
/* Form fields */
if ( (length > 0) && (strlen(cbtype) == 0) ) {
u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
memcpy(WC->upload, content, length);
}
else {
- lprintf(9, "malloc() failed: %s\n",
- strerror(errno));
+ lprintf(3, "malloc() failed: %s\n", strerror(errno));
}
}
char buf[SIZ];
int a, b;
int ContentLength = 0;
- int BytesRead;
+ int BytesRead = 0;
char ContentType[512];
char *content;
char *content_end;
}
if (ContentLength > 0) {
- lprintf(5, "Content length: %d\n", ContentLength);
content = malloc(ContentLength + SIZ);
memset(content, 0, ContentLength + SIZ);
sprintf(content, "Content-type: %s\n"
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)) {
addurls(&content[body_start]);
} else if (!strncasecmp(ContentType, "multipart", 9)) {
- content_end = content + ContentLength;
+ content_end = content + ContentLength + body_start;
mime_parser(content, content_end, *upload_handler,
NULL, NULL, NULL, 0);
}
}
}
+ /* Static content can be sent without connecting to Citadel. */
+ if (!strcasecmp(action, "static")) {
+ strcpy(buf, &cmd[12]);
+ for (a = 0; a < strlen(buf); ++a)
+ if (isspace(buf[a]))
+ buf[a] = 0;
+ output_static(buf);
+ goto SKIP_ALL_THIS_CRAP; /* Don't try to connect */
+ }
+
/*
* If we're not connected to a Citadel server, try to hook up the
* connection now.
do_listsub();
goto SKIP_ALL_THIS_CRAP;
}
+#ifdef WEBCIT_WITH_CALENDAR_SERVICE
+ if (!strcasecmp(action, "freebusy")) {
+ do_freebusy(cmd);
+ goto SKIP_ALL_THIS_CRAP;
+ }
+#endif
check_for_express_messages();
strcpy(WC->wc_roomname, c_roomname);
}
}
- if (!strcasecmp(action, "static")) {
- strcpy(buf, &cmd[12]);
- for (a = 0; a < strlen(buf); ++a)
- if (isspace(buf[a]))
- buf[a] = 0;
- output_static(buf);
- } else if (!strcasecmp(action, "image")) {
+
+ if (!strcasecmp(action, "image")) {
output_image();
/*
do_welcome();
} else if (!strcasecmp(action, "blank")) {
blank_page();
+ } else if (!strcasecmp(action, "do_template")) {
+ url_do_template();
} else if (!strcasecmp(action, "display_main_menu")) {
display_main_menu();
} else if (!strcasecmp(action, "whobbs")) {
} else if (!strcasecmp(action, "display_whok")) {
display_whok();
} else if (!strcasecmp(action, "display_editinfo")) {
- display_edit("Room info", "EINF 0", "RINF", "/editinfo");
+ display_edit("Room info", "EINF 0", "RINF", "/editinfo", 1);
} else if (!strcasecmp(action, "editinfo")) {
save_edit("Room info", "EINF 1", 1);
} else if (!strcasecmp(action, "display_editbio")) {
sprintf(buf, "RBIO %s", WC->wc_username);
- display_edit("Your bio", "NOOP", buf, "editbio");
+ display_edit("Your bio", "NOOP", buf, "editbio", 3);
} else if (!strcasecmp(action, "editbio")) {
save_edit("Your bio", "EBIO", 0);
} else if (!strcasecmp(action, "confirm_delete_room")) {
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")) {
create_user();
} else if (!strcasecmp(action, "changeview")) {
change_view();
- } else if (!strcasecmp(action, "folders")) {
- folders();
} else if (!strcasecmp(action, "do_stuff_to_msgs")) {
do_stuff_to_msgs();
} else if (!strcasecmp(action, "change_start_page")) {
#endif
} else if (!strcasecmp(action, "summary")) {
summary();
+ } else if (!strcasecmp(action, "iconbar")) {
+ do_iconbar();
+ } else if (!strcasecmp(action, "display_customize_iconbar")) {
+ display_customize_iconbar();
+ } else if (!strcasecmp(action, "commit_iconbar")) {
+ commit_iconbar();
} else if (!strcasecmp(action, "diagnostics")) {
output_headers(1);