#include <pthread.h>
#include <signal.h>
#include "webcit.h"
+#include "webserver.h"
#include "mime_parser.h"
/*
while (strlen(up) > 0) {
/* locate the = sign */
- strncpy(buf, up, 255);
+ safestrncpy(buf, up, sizeof buf);
b = (-1);
for (a = 255; a >= 0; --a)
if (buf[a] == '=')
}
+#ifdef WITH_ZLIB
+
+ssize_t http_write(int fd, const void *buf, size_t count) {
+
+ if (WC->gzfd) {
+ return gzwrite(WC->gzfd, buf, count);
+ }
+ else {
+ return write(fd, buf, count);
+ }
+
+
+}
+
+#else
+
+ssize_t http_write(int fd, const void *buf, size_t count) {
+ return write(fd, buf, count);
+}
+
+#endif
+
+
+
+
void wprintf(const char *format,...)
{
va_list arg_ptr;
vsprintf(wbuf, format, arg_ptr);
va_end(arg_ptr);
- write(WC->http_sock, wbuf, strlen(wbuf));
+ http_write(WC->http_sock, wbuf, strlen(wbuf));
}
/*
* Escape a string for feeding out as a URL.
- * FIXME this is not threadsafe!
+ * Returns a pointer to a buffer that must be freed by the caller!
*/
-char *urlesc(char *strbuf)
+void urlesc(char *outbuf, char *strbuf)
{
int a, b, c;
char *ec = " #&;`'|*?-~<>^()[]{}$\\";
- static char outbuf[1024];
strcpy(outbuf, "");
else
sprintf(&outbuf[b], "%c", strbuf[a]);
}
- return (outbuf);
}
void urlescputs(char *strbuf)
{
- wprintf("%s", urlesc(strbuf));
+ char outbuf[SIZ];
+
+ urlesc(outbuf, strbuf);
+ wprintf("%s", outbuf);
}
int suppress_check = 0;
char httpnow[SIZ];
static int pageseq = 0;
+#ifdef WITH_ZLIB
+ gzFile temp_gzfd = NULL;
+#endif
print_standard_html_head = controlcode & 0x03;
refresh30 = ((controlcode & 0x04) >> 2);
httpdate(httpnow, time(NULL));
+#ifdef WITH_ZLIB
+ if (WC->gzcompressed) {
+ temp_gzfd = gzdopen(WC->http_sock, "wb9");
+ }
+#endif
+
if (print_standard_html_head > 0) {
wprintf("Content-type: text/html\n");
wprintf("Server: %s\n", SERVER);
wprintf("Connection: close\n");
wprintf("Pragma: no-cache\n");
wprintf("Cache-Control: no-store\n");
+#ifdef WITH_ZLIB
+ if (temp_gzfd != NULL) {
+ wprintf("Content-Encoding: gzip\n");
+ }
+#endif
}
stuff_to_cookie(cookie, WC->wc_session, WC->wc_username,
WC->wc_password, WC->wc_roomname);
if (print_standard_html_head > 0) {
wprintf("\n");
+
+#ifdef WITH_ZLIB
+ if (temp_gzfd != NULL) {
+ WC->gzfd = temp_gzfd;
+ }
+#endif
+
wprintf("<HTML><HEAD><TITLE>");
escputs(serv_info.serv_humannode);
wprintf("</TITLE>\n"
wprintf("function launch_page_popup() {\n");
wprintf("pwin = window.open('/page_popup', 'CitaPage%d', "
"'toolbar=no,location=no,copyhistory=no,status=no,"
- "scrollbars=yes,resizable=no,height=150,width=400');\n",
+ "scrollbars=yes,resizable=no,height=250,width=400');\n",
++pageseq);
wprintf("}\n");
wprintf("</SCRIPT>\n");
"onload=\"launch_page_popup()\" ");
WC->HaveExpressMessages = 0;
}
- do_template("background.html");
+ do_template("background");
clear_local_substs();
if (print_standard_html_head == 1) {
wprintf("Content-type: image/gif\n");
else if (!strncasecmp(&what[strlen(what) - 4], ".txt", 4))
wprintf("Content-type: text/plain\n");
+ else if (!strncasecmp(&what[strlen(what) - 4], ".css", 4))
+ wprintf("Content-type: text/css\n");
else if (!strncasecmp(&what[strlen(what) - 4], ".jpg", 4))
wprintf("Content-type: image/jpeg\n");
+ else if (!strncasecmp(&what[strlen(what) - 4], ".png", 4))
+ wprintf("Content-type: image/png\n");
else if (!strncasecmp(&what[strlen(what) - 5], ".html", 5))
wprintf("Content-type: text/html\n");
+ else if (!strncasecmp(&what[strlen(what) - 4], ".wml", 4))
+ wprintf("Content-type: text/vnd.wap.wml\n");
+ else if (!strncasecmp(&what[strlen(what) - 5], ".wmls", 5))
+ wprintf("Content-type: text/vnd.wap.wmlscript\n");
+ else if (!strncasecmp(&what[strlen(what) - 5], ".wmlc", 5))
+ wprintf("Content-type: application/vnd.wap.wmlc\n");
+ else if (!strncasecmp(&what[strlen(what) - 6], ".wmlsc", 6))
+ wprintf("Content-type: application/vnd.wap.wmlscriptc\n");
+ else if (!strncasecmp(&what[strlen(what) - 5], ".wbmp", 5))
+ wprintf("Content-type: image/vnd.wap.wbmp\n");
else
wprintf("Content-type: application/octet-stream\n");
fstat(fileno(fp), &statbuf);
bytes = statbuf.st_size;
- fprintf(stderr, "Static: %s, %ld bytes\n", what, bytes);
+ lprintf(3, "Static: %s, %ld bytes\n", what, bytes);
wprintf("Content-length: %ld\n", (long) bytes);
wprintf("\n");
bigbuffer = malloc(bytes);
fread(bigbuffer, bytes, 1, fp);
fclose(fp);
- write(WC->http_sock, bigbuffer, bytes);
+ http_write(WC->http_sock, bigbuffer, bytes);
free(bigbuffer);
}
if (!strcasecmp(bstr("force_close_session"), "yes")) {
off_t thisblock;
off_t accomplished = 0L;
-
+ lprintf(5, "output_image() called\n");
serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
serv_gets(buf);
if (buf[0] == '2') {
else {
memset(xferbuf, 0, thisblock);
}
- write(WC->http_sock, xferbuf, thisblock);
+ http_write(WC->http_sock, xferbuf, thisblock);
bytes = bytes - thisblock;
accomplished = accomplished + thisblock;
}
else {
memset(xferbuf, 0, thisblock);
}
- write(WC->http_sock, xferbuf, thisblock);
+ http_write(WC->http_sock, xferbuf, thisblock);
bytes = bytes - thisblock;
accomplished = accomplished + thisblock;
}
}
+/*
+ */
+char *load_mimepart(long msgnum, char *partnum)
+{
+ char buf[SIZ];
+ off_t bytes;
+ off_t thisblock;
+ off_t accomplished = 0L;
+ char content_type[SIZ];
+ char *content;
+
+ serv_printf("OPNA %ld|%s", msgnum, partnum);
+ serv_gets(buf);
+ if (buf[0] == '2') {
+ bytes = extract_long(&buf[4], 0);
+ extract(content_type, &buf[4], 3);
+
+ content = malloc(bytes + 1);
+
+ while (bytes > (off_t) 0) {
+ thisblock = bytes;
+ if (thisblock > 4096L) {
+ thisblock = 4096L;
+ }
+ if (thisblock > bytes) {
+ thisblock = bytes;
+ }
+ serv_printf("READ %ld|%ld", accomplished, thisblock);
+ serv_gets(buf);
+ if (buf[0] == '6') {
+ thisblock = extract_long(&buf[4], 0);
+ serv_read(&content[accomplished], (int) thisblock);
+ }
+ else {
+ memset(&content[accomplished], 0, thisblock);
+ }
+ bytes = bytes - thisblock;
+ accomplished = accomplished + thisblock;
+ }
+ serv_puts("CLOS");
+ serv_gets(buf);
+ content[accomplished] = 0; /* null terminate for good measure */
+ return(content);
+ }
+ else {
+ return(NULL);
+ }
+
+}
+
+
/*
* Convenience functions to display a page containing only a string
*/
}
+
+
+/*
+ * Offer to make any page the user's "start page."
+ */
+void offer_start_page(void) {
+ wprintf("<A HREF=\"/change_start_page?startpage=");
+ urlescputs(WC->this_page);
+ wprintf("\">"
+ "<FONT SIZE=-2 COLOR=#AAAAAA>Make this my start page</FONT>"
+ "</A>"
+ );
+}
+
+
+/*
+ * Change the user's start page
+ */
+void change_start_page(void) {
+
+ if (bstr("startpage") == NULL) {
+ display_error("startpage set to null");
+ return;
+ }
+
+ set_preference("startpage", bstr("startpage"));
+
+ output_headers(3);
+ wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>");
+ wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
+ wprintf("<B>New start page</B>\n");
+ wprintf("</FONT></TD></TR></TABLE>\n");
+
+ wprintf("<CENTER>"
+ "<font size=+2>Your start page has been changed.</font>"
+ "<BR><BR>\n"
+ "<I>(Note: this does not change your browser's home page. "
+ "It changes the page you begin on when you log on to ");
+ escputs(serv_info.serv_humannode);
+ wprintf(".)</I><BR><BR>"
+ "<a href = \"javascript:history.back()\">Back...</a>"
+ "</CENTER>");
+
+ wDumpContent(1);
+}
+
+
+
+
void display_error(char *errormessage)
{
convenience_page("770000", "Error", errormessage);
char *encoding, void *userdata)
{
- fprintf(stderr, "UPLOAD HANDLER CALLED\n");
- fprintf(stderr, " name = %s\n", name);
- fprintf(stderr, "filename = %s\n", filename);
- fprintf(stderr, "encoding = %s\n", encoding);
- fprintf(stderr, " type = %s\n", cbtype);
- fprintf(stderr, " length = %ld\n", (long)length);
+ 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);
- if ( (strlen(name) > 0) || (strlen(filename) > 0) ) {
+ if (length > 0) {
WC->upload = malloc(length);
if (WC->upload != NULL) {
WC->upload_length = length;
memcpy(WC->upload, content, length);
}
+ else {
+ lprintf(9, "malloc() failed: %s\n",
+ strerror(errno));
+ }
}
}
+
+
/*
* Entry point for WebCit transaction
*/
-void session_loop(struct httprequest *req)
+void session_loop(struct httprequest *req, int gzip)
{
char cmd[SIZ];
char action[SIZ];
WC->upload_length = 0;
WC->upload = NULL;
+ WC->is_wap = 0;
+
+ if (gzip) {
+ WC->gzcompressed = 1;
+ }
+ else {
+ WC->gzcompressed = 0;
+ }
+
hptr = req;
if (hptr == NULL) return;
ContentLength = atoi(&buf[16]);
}
else if (!strncasecmp(buf, "Content-type: ", 14)) {
- strcpy(ContentType, &buf[14]);
+ safestrncpy(ContentType, &buf[14], sizeof ContentType);
}
else if (!strncasecmp(buf, "User-agent: ", 12)) {
- strcpy(user_agent, &buf[12]);
+ safestrncpy(user_agent, &buf[12], sizeof user_agent);
+ }
+ else if (!strncasecmp(buf, "Host: ", 6)) {
+ safestrncpy(WC->http_host, &buf[6], sizeof WC->http_host);
+ }
+ /* Only WAP gateways explicitly name this content-type */
+ else if (strstr(buf, "text/vnd.wap.wml")) {
+ WC->is_wap = 1;
}
}
if (ContentLength > 0) {
- fprintf(stderr, "Content length: %d\n", ContentLength);
+ lprintf(5, "Content length: %d\n", ContentLength);
content = malloc(ContentLength + 1);
memset(content, 0, ContentLength+1);
BytesRead = 0;
content = NULL;
}
+ /* make a note of where we are in case the user wants to save it */
+ safestrncpy(WC->this_page, cmd, sizeof(WC->this_page));
+ remove_token(WC->this_page, 2, ' ');
+ remove_token(WC->this_page, 0, ' ');
+
/* If there are variables in the URL, we must grab them now */
- for (a = 0; a < strlen(cmd); ++a)
+ for (a = 0; a < strlen(cmd); ++a) {
if ((cmd[a] == '?') || (cmd[a] == '&')) {
for (b = a; b < strlen(cmd); ++b)
if (isspace(cmd[b]))
addurls(&cmd[a + 1]);
cmd[a] = 0;
}
+ }
+
/*
* If we're not connected to a Citadel server, try to hook up the
* connection now. Preference is given to the host and port specified
}
}
+ /*
+ * Functions which can be performed without logging in
+ */
+ if (!strcasecmp(action, "listsub")) {
+ do_listsub();
+ goto SKIP_ALL_THIS_CRAP;
+ }
+
check_for_express_messages();
/*
output_static(buf);
} else if (!strcasecmp(action, "image")) {
output_image();
+
+ /*
+ * All functions handled below this point ... make sure we log in
+ * before doing anything else!
+ */
} else if ((!WC->logged_in) && (!strcasecmp(action, "login"))) {
do_login();
} else if (!WC->logged_in) {
display_login(NULL);
}
- /* Various commands... */
+
+ /*
+ * Various commands...
+ */
else if (!strcasecmp(action, "do_welcome")) {
do_welcome();
} else if (!strcasecmp(action, "whobbs")) {
whobbs();
} else if (!strcasecmp(action, "knrooms")) {
- list_all_rooms_by_floor();
+ knrooms();
} else if (!strcasecmp(action, "gotonext")) {
slrp_highest();
gotonext();
"/editroompic");
} else if (!strcasecmp(action, "editroompic")) {
do_graphics_upload("UIMG 1|_roompic_");
- } else if (!strcasecmp(action, "select_floor_to_edit_pic")) {
- select_floor_to_edit_pic();
+ } else if (!strcasecmp(action, "delete_floor")) {
+ delete_floor();
+ } else if (!strcasecmp(action, "rename_floor")) {
+ rename_floor();
+ } else if (!strcasecmp(action, "create_floor")) {
+ create_floor();
} else if (!strcasecmp(action, "display_editfloorpic")) {
sprintf(buf, "UIMG 0|_floorpic_|%s",
bstr("which_floor"));
display_menubar(1);
} else if (!strcasecmp(action, "output_mimepart")) {
output_mimepart();
+ } else if (!strcasecmp(action, "edit_vcard")) {
+ edit_vcard();
+ } else if (!strcasecmp(action, "submit_vcard")) {
+ submit_vcard();
+ } else if (!strcasecmp(action, "select_user_to_edit")) {
+ select_user_to_edit(NULL, NULL);
+ } else if (!strcasecmp(action, "display_edituser")) {
+ display_edituser(NULL);
+ } 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")) {
+ change_start_page();
+ } else if (!strcasecmp(action, "display_floorconfig")) {
+ display_floorconfig(NULL);
+ } else if (!strcasecmp(action, "toggle_self_service")) {
+ toggle_self_service();
+ } else if (!strcasecmp(action, "summary")) {
+ summary();
} else if (!strcasecmp(action, "diagnostics")) {
output_headers(1);
free(WC->upload);
WC->upload_length = 0;
}
+
+#ifdef WITH_ZLIB
+ if (WC->gzfd) {
+ gzclose(WC->gzfd);
+ WC->gzfd = NULL;
+ WC->gzcompressed = 0;
+ }
+#endif
}