u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
u->next = WC->urlstrings;
WC->urlstrings = u;
- strcpy(u->url_key, buf);
+ safestrncpy(u->url_key, buf, sizeof u->url_key);
/* now chop that part off */
for (a = 0; a <= b; ++a)
strcpy(ptr, "");
u->url_data = malloc(strlen(up) + 2);
- strcpy(u->url_data, up);
+ safestrncpy(u->url_data, up, strlen(up) + 1);
u->url_data[b] = 0;
unescape_input(u->url_data);
up = ptr;
httpdate(httpnow, time(NULL));
if (do_httpheaders) {
- wprintf("Content-type: text/html\r\n"
+ wprintf("Content-type: text/html; charset=utf-8\r\n"
"Server: %s / %s\n"
"Connection: close\r\n",
SERVER, serv_info.serv_software
"%s</SPAN><br />\n", WC->ImportantMessage);
do_template("endbox");
wprintf("</div>\n");
- strcpy(WC->ImportantMessage, "");
+ safestrncpy(WC->ImportantMessage, "", sizeof WC->ImportantMessage);
}
}
wprintf("HTTP/1.0 302 Moved Temporarily\n");
wprintf("Location: %s\r\n", whichpage);
wprintf("URI: %s\r\n", whichpage);
- wprintf("Content-type: text/html\r\n\r\n");
+ wprintf("Content-type: text/html; charset=utf-8\r\n\r\n");
wprintf("<html><body>\n");
wprintf("you really want to be <A HREF=\"%s\">here</A> now\n",
whichpage);
void output_static(char *what)
{
- char buf[4096];
+ char buf[256];
FILE *fp;
struct stat statbuf;
off_t bytes;
char *bigbuffer;
- char content_type[SIZ];
+ char content_type[128];
sprintf(buf, "static/%s", what);
fp = fopen(buf, "rb");
wprintf("Cannot open %s: %s\n", what, strerror(errno));
} else {
if (!strncasecmp(&what[strlen(what) - 4], ".gif", 4))
- strcpy(content_type, "image/gif");
+ safestrncpy(content_type, "image/gif", sizeof content_type);
else if (!strncasecmp(&what[strlen(what) - 4], ".txt", 4))
- strcpy(content_type, "text/plain");
+ safestrncpy(content_type, "text/plain", sizeof content_type);
else if (!strncasecmp(&what[strlen(what) - 4], ".css", 4))
- strcpy(content_type, "text/css");
+ safestrncpy(content_type, "text/css", sizeof content_type);
else if (!strncasecmp(&what[strlen(what) - 4], ".jpg", 4))
- strcpy(content_type, "image/jpeg");
+ safestrncpy(content_type, "image/jpeg", sizeof content_type);
else if (!strncasecmp(&what[strlen(what) - 4], ".png", 4))
- strcpy(content_type, "image/png");
+ safestrncpy(content_type, "image/png", sizeof content_type);
else if (!strncasecmp(&what[strlen(what) - 4], ".ico", 4))
- strcpy(content_type, "image/x-icon");
+ safestrncpy(content_type, "image/x-icon", sizeof content_type);
else if (!strncasecmp(&what[strlen(what) - 5], ".html", 5))
- strcpy(content_type, "text/html");
+ safestrncpy(content_type, "text/html", sizeof content_type);
else if (!strncasecmp(&what[strlen(what) - 4], ".htm", 4))
- strcpy(content_type, "text/html");
+ safestrncpy(content_type, "text/html", sizeof content_type);
else if (!strncasecmp(&what[strlen(what) - 4], ".wml", 4))
- strcpy(content_type, "text/vnd.wap.wml");
+ safestrncpy(content_type, "text/vnd.wap.wml", sizeof content_type);
else if (!strncasecmp(&what[strlen(what) - 5], ".wmls", 5))
- strcpy(content_type, "text/vnd.wap.wmlscript");
+ safestrncpy(content_type, "text/vnd.wap.wmlscript", sizeof content_type);
else if (!strncasecmp(&what[strlen(what) - 5], ".wmlc", 5))
- strcpy(content_type, "application/vnd.wap.wmlc");
+ safestrncpy(content_type, "application/vnd.wap.wmlc", sizeof content_type);
else if (!strncasecmp(&what[strlen(what) - 6], ".wmlsc", 6))
- strcpy(content_type, "application/vnd.wap.wmlscriptc");
+ safestrncpy(content_type, "application/vnd.wap.wmlscriptc", sizeof content_type);
else if (!strncasecmp(&what[strlen(what) - 5], ".wbmp", 5))
- strcpy(content_type, "image/vnd.wap.wbmp");
+ safestrncpy(content_type, "image/vnd.wap.wbmp", sizeof content_type);
else if (!strncasecmp(&what[strlen(what) - 3], ".js", 3))
- strcpy(content_type, "text/javascript");
+ safestrncpy(content_type, "text/javascript", sizeof content_type);
else
- strcpy(content_type, "application/octet-stream");
+ safestrncpy(content_type, "application/octet-stream", sizeof content_type);
fstat(fileno(fp), &statbuf);
bytes = statbuf.st_size;
- /* lprintf(3, "Static: %s, (%s; %ld bytes)\r\n",
- what, content_type, bytes); */
bigbuffer = malloc(bytes + 2);
fread(bigbuffer, bytes, 1, fp);
fclose(fp);
void change_start_page(void) {
if (bstr("startpage") == NULL) {
- strcpy(WC->ImportantMessage,
- "startpage set to null");
+ safestrncpy(WC->ImportantMessage,
+ "startpage set to null",
+ sizeof WC->ImportantMessage);
display_main_menu();
return;
}
- set_preference("startpage", bstr("startpage"));
+ set_preference("startpage", bstr("startpage"), 1);
output_headers(1, 1, 0, 0, 0, 0, 0);
do_template("newstartpage");
void upload_handler(char *name, char *filename, char *partnum, char *disp,
- void *content, char *cbtype, size_t length,
- char *encoding, void *userdata)
+ void *content, char *cbtype, char *cbcharset,
+ size_t length, char *encoding, void *userdata)
{
struct urlcontent *u;
+ lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n",
+ name, cbtype, length);
+
/* Form fields */
if ( (length > 0) && (strlen(cbtype) == 0) ) {
u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
char c_httpauth_pass[SIZ];
char cookie[SIZ];
- strcpy(c_username, "");
- strcpy(c_password, "");
- strcpy(c_roomname, "");
- strcpy(c_httpauth_string, "");
- strcpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER);
- strcpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS);
+ safestrncpy(c_username, "", sizeof c_username);
+ safestrncpy(c_password, "", sizeof c_password);
+ safestrncpy(c_roomname, "", sizeof c_roomname);
+ safestrncpy(c_httpauth_string, "", sizeof c_httpauth_string);
+ safestrncpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER, sizeof c_httpauth_user);
+ safestrncpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS, sizeof c_httpauth_pass);
WC->upload_length = 0;
WC->upload = NULL;
hptr = req;
if (hptr == NULL) return;
- strcpy(cmd, hptr->line);
+ safestrncpy(cmd, hptr->line, sizeof cmd);
hptr = hptr->next;
extract_token(method, cmd, 0, ' ', sizeof method);
extract_action(action, cmd);
while (hptr != NULL) {
- strcpy(buf, hptr->line);
+ safestrncpy(buf, hptr->line, sizeof buf);
hptr = hptr->next;
if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
ContentType, ContentLength);
body_start = strlen(content);
- /* Be daring and read it all at once. */
+ /* Read the entire input data at once. */
client_read(WC->http_sock, &content[BytesRead+body_start],
ContentLength);
/* Static content can be sent without connecting to Citadel. */
if (!strcasecmp(action, "static")) {
- strcpy(buf, &cmd[12]);
+ safestrncpy(buf, &cmd[12], sizeof buf);
for (a = 0; a < strlen(buf); ++a)
if (isspace(buf[a]))
buf[a] = 0;
if (buf[0] == '2') {
become_logged_in(c_httpauth_user,
c_httpauth_pass, buf);
- strcpy(WC->httpauth_user, c_httpauth_user);
- strcpy(WC->httpauth_pass, c_httpauth_pass);
+ safestrncpy(WC->httpauth_user, c_httpauth_user, sizeof WC->httpauth_user);
+ safestrncpy(WC->httpauth_pass, c_httpauth_pass, sizeof WC->httpauth_pass);
}
}
}
/*
- * If this isn't a GroupDAV session, it's an ordinary browser
- * connecting to the user interface. Only allow GET and POST
- * methods.
+ * Automatically send requests with any method other than GET or
+ * POST to the GroupDAV code as well.
*/
if ((strcasecmp(method, "GET")) && (strcasecmp(method, "POST"))) {
- wprintf("HTTP/1.1 405 Method Not Allowed\r\n");
- groupdav_common_headers();
- wprintf("Content-Length: 0\r\n\r\n");
+ groupdav_main(req, ContentType, /* do GroupDAV methods */
+ ContentLength, content+body_start);
+ if (!WC->logged_in) {
+ WC->killthis = 1; /* If not logged in, don't */
+ } /* keep the session active */
goto SKIP_ALL_THIS_CRAP;
}
serv_printf("GOTO %s", c_roomname);
serv_getln(buf, sizeof buf);
if (buf[0] == '2') {
- strcpy(WC->wc_roomname, c_roomname);
+ safestrncpy(WC->wc_roomname, c_roomname, sizeof WC->wc_roomname);
}
}
} else if (!strcasecmp(action, "ungoto")) {
ungoto();
} else if (!strcasecmp(action, "dotgoto")) {
- slrp_highest();
+ if (WC->wc_view != VIEW_MAILBOX) { /* dotgoto acts like dotskip when we're in a mailbox view */
+ slrp_highest();
+ }
smart_goto(bstr("room"));
} else if (!strcasecmp(action, "dotskip")) {
smart_goto(bstr("room"));
} else if (!strcasecmp(action, "editpic")) {
do_graphics_upload("UIMG 1|_userpic_");
} else if (!strcasecmp(action, "display_editroompic")) {
- display_graphics_upload("the graphic for this room",
+ display_graphics_upload("the icon for this room",
"UIMG 0|_roompic_",
"/editroompic");
} else if (!strcasecmp(action, "editroompic")) {
} else if (!strcasecmp(action, "display_editfloorpic")) {
sprintf(buf, "UIMG 0|_floorpic_|%s",
bstr("which_floor"));
- display_graphics_upload("the graphic for this floor",
+ display_graphics_upload("the icon for this floor",
buf,
"/editfloorpic");
} else if (!strcasecmp(action, "editfloorpic")) {
save_inetconf();
} else if (!strcasecmp(action, "setup_wizard")) {
do_setup_wizard();
+ } else if (!strcasecmp(action, "display_preferences")) {
+ display_preferences();
+ } else if (!strcasecmp(action, "set_preferences")) {
+ set_preferences();
} else if (!strcasecmp(action, "diagnostics")) {
output_headers(1, 1, 1, 0, 0, 0, 0);