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 const char *content_type;
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 content_type = GuessMimeByFilename(what, len);
697 if (fstat(fileno(fp), &statbuf) == -1) {
698 lprintf(9, "output_static('%s') -- FSTAT FAILED --\n", what);
699 wprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
700 wprintf("Content-Type: text/plain\r\n");
702 wprintf("Cannot fstat %s: %s\n", what, strerror(errno));
707 bytes = statbuf.st_size;
708 if ((bigbuffer = malloc(bytes + 2)) == NULL) {
709 lprintf(9, "output_static('%s') -- MALLOC FAILED (%s) --\n", what, strerror(errno));
710 wprintf("HTTP/1.1 500 internal server error\r\n");
711 wprintf("Content-Type: text/plain\r\n");
715 while (count < bytes) {
716 if ((res = fread(bigbuffer + count, 1, bytes - count, fp)) == 0) {
717 lprintf(9, "output_static('%s') -- FREAD FAILED (%s) %zu bytes of %zu --\n", what, strerror(errno), bytes - count, bytes);
718 wprintf("HTTP/1.1 500 internal server error \r\n");
719 wprintf("Content-Type: text/plain\r\n");
728 lprintf(9, "output_static('%s') %s\n", what, content_type);
729 http_transmit_thing(bigbuffer, (size_t)bytes, content_type, 1);
732 if (!strcasecmp(bstr("force_close_session"), "yes")) {
733 end_webcit_session();
738 * \brief When the browser requests an image file from the Citadel server,
739 * this function is called to transmit it.
744 char *xferbuf = NULL;
746 const char *MimeType;
748 serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
749 serv_getln(buf, sizeof buf);
751 bytes = extract_long(&buf[4], 0);
752 xferbuf = malloc(bytes + 2);
754 /** Read it from the server */
755 read_server_binary(xferbuf, bytes);
757 serv_getln(buf, sizeof buf);
759 MimeType = GuessMimeType (xferbuf, bytes);
760 /** Write it to the browser */
761 if (!IsEmptyStr(MimeType))
763 http_transmit_thing(xferbuf,
770 /* hm... unknown mimetype? fallback to blank gif */
776 * Instead of an ugly 404, send a 1x1 transparent GIF
777 * when there's no such image on the server.
780 snprintf (blank_gif, SIZ, "%s%s", static_dirs[0], "/blank.gif");
781 output_static(blank_gif);
785 * \brief Generic function to output an arbitrary MIME part from an arbitrary
786 * message number on the server.
788 * \param msgnum Number of the item on the citadel server
789 * \param partnum The MIME part to be output
790 * \param force_download Nonzero to force set the Content-Type: header
791 * to "application/octet-stream"
793 void mimepart(char *msgnum, char *partnum, int force_download)
797 char content_type[256];
798 char *content = NULL;
800 serv_printf("OPNA %s|%s", msgnum, partnum);
801 serv_getln(buf, sizeof buf);
803 bytes = extract_long(&buf[4], 0);
804 content = malloc(bytes + 2);
805 if (force_download) {
806 strcpy(content_type, "application/octet-stream");
809 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
811 output_headers(0, 0, 0, 0, 0, 0);
812 read_server_binary(content, bytes);
814 serv_getln(buf, sizeof buf);
815 http_transmit_thing(content, bytes, content_type, 0);
818 wprintf("HTTP/1.1 404 %s\n", &buf[4]);
819 output_headers(0, 0, 0, 0, 0, 0);
820 wprintf("Content-Type: text/plain\r\n");
822 wprintf(_("An error occurred while retrieving this part: %s\n"), &buf[4]);
829 * \brief Read any MIME part of a message, from the server, into memory.
830 * \param msgnum number of the message on the citadel server
831 * \param partnum the MIME part to be loaded
833 char *load_mimepart(long msgnum, char *partnum)
837 char content_type[SIZ];
840 serv_printf("DLAT %ld|%s", msgnum, partnum);
841 serv_getln(buf, sizeof buf);
843 bytes = extract_long(&buf[4], 0);
844 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
846 content = malloc(bytes + 2);
847 serv_read(content, bytes);
849 content[bytes] = 0; /* null terminate for good measure */
860 * \brief Convenience functions to display a page containing only a string
861 * \param titlebarcolor color of the titlebar of the frame
862 * \param titlebarmsg text to display in the title bar
863 * \param messagetext body of the box
865 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
867 wprintf("HTTP/1.1 200 OK\n");
868 output_headers(1, 1, 2, 0, 0, 0);
869 wprintf("<div id=\"banner\">\n");
870 wprintf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
871 wprintf("<span class=\"titlebar\">%s</span>\n", titlebarmsg);
872 wprintf("</td></tr></table>\n");
873 wprintf("</div>\n<div id=\"content\">\n");
874 escputs(messagetext);
882 * \brief Display a blank page.
884 void blank_page(void) {
885 output_headers(1, 1, 0, 0, 0, 0);
891 * \brief A template has been requested
893 void url_do_template(void) {
894 do_template(bstr("template"));
900 * \brief Offer to make any page the user's "start page."
902 void offer_start_page(void) {
903 wprintf("<a href=\"change_start_page?startpage=");
904 urlescputs(WC->this_page);
906 wprintf(_("Make this my start page"));
909 wprintf("<br/><a href=\"rss?room=");
910 urlescputs(WC->wc_roomname);
911 wprintf("\" title=\"RSS 2.0 feed for ");
912 escputs(WC->wc_roomname);
913 wprintf("\"><img alt=\"RSS\" border=\"0\" src=\"static/xml_button.gif\"/></a>\n");
919 * \brief Change the user's start page
921 void change_start_page(void) {
923 if (bstr("startpage") == NULL) {
924 safestrncpy(WC->ImportantMessage,
925 _("You no longer have a start page selected."),
926 sizeof WC->ImportantMessage);
931 set_preference("startpage", bstr("startpage"), 1);
933 output_headers(1, 1, 0, 0, 0, 0);
934 do_template("newstartpage");
941 * \brief convenience function to indicate success
942 * \param successmessage the mesage itself
944 void display_success(char *successmessage)
946 convenience_page("007700", "OK", successmessage);
951 * \brief Authorization required page
952 * This is probably temporary and should be revisited
953 * \param message message to put in header
955 void authorization_required(const char *message)
957 wprintf("HTTP/1.1 401 Authorization Required\r\n");
958 wprintf("WWW-Authenticate: Basic realm=\"\"\r\n", serv_info.serv_humannode);
959 wprintf("Content-Type: text/html\r\n\r\n");
961 wprintf(_("Authorization Required"));
962 wprintf("</h1>\r\n");
963 wprintf(_("The resource you requested requires a valid username and password. "
964 "You could not be logged in: %s\n"), message);
969 * \brief This function is called by the MIME parser to handle data uploaded by
970 * the browser. Form data, uploaded files, and the data from HTTP PUT
971 * operations (such as those found in GroupDAV) all arrive this way.
973 * \param name Name of the item being uploaded
974 * \param filename Filename of the item being uploaded
975 * \param partnum MIME part identifier (not needed)
976 * \param disp MIME content disposition (not needed)
977 * \param content The actual data
978 * \param cbtype MIME content-type
979 * \param cbcharset Character set
980 * \param length Content length
981 * \param encoding MIME encoding type (not needed)
982 * \param userdata Not used here
984 void upload_handler(char *name, char *filename, char *partnum, char *disp,
985 void *content, char *cbtype, char *cbcharset,
986 size_t length, char *encoding, void *userdata)
988 struct urlcontent *u;
990 lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n", name, cbtype, length);
993 if ( (length > 0) && (IsEmptyStr(cbtype)) ) {
994 u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
995 u->next = WC->urlstrings;
997 safestrncpy(u->url_key, name, sizeof(u->url_key));
998 u->url_data = malloc(length + 1);
999 memcpy(u->url_data, content, length);
1000 u->url_data[length] = 0;
1001 /* lprintf(9, "Key: <%s> Data: <%s>\n", u->url_key, u->url_data); */
1004 /** Uploaded files */
1005 if ( (length > 0) && (!IsEmptyStr(cbtype)) ) {
1006 WC->upload = malloc(length);
1007 if (WC->upload != NULL) {
1008 WC->upload_length = length;
1009 safestrncpy(WC->upload_filename, filename,
1010 sizeof(WC->upload_filename));
1011 safestrncpy(WC->upload_content_type, cbtype,
1012 sizeof(WC->upload_content_type));
1013 memcpy(WC->upload, content, length);
1016 lprintf(3, "malloc() failed: %s\n", strerror(errno));
1023 * \brief Convenience functions to wrap around asynchronous ajax responses
1025 void begin_ajax_response(void) {
1026 output_headers(0, 0, 0, 0, 0, 0);
1028 wprintf("Content-type: text/html; charset=UTF-8\r\n"
1030 "Connection: close\r\n"
1031 "Pragma: no-cache\r\n"
1032 "Cache-Control: no-cache\r\n"
1040 * \brief print ajax response footer
1042 void end_ajax_response(void) {
1048 * \brief Wraps a Citadel server command in an AJAX transaction.
1050 void ajax_servcmd(void)
1053 char gcontent[1024];
1057 begin_ajax_response();
1059 serv_printf("%s", bstr("g_cmd"));
1060 serv_getln(buf, sizeof buf);
1061 wprintf("%s\n", buf);
1063 if (buf[0] == '8') {
1064 serv_printf("\n\n000");
1066 if ((buf[0] == '1') || (buf[0] == '8')) {
1067 while (serv_getln(gcontent, sizeof gcontent), strcmp(gcontent, "000")) {
1068 wprintf("%s\n", gcontent);
1072 if (buf[0] == '4') {
1073 text_to_server(bstr("g_input"));
1076 if (buf[0] == '6') {
1077 len = atol(&buf[4]);
1079 serv_read(junk, len);
1082 if (buf[0] == '7') {
1083 len = atol(&buf[4]);
1085 memset(junk, 0, len);
1086 serv_write(junk, len);
1090 end_ajax_response();
1093 * This is kind of an ugly hack, but this is the only place it can go.
1094 * If the command was GEXP, then the instant messenger window must be
1095 * running, so reset the "last_pager_check" watchdog timer so
1096 * that page_popup() doesn't try to open it a second time.
1098 if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) {
1099 WC->last_pager_check = time(NULL);
1105 * \brief Helper function for the asynchronous check to see if we need
1106 * to open the instant messenger window.
1108 void seconds_since_last_gexp(void)
1112 begin_ajax_response();
1113 if ( (time(NULL) - WC->last_pager_check) < 30) {
1118 serv_getln(buf, sizeof buf);
1119 if (buf[3] == '*') {
1126 end_ajax_response();
1133 * \brief Entry point for WebCit transaction
1135 void session_loop(struct httprequest *req)
1143 char request_method[128];
1144 char pathname[1024];
1145 int a, b, nBackDots, nEmpty;
1146 int ContentLength = 0;
1148 char ContentType[512];
1149 char *content = NULL;
1150 char *content_end = NULL;
1151 struct httprequest *hptr;
1152 char browser_host[256];
1153 char user_agent[256];
1159 * We stuff these with the values coming from the client cookies,
1160 * so we can use them to reconnect a timed out session if we have to.
1162 char c_username[SIZ];
1163 char c_password[SIZ];
1164 char c_roomname[SIZ];
1165 char c_httpauth_string[SIZ];
1166 char c_httpauth_user[SIZ];
1167 char c_httpauth_pass[SIZ];
1170 safestrncpy(c_username, "", sizeof c_username);
1171 safestrncpy(c_password, "", sizeof c_password);
1172 safestrncpy(c_roomname, "", sizeof c_roomname);
1173 safestrncpy(c_httpauth_string, "", sizeof c_httpauth_string);
1174 safestrncpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER, sizeof c_httpauth_user);
1175 safestrncpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS, sizeof c_httpauth_pass);
1176 strcpy(browser_host, "");
1178 WC->upload_length = 0;
1184 if (hptr == NULL) return;
1186 safestrncpy(cmd, hptr->line, sizeof cmd);
1188 extract_token(request_method, cmd, 0, ' ', sizeof request_method);
1189 extract_token(pathname, cmd, 1, ' ', sizeof pathname);
1191 /** Figure out the action */
1193 sizes[0] = sizeof action;
1196 index[a] = arg[a-1];
1197 sizes[a] = sizeof arg[a-1];
1199 //// index[9] = &foo; todo
1202 for ( a = 0; a < 9; ++a)
1204 extract_token(index[a], pathname, a + 1, '/', sizes[a]);
1205 if (strstr(index[a], "?")) *strstr(index[a], "?") = 0;
1206 if (strstr(index[a], "&")) *strstr(index[a], "&") = 0;
1207 if (strstr(index[a], " ")) *strstr(index[a], " ") = 0;
1208 if ((index[a][0] == '.') && (index[a][1] == '.'))
1210 if (index[a][0] == '\0')
1214 while (hptr != NULL) {
1215 safestrncpy(buf, hptr->line, sizeof buf);
1216 /* lprintf(9, "HTTP HEADER: %s\n", buf); */
1219 if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
1220 safestrncpy(cookie, &buf[15], sizeof cookie);
1221 cookie_to_stuff(cookie, NULL,
1222 c_username, sizeof c_username,
1223 c_password, sizeof c_password,
1224 c_roomname, sizeof c_roomname);
1226 else if (!strncasecmp(buf, "Authorization: Basic ", 21)) {
1227 CtdlDecodeBase64(c_httpauth_string, &buf[21], strlen(&buf[21]));
1228 extract_token(c_httpauth_user, c_httpauth_string, 0, ':', sizeof c_httpauth_user);
1229 extract_token(c_httpauth_pass, c_httpauth_string, 1, ':', sizeof c_httpauth_pass);
1231 else if (!strncasecmp(buf, "Content-length: ", 16)) {
1232 ContentLength = atoi(&buf[16]);
1234 else if (!strncasecmp(buf, "Content-type: ", 14)) {
1235 safestrncpy(ContentType, &buf[14], sizeof ContentType);
1237 else if (!strncasecmp(buf, "User-agent: ", 12)) {
1238 safestrncpy(user_agent, &buf[12], sizeof user_agent);
1240 else if (!strncasecmp(buf, "X-Forwarded-Host: ", 18)) {
1242 safestrncpy(WC->http_host, &buf[18], sizeof WC->http_host);
1245 else if (!strncasecmp(buf, "Host: ", 6)) {
1246 if (IsEmptyStr(WC->http_host)) {
1247 safestrncpy(WC->http_host, &buf[6], sizeof WC->http_host);
1250 else if (!strncasecmp(buf, "X-Forwarded-For: ", 17)) {
1251 safestrncpy(browser_host, &buf[17], sizeof browser_host);
1252 while (num_tokens(browser_host, ',') > 1) {
1253 remove_token(browser_host, 0, ',');
1255 striplt(browser_host);
1257 /** Only WAP gateways explicitly name this content-type */
1258 else if (strstr(buf, "text/vnd.wap.wml")) {
1263 if (ContentLength > 0) {
1264 content = malloc(ContentLength + SIZ);
1265 memset(content, 0, ContentLength + SIZ);
1266 snprintf(content, ContentLength + SIZ, "Content-type: %s\n"
1267 "Content-length: %d\n\n",
1268 ContentType, ContentLength);
1269 body_start = strlen(content);
1271 /** Read the entire input data at once. */
1272 client_read(WC->http_sock, &content[BytesRead+body_start], ContentLength);
1274 if (!strncasecmp(ContentType, "application/x-www-form-urlencoded", 33)) {
1275 addurls(&content[body_start]);
1276 } else if (!strncasecmp(ContentType, "multipart", 9)) {
1277 content_end = content + ContentLength + body_start;
1278 mime_parser(content, content_end, *upload_handler, NULL, NULL, NULL, 0);
1284 /** make a note of where we are in case the user wants to save it */
1285 safestrncpy(WC->this_page, cmd, sizeof(WC->this_page));
1286 remove_token(WC->this_page, 2, ' ');
1287 remove_token(WC->this_page, 0, ' ');
1289 /** If there are variables in the URL, we must grab them now */
1291 for (a = 0; a < len; ++a) {
1292 if ((cmd[a] == '?') || (cmd[a] == '&')) {
1293 for (b = a; b < len; ++b) {
1294 if (isspace(cmd[b])){
1299 addurls(&cmd[a + 1]);
1305 /** If it's a "force 404" situation then display the error and bail. */
1306 if (!strcmp(action, "404")) {
1307 wprintf("HTTP/1.1 404 Not found\r\n");
1308 wprintf("Content-Type: text/plain\r\n");
1310 wprintf("Not found\r\n");
1311 goto SKIP_ALL_THIS_CRAP;
1314 /** Static content can be sent without connecting to Citadel. */
1316 for (a=0; a<ndirs; ++a) {
1317 if (!strcasecmp(action, (char*)static_content_dirs[a])) { /* map web to disk location */
1325 snprintf(buf, sizeof buf, "%s/%s/%s/%s/%s/%s/%s/%s",
1326 static_dirs[n_static],
1327 index[1], index[2], index[3], index[4], index[5], index[6], index[7]);
1328 for (a=0; a<8; ++a) {
1329 if (buf[strlen(buf)-1] == '/') {
1330 buf[strlen(buf)-1] = 0;
1333 for (a = 0; a < strlen(buf); ++a) {
1334 if (isspace(buf[a])) {
1342 lprintf(9, "Suspicious request. Ignoring.");
1343 wprintf("HTTP/1.1 404 Security check failed\r\n");
1344 wprintf("Content-Type: text/plain\r\n");
1346 wprintf("You have sent a malformed or invalid request.\r\n");
1348 goto SKIP_ALL_THIS_CRAP; /* Don't try to connect */
1351 /* If the client sent a nonce that is incorrect, kill the request. */
1352 if (strlen(bstr("nonce")) > 0) {
1353 lprintf(9, "Comparing supplied nonce %s to session nonce %ld\n",
1354 bstr("nonce"), WC->nonce);
1355 if (atoi(bstr("nonce")) != WC->nonce) {
1356 lprintf(9, "Ignoring request with mismatched nonce.\n");
1357 wprintf("HTTP/1.1 404 Security check failed\r\n");
1358 wprintf("Content-Type: text/plain\r\n");
1360 wprintf("Security check failed.\r\n");
1361 goto SKIP_ALL_THIS_CRAP;
1366 * If we're not connected to a Citadel server, try to hook up the
1369 if (!WC->connected) {
1370 if (!strcasecmp(ctdlhost, "uds")) {
1371 /* unix domain socket */
1372 snprintf(buf, SIZ, "%s/citadel.socket", ctdlport);
1373 WC->serv_sock = uds_connectsock(buf);
1377 WC->serv_sock = tcp_connectsock(ctdlhost, ctdlport);
1380 if (WC->serv_sock < 0) {
1382 goto SKIP_ALL_THIS_CRAP;
1386 serv_getln(buf, sizeof buf); /** get the server welcome message */
1389 * From what host is our user connecting? Go with
1390 * the host at the other end of the HTTP socket,
1391 * unless we are following X-Forwarded-For: headers
1392 * and such a header has already turned up something.
1394 if ( (!follow_xff) || (strlen(browser_host) == 0) ) {
1395 locate_host(browser_host, WC->http_sock);
1398 get_serv_info(browser_host, user_agent);
1399 if (serv_info.serv_rev_level < MINIMUM_CIT_VERSION) {
1400 wprintf(_("You are connected to a Citadel "
1401 "server running Citadel %d.%02d. \n"
1402 "In order to run this version of WebCit "
1403 "you must also have Citadel %d.%02d or"
1405 serv_info.serv_rev_level / 100,
1406 serv_info.serv_rev_level % 100,
1407 MINIMUM_CIT_VERSION / 100,
1408 MINIMUM_CIT_VERSION % 100
1410 end_webcit_session();
1411 goto SKIP_ALL_THIS_CRAP;
1417 * Functions which can be performed without logging in
1419 if (!strcasecmp(action, "listsub")) {
1421 goto SKIP_ALL_THIS_CRAP;
1423 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1424 if (!strcasecmp(action, "freebusy")) {
1426 goto SKIP_ALL_THIS_CRAP;
1431 * If we're not logged in, but we have HTTP Authentication data,
1432 * try logging in to Citadel using that.
1434 if ((!WC->logged_in)
1435 && (strlen(c_httpauth_user) > 0)
1436 && (strlen(c_httpauth_pass) > 0)) {
1437 serv_printf("USER %s", c_httpauth_user);
1438 serv_getln(buf, sizeof buf);
1439 if (buf[0] == '3') {
1440 serv_printf("PASS %s", c_httpauth_pass);
1441 serv_getln(buf, sizeof buf);
1442 if (buf[0] == '2') {
1443 become_logged_in(c_httpauth_user,
1444 c_httpauth_pass, buf);
1445 safestrncpy(WC->httpauth_user, c_httpauth_user, sizeof WC->httpauth_user);
1446 safestrncpy(WC->httpauth_pass, c_httpauth_pass, sizeof WC->httpauth_pass);
1448 /** Should only display when password is wrong */
1449 authorization_required(&buf[4]);
1450 goto SKIP_ALL_THIS_CRAP;
1455 /** This needs to run early */
1457 if (!strcasecmp(action, "rss")) {
1458 display_rss(bstr("room"), request_method);
1459 goto SKIP_ALL_THIS_CRAP;
1464 * The GroupDAV stuff relies on HTTP authentication instead of
1465 * our session's authentication.
1467 if (!strncasecmp(action, "groupdav", 8)) {
1468 groupdav_main(req, ContentType, /* do GroupDAV methods */
1469 ContentLength, content+body_start);
1470 if (!WC->logged_in) {
1471 WC->killthis = 1; /* If not logged in, don't */
1472 } /* keep the session active */
1473 goto SKIP_ALL_THIS_CRAP;
1478 * Automatically send requests with any method other than GET or
1479 * POST to the GroupDAV code as well.
1481 if ((strcasecmp(request_method, "GET")) && (strcasecmp(request_method, "POST"))) {
1482 groupdav_main(req, ContentType, /** do GroupDAV methods */
1483 ContentLength, content+body_start);
1484 if (!WC->logged_in) {
1485 WC->killthis = 1; /** If not logged in, don't */
1486 } /** keep the session active */
1487 goto SKIP_ALL_THIS_CRAP;
1491 * If we're not logged in, but we have username and password cookies
1492 * supplied by the browser, try using them to log in.
1494 if ((!WC->logged_in)
1495 && (!IsEmptyStr(c_username))
1496 && (!IsEmptyStr(c_password))) {
1497 serv_printf("USER %s", c_username);
1498 serv_getln(buf, sizeof buf);
1499 if (buf[0] == '3') {
1500 serv_printf("PASS %s", c_password);
1501 serv_getln(buf, sizeof buf);
1502 if (buf[0] == '2') {
1503 become_logged_in(c_username, c_password, buf);
1508 * If we don't have a current room, but a cookie specifying the
1509 * current room is supplied, make an effort to go there.
1511 if ((IsEmptyStr(WC->wc_roomname)) && (!IsEmptyStr(c_roomname))) {
1512 serv_printf("GOTO %s", c_roomname);
1513 serv_getln(buf, sizeof buf);
1514 if (buf[0] == '2') {
1515 safestrncpy(WC->wc_roomname, c_roomname, sizeof WC->wc_roomname);
1519 if (!strcasecmp(action, "image")) {
1521 } else if (!strcasecmp(action, "display_mime_icon")) {
1522 display_mime_icon();
1525 * All functions handled below this point ... make sure we log in
1526 * before doing anything else!
1528 } else if ((!WC->logged_in) && (!strcasecmp(action, "login"))) {
1530 } else if (!WC->logged_in) {
1531 display_login(NULL);
1535 * Various commands...
1538 else if (!strcasecmp(action, "do_welcome")) {
1540 } else if (!strcasecmp(action, "blank")) {
1542 } else if (!strcasecmp(action, "do_template")) {
1544 } else if (!strcasecmp(action, "display_aide_menu")) {
1545 display_aide_menu();
1546 } else if (!strcasecmp(action, "server_shutdown")) {
1548 } else if (!strcasecmp(action, "display_main_menu")) {
1549 display_main_menu();
1550 } else if (!strcasecmp(action, "who")) {
1552 } else if (!strcasecmp(action, "sslg")) {
1553 seconds_since_last_gexp();
1554 } else if (!strcasecmp(action, "who_inner_html")) {
1555 begin_ajax_response();
1557 end_ajax_response();
1558 } else if (!strcasecmp(action, "wholist_section")) {
1559 begin_ajax_response();
1561 end_ajax_response();
1562 } else if (!strcasecmp(action, "new_messages_html")) {
1563 begin_ajax_response();
1564 new_messages_section();
1565 end_ajax_response();
1566 } else if (!strcasecmp(action, "tasks_inner_html")) {
1567 begin_ajax_response();
1569 end_ajax_response();
1570 } else if (!strcasecmp(action, "calendar_inner_html")) {
1571 begin_ajax_response();
1573 end_ajax_response();
1574 } else if (!strcasecmp(action, "mini_calendar")) {
1575 begin_ajax_response();
1576 ajax_mini_calendar();
1577 end_ajax_response();
1578 } else if (!strcasecmp(action, "iconbar_ajax_menu")) {
1579 begin_ajax_response();
1581 end_ajax_response();
1582 } else if (!strcasecmp(action, "iconbar_ajax_rooms")) {
1583 begin_ajax_response();
1584 do_iconbar_roomlist();
1585 end_ajax_response();
1586 } else if (!strcasecmp(action, "knrooms")) {
1588 } else if (!strcasecmp(action, "gotonext")) {
1591 } else if (!strcasecmp(action, "skip")) {
1593 } else if (!strcasecmp(action, "ungoto")) {
1595 } else if (!strcasecmp(action, "dotgoto")) {
1596 if (WC->wc_view != VIEW_MAILBOX) { /* dotgoto acts like dotskip when we're in a mailbox view */
1599 smart_goto(bstr("room"));
1600 } else if (!strcasecmp(action, "dotskip")) {
1601 smart_goto(bstr("room"));
1602 } else if (!strcasecmp(action, "termquit")) {
1604 } else if (!strcasecmp(action, "readnew")) {
1605 readloop("readnew");
1606 } else if (!strcasecmp(action, "readold")) {
1607 readloop("readold");
1608 } else if (!strcasecmp(action, "readfwd")) {
1609 readloop("readfwd");
1610 } else if (!strcasecmp(action, "headers")) {
1611 readloop("headers");
1612 } else if (!strcasecmp(action, "do_search")) {
1613 readloop("do_search");
1614 } else if (!strcasecmp(action, "msg")) {
1615 embed_message(index[1]);
1616 } else if (!strcasecmp(action, "printmsg")) {
1617 print_message(index[1]);
1618 } else if (!strcasecmp(action, "msgheaders")) {
1619 display_headers(index[1]);
1620 } else if (!strcasecmp(action, "wiki")) {
1621 display_wiki_page();
1622 } else if (!strcasecmp(action, "display_enter")) {
1624 } else if (!strcasecmp(action, "post")) {
1626 } else if (!strcasecmp(action, "move_msg")) {
1628 } else if (!strcasecmp(action, "delete_msg")) {
1630 } else if (!strcasecmp(action, "userlist")) {
1632 } else if (!strcasecmp(action, "showuser")) {
1634 } else if (!strcasecmp(action, "display_page")) {
1636 } else if (!strcasecmp(action, "page_user")) {
1638 } else if (!strcasecmp(action, "chat")) {
1640 } else if (!strcasecmp(action, "display_private")) {
1641 display_private("", 0);
1642 } else if (!strcasecmp(action, "goto_private")) {
1644 } else if (!strcasecmp(action, "zapped_list")) {
1646 } else if (!strcasecmp(action, "display_zap")) {
1648 } else if (!strcasecmp(action, "zap")) {
1650 } else if (!strcasecmp(action, "display_entroom")) {
1652 } else if (!strcasecmp(action, "entroom")) {
1654 } else if (!strcasecmp(action, "display_whok")) {
1656 } else if (!strcasecmp(action, "do_invt_kick")) {
1658 } else if (!strcasecmp(action, "display_editroom")) {
1660 } else if (!strcasecmp(action, "netedit")) {
1662 } else if (!strcasecmp(action, "editroom")) {
1664 } else if (!strcasecmp(action, "display_editinfo")) {
1665 display_edit(_("Room info"), "EINF 0", "RINF", "editinfo", 1);
1666 } else if (!strcasecmp(action, "editinfo")) {
1667 save_edit(_("Room info"), "EINF 1", 1);
1668 } else if (!strcasecmp(action, "display_editbio")) {
1669 snprintf(buf, SIZ, "RBIO %s", WC->wc_fullname);
1670 display_edit(_("Your bio"), "NOOP", buf, "editbio", 3);
1671 } else if (!strcasecmp(action, "editbio")) {
1672 save_edit(_("Your bio"), "EBIO", 0);
1673 } else if (!strcasecmp(action, "confirm_move_msg")) {
1675 } else if (!strcasecmp(action, "delete_room")) {
1677 } else if (!strcasecmp(action, "validate")) {
1679 /* The users photo display / upload facility */
1680 } else if (!strcasecmp(action, "display_editpic")) {
1681 display_graphics_upload(_("your photo"),
1684 } else if (!strcasecmp(action, "editpic")) {
1685 do_graphics_upload("_userpic_");
1686 /* room picture dispay / upload facility */
1687 } else if (!strcasecmp(action, "display_editroompic")) {
1688 display_graphics_upload(_("the icon for this room"),
1691 } else if (!strcasecmp(action, "editroompic")) {
1692 do_graphics_upload("_roompic_");
1693 /* the greetingpage hello pic */
1694 } else if (!strcasecmp(action, "display_edithello")) {
1695 display_graphics_upload(_("the Greetingpicture for the login prompt"),
1698 } else if (!strcasecmp(action, "edithellopic")) {
1699 do_graphics_upload("hello");
1700 /* the logoff banner */
1701 } else if (!strcasecmp(action, "display_editgoodbyepic")) {
1702 display_graphics_upload(_("the Logoff banner picture"),
1703 "UIMG 0|%s|goodbuye",
1705 } else if (!strcasecmp(action, "editgoodbuyepic")) {
1706 do_graphics_upload("UIMG 1|%s|goodbuye");
1708 } else if (!strcasecmp(action, "delete_floor")) {
1710 } else if (!strcasecmp(action, "rename_floor")) {
1712 } else if (!strcasecmp(action, "create_floor")) {
1714 } else if (!strcasecmp(action, "display_editfloorpic")) {
1715 snprintf(buf, SIZ, "UIMG 0|_floorpic_|%s",
1716 bstr("which_floor"));
1717 display_graphics_upload(_("the icon for this floor"),
1720 } else if (!strcasecmp(action, "editfloorpic")) {
1721 snprintf(buf, SIZ, "UIMG 1|_floorpic_|%s",
1722 bstr("which_floor"));
1723 do_graphics_upload(buf);
1724 } else if (!strcasecmp(action, "display_reg")) {
1726 } else if (!strcasecmp(action, "display_changepw")) {
1728 } else if (!strcasecmp(action, "changepw")) {
1730 } else if (!strcasecmp(action, "display_edit_node")) {
1731 display_edit_node();
1732 } else if (!strcasecmp(action, "edit_node")) {
1734 } else if (!strcasecmp(action, "display_netconf")) {
1736 } else if (!strcasecmp(action, "display_confirm_delete_node")) {
1737 display_confirm_delete_node();
1738 } else if (!strcasecmp(action, "delete_node")) {
1740 } else if (!strcasecmp(action, "display_add_node")) {
1742 } else if (!strcasecmp(action, "terminate_session")) {
1744 terminate_session();
1745 } else if (!strcasecmp(action, "edit_me")) {
1747 } else if (!strcasecmp(action, "display_siteconfig")) {
1748 display_siteconfig();
1749 } else if (!strcasecmp(action, "chat_recv")) {
1751 } else if (!strcasecmp(action, "chat_send")) {
1753 } else if (!strcasecmp(action, "siteconfig")) {
1755 } else if (!strcasecmp(action, "display_generic")) {
1757 } else if (!strcasecmp(action, "do_generic")) {
1759 } else if (!strcasecmp(action, "ajax_servcmd")) {
1761 } else if (!strcasecmp(action, "display_menubar")) {
1763 } else if (!strcasecmp(action, "mimepart")) {
1764 mimepart(index[1], index[2], 0);
1765 } else if (!strcasecmp(action, "mimepart_download")) {
1766 mimepart(index[1], index[2], 1);
1767 } else if (!strcasecmp(action, "edit_vcard")) {
1769 } else if (!strcasecmp(action, "submit_vcard")) {
1771 } else if (!strcasecmp(action, "select_user_to_edit")) {
1772 select_user_to_edit(NULL, NULL);
1773 } else if (!strcasecmp(action, "display_edituser")) {
1774 display_edituser(NULL, 0);
1775 } else if (!strcasecmp(action, "edituser")) {
1777 } else if (!strcasecmp(action, "create_user")) {
1779 } else if (!strcasecmp(action, "changeview")) {
1781 } else if (!strcasecmp(action, "change_start_page")) {
1782 change_start_page();
1783 } else if (!strcasecmp(action, "display_floorconfig")) {
1784 display_floorconfig(NULL);
1785 } else if (!strcasecmp(action, "toggle_self_service")) {
1786 toggle_self_service();
1787 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1788 } else if (!strcasecmp(action, "display_edit_task")) {
1789 display_edit_task();
1790 } else if (!strcasecmp(action, "save_task")) {
1792 } else if (!strcasecmp(action, "display_edit_event")) {
1793 display_edit_event();
1794 } else if (!strcasecmp(action, "save_event")) {
1796 } else if (!strcasecmp(action, "respond_to_request")) {
1797 respond_to_request();
1798 } else if (!strcasecmp(action, "handle_rsvp")) {
1801 } else if (!strcasecmp(action, "summary")) {
1803 } else if (!strcasecmp(action, "summary_inner_div")) {
1804 begin_ajax_response();
1805 summary_inner_div();
1806 end_ajax_response();
1807 } else if (!strcasecmp(action, "display_customize_iconbar")) {
1808 display_customize_iconbar();
1809 } else if (!strcasecmp(action, "commit_iconbar")) {
1811 } else if (!strcasecmp(action, "set_room_policy")) {
1813 } else if (!strcasecmp(action, "display_inetconf")) {
1815 } else if (!strcasecmp(action, "save_inetconf")) {
1817 } else if (!strcasecmp(action, "display_smtpqueue")) {
1818 display_smtpqueue();
1819 } else if (!strcasecmp(action, "display_smtpqueue_inner_div")) {
1820 display_smtpqueue_inner_div();
1821 } else if (!strcasecmp(action, "display_sieve")) {
1823 } else if (!strcasecmp(action, "save_sieve")) {
1825 } else if (!strcasecmp(action, "display_pushemail")) {
1826 display_pushemail();
1827 } else if (!strcasecmp(action, "save_pushemail")) {
1829 } else if (!strcasecmp(action, "display_add_remove_scripts")) {
1830 display_add_remove_scripts(NULL);
1831 } else if (!strcasecmp(action, "create_script")) {
1833 } else if (!strcasecmp(action, "delete_script")) {
1835 } else if (!strcasecmp(action, "setup_wizard")) {
1837 } else if (!strcasecmp(action, "display_preferences")) {
1838 display_preferences();
1839 } else if (!strcasecmp(action, "set_preferences")) {
1841 } else if (!strcasecmp(action, "recp_autocomplete")) {
1842 recp_autocomplete(bstr("recp"));
1843 } else if (!strcasecmp(action, "cc_autocomplete")) {
1844 recp_autocomplete(bstr("cc"));
1845 } else if (!strcasecmp(action, "bcc_autocomplete")) {
1846 recp_autocomplete(bstr("bcc"));
1847 } else if (!strcasecmp(action, "display_address_book_middle_div")) {
1848 display_address_book_middle_div();
1849 } else if (!strcasecmp(action, "display_address_book_inner_div")) {
1850 display_address_book_inner_div();
1851 } else if (!strcasecmp(action, "set_floordiv_expanded")) {
1852 set_floordiv_expanded(index[1]);
1853 } else if (!strcasecmp(action, "diagnostics")) {
1854 output_headers(1, 1, 1, 0, 0, 0);
1855 wprintf("Session: %d<hr />\n", WC->wc_session);
1856 wprintf("Command: <br /><PRE>\n");
1858 wprintf("</PRE><hr />\n");
1859 wprintf("Variables: <br /><PRE>\n");
1861 wprintf("</PRE><hr />\n");
1863 } else if (!strcasecmp(action, "updatenote")) {
1865 } else if (!strcasecmp(action, "display_room_directory")) {
1866 display_room_directory();
1867 } else if (!strcasecmp(action, "display_pictureview")) {
1868 display_pictureview();
1869 } else if (!strcasecmp(action, "download_file")) {
1870 download_file(index[1]);
1871 } else if (!strcasecmp(action, "upload_file")) {
1875 /** When all else fais, display the main menu. */
1877 display_main_menu();
1882 if (content != NULL) {
1887 if (WC->upload_length > 0) {
1889 WC->upload_length = 0;
1894 * \brief Replacement for sleep() that uses select() in order to avoid SIGALRM
1895 * \param seconds how many seconds should we sleep?
1897 void sleeeeeeeeeep(int seconds)
1901 tv.tv_sec = seconds;
1903 select(0, NULL, NULL, NULL, &tv);