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, const 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();
767 * \brief When the browser requests an image file from the Citadel server,
768 * this function is called to transmit it.
773 char *xferbuf = NULL;
775 const char *MimeType;
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 MimeType = GuessMimeType (xferbuf, bytes);
789 /** Write it to the browser */
790 if (!IsEmptyStr(MimeType))
792 http_transmit_thing(xferbuf,
799 /* hm... unknown mimetype? fallback to blank gif */
805 * Instead of an ugly 404, send a 1x1 transparent GIF
806 * when there's no such image on the server.
809 snprintf (blank_gif, SIZ, "%s%s", static_dirs[0], "/blank.gif");
810 output_static(blank_gif);
814 * \brief Generic function to output an arbitrary MIME part from an arbitrary
815 * message number on the server.
817 * \param msgnum Number of the item on the citadel server
818 * \param partnum The MIME part to be output
819 * \param force_download Nonzero to force set the Content-Type: header
820 * to "application/octet-stream"
822 void mimepart(char *msgnum, char *partnum, int force_download)
826 char content_type[256];
827 char *content = NULL;
829 serv_printf("OPNA %s|%s", msgnum, partnum);
830 serv_getln(buf, sizeof buf);
832 bytes = extract_long(&buf[4], 0);
833 content = malloc(bytes + 2);
834 if (force_download) {
835 strcpy(content_type, "application/octet-stream");
838 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
840 output_headers(0, 0, 0, 0, 0, 0);
841 read_server_binary(content, bytes);
843 serv_getln(buf, sizeof buf);
844 http_transmit_thing(content, bytes, content_type, 0);
847 wprintf("HTTP/1.1 404 %s\n", &buf[4]);
848 output_headers(0, 0, 0, 0, 0, 0);
849 wprintf("Content-Type: text/plain\r\n");
851 wprintf(_("An error occurred while retrieving this part: %s\n"), &buf[4]);
858 * \brief Read any MIME part of a message, from the server, into memory.
859 * \param msgnum number of the message on the citadel server
860 * \param partnum the MIME part to be loaded
862 char *load_mimepart(long msgnum, char *partnum)
866 char content_type[SIZ];
869 serv_printf("DLAT %ld|%s", msgnum, partnum);
870 serv_getln(buf, sizeof buf);
872 bytes = extract_long(&buf[4], 0);
873 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
875 content = malloc(bytes + 2);
876 serv_read(content, bytes);
878 content[bytes] = 0; /* null terminate for good measure */
889 * \brief Convenience functions to display a page containing only a string
890 * \param titlebarcolor color of the titlebar of the frame
891 * \param titlebarmsg text to display in the title bar
892 * \param messagetext body of the box
894 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
896 wprintf("HTTP/1.1 200 OK\n");
897 output_headers(1, 1, 2, 0, 0, 0);
898 wprintf("<div id=\"banner\">\n");
899 wprintf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
900 wprintf("<span class=\"titlebar\">%s</span>\n", titlebarmsg);
901 wprintf("</td></tr></table>\n");
902 wprintf("</div>\n<div id=\"content\">\n");
903 escputs(messagetext);
911 * \brief Display a blank page.
913 void blank_page(void) {
914 output_headers(1, 1, 0, 0, 0, 0);
920 * \brief A template has been requested
922 void url_do_template(void) {
923 do_template(bstr("template"));
929 * \brief Offer to make any page the user's "start page."
931 void offer_start_page(void) {
932 wprintf("<a href=\"change_start_page?startpage=");
933 urlescputs(WC->this_page);
935 wprintf(_("Make this my start page"));
938 wprintf("<br/><a href=\"rss?room=");
939 urlescputs(WC->wc_roomname);
940 wprintf("\" title=\"RSS 2.0 feed for ");
941 escputs(WC->wc_roomname);
942 wprintf("\"><img alt=\"RSS\" border=\"0\" src=\"static/xml_button.gif\"/></a>\n");
948 * \brief Change the user's start page
950 void change_start_page(void) {
952 if (bstr("startpage") == NULL) {
953 safestrncpy(WC->ImportantMessage,
954 _("You no longer have a start page selected."),
955 sizeof WC->ImportantMessage);
960 set_preference("startpage", bstr("startpage"), 1);
962 output_headers(1, 1, 0, 0, 0, 0);
963 do_template("newstartpage");
970 * \brief convenience function to indicate success
971 * \param successmessage the mesage itself
973 void display_success(char *successmessage)
975 convenience_page("007700", "OK", successmessage);
980 * \brief Authorization required page
981 * This is probably temporary and should be revisited
982 * \param message message to put in header
984 void authorization_required(const char *message)
986 wprintf("HTTP/1.1 401 Authorization Required\r\n");
987 wprintf("WWW-Authenticate: Basic realm=\"\"\r\n", serv_info.serv_humannode);
988 wprintf("Content-Type: text/html\r\n\r\n");
990 wprintf(_("Authorization Required"));
991 wprintf("</h1>\r\n");
992 wprintf(_("The resource you requested requires a valid username and password. "
993 "You could not be logged in: %s\n"), message);
998 * \brief This function is called by the MIME parser to handle data uploaded by
999 * the browser. Form data, uploaded files, and the data from HTTP PUT
1000 * operations (such as those found in GroupDAV) all arrive this way.
1002 * \param name Name of the item being uploaded
1003 * \param filename Filename of the item being uploaded
1004 * \param partnum MIME part identifier (not needed)
1005 * \param disp MIME content disposition (not needed)
1006 * \param content The actual data
1007 * \param cbtype MIME content-type
1008 * \param cbcharset Character set
1009 * \param length Content length
1010 * \param encoding MIME encoding type (not needed)
1011 * \param userdata Not used here
1013 void upload_handler(char *name, char *filename, char *partnum, char *disp,
1014 void *content, char *cbtype, char *cbcharset,
1015 size_t length, char *encoding, void *userdata)
1017 struct urlcontent *u;
1019 lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n", name, cbtype, length);
1022 if ( (length > 0) && (IsEmptyStr(cbtype)) ) {
1023 u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
1024 u->next = WC->urlstrings;
1026 safestrncpy(u->url_key, name, sizeof(u->url_key));
1027 u->url_data = malloc(length + 1);
1028 memcpy(u->url_data, content, length);
1029 u->url_data[length] = 0;
1030 /* lprintf(9, "Key: <%s> Data: <%s>\n", u->url_key, u->url_data); */
1033 /** Uploaded files */
1034 if ( (length > 0) && (!IsEmptyStr(cbtype)) ) {
1035 WC->upload = malloc(length);
1036 if (WC->upload != NULL) {
1037 WC->upload_length = length;
1038 safestrncpy(WC->upload_filename, filename,
1039 sizeof(WC->upload_filename));
1040 safestrncpy(WC->upload_content_type, cbtype,
1041 sizeof(WC->upload_content_type));
1042 memcpy(WC->upload, content, length);
1045 lprintf(3, "malloc() failed: %s\n", strerror(errno));
1052 * \brief Convenience functions to wrap around asynchronous ajax responses
1054 void begin_ajax_response(void) {
1055 output_headers(0, 0, 0, 0, 0, 0);
1057 wprintf("Content-type: text/html; charset=UTF-8\r\n"
1059 "Connection: close\r\n"
1060 "Pragma: no-cache\r\n"
1061 "Cache-Control: no-cache\r\n"
1069 * \brief print ajax response footer
1071 void end_ajax_response(void) {
1077 * \brief Wraps a Citadel server command in an AJAX transaction.
1079 void ajax_servcmd(void)
1082 char gcontent[1024];
1086 begin_ajax_response();
1088 serv_printf("%s", bstr("g_cmd"));
1089 serv_getln(buf, sizeof buf);
1090 wprintf("%s\n", buf);
1092 if (buf[0] == '8') {
1093 serv_printf("\n\n000");
1095 if ((buf[0] == '1') || (buf[0] == '8')) {
1096 while (serv_getln(gcontent, sizeof gcontent), strcmp(gcontent, "000")) {
1097 wprintf("%s\n", gcontent);
1101 if (buf[0] == '4') {
1102 text_to_server(bstr("g_input"));
1105 if (buf[0] == '6') {
1106 len = atol(&buf[4]);
1108 serv_read(junk, len);
1111 if (buf[0] == '7') {
1112 len = atol(&buf[4]);
1114 memset(junk, 0, len);
1115 serv_write(junk, len);
1119 end_ajax_response();
1122 * This is kind of an ugly hack, but this is the only place it can go.
1123 * If the command was GEXP, then the instant messenger window must be
1124 * running, so reset the "last_pager_check" watchdog timer so
1125 * that page_popup() doesn't try to open it a second time.
1127 if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) {
1128 WC->last_pager_check = time(NULL);
1134 * \brief Helper function for the asynchronous check to see if we need
1135 * to open the instant messenger window.
1137 void seconds_since_last_gexp(void)
1141 begin_ajax_response();
1142 if ( (time(NULL) - WC->last_pager_check) < 30) {
1147 serv_getln(buf, sizeof buf);
1148 if (buf[3] == '*') {
1155 end_ajax_response();
1162 * \brief Entry point for WebCit transaction
1164 void session_loop(struct httprequest *req)
1172 char request_method[128];
1173 char pathname[1024];
1174 int a, b, nBackDots, nEmpty;
1175 int ContentLength = 0;
1177 char ContentType[512];
1178 char *content = NULL;
1179 char *content_end = NULL;
1180 struct httprequest *hptr;
1181 char browser_host[256];
1182 char user_agent[256];
1188 * We stuff these with the values coming from the client cookies,
1189 * so we can use them to reconnect a timed out session if we have to.
1191 char c_username[SIZ];
1192 char c_password[SIZ];
1193 char c_roomname[SIZ];
1194 char c_httpauth_string[SIZ];
1195 char c_httpauth_user[SIZ];
1196 char c_httpauth_pass[SIZ];
1199 safestrncpy(c_username, "", sizeof c_username);
1200 safestrncpy(c_password, "", sizeof c_password);
1201 safestrncpy(c_roomname, "", sizeof c_roomname);
1202 safestrncpy(c_httpauth_string, "", sizeof c_httpauth_string);
1203 safestrncpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER, sizeof c_httpauth_user);
1204 safestrncpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS, sizeof c_httpauth_pass);
1205 strcpy(browser_host, "");
1207 WC->upload_length = 0;
1213 if (hptr == NULL) return;
1215 safestrncpy(cmd, hptr->line, sizeof cmd);
1217 extract_token(request_method, cmd, 0, ' ', sizeof request_method);
1218 extract_token(pathname, cmd, 1, ' ', sizeof pathname);
1220 /** Figure out the action */
1222 sizes[0] = sizeof action;
1225 index[a] = arg[a-1];
1226 sizes[a] = sizeof arg[a-1];
1228 //// index[9] = &foo; todo
1231 for ( a = 0; a < 9; ++a)
1233 extract_token(index[a], pathname, a + 1, '/', sizes[a]);
1234 if (strstr(index[a], "?")) *strstr(index[a], "?") = 0;
1235 if (strstr(index[a], "&")) *strstr(index[a], "&") = 0;
1236 if (strstr(index[a], " ")) *strstr(index[a], " ") = 0;
1237 if ((index[a][0] == '.') && (index[a][1] == '.'))
1239 if (index[a][0] == '\0')
1243 while (hptr != NULL) {
1244 safestrncpy(buf, hptr->line, sizeof buf);
1245 /* lprintf(9, "HTTP HEADER: %s\n", buf); */
1248 if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
1249 safestrncpy(cookie, &buf[15], sizeof cookie);
1250 cookie_to_stuff(cookie, NULL,
1251 c_username, sizeof c_username,
1252 c_password, sizeof c_password,
1253 c_roomname, sizeof c_roomname);
1255 else if (!strncasecmp(buf, "Authorization: Basic ", 21)) {
1256 CtdlDecodeBase64(c_httpauth_string, &buf[21], strlen(&buf[21]));
1257 extract_token(c_httpauth_user, c_httpauth_string, 0, ':', sizeof c_httpauth_user);
1258 extract_token(c_httpauth_pass, c_httpauth_string, 1, ':', sizeof c_httpauth_pass);
1260 else if (!strncasecmp(buf, "Content-length: ", 16)) {
1261 ContentLength = atoi(&buf[16]);
1263 else if (!strncasecmp(buf, "Content-type: ", 14)) {
1264 safestrncpy(ContentType, &buf[14], sizeof ContentType);
1266 else if (!strncasecmp(buf, "User-agent: ", 12)) {
1267 safestrncpy(user_agent, &buf[12], sizeof user_agent);
1269 else if (!strncasecmp(buf, "X-Forwarded-Host: ", 18)) {
1271 safestrncpy(WC->http_host, &buf[18], sizeof WC->http_host);
1274 else if (!strncasecmp(buf, "Host: ", 6)) {
1275 if (IsEmptyStr(WC->http_host)) {
1276 safestrncpy(WC->http_host, &buf[6], sizeof WC->http_host);
1279 else if (!strncasecmp(buf, "X-Forwarded-For: ", 17)) {
1280 safestrncpy(browser_host, &buf[17], sizeof browser_host);
1281 while (num_tokens(browser_host, ',') > 1) {
1282 remove_token(browser_host, 0, ',');
1284 striplt(browser_host);
1286 /** Only WAP gateways explicitly name this content-type */
1287 else if (strstr(buf, "text/vnd.wap.wml")) {
1292 if (ContentLength > 0) {
1293 content = malloc(ContentLength + SIZ);
1294 memset(content, 0, ContentLength + SIZ);
1295 snprintf(content, ContentLength + SIZ, "Content-type: %s\n"
1296 "Content-length: %d\n\n",
1297 ContentType, ContentLength);
1298 body_start = strlen(content);
1300 /** Read the entire input data at once. */
1301 client_read(WC->http_sock, &content[BytesRead+body_start], ContentLength);
1303 if (!strncasecmp(ContentType, "application/x-www-form-urlencoded", 33)) {
1304 addurls(&content[body_start]);
1305 } else if (!strncasecmp(ContentType, "multipart", 9)) {
1306 content_end = content + ContentLength + body_start;
1307 mime_parser(content, content_end, *upload_handler, NULL, NULL, NULL, 0);
1313 /** make a note of where we are in case the user wants to save it */
1314 safestrncpy(WC->this_page, cmd, sizeof(WC->this_page));
1315 remove_token(WC->this_page, 2, ' ');
1316 remove_token(WC->this_page, 0, ' ');
1318 /** If there are variables in the URL, we must grab them now */
1320 for (a = 0; a < len; ++a) {
1321 if ((cmd[a] == '?') || (cmd[a] == '&')) {
1322 for (b = a; b < len; ++b) {
1323 if (isspace(cmd[b])){
1328 addurls(&cmd[a + 1]);
1334 /** If it's a "force 404" situation then display the error and bail. */
1335 if (!strcmp(action, "404")) {
1336 wprintf("HTTP/1.1 404 Not found\r\n");
1337 wprintf("Content-Type: text/plain\r\n");
1339 wprintf("Not found\r\n");
1340 goto SKIP_ALL_THIS_CRAP;
1343 /** Static content can be sent without connecting to Citadel. */
1345 for (a=0; a<ndirs; ++a) {
1346 if (!strcasecmp(action, (char*)static_content_dirs[a])) { /* map web to disk location */
1354 snprintf(buf, sizeof buf, "%s/%s/%s/%s/%s/%s/%s/%s",
1355 static_dirs[n_static],
1356 index[1], index[2], index[3], index[4], index[5], index[6], index[7]);
1357 for (a=0; a<8; ++a) {
1358 if (buf[strlen(buf)-1] == '/') {
1359 buf[strlen(buf)-1] = 0;
1362 for (a = 0; a < strlen(buf); ++a) {
1363 if (isspace(buf[a])) {
1371 lprintf(9, "Suspicious request. Ignoring.");
1372 wprintf("HTTP/1.1 404 Security check failed\r\n");
1373 wprintf("Content-Type: text/plain\r\n");
1375 wprintf("You have sent a malformed or invalid request.\r\n");
1377 goto SKIP_ALL_THIS_CRAP; /* Don't try to connect */
1380 /* If the client sent a nonce that is incorrect, kill the request. */
1381 if (strlen(bstr("nonce")) > 0) {
1382 lprintf(9, "Comparing supplied nonce %s to session nonce %ld\n",
1383 bstr("nonce"), WC->nonce);
1384 if (atoi(bstr("nonce")) != WC->nonce) {
1385 lprintf(9, "Ignoring request with mismatched nonce.\n");
1386 wprintf("HTTP/1.1 404 Security check failed\r\n");
1387 wprintf("Content-Type: text/plain\r\n");
1389 wprintf("Security check failed.\r\n");
1390 goto SKIP_ALL_THIS_CRAP;
1395 * If we're not connected to a Citadel server, try to hook up the
1398 if (!WC->connected) {
1399 if (!strcasecmp(ctdlhost, "uds")) {
1400 /* unix domain socket */
1401 snprintf(buf, SIZ, "%s/citadel.socket", ctdlport);
1402 WC->serv_sock = uds_connectsock(buf);
1406 WC->serv_sock = tcp_connectsock(ctdlhost, ctdlport);
1409 if (WC->serv_sock < 0) {
1411 goto SKIP_ALL_THIS_CRAP;
1415 serv_getln(buf, sizeof buf); /** get the server welcome message */
1418 * From what host is our user connecting? Go with
1419 * the host at the other end of the HTTP socket,
1420 * unless we are following X-Forwarded-For: headers
1421 * and such a header has already turned up something.
1423 if ( (!follow_xff) || (strlen(browser_host) == 0) ) {
1424 locate_host(browser_host, WC->http_sock);
1427 get_serv_info(browser_host, user_agent);
1428 if (serv_info.serv_rev_level < MINIMUM_CIT_VERSION) {
1429 wprintf(_("You are connected to a Citadel "
1430 "server running Citadel %d.%02d. \n"
1431 "In order to run this version of WebCit "
1432 "you must also have Citadel %d.%02d or"
1434 serv_info.serv_rev_level / 100,
1435 serv_info.serv_rev_level % 100,
1436 MINIMUM_CIT_VERSION / 100,
1437 MINIMUM_CIT_VERSION % 100
1439 end_webcit_session();
1440 goto SKIP_ALL_THIS_CRAP;
1446 * Functions which can be performed without logging in
1448 if (!strcasecmp(action, "listsub")) {
1450 goto SKIP_ALL_THIS_CRAP;
1452 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1453 if (!strcasecmp(action, "freebusy")) {
1455 goto SKIP_ALL_THIS_CRAP;
1460 * If we're not logged in, but we have HTTP Authentication data,
1461 * try logging in to Citadel using that.
1463 if ((!WC->logged_in)
1464 && (strlen(c_httpauth_user) > 0)
1465 && (strlen(c_httpauth_pass) > 0)) {
1466 serv_printf("USER %s", c_httpauth_user);
1467 serv_getln(buf, sizeof buf);
1468 if (buf[0] == '3') {
1469 serv_printf("PASS %s", c_httpauth_pass);
1470 serv_getln(buf, sizeof buf);
1471 if (buf[0] == '2') {
1472 become_logged_in(c_httpauth_user,
1473 c_httpauth_pass, buf);
1474 safestrncpy(WC->httpauth_user, c_httpauth_user, sizeof WC->httpauth_user);
1475 safestrncpy(WC->httpauth_pass, c_httpauth_pass, sizeof WC->httpauth_pass);
1477 /** Should only display when password is wrong */
1478 authorization_required(&buf[4]);
1479 goto SKIP_ALL_THIS_CRAP;
1484 /** This needs to run early */
1486 if (!strcasecmp(action, "rss")) {
1487 display_rss(bstr("room"), request_method);
1488 goto SKIP_ALL_THIS_CRAP;
1493 * The GroupDAV stuff relies on HTTP authentication instead of
1494 * our session's authentication.
1496 if (!strncasecmp(action, "groupdav", 8)) {
1497 groupdav_main(req, ContentType, /* do GroupDAV methods */
1498 ContentLength, content+body_start);
1499 if (!WC->logged_in) {
1500 WC->killthis = 1; /* If not logged in, don't */
1501 } /* keep the session active */
1502 goto SKIP_ALL_THIS_CRAP;
1507 * Automatically send requests with any method other than GET or
1508 * POST to the GroupDAV code as well.
1510 if ((strcasecmp(request_method, "GET")) && (strcasecmp(request_method, "POST"))) {
1511 groupdav_main(req, ContentType, /** do GroupDAV methods */
1512 ContentLength, content+body_start);
1513 if (!WC->logged_in) {
1514 WC->killthis = 1; /** If not logged in, don't */
1515 } /** keep the session active */
1516 goto SKIP_ALL_THIS_CRAP;
1520 * If we're not logged in, but we have username and password cookies
1521 * supplied by the browser, try using them to log in.
1523 if ((!WC->logged_in)
1524 && (!IsEmptyStr(c_username))
1525 && (!IsEmptyStr(c_password))) {
1526 serv_printf("USER %s", c_username);
1527 serv_getln(buf, sizeof buf);
1528 if (buf[0] == '3') {
1529 serv_printf("PASS %s", c_password);
1530 serv_getln(buf, sizeof buf);
1531 if (buf[0] == '2') {
1532 become_logged_in(c_username, c_password, buf);
1537 * If we don't have a current room, but a cookie specifying the
1538 * current room is supplied, make an effort to go there.
1540 if ((IsEmptyStr(WC->wc_roomname)) && (!IsEmptyStr(c_roomname))) {
1541 serv_printf("GOTO %s", c_roomname);
1542 serv_getln(buf, sizeof buf);
1543 if (buf[0] == '2') {
1544 safestrncpy(WC->wc_roomname, c_roomname, sizeof WC->wc_roomname);
1548 if (!strcasecmp(action, "image")) {
1552 * All functions handled below this point ... make sure we log in
1553 * before doing anything else!
1555 } else if ((!WC->logged_in) && (!strcasecmp(action, "login"))) {
1557 } else if (!WC->logged_in) {
1558 display_login(NULL);
1562 * Various commands...
1565 else if (!strcasecmp(action, "do_welcome")) {
1567 } else if (!strcasecmp(action, "blank")) {
1569 } else if (!strcasecmp(action, "do_template")) {
1571 } else if (!strcasecmp(action, "display_aide_menu")) {
1572 display_aide_menu();
1573 } else if (!strcasecmp(action, "server_shutdown")) {
1575 } else if (!strcasecmp(action, "display_main_menu")) {
1576 display_main_menu();
1577 } else if (!strcasecmp(action, "who")) {
1579 } else if (!strcasecmp(action, "sslg")) {
1580 seconds_since_last_gexp();
1581 } else if (!strcasecmp(action, "who_inner_html")) {
1582 begin_ajax_response();
1584 end_ajax_response();
1585 } else if (!strcasecmp(action, "wholist_section")) {
1586 begin_ajax_response();
1588 end_ajax_response();
1589 } else if (!strcasecmp(action, "new_messages_html")) {
1590 begin_ajax_response();
1591 new_messages_section();
1592 end_ajax_response();
1593 } else if (!strcasecmp(action, "tasks_inner_html")) {
1594 begin_ajax_response();
1596 end_ajax_response();
1597 } else if (!strcasecmp(action, "calendar_inner_html")) {
1598 begin_ajax_response();
1600 end_ajax_response();
1601 } else if (!strcasecmp(action, "mini_calendar")) {
1602 begin_ajax_response();
1603 ajax_mini_calendar();
1604 end_ajax_response();
1605 } else if (!strcasecmp(action, "iconbar_ajax_menu")) {
1606 begin_ajax_response();
1608 end_ajax_response();
1609 } else if (!strcasecmp(action, "iconbar_ajax_rooms")) {
1610 begin_ajax_response();
1611 do_iconbar_roomlist();
1612 end_ajax_response();
1613 } else if (!strcasecmp(action, "knrooms")) {
1615 } else if (!strcasecmp(action, "gotonext")) {
1618 } else if (!strcasecmp(action, "skip")) {
1620 } else if (!strcasecmp(action, "ungoto")) {
1622 } else if (!strcasecmp(action, "dotgoto")) {
1623 if (WC->wc_view != VIEW_MAILBOX) { /* dotgoto acts like dotskip when we're in a mailbox view */
1626 smart_goto(bstr("room"));
1627 } else if (!strcasecmp(action, "dotskip")) {
1628 smart_goto(bstr("room"));
1629 } else if (!strcasecmp(action, "termquit")) {
1631 } else if (!strcasecmp(action, "readnew")) {
1632 readloop("readnew");
1633 } else if (!strcasecmp(action, "readold")) {
1634 readloop("readold");
1635 } else if (!strcasecmp(action, "readfwd")) {
1636 readloop("readfwd");
1637 } else if (!strcasecmp(action, "headers")) {
1638 readloop("headers");
1639 } else if (!strcasecmp(action, "do_search")) {
1640 readloop("do_search");
1641 } else if (!strcasecmp(action, "msg")) {
1642 embed_message(index[1]);
1643 } else if (!strcasecmp(action, "printmsg")) {
1644 print_message(index[1]);
1645 } else if (!strcasecmp(action, "msgheaders")) {
1646 display_headers(index[1]);
1647 } else if (!strcasecmp(action, "wiki")) {
1648 display_wiki_page();
1649 } else if (!strcasecmp(action, "display_enter")) {
1651 } else if (!strcasecmp(action, "post")) {
1653 } else if (!strcasecmp(action, "move_msg")) {
1655 } else if (!strcasecmp(action, "delete_msg")) {
1657 } else if (!strcasecmp(action, "userlist")) {
1659 } else if (!strcasecmp(action, "showuser")) {
1661 } else if (!strcasecmp(action, "display_page")) {
1663 } else if (!strcasecmp(action, "page_user")) {
1665 } else if (!strcasecmp(action, "chat")) {
1667 } else if (!strcasecmp(action, "display_private")) {
1668 display_private("", 0);
1669 } else if (!strcasecmp(action, "goto_private")) {
1671 } else if (!strcasecmp(action, "zapped_list")) {
1673 } else if (!strcasecmp(action, "display_zap")) {
1675 } else if (!strcasecmp(action, "zap")) {
1677 } else if (!strcasecmp(action, "display_entroom")) {
1679 } else if (!strcasecmp(action, "entroom")) {
1681 } else if (!strcasecmp(action, "display_whok")) {
1683 } else if (!strcasecmp(action, "do_invt_kick")) {
1685 } else if (!strcasecmp(action, "display_editroom")) {
1687 } else if (!strcasecmp(action, "netedit")) {
1689 } else if (!strcasecmp(action, "editroom")) {
1691 } else if (!strcasecmp(action, "display_editinfo")) {
1692 display_edit(_("Room info"), "EINF 0", "RINF", "editinfo", 1);
1693 } else if (!strcasecmp(action, "editinfo")) {
1694 save_edit(_("Room info"), "EINF 1", 1);
1695 } else if (!strcasecmp(action, "display_editbio")) {
1696 snprintf(buf, SIZ, "RBIO %s", WC->wc_fullname);
1697 display_edit(_("Your bio"), "NOOP", buf, "editbio", 3);
1698 } else if (!strcasecmp(action, "editbio")) {
1699 save_edit(_("Your bio"), "EBIO", 0);
1700 } else if (!strcasecmp(action, "confirm_move_msg")) {
1702 } else if (!strcasecmp(action, "delete_room")) {
1704 } else if (!strcasecmp(action, "validate")) {
1706 /* The users photo display / upload facility */
1707 } else if (!strcasecmp(action, "display_editpic")) {
1708 display_graphics_upload(_("your photo"),
1711 } else if (!strcasecmp(action, "editpic")) {
1712 do_graphics_upload("UIMG 1|_userpic_");
1713 /* room picture dispay / upload facility */
1714 } else if (!strcasecmp(action, "display_editroompic")) {
1715 display_graphics_upload(_("the icon for this room"),
1718 } else if (!strcasecmp(action, "editroompic")) {
1719 do_graphics_upload("UIMG 1|_roompic_");
1720 /* the greetingpage hello pic */
1721 } else if (!strcasecmp(action, "display_edithello")) {
1722 display_graphics_upload(_("the Greetingpicture for the login prompt"),
1725 } else if (!strcasecmp(action, "edithellopic")) {
1726 do_graphics_upload("UIMG 1|hello.gif");
1727 /* the logoff banner */
1728 } else if (!strcasecmp(action, "display_editgoodbyepic")) {
1729 display_graphics_upload(_("the Logoff banner picture"),
1730 "UIMG 0|goodbuye.gif",
1732 } else if (!strcasecmp(action, "editgoodbuyepic")) {
1733 do_graphics_upload("UIMG 1|goodbuye.gif");
1735 } else if (!strcasecmp(action, "delete_floor")) {
1737 } else if (!strcasecmp(action, "rename_floor")) {
1739 } else if (!strcasecmp(action, "create_floor")) {
1741 } else if (!strcasecmp(action, "display_editfloorpic")) {
1742 snprintf(buf, SIZ, "UIMG 0|_floorpic_|%s",
1743 bstr("which_floor"));
1744 display_graphics_upload(_("the icon for this floor"),
1747 } else if (!strcasecmp(action, "editfloorpic")) {
1748 snprintf(buf, SIZ, "UIMG 1|_floorpic_|%s",
1749 bstr("which_floor"));
1750 do_graphics_upload(buf);
1751 } else if (!strcasecmp(action, "display_reg")) {
1753 } else if (!strcasecmp(action, "display_changepw")) {
1755 } else if (!strcasecmp(action, "changepw")) {
1757 } else if (!strcasecmp(action, "display_edit_node")) {
1758 display_edit_node();
1759 } else if (!strcasecmp(action, "edit_node")) {
1761 } else if (!strcasecmp(action, "display_netconf")) {
1763 } else if (!strcasecmp(action, "display_confirm_delete_node")) {
1764 display_confirm_delete_node();
1765 } else if (!strcasecmp(action, "delete_node")) {
1767 } else if (!strcasecmp(action, "display_add_node")) {
1769 } else if (!strcasecmp(action, "terminate_session")) {
1771 terminate_session();
1772 } else if (!strcasecmp(action, "edit_me")) {
1774 } else if (!strcasecmp(action, "display_siteconfig")) {
1775 display_siteconfig();
1776 } else if (!strcasecmp(action, "chat_recv")) {
1778 } else if (!strcasecmp(action, "chat_send")) {
1780 } else if (!strcasecmp(action, "siteconfig")) {
1782 } else if (!strcasecmp(action, "display_generic")) {
1784 } else if (!strcasecmp(action, "do_generic")) {
1786 } else if (!strcasecmp(action, "ajax_servcmd")) {
1788 } else if (!strcasecmp(action, "display_menubar")) {
1790 } else if (!strcasecmp(action, "mimepart")) {
1791 mimepart(index[1], index[2], 0);
1792 } else if (!strcasecmp(action, "mimepart_download")) {
1793 mimepart(index[1], index[2], 1);
1794 } else if (!strcasecmp(action, "edit_vcard")) {
1796 } else if (!strcasecmp(action, "submit_vcard")) {
1798 } else if (!strcasecmp(action, "select_user_to_edit")) {
1799 select_user_to_edit(NULL, NULL);
1800 } else if (!strcasecmp(action, "display_edituser")) {
1801 display_edituser(NULL, 0);
1802 } else if (!strcasecmp(action, "edituser")) {
1804 } else if (!strcasecmp(action, "create_user")) {
1806 } else if (!strcasecmp(action, "changeview")) {
1808 } else if (!strcasecmp(action, "change_start_page")) {
1809 change_start_page();
1810 } else if (!strcasecmp(action, "display_floorconfig")) {
1811 display_floorconfig(NULL);
1812 } else if (!strcasecmp(action, "toggle_self_service")) {
1813 toggle_self_service();
1814 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1815 } else if (!strcasecmp(action, "display_edit_task")) {
1816 display_edit_task();
1817 } else if (!strcasecmp(action, "save_task")) {
1819 } else if (!strcasecmp(action, "display_edit_event")) {
1820 display_edit_event();
1821 } else if (!strcasecmp(action, "save_event")) {
1823 } else if (!strcasecmp(action, "respond_to_request")) {
1824 respond_to_request();
1825 } else if (!strcasecmp(action, "handle_rsvp")) {
1828 } else if (!strcasecmp(action, "summary")) {
1830 } else if (!strcasecmp(action, "summary_inner_div")) {
1831 begin_ajax_response();
1832 summary_inner_div();
1833 end_ajax_response();
1834 } else if (!strcasecmp(action, "display_customize_iconbar")) {
1835 display_customize_iconbar();
1836 } else if (!strcasecmp(action, "commit_iconbar")) {
1838 } else if (!strcasecmp(action, "set_room_policy")) {
1840 } else if (!strcasecmp(action, "display_inetconf")) {
1842 } else if (!strcasecmp(action, "save_inetconf")) {
1844 } else if (!strcasecmp(action, "display_smtpqueue")) {
1845 display_smtpqueue();
1846 } else if (!strcasecmp(action, "display_smtpqueue_inner_div")) {
1847 display_smtpqueue_inner_div();
1848 } else if (!strcasecmp(action, "display_sieve")) {
1850 } else if (!strcasecmp(action, "save_sieve")) {
1852 } else if (!strcasecmp(action, "display_pushemail")) {
1853 display_pushemail();
1854 } else if (!strcasecmp(action, "save_pushemail")) {
1856 } else if (!strcasecmp(action, "display_add_remove_scripts")) {
1857 display_add_remove_scripts(NULL);
1858 } else if (!strcasecmp(action, "create_script")) {
1860 } else if (!strcasecmp(action, "delete_script")) {
1862 } else if (!strcasecmp(action, "setup_wizard")) {
1864 } else if (!strcasecmp(action, "display_preferences")) {
1865 display_preferences();
1866 } else if (!strcasecmp(action, "set_preferences")) {
1868 } else if (!strcasecmp(action, "recp_autocomplete")) {
1869 recp_autocomplete(bstr("recp"));
1870 } else if (!strcasecmp(action, "cc_autocomplete")) {
1871 recp_autocomplete(bstr("cc"));
1872 } else if (!strcasecmp(action, "bcc_autocomplete")) {
1873 recp_autocomplete(bstr("bcc"));
1874 } else if (!strcasecmp(action, "display_address_book_middle_div")) {
1875 display_address_book_middle_div();
1876 } else if (!strcasecmp(action, "display_address_book_inner_div")) {
1877 display_address_book_inner_div();
1878 } else if (!strcasecmp(action, "set_floordiv_expanded")) {
1879 set_floordiv_expanded(index[1]);
1880 } else if (!strcasecmp(action, "diagnostics")) {
1881 output_headers(1, 1, 1, 0, 0, 0);
1882 wprintf("Session: %d<hr />\n", WC->wc_session);
1883 wprintf("Command: <br /><PRE>\n");
1885 wprintf("</PRE><hr />\n");
1886 wprintf("Variables: <br /><PRE>\n");
1888 wprintf("</PRE><hr />\n");
1890 } else if (!strcasecmp(action, "updatenote")) {
1892 } else if (!strcasecmp(action, "display_room_directory")) {
1893 display_room_directory();
1894 } else if (!strcasecmp(action, "download_file")) {
1895 download_file(index[1]);
1896 } else if (!strcasecmp(action, "upload_file")) {
1900 /** When all else fais, display the main menu. */
1902 display_main_menu();
1907 if (content != NULL) {
1912 if (WC->upload_length > 0) {
1914 WC->upload_length = 0;
1919 * \brief Replacement for sleep() that uses select() in order to avoid SIGALRM
1920 * \param seconds how many seconds should we sleep?
1922 void sleeeeeeeeeep(int seconds)
1926 tv.tv_sec = seconds;
1928 select(0, NULL, NULL, NULL, &tv);