5 * \defgroup MainServer This is the main transaction loop of the web service. It maintains a
6 * persistent session to the Citadel server, handling HTTP WebCit requests as
7 * they arrive and presenting a user interface.
8 * \ingroup WebcitHttpServer
13 #include "webserver.h"
19 * String to unset the cookie.
20 * Any date "in the past" will work, so I chose my birthday, right down to
21 * the exact minute. :)
23 static char *unset = "; expires=28-May-1971 18:10:00 GMT";
26 * \brief remove escaped strings from i.e. the url string (like %20 for blanks)
27 * \param buf the buffer to examine
29 void unescape_input(char *buf)
37 while ((buflen > 0) && (isspace(buf[buflen - 1]))){
42 for (a = 0; a < buflen; ++a) {
50 sscanf(hex, "%02x", &b);
52 memmove(&buf[a + 1], &buf[a + 3], buflen - a - 2);
61 * \brief Extract variables from the URL.
62 * \param url URL supplied by the HTTP parser
64 void addurls(char *url)
72 while (!IsEmptyStr(up)) {
74 /** locate the = sign */
75 safestrncpy(buf, up, sizeof buf);
77 for (a = 255; a >= 0; --a)
84 u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
85 u->next = WC->urlstrings;
87 safestrncpy(u->url_key, buf, sizeof u->url_key);
89 /** now chop that part off */
90 for (a = 0; a <= b; ++a)
93 /** locate "&" and "?" delimiters */
96 for (a = 0; a < len; ++a) {
97 if ( (ptr[0] == '&') || (ptr[0] == '?') ) {
107 u->url_data = malloc(len + 2);
108 safestrncpy(u->url_data, up, b + 1);
110 unescape_input(u->url_data);
114 /* lprintf(9, "%s = %s\n", u->url_key, u->url_data); */
119 * \brief free urlstring memory
123 struct urlcontent *u;
125 while (WC->urlstrings != NULL) {
126 free(WC->urlstrings->url_data);
127 u = WC->urlstrings->next;
128 free(WC->urlstrings);
134 * \brief Diagnostic function to display the contents of all variables
138 struct urlcontent *u;
140 for (u = WC->urlstrings; u != NULL; u = u->next) {
141 wprintf("%38s = %s\n", u->url_key, u->url_data);
146 * \brief Return the value of a variable supplied to the current web page (from the url or a form)
147 * \param key The name of the variable we want
149 char *bstr(char *key)
151 struct urlcontent *u;
153 for (u = WC->urlstrings; u != NULL; u = u->next) {
154 if (!strcasecmp(u->url_key, key))
155 return (u->url_data);
161 * \brief web-printing funcion. uses our vsnprintf wrapper
162 * \param format printf format string
163 * \param ... the varargs to put into formatstring
165 void wprintf(const char *format,...)
170 va_start(arg_ptr, format);
171 vsnprintf(wbuf, sizeof wbuf, format, arg_ptr);
174 client_write(wbuf, strlen(wbuf));
179 * \brief wrap up an HTTP session, closes tags, etc.
180 * \todo multiline params?
181 * \param print_standard_html_footer should be set to 0 to transmit only, 1 to
182 * append the main menu and closing tags, or 2 to
183 * append the closing tags only.
185 void wDumpContent(int print_standard_html_footer)
187 if (print_standard_html_footer) {
188 wprintf("</div>\n"); /* end of "text" div */
189 do_template("trailing");
192 /* If we've been saving it all up for one big output burst,
193 * go ahead and do that now.
200 * \brief Copy a string, escaping characters which have meaning in HTML.
201 * \param target target buffer
202 * \param strbuf source buffer
203 * \param nbsp If nonzero, spaces are converted to non-breaking spaces.
204 * \param nolinebreaks if set, linebreaks are removed from the string.
206 long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks)
208 char *aptr, *bptr, *eptr;
213 eptr = target + tSize - 6; // our biggest unit to put in...
215 while ((bptr < eptr) && !IsEmptyStr(aptr) ){
217 memcpy(bptr, "<", 4);
220 else if (*aptr == '>') {
221 memcpy(bptr, ">", 4);
224 else if (*aptr == '&') {
225 memcpy(bptr, "&", 5);
228 else if (*aptr == '\"') {
229 memcpy(bptr, """, 6);
232 else if (*aptr == '\'') {
233 memcpy(bptr, "'", 5);
236 else if (*aptr == LB) {
240 else if (*aptr == RB) {
244 else if (*aptr == QU) {
248 else if ((*aptr == 32) && (nbsp == 1)) {
249 memcpy(bptr, " ", 6);
252 else if ((*aptr == '\n') && (nolinebreaks)) {
253 *bptr='\0'; /* nothing */
255 else if ((*aptr == '\r') && (nolinebreaks)) {
256 *bptr='\0'; /* nothing */
265 if ((bptr = eptr - 1 ) && !IsEmptyStr(aptr) )
267 return (bptr - target);
272 * \param strbuf what???
273 * \param nbsp If nonzero, spaces are converted to non-breaking spaces.
274 * \param nolinebreaks if set, linebreaks are removed from the string.
276 void escputs1(char *strbuf, int nbsp, int nolinebreaks)
281 if (strbuf == NULL) return;
282 Siz = (3 * strlen(strbuf)) + SIZ ;
284 stresc(buf, Siz, strbuf, nbsp, nolinebreaks);
290 * \brief static wrapper for ecsputs1
291 * \param strbuf buffer to print escaped to client
293 void escputs(char *strbuf)
295 escputs1(strbuf, 0, 0);
299 * \brief Escape a string for feeding out as a URL.
300 * \param outbuf the output buffer
301 * \param strbuf the input buffer
303 void urlesc(char *outbuf, char *strbuf)
305 int a, b, c, len, eclen, olen;
306 char *ec = " +#&;`'|*?-~<>^()[]{}/$\"\\";
309 len = strlen(strbuf);
312 for (a = 0; a < len; ++a) {
314 for (b = 0; b < eclen; ++b) {
315 if (strbuf[a] == ec[b])
319 sprintf(&outbuf[olen], "%%%02x", strbuf[a]);
323 outbuf[olen ++] = strbuf[a];
329 * \brief urlescape buffer and print it to the client
330 * \param strbuf buffer to urlescape
332 void urlescputs(char *strbuf)
336 urlesc(outbuf, strbuf);
337 wprintf("%s", outbuf);
342 * \brief Copy a string, escaping characters for JavaScript strings.
343 * \param target output string
344 * \param strbuf input string
346 void jsesc(char *target, char *strbuf)
351 len = strlen (strbuf);
352 for (a = 0; a < len; ++a) {
353 if (strbuf[a] == '<')
355 else if (strbuf[a] == '>')
357 else if (strbuf[a] == '\"')
358 strcat(target, """);
359 else if (strbuf[a] == '&')
360 strcat(target, "&;");
361 else if (strbuf[a] == '\'')
362 strcat(target, "\\'");
364 strncat(target, &strbuf[a], 1);
370 * \brief escape and print java script
371 * \param strbuf the js code
373 void jsescputs(char *strbuf)
377 jsesc(outbuf, strbuf);
378 wprintf("%s", outbuf);
382 * \brief Copy a string, escaping characters for message text hold
383 * \param target target buffer
384 * \param strbuf source buffer
386 void msgesc(char *target, char *strbuf)
391 len = strlen(strbuf);
392 for (a = 0; a < len; ++a) {
393 if (strbuf[a] == '\n')
395 else if (strbuf[a] == '\r')
397 else if (strbuf[a] == '\'')
398 strcat(target, "'");
400 strncat(target, &strbuf[a], 1);
406 * \brief print a string to the client after cleaning it with msgesc() and stresc()
407 * \param strbuf string to be printed
409 void msgescputs1( char *strbuf)
415 if (strbuf == NULL) return;
416 buflen = 3 * strlen(strbuf) + SIZ;
417 outbuf = malloc( buflen);
418 outbuf2 = malloc( buflen);
419 msgesc(outbuf, strbuf);
420 stresc(outbuf2, buflen, outbuf, 0, 0);
421 wprintf("%s", outbuf2);
427 * \brief print a string to the client after cleaning it with msgesc()
428 * \param strbuf string to be printed
430 void msgescputs(char *strbuf) {
433 if (strbuf == NULL) return;
434 outbuf = malloc( (3 * strlen(strbuf)) + SIZ);
435 msgesc(outbuf, strbuf);
436 wprintf("%s", outbuf);
444 * \brief Output all that important stuff that the browser will want to see
446 void output_headers( int do_httpheaders, /**< 1 = output HTTP headers */
447 int do_htmlhead, /**< 1 = output HTML <head> section and <body> opener */
449 int do_room_banner, /**< 0=no, 1=yes,
450 * 2 = I'm going to embed my own, so don't open the
451 * <div id="content"> either.
454 int unset_cookies, /**< 1 = session is terminating, so unset the cookies */
455 int suppress_check, /**< 1 = suppress check for instant messages */
456 int cache /**< 1 = allow browser to cache this page */
461 wprintf("HTTP/1.1 200 OK\n");
462 http_datestring(httpnow, sizeof httpnow, time(NULL));
464 if (do_httpheaders) {
465 wprintf("Content-type: text/html; charset=utf-8\r\n"
467 "Connection: close\r\n",
468 PACKAGE_STRING, serv_info.serv_software
473 wprintf("Pragma: public\r\n"
474 "Cache-Control: max-age=3600, must-revalidate\r\n"
475 "Last-modified: %s\r\n",
480 wprintf("Pragma: no-cache\r\n"
481 "Cache-Control: no-store\r\n"
486 stuff_to_cookie(cookie, WC->wc_session, WC->wc_username,
487 WC->wc_password, WC->wc_roomname);
490 wprintf("Set-cookie: webcit=%s; path=/\r\n", unset);
492 wprintf("Set-cookie: webcit=%s; path=/\r\n", cookie);
493 if (server_cookie != NULL) {
494 wprintf("%s\n", server_cookie);
500 if (!access("static.local/webcit.css", R_OK)) {
501 svprintf("CSSLOCAL", WCS_STRING,
502 "<link href=\"static.local/webcit.css\" rel=\"stylesheet\" type=\"text/css\">"
512 /** check for ImportantMessages (these display in a div overlaying the main screen) */
513 if (!IsEmptyStr(WC->ImportantMessage)) {
514 wprintf("<div id=\"important_message\">\n");
515 wprintf("<span class=\"imsg\">"
516 "%s</span><br />\n", WC->ImportantMessage);
518 wprintf("<script type=\"text/javascript\">\n"
519 " setTimeout('hide_imsg_popup()', 3000); \n"
521 safestrncpy(WC->ImportantMessage, "", sizeof WC->ImportantMessage);
524 if ( (WC->logged_in) && (!unset_cookies) ) {
525 wprintf("<div id=\"iconbar\">");
526 do_selected_iconbar();
527 /** check for instant messages (these display in a new window) */
532 if (do_room_banner == 1) {
533 wprintf("<div id=\"banner\">\n");
534 embed_room_banner(NULL, navbar_default);
539 if (do_room_banner == 1) {
540 wprintf("<div id=\"content\">\n");
546 * \brief Generic function to do an HTTP redirect. Easy and fun.
547 * \param whichpage target url to 302 to
549 void http_redirect(char *whichpage) {
550 wprintf("HTTP/1.1 302 Moved Temporarily\n");
551 wprintf("Location: %s\r\n", whichpage);
552 wprintf("URI: %s\r\n", whichpage);
553 wprintf("Content-type: text/html; charset=utf-8\r\n\r\n");
554 wprintf("<html><body>");
555 wprintf("Go <a href=\"%s\">here</A>.", whichpage);
556 wprintf("</body></html>\n");
562 * \brief Output a piece of content to the web browser
564 void http_transmit_thing(char *thing, size_t length, char *content_type,
567 output_headers(0, 0, 0, 0, 0, is_static);
569 wprintf("Content-type: %s\r\n"
571 "Connection: close\r\n",
576 /** If we can send the data out compressed, please do so. */
578 char *compressed_data = NULL;
579 uLongf compressed_len;
581 compressed_len = (uLongf) ((length * 101) / 100) + 100;
582 compressed_data = malloc(compressed_len);
584 if (compress_gzip((Bytef *) compressed_data,
587 (uLongf) length, Z_BEST_SPEED) == Z_OK) {
588 wprintf("Content-encoding: gzip\r\n"
589 "Content-length: %ld\r\n"
591 (long) compressed_len
593 client_write(compressed_data, (size_t)compressed_len);
594 free(compressed_data);
600 /** No compression ... just send it out as-is */
601 wprintf("Content-length: %ld\r\n"
605 client_write(thing, (size_t)length);
609 * \brief print menu box like used in the floor view or admin interface.
610 * This function takes pair of strings as va_args,
611 * \param Title Title string of the box
612 * \param Class CSS Class for the box
613 * \param nLines How many string pairs should we print? (URL, UrlText)
614 * \param ... Pairs of URL Strings and their Names
616 void print_menu_box(char* Title, char *Class, int nLines, ...)
621 svprintf("BOXTITLE", WCS_STRING, Title);
622 do_template("beginbox");
624 wprintf("<ul class=\"%s\">", Class);
626 va_start(arg_list, nLines);
627 for (i = 0; i < nLines; ++i)
629 wprintf("<li><a href=\"%s\">", va_arg(arg_list, char *));
630 wprintf((char *) va_arg(arg_list, char *));
631 wprintf("</a></li>\n");
635 wprintf("</a></li>\n");
639 do_template("endbox");
644 * \brief dump out static pages from disk
645 * \param what the file urs to print
647 void output_static(char *what)
653 char content_type[128];
656 fp = fopen(what, "rb");
658 lprintf(9, "output_static('%s') -- NOT FOUND --\n", what);
659 wprintf("HTTP/1.1 404 %s\n", strerror(errno));
660 wprintf("Content-Type: text/plain\r\n");
662 wprintf("Cannot open %s: %s\n", what, strerror(errno));
665 if (!strncasecmp(&what[len - 4], ".gif", 4))
666 safestrncpy(content_type, "image/gif", sizeof content_type);
667 else if (!strncasecmp(&what[len - 4], ".txt", 4))
668 safestrncpy(content_type, "text/plain", sizeof content_type);
669 else if (!strncasecmp(&what[len - 4], ".css", 4))
670 safestrncpy(content_type, "text/css", sizeof content_type);
671 else if (!strncasecmp(&what[len - 4], ".jpg", 4))
672 safestrncpy(content_type, "image/jpeg", sizeof content_type);
673 else if (!strncasecmp(&what[len - 4], ".png", 4))
674 safestrncpy(content_type, "image/png", sizeof content_type);
675 else if (!strncasecmp(&what[len - 4], ".ico", 4))
676 safestrncpy(content_type, "image/x-icon", sizeof content_type);
677 else if (!strncasecmp(&what[len - 5], ".html", 5))
678 safestrncpy(content_type, "text/html", sizeof content_type);
679 else if (!strncasecmp(&what[len - 4], ".htm", 4))
680 safestrncpy(content_type, "text/html", sizeof content_type);
681 else if (!strncasecmp(&what[len - 4], ".wml", 4))
682 safestrncpy(content_type, "text/vnd.wap.wml", sizeof content_type);
683 else if (!strncasecmp(&what[len - 5], ".wmls", 5))
684 safestrncpy(content_type, "text/vnd.wap.wmlscript", sizeof content_type);
685 else if (!strncasecmp(&what[len - 5], ".wmlc", 5))
686 safestrncpy(content_type, "application/vnd.wap.wmlc", sizeof content_type);
687 else if (!strncasecmp(&what[len - 6], ".wmlsc", 6))
688 safestrncpy(content_type, "application/vnd.wap.wmlscriptc", sizeof content_type);
689 else if (!strncasecmp(&what[len - 5], ".wbmp", 5))
690 safestrncpy(content_type, "image/vnd.wap.wbmp", sizeof content_type);
691 else if (!strncasecmp(&what[len - 3], ".js", 3))
692 safestrncpy(content_type, "text/javascript", sizeof content_type);
694 safestrncpy(content_type, "application/octet-stream", sizeof content_type);
696 fstat(fileno(fp), &statbuf);
697 bytes = statbuf.st_size;
698 bigbuffer = malloc(bytes + 2);
699 fread(bigbuffer, bytes, 1, fp);
702 lprintf(9, "output_static('%s') %s\n", what, content_type);
703 http_transmit_thing(bigbuffer, (size_t)bytes, content_type, 1);
706 if (!strcasecmp(bstr("force_close_session"), "yes")) {
707 end_webcit_session();
713 * \brief When the browser requests an image file from the Citadel server,
714 * this function is called to transmit it.
719 char *xferbuf = NULL;
722 serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
723 serv_getln(buf, sizeof buf);
725 bytes = extract_long(&buf[4], 0);
726 xferbuf = malloc(bytes + 2);
728 /** Read it from the server */
729 read_server_binary(xferbuf, bytes);
731 serv_getln(buf, sizeof buf);
733 /** Write it to the browser */
734 http_transmit_thing(xferbuf, (size_t)bytes, "image/gif", 0);
739 * Instead of an ugly 404, send a 1x1 transparent GIF
740 * when there's no such image on the server.
742 output_static("static/blank.gif");
750 * \brief Generic function to output an arbitrary MIME part from an arbitrary
751 * message number on the server.
753 * \param msgnum Number of the item on the citadel server
754 * \param partnum The MIME part to be output
755 * \param force_download Nonzero to force set the Content-Type: header
756 * to "application/octet-stream"
758 void mimepart(char *msgnum, char *partnum, int force_download)
762 char content_type[256];
763 char *content = NULL;
765 serv_printf("OPNA %s|%s", msgnum, partnum);
766 serv_getln(buf, sizeof buf);
768 bytes = extract_long(&buf[4], 0);
769 content = malloc(bytes + 2);
770 if (force_download) {
771 strcpy(content_type, "application/octet-stream");
774 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
776 output_headers(0, 0, 0, 0, 0, 0);
777 read_server_binary(content, bytes);
779 serv_getln(buf, sizeof buf);
780 http_transmit_thing(content, bytes, content_type, 0);
783 wprintf("HTTP/1.1 404 %s\n", &buf[4]);
784 output_headers(0, 0, 0, 0, 0, 0);
785 wprintf("Content-Type: text/plain\r\n");
787 wprintf(_("An error occurred while retrieving this part: %s\n"), &buf[4]);
794 * \brief Read any MIME part of a message, from the server, into memory.
795 * \param msgnum number of the message on the citadel server
796 * \param partnum the MIME part to be loaded
798 char *load_mimepart(long msgnum, char *partnum)
802 char content_type[SIZ];
805 serv_printf("DLAT %ld|%s", msgnum, partnum);
806 serv_getln(buf, sizeof buf);
808 bytes = extract_long(&buf[4], 0);
809 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
811 content = malloc(bytes + 2);
812 serv_read(content, bytes);
814 content[bytes] = 0; /* null terminate for good measure */
825 * \brief Convenience functions to display a page containing only a string
826 * \param titlebarcolor color of the titlebar of the frame
827 * \param titlebarmsg text to display in the title bar
828 * \param messagetext body of the box
830 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
832 wprintf("HTTP/1.1 200 OK\n");
833 output_headers(1, 1, 2, 0, 0, 0);
834 wprintf("<div id=\"banner\">\n");
835 wprintf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
836 wprintf("<span class=\"titlebar\">%s</span>\n", titlebarmsg);
837 wprintf("</td></tr></table>\n");
838 wprintf("</div>\n<div id=\"content\">\n");
839 escputs(messagetext);
847 * \brief Display a blank page.
849 void blank_page(void) {
850 output_headers(1, 1, 0, 0, 0, 0);
856 * \brief A template has been requested
858 void url_do_template(void) {
859 do_template(bstr("template"));
865 * \brief Offer to make any page the user's "start page."
867 void offer_start_page(void) {
868 wprintf("<a href=\"change_start_page?startpage=");
869 urlescputs(WC->this_page);
871 wprintf(_("Make this my start page"));
874 wprintf("<br/><a href=\"rss?room=");
875 urlescputs(WC->wc_roomname);
876 wprintf("\" title=\"RSS 2.0 feed for ");
877 escputs(WC->wc_roomname);
878 wprintf("\"><img alt=\"RSS\" border=\"0\" src=\"static/xml_button.gif\"/></a>\n");
884 * \brief Change the user's start page
886 void change_start_page(void) {
888 if (bstr("startpage") == NULL) {
889 safestrncpy(WC->ImportantMessage,
890 _("You no longer have a start page selected."),
891 sizeof WC->ImportantMessage);
896 set_preference("startpage", bstr("startpage"), 1);
898 output_headers(1, 1, 0, 0, 0, 0);
899 do_template("newstartpage");
906 * \brief convenience function to indicate success
907 * \param successmessage the mesage itself
909 void display_success(char *successmessage)
911 convenience_page("007700", "OK", successmessage);
916 * \brief Authorization required page
917 * This is probably temporary and should be revisited
918 * \param message message to put in header
920 void authorization_required(const char *message)
922 wprintf("HTTP/1.1 401 Authorization Required\r\n");
923 wprintf("WWW-Authenticate: Basic realm=\"\"\r\n", serv_info.serv_humannode);
924 wprintf("Content-Type: text/html\r\n\r\n");
926 wprintf(_("Authorization Required"));
927 wprintf("</h1>\r\n");
928 wprintf(_("The resource you requested requires a valid username and password. "
929 "You could not be logged in: %s\n"), message);
934 * \brief This function is called by the MIME parser to handle data uploaded by
935 * the browser. Form data, uploaded files, and the data from HTTP PUT
936 * operations (such as those found in GroupDAV) all arrive this way.
938 * \param name Name of the item being uploaded
939 * \param filename Filename of the item being uploaded
940 * \param partnum MIME part identifier (not needed)
941 * \param disp MIME content disposition (not needed)
942 * \param content The actual data
943 * \param cbtype MIME content-type
944 * \param cbcharset Character set
945 * \param length Content length
946 * \param encoding MIME encoding type (not needed)
947 * \param userdata Not used here
949 void upload_handler(char *name, char *filename, char *partnum, char *disp,
950 void *content, char *cbtype, char *cbcharset,
951 size_t length, char *encoding, void *userdata)
953 struct urlcontent *u;
955 lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n", name, cbtype, length);
958 if ( (length > 0) && (IsEmptyStr(cbtype)) ) {
959 u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
960 u->next = WC->urlstrings;
962 safestrncpy(u->url_key, name, sizeof(u->url_key));
963 u->url_data = malloc(length + 1);
964 memcpy(u->url_data, content, length);
965 u->url_data[length] = 0;
966 /* lprintf(9, "Key: <%s> Data: <%s>\n", u->url_key, u->url_data); */
969 /** Uploaded files */
970 if ( (length > 0) && (!IsEmptyStr(cbtype)) ) {
971 WC->upload = malloc(length);
972 if (WC->upload != NULL) {
973 WC->upload_length = length;
974 safestrncpy(WC->upload_filename, filename,
975 sizeof(WC->upload_filename));
976 safestrncpy(WC->upload_content_type, cbtype,
977 sizeof(WC->upload_content_type));
978 memcpy(WC->upload, content, length);
981 lprintf(3, "malloc() failed: %s\n", strerror(errno));
988 * \brief Convenience functions to wrap around asynchronous ajax responses
990 void begin_ajax_response(void) {
991 output_headers(0, 0, 0, 0, 0, 0);
993 wprintf("Content-type: text/html; charset=UTF-8\r\n"
995 "Connection: close\r\n"
996 "Pragma: no-cache\r\n"
997 "Cache-Control: no-cache\r\n"
1005 * \brief print ajax response footer
1007 void end_ajax_response(void) {
1013 * \brief Wraps a Citadel server command in an AJAX transaction.
1015 void ajax_servcmd(void)
1018 char gcontent[1024];
1022 begin_ajax_response();
1024 serv_printf("%s", bstr("g_cmd"));
1025 serv_getln(buf, sizeof buf);
1026 wprintf("%s\n", buf);
1028 if (buf[0] == '8') {
1029 serv_printf("\n\n000");
1031 if ((buf[0] == '1') || (buf[0] == '8')) {
1032 while (serv_getln(gcontent, sizeof gcontent), strcmp(gcontent, "000")) {
1033 wprintf("%s\n", gcontent);
1037 if (buf[0] == '4') {
1038 text_to_server(bstr("g_input"));
1041 if (buf[0] == '6') {
1042 len = atol(&buf[4]);
1044 serv_read(junk, len);
1047 if (buf[0] == '7') {
1048 len = atol(&buf[4]);
1050 memset(junk, 0, len);
1051 serv_write(junk, len);
1055 end_ajax_response();
1058 * This is kind of an ugly hack, but this is the only place it can go.
1059 * If the command was GEXP, then the instant messenger window must be
1060 * running, so reset the "last_pager_check" watchdog timer so
1061 * that page_popup() doesn't try to open it a second time.
1063 if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) {
1064 WC->last_pager_check = time(NULL);
1070 * \brief Helper function for the asynchronous check to see if we need
1071 * to open the instant messenger window.
1073 void seconds_since_last_gexp(void)
1077 begin_ajax_response();
1078 if ( (time(NULL) - WC->last_pager_check) < 30) {
1083 serv_getln(buf, sizeof buf);
1084 if (buf[3] == '*') {
1091 end_ajax_response();
1098 * \brief Entry point for WebCit transaction
1100 void session_loop(struct httprequest *req)
1108 char request_method[128];
1109 char pathname[1024];
1110 int a, b, nBackDots, nEmpty;
1111 int ContentLength = 0;
1113 char ContentType[512];
1114 char *content = NULL;
1115 char *content_end = NULL;
1116 struct httprequest *hptr;
1117 char browser_host[256];
1118 char user_agent[256];
1124 * We stuff these with the values coming from the client cookies,
1125 * so we can use them to reconnect a timed out session if we have to.
1127 char c_username[SIZ];
1128 char c_password[SIZ];
1129 char c_roomname[SIZ];
1130 char c_httpauth_string[SIZ];
1131 char c_httpauth_user[SIZ];
1132 char c_httpauth_pass[SIZ];
1135 safestrncpy(c_username, "", sizeof c_username);
1136 safestrncpy(c_password, "", sizeof c_password);
1137 safestrncpy(c_roomname, "", sizeof c_roomname);
1138 safestrncpy(c_httpauth_string, "", sizeof c_httpauth_string);
1139 safestrncpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER, sizeof c_httpauth_user);
1140 safestrncpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS, sizeof c_httpauth_pass);
1141 strcpy(browser_host, "");
1143 WC->upload_length = 0;
1149 if (hptr == NULL) return;
1151 safestrncpy(cmd, hptr->line, sizeof cmd);
1153 extract_token(request_method, cmd, 0, ' ', sizeof request_method);
1154 extract_token(pathname, cmd, 1, ' ', sizeof pathname);
1156 /** Figure out the action */
1158 sizes[0] = sizeof action;
1161 index[a] = arg[a-1];
1162 sizes[a] = sizeof arg[a-1];
1164 //// index[9] = &foo; todo
1167 for ( a = 0; a < 9; ++a)
1169 extract_token(index[a], pathname, a + 1, '/', sizes[a]);
1170 if (strstr(index[a], "?")) *strstr(index[a], "?") = 0;
1171 if (strstr(index[a], "&")) *strstr(index[a], "&") = 0;
1172 if (strstr(index[a], " ")) *strstr(index[a], " ") = 0;
1173 if ((index[a][0] == '.') && (index[a][1] == '.'))
1175 if (index[a][0] == '\0')
1179 while (hptr != NULL) {
1180 safestrncpy(buf, hptr->line, sizeof buf);
1181 /* lprintf(9, "HTTP HEADER: %s\n", buf); */
1184 if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
1185 safestrncpy(cookie, &buf[15], sizeof cookie);
1186 cookie_to_stuff(cookie, NULL,
1187 c_username, sizeof c_username,
1188 c_password, sizeof c_password,
1189 c_roomname, sizeof c_roomname);
1191 else if (!strncasecmp(buf, "Authorization: Basic ", 21)) {
1192 CtdlDecodeBase64(c_httpauth_string, &buf[21], strlen(&buf[21]));
1193 extract_token(c_httpauth_user, c_httpauth_string, 0, ':', sizeof c_httpauth_user);
1194 extract_token(c_httpauth_pass, c_httpauth_string, 1, ':', sizeof c_httpauth_pass);
1196 else if (!strncasecmp(buf, "Content-length: ", 16)) {
1197 ContentLength = atoi(&buf[16]);
1199 else if (!strncasecmp(buf, "Content-type: ", 14)) {
1200 safestrncpy(ContentType, &buf[14], sizeof ContentType);
1202 else if (!strncasecmp(buf, "User-agent: ", 12)) {
1203 safestrncpy(user_agent, &buf[12], sizeof user_agent);
1205 else if (!strncasecmp(buf, "X-Forwarded-Host: ", 18)) {
1207 safestrncpy(WC->http_host, &buf[18], sizeof WC->http_host);
1210 else if (!strncasecmp(buf, "Host: ", 6)) {
1211 if (IsEmptyStr(WC->http_host)) {
1212 safestrncpy(WC->http_host, &buf[6], sizeof WC->http_host);
1215 else if (!strncasecmp(buf, "X-Forwarded-For: ", 17)) {
1216 safestrncpy(browser_host, &buf[17], sizeof browser_host);
1217 while (num_tokens(browser_host, ',') > 1) {
1218 remove_token(browser_host, 0, ',');
1220 striplt(browser_host);
1222 /** Only WAP gateways explicitly name this content-type */
1223 else if (strstr(buf, "text/vnd.wap.wml")) {
1228 if (ContentLength > 0) {
1229 content = malloc(ContentLength + SIZ);
1230 memset(content, 0, ContentLength + SIZ);
1231 sprintf(content, "Content-type: %s\n"
1232 "Content-length: %d\n\n",
1233 ContentType, ContentLength);
1234 body_start = strlen(content);
1236 /** Read the entire input data at once. */
1237 client_read(WC->http_sock, &content[BytesRead+body_start], ContentLength);
1239 if (!strncasecmp(ContentType, "application/x-www-form-urlencoded", 33)) {
1240 addurls(&content[body_start]);
1241 } else if (!strncasecmp(ContentType, "multipart", 9)) {
1242 content_end = content + ContentLength + body_start;
1243 mime_parser(content, content_end, *upload_handler, NULL, NULL, NULL, 0);
1249 /** make a note of where we are in case the user wants to save it */
1250 safestrncpy(WC->this_page, cmd, sizeof(WC->this_page));
1251 remove_token(WC->this_page, 2, ' ');
1252 remove_token(WC->this_page, 0, ' ');
1254 /** If there are variables in the URL, we must grab them now */
1256 for (a = 0; a < len; ++a) {
1257 if ((cmd[a] == '?') || (cmd[a] == '&')) {
1258 for (b = a; b < len; ++b) {
1259 if (isspace(cmd[b])){
1264 addurls(&cmd[a + 1]);
1270 /** If it's a "force 404" situation then display the error and bail. */
1271 if (!strcmp(action, "404")) {
1272 wprintf("HTTP/1.1 404 Not found\r\n");
1273 wprintf("Content-Type: text/plain\r\n");
1275 wprintf("Not found\r\n");
1276 goto SKIP_ALL_THIS_CRAP;
1279 /** Static content can be sent without connecting to Citadel. */
1281 for (a=0; a<ndirs; ++a) {
1282 if (!strcasecmp(action, (char*)static_content_dirs[a])) { /* map web to disk location */
1290 snprintf(buf, sizeof buf, "%s/%s/%s/%s/%s/%s/%s/%s",
1291 static_dirs[n_static],
1292 index[1], index[2], index[3], index[4], index[5], index[6], index[7]);
1293 for (a=0; a<8; ++a) {
1294 if (buf[strlen(buf)-1] == '/') {
1295 buf[strlen(buf)-1] = 0;
1298 for (a = 0; a < strlen(buf); ++a) {
1299 if (isspace(buf[a])) {
1307 lprintf(9, "Suspicious request. Ignoring.");
1308 wprintf("HTTP/1.1 404 Security check failed\r\n");
1309 wprintf("Content-Type: text/plain\r\n");
1311 wprintf("Security check failed.\r\n");
1313 goto SKIP_ALL_THIS_CRAP; /* Don't try to connect */
1316 /* If the client sent a nonce that is incorrect, kill the request. */
1317 if (strlen(bstr("nonce")) > 0) {
1318 lprintf(9, "Comparing supplied nonce %s to session nonce %ld\n",
1319 bstr("nonce"), WC->nonce);
1320 if (atoi(bstr("nonce")) != WC->nonce) {
1321 lprintf(9, "Ignoring request with mismatched nonce.\n");
1322 wprintf("HTTP/1.1 404 Security check failed\r\n");
1323 wprintf("Content-Type: text/plain\r\n");
1325 wprintf("Security check failed.\r\n");
1326 goto SKIP_ALL_THIS_CRAP;
1331 * If we're not connected to a Citadel server, try to hook up the
1334 if (!WC->connected) {
1335 if (!strcasecmp(ctdlhost, "uds")) {
1336 /* unix domain socket */
1337 sprintf(buf, "%s/citadel.socket", ctdlport);
1338 WC->serv_sock = uds_connectsock(buf);
1342 WC->serv_sock = tcp_connectsock(ctdlhost, ctdlport);
1345 if (WC->serv_sock < 0) {
1347 goto SKIP_ALL_THIS_CRAP;
1351 serv_getln(buf, sizeof buf); /** get the server welcome message */
1354 * From what host is our user connecting? Go with
1355 * the host at the other end of the HTTP socket,
1356 * unless we are following X-Forwarded-For: headers
1357 * and such a header has already turned up something.
1359 if ( (!follow_xff) || (strlen(browser_host) == 0) ) {
1360 locate_host(browser_host, WC->http_sock);
1363 get_serv_info(browser_host, user_agent);
1364 if (serv_info.serv_rev_level < MINIMUM_CIT_VERSION) {
1365 wprintf(_("You are connected to a Citadel "
1366 "server running Citadel %d.%02d. \n"
1367 "In order to run this version of WebCit "
1368 "you must also have Citadel %d.%02d or"
1370 serv_info.serv_rev_level / 100,
1371 serv_info.serv_rev_level % 100,
1372 MINIMUM_CIT_VERSION / 100,
1373 MINIMUM_CIT_VERSION % 100
1375 end_webcit_session();
1376 goto SKIP_ALL_THIS_CRAP;
1382 * Functions which can be performed without logging in
1384 if (!strcasecmp(action, "listsub")) {
1386 goto SKIP_ALL_THIS_CRAP;
1388 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1389 if (!strcasecmp(action, "freebusy")) {
1391 goto SKIP_ALL_THIS_CRAP;
1396 * If we're not logged in, but we have HTTP Authentication data,
1397 * try logging in to Citadel using that.
1399 if ((!WC->logged_in)
1400 && (strlen(c_httpauth_user) > 0)
1401 && (strlen(c_httpauth_pass) > 0)) {
1402 serv_printf("USER %s", c_httpauth_user);
1403 serv_getln(buf, sizeof buf);
1404 if (buf[0] == '3') {
1405 serv_printf("PASS %s", c_httpauth_pass);
1406 serv_getln(buf, sizeof buf);
1407 if (buf[0] == '2') {
1408 become_logged_in(c_httpauth_user,
1409 c_httpauth_pass, buf);
1410 safestrncpy(WC->httpauth_user, c_httpauth_user, sizeof WC->httpauth_user);
1411 safestrncpy(WC->httpauth_pass, c_httpauth_pass, sizeof WC->httpauth_pass);
1413 /** Should only display when password is wrong */
1414 authorization_required(&buf[4]);
1415 goto SKIP_ALL_THIS_CRAP;
1420 /** This needs to run early */
1421 if (!strcasecmp(action, "rss")) {
1422 display_rss(bstr("room"), request_method);
1423 goto SKIP_ALL_THIS_CRAP;
1427 * The GroupDAV stuff relies on HTTP authentication instead of
1428 * our session's authentication.
1430 if (!strncasecmp(action, "groupdav", 8)) {
1431 groupdav_main(req, ContentType, /* do GroupDAV methods */
1432 ContentLength, content+body_start);
1433 if (!WC->logged_in) {
1434 WC->killthis = 1; /* If not logged in, don't */
1435 } /* keep the session active */
1436 goto SKIP_ALL_THIS_CRAP;
1441 * Automatically send requests with any method other than GET or
1442 * POST to the GroupDAV code as well.
1444 if ((strcasecmp(request_method, "GET")) && (strcasecmp(request_method, "POST"))) {
1445 groupdav_main(req, ContentType, /** do GroupDAV methods */
1446 ContentLength, content+body_start);
1447 if (!WC->logged_in) {
1448 WC->killthis = 1; /** If not logged in, don't */
1449 } /** keep the session active */
1450 goto SKIP_ALL_THIS_CRAP;
1454 * If we're not logged in, but we have username and password cookies
1455 * supplied by the browser, try using them to log in.
1457 if ((!WC->logged_in)
1458 && (!IsEmptyStr(c_username))
1459 && (!IsEmptyStr(c_password))) {
1460 serv_printf("USER %s", c_username);
1461 serv_getln(buf, sizeof buf);
1462 if (buf[0] == '3') {
1463 serv_printf("PASS %s", c_password);
1464 serv_getln(buf, sizeof buf);
1465 if (buf[0] == '2') {
1466 become_logged_in(c_username, c_password, buf);
1471 * If we don't have a current room, but a cookie specifying the
1472 * current room is supplied, make an effort to go there.
1474 if ((IsEmptyStr(WC->wc_roomname)) && (!IsEmptyStr(c_roomname))) {
1475 serv_printf("GOTO %s", c_roomname);
1476 serv_getln(buf, sizeof buf);
1477 if (buf[0] == '2') {
1478 safestrncpy(WC->wc_roomname, c_roomname, sizeof WC->wc_roomname);
1482 if (!strcasecmp(action, "image")) {
1486 * All functions handled below this point ... make sure we log in
1487 * before doing anything else!
1489 } else if ((!WC->logged_in) && (!strcasecmp(action, "login"))) {
1491 } else if (!WC->logged_in) {
1492 display_login(NULL);
1496 * Various commands...
1499 else if (!strcasecmp(action, "do_welcome")) {
1501 } else if (!strcasecmp(action, "blank")) {
1503 } else if (!strcasecmp(action, "do_template")) {
1505 } else if (!strcasecmp(action, "display_aide_menu")) {
1506 display_aide_menu();
1507 } else if (!strcasecmp(action, "server_shutdown")) {
1509 } else if (!strcasecmp(action, "display_main_menu")) {
1510 display_main_menu();
1511 } else if (!strcasecmp(action, "who")) {
1513 } else if (!strcasecmp(action, "sslg")) {
1514 seconds_since_last_gexp();
1515 } else if (!strcasecmp(action, "who_inner_html")) {
1516 begin_ajax_response();
1518 end_ajax_response();
1519 } else if (!strcasecmp(action, "wholist_section")) {
1520 begin_ajax_response();
1522 end_ajax_response();
1523 } else if (!strcasecmp(action, "new_messages_html")) {
1524 begin_ajax_response();
1525 new_messages_section();
1526 end_ajax_response();
1527 } else if (!strcasecmp(action, "tasks_inner_html")) {
1528 begin_ajax_response();
1530 end_ajax_response();
1531 } else if (!strcasecmp(action, "calendar_inner_html")) {
1532 begin_ajax_response();
1534 end_ajax_response();
1535 } else if (!strcasecmp(action, "mini_calendar")) {
1536 begin_ajax_response();
1537 ajax_mini_calendar();
1538 end_ajax_response();
1539 } else if (!strcasecmp(action, "iconbar_ajax_menu")) {
1540 begin_ajax_response();
1542 end_ajax_response();
1543 } else if (!strcasecmp(action, "iconbar_ajax_rooms")) {
1544 begin_ajax_response();
1545 do_iconbar_roomlist();
1546 end_ajax_response();
1547 } else if (!strcasecmp(action, "knrooms")) {
1549 } else if (!strcasecmp(action, "gotonext")) {
1552 } else if (!strcasecmp(action, "skip")) {
1554 } else if (!strcasecmp(action, "ungoto")) {
1556 } else if (!strcasecmp(action, "dotgoto")) {
1557 if (WC->wc_view != VIEW_MAILBOX) { /* dotgoto acts like dotskip when we're in a mailbox view */
1560 smart_goto(bstr("room"));
1561 } else if (!strcasecmp(action, "dotskip")) {
1562 smart_goto(bstr("room"));
1563 } else if (!strcasecmp(action, "termquit")) {
1565 } else if (!strcasecmp(action, "readnew")) {
1566 readloop("readnew");
1567 } else if (!strcasecmp(action, "readold")) {
1568 readloop("readold");
1569 } else if (!strcasecmp(action, "readfwd")) {
1570 readloop("readfwd");
1571 } else if (!strcasecmp(action, "headers")) {
1572 readloop("headers");
1573 } else if (!strcasecmp(action, "do_search")) {
1574 readloop("do_search");
1575 } else if (!strcasecmp(action, "msg")) {
1576 embed_message(index[1]);
1577 } else if (!strcasecmp(action, "printmsg")) {
1578 print_message(index[1]);
1579 } else if (!strcasecmp(action, "msgheaders")) {
1580 display_headers(index[1]);
1581 } else if (!strcasecmp(action, "wiki")) {
1582 display_wiki_page();
1583 } else if (!strcasecmp(action, "display_enter")) {
1585 } else if (!strcasecmp(action, "post")) {
1587 } else if (!strcasecmp(action, "move_msg")) {
1589 } else if (!strcasecmp(action, "delete_msg")) {
1591 } else if (!strcasecmp(action, "userlist")) {
1593 } else if (!strcasecmp(action, "showuser")) {
1595 } else if (!strcasecmp(action, "display_page")) {
1597 } else if (!strcasecmp(action, "page_user")) {
1599 } else if (!strcasecmp(action, "chat")) {
1601 } else if (!strcasecmp(action, "display_private")) {
1602 display_private("", 0);
1603 } else if (!strcasecmp(action, "goto_private")) {
1605 } else if (!strcasecmp(action, "zapped_list")) {
1607 } else if (!strcasecmp(action, "display_zap")) {
1609 } else if (!strcasecmp(action, "zap")) {
1611 } else if (!strcasecmp(action, "display_entroom")) {
1613 } else if (!strcasecmp(action, "entroom")) {
1615 } else if (!strcasecmp(action, "display_whok")) {
1617 } else if (!strcasecmp(action, "do_invt_kick")) {
1619 } else if (!strcasecmp(action, "display_editroom")) {
1621 } else if (!strcasecmp(action, "netedit")) {
1623 } else if (!strcasecmp(action, "editroom")) {
1625 } else if (!strcasecmp(action, "display_editinfo")) {
1626 display_edit(_("Room info"), "EINF 0", "RINF", "editinfo", 1);
1627 } else if (!strcasecmp(action, "editinfo")) {
1628 save_edit(_("Room info"), "EINF 1", 1);
1629 } else if (!strcasecmp(action, "display_editbio")) {
1630 sprintf(buf, "RBIO %s", WC->wc_fullname);
1631 display_edit(_("Your bio"), "NOOP", buf, "editbio", 3);
1632 } else if (!strcasecmp(action, "editbio")) {
1633 save_edit(_("Your bio"), "EBIO", 0);
1634 } else if (!strcasecmp(action, "confirm_move_msg")) {
1636 } else if (!strcasecmp(action, "delete_room")) {
1638 } else if (!strcasecmp(action, "validate")) {
1640 } else if (!strcasecmp(action, "display_editpic")) {
1641 display_graphics_upload(_("your photo"),
1644 } else if (!strcasecmp(action, "editpic")) {
1645 do_graphics_upload("UIMG 1|_userpic_");
1646 } else if (!strcasecmp(action, "display_editroompic")) {
1647 display_graphics_upload(_("the icon for this room"),
1650 } else if (!strcasecmp(action, "editroompic")) {
1651 do_graphics_upload("UIMG 1|_roompic_");
1652 } else if (!strcasecmp(action, "delete_floor")) {
1654 } else if (!strcasecmp(action, "rename_floor")) {
1656 } else if (!strcasecmp(action, "create_floor")) {
1658 } else if (!strcasecmp(action, "display_editfloorpic")) {
1659 sprintf(buf, "UIMG 0|_floorpic_|%s",
1660 bstr("which_floor"));
1661 display_graphics_upload(_("the icon for this floor"),
1664 } else if (!strcasecmp(action, "editfloorpic")) {
1665 sprintf(buf, "UIMG 1|_floorpic_|%s",
1666 bstr("which_floor"));
1667 do_graphics_upload(buf);
1668 } else if (!strcasecmp(action, "display_reg")) {
1670 } else if (!strcasecmp(action, "display_changepw")) {
1672 } else if (!strcasecmp(action, "changepw")) {
1674 } else if (!strcasecmp(action, "display_edit_node")) {
1675 display_edit_node();
1676 } else if (!strcasecmp(action, "edit_node")) {
1678 } else if (!strcasecmp(action, "display_netconf")) {
1680 } else if (!strcasecmp(action, "display_confirm_delete_node")) {
1681 display_confirm_delete_node();
1682 } else if (!strcasecmp(action, "delete_node")) {
1684 } else if (!strcasecmp(action, "display_add_node")) {
1686 } else if (!strcasecmp(action, "terminate_session")) {
1688 terminate_session();
1689 } else if (!strcasecmp(action, "edit_me")) {
1691 } else if (!strcasecmp(action, "display_siteconfig")) {
1692 display_siteconfig();
1693 } else if (!strcasecmp(action, "chat_recv")) {
1695 } else if (!strcasecmp(action, "chat_send")) {
1697 } else if (!strcasecmp(action, "siteconfig")) {
1699 } else if (!strcasecmp(action, "display_generic")) {
1701 } else if (!strcasecmp(action, "do_generic")) {
1703 } else if (!strcasecmp(action, "ajax_servcmd")) {
1705 } else if (!strcasecmp(action, "display_menubar")) {
1707 } else if (!strcasecmp(action, "mimepart")) {
1708 mimepart(index[1], index[2], 0);
1709 } else if (!strcasecmp(action, "mimepart_download")) {
1710 mimepart(index[1], index[2], 1);
1711 } else if (!strcasecmp(action, "edit_vcard")) {
1713 } else if (!strcasecmp(action, "submit_vcard")) {
1715 } else if (!strcasecmp(action, "select_user_to_edit")) {
1716 select_user_to_edit(NULL, NULL);
1717 } else if (!strcasecmp(action, "display_edituser")) {
1718 display_edituser(NULL, 0);
1719 } else if (!strcasecmp(action, "edituser")) {
1721 } else if (!strcasecmp(action, "create_user")) {
1723 } else if (!strcasecmp(action, "changeview")) {
1725 } else if (!strcasecmp(action, "change_start_page")) {
1726 change_start_page();
1727 } else if (!strcasecmp(action, "display_floorconfig")) {
1728 display_floorconfig(NULL);
1729 } else if (!strcasecmp(action, "toggle_self_service")) {
1730 toggle_self_service();
1731 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1732 } else if (!strcasecmp(action, "display_edit_task")) {
1733 display_edit_task();
1734 } else if (!strcasecmp(action, "save_task")) {
1736 } else if (!strcasecmp(action, "display_edit_event")) {
1737 display_edit_event();
1738 } else if (!strcasecmp(action, "save_event")) {
1740 } else if (!strcasecmp(action, "respond_to_request")) {
1741 respond_to_request();
1742 } else if (!strcasecmp(action, "handle_rsvp")) {
1745 } else if (!strcasecmp(action, "summary")) {
1747 } else if (!strcasecmp(action, "summary_inner_div")) {
1748 begin_ajax_response();
1749 summary_inner_div();
1750 end_ajax_response();
1751 } else if (!strcasecmp(action, "display_customize_iconbar")) {
1752 display_customize_iconbar();
1753 } else if (!strcasecmp(action, "commit_iconbar")) {
1755 } else if (!strcasecmp(action, "set_room_policy")) {
1757 } else if (!strcasecmp(action, "display_inetconf")) {
1759 } else if (!strcasecmp(action, "save_inetconf")) {
1761 } else if (!strcasecmp(action, "display_smtpqueue")) {
1762 display_smtpqueue();
1763 } else if (!strcasecmp(action, "display_smtpqueue_inner_div")) {
1764 display_smtpqueue_inner_div();
1765 } else if (!strcasecmp(action, "display_sieve")) {
1767 } else if (!strcasecmp(action, "save_sieve")) {
1769 } else if (!strcasecmp(action, "display_pushemail")) {
1770 display_pushemail();
1771 } else if (!strcasecmp(action, "save_pushemail")) {
1773 } else if (!strcasecmp(action, "display_add_remove_scripts")) {
1774 display_add_remove_scripts(NULL);
1775 } else if (!strcasecmp(action, "create_script")) {
1777 } else if (!strcasecmp(action, "delete_script")) {
1779 } else if (!strcasecmp(action, "setup_wizard")) {
1781 } else if (!strcasecmp(action, "display_preferences")) {
1782 display_preferences();
1783 } else if (!strcasecmp(action, "set_preferences")) {
1785 } else if (!strcasecmp(action, "recp_autocomplete")) {
1786 recp_autocomplete(bstr("recp"));
1787 } else if (!strcasecmp(action, "cc_autocomplete")) {
1788 recp_autocomplete(bstr("cc"));
1789 } else if (!strcasecmp(action, "bcc_autocomplete")) {
1790 recp_autocomplete(bstr("bcc"));
1791 } else if (!strcasecmp(action, "display_address_book_middle_div")) {
1792 display_address_book_middle_div();
1793 } else if (!strcasecmp(action, "display_address_book_inner_div")) {
1794 display_address_book_inner_div();
1795 } else if (!strcasecmp(action, "set_floordiv_expanded")) {
1796 set_floordiv_expanded(index[1]);
1797 } else if (!strcasecmp(action, "diagnostics")) {
1798 output_headers(1, 1, 1, 0, 0, 0);
1799 wprintf("Session: %d<hr />\n", WC->wc_session);
1800 wprintf("Command: <br /><PRE>\n");
1802 wprintf("</PRE><hr />\n");
1803 wprintf("Variables: <br /><PRE>\n");
1805 wprintf("</PRE><hr />\n");
1807 } else if (!strcasecmp(action, "updatenote")) {
1809 } else if (!strcasecmp(action, "display_room_directory")) {
1810 display_room_directory();
1811 } else if (!strcasecmp(action, "download_file")) {
1812 download_file(index[1]);
1813 } else if (!strcasecmp(action, "upload_file")) {
1817 /** When all else fais, display the main menu. */
1819 display_main_menu();
1824 if (content != NULL) {
1829 if (WC->upload_length > 0) {
1831 WC->upload_length = 0;
1836 * \brief Replacement for sleep() that uses select() in order to avoid SIGALRM
1837 * \param seconds how many seconds should we sleep?
1839 void sleeeeeeeeeep(int seconds)
1843 tv.tv_sec = seconds;
1845 select(0, NULL, NULL, NULL, &tv);