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]))){
51 sscanf(hex, "%02x", &b);
53 memmove(&buf[a + 1], &buf[a + 3], buflen - a - 2);
63 * \brief Extract variables from the URL.
64 * \param url URL supplied by the HTTP parser
66 void addurls(char *url)
74 while (!IsEmptyStr(up)) {
76 /** locate the = sign */
77 safestrncpy(buf, up, sizeof buf);
79 for (a = 255; a >= 0; --a)
86 u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
87 u->next = WC->urlstrings;
89 safestrncpy(u->url_key, buf, sizeof u->url_key);
91 /** now chop that part off */
92 for (a = 0; a <= b; ++a)
95 /** locate "&" and "?" delimiters */
98 for (a = 0; a < len; ++a) {
99 if ( (ptr[0] == '&') || (ptr[0] == '?') ) {
109 u->url_data = malloc(len + 2);
110 safestrncpy(u->url_data, up, b + 1);
112 unescape_input(u->url_data);
116 /* lprintf(9, "%s = %s\n", u->url_key, u->url_data); */
121 * \brief free urlstring memory
125 struct urlcontent *u;
127 while (WC->urlstrings != NULL) {
128 free(WC->urlstrings->url_data);
129 u = WC->urlstrings->next;
130 free(WC->urlstrings);
136 * \brief Diagnostic function to display the contents of all variables
140 struct urlcontent *u;
142 for (u = WC->urlstrings; u != NULL; u = u->next) {
143 wprintf("%38s = %s\n", u->url_key, u->url_data);
148 * \brief Return the value of a variable supplied to the current web page (from the url or a form)
149 * \param key The name of the variable we want
151 char *bstr(char *key)
153 struct urlcontent *u;
155 for (u = WC->urlstrings; u != NULL; u = u->next) {
156 if (!strcasecmp(u->url_key, key))
157 return (u->url_data);
163 * \brief web-printing funcion. uses our vsnprintf wrapper
164 * \param format printf format string
165 * \param ... the varargs to put into formatstring
167 void wprintf(const char *format,...)
172 va_start(arg_ptr, format);
173 vsnprintf(wbuf, sizeof wbuf, format, arg_ptr);
176 client_write(wbuf, strlen(wbuf));
181 * \brief wrap up an HTTP session, closes tags, etc.
182 * \todo multiline params?
183 * \param print_standard_html_footer should be set to 0 to transmit only, 1 to
184 * append the main menu and closing tags, or 2 to
185 * append the closing tags only.
187 void wDumpContent(int print_standard_html_footer)
189 if (print_standard_html_footer) {
190 wprintf("</div>\n"); /* end of "text" div */
191 do_template("trailing");
194 /* If we've been saving it all up for one big output burst,
195 * go ahead and do that now.
202 * \brief Copy a string, escaping characters which have meaning in HTML.
203 * \param target target buffer
204 * \param strbuf source buffer
205 * \param nbsp If nonzero, spaces are converted to non-breaking spaces.
206 * \param nolinebreaks if set, linebreaks are removed from the string.
208 long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks)
210 char *aptr, *bptr, *eptr;
215 eptr = target + tSize - 6; // our biggest unit to put in...
217 while ((bptr < eptr) && !IsEmptyStr(aptr) ){
219 memcpy(bptr, "<", 4);
222 else if (*aptr == '>') {
223 memcpy(bptr, ">", 4);
226 else if (*aptr == '&') {
227 memcpy(bptr, "&", 5);
230 else if (*aptr == '\"') {
231 memcpy(bptr, """, 6);
234 else if (*aptr == '\'') {
235 memcpy(bptr, "'", 5);
238 else if (*aptr == LB) {
242 else if (*aptr == RB) {
246 else if (*aptr == QU) {
250 else if ((*aptr == 32) && (nbsp == 1)) {
251 memcpy(bptr, " ", 6);
254 else if ((*aptr == '\n') && (nolinebreaks)) {
255 *bptr='\0'; /* nothing */
257 else if ((*aptr == '\r') && (nolinebreaks)) {
258 *bptr='\0'; /* nothing */
267 if ((bptr = eptr - 1 ) && !IsEmptyStr(aptr) )
269 return (bptr - target);
274 * \param strbuf what???
275 * \param nbsp If nonzero, spaces are converted to non-breaking spaces.
276 * \param nolinebreaks if set, linebreaks are removed from the string.
278 void escputs1(char *strbuf, int nbsp, int nolinebreaks)
283 if (strbuf == NULL) return;
284 Siz = (3 * strlen(strbuf)) + SIZ ;
286 stresc(buf, Siz, strbuf, nbsp, nolinebreaks);
292 * \brief static wrapper for ecsputs1
293 * \param strbuf buffer to print escaped to client
295 void escputs(char *strbuf)
297 escputs1(strbuf, 0, 0);
302 * \brief urlescape buffer and print it to the client
303 * \param strbuf buffer to urlescape
305 void urlescputs(char *strbuf)
309 urlesc(outbuf, SIZ, strbuf);
310 wprintf("%s", outbuf);
315 * \brief Copy a string, escaping characters for JavaScript strings.
316 * \param target output string
317 * \param strbuf input string
319 void jsesc(char *target, size_t tlen, char *strbuf)
328 len = strlen (strbuf);
330 tend = target + tlen;
334 while (!IsEmptyStr(sptr) &&
340 else if (*sptr == '>')
342 else if (*sptr == '\'') {
348 else if (*sptr == '"') {
358 else if (*sptr == '&') {
375 * \brief escape and print java script
376 * \param strbuf the js code
378 void jsescputs(char *strbuf)
382 jsesc(outbuf, SIZ, strbuf);
383 wprintf("%s", outbuf);
387 * \brief Copy a string, escaping characters for message text hold
388 * \param target target buffer
389 * \param strbuf source buffer
391 void msgesc(char *target, size_t tlen, char *strbuf)
400 len = strlen (strbuf);
402 tend = target + tlen;
406 while (!IsEmptyStr(sptr) &&
412 else if (*sptr == '\r')
414 else if (*sptr == '\'') {
431 * \brief print a string to the client after cleaning it with msgesc() and stresc()
432 * \param strbuf string to be printed
434 void msgescputs1( char *strbuf)
440 if (strbuf == NULL) return;
441 buflen = 3 * strlen(strbuf) + SIZ;
442 outbuf = malloc( buflen);
443 outbuf2 = malloc( buflen);
444 msgesc(outbuf, buflen, strbuf);
445 stresc(outbuf2, buflen, outbuf, 0, 0);
446 wprintf("%s", outbuf2);
452 * \brief print a string to the client after cleaning it with msgesc()
453 * \param strbuf string to be printed
455 void msgescputs(char *strbuf) {
459 if (strbuf == NULL) return;
460 len = (3 * strlen(strbuf)) + SIZ;
461 outbuf = malloc(len);
462 msgesc(outbuf, len, strbuf);
463 wprintf("%s", outbuf);
471 * \brief Output all that important stuff that the browser will want to see
473 void output_headers( int do_httpheaders, /**< 1 = output HTTP headers */
474 int do_htmlhead, /**< 1 = output HTML <head> section and <body> opener */
476 int do_room_banner, /**< 0=no, 1=yes,
477 * 2 = I'm going to embed my own, so don't open the
478 * <div id="content"> either.
481 int unset_cookies, /**< 1 = session is terminating, so unset the cookies */
482 int suppress_check, /**< 1 = suppress check for instant messages */
483 int cache /**< 1 = allow browser to cache this page */
488 wprintf("HTTP/1.1 200 OK\n");
489 http_datestring(httpnow, sizeof httpnow, time(NULL));
491 if (do_httpheaders) {
492 wprintf("Content-type: text/html; charset=utf-8\r\n"
494 "Connection: close\r\n",
495 PACKAGE_STRING, serv_info.serv_software
500 wprintf("Pragma: public\r\n"
501 "Cache-Control: max-age=3600, must-revalidate\r\n"
502 "Last-modified: %s\r\n",
507 wprintf("Pragma: no-cache\r\n"
508 "Cache-Control: no-store\r\n"
513 stuff_to_cookie(cookie, 1024, WC->wc_session, WC->wc_username,
514 WC->wc_password, WC->wc_roomname);
517 wprintf("Set-cookie: webcit=%s; path=/\r\n", unset);
519 wprintf("Set-cookie: webcit=%s; path=/\r\n", cookie);
520 if (server_cookie != NULL) {
521 wprintf("%s\n", server_cookie);
527 if (!access("static.local/webcit.css", R_OK)) {
528 svprintf("CSSLOCAL", WCS_STRING,
529 "<link href=\"static.local/webcit.css\" rel=\"stylesheet\" type=\"text/css\">"
539 /** check for ImportantMessages (these display in a div overlaying the main screen) */
540 if (!IsEmptyStr(WC->ImportantMessage)) {
541 wprintf("<div id=\"important_message\">\n"
542 "<span class=\"imsg\">");
543 escputs(WC->ImportantMessage);
544 wprintf("</span><br />\n"
546 "<script type=\"text/javascript\">\n"
547 " setTimeout('hide_imsg_popup()', 5000); \n"
549 WC->ImportantMessage[0] = 0;
552 if ( (WC->logged_in) && (!unset_cookies) ) {
553 wprintf("<div id=\"iconbar\">");
554 do_selected_iconbar();
555 /** check for instant messages (these display in a new window) */
560 if (do_room_banner == 1) {
561 wprintf("<div id=\"banner\">\n");
562 embed_room_banner(NULL, navbar_default);
567 if (do_room_banner == 1) {
568 wprintf("<div id=\"content\">\n");
574 * \brief Generic function to do an HTTP redirect. Easy and fun.
575 * \param whichpage target url to 302 to
577 void http_redirect(char *whichpage) {
578 wprintf("HTTP/1.1 302 Moved Temporarily\n");
579 wprintf("Location: %s\r\n", whichpage);
580 wprintf("URI: %s\r\n", whichpage);
581 wprintf("Content-type: text/html; charset=utf-8\r\n\r\n");
582 wprintf("<html><body>");
583 wprintf("Go <a href=\"%s\">here</A>.", whichpage);
584 wprintf("</body></html>\n");
590 * \brief Output a piece of content to the web browser
592 void http_transmit_thing(char *thing, size_t length, char *content_type,
595 output_headers(0, 0, 0, 0, 0, is_static);
597 wprintf("Content-type: %s\r\n"
599 "Connection: close\r\n",
604 /** If we can send the data out compressed, please do so. */
606 char *compressed_data = NULL;
607 size_t compressed_len;
609 compressed_len = ((length * 101) / 100) + 100;
610 compressed_data = malloc(compressed_len);
612 if (compress_gzip((Bytef *) compressed_data,
615 (uLongf) length, Z_BEST_SPEED) == Z_OK) {
616 wprintf("Content-encoding: gzip\r\n"
617 "Content-length: %ld\r\n"
619 (long) compressed_len
621 client_write(compressed_data, (size_t)compressed_len);
622 free(compressed_data);
628 /** No compression ... just send it out as-is */
629 wprintf("Content-length: %ld\r\n"
633 client_write(thing, (size_t)length);
637 * \brief print menu box like used in the floor view or admin interface.
638 * This function takes pair of strings as va_args,
639 * \param Title Title string of the box
640 * \param Class CSS Class for the box
641 * \param nLines How many string pairs should we print? (URL, UrlText)
642 * \param ... Pairs of URL Strings and their Names
644 void print_menu_box(char* Title, char *Class, int nLines, ...)
649 svprintf("BOXTITLE", WCS_STRING, Title);
650 do_template("beginbox");
652 wprintf("<ul class=\"%s\">", Class);
654 va_start(arg_list, nLines);
655 for (i = 0; i < nLines; ++i)
657 wprintf("<li><a href=\"%s\">", va_arg(arg_list, char *));
658 wprintf((char *) va_arg(arg_list, char *));
659 wprintf("</a></li>\n");
663 wprintf("</a></li>\n");
667 do_template("endbox");
672 * \brief dump out static pages from disk
673 * \param what the file urs to print
675 void output_static(char *what)
683 char content_type[128];
686 fp = fopen(what, "rb");
688 lprintf(9, "output_static('%s') -- NOT FOUND --\n", what);
689 wprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
690 wprintf("Content-Type: text/plain\r\n");
692 wprintf("Cannot open %s: %s\r\n", what, strerror(errno));
695 if (!strncasecmp(&what[len - 4], ".gif", 4))
696 safestrncpy(content_type, "image/gif", sizeof content_type);
697 else if (!strncasecmp(&what[len - 4], ".txt", 4))
698 safestrncpy(content_type, "text/plain", sizeof content_type);
699 else if (!strncasecmp(&what[len - 4], ".css", 4))
700 safestrncpy(content_type, "text/css", sizeof content_type);
701 else if (!strncasecmp(&what[len - 4], ".jpg", 4))
702 safestrncpy(content_type, "image/jpeg", sizeof content_type);
703 else if (!strncasecmp(&what[len - 4], ".png", 4))
704 safestrncpy(content_type, "image/png", sizeof content_type);
705 else if (!strncasecmp(&what[len - 4], ".ico", 4))
706 safestrncpy(content_type, "image/x-icon", sizeof content_type);
707 else if (!strncasecmp(&what[len - 5], ".html", 5))
708 safestrncpy(content_type, "text/html", sizeof content_type);
709 else if (!strncasecmp(&what[len - 4], ".htm", 4))
710 safestrncpy(content_type, "text/html", sizeof content_type);
711 else if (!strncasecmp(&what[len - 4], ".wml", 4))
712 safestrncpy(content_type, "text/vnd.wap.wml", sizeof content_type);
713 else if (!strncasecmp(&what[len - 5], ".wmls", 5))
714 safestrncpy(content_type, "text/vnd.wap.wmlscript", sizeof content_type);
715 else if (!strncasecmp(&what[len - 5], ".wmlc", 5))
716 safestrncpy(content_type, "application/vnd.wap.wmlc", sizeof content_type);
717 else if (!strncasecmp(&what[len - 6], ".wmlsc", 6))
718 safestrncpy(content_type, "application/vnd.wap.wmlscriptc", sizeof content_type);
719 else if (!strncasecmp(&what[len - 5], ".wbmp", 5))
720 safestrncpy(content_type, "image/vnd.wap.wbmp", sizeof content_type);
721 else if (!strncasecmp(&what[len - 3], ".js", 3))
722 safestrncpy(content_type, "text/javascript", sizeof content_type);
724 safestrncpy(content_type, "application/octet-stream", sizeof content_type);
726 if (fstat(fileno(fp), &statbuf) == -1) {
727 lprintf(9, "output_static('%s') -- FSTAT FAILED --\n", what);
728 wprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
729 wprintf("Content-Type: text/plain\r\n");
731 wprintf("Cannot fstat %s: %s\n", what, strerror(errno));
736 bytes = statbuf.st_size;
737 if ((bigbuffer = malloc(bytes + 2)) == NULL) {
738 lprintf(9, "output_static('%s') -- MALLOC FAILED (%s) --\n", what, strerror(errno));
739 wprintf("HTTP/1.1 500 internal server error\r\n");
740 wprintf("Content-Type: text/plain\r\n");
744 while (count < bytes) {
745 if ((res = fread(bigbuffer + count, 1, bytes - count, fp)) == 0) {
746 lprintf(9, "output_static('%s') -- FREAD FAILED (%s) %zu bytes of %zu --\n", what, strerror(errno), bytes - count, bytes);
747 wprintf("HTTP/1.1 500 internal server error \r\n");
748 wprintf("Content-Type: text/plain\r\n");
757 lprintf(9, "output_static('%s') %s\n", what, content_type);
758 http_transmit_thing(bigbuffer, (size_t)bytes, content_type, 1);
761 if (!strcasecmp(bstr("force_close_session"), "yes")) {
762 end_webcit_session();
768 * \brief When the browser requests an image file from the Citadel server,
769 * this function is called to transmit it.
774 char *xferbuf = NULL;
777 serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
778 serv_getln(buf, sizeof buf);
780 bytes = extract_long(&buf[4], 0);
781 xferbuf = malloc(bytes + 2);
783 /** Read it from the server */
784 read_server_binary(xferbuf, bytes);
786 serv_getln(buf, sizeof buf);
788 /** Write it to the browser */
789 http_transmit_thing(xferbuf, (size_t)bytes, "image/gif", 0);
794 * Instead of an ugly 404, send a 1x1 transparent GIF
795 * when there's no such image on the server.
798 snprintf (blank_gif, SIZ, "%s%s", static_dirs[0], "/blank.gif");
799 output_static(blank_gif);
807 * \brief Generic function to output an arbitrary MIME part from an arbitrary
808 * message number on the server.
810 * \param msgnum Number of the item on the citadel server
811 * \param partnum The MIME part to be output
812 * \param force_download Nonzero to force set the Content-Type: header
813 * to "application/octet-stream"
815 void mimepart(char *msgnum, char *partnum, int force_download)
819 char content_type[256];
820 char *content = NULL;
822 serv_printf("OPNA %s|%s", msgnum, partnum);
823 serv_getln(buf, sizeof buf);
825 bytes = extract_long(&buf[4], 0);
826 content = malloc(bytes + 2);
827 if (force_download) {
828 strcpy(content_type, "application/octet-stream");
831 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
833 output_headers(0, 0, 0, 0, 0, 0);
834 read_server_binary(content, bytes);
836 serv_getln(buf, sizeof buf);
837 http_transmit_thing(content, bytes, content_type, 0);
840 wprintf("HTTP/1.1 404 %s\n", &buf[4]);
841 output_headers(0, 0, 0, 0, 0, 0);
842 wprintf("Content-Type: text/plain\r\n");
844 wprintf(_("An error occurred while retrieving this part: %s\n"), &buf[4]);
851 * \brief Read any MIME part of a message, from the server, into memory.
852 * \param msgnum number of the message on the citadel server
853 * \param partnum the MIME part to be loaded
855 char *load_mimepart(long msgnum, char *partnum)
859 char content_type[SIZ];
862 serv_printf("DLAT %ld|%s", msgnum, partnum);
863 serv_getln(buf, sizeof buf);
865 bytes = extract_long(&buf[4], 0);
866 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
868 content = malloc(bytes + 2);
869 serv_read(content, bytes);
871 content[bytes] = 0; /* null terminate for good measure */
882 * \brief Convenience functions to display a page containing only a string
883 * \param titlebarcolor color of the titlebar of the frame
884 * \param titlebarmsg text to display in the title bar
885 * \param messagetext body of the box
887 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
889 wprintf("HTTP/1.1 200 OK\n");
890 output_headers(1, 1, 2, 0, 0, 0);
891 wprintf("<div id=\"banner\">\n");
892 wprintf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
893 wprintf("<span class=\"titlebar\">%s</span>\n", titlebarmsg);
894 wprintf("</td></tr></table>\n");
895 wprintf("</div>\n<div id=\"content\">\n");
896 escputs(messagetext);
904 * \brief Display a blank page.
906 void blank_page(void) {
907 output_headers(1, 1, 0, 0, 0, 0);
913 * \brief A template has been requested
915 void url_do_template(void) {
916 do_template(bstr("template"));
922 * \brief Offer to make any page the user's "start page."
924 void offer_start_page(void) {
925 wprintf("<a href=\"change_start_page?startpage=");
926 urlescputs(WC->this_page);
928 wprintf(_("Make this my start page"));
931 wprintf("<br/><a href=\"rss?room=");
932 urlescputs(WC->wc_roomname);
933 wprintf("\" title=\"RSS 2.0 feed for ");
934 escputs(WC->wc_roomname);
935 wprintf("\"><img alt=\"RSS\" border=\"0\" src=\"static/xml_button.gif\"/></a>\n");
941 * \brief Change the user's start page
943 void change_start_page(void) {
945 if (bstr("startpage") == NULL) {
946 safestrncpy(WC->ImportantMessage,
947 _("You no longer have a start page selected."),
948 sizeof WC->ImportantMessage);
953 set_preference("startpage", bstr("startpage"), 1);
955 output_headers(1, 1, 0, 0, 0, 0);
956 do_template("newstartpage");
963 * \brief convenience function to indicate success
964 * \param successmessage the mesage itself
966 void display_success(char *successmessage)
968 convenience_page("007700", "OK", successmessage);
973 * \brief Authorization required page
974 * This is probably temporary and should be revisited
975 * \param message message to put in header
977 void authorization_required(const char *message)
979 wprintf("HTTP/1.1 401 Authorization Required\r\n");
980 wprintf("WWW-Authenticate: Basic realm=\"\"\r\n", serv_info.serv_humannode);
981 wprintf("Content-Type: text/html\r\n\r\n");
983 wprintf(_("Authorization Required"));
984 wprintf("</h1>\r\n");
985 wprintf(_("The resource you requested requires a valid username and password. "
986 "You could not be logged in: %s\n"), message);
991 * \brief This function is called by the MIME parser to handle data uploaded by
992 * the browser. Form data, uploaded files, and the data from HTTP PUT
993 * operations (such as those found in GroupDAV) all arrive this way.
995 * \param name Name of the item being uploaded
996 * \param filename Filename of the item being uploaded
997 * \param partnum MIME part identifier (not needed)
998 * \param disp MIME content disposition (not needed)
999 * \param content The actual data
1000 * \param cbtype MIME content-type
1001 * \param cbcharset Character set
1002 * \param length Content length
1003 * \param encoding MIME encoding type (not needed)
1004 * \param userdata Not used here
1006 void upload_handler(char *name, char *filename, char *partnum, char *disp,
1007 void *content, char *cbtype, char *cbcharset,
1008 size_t length, char *encoding, void *userdata)
1010 struct urlcontent *u;
1012 lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n", name, cbtype, length);
1015 if ( (length > 0) && (IsEmptyStr(cbtype)) ) {
1016 u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
1017 u->next = WC->urlstrings;
1019 safestrncpy(u->url_key, name, sizeof(u->url_key));
1020 u->url_data = malloc(length + 1);
1021 memcpy(u->url_data, content, length);
1022 u->url_data[length] = 0;
1023 /* lprintf(9, "Key: <%s> Data: <%s>\n", u->url_key, u->url_data); */
1026 /** Uploaded files */
1027 if ( (length > 0) && (!IsEmptyStr(cbtype)) ) {
1028 WC->upload = malloc(length);
1029 if (WC->upload != NULL) {
1030 WC->upload_length = length;
1031 safestrncpy(WC->upload_filename, filename,
1032 sizeof(WC->upload_filename));
1033 safestrncpy(WC->upload_content_type, cbtype,
1034 sizeof(WC->upload_content_type));
1035 memcpy(WC->upload, content, length);
1038 lprintf(3, "malloc() failed: %s\n", strerror(errno));
1045 * \brief Convenience functions to wrap around asynchronous ajax responses
1047 void begin_ajax_response(void) {
1048 output_headers(0, 0, 0, 0, 0, 0);
1050 wprintf("Content-type: text/html; charset=UTF-8\r\n"
1052 "Connection: close\r\n"
1053 "Pragma: no-cache\r\n"
1054 "Cache-Control: no-cache\r\n"
1062 * \brief print ajax response footer
1064 void end_ajax_response(void) {
1070 * \brief Wraps a Citadel server command in an AJAX transaction.
1072 void ajax_servcmd(void)
1075 char gcontent[1024];
1079 begin_ajax_response();
1081 serv_printf("%s", bstr("g_cmd"));
1082 serv_getln(buf, sizeof buf);
1083 wprintf("%s\n", buf);
1085 if (buf[0] == '8') {
1086 serv_printf("\n\n000");
1088 if ((buf[0] == '1') || (buf[0] == '8')) {
1089 while (serv_getln(gcontent, sizeof gcontent), strcmp(gcontent, "000")) {
1090 wprintf("%s\n", gcontent);
1094 if (buf[0] == '4') {
1095 text_to_server(bstr("g_input"));
1098 if (buf[0] == '6') {
1099 len = atol(&buf[4]);
1101 serv_read(junk, len);
1104 if (buf[0] == '7') {
1105 len = atol(&buf[4]);
1107 memset(junk, 0, len);
1108 serv_write(junk, len);
1112 end_ajax_response();
1115 * This is kind of an ugly hack, but this is the only place it can go.
1116 * If the command was GEXP, then the instant messenger window must be
1117 * running, so reset the "last_pager_check" watchdog timer so
1118 * that page_popup() doesn't try to open it a second time.
1120 if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) {
1121 WC->last_pager_check = time(NULL);
1127 * \brief Helper function for the asynchronous check to see if we need
1128 * to open the instant messenger window.
1130 void seconds_since_last_gexp(void)
1134 begin_ajax_response();
1135 if ( (time(NULL) - WC->last_pager_check) < 30) {
1140 serv_getln(buf, sizeof buf);
1141 if (buf[3] == '*') {
1148 end_ajax_response();
1155 * \brief Entry point for WebCit transaction
1157 void session_loop(struct httprequest *req)
1165 char request_method[128];
1166 char pathname[1024];
1167 int a, b, nBackDots, nEmpty;
1168 int ContentLength = 0;
1170 char ContentType[512];
1171 char *content = NULL;
1172 char *content_end = NULL;
1173 struct httprequest *hptr;
1174 char browser_host[256];
1175 char user_agent[256];
1181 * We stuff these with the values coming from the client cookies,
1182 * so we can use them to reconnect a timed out session if we have to.
1184 char c_username[SIZ];
1185 char c_password[SIZ];
1186 char c_roomname[SIZ];
1187 char c_httpauth_string[SIZ];
1188 char c_httpauth_user[SIZ];
1189 char c_httpauth_pass[SIZ];
1192 safestrncpy(c_username, "", sizeof c_username);
1193 safestrncpy(c_password, "", sizeof c_password);
1194 safestrncpy(c_roomname, "", sizeof c_roomname);
1195 safestrncpy(c_httpauth_string, "", sizeof c_httpauth_string);
1196 safestrncpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER, sizeof c_httpauth_user);
1197 safestrncpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS, sizeof c_httpauth_pass);
1198 strcpy(browser_host, "");
1200 WC->upload_length = 0;
1206 if (hptr == NULL) return;
1208 safestrncpy(cmd, hptr->line, sizeof cmd);
1210 extract_token(request_method, cmd, 0, ' ', sizeof request_method);
1211 extract_token(pathname, cmd, 1, ' ', sizeof pathname);
1213 /** Figure out the action */
1215 sizes[0] = sizeof action;
1218 index[a] = arg[a-1];
1219 sizes[a] = sizeof arg[a-1];
1221 //// index[9] = &foo; todo
1224 for ( a = 0; a < 9; ++a)
1226 extract_token(index[a], pathname, a + 1, '/', sizes[a]);
1227 if (strstr(index[a], "?")) *strstr(index[a], "?") = 0;
1228 if (strstr(index[a], "&")) *strstr(index[a], "&") = 0;
1229 if (strstr(index[a], " ")) *strstr(index[a], " ") = 0;
1230 if ((index[a][0] == '.') && (index[a][1] == '.'))
1232 if (index[a][0] == '\0')
1236 while (hptr != NULL) {
1237 safestrncpy(buf, hptr->line, sizeof buf);
1238 /* lprintf(9, "HTTP HEADER: %s\n", buf); */
1241 if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
1242 safestrncpy(cookie, &buf[15], sizeof cookie);
1243 cookie_to_stuff(cookie, NULL,
1244 c_username, sizeof c_username,
1245 c_password, sizeof c_password,
1246 c_roomname, sizeof c_roomname);
1248 else if (!strncasecmp(buf, "Authorization: Basic ", 21)) {
1249 CtdlDecodeBase64(c_httpauth_string, &buf[21], strlen(&buf[21]));
1250 extract_token(c_httpauth_user, c_httpauth_string, 0, ':', sizeof c_httpauth_user);
1251 extract_token(c_httpauth_pass, c_httpauth_string, 1, ':', sizeof c_httpauth_pass);
1253 else if (!strncasecmp(buf, "Content-length: ", 16)) {
1254 ContentLength = atoi(&buf[16]);
1256 else if (!strncasecmp(buf, "Content-type: ", 14)) {
1257 safestrncpy(ContentType, &buf[14], sizeof ContentType);
1259 else if (!strncasecmp(buf, "User-agent: ", 12)) {
1260 safestrncpy(user_agent, &buf[12], sizeof user_agent);
1262 else if (!strncasecmp(buf, "X-Forwarded-Host: ", 18)) {
1264 safestrncpy(WC->http_host, &buf[18], sizeof WC->http_host);
1267 else if (!strncasecmp(buf, "Host: ", 6)) {
1268 if (IsEmptyStr(WC->http_host)) {
1269 safestrncpy(WC->http_host, &buf[6], sizeof WC->http_host);
1272 else if (!strncasecmp(buf, "X-Forwarded-For: ", 17)) {
1273 safestrncpy(browser_host, &buf[17], sizeof browser_host);
1274 while (num_tokens(browser_host, ',') > 1) {
1275 remove_token(browser_host, 0, ',');
1277 striplt(browser_host);
1279 /** Only WAP gateways explicitly name this content-type */
1280 else if (strstr(buf, "text/vnd.wap.wml")) {
1285 if (ContentLength > 0) {
1286 content = malloc(ContentLength + SIZ);
1287 memset(content, 0, ContentLength + SIZ);
1288 snprintf(content, ContentLength + SIZ, "Content-type: %s\n"
1289 "Content-length: %d\n\n",
1290 ContentType, ContentLength);
1291 body_start = strlen(content);
1293 /** Read the entire input data at once. */
1294 client_read(WC->http_sock, &content[BytesRead+body_start], ContentLength);
1296 if (!strncasecmp(ContentType, "application/x-www-form-urlencoded", 33)) {
1297 addurls(&content[body_start]);
1298 } else if (!strncasecmp(ContentType, "multipart", 9)) {
1299 content_end = content + ContentLength + body_start;
1300 mime_parser(content, content_end, *upload_handler, NULL, NULL, NULL, 0);
1306 /** make a note of where we are in case the user wants to save it */
1307 safestrncpy(WC->this_page, cmd, sizeof(WC->this_page));
1308 remove_token(WC->this_page, 2, ' ');
1309 remove_token(WC->this_page, 0, ' ');
1311 /** If there are variables in the URL, we must grab them now */
1313 for (a = 0; a < len; ++a) {
1314 if ((cmd[a] == '?') || (cmd[a] == '&')) {
1315 for (b = a; b < len; ++b) {
1316 if (isspace(cmd[b])){
1321 addurls(&cmd[a + 1]);
1327 /** If it's a "force 404" situation then display the error and bail. */
1328 if (!strcmp(action, "404")) {
1329 wprintf("HTTP/1.1 404 Not found\r\n");
1330 wprintf("Content-Type: text/plain\r\n");
1332 wprintf("Not found\r\n");
1333 goto SKIP_ALL_THIS_CRAP;
1336 /** Static content can be sent without connecting to Citadel. */
1338 for (a=0; a<ndirs; ++a) {
1339 if (!strcasecmp(action, (char*)static_content_dirs[a])) { /* map web to disk location */
1347 snprintf(buf, sizeof buf, "%s/%s/%s/%s/%s/%s/%s/%s",
1348 static_dirs[n_static],
1349 index[1], index[2], index[3], index[4], index[5], index[6], index[7]);
1350 for (a=0; a<8; ++a) {
1351 if (buf[strlen(buf)-1] == '/') {
1352 buf[strlen(buf)-1] = 0;
1355 for (a = 0; a < strlen(buf); ++a) {
1356 if (isspace(buf[a])) {
1364 lprintf(9, "Suspicious request. Ignoring.");
1365 wprintf("HTTP/1.1 404 Security check failed\r\n");
1366 wprintf("Content-Type: text/plain\r\n");
1368 wprintf("You have sent a malformed or invalid request.\r\n");
1370 goto SKIP_ALL_THIS_CRAP; /* Don't try to connect */
1373 /* If the client sent a nonce that is incorrect, kill the request. */
1374 if (strlen(bstr("nonce")) > 0) {
1375 lprintf(9, "Comparing supplied nonce %s to session nonce %ld\n",
1376 bstr("nonce"), WC->nonce);
1377 if (atoi(bstr("nonce")) != WC->nonce) {
1378 lprintf(9, "Ignoring request with mismatched nonce.\n");
1379 wprintf("HTTP/1.1 404 Security check failed\r\n");
1380 wprintf("Content-Type: text/plain\r\n");
1382 wprintf("Security check failed.\r\n");
1383 goto SKIP_ALL_THIS_CRAP;
1388 * If we're not connected to a Citadel server, try to hook up the
1391 if (!WC->connected) {
1392 if (!strcasecmp(ctdlhost, "uds")) {
1393 /* unix domain socket */
1394 snprintf(buf, SIZ, "%s/citadel.socket", ctdlport);
1395 WC->serv_sock = uds_connectsock(buf);
1399 WC->serv_sock = tcp_connectsock(ctdlhost, ctdlport);
1402 if (WC->serv_sock < 0) {
1404 goto SKIP_ALL_THIS_CRAP;
1408 serv_getln(buf, sizeof buf); /** get the server welcome message */
1411 * From what host is our user connecting? Go with
1412 * the host at the other end of the HTTP socket,
1413 * unless we are following X-Forwarded-For: headers
1414 * and such a header has already turned up something.
1416 if ( (!follow_xff) || (strlen(browser_host) == 0) ) {
1417 locate_host(browser_host, WC->http_sock);
1420 get_serv_info(browser_host, user_agent);
1421 if (serv_info.serv_rev_level < MINIMUM_CIT_VERSION) {
1422 wprintf(_("You are connected to a Citadel "
1423 "server running Citadel %d.%02d. \n"
1424 "In order to run this version of WebCit "
1425 "you must also have Citadel %d.%02d or"
1427 serv_info.serv_rev_level / 100,
1428 serv_info.serv_rev_level % 100,
1429 MINIMUM_CIT_VERSION / 100,
1430 MINIMUM_CIT_VERSION % 100
1432 end_webcit_session();
1433 goto SKIP_ALL_THIS_CRAP;
1439 * Functions which can be performed without logging in
1441 if (!strcasecmp(action, "listsub")) {
1443 goto SKIP_ALL_THIS_CRAP;
1445 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1446 if (!strcasecmp(action, "freebusy")) {
1448 goto SKIP_ALL_THIS_CRAP;
1453 * If we're not logged in, but we have HTTP Authentication data,
1454 * try logging in to Citadel using that.
1456 if ((!WC->logged_in)
1457 && (strlen(c_httpauth_user) > 0)
1458 && (strlen(c_httpauth_pass) > 0)) {
1459 serv_printf("USER %s", c_httpauth_user);
1460 serv_getln(buf, sizeof buf);
1461 if (buf[0] == '3') {
1462 serv_printf("PASS %s", c_httpauth_pass);
1463 serv_getln(buf, sizeof buf);
1464 if (buf[0] == '2') {
1465 become_logged_in(c_httpauth_user,
1466 c_httpauth_pass, buf);
1467 safestrncpy(WC->httpauth_user, c_httpauth_user, sizeof WC->httpauth_user);
1468 safestrncpy(WC->httpauth_pass, c_httpauth_pass, sizeof WC->httpauth_pass);
1470 /** Should only display when password is wrong */
1471 authorization_required(&buf[4]);
1472 goto SKIP_ALL_THIS_CRAP;
1477 /** This needs to run early */
1479 if (!strcasecmp(action, "rss")) {
1480 display_rss(bstr("room"), request_method);
1481 goto SKIP_ALL_THIS_CRAP;
1486 * The GroupDAV stuff relies on HTTP authentication instead of
1487 * our session's authentication.
1489 if (!strncasecmp(action, "groupdav", 8)) {
1490 groupdav_main(req, ContentType, /* do GroupDAV methods */
1491 ContentLength, content+body_start);
1492 if (!WC->logged_in) {
1493 WC->killthis = 1; /* If not logged in, don't */
1494 } /* keep the session active */
1495 goto SKIP_ALL_THIS_CRAP;
1500 * Automatically send requests with any method other than GET or
1501 * POST to the GroupDAV code as well.
1503 if ((strcasecmp(request_method, "GET")) && (strcasecmp(request_method, "POST"))) {
1504 groupdav_main(req, ContentType, /** do GroupDAV methods */
1505 ContentLength, content+body_start);
1506 if (!WC->logged_in) {
1507 WC->killthis = 1; /** If not logged in, don't */
1508 } /** keep the session active */
1509 goto SKIP_ALL_THIS_CRAP;
1513 * If we're not logged in, but we have username and password cookies
1514 * supplied by the browser, try using them to log in.
1516 if ((!WC->logged_in)
1517 && (!IsEmptyStr(c_username))
1518 && (!IsEmptyStr(c_password))) {
1519 serv_printf("USER %s", c_username);
1520 serv_getln(buf, sizeof buf);
1521 if (buf[0] == '3') {
1522 serv_printf("PASS %s", c_password);
1523 serv_getln(buf, sizeof buf);
1524 if (buf[0] == '2') {
1525 become_logged_in(c_username, c_password, buf);
1530 * If we don't have a current room, but a cookie specifying the
1531 * current room is supplied, make an effort to go there.
1533 if ((IsEmptyStr(WC->wc_roomname)) && (!IsEmptyStr(c_roomname))) {
1534 serv_printf("GOTO %s", c_roomname);
1535 serv_getln(buf, sizeof buf);
1536 if (buf[0] == '2') {
1537 safestrncpy(WC->wc_roomname, c_roomname, sizeof WC->wc_roomname);
1541 if (!strcasecmp(action, "image")) {
1545 * All functions handled below this point ... make sure we log in
1546 * before doing anything else!
1548 } else if ((!WC->logged_in) && (!strcasecmp(action, "login"))) {
1550 } else if (!WC->logged_in) {
1551 display_login(NULL);
1555 * Various commands...
1558 else if (!strcasecmp(action, "do_welcome")) {
1560 } else if (!strcasecmp(action, "blank")) {
1562 } else if (!strcasecmp(action, "do_template")) {
1564 } else if (!strcasecmp(action, "display_aide_menu")) {
1565 display_aide_menu();
1566 } else if (!strcasecmp(action, "server_shutdown")) {
1568 } else if (!strcasecmp(action, "display_main_menu")) {
1569 display_main_menu();
1570 } else if (!strcasecmp(action, "who")) {
1572 } else if (!strcasecmp(action, "sslg")) {
1573 seconds_since_last_gexp();
1574 } else if (!strcasecmp(action, "who_inner_html")) {
1575 begin_ajax_response();
1577 end_ajax_response();
1578 } else if (!strcasecmp(action, "wholist_section")) {
1579 begin_ajax_response();
1581 end_ajax_response();
1582 } else if (!strcasecmp(action, "new_messages_html")) {
1583 begin_ajax_response();
1584 new_messages_section();
1585 end_ajax_response();
1586 } else if (!strcasecmp(action, "tasks_inner_html")) {
1587 begin_ajax_response();
1589 end_ajax_response();
1590 } else if (!strcasecmp(action, "calendar_inner_html")) {
1591 begin_ajax_response();
1593 end_ajax_response();
1594 } else if (!strcasecmp(action, "mini_calendar")) {
1595 begin_ajax_response();
1596 ajax_mini_calendar();
1597 end_ajax_response();
1598 } else if (!strcasecmp(action, "iconbar_ajax_menu")) {
1599 begin_ajax_response();
1601 end_ajax_response();
1602 } else if (!strcasecmp(action, "iconbar_ajax_rooms")) {
1603 begin_ajax_response();
1604 do_iconbar_roomlist();
1605 end_ajax_response();
1606 } else if (!strcasecmp(action, "knrooms")) {
1608 } else if (!strcasecmp(action, "gotonext")) {
1611 } else if (!strcasecmp(action, "skip")) {
1613 } else if (!strcasecmp(action, "ungoto")) {
1615 } else if (!strcasecmp(action, "dotgoto")) {
1616 if (WC->wc_view != VIEW_MAILBOX) { /* dotgoto acts like dotskip when we're in a mailbox view */
1619 smart_goto(bstr("room"));
1620 } else if (!strcasecmp(action, "dotskip")) {
1621 smart_goto(bstr("room"));
1622 } else if (!strcasecmp(action, "termquit")) {
1624 } else if (!strcasecmp(action, "readnew")) {
1625 readloop("readnew");
1626 } else if (!strcasecmp(action, "readold")) {
1627 readloop("readold");
1628 } else if (!strcasecmp(action, "readfwd")) {
1629 readloop("readfwd");
1630 } else if (!strcasecmp(action, "headers")) {
1631 readloop("headers");
1632 } else if (!strcasecmp(action, "do_search")) {
1633 readloop("do_search");
1634 } else if (!strcasecmp(action, "msg")) {
1635 embed_message(index[1]);
1636 } else if (!strcasecmp(action, "printmsg")) {
1637 print_message(index[1]);
1638 } else if (!strcasecmp(action, "msgheaders")) {
1639 display_headers(index[1]);
1640 } else if (!strcasecmp(action, "wiki")) {
1641 display_wiki_page();
1642 } else if (!strcasecmp(action, "display_enter")) {
1644 } else if (!strcasecmp(action, "post")) {
1646 } else if (!strcasecmp(action, "move_msg")) {
1648 } else if (!strcasecmp(action, "delete_msg")) {
1650 } else if (!strcasecmp(action, "userlist")) {
1652 } else if (!strcasecmp(action, "showuser")) {
1654 } else if (!strcasecmp(action, "display_page")) {
1656 } else if (!strcasecmp(action, "page_user")) {
1658 } else if (!strcasecmp(action, "chat")) {
1660 } else if (!strcasecmp(action, "display_private")) {
1661 display_private("", 0);
1662 } else if (!strcasecmp(action, "goto_private")) {
1664 } else if (!strcasecmp(action, "zapped_list")) {
1666 } else if (!strcasecmp(action, "display_zap")) {
1668 } else if (!strcasecmp(action, "zap")) {
1670 } else if (!strcasecmp(action, "display_entroom")) {
1672 } else if (!strcasecmp(action, "entroom")) {
1674 } else if (!strcasecmp(action, "display_whok")) {
1676 } else if (!strcasecmp(action, "do_invt_kick")) {
1678 } else if (!strcasecmp(action, "display_editroom")) {
1680 } else if (!strcasecmp(action, "netedit")) {
1682 } else if (!strcasecmp(action, "editroom")) {
1684 } else if (!strcasecmp(action, "display_editinfo")) {
1685 display_edit(_("Room info"), "EINF 0", "RINF", "editinfo", 1);
1686 } else if (!strcasecmp(action, "editinfo")) {
1687 save_edit(_("Room info"), "EINF 1", 1);
1688 } else if (!strcasecmp(action, "display_editbio")) {
1689 snprintf(buf, SIZ, "RBIO %s", WC->wc_fullname);
1690 display_edit(_("Your bio"), "NOOP", buf, "editbio", 3);
1691 } else if (!strcasecmp(action, "editbio")) {
1692 save_edit(_("Your bio"), "EBIO", 0);
1693 } else if (!strcasecmp(action, "confirm_move_msg")) {
1695 } else if (!strcasecmp(action, "delete_room")) {
1697 } else if (!strcasecmp(action, "validate")) {
1699 /* The users photo display / upload facility */
1700 } else if (!strcasecmp(action, "display_editpic")) {
1701 display_graphics_upload(_("your photo"),
1704 } else if (!strcasecmp(action, "editpic")) {
1705 do_graphics_upload("UIMG 1|_userpic_");
1706 /* room picture dispay / upload facility */
1707 } else if (!strcasecmp(action, "display_editroompic")) {
1708 display_graphics_upload(_("the icon for this room"),
1711 } else if (!strcasecmp(action, "editroompic")) {
1712 do_graphics_upload("UIMG 1|_roompic_");
1713 /* the greetingpage hello pic */
1714 } else if (!strcasecmp(action, "display_edithello")) {
1715 display_graphics_upload(_("the Greetingpicture for the login prompt"),
1718 } else if (!strcasecmp(action, "edithellopic")) {
1719 do_graphics_upload("UIMG 1|hello.gif");
1720 /* the logoff banner */
1721 } else if (!strcasecmp(action, "display_editgoodbyepic")) {
1722 display_graphics_upload(_("the Logoff banner picture"),
1723 "UIMG 0|goodbuye.gif",
1725 } else if (!strcasecmp(action, "editgoodbuyepic")) {
1726 do_graphics_upload("UIMG 1|goodbuye.gif");
1728 } else if (!strcasecmp(action, "delete_floor")) {
1730 } else if (!strcasecmp(action, "rename_floor")) {
1732 } else if (!strcasecmp(action, "create_floor")) {
1734 } else if (!strcasecmp(action, "display_editfloorpic")) {
1735 snprintf(buf, SIZ, "UIMG 0|_floorpic_|%s",
1736 bstr("which_floor"));
1737 display_graphics_upload(_("the icon for this floor"),
1740 } else if (!strcasecmp(action, "editfloorpic")) {
1741 snprintf(buf, SIZ, "UIMG 1|_floorpic_|%s",
1742 bstr("which_floor"));
1743 do_graphics_upload(buf);
1744 } else if (!strcasecmp(action, "display_reg")) {
1746 } else if (!strcasecmp(action, "display_changepw")) {
1748 } else if (!strcasecmp(action, "changepw")) {
1750 } else if (!strcasecmp(action, "display_edit_node")) {
1751 display_edit_node();
1752 } else if (!strcasecmp(action, "edit_node")) {
1754 } else if (!strcasecmp(action, "display_netconf")) {
1756 } else if (!strcasecmp(action, "display_confirm_delete_node")) {
1757 display_confirm_delete_node();
1758 } else if (!strcasecmp(action, "delete_node")) {
1760 } else if (!strcasecmp(action, "display_add_node")) {
1762 } else if (!strcasecmp(action, "terminate_session")) {
1764 terminate_session();
1765 } else if (!strcasecmp(action, "edit_me")) {
1767 } else if (!strcasecmp(action, "display_siteconfig")) {
1768 display_siteconfig();
1769 } else if (!strcasecmp(action, "chat_recv")) {
1771 } else if (!strcasecmp(action, "chat_send")) {
1773 } else if (!strcasecmp(action, "siteconfig")) {
1775 } else if (!strcasecmp(action, "display_generic")) {
1777 } else if (!strcasecmp(action, "do_generic")) {
1779 } else if (!strcasecmp(action, "ajax_servcmd")) {
1781 } else if (!strcasecmp(action, "display_menubar")) {
1783 } else if (!strcasecmp(action, "mimepart")) {
1784 mimepart(index[1], index[2], 0);
1785 } else if (!strcasecmp(action, "mimepart_download")) {
1786 mimepart(index[1], index[2], 1);
1787 } else if (!strcasecmp(action, "edit_vcard")) {
1789 } else if (!strcasecmp(action, "submit_vcard")) {
1791 } else if (!strcasecmp(action, "select_user_to_edit")) {
1792 select_user_to_edit(NULL, NULL);
1793 } else if (!strcasecmp(action, "display_edituser")) {
1794 display_edituser(NULL, 0);
1795 } else if (!strcasecmp(action, "edituser")) {
1797 } else if (!strcasecmp(action, "create_user")) {
1799 } else if (!strcasecmp(action, "changeview")) {
1801 } else if (!strcasecmp(action, "change_start_page")) {
1802 change_start_page();
1803 } else if (!strcasecmp(action, "display_floorconfig")) {
1804 display_floorconfig(NULL);
1805 } else if (!strcasecmp(action, "toggle_self_service")) {
1806 toggle_self_service();
1807 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1808 } else if (!strcasecmp(action, "display_edit_task")) {
1809 display_edit_task();
1810 } else if (!strcasecmp(action, "save_task")) {
1812 } else if (!strcasecmp(action, "display_edit_event")) {
1813 display_edit_event();
1814 } else if (!strcasecmp(action, "save_event")) {
1816 } else if (!strcasecmp(action, "respond_to_request")) {
1817 respond_to_request();
1818 } else if (!strcasecmp(action, "handle_rsvp")) {
1821 } else if (!strcasecmp(action, "summary")) {
1823 } else if (!strcasecmp(action, "summary_inner_div")) {
1824 begin_ajax_response();
1825 summary_inner_div();
1826 end_ajax_response();
1827 } else if (!strcasecmp(action, "display_customize_iconbar")) {
1828 display_customize_iconbar();
1829 } else if (!strcasecmp(action, "commit_iconbar")) {
1831 } else if (!strcasecmp(action, "set_room_policy")) {
1833 } else if (!strcasecmp(action, "display_inetconf")) {
1835 } else if (!strcasecmp(action, "save_inetconf")) {
1837 } else if (!strcasecmp(action, "display_smtpqueue")) {
1838 display_smtpqueue();
1839 } else if (!strcasecmp(action, "display_smtpqueue_inner_div")) {
1840 display_smtpqueue_inner_div();
1841 } else if (!strcasecmp(action, "display_sieve")) {
1843 } else if (!strcasecmp(action, "save_sieve")) {
1845 } else if (!strcasecmp(action, "display_pushemail")) {
1846 display_pushemail();
1847 } else if (!strcasecmp(action, "save_pushemail")) {
1849 } else if (!strcasecmp(action, "display_add_remove_scripts")) {
1850 display_add_remove_scripts(NULL);
1851 } else if (!strcasecmp(action, "create_script")) {
1853 } else if (!strcasecmp(action, "delete_script")) {
1855 } else if (!strcasecmp(action, "setup_wizard")) {
1857 } else if (!strcasecmp(action, "display_preferences")) {
1858 display_preferences();
1859 } else if (!strcasecmp(action, "set_preferences")) {
1861 } else if (!strcasecmp(action, "recp_autocomplete")) {
1862 recp_autocomplete(bstr("recp"));
1863 } else if (!strcasecmp(action, "cc_autocomplete")) {
1864 recp_autocomplete(bstr("cc"));
1865 } else if (!strcasecmp(action, "bcc_autocomplete")) {
1866 recp_autocomplete(bstr("bcc"));
1867 } else if (!strcasecmp(action, "display_address_book_middle_div")) {
1868 display_address_book_middle_div();
1869 } else if (!strcasecmp(action, "display_address_book_inner_div")) {
1870 display_address_book_inner_div();
1871 } else if (!strcasecmp(action, "set_floordiv_expanded")) {
1872 set_floordiv_expanded(index[1]);
1873 } else if (!strcasecmp(action, "diagnostics")) {
1874 output_headers(1, 1, 1, 0, 0, 0);
1875 wprintf("Session: %d<hr />\n", WC->wc_session);
1876 wprintf("Command: <br /><PRE>\n");
1878 wprintf("</PRE><hr />\n");
1879 wprintf("Variables: <br /><PRE>\n");
1881 wprintf("</PRE><hr />\n");
1883 } else if (!strcasecmp(action, "updatenote")) {
1885 } else if (!strcasecmp(action, "display_room_directory")) {
1886 display_room_directory();
1887 } else if (!strcasecmp(action, "download_file")) {
1888 download_file(index[1]);
1889 } else if (!strcasecmp(action, "upload_file")) {
1893 /** When all else fais, display the main menu. */
1895 display_main_menu();
1900 if (content != NULL) {
1905 if (WC->upload_length > 0) {
1907 WC->upload_length = 0;
1912 * \brief Replacement for sleep() that uses select() in order to avoid SIGALRM
1913 * \param seconds how many seconds should we sleep?
1915 void sleeeeeeeeeep(int seconds)
1919 tv.tv_sec = seconds;
1921 select(0, NULL, NULL, NULL, &tv);