4 * This is the main transaction loop of the web service. It maintains a
5 * persistent session to the Citadel server, handling HTTP WebCit requests as
6 * they arrive and presenting a user interface.
11 #include "webserver.h"
17 * String to unset the cookie.
18 * Any date "in the past" will work, so I chose my birthday, right down to
19 * the exact minute. :)
21 static char *unset = "; expires=28-May-1971 18:10:00 GMT";
24 * \brief remove escaped strings from i.e. the url string (like %20 for blanks)
25 * \param buf the buffer to examine
27 long unescape_input(char *buf)
36 while ((buflen > 0) && (isspace(buf[buflen - 1]))){
46 /* don't let % chars through, rather truncate the input. */
56 sscanf(hex, "%02x", &b);
60 memmove(&buf[a + 1], &buf[a + 3], len);
70 void free_url(void *U)
72 urlcontent *u = (urlcontent*) U;
78 * \brief Extract variables from the URL.
79 * \param url URL supplied by the HTTP parser
81 void addurls(char *url)
83 char *aptr, *bptr, *eptr;
88 struct wcsession *WCC = WC;
90 if (WCC->urlstrings == NULL)
91 WCC->urlstrings = NewHash();
92 eptr = buf + sizeof (buf);
94 /** locate the = sign */
95 n = safestrncpy(buf, up, sizeof buf);
96 if (n < 0) /** hm, we exceeded the buffer... hmmm what todo now? */
99 // while ((up < eptr) && (*up != '?') && (*up != '&'))
101 while (!IsEmptyStr(up)) {
103 while ((aptr < eptr) && (*aptr != '\0') && (*aptr != '='))
110 while ((bptr < eptr) && (*bptr != '\0') &&
111 (*bptr != '&') && (*bptr != ' '))
114 u = (urlcontent *) malloc(sizeof(urlcontent));
117 keylen = safestrncpy(u->url_key, up, sizeof u->url_key);
119 lprintf(1, "URLkey to long! [%s]", up);
123 Put(WCC->urlstrings, u->url_key, keylen, u, free_url);
125 u->url_data = malloc(len + 2);
126 safestrncpy(u->url_data, aptr, len + 2);
127 u->url_data_size = unescape_input(u->url_data);
128 u->url_data[u->url_data_size] = '\0';
132 lprintf(9, "%s = [%ld] %s\n", u->url_key, u->url_data_size, u->url_data);
137 * \brief free urlstring memory
141 DeleteHash(&WC->urlstrings);
145 * \brief Diagnostic function to display the contents of all variables
150 struct wcsession *WCC = WC;
157 Cursor = GetNewHashPos ();
158 while (GetNextHashPos(WCC->urlstrings, Cursor, &HKLen, &HKey, &U)) {
160 wprintf("%38s = %s\n", u->url_key, u->url_data);
165 * \brief Return the value of a variable supplied to the current web page (from the url or a form)
166 * \param key The name of the variable we want
168 const char *BSTR(char *key)
172 if ((WC->urlstrings != NULL) &&
173 GetHash(WC->urlstrings, key, strlen (key), &U))
174 return ((urlcontent *)U)->url_data;
179 const char *Bstr(char *key, size_t keylen)
183 if ((WC->urlstrings != NULL) &&
184 GetHash(WC->urlstrings, key, keylen, &U))
185 return ((urlcontent *)U)->url_data;
191 * \brief web-printing funcion. uses our vsnprintf wrapper
192 * \param format printf format string
193 * \param ... the varargs to put into formatstring
195 void wprintf(const char *format,...)
200 va_start(arg_ptr, format);
201 vsnprintf(wbuf, sizeof wbuf, format, arg_ptr);
204 client_write(wbuf, strlen(wbuf));
209 * \brief wrap up an HTTP session, closes tags, etc.
210 * \todo multiline params?
211 * \param print_standard_html_footer should be set to 0 to transmit only, 1 to
212 * append the main menu and closing tags, or 2 to
213 * append the closing tags only.
215 void wDumpContent(int print_standard_html_footer)
217 if (print_standard_html_footer) {
218 wprintf("</div>\n"); /* end of "text" div */
219 do_template("trailing");
222 /* If we've been saving it all up for one big output burst,
223 * go ahead and do that now.
230 * \brief Copy a string, escaping characters which have meaning in HTML.
231 * \param target target buffer
232 * \param strbuf source buffer
233 * \param nbsp If nonzero, spaces are converted to non-breaking spaces.
234 * \param nolinebreaks if set, linebreaks are removed from the string.
236 long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks)
238 char *aptr, *bptr, *eptr;
243 eptr = target + tSize - 6; // our biggest unit to put in...
245 while ((bptr < eptr) && !IsEmptyStr(aptr) ){
247 memcpy(bptr, "<", 4);
250 else if (*aptr == '>') {
251 memcpy(bptr, ">", 4);
254 else if (*aptr == '&') {
255 memcpy(bptr, "&", 5);
258 else if (*aptr == '\"') {
259 memcpy(bptr, """, 6);
262 else if (*aptr == '\'') {
263 memcpy(bptr, "'", 5);
266 else if (*aptr == LB) {
270 else if (*aptr == RB) {
274 else if (*aptr == QU) {
278 else if ((*aptr == 32) && (nbsp == 1)) {
279 memcpy(bptr, " ", 6);
282 else if ((*aptr == '\n') && (nolinebreaks)) {
283 *bptr='\0'; /* nothing */
285 else if ((*aptr == '\r') && (nolinebreaks)) {
286 *bptr='\0'; /* nothing */
295 if ((bptr = eptr - 1 ) && !IsEmptyStr(aptr) )
297 return (bptr - target);
302 * \param strbuf what???
303 * \param nbsp If nonzero, spaces are converted to non-breaking spaces.
304 * \param nolinebreaks if set, linebreaks are removed from the string.
306 void escputs1(char *strbuf, int nbsp, int nolinebreaks)
311 if (strbuf == NULL) return;
312 Siz = (3 * strlen(strbuf)) + SIZ ;
314 stresc(buf, Siz, strbuf, nbsp, nolinebreaks);
320 * \brief static wrapper for ecsputs1
321 * \param strbuf buffer to print escaped to client
323 void escputs(char *strbuf)
325 escputs1(strbuf, 0, 0);
330 * \brief urlescape buffer and print it to the client
331 * \param strbuf buffer to urlescape
333 void urlescputs(char *strbuf)
337 urlesc(outbuf, SIZ, strbuf);
338 wprintf("%s", outbuf);
343 * \brief Copy a string, escaping characters for JavaScript strings.
344 * \param target output string
345 * \param strbuf input string
347 void jsesc(char *target, size_t tlen, char *strbuf)
356 len = strlen (strbuf);
358 tend = target + tlen;
362 while (!IsEmptyStr(sptr) &&
368 else if (*sptr == '>')
370 else if (*sptr == '\'') {
376 else if (*sptr == '"') {
386 else if (*sptr == '&') {
403 * \brief escape and print java script
404 * \param strbuf the js code
406 void jsescputs(char *strbuf)
410 jsesc(outbuf, SIZ, strbuf);
411 wprintf("%s", outbuf);
415 * \brief Copy a string, escaping characters for message text hold
416 * \param target target buffer
417 * \param strbuf source buffer
419 void msgesc(char *target, size_t tlen, char *strbuf)
428 len = strlen (strbuf);
430 tend = target + tlen;
434 while (!IsEmptyStr(sptr) &&
440 else if (*sptr == '\r')
442 else if (*sptr == '\'') {
459 * \brief print a string to the client after cleaning it with msgesc() and stresc()
460 * \param strbuf string to be printed
462 void msgescputs1( char *strbuf)
468 if (strbuf == NULL) return;
469 buflen = 3 * strlen(strbuf) + SIZ;
470 outbuf = malloc( buflen);
471 outbuf2 = malloc( buflen);
472 msgesc(outbuf, buflen, strbuf);
473 stresc(outbuf2, buflen, outbuf, 0, 0);
474 wprintf("%s", outbuf2);
480 * \brief print a string to the client after cleaning it with msgesc()
481 * \param strbuf string to be printed
483 void msgescputs(char *strbuf) {
487 if (strbuf == NULL) return;
488 len = (3 * strlen(strbuf)) + SIZ;
489 outbuf = malloc(len);
490 msgesc(outbuf, len, strbuf);
491 wprintf("%s", outbuf);
499 * \brief Output all that important stuff that the browser will want to see
501 void output_headers( int do_httpheaders, /**< 1 = output HTTP headers */
502 int do_htmlhead, /**< 1 = output HTML <head> section and <body> opener */
504 int do_room_banner, /**< 0=no, 1=yes,
505 * 2 = I'm going to embed my own, so don't open the
506 * <div id="content"> either.
509 int unset_cookies, /**< 1 = session is terminating, so unset the cookies */
510 int suppress_check, /**< 1 = suppress check for instant messages */
511 int cache /**< 1 = allow browser to cache this page */
516 wprintf("HTTP/1.1 200 OK\n");
517 http_datestring(httpnow, sizeof httpnow, time(NULL));
519 if (do_httpheaders) {
520 wprintf("Content-type: text/html; charset=utf-8\r\n"
522 "Connection: close\r\n",
523 PACKAGE_STRING, serv_info.serv_software
528 wprintf("Pragma: public\r\n"
529 "Cache-Control: max-age=3600, must-revalidate\r\n"
530 "Last-modified: %s\r\n",
535 wprintf("Pragma: no-cache\r\n"
536 "Cache-Control: no-store\r\n"
541 stuff_to_cookie(cookie, 1024, WC->wc_session, WC->wc_username,
542 WC->wc_password, WC->wc_roomname);
545 wprintf("Set-cookie: webcit=%s; path=/\r\n", unset);
547 wprintf("Set-cookie: webcit=%s; path=/\r\n", cookie);
548 if (server_cookie != NULL) {
549 wprintf("%s\n", server_cookie);
555 if (!access("static.local/webcit.css", R_OK)) {
556 svprintf("CSSLOCAL", WCS_STRING,
557 "<link href=\"static.local/webcit.css\" rel=\"stylesheet\" type=\"text/css\">"
567 /** check for ImportantMessages (these display in a div overlaying the main screen) */
568 if (!IsEmptyStr(WC->ImportantMessage)) {
569 wprintf("<div id=\"important_message\">\n"
570 "<span class=\"imsg\">");
571 escputs(WC->ImportantMessage);
572 wprintf("</span><br />\n"
574 "<script type=\"text/javascript\">\n"
575 " setTimeout('hide_imsg_popup()', 5000); \n"
577 WC->ImportantMessage[0] = 0;
580 if ( (WC->logged_in) && (!unset_cookies) ) {
581 wprintf("<div id=\"iconbar\">");
582 do_selected_iconbar();
583 /** check for instant messages (these display in a new window) */
588 if (do_room_banner == 1) {
589 wprintf("<div id=\"banner\">\n");
590 embed_room_banner(NULL, navbar_default);
595 if (do_room_banner == 1) {
596 wprintf("<div id=\"content\">\n");
602 * \brief Generic function to do an HTTP redirect. Easy and fun.
603 * \param whichpage target url to 302 to
605 void http_redirect(char *whichpage) {
606 wprintf("HTTP/1.1 302 Moved Temporarily\n");
607 wprintf("Location: %s\r\n", whichpage);
608 wprintf("URI: %s\r\n", whichpage);
609 wprintf("Content-type: text/html; charset=utf-8\r\n\r\n");
610 wprintf("<html><body>");
611 wprintf("Go <a href=\"%s\">here</A>.", whichpage);
612 wprintf("</body></html>\n");
618 * \brief Output a piece of content to the web browser
620 void http_transmit_thing(char *thing, size_t length, const char *content_type,
623 output_headers(0, 0, 0, 0, 0, is_static);
625 wprintf("Content-type: %s\r\n"
627 "Connection: close\r\n",
632 /** If we can send the data out compressed, please do so. */
634 char *compressed_data = NULL;
635 size_t compressed_len;
637 compressed_len = ((length * 101) / 100) + 100;
638 compressed_data = malloc(compressed_len);
640 if (compress_gzip((Bytef *) compressed_data,
643 (uLongf) length, Z_BEST_SPEED) == Z_OK) {
644 wprintf("Content-encoding: gzip\r\n"
645 "Content-length: %ld\r\n"
647 (long) compressed_len
649 client_write(compressed_data, (size_t)compressed_len);
650 free(compressed_data);
656 /** No compression ... just send it out as-is */
657 wprintf("Content-length: %ld\r\n"
661 client_write(thing, (size_t)length);
665 * \brief print menu box like used in the floor view or admin interface.
666 * This function takes pair of strings as va_args,
667 * \param Title Title string of the box
668 * \param Class CSS Class for the box
669 * \param nLines How many string pairs should we print? (URL, UrlText)
670 * \param ... Pairs of URL Strings and their Names
672 void print_menu_box(char* Title, char *Class, int nLines, ...)
677 svprintf("BOXTITLE", WCS_STRING, Title);
678 do_template("beginbox");
680 wprintf("<ul class=\"%s\">", Class);
682 va_start(arg_list, nLines);
683 for (i = 0; i < nLines; ++i)
685 wprintf("<li><a href=\"%s\">", va_arg(arg_list, char *));
686 wprintf((char *) va_arg(arg_list, char *));
687 wprintf("</a></li>\n");
691 wprintf("</a></li>\n");
695 do_template("endbox");
700 * \brief dump out static pages from disk
701 * \param what the file urs to print
703 void output_static(char *what)
711 const char *content_type;
714 fp = fopen(what, "rb");
716 lprintf(9, "output_static('%s') -- NOT FOUND --\n", what);
717 wprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
718 wprintf("Content-Type: text/plain\r\n");
720 wprintf("Cannot open %s: %s\r\n", what, strerror(errno));
723 content_type = GuessMimeByFilename(what, len);
725 if (fstat(fileno(fp), &statbuf) == -1) {
726 lprintf(9, "output_static('%s') -- FSTAT FAILED --\n", what);
727 wprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
728 wprintf("Content-Type: text/plain\r\n");
730 wprintf("Cannot fstat %s: %s\n", what, strerror(errno));
735 bytes = statbuf.st_size;
736 if ((bigbuffer = malloc(bytes + 2)) == NULL) {
737 lprintf(9, "output_static('%s') -- MALLOC FAILED (%s) --\n", what, strerror(errno));
738 wprintf("HTTP/1.1 500 internal server error\r\n");
739 wprintf("Content-Type: text/plain\r\n");
743 while (count < bytes) {
744 if ((res = fread(bigbuffer + count, 1, bytes - count, fp)) == 0) {
745 lprintf(9, "output_static('%s') -- FREAD FAILED (%s) %zu bytes of %zu --\n", what, strerror(errno), bytes - count, bytes);
746 wprintf("HTTP/1.1 500 internal server error \r\n");
747 wprintf("Content-Type: text/plain\r\n");
756 lprintf(9, "output_static('%s') %s\n", what, content_type);
757 http_transmit_thing(bigbuffer, (size_t)bytes, content_type, 1);
760 if (!strcasecmp(bstr("force_close_session"), "yes")) {
761 end_webcit_session();
766 * \brief When the browser requests an image file from the Citadel server,
767 * this function is called to transmit it.
772 char *xferbuf = NULL;
774 const char *MimeType;
776 serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
777 serv_getln(buf, sizeof buf);
779 bytes = extract_long(&buf[4], 0);
780 xferbuf = malloc(bytes + 2);
782 /** Read it from the server */
783 read_server_binary(xferbuf, bytes);
785 serv_getln(buf, sizeof buf);
787 MimeType = GuessMimeType (xferbuf, bytes);
788 /** Write it to the browser */
789 if (!IsEmptyStr(MimeType))
791 http_transmit_thing(xferbuf,
798 /* hm... unknown mimetype? fallback to blank gif */
804 * Instead of an ugly 404, send a 1x1 transparent GIF
805 * when there's no such image on the server.
808 snprintf (blank_gif, SIZ, "%s%s", static_dirs[0], "/blank.gif");
809 output_static(blank_gif);
813 * \brief Generic function to output an arbitrary MIME part from an arbitrary
814 * message number on the server.
816 * \param msgnum Number of the item on the citadel server
817 * \param partnum The MIME part to be output
818 * \param force_download Nonzero to force set the Content-Type: header
819 * to "application/octet-stream"
821 void mimepart(char *msgnum, char *partnum, int force_download)
825 char content_type[256];
826 char *content = NULL;
828 serv_printf("OPNA %s|%s", msgnum, partnum);
829 serv_getln(buf, sizeof buf);
831 bytes = extract_long(&buf[4], 0);
832 content = malloc(bytes + 2);
833 if (force_download) {
834 strcpy(content_type, "application/octet-stream");
837 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
839 output_headers(0, 0, 0, 0, 0, 0);
840 read_server_binary(content, bytes);
842 serv_getln(buf, sizeof buf);
843 http_transmit_thing(content, bytes, content_type, 0);
846 wprintf("HTTP/1.1 404 %s\n", &buf[4]);
847 output_headers(0, 0, 0, 0, 0, 0);
848 wprintf("Content-Type: text/plain\r\n");
850 wprintf(_("An error occurred while retrieving this part: %s\n"), &buf[4]);
857 * \brief Read any MIME part of a message, from the server, into memory.
858 * \param msgnum number of the message on the citadel server
859 * \param partnum the MIME part to be loaded
861 char *load_mimepart(long msgnum, char *partnum)
865 char content_type[SIZ];
868 serv_printf("DLAT %ld|%s", msgnum, partnum);
869 serv_getln(buf, sizeof buf);
871 bytes = extract_long(&buf[4], 0);
872 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
874 content = malloc(bytes + 2);
875 serv_read(content, bytes);
877 content[bytes] = 0; /* null terminate for good measure */
888 * \brief Convenience functions to display a page containing only a string
889 * \param titlebarcolor color of the titlebar of the frame
890 * \param titlebarmsg text to display in the title bar
891 * \param messagetext body of the box
893 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
895 wprintf("HTTP/1.1 200 OK\n");
896 output_headers(1, 1, 2, 0, 0, 0);
897 wprintf("<div id=\"banner\">\n");
898 wprintf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
899 wprintf("<span class=\"titlebar\">%s</span>\n", titlebarmsg);
900 wprintf("</td></tr></table>\n");
901 wprintf("</div>\n<div id=\"content\">\n");
902 escputs(messagetext);
910 * \brief Display a blank page.
912 void blank_page(void) {
913 output_headers(1, 1, 0, 0, 0, 0);
919 * \brief A template has been requested
921 void url_do_template(void) {
922 do_template(bstr("template"));
928 * \brief Offer to make any page the user's "start page."
930 void offer_start_page(void) {
931 wprintf("<a href=\"change_start_page?startpage=");
932 urlescputs(WC->this_page);
934 wprintf(_("Make this my start page"));
937 wprintf("<br/><a href=\"rss?room=");
938 urlescputs(WC->wc_roomname);
939 wprintf("\" title=\"RSS 2.0 feed for ");
940 escputs(WC->wc_roomname);
941 wprintf("\"><img alt=\"RSS\" border=\"0\" src=\"static/xml_button.gif\"/></a>\n");
947 * \brief Change the user's start page
949 void change_start_page(void) {
951 if (bstr("startpage") == NULL) {
952 safestrncpy(WC->ImportantMessage,
953 _("You no longer have a start page selected."),
954 sizeof WC->ImportantMessage);
959 set_preference("startpage", bstr("startpage"), 1);
961 output_headers(1, 1, 0, 0, 0, 0);
962 do_template("newstartpage");
969 * \brief convenience function to indicate success
970 * \param successmessage the mesage itself
972 void display_success(char *successmessage)
974 convenience_page("007700", "OK", successmessage);
979 * \brief Authorization required page
980 * This is probably temporary and should be revisited
981 * \param message message to put in header
983 void authorization_required(const char *message)
985 wprintf("HTTP/1.1 401 Authorization Required\r\n");
986 wprintf("WWW-Authenticate: Basic realm=\"\"\r\n", serv_info.serv_humannode);
987 wprintf("Content-Type: text/html\r\n\r\n");
989 wprintf(_("Authorization Required"));
990 wprintf("</h1>\r\n");
991 wprintf(_("The resource you requested requires a valid username and password. "
992 "You could not be logged in: %s\n"), message);
997 * \brief This function is called by the MIME parser to handle data uploaded by
998 * the browser. Form data, uploaded files, and the data from HTTP PUT
999 * operations (such as those found in GroupDAV) all arrive this way.
1001 * \param name Name of the item being uploaded
1002 * \param filename Filename of the item being uploaded
1003 * \param partnum MIME part identifier (not needed)
1004 * \param disp MIME content disposition (not needed)
1005 * \param content The actual data
1006 * \param cbtype MIME content-type
1007 * \param cbcharset Character set
1008 * \param length Content length
1009 * \param encoding MIME encoding type (not needed)
1010 * \param userdata Not used here
1012 void upload_handler(char *name, char *filename, char *partnum, char *disp,
1013 void *content, char *cbtype, char *cbcharset,
1014 size_t length, char *encoding, void *userdata)
1018 lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n", name, cbtype, length);
1020 if (WC->urlstrings == NULL)
1021 WC->urlstrings = NewHash();
1024 if ( (length > 0) && (IsEmptyStr(cbtype)) ) {
1025 u = (urlcontent *) malloc(sizeof(urlcontent));
1027 safestrncpy(u->url_key, name, sizeof(u->url_key));
1028 u->url_data = malloc(length + 1);
1029 u->url_data_size = length;
1030 memcpy(u->url_data, content, length);
1031 u->url_data[length] = 0;
1032 Put(WC->urlstrings, u->url_key, strlen(u->url_key), u, free_url);
1034 /* lprintf(9, "Key: <%s> Data: <%s>\n", u->url_key, u->url_data); */
1037 /** Uploaded files */
1038 if ( (length > 0) && (!IsEmptyStr(cbtype)) ) {
1039 WC->upload = malloc(length);
1040 if (WC->upload != NULL) {
1041 WC->upload_length = length;
1042 safestrncpy(WC->upload_filename, filename,
1043 sizeof(WC->upload_filename));
1044 safestrncpy(WC->upload_content_type, cbtype,
1045 sizeof(WC->upload_content_type));
1046 memcpy(WC->upload, content, length);
1049 lprintf(3, "malloc() failed: %s\n", strerror(errno));
1056 * \brief Convenience functions to wrap around asynchronous ajax responses
1058 void begin_ajax_response(void) {
1059 output_headers(0, 0, 0, 0, 0, 0);
1061 wprintf("Content-type: text/html; charset=UTF-8\r\n"
1063 "Connection: close\r\n"
1064 "Pragma: no-cache\r\n"
1065 "Cache-Control: no-cache\r\n"
1073 * \brief print ajax response footer
1075 void end_ajax_response(void) {
1081 * \brief Wraps a Citadel server command in an AJAX transaction.
1083 void ajax_servcmd(void)
1086 char gcontent[1024];
1090 begin_ajax_response();
1092 serv_printf("%s", bstr("g_cmd"));
1093 serv_getln(buf, sizeof buf);
1094 wprintf("%s\n", buf);
1096 if (buf[0] == '8') {
1097 serv_printf("\n\n000");
1099 if ((buf[0] == '1') || (buf[0] == '8')) {
1100 while (serv_getln(gcontent, sizeof gcontent), strcmp(gcontent, "000")) {
1101 wprintf("%s\n", gcontent);
1105 if (buf[0] == '4') {
1106 text_to_server(bstr("g_input"));
1109 if (buf[0] == '6') {
1110 len = atol(&buf[4]);
1112 serv_read(junk, len);
1115 if (buf[0] == '7') {
1116 len = atol(&buf[4]);
1118 memset(junk, 0, len);
1119 serv_write(junk, len);
1123 end_ajax_response();
1126 * This is kind of an ugly hack, but this is the only place it can go.
1127 * If the command was GEXP, then the instant messenger window must be
1128 * running, so reset the "last_pager_check" watchdog timer so
1129 * that page_popup() doesn't try to open it a second time.
1131 if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) {
1132 WC->last_pager_check = time(NULL);
1138 * \brief Helper function for the asynchronous check to see if we need
1139 * to open the instant messenger window.
1141 void seconds_since_last_gexp(void)
1145 begin_ajax_response();
1146 if ( (time(NULL) - WC->last_pager_check) < 30) {
1151 serv_getln(buf, sizeof buf);
1152 if (buf[3] == '*') {
1159 end_ajax_response();
1166 * \brief Entry point for WebCit transaction
1168 void session_loop(struct httprequest *req)
1176 char request_method[128];
1177 char pathname[1024];
1178 int a, b, nBackDots, nEmpty;
1179 int ContentLength = 0;
1181 char ContentType[512];
1182 char *content = NULL;
1183 char *content_end = NULL;
1184 struct httprequest *hptr;
1185 char browser_host[256];
1186 char user_agent[256];
1192 * We stuff these with the values coming from the client cookies,
1193 * so we can use them to reconnect a timed out session if we have to.
1195 char c_username[SIZ];
1196 char c_password[SIZ];
1197 char c_roomname[SIZ];
1198 char c_httpauth_string[SIZ];
1199 char c_httpauth_user[SIZ];
1200 char c_httpauth_pass[SIZ];
1203 safestrncpy(c_username, "", sizeof c_username);
1204 safestrncpy(c_password, "", sizeof c_password);
1205 safestrncpy(c_roomname, "", sizeof c_roomname);
1206 safestrncpy(c_httpauth_string, "", sizeof c_httpauth_string);
1207 safestrncpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER, sizeof c_httpauth_user);
1208 safestrncpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS, sizeof c_httpauth_pass);
1209 strcpy(browser_host, "");
1211 WC->upload_length = 0;
1217 if (hptr == NULL) return;
1219 safestrncpy(cmd, hptr->line, sizeof cmd);
1221 extract_token(request_method, cmd, 0, ' ', sizeof request_method);
1222 extract_token(pathname, cmd, 1, ' ', sizeof pathname);
1224 /** Figure out the action */
1226 sizes[0] = sizeof action;
1229 index[a] = arg[a-1];
1230 sizes[a] = sizeof arg[a-1];
1232 //// index[9] = &foo; todo
1235 for ( a = 0; a < 9; ++a)
1237 extract_token(index[a], pathname, a + 1, '/', sizes[a]);
1238 if (strstr(index[a], "?")) *strstr(index[a], "?") = 0;
1239 if (strstr(index[a], "&")) *strstr(index[a], "&") = 0;
1240 if (strstr(index[a], " ")) *strstr(index[a], " ") = 0;
1241 if ((index[a][0] == '.') && (index[a][1] == '.'))
1243 if (index[a][0] == '\0')
1247 while (hptr != NULL) {
1248 safestrncpy(buf, hptr->line, sizeof buf);
1249 /* lprintf(9, "HTTP HEADER: %s\n", buf); */
1252 if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
1253 safestrncpy(cookie, &buf[15], sizeof cookie);
1254 cookie_to_stuff(cookie, NULL,
1255 c_username, sizeof c_username,
1256 c_password, sizeof c_password,
1257 c_roomname, sizeof c_roomname);
1259 else if (!strncasecmp(buf, "Authorization: Basic ", 21)) {
1260 CtdlDecodeBase64(c_httpauth_string, &buf[21], strlen(&buf[21]));
1261 extract_token(c_httpauth_user, c_httpauth_string, 0, ':', sizeof c_httpauth_user);
1262 extract_token(c_httpauth_pass, c_httpauth_string, 1, ':', sizeof c_httpauth_pass);
1264 else if (!strncasecmp(buf, "Content-length: ", 16)) {
1265 ContentLength = atoi(&buf[16]);
1267 else if (!strncasecmp(buf, "Content-type: ", 14)) {
1268 safestrncpy(ContentType, &buf[14], sizeof ContentType);
1270 else if (!strncasecmp(buf, "User-agent: ", 12)) {
1271 safestrncpy(user_agent, &buf[12], sizeof user_agent);
1273 else if (!strncasecmp(buf, "X-Forwarded-Host: ", 18)) {
1275 safestrncpy(WC->http_host, &buf[18], sizeof WC->http_host);
1278 else if (!strncasecmp(buf, "Host: ", 6)) {
1279 if (IsEmptyStr(WC->http_host)) {
1280 safestrncpy(WC->http_host, &buf[6], sizeof WC->http_host);
1283 else if (!strncasecmp(buf, "X-Forwarded-For: ", 17)) {
1284 safestrncpy(browser_host, &buf[17], sizeof browser_host);
1285 while (num_tokens(browser_host, ',') > 1) {
1286 remove_token(browser_host, 0, ',');
1288 striplt(browser_host);
1290 /** Only WAP gateways explicitly name this content-type */
1291 else if (strstr(buf, "text/vnd.wap.wml")) {
1296 if (ContentLength > 0) {
1297 content = malloc(ContentLength + SIZ);
1298 memset(content, 0, ContentLength + SIZ);
1299 snprintf(content, ContentLength + SIZ, "Content-type: %s\n"
1300 "Content-length: %d\n\n",
1301 ContentType, ContentLength);
1302 body_start = strlen(content);
1304 /** Read the entire input data at once. */
1305 client_read(WC->http_sock, &content[BytesRead+body_start], ContentLength);
1307 if (!strncasecmp(ContentType, "application/x-www-form-urlencoded", 33)) {
1308 addurls(&content[body_start]);
1309 } else if (!strncasecmp(ContentType, "multipart", 9)) {
1310 content_end = content + ContentLength + body_start;
1311 mime_parser(content, content_end, *upload_handler, NULL, NULL, NULL, 0);
1317 /** make a note of where we are in case the user wants to save it */
1318 safestrncpy(WC->this_page, cmd, sizeof(WC->this_page));
1319 remove_token(WC->this_page, 2, ' ');
1320 remove_token(WC->this_page, 0, ' ');
1322 /** If there are variables in the URL, we must grab them now */
1324 for (a = 0; a < len; ++a) {
1325 if ((cmd[a] == '?') || (cmd[a] == '&')) {
1326 for (b = a; b < len; ++b) {
1327 if (isspace(cmd[b])){
1332 addurls(&cmd[a + 1]);
1338 /** If it's a "force 404" situation then display the error and bail. */
1339 if (!strcmp(action, "404")) {
1340 wprintf("HTTP/1.1 404 Not found\r\n");
1341 wprintf("Content-Type: text/plain\r\n");
1343 wprintf("Not found\r\n");
1344 goto SKIP_ALL_THIS_CRAP;
1347 /** Static content can be sent without connecting to Citadel. */
1349 for (a=0; a<ndirs; ++a) {
1350 if (!strcasecmp(action, (char*)static_content_dirs[a])) { /* map web to disk location */
1358 snprintf(buf, sizeof buf, "%s/%s/%s/%s/%s/%s/%s/%s",
1359 static_dirs[n_static],
1360 index[1], index[2], index[3], index[4], index[5], index[6], index[7]);
1361 for (a=0; a<8; ++a) {
1362 if (buf[strlen(buf)-1] == '/') {
1363 buf[strlen(buf)-1] = 0;
1366 for (a = 0; a < strlen(buf); ++a) {
1367 if (isspace(buf[a])) {
1375 lprintf(9, "Suspicious request. Ignoring.");
1376 wprintf("HTTP/1.1 404 Security check failed\r\n");
1377 wprintf("Content-Type: text/plain\r\n");
1379 wprintf("You have sent a malformed or invalid request.\r\n");
1381 goto SKIP_ALL_THIS_CRAP; /* Don't try to connect */
1384 /* If the client sent a nonce that is incorrect, kill the request. */
1385 if (strlen(bstr("nonce")) > 0) {
1386 lprintf(9, "Comparing supplied nonce %s to session nonce %ld\n",
1387 bstr("nonce"), WC->nonce);
1388 if (atoi(bstr("nonce")) != WC->nonce) {
1389 lprintf(9, "Ignoring request with mismatched nonce.\n");
1390 wprintf("HTTP/1.1 404 Security check failed\r\n");
1391 wprintf("Content-Type: text/plain\r\n");
1393 wprintf("Security check failed.\r\n");
1394 goto SKIP_ALL_THIS_CRAP;
1399 * If we're not connected to a Citadel server, try to hook up the
1402 if (!WC->connected) {
1403 if (!strcasecmp(ctdlhost, "uds")) {
1404 /* unix domain socket */
1405 snprintf(buf, SIZ, "%s/citadel.socket", ctdlport);
1406 WC->serv_sock = uds_connectsock(buf);
1410 WC->serv_sock = tcp_connectsock(ctdlhost, ctdlport);
1413 if (WC->serv_sock < 0) {
1415 goto SKIP_ALL_THIS_CRAP;
1419 serv_getln(buf, sizeof buf); /** get the server welcome message */
1422 * From what host is our user connecting? Go with
1423 * the host at the other end of the HTTP socket,
1424 * unless we are following X-Forwarded-For: headers
1425 * and such a header has already turned up something.
1427 if ( (!follow_xff) || (strlen(browser_host) == 0) ) {
1428 locate_host(browser_host, WC->http_sock);
1431 get_serv_info(browser_host, user_agent);
1432 if (serv_info.serv_rev_level < MINIMUM_CIT_VERSION) {
1433 wprintf(_("You are connected to a Citadel "
1434 "server running Citadel %d.%02d. \n"
1435 "In order to run this version of WebCit "
1436 "you must also have Citadel %d.%02d or"
1438 serv_info.serv_rev_level / 100,
1439 serv_info.serv_rev_level % 100,
1440 MINIMUM_CIT_VERSION / 100,
1441 MINIMUM_CIT_VERSION % 100
1443 end_webcit_session();
1444 goto SKIP_ALL_THIS_CRAP;
1450 * Functions which can be performed without logging in
1452 if (!strcasecmp(action, "listsub")) {
1454 goto SKIP_ALL_THIS_CRAP;
1456 if (!strcasecmp(action, "freebusy")) {
1458 goto SKIP_ALL_THIS_CRAP;
1462 * If we're not logged in, but we have HTTP Authentication data,
1463 * try logging in to Citadel using that.
1465 if ((!WC->logged_in)
1466 && (strlen(c_httpauth_user) > 0)
1467 && (strlen(c_httpauth_pass) > 0)) {
1468 serv_printf("USER %s", c_httpauth_user);
1469 serv_getln(buf, sizeof buf);
1470 if (buf[0] == '3') {
1471 serv_printf("PASS %s", c_httpauth_pass);
1472 serv_getln(buf, sizeof buf);
1473 if (buf[0] == '2') {
1474 become_logged_in(c_httpauth_user,
1475 c_httpauth_pass, buf);
1476 safestrncpy(WC->httpauth_user, c_httpauth_user, sizeof WC->httpauth_user);
1477 safestrncpy(WC->httpauth_pass, c_httpauth_pass, sizeof WC->httpauth_pass);
1479 /** Should only display when password is wrong */
1480 authorization_required(&buf[4]);
1481 goto SKIP_ALL_THIS_CRAP;
1486 /** This needs to run early */
1488 if (!strcasecmp(action, "rss")) {
1489 display_rss(bstr("room"), request_method);
1490 goto SKIP_ALL_THIS_CRAP;
1495 * The GroupDAV stuff relies on HTTP authentication instead of
1496 * our session's authentication.
1498 if (!strncasecmp(action, "groupdav", 8)) {
1499 groupdav_main(req, ContentType, /* do GroupDAV methods */
1500 ContentLength, content+body_start);
1501 if (!WC->logged_in) {
1502 WC->killthis = 1; /* If not logged in, don't */
1503 } /* keep the session active */
1504 goto SKIP_ALL_THIS_CRAP;
1509 * Automatically send requests with any method other than GET or
1510 * POST to the GroupDAV code as well.
1512 if ((strcasecmp(request_method, "GET")) && (strcasecmp(request_method, "POST"))) {
1513 groupdav_main(req, ContentType, /** do GroupDAV methods */
1514 ContentLength, content+body_start);
1515 if (!WC->logged_in) {
1516 WC->killthis = 1; /** If not logged in, don't */
1517 } /** keep the session active */
1518 goto SKIP_ALL_THIS_CRAP;
1522 * If we're not logged in, but we have username and password cookies
1523 * supplied by the browser, try using them to log in.
1525 if ((!WC->logged_in)
1526 && (!IsEmptyStr(c_username))
1527 && (!IsEmptyStr(c_password))) {
1528 serv_printf("USER %s", c_username);
1529 serv_getln(buf, sizeof buf);
1530 if (buf[0] == '3') {
1531 serv_printf("PASS %s", c_password);
1532 serv_getln(buf, sizeof buf);
1533 if (buf[0] == '2') {
1534 become_logged_in(c_username, c_password, buf);
1539 * If we don't have a current room, but a cookie specifying the
1540 * current room is supplied, make an effort to go there.
1542 if ((IsEmptyStr(WC->wc_roomname)) && (!IsEmptyStr(c_roomname))) {
1543 serv_printf("GOTO %s", c_roomname);
1544 serv_getln(buf, sizeof buf);
1545 if (buf[0] == '2') {
1546 safestrncpy(WC->wc_roomname, c_roomname, sizeof WC->wc_roomname);
1550 if (!strcasecmp(action, "image")) {
1552 } else if (!strcasecmp(action, "display_mime_icon")) {
1553 display_mime_icon();
1556 * All functions handled below this point ... make sure we log in
1557 * before doing anything else!
1559 } else if ((!WC->logged_in) && (!strcasecmp(action, "login"))) {
1561 } else if (!WC->logged_in) {
1562 display_login(NULL);
1566 * Various commands...
1569 else if (!strcasecmp(action, "do_welcome")) {
1571 } else if (!strcasecmp(action, "blank")) {
1573 } else if (!strcasecmp(action, "do_template")) {
1575 } else if (!strcasecmp(action, "display_aide_menu")) {
1576 display_aide_menu();
1577 } else if (!strcasecmp(action, "server_shutdown")) {
1579 } else if (!strcasecmp(action, "display_main_menu")) {
1580 display_main_menu();
1581 } else if (!strcasecmp(action, "who")) {
1583 } else if (!strcasecmp(action, "sslg")) {
1584 seconds_since_last_gexp();
1585 } else if (!strcasecmp(action, "who_inner_html")) {
1586 begin_ajax_response();
1588 end_ajax_response();
1589 } else if (!strcasecmp(action, "wholist_section")) {
1590 begin_ajax_response();
1592 end_ajax_response();
1593 } else if (!strcasecmp(action, "new_messages_html")) {
1594 begin_ajax_response();
1595 new_messages_section();
1596 end_ajax_response();
1597 } else if (!strcasecmp(action, "tasks_inner_html")) {
1598 begin_ajax_response();
1600 end_ajax_response();
1601 } else if (!strcasecmp(action, "calendar_inner_html")) {
1602 begin_ajax_response();
1604 end_ajax_response();
1605 } else if (!strcasecmp(action, "mini_calendar")) {
1606 begin_ajax_response();
1607 ajax_mini_calendar();
1608 end_ajax_response();
1609 } else if (!strcasecmp(action, "iconbar_ajax_menu")) {
1610 begin_ajax_response();
1612 end_ajax_response();
1613 } else if (!strcasecmp(action, "iconbar_ajax_rooms")) {
1614 begin_ajax_response();
1615 do_iconbar_roomlist();
1616 end_ajax_response();
1617 } else if (!strcasecmp(action, "knrooms")) {
1619 } else if (!strcasecmp(action, "gotonext")) {
1622 } else if (!strcasecmp(action, "skip")) {
1624 } else if (!strcasecmp(action, "ungoto")) {
1626 } else if (!strcasecmp(action, "dotgoto")) {
1627 if (WC->wc_view != VIEW_MAILBOX) { /* dotgoto acts like dotskip when we're in a mailbox view */
1630 smart_goto(bstr("room"));
1631 } else if (!strcasecmp(action, "dotskip")) {
1632 smart_goto(bstr("room"));
1633 } else if (!strcasecmp(action, "termquit")) {
1635 } else if (!strcasecmp(action, "readnew")) {
1636 readloop("readnew");
1637 } else if (!strcasecmp(action, "readold")) {
1638 readloop("readold");
1639 } else if (!strcasecmp(action, "readfwd")) {
1640 readloop("readfwd");
1641 } else if (!strcasecmp(action, "headers")) {
1642 readloop("headers");
1643 } else if (!strcasecmp(action, "do_search")) {
1644 readloop("do_search");
1645 } else if (!strcasecmp(action, "msg")) {
1646 embed_message(index[1]);
1647 } else if (!strcasecmp(action, "printmsg")) {
1648 print_message(index[1]);
1649 } else if (!strcasecmp(action, "msgheaders")) {
1650 display_headers(index[1]);
1651 } else if (!strcasecmp(action, "wiki")) {
1652 display_wiki_page();
1653 } else if (!strcasecmp(action, "display_enter")) {
1655 } else if (!strcasecmp(action, "post")) {
1657 } else if (!strcasecmp(action, "move_msg")) {
1659 } else if (!strcasecmp(action, "delete_msg")) {
1661 } else if (!strcasecmp(action, "userlist")) {
1663 } else if (!strcasecmp(action, "showuser")) {
1665 } else if (!strcasecmp(action, "display_page")) {
1667 } else if (!strcasecmp(action, "page_user")) {
1669 } else if (!strcasecmp(action, "chat")) {
1671 } else if (!strcasecmp(action, "display_private")) {
1672 display_private("", 0);
1673 } else if (!strcasecmp(action, "goto_private")) {
1675 } else if (!strcasecmp(action, "zapped_list")) {
1677 } else if (!strcasecmp(action, "display_zap")) {
1679 } else if (!strcasecmp(action, "zap")) {
1681 } else if (!strcasecmp(action, "display_entroom")) {
1683 } else if (!strcasecmp(action, "entroom")) {
1685 } else if (!strcasecmp(action, "display_whok")) {
1687 } else if (!strcasecmp(action, "do_invt_kick")) {
1689 } else if (!strcasecmp(action, "display_editroom")) {
1691 } else if (!strcasecmp(action, "netedit")) {
1693 } else if (!strcasecmp(action, "editroom")) {
1695 } else if (!strcasecmp(action, "display_editinfo")) {
1696 display_edit(_("Room info"), "EINF 0", "RINF", "editinfo", 1);
1697 } else if (!strcasecmp(action, "editinfo")) {
1698 save_edit(_("Room info"), "EINF 1", 1);
1699 } else if (!strcasecmp(action, "display_editbio")) {
1700 snprintf(buf, SIZ, "RBIO %s", WC->wc_fullname);
1701 display_edit(_("Your bio"), "NOOP", buf, "editbio", 3);
1702 } else if (!strcasecmp(action, "editbio")) {
1703 save_edit(_("Your bio"), "EBIO", 0);
1704 } else if (!strcasecmp(action, "confirm_move_msg")) {
1706 } else if (!strcasecmp(action, "delete_room")) {
1708 } else if (!strcasecmp(action, "validate")) {
1710 /* The users photo display / upload facility */
1711 } else if (!strcasecmp(action, "display_editpic")) {
1712 display_graphics_upload(_("your photo"),
1715 } else if (!strcasecmp(action, "editpic")) {
1716 do_graphics_upload("_userpic_");
1717 /* room picture dispay / upload facility */
1718 } else if (!strcasecmp(action, "display_editroompic")) {
1719 display_graphics_upload(_("the icon for this room"),
1722 } else if (!strcasecmp(action, "editroompic")) {
1723 do_graphics_upload("_roompic_");
1724 /* the greetingpage hello pic */
1725 } else if (!strcasecmp(action, "display_edithello")) {
1726 display_graphics_upload(_("the Greetingpicture for the login prompt"),
1729 } else if (!strcasecmp(action, "edithellopic")) {
1730 do_graphics_upload("hello");
1731 /* the logoff banner */
1732 } else if (!strcasecmp(action, "display_editgoodbyepic")) {
1733 display_graphics_upload(_("the Logoff banner picture"),
1734 "UIMG 0|%s|goodbuye",
1736 } else if (!strcasecmp(action, "editgoodbuyepic")) {
1737 do_graphics_upload("UIMG 1|%s|goodbuye");
1739 } else if (!strcasecmp(action, "delete_floor")) {
1741 } else if (!strcasecmp(action, "rename_floor")) {
1743 } else if (!strcasecmp(action, "create_floor")) {
1745 } else if (!strcasecmp(action, "display_editfloorpic")) {
1746 snprintf(buf, SIZ, "UIMG 0|_floorpic_|%s",
1747 bstr("which_floor"));
1748 display_graphics_upload(_("the icon for this floor"),
1751 } else if (!strcasecmp(action, "editfloorpic")) {
1752 snprintf(buf, SIZ, "UIMG 1|_floorpic_|%s",
1753 bstr("which_floor"));
1754 do_graphics_upload(buf);
1755 } else if (!strcasecmp(action, "display_reg")) {
1757 } else if (!strcasecmp(action, "display_changepw")) {
1759 } else if (!strcasecmp(action, "changepw")) {
1761 } else if (!strcasecmp(action, "display_edit_node")) {
1762 display_edit_node();
1763 } else if (!strcasecmp(action, "edit_node")) {
1765 } else if (!strcasecmp(action, "display_netconf")) {
1767 } else if (!strcasecmp(action, "display_confirm_delete_node")) {
1768 display_confirm_delete_node();
1769 } else if (!strcasecmp(action, "delete_node")) {
1771 } else if (!strcasecmp(action, "display_add_node")) {
1773 } else if (!strcasecmp(action, "terminate_session")) {
1775 terminate_session();
1776 } else if (!strcasecmp(action, "edit_me")) {
1778 } else if (!strcasecmp(action, "display_siteconfig")) {
1779 display_siteconfig();
1780 } else if (!strcasecmp(action, "chat_recv")) {
1782 } else if (!strcasecmp(action, "chat_send")) {
1784 } else if (!strcasecmp(action, "siteconfig")) {
1786 } else if (!strcasecmp(action, "display_generic")) {
1788 } else if (!strcasecmp(action, "do_generic")) {
1790 } else if (!strcasecmp(action, "ajax_servcmd")) {
1792 } else if (!strcasecmp(action, "display_menubar")) {
1794 } else if (!strcasecmp(action, "mimepart")) {
1795 mimepart(index[1], index[2], 0);
1796 } else if (!strcasecmp(action, "mimepart_download")) {
1797 mimepart(index[1], index[2], 1);
1798 } else if (!strcasecmp(action, "edit_vcard")) {
1800 } else if (!strcasecmp(action, "submit_vcard")) {
1802 } else if (!strcasecmp(action, "select_user_to_edit")) {
1803 select_user_to_edit(NULL, NULL);
1804 } else if (!strcasecmp(action, "display_edituser")) {
1805 display_edituser(NULL, 0);
1806 } else if (!strcasecmp(action, "edituser")) {
1808 } else if (!strcasecmp(action, "create_user")) {
1810 } else if (!strcasecmp(action, "changeview")) {
1812 } else if (!strcasecmp(action, "change_start_page")) {
1813 change_start_page();
1814 } else if (!strcasecmp(action, "display_floorconfig")) {
1815 display_floorconfig(NULL);
1816 } else if (!strcasecmp(action, "toggle_self_service")) {
1817 toggle_self_service();
1818 } else if (!strcasecmp(action, "display_edit_task")) {
1819 display_edit_task();
1820 } else if (!strcasecmp(action, "save_task")) {
1822 } else if (!strcasecmp(action, "display_edit_event")) {
1823 display_edit_event();
1824 } else if (!strcasecmp(action, "save_event")) {
1826 } else if (!strcasecmp(action, "respond_to_request")) {
1827 respond_to_request();
1828 } else if (!strcasecmp(action, "handle_rsvp")) {
1830 } else if (!strcasecmp(action, "summary")) {
1832 } else if (!strcasecmp(action, "summary_inner_div")) {
1833 begin_ajax_response();
1834 summary_inner_div();
1835 end_ajax_response();
1836 } else if (!strcasecmp(action, "display_customize_iconbar")) {
1837 display_customize_iconbar();
1838 } else if (!strcasecmp(action, "commit_iconbar")) {
1840 } else if (!strcasecmp(action, "set_room_policy")) {
1842 } else if (!strcasecmp(action, "display_inetconf")) {
1844 } else if (!strcasecmp(action, "save_inetconf")) {
1846 } else if (!strcasecmp(action, "display_smtpqueue")) {
1847 display_smtpqueue();
1848 } else if (!strcasecmp(action, "display_smtpqueue_inner_div")) {
1849 display_smtpqueue_inner_div();
1850 } else if (!strcasecmp(action, "display_sieve")) {
1852 } else if (!strcasecmp(action, "save_sieve")) {
1854 } else if (!strcasecmp(action, "display_pushemail")) {
1855 display_pushemail();
1856 } else if (!strcasecmp(action, "save_pushemail")) {
1858 } else if (!strcasecmp(action, "display_add_remove_scripts")) {
1859 display_add_remove_scripts(NULL);
1860 } else if (!strcasecmp(action, "create_script")) {
1862 } else if (!strcasecmp(action, "delete_script")) {
1864 } else if (!strcasecmp(action, "setup_wizard")) {
1866 } else if (!strcasecmp(action, "display_preferences")) {
1867 display_preferences();
1868 } else if (!strcasecmp(action, "set_preferences")) {
1870 } else if (!strcasecmp(action, "recp_autocomplete")) {
1871 recp_autocomplete(bstr("recp"));
1872 } else if (!strcasecmp(action, "cc_autocomplete")) {
1873 recp_autocomplete(bstr("cc"));
1874 } else if (!strcasecmp(action, "bcc_autocomplete")) {
1875 recp_autocomplete(bstr("bcc"));
1876 } else if (!strcasecmp(action, "display_address_book_middle_div")) {
1877 display_address_book_middle_div();
1878 } else if (!strcasecmp(action, "display_address_book_inner_div")) {
1879 display_address_book_inner_div();
1880 } else if (!strcasecmp(action, "set_floordiv_expanded")) {
1881 set_floordiv_expanded(index[1]);
1882 } else if (!strcasecmp(action, "diagnostics")) {
1883 output_headers(1, 1, 1, 0, 0, 0);
1884 wprintf("Session: %d<hr />\n", WC->wc_session);
1885 wprintf("Command: <br /><PRE>\n");
1887 wprintf("</PRE><hr />\n");
1888 wprintf("Variables: <br /><PRE>\n");
1890 wprintf("</PRE><hr />\n");
1892 } else if (!strcasecmp(action, "updatenote")) {
1894 } else if (!strcasecmp(action, "display_room_directory")) {
1895 display_room_directory();
1896 } else if (!strcasecmp(action, "display_pictureview")) {
1897 display_pictureview();
1898 } else if (!strcasecmp(action, "download_file")) {
1899 download_file(index[1]);
1900 } else if (!strcasecmp(action, "upload_file")) {
1904 /** When all else fais, display the main menu. */
1906 display_main_menu();
1911 if (content != NULL) {
1916 if (WC->upload_length > 0) {
1918 WC->upload_length = 0;
1923 * \brief Replacement for sleep() that uses select() in order to avoid SIGALRM
1924 * \param seconds how many seconds should we sleep?
1926 void sleeeeeeeeeep(int seconds)
1930 tv.tv_sec = seconds;
1932 select(0, NULL, NULL, NULL, &tv);