4 * This is the main transaction loop of the web service. It maintains a
5 * persistent session to the Citadel server, handling HTTP WebCit requests as
6 * they arrive and presenting a user interface.
11 #include "webserver.h"
17 * String to unset the cookie.
18 * Any date "in the past" will work, so I chose my birthday, right down to
19 * the exact minute. :)
21 static char *unset = "; expires=28-May-1971 18:10:00 GMT";
24 * \brief remove escaped strings from i.e. the url string (like %20 for blanks)
25 * \param buf the buffer to examine
27 void unescape_input(char *buf)
36 while ((buflen > 0) && (isspace(buf[buflen - 1]))){
46 /* don't let % chars through, rather truncate the input. */
56 sscanf(hex, "%02x", &b);
60 memmove(&buf[a + 1], &buf[a + 3], len);
71 * \brief Extract variables from the URL.
72 * \param url URL supplied by the HTTP parser
74 void addurls(char *url)
76 char *aptr, *bptr, *eptr;
82 eptr = buf + sizeof (buf);
84 /** locate the = sign */
85 n = safestrncpy(buf, up, sizeof buf);
86 if (n < 0) /** hm, we exceeded the buffer... hmmm what todo now? */
89 // while ((up < eptr) && (*up != '?') && (*up != '&'))
91 while (!IsEmptyStr(up)) {
93 while ((aptr < eptr) && (*aptr != '\0') && (*aptr != '='))
100 while ((bptr < eptr) && (*bptr != '\0') &&
101 (*bptr != '&') && (*bptr != ' '))
104 u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
105 u->next = WC->urlstrings;
108 if (safestrncpy(u->url_key, up, sizeof u->url_key) < 0)
109 lprintf(1, "URLkey to long! [%s]", up);
112 u->url_data = malloc(len + 2);
113 safestrncpy(u->url_data, aptr, len + 2);
114 u->url_data[len] = 0;
115 unescape_input(u->url_data);
119 lprintf(9, "%s = %s\n", u->url_key, u->url_data);
124 * \brief free urlstring memory
128 struct urlcontent *u;
130 while (WC->urlstrings != NULL) {
131 free(WC->urlstrings->url_data);
132 u = WC->urlstrings->next;
133 free(WC->urlstrings);
139 * \brief Diagnostic function to display the contents of all variables
143 struct urlcontent *u;
145 for (u = WC->urlstrings; u != NULL; u = u->next) {
146 wprintf("%38s = %s\n", u->url_key, u->url_data);
151 * \brief Return the value of a variable supplied to the current web page (from the url or a form)
152 * \param key The name of the variable we want
154 char *bstr(char *key)
156 struct urlcontent *u;
158 for (u = WC->urlstrings; u != NULL; u = u->next) {
159 if (!strcasecmp(u->url_key, key))
160 return (u->url_data);
166 * \brief web-printing funcion. uses our vsnprintf wrapper
167 * \param format printf format string
168 * \param ... the varargs to put into formatstring
170 void wprintf(const char *format,...)
175 va_start(arg_ptr, format);
176 vsnprintf(wbuf, sizeof wbuf, format, arg_ptr);
179 client_write(wbuf, strlen(wbuf));
184 * \brief wrap up an HTTP session, closes tags, etc.
185 * \todo multiline params?
186 * \param print_standard_html_footer should be set to 0 to transmit only, 1 to
187 * append the main menu and closing tags, or 2 to
188 * append the closing tags only.
190 void wDumpContent(int print_standard_html_footer)
192 if (print_standard_html_footer) {
193 wprintf("</div>\n"); /* end of "text" div */
194 do_template("trailing");
197 /* If we've been saving it all up for one big output burst,
198 * go ahead and do that now.
205 * \brief Copy a string, escaping characters which have meaning in HTML.
206 * \param target target buffer
207 * \param strbuf source buffer
208 * \param nbsp If nonzero, spaces are converted to non-breaking spaces.
209 * \param nolinebreaks if set, linebreaks are removed from the string.
211 long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks)
213 char *aptr, *bptr, *eptr;
218 eptr = target + tSize - 6; // our biggest unit to put in...
220 while ((bptr < eptr) && !IsEmptyStr(aptr) ){
222 memcpy(bptr, "<", 4);
225 else if (*aptr == '>') {
226 memcpy(bptr, ">", 4);
229 else if (*aptr == '&') {
230 memcpy(bptr, "&", 5);
233 else if (*aptr == '\"') {
234 memcpy(bptr, """, 6);
237 else if (*aptr == '\'') {
238 memcpy(bptr, "'", 5);
241 else if (*aptr == LB) {
245 else if (*aptr == RB) {
249 else if (*aptr == QU) {
253 else if ((*aptr == 32) && (nbsp == 1)) {
254 memcpy(bptr, " ", 6);
257 else if ((*aptr == '\n') && (nolinebreaks)) {
258 *bptr='\0'; /* nothing */
260 else if ((*aptr == '\r') && (nolinebreaks)) {
261 *bptr='\0'; /* nothing */
270 if ((bptr = eptr - 1 ) && !IsEmptyStr(aptr) )
272 return (bptr - target);
277 * \param strbuf what???
278 * \param nbsp If nonzero, spaces are converted to non-breaking spaces.
279 * \param nolinebreaks if set, linebreaks are removed from the string.
281 void escputs1(char *strbuf, int nbsp, int nolinebreaks)
286 if (strbuf == NULL) return;
287 Siz = (3 * strlen(strbuf)) + SIZ ;
289 stresc(buf, Siz, strbuf, nbsp, nolinebreaks);
295 * \brief static wrapper for ecsputs1
296 * \param strbuf buffer to print escaped to client
298 void escputs(char *strbuf)
300 escputs1(strbuf, 0, 0);
305 * \brief urlescape buffer and print it to the client
306 * \param strbuf buffer to urlescape
308 void urlescputs(char *strbuf)
312 urlesc(outbuf, SIZ, strbuf);
313 wprintf("%s", outbuf);
318 * \brief Copy a string, escaping characters for JavaScript strings.
319 * \param target output string
320 * \param strbuf input string
322 void jsesc(char *target, size_t tlen, char *strbuf)
331 len = strlen (strbuf);
333 tend = target + tlen;
337 while (!IsEmptyStr(sptr) &&
343 else if (*sptr == '>')
345 else if (*sptr == '\'') {
351 else if (*sptr == '"') {
361 else if (*sptr == '&') {
378 * \brief escape and print java script
379 * \param strbuf the js code
381 void jsescputs(char *strbuf)
385 jsesc(outbuf, SIZ, strbuf);
386 wprintf("%s", outbuf);
390 * \brief Copy a string, escaping characters for message text hold
391 * \param target target buffer
392 * \param strbuf source buffer
394 void msgesc(char *target, size_t tlen, char *strbuf)
403 len = strlen (strbuf);
405 tend = target + tlen;
409 while (!IsEmptyStr(sptr) &&
415 else if (*sptr == '\r')
417 else if (*sptr == '\'') {
434 * \brief print a string to the client after cleaning it with msgesc() and stresc()
435 * \param strbuf string to be printed
437 void msgescputs1( char *strbuf)
443 if (strbuf == NULL) return;
444 buflen = 3 * strlen(strbuf) + SIZ;
445 outbuf = malloc( buflen);
446 outbuf2 = malloc( buflen);
447 msgesc(outbuf, buflen, strbuf);
448 stresc(outbuf2, buflen, outbuf, 0, 0);
449 wprintf("%s", outbuf2);
455 * \brief print a string to the client after cleaning it with msgesc()
456 * \param strbuf string to be printed
458 void msgescputs(char *strbuf) {
462 if (strbuf == NULL) return;
463 len = (3 * strlen(strbuf)) + SIZ;
464 outbuf = malloc(len);
465 msgesc(outbuf, len, strbuf);
466 wprintf("%s", outbuf);
474 * \brief Output all that important stuff that the browser will want to see
476 void output_headers( int do_httpheaders, /**< 1 = output HTTP headers */
477 int do_htmlhead, /**< 1 = output HTML <head> section and <body> opener */
479 int do_room_banner, /**< 0=no, 1=yes,
480 * 2 = I'm going to embed my own, so don't open the
481 * <div id="content"> either.
484 int unset_cookies, /**< 1 = session is terminating, so unset the cookies */
485 int suppress_check, /**< 1 = suppress check for instant messages */
486 int cache /**< 1 = allow browser to cache this page */
491 wprintf("HTTP/1.1 200 OK\n");
492 http_datestring(httpnow, sizeof httpnow, time(NULL));
494 if (do_httpheaders) {
495 wprintf("Content-type: text/html; charset=utf-8\r\n"
497 "Connection: close\r\n",
498 PACKAGE_STRING, serv_info.serv_software
503 wprintf("Pragma: public\r\n"
504 "Cache-Control: max-age=3600, must-revalidate\r\n"
505 "Last-modified: %s\r\n",
510 wprintf("Pragma: no-cache\r\n"
511 "Cache-Control: no-store\r\n"
516 stuff_to_cookie(cookie, 1024, WC->wc_session, WC->wc_username,
517 WC->wc_password, WC->wc_roomname);
520 wprintf("Set-cookie: webcit=%s; path=/\r\n", unset);
522 wprintf("Set-cookie: webcit=%s; path=/\r\n", cookie);
523 if (server_cookie != NULL) {
524 wprintf("%s\n", server_cookie);
530 if (!access("static.local/webcit.css", R_OK)) {
531 svprintf("CSSLOCAL", WCS_STRING,
532 "<link href=\"static.local/webcit.css\" rel=\"stylesheet\" type=\"text/css\">"
542 /** check for ImportantMessages (these display in a div overlaying the main screen) */
543 if (!IsEmptyStr(WC->ImportantMessage)) {
544 wprintf("<div id=\"important_message\">\n"
545 "<span class=\"imsg\">");
546 escputs(WC->ImportantMessage);
547 wprintf("</span><br />\n"
549 "<script type=\"text/javascript\">\n"
550 " setTimeout('hide_imsg_popup()', 5000); \n"
552 WC->ImportantMessage[0] = 0;
555 if ( (WC->logged_in) && (!unset_cookies) ) {
556 wprintf("<div id=\"iconbar\">");
557 do_selected_iconbar();
558 /** check for instant messages (these display in a new window) */
563 if (do_room_banner == 1) {
564 wprintf("<div id=\"banner\">\n");
565 embed_room_banner(NULL, navbar_default);
570 if (do_room_banner == 1) {
571 wprintf("<div id=\"content\">\n");
577 * \brief Generic function to do an HTTP redirect. Easy and fun.
578 * \param whichpage target url to 302 to
580 void http_redirect(char *whichpage) {
581 wprintf("HTTP/1.1 302 Moved Temporarily\n");
582 wprintf("Location: %s\r\n", whichpage);
583 wprintf("URI: %s\r\n", whichpage);
584 wprintf("Content-type: text/html; charset=utf-8\r\n\r\n");
585 wprintf("<html><body>");
586 wprintf("Go <a href=\"%s\">here</A>.", whichpage);
587 wprintf("</body></html>\n");
593 * \brief Output a piece of content to the web browser
595 void http_transmit_thing(char *thing, size_t length, const char *content_type,
598 output_headers(0, 0, 0, 0, 0, is_static);
600 wprintf("Content-type: %s\r\n"
602 "Connection: close\r\n",
607 /** If we can send the data out compressed, please do so. */
609 char *compressed_data = NULL;
610 size_t compressed_len;
612 compressed_len = ((length * 101) / 100) + 100;
613 compressed_data = malloc(compressed_len);
615 if (compress_gzip((Bytef *) compressed_data,
618 (uLongf) length, Z_BEST_SPEED) == Z_OK) {
619 wprintf("Content-encoding: gzip\r\n"
620 "Content-length: %ld\r\n"
622 (long) compressed_len
624 client_write(compressed_data, (size_t)compressed_len);
625 free(compressed_data);
631 /** No compression ... just send it out as-is */
632 wprintf("Content-length: %ld\r\n"
636 client_write(thing, (size_t)length);
640 * \brief print menu box like used in the floor view or admin interface.
641 * This function takes pair of strings as va_args,
642 * \param Title Title string of the box
643 * \param Class CSS Class for the box
644 * \param nLines How many string pairs should we print? (URL, UrlText)
645 * \param ... Pairs of URL Strings and their Names
647 void print_menu_box(char* Title, char *Class, int nLines, ...)
652 svprintf("BOXTITLE", WCS_STRING, Title);
653 do_template("beginbox");
655 wprintf("<ul class=\"%s\">", Class);
657 va_start(arg_list, nLines);
658 for (i = 0; i < nLines; ++i)
660 wprintf("<li><a href=\"%s\">", va_arg(arg_list, char *));
661 wprintf((char *) va_arg(arg_list, char *));
662 wprintf("</a></li>\n");
666 wprintf("</a></li>\n");
670 do_template("endbox");
675 * \brief dump out static pages from disk
676 * \param what the file urs to print
678 void output_static(char *what)
686 const char *content_type;
689 fp = fopen(what, "rb");
691 lprintf(9, "output_static('%s') -- NOT FOUND --\n", what);
692 wprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
693 wprintf("Content-Type: text/plain\r\n");
695 wprintf("Cannot open %s: %s\r\n", what, strerror(errno));
698 content_type = GuessMimeByFilename(what, len);
700 if (fstat(fileno(fp), &statbuf) == -1) {
701 lprintf(9, "output_static('%s') -- FSTAT FAILED --\n", what);
702 wprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
703 wprintf("Content-Type: text/plain\r\n");
705 wprintf("Cannot fstat %s: %s\n", what, strerror(errno));
710 bytes = statbuf.st_size;
711 if ((bigbuffer = malloc(bytes + 2)) == NULL) {
712 lprintf(9, "output_static('%s') -- MALLOC FAILED (%s) --\n", what, strerror(errno));
713 wprintf("HTTP/1.1 500 internal server error\r\n");
714 wprintf("Content-Type: text/plain\r\n");
718 while (count < bytes) {
719 if ((res = fread(bigbuffer + count, 1, bytes - count, fp)) == 0) {
720 lprintf(9, "output_static('%s') -- FREAD FAILED (%s) %zu bytes of %zu --\n", what, strerror(errno), bytes - count, bytes);
721 wprintf("HTTP/1.1 500 internal server error \r\n");
722 wprintf("Content-Type: text/plain\r\n");
731 lprintf(9, "output_static('%s') %s\n", what, content_type);
732 http_transmit_thing(bigbuffer, (size_t)bytes, content_type, 1);
735 if (!strcasecmp(bstr("force_close_session"), "yes")) {
736 end_webcit_session();
741 * \brief When the browser requests an image file from the Citadel server,
742 * this function is called to transmit it.
747 char *xferbuf = NULL;
749 const char *MimeType;
751 serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
752 serv_getln(buf, sizeof buf);
754 bytes = extract_long(&buf[4], 0);
755 xferbuf = malloc(bytes + 2);
757 /** Read it from the server */
758 read_server_binary(xferbuf, bytes);
760 serv_getln(buf, sizeof buf);
762 MimeType = GuessMimeType (xferbuf, bytes);
763 /** Write it to the browser */
764 if (!IsEmptyStr(MimeType))
766 http_transmit_thing(xferbuf,
773 /* hm... unknown mimetype? fallback to blank gif */
779 * Instead of an ugly 404, send a 1x1 transparent GIF
780 * when there's no such image on the server.
783 snprintf (blank_gif, SIZ, "%s%s", static_dirs[0], "/blank.gif");
784 output_static(blank_gif);
788 * \brief Generic function to output an arbitrary MIME part from an arbitrary
789 * message number on the server.
791 * \param msgnum Number of the item on the citadel server
792 * \param partnum The MIME part to be output
793 * \param force_download Nonzero to force set the Content-Type: header
794 * to "application/octet-stream"
796 void mimepart(char *msgnum, char *partnum, int force_download)
800 char content_type[256];
801 char *content = NULL;
803 serv_printf("OPNA %s|%s", msgnum, partnum);
804 serv_getln(buf, sizeof buf);
806 bytes = extract_long(&buf[4], 0);
807 content = malloc(bytes + 2);
808 if (force_download) {
809 strcpy(content_type, "application/octet-stream");
812 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
814 output_headers(0, 0, 0, 0, 0, 0);
815 read_server_binary(content, bytes);
817 serv_getln(buf, sizeof buf);
818 http_transmit_thing(content, bytes, content_type, 0);
821 wprintf("HTTP/1.1 404 %s\n", &buf[4]);
822 output_headers(0, 0, 0, 0, 0, 0);
823 wprintf("Content-Type: text/plain\r\n");
825 wprintf(_("An error occurred while retrieving this part: %s\n"), &buf[4]);
832 * \brief Read any MIME part of a message, from the server, into memory.
833 * \param msgnum number of the message on the citadel server
834 * \param partnum the MIME part to be loaded
836 char *load_mimepart(long msgnum, char *partnum)
840 char content_type[SIZ];
843 serv_printf("DLAT %ld|%s", msgnum, partnum);
844 serv_getln(buf, sizeof buf);
846 bytes = extract_long(&buf[4], 0);
847 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
849 content = malloc(bytes + 2);
850 serv_read(content, bytes);
852 content[bytes] = 0; /* null terminate for good measure */
863 * \brief Convenience functions to display a page containing only a string
864 * \param titlebarcolor color of the titlebar of the frame
865 * \param titlebarmsg text to display in the title bar
866 * \param messagetext body of the box
868 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
870 wprintf("HTTP/1.1 200 OK\n");
871 output_headers(1, 1, 2, 0, 0, 0);
872 wprintf("<div id=\"banner\">\n");
873 wprintf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
874 wprintf("<span class=\"titlebar\">%s</span>\n", titlebarmsg);
875 wprintf("</td></tr></table>\n");
876 wprintf("</div>\n<div id=\"content\">\n");
877 escputs(messagetext);
885 * \brief Display a blank page.
887 void blank_page(void) {
888 output_headers(1, 1, 0, 0, 0, 0);
894 * \brief A template has been requested
896 void url_do_template(void) {
897 do_template(bstr("template"));
903 * \brief Offer to make any page the user's "start page."
905 void offer_start_page(void) {
906 wprintf("<a href=\"change_start_page?startpage=");
907 urlescputs(WC->this_page);
909 wprintf(_("Make this my start page"));
912 wprintf("<br/><a href=\"rss?room=");
913 urlescputs(WC->wc_roomname);
914 wprintf("\" title=\"RSS 2.0 feed for ");
915 escputs(WC->wc_roomname);
916 wprintf("\"><img alt=\"RSS\" border=\"0\" src=\"static/xml_button.gif\"/></a>\n");
922 * \brief Change the user's start page
924 void change_start_page(void) {
926 if (bstr("startpage") == NULL) {
927 safestrncpy(WC->ImportantMessage,
928 _("You no longer have a start page selected."),
929 sizeof WC->ImportantMessage);
934 set_preference("startpage", bstr("startpage"), 1);
936 output_headers(1, 1, 0, 0, 0, 0);
937 do_template("newstartpage");
944 * \brief convenience function to indicate success
945 * \param successmessage the mesage itself
947 void display_success(char *successmessage)
949 convenience_page("007700", "OK", successmessage);
954 * \brief Authorization required page
955 * This is probably temporary and should be revisited
956 * \param message message to put in header
958 void authorization_required(const char *message)
960 wprintf("HTTP/1.1 401 Authorization Required\r\n");
961 wprintf("WWW-Authenticate: Basic realm=\"\"\r\n", serv_info.serv_humannode);
962 wprintf("Content-Type: text/html\r\n\r\n");
964 wprintf(_("Authorization Required"));
965 wprintf("</h1>\r\n");
966 wprintf(_("The resource you requested requires a valid username and password. "
967 "You could not be logged in: %s\n"), message);
972 * \brief This function is called by the MIME parser to handle data uploaded by
973 * the browser. Form data, uploaded files, and the data from HTTP PUT
974 * operations (such as those found in GroupDAV) all arrive this way.
976 * \param name Name of the item being uploaded
977 * \param filename Filename of the item being uploaded
978 * \param partnum MIME part identifier (not needed)
979 * \param disp MIME content disposition (not needed)
980 * \param content The actual data
981 * \param cbtype MIME content-type
982 * \param cbcharset Character set
983 * \param length Content length
984 * \param encoding MIME encoding type (not needed)
985 * \param userdata Not used here
987 void upload_handler(char *name, char *filename, char *partnum, char *disp,
988 void *content, char *cbtype, char *cbcharset,
989 size_t length, char *encoding, void *userdata)
991 struct urlcontent *u;
993 lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n", name, cbtype, length);
996 if ( (length > 0) && (IsEmptyStr(cbtype)) ) {
997 u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
998 u->next = WC->urlstrings;
1000 safestrncpy(u->url_key, name, sizeof(u->url_key));
1001 u->url_data = malloc(length + 1);
1002 memcpy(u->url_data, content, length);
1003 u->url_data[length] = 0;
1004 /* lprintf(9, "Key: <%s> Data: <%s>\n", u->url_key, u->url_data); */
1007 /** Uploaded files */
1008 if ( (length > 0) && (!IsEmptyStr(cbtype)) ) {
1009 WC->upload = malloc(length);
1010 if (WC->upload != NULL) {
1011 WC->upload_length = length;
1012 safestrncpy(WC->upload_filename, filename,
1013 sizeof(WC->upload_filename));
1014 safestrncpy(WC->upload_content_type, cbtype,
1015 sizeof(WC->upload_content_type));
1016 memcpy(WC->upload, content, length);
1019 lprintf(3, "malloc() failed: %s\n", strerror(errno));
1026 * \brief Convenience functions to wrap around asynchronous ajax responses
1028 void begin_ajax_response(void) {
1029 output_headers(0, 0, 0, 0, 0, 0);
1031 wprintf("Content-type: text/html; charset=UTF-8\r\n"
1033 "Connection: close\r\n"
1034 "Pragma: no-cache\r\n"
1035 "Cache-Control: no-cache\r\n"
1043 * \brief print ajax response footer
1045 void end_ajax_response(void) {
1051 * \brief Wraps a Citadel server command in an AJAX transaction.
1053 void ajax_servcmd(void)
1056 char gcontent[1024];
1060 begin_ajax_response();
1062 serv_printf("%s", bstr("g_cmd"));
1063 serv_getln(buf, sizeof buf);
1064 wprintf("%s\n", buf);
1066 if (buf[0] == '8') {
1067 serv_printf("\n\n000");
1069 if ((buf[0] == '1') || (buf[0] == '8')) {
1070 while (serv_getln(gcontent, sizeof gcontent), strcmp(gcontent, "000")) {
1071 wprintf("%s\n", gcontent);
1075 if (buf[0] == '4') {
1076 text_to_server(bstr("g_input"));
1079 if (buf[0] == '6') {
1080 len = atol(&buf[4]);
1082 serv_read(junk, len);
1085 if (buf[0] == '7') {
1086 len = atol(&buf[4]);
1088 memset(junk, 0, len);
1089 serv_write(junk, len);
1093 end_ajax_response();
1096 * This is kind of an ugly hack, but this is the only place it can go.
1097 * If the command was GEXP, then the instant messenger window must be
1098 * running, so reset the "last_pager_check" watchdog timer so
1099 * that page_popup() doesn't try to open it a second time.
1101 if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) {
1102 WC->last_pager_check = time(NULL);
1108 * \brief Helper function for the asynchronous check to see if we need
1109 * to open the instant messenger window.
1111 void seconds_since_last_gexp(void)
1115 begin_ajax_response();
1116 if ( (time(NULL) - WC->last_pager_check) < 30) {
1121 serv_getln(buf, sizeof buf);
1122 if (buf[3] == '*') {
1129 end_ajax_response();
1136 * \brief Entry point for WebCit transaction
1138 void session_loop(struct httprequest *req)
1146 char request_method[128];
1147 char pathname[1024];
1148 int a, b, nBackDots, nEmpty;
1149 int ContentLength = 0;
1151 char ContentType[512];
1152 char *content = NULL;
1153 char *content_end = NULL;
1154 struct httprequest *hptr;
1155 char browser_host[256];
1156 char user_agent[256];
1162 * We stuff these with the values coming from the client cookies,
1163 * so we can use them to reconnect a timed out session if we have to.
1165 char c_username[SIZ];
1166 char c_password[SIZ];
1167 char c_roomname[SIZ];
1168 char c_httpauth_string[SIZ];
1169 char c_httpauth_user[SIZ];
1170 char c_httpauth_pass[SIZ];
1173 safestrncpy(c_username, "", sizeof c_username);
1174 safestrncpy(c_password, "", sizeof c_password);
1175 safestrncpy(c_roomname, "", sizeof c_roomname);
1176 safestrncpy(c_httpauth_string, "", sizeof c_httpauth_string);
1177 safestrncpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER, sizeof c_httpauth_user);
1178 safestrncpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS, sizeof c_httpauth_pass);
1179 strcpy(browser_host, "");
1181 WC->upload_length = 0;
1187 if (hptr == NULL) return;
1189 safestrncpy(cmd, hptr->line, sizeof cmd);
1191 extract_token(request_method, cmd, 0, ' ', sizeof request_method);
1192 extract_token(pathname, cmd, 1, ' ', sizeof pathname);
1194 /** Figure out the action */
1196 sizes[0] = sizeof action;
1199 index[a] = arg[a-1];
1200 sizes[a] = sizeof arg[a-1];
1202 //// index[9] = &foo; todo
1205 for ( a = 0; a < 9; ++a)
1207 extract_token(index[a], pathname, a + 1, '/', sizes[a]);
1208 if (strstr(index[a], "?")) *strstr(index[a], "?") = 0;
1209 if (strstr(index[a], "&")) *strstr(index[a], "&") = 0;
1210 if (strstr(index[a], " ")) *strstr(index[a], " ") = 0;
1211 if ((index[a][0] == '.') && (index[a][1] == '.'))
1213 if (index[a][0] == '\0')
1217 while (hptr != NULL) {
1218 safestrncpy(buf, hptr->line, sizeof buf);
1219 /* lprintf(9, "HTTP HEADER: %s\n", buf); */
1222 if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
1223 safestrncpy(cookie, &buf[15], sizeof cookie);
1224 cookie_to_stuff(cookie, NULL,
1225 c_username, sizeof c_username,
1226 c_password, sizeof c_password,
1227 c_roomname, sizeof c_roomname);
1229 else if (!strncasecmp(buf, "Authorization: Basic ", 21)) {
1230 CtdlDecodeBase64(c_httpauth_string, &buf[21], strlen(&buf[21]));
1231 extract_token(c_httpauth_user, c_httpauth_string, 0, ':', sizeof c_httpauth_user);
1232 extract_token(c_httpauth_pass, c_httpauth_string, 1, ':', sizeof c_httpauth_pass);
1234 else if (!strncasecmp(buf, "Content-length: ", 16)) {
1235 ContentLength = atoi(&buf[16]);
1237 else if (!strncasecmp(buf, "Content-type: ", 14)) {
1238 safestrncpy(ContentType, &buf[14], sizeof ContentType);
1240 else if (!strncasecmp(buf, "User-agent: ", 12)) {
1241 safestrncpy(user_agent, &buf[12], sizeof user_agent);
1243 else if (!strncasecmp(buf, "X-Forwarded-Host: ", 18)) {
1245 safestrncpy(WC->http_host, &buf[18], sizeof WC->http_host);
1248 else if (!strncasecmp(buf, "Host: ", 6)) {
1249 if (IsEmptyStr(WC->http_host)) {
1250 safestrncpy(WC->http_host, &buf[6], sizeof WC->http_host);
1253 else if (!strncasecmp(buf, "X-Forwarded-For: ", 17)) {
1254 safestrncpy(browser_host, &buf[17], sizeof browser_host);
1255 while (num_tokens(browser_host, ',') > 1) {
1256 remove_token(browser_host, 0, ',');
1258 striplt(browser_host);
1260 /** Only WAP gateways explicitly name this content-type */
1261 else if (strstr(buf, "text/vnd.wap.wml")) {
1266 if (ContentLength > 0) {
1267 content = malloc(ContentLength + SIZ);
1268 memset(content, 0, ContentLength + SIZ);
1269 snprintf(content, ContentLength + SIZ, "Content-type: %s\n"
1270 "Content-length: %d\n\n",
1271 ContentType, ContentLength);
1272 body_start = strlen(content);
1274 /** Read the entire input data at once. */
1275 client_read(WC->http_sock, &content[BytesRead+body_start], ContentLength);
1277 if (!strncasecmp(ContentType, "application/x-www-form-urlencoded", 33)) {
1278 addurls(&content[body_start]);
1279 } else if (!strncasecmp(ContentType, "multipart", 9)) {
1280 content_end = content + ContentLength + body_start;
1281 mime_parser(content, content_end, *upload_handler, NULL, NULL, NULL, 0);
1287 /** make a note of where we are in case the user wants to save it */
1288 safestrncpy(WC->this_page, cmd, sizeof(WC->this_page));
1289 remove_token(WC->this_page, 2, ' ');
1290 remove_token(WC->this_page, 0, ' ');
1292 /** If there are variables in the URL, we must grab them now */
1294 for (a = 0; a < len; ++a) {
1295 if ((cmd[a] == '?') || (cmd[a] == '&')) {
1296 for (b = a; b < len; ++b) {
1297 if (isspace(cmd[b])){
1302 addurls(&cmd[a + 1]);
1308 /** If it's a "force 404" situation then display the error and bail. */
1309 if (!strcmp(action, "404")) {
1310 wprintf("HTTP/1.1 404 Not found\r\n");
1311 wprintf("Content-Type: text/plain\r\n");
1313 wprintf("Not found\r\n");
1314 goto SKIP_ALL_THIS_CRAP;
1317 /** Static content can be sent without connecting to Citadel. */
1319 for (a=0; a<ndirs; ++a) {
1320 if (!strcasecmp(action, (char*)static_content_dirs[a])) { /* map web to disk location */
1328 snprintf(buf, sizeof buf, "%s/%s/%s/%s/%s/%s/%s/%s",
1329 static_dirs[n_static],
1330 index[1], index[2], index[3], index[4], index[5], index[6], index[7]);
1331 for (a=0; a<8; ++a) {
1332 if (buf[strlen(buf)-1] == '/') {
1333 buf[strlen(buf)-1] = 0;
1336 for (a = 0; a < strlen(buf); ++a) {
1337 if (isspace(buf[a])) {
1345 lprintf(9, "Suspicious request. Ignoring.");
1346 wprintf("HTTP/1.1 404 Security check failed\r\n");
1347 wprintf("Content-Type: text/plain\r\n");
1349 wprintf("You have sent a malformed or invalid request.\r\n");
1351 goto SKIP_ALL_THIS_CRAP; /* Don't try to connect */
1354 /* If the client sent a nonce that is incorrect, kill the request. */
1355 if (strlen(bstr("nonce")) > 0) {
1356 lprintf(9, "Comparing supplied nonce %s to session nonce %ld\n",
1357 bstr("nonce"), WC->nonce);
1358 if (atoi(bstr("nonce")) != WC->nonce) {
1359 lprintf(9, "Ignoring request with mismatched nonce.\n");
1360 wprintf("HTTP/1.1 404 Security check failed\r\n");
1361 wprintf("Content-Type: text/plain\r\n");
1363 wprintf("Security check failed.\r\n");
1364 goto SKIP_ALL_THIS_CRAP;
1369 * If we're not connected to a Citadel server, try to hook up the
1372 if (!WC->connected) {
1373 if (!strcasecmp(ctdlhost, "uds")) {
1374 /* unix domain socket */
1375 snprintf(buf, SIZ, "%s/citadel.socket", ctdlport);
1376 WC->serv_sock = uds_connectsock(buf);
1380 WC->serv_sock = tcp_connectsock(ctdlhost, ctdlport);
1383 if (WC->serv_sock < 0) {
1385 goto SKIP_ALL_THIS_CRAP;
1389 serv_getln(buf, sizeof buf); /** get the server welcome message */
1392 * From what host is our user connecting? Go with
1393 * the host at the other end of the HTTP socket,
1394 * unless we are following X-Forwarded-For: headers
1395 * and such a header has already turned up something.
1397 if ( (!follow_xff) || (strlen(browser_host) == 0) ) {
1398 locate_host(browser_host, WC->http_sock);
1401 get_serv_info(browser_host, user_agent);
1402 if (serv_info.serv_rev_level < MINIMUM_CIT_VERSION) {
1403 wprintf(_("You are connected to a Citadel "
1404 "server running Citadel %d.%02d. \n"
1405 "In order to run this version of WebCit "
1406 "you must also have Citadel %d.%02d or"
1408 serv_info.serv_rev_level / 100,
1409 serv_info.serv_rev_level % 100,
1410 MINIMUM_CIT_VERSION / 100,
1411 MINIMUM_CIT_VERSION % 100
1413 end_webcit_session();
1414 goto SKIP_ALL_THIS_CRAP;
1420 * Functions which can be performed without logging in
1422 if (!strcasecmp(action, "listsub")) {
1424 goto SKIP_ALL_THIS_CRAP;
1426 if (!strcasecmp(action, "freebusy")) {
1428 goto SKIP_ALL_THIS_CRAP;
1432 * If we're not logged in, but we have HTTP Authentication data,
1433 * try logging in to Citadel using that.
1435 if ((!WC->logged_in)
1436 && (strlen(c_httpauth_user) > 0)
1437 && (strlen(c_httpauth_pass) > 0)) {
1438 serv_printf("USER %s", c_httpauth_user);
1439 serv_getln(buf, sizeof buf);
1440 if (buf[0] == '3') {
1441 serv_printf("PASS %s", c_httpauth_pass);
1442 serv_getln(buf, sizeof buf);
1443 if (buf[0] == '2') {
1444 become_logged_in(c_httpauth_user,
1445 c_httpauth_pass, buf);
1446 safestrncpy(WC->httpauth_user, c_httpauth_user, sizeof WC->httpauth_user);
1447 safestrncpy(WC->httpauth_pass, c_httpauth_pass, sizeof WC->httpauth_pass);
1449 /** Should only display when password is wrong */
1450 authorization_required(&buf[4]);
1451 goto SKIP_ALL_THIS_CRAP;
1456 /** This needs to run early */
1458 if (!strcasecmp(action, "rss")) {
1459 display_rss(bstr("room"), request_method);
1460 goto SKIP_ALL_THIS_CRAP;
1465 * The GroupDAV stuff relies on HTTP authentication instead of
1466 * our session's authentication.
1468 if (!strncasecmp(action, "groupdav", 8)) {
1469 groupdav_main(req, ContentType, /* do GroupDAV methods */
1470 ContentLength, content+body_start);
1471 if (!WC->logged_in) {
1472 WC->killthis = 1; /* If not logged in, don't */
1473 } /* keep the session active */
1474 goto SKIP_ALL_THIS_CRAP;
1479 * Automatically send requests with any method other than GET or
1480 * POST to the GroupDAV code as well.
1482 if ((strcasecmp(request_method, "GET")) && (strcasecmp(request_method, "POST"))) {
1483 groupdav_main(req, ContentType, /** do GroupDAV methods */
1484 ContentLength, content+body_start);
1485 if (!WC->logged_in) {
1486 WC->killthis = 1; /** If not logged in, don't */
1487 } /** keep the session active */
1488 goto SKIP_ALL_THIS_CRAP;
1492 * If we're not logged in, but we have username and password cookies
1493 * supplied by the browser, try using them to log in.
1495 if ((!WC->logged_in)
1496 && (!IsEmptyStr(c_username))
1497 && (!IsEmptyStr(c_password))) {
1498 serv_printf("USER %s", c_username);
1499 serv_getln(buf, sizeof buf);
1500 if (buf[0] == '3') {
1501 serv_printf("PASS %s", c_password);
1502 serv_getln(buf, sizeof buf);
1503 if (buf[0] == '2') {
1504 become_logged_in(c_username, c_password, buf);
1509 * If we don't have a current room, but a cookie specifying the
1510 * current room is supplied, make an effort to go there.
1512 if ((IsEmptyStr(WC->wc_roomname)) && (!IsEmptyStr(c_roomname))) {
1513 serv_printf("GOTO %s", c_roomname);
1514 serv_getln(buf, sizeof buf);
1515 if (buf[0] == '2') {
1516 safestrncpy(WC->wc_roomname, c_roomname, sizeof WC->wc_roomname);
1520 if (!strcasecmp(action, "image")) {
1522 } else if (!strcasecmp(action, "display_mime_icon")) {
1523 display_mime_icon();
1526 * All functions handled below this point ... make sure we log in
1527 * before doing anything else!
1529 } else if ((!WC->logged_in) && (!strcasecmp(action, "login"))) {
1531 } else if (!WC->logged_in) {
1532 display_login(NULL);
1536 * Various commands...
1539 else if (!strcasecmp(action, "do_welcome")) {
1541 } else if (!strcasecmp(action, "blank")) {
1543 } else if (!strcasecmp(action, "do_template")) {
1545 } else if (!strcasecmp(action, "display_aide_menu")) {
1546 display_aide_menu();
1547 } else if (!strcasecmp(action, "server_shutdown")) {
1549 } else if (!strcasecmp(action, "display_main_menu")) {
1550 display_main_menu();
1551 } else if (!strcasecmp(action, "who")) {
1553 } else if (!strcasecmp(action, "sslg")) {
1554 seconds_since_last_gexp();
1555 } else if (!strcasecmp(action, "who_inner_html")) {
1556 begin_ajax_response();
1558 end_ajax_response();
1559 } else if (!strcasecmp(action, "wholist_section")) {
1560 begin_ajax_response();
1562 end_ajax_response();
1563 } else if (!strcasecmp(action, "new_messages_html")) {
1564 begin_ajax_response();
1565 new_messages_section();
1566 end_ajax_response();
1567 } else if (!strcasecmp(action, "tasks_inner_html")) {
1568 begin_ajax_response();
1570 end_ajax_response();
1571 } else if (!strcasecmp(action, "calendar_inner_html")) {
1572 begin_ajax_response();
1574 end_ajax_response();
1575 } else if (!strcasecmp(action, "mini_calendar")) {
1576 begin_ajax_response();
1577 ajax_mini_calendar();
1578 end_ajax_response();
1579 } else if (!strcasecmp(action, "iconbar_ajax_menu")) {
1580 begin_ajax_response();
1582 end_ajax_response();
1583 } else if (!strcasecmp(action, "iconbar_ajax_rooms")) {
1584 begin_ajax_response();
1585 do_iconbar_roomlist();
1586 end_ajax_response();
1587 } else if (!strcasecmp(action, "knrooms")) {
1589 } else if (!strcasecmp(action, "gotonext")) {
1592 } else if (!strcasecmp(action, "skip")) {
1594 } else if (!strcasecmp(action, "ungoto")) {
1596 } else if (!strcasecmp(action, "dotgoto")) {
1597 if (WC->wc_view != VIEW_MAILBOX) { /* dotgoto acts like dotskip when we're in a mailbox view */
1600 smart_goto(bstr("room"));
1601 } else if (!strcasecmp(action, "dotskip")) {
1602 smart_goto(bstr("room"));
1603 } else if (!strcasecmp(action, "termquit")) {
1605 } else if (!strcasecmp(action, "readnew")) {
1606 readloop("readnew");
1607 } else if (!strcasecmp(action, "readold")) {
1608 readloop("readold");
1609 } else if (!strcasecmp(action, "readfwd")) {
1610 readloop("readfwd");
1611 } else if (!strcasecmp(action, "headers")) {
1612 readloop("headers");
1613 } else if (!strcasecmp(action, "do_search")) {
1614 readloop("do_search");
1615 } else if (!strcasecmp(action, "msg")) {
1616 embed_message(index[1]);
1617 } else if (!strcasecmp(action, "printmsg")) {
1618 print_message(index[1]);
1619 } else if (!strcasecmp(action, "msgheaders")) {
1620 display_headers(index[1]);
1621 } else if (!strcasecmp(action, "wiki")) {
1622 display_wiki_page();
1623 } else if (!strcasecmp(action, "display_enter")) {
1625 } else if (!strcasecmp(action, "post")) {
1627 } else if (!strcasecmp(action, "move_msg")) {
1629 } else if (!strcasecmp(action, "delete_msg")) {
1631 } else if (!strcasecmp(action, "userlist")) {
1633 } else if (!strcasecmp(action, "showuser")) {
1635 } else if (!strcasecmp(action, "display_page")) {
1637 } else if (!strcasecmp(action, "page_user")) {
1639 } else if (!strcasecmp(action, "chat")) {
1641 } else if (!strcasecmp(action, "display_private")) {
1642 display_private("", 0);
1643 } else if (!strcasecmp(action, "goto_private")) {
1645 } else if (!strcasecmp(action, "zapped_list")) {
1647 } else if (!strcasecmp(action, "display_zap")) {
1649 } else if (!strcasecmp(action, "zap")) {
1651 } else if (!strcasecmp(action, "display_entroom")) {
1653 } else if (!strcasecmp(action, "entroom")) {
1655 } else if (!strcasecmp(action, "display_whok")) {
1657 } else if (!strcasecmp(action, "do_invt_kick")) {
1659 } else if (!strcasecmp(action, "display_editroom")) {
1661 } else if (!strcasecmp(action, "netedit")) {
1663 } else if (!strcasecmp(action, "editroom")) {
1665 } else if (!strcasecmp(action, "display_editinfo")) {
1666 display_edit(_("Room info"), "EINF 0", "RINF", "editinfo", 1);
1667 } else if (!strcasecmp(action, "editinfo")) {
1668 save_edit(_("Room info"), "EINF 1", 1);
1669 } else if (!strcasecmp(action, "display_editbio")) {
1670 snprintf(buf, SIZ, "RBIO %s", WC->wc_fullname);
1671 display_edit(_("Your bio"), "NOOP", buf, "editbio", 3);
1672 } else if (!strcasecmp(action, "editbio")) {
1673 save_edit(_("Your bio"), "EBIO", 0);
1674 } else if (!strcasecmp(action, "confirm_move_msg")) {
1676 } else if (!strcasecmp(action, "delete_room")) {
1678 } else if (!strcasecmp(action, "validate")) {
1680 /* The users photo display / upload facility */
1681 } else if (!strcasecmp(action, "display_editpic")) {
1682 display_graphics_upload(_("your photo"),
1685 } else if (!strcasecmp(action, "editpic")) {
1686 do_graphics_upload("_userpic_");
1687 /* room picture dispay / upload facility */
1688 } else if (!strcasecmp(action, "display_editroompic")) {
1689 display_graphics_upload(_("the icon for this room"),
1692 } else if (!strcasecmp(action, "editroompic")) {
1693 do_graphics_upload("_roompic_");
1694 /* the greetingpage hello pic */
1695 } else if (!strcasecmp(action, "display_edithello")) {
1696 display_graphics_upload(_("the Greetingpicture for the login prompt"),
1699 } else if (!strcasecmp(action, "edithellopic")) {
1700 do_graphics_upload("hello");
1701 /* the logoff banner */
1702 } else if (!strcasecmp(action, "display_editgoodbyepic")) {
1703 display_graphics_upload(_("the Logoff banner picture"),
1704 "UIMG 0|%s|goodbuye",
1706 } else if (!strcasecmp(action, "editgoodbuyepic")) {
1707 do_graphics_upload("UIMG 1|%s|goodbuye");
1709 } else if (!strcasecmp(action, "delete_floor")) {
1711 } else if (!strcasecmp(action, "rename_floor")) {
1713 } else if (!strcasecmp(action, "create_floor")) {
1715 } else if (!strcasecmp(action, "display_editfloorpic")) {
1716 snprintf(buf, SIZ, "UIMG 0|_floorpic_|%s",
1717 bstr("which_floor"));
1718 display_graphics_upload(_("the icon for this floor"),
1721 } else if (!strcasecmp(action, "editfloorpic")) {
1722 snprintf(buf, SIZ, "UIMG 1|_floorpic_|%s",
1723 bstr("which_floor"));
1724 do_graphics_upload(buf);
1725 } else if (!strcasecmp(action, "display_reg")) {
1727 } else if (!strcasecmp(action, "display_changepw")) {
1729 } else if (!strcasecmp(action, "changepw")) {
1731 } else if (!strcasecmp(action, "display_edit_node")) {
1732 display_edit_node();
1733 } else if (!strcasecmp(action, "edit_node")) {
1735 } else if (!strcasecmp(action, "display_netconf")) {
1737 } else if (!strcasecmp(action, "display_confirm_delete_node")) {
1738 display_confirm_delete_node();
1739 } else if (!strcasecmp(action, "delete_node")) {
1741 } else if (!strcasecmp(action, "display_add_node")) {
1743 } else if (!strcasecmp(action, "terminate_session")) {
1745 terminate_session();
1746 } else if (!strcasecmp(action, "edit_me")) {
1748 } else if (!strcasecmp(action, "display_siteconfig")) {
1749 display_siteconfig();
1750 } else if (!strcasecmp(action, "chat_recv")) {
1752 } else if (!strcasecmp(action, "chat_send")) {
1754 } else if (!strcasecmp(action, "siteconfig")) {
1756 } else if (!strcasecmp(action, "display_generic")) {
1758 } else if (!strcasecmp(action, "do_generic")) {
1760 } else if (!strcasecmp(action, "ajax_servcmd")) {
1762 } else if (!strcasecmp(action, "display_menubar")) {
1764 } else if (!strcasecmp(action, "mimepart")) {
1765 mimepart(index[1], index[2], 0);
1766 } else if (!strcasecmp(action, "mimepart_download")) {
1767 mimepart(index[1], index[2], 1);
1768 } else if (!strcasecmp(action, "edit_vcard")) {
1770 } else if (!strcasecmp(action, "submit_vcard")) {
1772 } else if (!strcasecmp(action, "select_user_to_edit")) {
1773 select_user_to_edit(NULL, NULL);
1774 } else if (!strcasecmp(action, "display_edituser")) {
1775 display_edituser(NULL, 0);
1776 } else if (!strcasecmp(action, "edituser")) {
1778 } else if (!strcasecmp(action, "create_user")) {
1780 } else if (!strcasecmp(action, "changeview")) {
1782 } else if (!strcasecmp(action, "change_start_page")) {
1783 change_start_page();
1784 } else if (!strcasecmp(action, "display_floorconfig")) {
1785 display_floorconfig(NULL);
1786 } else if (!strcasecmp(action, "toggle_self_service")) {
1787 toggle_self_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")) {
1800 } else if (!strcasecmp(action, "summary")) {
1802 } else if (!strcasecmp(action, "summary_inner_div")) {
1803 begin_ajax_response();
1804 summary_inner_div();
1805 end_ajax_response();
1806 } else if (!strcasecmp(action, "display_customize_iconbar")) {
1807 display_customize_iconbar();
1808 } else if (!strcasecmp(action, "commit_iconbar")) {
1810 } else if (!strcasecmp(action, "set_room_policy")) {
1812 } else if (!strcasecmp(action, "display_inetconf")) {
1814 } else if (!strcasecmp(action, "save_inetconf")) {
1816 } else if (!strcasecmp(action, "display_smtpqueue")) {
1817 display_smtpqueue();
1818 } else if (!strcasecmp(action, "display_smtpqueue_inner_div")) {
1819 display_smtpqueue_inner_div();
1820 } else if (!strcasecmp(action, "display_sieve")) {
1822 } else if (!strcasecmp(action, "save_sieve")) {
1824 } else if (!strcasecmp(action, "display_pushemail")) {
1825 display_pushemail();
1826 } else if (!strcasecmp(action, "save_pushemail")) {
1828 } else if (!strcasecmp(action, "display_add_remove_scripts")) {
1829 display_add_remove_scripts(NULL);
1830 } else if (!strcasecmp(action, "create_script")) {
1832 } else if (!strcasecmp(action, "delete_script")) {
1834 } else if (!strcasecmp(action, "setup_wizard")) {
1836 } else if (!strcasecmp(action, "display_preferences")) {
1837 display_preferences();
1838 } else if (!strcasecmp(action, "set_preferences")) {
1840 } else if (!strcasecmp(action, "recp_autocomplete")) {
1841 recp_autocomplete(bstr("recp"));
1842 } else if (!strcasecmp(action, "cc_autocomplete")) {
1843 recp_autocomplete(bstr("cc"));
1844 } else if (!strcasecmp(action, "bcc_autocomplete")) {
1845 recp_autocomplete(bstr("bcc"));
1846 } else if (!strcasecmp(action, "display_address_book_middle_div")) {
1847 display_address_book_middle_div();
1848 } else if (!strcasecmp(action, "display_address_book_inner_div")) {
1849 display_address_book_inner_div();
1850 } else if (!strcasecmp(action, "set_floordiv_expanded")) {
1851 set_floordiv_expanded(index[1]);
1852 } else if (!strcasecmp(action, "diagnostics")) {
1853 output_headers(1, 1, 1, 0, 0, 0);
1854 wprintf("Session: %d<hr />\n", WC->wc_session);
1855 wprintf("Command: <br /><PRE>\n");
1857 wprintf("</PRE><hr />\n");
1858 wprintf("Variables: <br /><PRE>\n");
1860 wprintf("</PRE><hr />\n");
1862 } else if (!strcasecmp(action, "updatenote")) {
1864 } else if (!strcasecmp(action, "display_room_directory")) {
1865 display_room_directory();
1866 } else if (!strcasecmp(action, "display_pictureview")) {
1867 display_pictureview();
1868 } else if (!strcasecmp(action, "download_file")) {
1869 download_file(index[1]);
1870 } else if (!strcasecmp(action, "upload_file")) {
1874 /** When all else fais, display the main menu. */
1876 display_main_menu();
1881 if (content != NULL) {
1886 if (WC->upload_length > 0) {
1888 WC->upload_length = 0;
1893 * \brief Replacement for sleep() that uses select() in order to avoid SIGALRM
1894 * \param seconds how many seconds should we sleep?
1896 void sleeeeeeeeeep(int seconds)
1900 tv.tv_sec = seconds;
1902 select(0, NULL, NULL, NULL, &tv);