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";
23 HashList *HandlerHash = NULL;
26 void WebcitAddUrlHandler(const char * UrlString, long UrlSLen, WebcitHandlerFunc F, int IsAjax)
28 WebcitHandler *NewHandler;
30 if (HandlerHash == NULL)
31 HandlerHash = NewHash(1, NULL);
33 NewHandler = (WebcitHandler*) malloc(sizeof(WebcitHandler));
35 NewHandler->IsAjax = IsAjax;
37 Put(HandlerHash, UrlString, UrlSLen, NewHandler, NULL);
41 * remove escaped strings from i.e. the url string (like %20 for blanks)
43 long unescape_input(char *buf)
52 while ((buflen > 0) && (isspace(buf[buflen - 1]))){
62 /* don't let % chars through, rather truncate the input. */
72 sscanf(hex, "%02x", &b);
76 memmove(&buf[a + 1], &buf[a + 3], len);
86 void free_url(void *U)
88 urlcontent *u = (urlcontent*) U;
94 * Extract variables from the URL.
96 void addurls(char *url)
98 char *aptr, *bptr, *eptr;
103 struct wcsession *WCC = WC;
105 if (WCC->urlstrings == NULL)
106 WCC->urlstrings = NewHash(1, NULL);
107 eptr = buf + sizeof (buf);
109 /** locate the = sign */
110 n = safestrncpy(buf, up, sizeof buf);
111 if (n < 0) /* hm, we exceeded the buffer... hmmm what to do now? */
114 while (!IsEmptyStr(up)) {
116 while ((aptr < eptr) && (*aptr != '\0') && (*aptr != '='))
123 while ((bptr < eptr) && (*bptr != '\0')
124 && (*bptr != '&') && (*bptr != '?') && (*bptr != ' ')) {
128 u = (urlcontent *) malloc(sizeof(urlcontent));
130 keylen = safestrncpy(u->url_key, up, sizeof u->url_key);
132 lprintf(1, "URLkey to long! [%s]", up);
136 Put(WCC->urlstrings, u->url_key, keylen, u, free_url);
138 u->url_data = malloc(len + 2);
139 safestrncpy(u->url_data, aptr, len + 2);
140 u->url_data_size = unescape_input(u->url_data);
141 u->url_data[u->url_data_size] = '\0';
144 /* uncomment the following line to see each parameter in the log
145 lprintf(9, "%s = [%ld] %s\n", u->url_key, u->url_data_size, u->url_data);
151 * free urlstring memory
155 DeleteHash(&WC->urlstrings);
159 * Diagnostic function to display the contents of all variables
164 struct wcsession *WCC = WC;
171 Cursor = GetNewHashPos ();
172 while (GetNextHashPos(WCC->urlstrings, Cursor, &HKLen, &HKey, &U)) {
174 wprintf("%38s = %s\n", u->url_key, u->url_data);
179 * Return the value of a variable supplied to the current web page (from the url or a form)
182 const char *XBstr(char *key, size_t keylen, size_t *len)
186 if ((WC->urlstrings != NULL) &&
187 GetHash(WC->urlstrings, key, keylen, &U)) {
188 *len = ((urlcontent *)U)->url_data_size;
189 return ((urlcontent *)U)->url_data;
197 const char *XBSTR(char *key, size_t *len)
201 if ((WC->urlstrings != NULL) &&
202 GetHash(WC->urlstrings, key, strlen (key), &U)){
203 *len = ((urlcontent *)U)->url_data_size;
204 return ((urlcontent *)U)->url_data;
213 const char *BSTR(char *key)
217 if ((WC->urlstrings != NULL) &&
218 GetHash(WC->urlstrings, key, strlen (key), &U))
219 return ((urlcontent *)U)->url_data;
224 const char *Bstr(char *key, size_t keylen)
228 if ((WC->urlstrings != NULL) &&
229 GetHash(WC->urlstrings, key, keylen, &U))
230 return ((urlcontent *)U)->url_data;
235 long LBstr(char *key, size_t keylen)
239 if ((WC->urlstrings != NULL) &&
240 GetHash(WC->urlstrings, key, keylen, &U))
241 return atol(((urlcontent *)U)->url_data);
246 long LBSTR(char *key)
250 if ((WC->urlstrings != NULL) &&
251 GetHash(WC->urlstrings, key, strlen(key), &U))
252 return atol(((urlcontent *)U)->url_data);
257 int IBstr(char *key, size_t keylen)
261 if ((WC->urlstrings != NULL) &&
262 GetHash(WC->urlstrings, key, keylen, &U))
263 return atoi(((urlcontent *)U)->url_data);
272 if ((WC->urlstrings != NULL) &&
273 GetHash(WC->urlstrings, key, strlen(key), &U))
274 return atoi(((urlcontent *)U)->url_data);
279 int HaveBstr(char *key, size_t keylen)
283 if ((WC->urlstrings != NULL) &&
284 GetHash(WC->urlstrings, key, keylen, &U))
285 return ((urlcontent *)U)->url_data_size != 0;
290 int HAVEBSTR(char *key)
294 if ((WC->urlstrings != NULL) &&
295 GetHash(WC->urlstrings, key, strlen(key), &U))
296 return ((urlcontent *)U)->url_data_size != 0;
302 int YesBstr(char *key, size_t keylen)
306 if ((WC->urlstrings != NULL) &&
307 GetHash(WC->urlstrings, key, keylen, &U))
308 return strcmp( ((urlcontent *)U)->url_data, "yes") == 0;
313 int YESBSTR(char *key)
317 if ((WC->urlstrings != NULL) &&
318 GetHash(WC->urlstrings, key, strlen(key), &U))
319 return strcmp( ((urlcontent *)U)->url_data, "yes") == 0;
325 * web-printing funcion. uses our vsnprintf wrapper
327 void wprintf(const char *format,...)
332 va_start(arg_ptr, format);
333 vsnprintf(wbuf, sizeof wbuf, format, arg_ptr);
336 client_write(wbuf, strlen(wbuf));
341 * wrap up an HTTP session, closes tags, etc.
343 * print_standard_html_footer should be set to:
344 * 0 to transmit only,
345 * 1 to append the main menu and closing tags,
346 * 2 to append the closing tags only.
348 void wDumpContent(int print_standard_html_footer)
350 if (print_standard_html_footer) {
351 wprintf("</div>\n"); /* end of "text" div */
352 do_template("trailing");
355 /* If we've been saving it all up for one big output burst,
356 * go ahead and do that now.
363 * Copy a string, escaping characters which have meaning in HTML.
365 * target target buffer
366 * strbuf source buffer
367 * nbsp If nonzero, spaces are converted to non-breaking spaces.
368 * nolinebreaks if set, linebreaks are removed from the string.
370 long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks)
372 char *aptr, *bptr, *eptr;
377 eptr = target + tSize - 6; // our biggest unit to put in...
379 while ((bptr < eptr) && !IsEmptyStr(aptr) ){
381 memcpy(bptr, "<", 4);
384 else if (*aptr == '>') {
385 memcpy(bptr, ">", 4);
388 else if (*aptr == '&') {
389 memcpy(bptr, "&", 5);
392 else if (*aptr == '\"') {
393 memcpy(bptr, """, 6);
396 else if (*aptr == '\'') {
397 memcpy(bptr, "'", 5);
400 else if (*aptr == LB) {
404 else if (*aptr == RB) {
408 else if (*aptr == QU) {
412 else if ((*aptr == 32) && (nbsp == 1)) {
413 memcpy(bptr, " ", 6);
416 else if ((*aptr == '\n') && (nolinebreaks)) {
417 *bptr='\0'; /* nothing */
419 else if ((*aptr == '\r') && (nolinebreaks)) {
420 *bptr='\0'; /* nothing */
429 if ((bptr = eptr - 1 ) && !IsEmptyStr(aptr) )
431 return (bptr - target);
434 void escputs1(char *strbuf, int nbsp, int nolinebreaks)
439 if (strbuf == NULL) return;
440 Siz = (3 * strlen(strbuf)) + SIZ ;
442 stresc(buf, Siz, strbuf, nbsp, nolinebreaks);
448 * static wrapper for ecsputs1
450 void escputs(char *strbuf)
452 escputs1(strbuf, 0, 0);
457 * urlescape buffer and print it to the client
459 void urlescputs(char *strbuf)
463 urlesc(outbuf, SIZ, strbuf);
464 wprintf("%s", outbuf);
469 * Copy a string, escaping characters for JavaScript strings.
471 void jsesc(char *target, size_t tlen, char *strbuf)
480 len = strlen (strbuf);
482 tend = target + tlen;
486 while (!IsEmptyStr(sptr) &&
492 else if (*sptr == '>')
494 else if (*sptr == '\'') {
500 else if (*sptr == '"') {
510 else if (*sptr == '&') {
527 * escape and print javascript
529 void jsescputs(char *strbuf)
533 jsesc(outbuf, SIZ, strbuf);
534 wprintf("%s", outbuf);
538 * Copy a string, escaping characters for message text hold
540 void msgesc(char *target, size_t tlen, char *strbuf)
549 len = strlen (strbuf);
551 tend = target + tlen;
555 while (!IsEmptyStr(sptr) &&
561 else if (*sptr == '\r')
563 else if (*sptr == '\'') {
580 * \brief print a string to the client after cleaning it with msgesc() and stresc()
581 * \param strbuf string to be printed
583 void msgescputs1( char *strbuf)
589 if (strbuf == NULL) return;
590 buflen = 3 * strlen(strbuf) + SIZ;
591 outbuf = malloc( buflen);
592 outbuf2 = malloc( buflen);
593 msgesc(outbuf, buflen, strbuf);
594 stresc(outbuf2, buflen, outbuf, 0, 0);
595 wprintf("%s", outbuf2);
601 * \brief print a string to the client after cleaning it with msgesc()
602 * \param strbuf string to be printed
604 void msgescputs(char *strbuf) {
608 if (strbuf == NULL) return;
609 len = (3 * strlen(strbuf)) + SIZ;
610 outbuf = malloc(len);
611 msgesc(outbuf, len, strbuf);
612 wprintf("%s", outbuf);
620 * Output HTTP headers and leading HTML for a page
622 void output_headers( int do_httpheaders, /* 1 = output HTTP headers */
623 int do_htmlhead, /* 1 = output HTML <head> section and <body> opener */
625 int do_room_banner, /* 0=no, 1=yes,
626 * 2 = I'm going to embed my own, so don't open the
627 * <div id="content"> either.
630 int unset_cookies, /* 1 = session is terminating, so unset the cookies */
631 int suppress_check, /* 1 = suppress check for instant messages */
632 int cache /* 1 = allow browser to cache this page */
637 wprintf("HTTP/1.1 200 OK\n");
638 http_datestring(httpnow, sizeof httpnow, time(NULL));
640 if (do_httpheaders) {
641 wprintf("Content-type: text/html; charset=utf-8\r\n"
643 "Connection: close\r\n",
644 PACKAGE_STRING, serv_info.serv_software
649 wprintf("Pragma: public\r\n"
650 "Cache-Control: max-age=3600, must-revalidate\r\n"
651 "Last-modified: %s\r\n",
656 wprintf("Pragma: no-cache\r\n"
657 "Cache-Control: no-store\r\n"
662 stuff_to_cookie(cookie, 1024, WC->wc_session, WC->wc_username,
663 WC->wc_password, WC->wc_roomname);
666 wprintf("Set-cookie: webcit=%s; path=/\r\n", unset);
668 wprintf("Set-cookie: webcit=%s; path=/\r\n", cookie);
669 if (server_cookie != NULL) {
670 wprintf("%s\n", server_cookie);
676 if (!access("static.local/webcit.css", R_OK)) {
677 svprintf("CSSLOCAL", WCS_STRING,
678 "<link href=\"static.local/webcit.css\" rel=\"stylesheet\" type=\"text/css\">"
688 /* check for ImportantMessages (these display in a div overlaying the main screen) */
689 if (!IsEmptyStr(WC->ImportantMessage)) {
690 wprintf("<div id=\"important_message\">\n"
691 "<span class=\"imsg\">");
692 escputs(WC->ImportantMessage);
693 wprintf("</span><br />\n"
695 "<script type=\"text/javascript\">\n"
696 " setTimeout('hide_imsg_popup()', 5000); \n"
698 WC->ImportantMessage[0] = 0;
701 if ( (WC->logged_in) && (!unset_cookies) ) {
702 wprintf("<div id=\"iconbar\">");
703 do_selected_iconbar();
704 /** check for instant messages (these display in a new window) */
709 if (do_room_banner == 1) {
710 wprintf("<div id=\"banner\">\n");
711 embed_room_banner(NULL, navbar_default);
716 if (do_room_banner == 1) {
717 wprintf("<div id=\"content\">\n");
723 * Generic function to do an HTTP redirect. Easy and fun.
725 void http_redirect(char *whichpage) {
726 wprintf("HTTP/1.1 302 Moved Temporarily\n");
727 wprintf("Location: %s\r\n", whichpage);
728 wprintf("URI: %s\r\n", whichpage);
729 wprintf("Content-type: text/html; charset=utf-8\r\n\r\n");
730 wprintf("<html><body>");
731 wprintf("Go <a href=\"%s\">here</A>.", whichpage);
732 wprintf("</body></html>\n");
738 * Output a piece of content to the web browser using conformant HTTP and MIME semantics
740 void http_transmit_thing(char *thing, size_t length, const char *content_type,
743 output_headers(0, 0, 0, 0, 0, is_static);
745 wprintf("Content-type: %s\r\n"
747 "Connection: close\r\n",
752 /* If we can send the data out compressed, please do so. */
754 char *compressed_data = NULL;
755 size_t compressed_len;
757 compressed_len = ((length * 101) / 100) + 100;
758 compressed_data = malloc(compressed_len);
760 if (compress_gzip((Bytef *) compressed_data,
763 (uLongf) length, Z_BEST_SPEED) == Z_OK) {
764 wprintf("Content-encoding: gzip\r\n"
765 "Content-length: %ld\r\n"
767 (long) compressed_len
769 client_write(compressed_data, (size_t)compressed_len);
770 free(compressed_data);
776 /* No compression ... just send it out as-is */
777 wprintf("Content-length: %ld\r\n"
781 client_write(thing, (size_t)length);
785 * \brief print menu box like used in the floor view or admin interface.
786 * This function takes pair of strings as va_args,
787 * \param Title Title string of the box
788 * \param Class CSS Class for the box
789 * \param nLines How many string pairs should we print? (URL, UrlText)
790 * \param ... Pairs of URL Strings and their Names
792 void print_menu_box(char* Title, char *Class, int nLines, ...)
797 svprintf("BOXTITLE", WCS_STRING, Title);
798 do_template("beginbox");
800 wprintf("<ul class=\"%s\">", Class);
802 va_start(arg_list, nLines);
803 for (i = 0; i < nLines; ++i)
805 wprintf("<li><a href=\"%s\">", va_arg(arg_list, char *));
806 wprintf((char *) va_arg(arg_list, char *));
807 wprintf("</a></li>\n");
811 wprintf("</a></li>\n");
815 do_template("endbox");
820 * \brief dump out static pages from disk
821 * \param what the file urs to print
823 void output_static(char *what)
831 const char *content_type;
834 fp = fopen(what, "rb");
836 lprintf(9, "output_static('%s') -- NOT FOUND --\n", what);
837 wprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
838 wprintf("Content-Type: text/plain\r\n");
840 wprintf("Cannot open %s: %s\r\n", what, strerror(errno));
843 content_type = GuessMimeByFilename(what, len);
845 if (fstat(fileno(fp), &statbuf) == -1) {
846 lprintf(9, "output_static('%s') -- FSTAT FAILED --\n", what);
847 wprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
848 wprintf("Content-Type: text/plain\r\n");
850 wprintf("Cannot fstat %s: %s\n", what, strerror(errno));
855 bytes = statbuf.st_size;
856 if ((bigbuffer = malloc(bytes + 2)) == NULL) {
857 lprintf(9, "output_static('%s') -- MALLOC FAILED (%s) --\n", what, strerror(errno));
858 wprintf("HTTP/1.1 500 internal server error\r\n");
859 wprintf("Content-Type: text/plain\r\n");
863 while (count < bytes) {
864 if ((res = fread(bigbuffer + count, 1, bytes - count, fp)) == 0) {
865 lprintf(9, "output_static('%s') -- FREAD FAILED (%s) %zu bytes of %zu --\n", what, strerror(errno), bytes - count, bytes);
866 wprintf("HTTP/1.1 500 internal server error \r\n");
867 wprintf("Content-Type: text/plain\r\n");
876 lprintf(9, "output_static('%s') %s\n", what, content_type);
877 http_transmit_thing(bigbuffer, (size_t)bytes, content_type, 1);
880 if (yesbstr("force_close_session")) {
881 end_webcit_session();
886 * \brief When the browser requests an image file from the Citadel server,
887 * this function is called to transmit it.
892 char *xferbuf = NULL;
894 const char *MimeType;
896 serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
897 serv_getln(buf, sizeof buf);
899 bytes = extract_long(&buf[4], 0);
900 xferbuf = malloc(bytes + 2);
902 /** Read it from the server */
903 read_server_binary(xferbuf, bytes);
905 serv_getln(buf, sizeof buf);
907 MimeType = GuessMimeType (xferbuf, bytes);
908 /** Write it to the browser */
909 if (!IsEmptyStr(MimeType))
911 http_transmit_thing(xferbuf,
918 /* hm... unknown mimetype? fallback to blank gif */
924 * Instead of an ugly 404, send a 1x1 transparent GIF
925 * when there's no such image on the server.
928 snprintf (blank_gif, SIZ, "%s%s", static_dirs[0], "/blank.gif");
929 output_static(blank_gif);
933 * \brief Generic function to output an arbitrary MIME part from an arbitrary
934 * message number on the server.
936 * \param msgnum Number of the item on the citadel server
937 * \param partnum The MIME part to be output
938 * \param force_download Nonzero to force set the Content-Type: header
939 * to "application/octet-stream"
941 void mimepart(char *msgnum, char *partnum, int force_download)
945 char content_type[256];
946 char *content = NULL;
948 serv_printf("OPNA %s|%s", msgnum, partnum);
949 serv_getln(buf, sizeof buf);
951 bytes = extract_long(&buf[4], 0);
952 content = malloc(bytes + 2);
953 if (force_download) {
954 strcpy(content_type, "application/octet-stream");
957 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
959 output_headers(0, 0, 0, 0, 0, 0);
960 read_server_binary(content, bytes);
962 serv_getln(buf, sizeof buf);
963 http_transmit_thing(content, bytes, content_type, 0);
966 wprintf("HTTP/1.1 404 %s\n", &buf[4]);
967 output_headers(0, 0, 0, 0, 0, 0);
968 wprintf("Content-Type: text/plain\r\n");
970 wprintf(_("An error occurred while retrieving this part: %s\n"), &buf[4]);
977 * \brief Read any MIME part of a message, from the server, into memory.
978 * \param msgnum number of the message on the citadel server
979 * \param partnum the MIME part to be loaded
981 char *load_mimepart(long msgnum, char *partnum)
985 char content_type[SIZ];
988 serv_printf("DLAT %ld|%s", msgnum, partnum);
989 serv_getln(buf, sizeof buf);
991 bytes = extract_long(&buf[4], 0);
992 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
994 content = malloc(bytes + 2);
995 serv_read(content, bytes);
997 content[bytes] = 0; /* null terminate for good measure */
1008 * \brief Convenience functions to display a page containing only a string
1009 * \param titlebarcolor color of the titlebar of the frame
1010 * \param titlebarmsg text to display in the title bar
1011 * \param messagetext body of the box
1013 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
1015 wprintf("HTTP/1.1 200 OK\n");
1016 output_headers(1, 1, 2, 0, 0, 0);
1017 wprintf("<div id=\"banner\">\n");
1018 wprintf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
1019 wprintf("<span class=\"titlebar\">%s</span>\n", titlebarmsg);
1020 wprintf("</td></tr></table>\n");
1021 wprintf("</div>\n<div id=\"content\">\n");
1022 escputs(messagetext);
1024 wprintf("<hr />\n");
1030 * \brief Display a blank page.
1032 void blank_page(void) {
1033 output_headers(1, 1, 0, 0, 0, 0);
1039 * \brief A template has been requested
1041 void url_do_template(void) {
1042 do_template(bstr("template"));
1048 * \brief Offer to make any page the user's "start page."
1050 void offer_start_page(void) {
1051 wprintf("<a href=\"change_start_page?startpage=");
1052 urlescputs(WC->this_page);
1054 wprintf(_("Make this my start page"));
1057 wprintf("<br/><a href=\"rss?room=");
1058 urlescputs(WC->wc_roomname);
1059 wprintf("\" title=\"RSS 2.0 feed for ");
1060 escputs(WC->wc_roomname);
1061 wprintf("\"><img alt=\"RSS\" border=\"0\" src=\"static/xml_button.gif\"/></a>\n");
1067 * \brief Change the user's start page
1069 void change_start_page(void) {
1071 if (bstr("startpage") == NULL) {
1072 safestrncpy(WC->ImportantMessage,
1073 _("You no longer have a start page selected."),
1074 sizeof WC->ImportantMessage);
1075 display_main_menu();
1079 set_preference("startpage", bstr("startpage"), 1);
1081 output_headers(1, 1, 0, 0, 0, 0);
1082 do_template("newstartpage");
1089 * \brief convenience function to indicate success
1090 * \param successmessage the mesage itself
1092 void display_success(char *successmessage)
1094 convenience_page("007700", "OK", successmessage);
1099 * \brief Authorization required page
1100 * This is probably temporary and should be revisited
1101 * \param message message to put in header
1103 void authorization_required(const char *message)
1105 wprintf("HTTP/1.1 401 Authorization Required\r\n");
1106 wprintf("WWW-Authenticate: Basic realm=\"\"\r\n", serv_info.serv_humannode);
1107 wprintf("Content-Type: text/html\r\n\r\n");
1109 wprintf(_("Authorization Required"));
1110 wprintf("</h1>\r\n");
1111 wprintf(_("The resource you requested requires a valid username and password. "
1112 "You could not be logged in: %s\n"), message);
1117 * \brief This function is called by the MIME parser to handle data uploaded by
1118 * the browser. Form data, uploaded files, and the data from HTTP PUT
1119 * operations (such as those found in GroupDAV) all arrive this way.
1121 * \param name Name of the item being uploaded
1122 * \param filename Filename of the item being uploaded
1123 * \param partnum MIME part identifier (not needed)
1124 * \param disp MIME content disposition (not needed)
1125 * \param content The actual data
1126 * \param cbtype MIME content-type
1127 * \param cbcharset Character set
1128 * \param length Content length
1129 * \param encoding MIME encoding type (not needed)
1130 * \param userdata Not used here
1132 void upload_handler(char *name, char *filename, char *partnum, char *disp,
1133 void *content, char *cbtype, char *cbcharset,
1134 size_t length, char *encoding, void *userdata)
1138 lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n", name, cbtype, length);
1140 if (WC->urlstrings == NULL)
1141 WC->urlstrings = NewHash(1, NULL);
1144 if ( (length > 0) && (IsEmptyStr(cbtype)) ) {
1145 u = (urlcontent *) malloc(sizeof(urlcontent));
1147 safestrncpy(u->url_key, name, sizeof(u->url_key));
1148 u->url_data = malloc(length + 1);
1149 u->url_data_size = length;
1150 memcpy(u->url_data, content, length);
1151 u->url_data[length] = 0;
1152 Put(WC->urlstrings, u->url_key, strlen(u->url_key), u, free_url);
1154 /* lprintf(9, "Key: <%s> len: [%ld] Data: <%s>\n", u->url_key, u->url_data_size, u->url_data);*/
1157 /** Uploaded files */
1158 if ( (length > 0) && (!IsEmptyStr(cbtype)) ) {
1159 WC->upload = malloc(length);
1160 if (WC->upload != NULL) {
1161 WC->upload_length = length;
1162 safestrncpy(WC->upload_filename, filename,
1163 sizeof(WC->upload_filename));
1164 safestrncpy(WC->upload_content_type, cbtype,
1165 sizeof(WC->upload_content_type));
1166 memcpy(WC->upload, content, length);
1169 lprintf(3, "malloc() failed: %s\n", strerror(errno));
1176 * \brief Convenience functions to wrap around asynchronous ajax responses
1178 void begin_ajax_response(void) {
1179 output_headers(0, 0, 0, 0, 0, 0);
1181 wprintf("Content-type: text/html; charset=UTF-8\r\n"
1183 "Connection: close\r\n"
1184 "Pragma: no-cache\r\n"
1185 "Cache-Control: no-cache\r\n"
1193 * \brief print ajax response footer
1195 void end_ajax_response(void) {
1201 * \brief Wraps a Citadel server command in an AJAX transaction.
1203 void ajax_servcmd(void)
1206 char gcontent[1024];
1210 begin_ajax_response();
1212 serv_printf("%s", bstr("g_cmd"));
1213 serv_getln(buf, sizeof buf);
1214 wprintf("%s\n", buf);
1216 if (buf[0] == '8') {
1217 serv_printf("\n\n000");
1219 if ((buf[0] == '1') || (buf[0] == '8')) {
1220 while (serv_getln(gcontent, sizeof gcontent), strcmp(gcontent, "000")) {
1221 wprintf("%s\n", gcontent);
1225 if (buf[0] == '4') {
1226 text_to_server(bstr("g_input"));
1229 if (buf[0] == '6') {
1230 len = atol(&buf[4]);
1232 serv_read(junk, len);
1235 if (buf[0] == '7') {
1236 len = atol(&buf[4]);
1238 memset(junk, 0, len);
1239 serv_write(junk, len);
1243 end_ajax_response();
1246 * This is kind of an ugly hack, but this is the only place it can go.
1247 * If the command was GEXP, then the instant messenger window must be
1248 * running, so reset the "last_pager_check" watchdog timer so
1249 * that page_popup() doesn't try to open it a second time.
1251 if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) {
1252 WC->last_pager_check = time(NULL);
1258 * \brief Helper function for the asynchronous check to see if we need
1259 * to open the instant messenger window.
1261 void seconds_since_last_gexp(void)
1265 begin_ajax_response();
1266 if ( (time(NULL) - WC->last_pager_check) < 30) {
1271 serv_getln(buf, sizeof buf);
1272 if (buf[3] == '*') {
1279 end_ajax_response();
1286 * \brief Entry point for WebCit transaction
1288 void session_loop(struct httprequest *req)
1296 char request_method[128];
1297 char pathname[1024];
1298 int a, b, nBackDots, nEmpty;
1299 int ContentLength = 0;
1301 char ContentType[512];
1302 char *content = NULL;
1303 char *content_end = NULL;
1304 struct httprequest *hptr;
1305 char browser_host[256];
1306 char user_agent[256];
1312 * We stuff these with the values coming from the client cookies,
1313 * so we can use them to reconnect a timed out session if we have to.
1315 char c_username[SIZ];
1316 char c_password[SIZ];
1317 char c_roomname[SIZ];
1318 char c_httpauth_string[SIZ];
1319 char c_httpauth_user[SIZ];
1320 char c_httpauth_pass[SIZ];
1323 safestrncpy(c_username, "", sizeof c_username);
1324 safestrncpy(c_password, "", sizeof c_password);
1325 safestrncpy(c_roomname, "", sizeof c_roomname);
1326 safestrncpy(c_httpauth_string, "", sizeof c_httpauth_string);
1327 safestrncpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER, sizeof c_httpauth_user);
1328 safestrncpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS, sizeof c_httpauth_pass);
1329 strcpy(browser_host, "");
1331 WC->upload_length = 0;
1337 if (hptr == NULL) return;
1339 safestrncpy(cmd, hptr->line, sizeof cmd);
1341 extract_token(request_method, cmd, 0, ' ', sizeof request_method);
1342 extract_token(pathname, cmd, 1, ' ', sizeof pathname);
1344 /** Figure out the action */
1346 sizes[0] = sizeof action;
1349 index[a] = arg[a-1];
1350 sizes[a] = sizeof arg[a-1];
1352 //// index[9] = &foo; todo
1355 for ( a = 0; a < 9; ++a)
1357 extract_token(index[a], pathname, a + 1, '/', sizes[a]);
1358 if (strstr(index[a], "?")) *strstr(index[a], "?") = 0;
1359 if (strstr(index[a], "&")) *strstr(index[a], "&") = 0;
1360 if (strstr(index[a], " ")) *strstr(index[a], " ") = 0;
1361 if ((index[a][0] == '.') && (index[a][1] == '.'))
1363 if (index[a][0] == '\0')
1367 while (hptr != NULL) {
1368 safestrncpy(buf, hptr->line, sizeof buf);
1369 /* lprintf(9, "HTTP HEADER: %s\n", buf); */
1372 if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
1373 safestrncpy(cookie, &buf[15], sizeof cookie);
1374 cookie_to_stuff(cookie, NULL,
1375 c_username, sizeof c_username,
1376 c_password, sizeof c_password,
1377 c_roomname, sizeof c_roomname);
1379 else if (!strncasecmp(buf, "Authorization: Basic ", 21)) {
1380 CtdlDecodeBase64(c_httpauth_string, &buf[21], strlen(&buf[21]));
1381 extract_token(c_httpauth_user, c_httpauth_string, 0, ':', sizeof c_httpauth_user);
1382 extract_token(c_httpauth_pass, c_httpauth_string, 1, ':', sizeof c_httpauth_pass);
1384 else if (!strncasecmp(buf, "Content-length: ", 16)) {
1385 ContentLength = atoi(&buf[16]);
1387 else if (!strncasecmp(buf, "Content-type: ", 14)) {
1388 safestrncpy(ContentType, &buf[14], sizeof ContentType);
1390 else if (!strncasecmp(buf, "User-agent: ", 12)) {
1391 safestrncpy(user_agent, &buf[12], sizeof user_agent);
1393 else if (!strncasecmp(buf, "X-Forwarded-Host: ", 18)) {
1395 safestrncpy(WC->http_host, &buf[18], sizeof WC->http_host);
1398 else if (!strncasecmp(buf, "Host: ", 6)) {
1399 if (IsEmptyStr(WC->http_host)) {
1400 safestrncpy(WC->http_host, &buf[6], sizeof WC->http_host);
1403 else if (!strncasecmp(buf, "X-Forwarded-For: ", 17)) {
1404 safestrncpy(browser_host, &buf[17], sizeof browser_host);
1405 while (num_tokens(browser_host, ',') > 1) {
1406 remove_token(browser_host, 0, ',');
1408 striplt(browser_host);
1410 /** Only WAP gateways explicitly name this content-type */
1411 else if (strstr(buf, "text/vnd.wap.wml")) {
1416 if (ContentLength > 0) {
1417 content = malloc(ContentLength + SIZ);
1418 memset(content, 0, ContentLength + SIZ);
1419 snprintf(content, ContentLength + SIZ, "Content-type: %s\n"
1420 "Content-length: %d\n\n",
1421 ContentType, ContentLength);
1422 body_start = strlen(content);
1424 /** Read the entire input data at once. */
1425 client_read(WC->http_sock, &content[BytesRead+body_start], ContentLength);
1427 if (!strncasecmp(ContentType, "application/x-www-form-urlencoded", 33)) {
1428 addurls(&content[body_start]);
1429 } else if (!strncasecmp(ContentType, "multipart", 9)) {
1430 content_end = content + ContentLength + body_start;
1431 mime_parser(content, content_end, *upload_handler, NULL, NULL, NULL, 0);
1437 /** make a note of where we are in case the user wants to save it */
1438 safestrncpy(WC->this_page, cmd, sizeof(WC->this_page));
1439 remove_token(WC->this_page, 2, ' ');
1440 remove_token(WC->this_page, 0, ' ');
1442 /** If there are variables in the URL, we must grab them now */
1444 for (a = 0; a < len; ++a) {
1445 if ((cmd[a] == '?') || (cmd[a] == '&')) {
1446 for (b = a; b < len; ++b) {
1447 if (isspace(cmd[b])){
1452 addurls(&cmd[a + 1]);
1458 /** If it's a "force 404" situation then display the error and bail. */
1459 if (!strcmp(action, "404")) {
1460 wprintf("HTTP/1.1 404 Not found\r\n");
1461 wprintf("Content-Type: text/plain\r\n");
1463 wprintf("Not found\r\n");
1464 goto SKIP_ALL_THIS_CRAP;
1467 /** Static content can be sent without connecting to Citadel. */
1469 for (a=0; a<ndirs; ++a) {
1470 if (!strcasecmp(action, (char*)static_content_dirs[a])) { /* map web to disk location */
1478 snprintf(buf, sizeof buf, "%s/%s/%s/%s/%s/%s/%s/%s",
1479 static_dirs[n_static],
1480 index[1], index[2], index[3], index[4], index[5], index[6], index[7]);
1481 for (a=0; a<8; ++a) {
1482 if (buf[strlen(buf)-1] == '/') {
1483 buf[strlen(buf)-1] = 0;
1486 for (a = 0; a < strlen(buf); ++a) {
1487 if (isspace(buf[a])) {
1495 lprintf(9, "Suspicious request. Ignoring.");
1496 wprintf("HTTP/1.1 404 Security check failed\r\n");
1497 wprintf("Content-Type: text/plain\r\n");
1499 wprintf("You have sent a malformed or invalid request.\r\n");
1501 goto SKIP_ALL_THIS_CRAP; /* Don't try to connect */
1504 /* If the client sent a nonce that is incorrect, kill the request. */
1505 if (strlen(bstr("nonce")) > 0) {
1506 lprintf(9, "Comparing supplied nonce %s to session nonce %ld\n",
1507 bstr("nonce"), WC->nonce);
1508 if (ibstr("nonce") != WC->nonce) {
1509 lprintf(9, "Ignoring request with mismatched nonce.\n");
1510 wprintf("HTTP/1.1 404 Security check failed\r\n");
1511 wprintf("Content-Type: text/plain\r\n");
1513 wprintf("Security check failed.\r\n");
1514 goto SKIP_ALL_THIS_CRAP;
1519 * If we're not connected to a Citadel server, try to hook up the
1522 if (!WC->connected) {
1523 if (!strcasecmp(ctdlhost, "uds")) {
1524 /* unix domain socket */
1525 snprintf(buf, SIZ, "%s/citadel.socket", ctdlport);
1526 WC->serv_sock = uds_connectsock(buf);
1530 WC->serv_sock = tcp_connectsock(ctdlhost, ctdlport);
1533 if (WC->serv_sock < 0) {
1535 goto SKIP_ALL_THIS_CRAP;
1539 serv_getln(buf, sizeof buf); /** get the server welcome message */
1542 * From what host is our user connecting? Go with
1543 * the host at the other end of the HTTP socket,
1544 * unless we are following X-Forwarded-For: headers
1545 * and such a header has already turned up something.
1547 if ( (!follow_xff) || (strlen(browser_host) == 0) ) {
1548 locate_host(browser_host, WC->http_sock);
1551 get_serv_info(browser_host, user_agent);
1552 if (serv_info.serv_rev_level < MINIMUM_CIT_VERSION) {
1553 wprintf(_("You are connected to a Citadel "
1554 "server running Citadel %d.%02d. \n"
1555 "In order to run this version of WebCit "
1556 "you must also have Citadel %d.%02d or"
1558 serv_info.serv_rev_level / 100,
1559 serv_info.serv_rev_level % 100,
1560 MINIMUM_CIT_VERSION / 100,
1561 MINIMUM_CIT_VERSION % 100
1563 end_webcit_session();
1564 goto SKIP_ALL_THIS_CRAP;
1570 * Functions which can be performed without logging in
1572 if (!strcasecmp(action, "listsub")) {
1574 goto SKIP_ALL_THIS_CRAP;
1576 if (!strcasecmp(action, "freebusy")) {
1578 goto SKIP_ALL_THIS_CRAP;
1582 * If we're not logged in, but we have HTTP Authentication data,
1583 * try logging in to Citadel using that.
1585 if ((!WC->logged_in)
1586 && (strlen(c_httpauth_user) > 0)
1587 && (strlen(c_httpauth_pass) > 0)) {
1588 serv_printf("USER %s", c_httpauth_user);
1589 serv_getln(buf, sizeof buf);
1590 if (buf[0] == '3') {
1591 serv_printf("PASS %s", c_httpauth_pass);
1592 serv_getln(buf, sizeof buf);
1593 if (buf[0] == '2') {
1594 become_logged_in(c_httpauth_user,
1595 c_httpauth_pass, buf);
1596 safestrncpy(WC->httpauth_user, c_httpauth_user, sizeof WC->httpauth_user);
1597 safestrncpy(WC->httpauth_pass, c_httpauth_pass, sizeof WC->httpauth_pass);
1599 /** Should only display when password is wrong */
1600 authorization_required(&buf[4]);
1601 goto SKIP_ALL_THIS_CRAP;
1606 /** This needs to run early */
1608 if (!strcasecmp(action, "rss")) {
1609 display_rss(bstr("room"), request_method);
1610 goto SKIP_ALL_THIS_CRAP;
1615 * The GroupDAV stuff relies on HTTP authentication instead of
1616 * our session's authentication.
1618 if (!strncasecmp(action, "groupdav", 8)) {
1619 groupdav_main(req, ContentType, /* do GroupDAV methods */
1620 ContentLength, content+body_start);
1621 if (!WC->logged_in) {
1622 WC->killthis = 1; /* If not logged in, don't */
1623 } /* keep the session active */
1624 goto SKIP_ALL_THIS_CRAP;
1629 * Automatically send requests with any method other than GET or
1630 * POST to the GroupDAV code as well.
1632 if ((strcasecmp(request_method, "GET")) && (strcasecmp(request_method, "POST"))) {
1633 groupdav_main(req, ContentType, /** do GroupDAV methods */
1634 ContentLength, content+body_start);
1635 if (!WC->logged_in) {
1636 WC->killthis = 1; /** If not logged in, don't */
1637 } /** keep the session active */
1638 goto SKIP_ALL_THIS_CRAP;
1642 * If we're not logged in, but we have username and password cookies
1643 * supplied by the browser, try using them to log in.
1645 if ((!WC->logged_in)
1646 && (!IsEmptyStr(c_username))
1647 && (!IsEmptyStr(c_password))) {
1648 serv_printf("USER %s", c_username);
1649 serv_getln(buf, sizeof buf);
1650 if (buf[0] == '3') {
1651 serv_printf("PASS %s", c_password);
1652 serv_getln(buf, sizeof buf);
1653 if (buf[0] == '2') {
1654 become_logged_in(c_username, c_password, buf);
1659 * If we don't have a current room, but a cookie specifying the
1660 * current room is supplied, make an effort to go there.
1662 if ((IsEmptyStr(WC->wc_roomname)) && (!IsEmptyStr(c_roomname))) {
1663 serv_printf("GOTO %s", c_roomname);
1664 serv_getln(buf, sizeof buf);
1665 if (buf[0] == '2') {
1666 safestrncpy(WC->wc_roomname, c_roomname, sizeof WC->wc_roomname);
1670 if (!strcasecmp(action, "image")) {
1672 } else if (!strcasecmp(action, "display_mime_icon")) {
1673 display_mime_icon();
1676 * All functions handled below this point ... make sure we log in
1677 * before doing anything else!
1679 } else if ((!WC->logged_in) && (!strcasecmp(action, "login"))) {
1681 } else if (!WC->logged_in) {
1682 display_login(NULL);
1686 * Various commands...
1691 WebcitHandler *Handler;
1693 GetHash(HandlerHash, action, strlen(action) /* TODO*/, &vHandler),
1694 Handler = (WebcitHandler*) vHandler;
1695 if (Handler != NULL) {
1696 if (Handler->IsAjax)
1697 begin_ajax_response();
1699 if (Handler->IsAjax)
1700 end_ajax_response();
1704 else if (!strcasecmp(action, "do_welcome")) {
1706 } else if (!strcasecmp(action, "blank")) {
1708 } else if (!strcasecmp(action, "do_template")) {
1710 } else if (!strcasecmp(action, "display_aide_menu")) {
1711 display_aide_menu();
1712 } else if (!strcasecmp(action, "server_shutdown")) {
1714 } else if (!strcasecmp(action, "display_main_menu")) {
1715 display_main_menu();
1716 } else if (!strcasecmp(action, "who")) {
1718 } else if (!strcasecmp(action, "sslg")) {
1719 seconds_since_last_gexp();
1720 } else if (!strcasecmp(action, "who_inner_html")) {
1721 begin_ajax_response();
1723 end_ajax_response();
1724 } else if (!strcasecmp(action, "wholist_section")) {
1725 begin_ajax_response();
1727 end_ajax_response();
1728 } else if (!strcasecmp(action, "new_messages_html")) {
1729 begin_ajax_response();
1730 new_messages_section();
1731 end_ajax_response();
1732 } else if (!strcasecmp(action, "tasks_inner_html")) {
1733 begin_ajax_response();
1735 end_ajax_response();
1736 } else if (!strcasecmp(action, "calendar_inner_html")) {
1737 begin_ajax_response();
1739 end_ajax_response();
1740 } else if (!strcasecmp(action, "mini_calendar")) {
1741 begin_ajax_response();
1742 ajax_mini_calendar();
1743 end_ajax_response();
1744 } else if (!strcasecmp(action, "iconbar_ajax_menu")) {
1745 begin_ajax_response();
1747 end_ajax_response();
1748 } else if (!strcasecmp(action, "iconbar_ajax_rooms")) {
1749 begin_ajax_response();
1750 do_iconbar_roomlist();
1751 end_ajax_response();
1752 } else if (!strcasecmp(action, "knrooms")) {
1754 } else if (!strcasecmp(action, "gotonext")) {
1757 } else if (!strcasecmp(action, "skip")) {
1759 } else if (!strcasecmp(action, "ungoto")) {
1761 } else if (!strcasecmp(action, "dotgoto")) {
1762 if (WC->wc_view != VIEW_MAILBOX) { /* dotgoto acts like dotskip when we're in a mailbox view */
1765 smart_goto(bstr("room"));
1766 } else if (!strcasecmp(action, "dotskip")) {
1767 smart_goto(bstr("room"));
1768 } else if (!strcasecmp(action, "termquit")) {
1770 } else if (!strcasecmp(action, "readnew")) {
1771 readloop("readnew");
1772 } else if (!strcasecmp(action, "readold")) {
1773 readloop("readold");
1774 } else if (!strcasecmp(action, "readfwd")) {
1775 readloop("readfwd");
1776 } else if (!strcasecmp(action, "headers")) {
1777 readloop("headers");
1778 } else if (!strcasecmp(action, "do_search")) {
1779 readloop("do_search");
1780 } else if (!strcasecmp(action, "msg")) {
1781 embed_message(index[1]);
1782 } else if (!strcasecmp(action, "printmsg")) {
1783 print_message(index[1]);
1784 } else if (!strcasecmp(action, "msgheaders")) {
1785 display_headers(index[1]);
1786 } else if (!strcasecmp(action, "wiki")) {
1787 display_wiki_page();
1788 } else if (!strcasecmp(action, "display_enter")) {
1790 } else if (!strcasecmp(action, "post")) {
1792 } else if (!strcasecmp(action, "move_msg")) {
1794 } else if (!strcasecmp(action, "delete_msg")) {
1796 } else if (!strcasecmp(action, "userlist")) {
1798 } else if (!strcasecmp(action, "showuser")) {
1800 } else if (!strcasecmp(action, "display_page")) {
1802 } else if (!strcasecmp(action, "page_user")) {
1804 } else if (!strcasecmp(action, "chat")) {
1806 } else if (!strcasecmp(action, "display_private")) {
1807 display_private("", 0);
1808 } else if (!strcasecmp(action, "goto_private")) {
1810 } else if (!strcasecmp(action, "zapped_list")) {
1812 } else if (!strcasecmp(action, "display_zap")) {
1814 } else if (!strcasecmp(action, "zap")) {
1816 } else if (!strcasecmp(action, "display_entroom")) {
1818 } else if (!strcasecmp(action, "entroom")) {
1820 } else if (!strcasecmp(action, "display_whok")) {
1822 } else if (!strcasecmp(action, "do_invt_kick")) {
1824 } else if (!strcasecmp(action, "display_editroom")) {
1826 } else if (!strcasecmp(action, "netedit")) {
1828 } else if (!strcasecmp(action, "editroom")) {
1830 } else if (!strcasecmp(action, "display_editinfo")) {
1831 display_edit(_("Room info"), "EINF 0", "RINF", "editinfo", 1);
1832 } else if (!strcasecmp(action, "editinfo")) {
1833 save_edit(_("Room info"), "EINF 1", 1);
1834 } else if (!strcasecmp(action, "display_editbio")) {
1835 snprintf(buf, SIZ, "RBIO %s", WC->wc_fullname);
1836 display_edit(_("Your bio"), "NOOP", buf, "editbio", 3);
1837 } else if (!strcasecmp(action, "editbio")) {
1838 save_edit(_("Your bio"), "EBIO", 0);
1839 } else if (!strcasecmp(action, "confirm_move_msg")) {
1841 } else if (!strcasecmp(action, "delete_room")) {
1843 } else if (!strcasecmp(action, "validate")) {
1845 /* The users photo display / upload facility */
1846 } else if (!strcasecmp(action, "display_editpic")) {
1847 display_graphics_upload(_("your photo"),
1850 } else if (!strcasecmp(action, "editpic")) {
1851 do_graphics_upload("_userpic_");
1852 /* room picture dispay / upload facility */
1853 } else if (!strcasecmp(action, "display_editroompic")) {
1854 display_graphics_upload(_("the icon for this room"),
1857 } else if (!strcasecmp(action, "editroompic")) {
1858 do_graphics_upload("_roompic_");
1859 /* the greetingpage hello pic */
1860 } else if (!strcasecmp(action, "display_edithello")) {
1861 display_graphics_upload(_("the Greetingpicture for the login prompt"),
1864 } else if (!strcasecmp(action, "edithellopic")) {
1865 do_graphics_upload("hello");
1866 /* the logoff banner */
1867 } else if (!strcasecmp(action, "display_editgoodbyepic")) {
1868 display_graphics_upload(_("the Logoff banner picture"),
1869 "UIMG 0|%s|goodbuye",
1871 } else if (!strcasecmp(action, "editgoodbuyepic")) {
1872 do_graphics_upload("UIMG 1|%s|goodbuye");
1874 } else if (!strcasecmp(action, "delete_floor")) {
1876 } else if (!strcasecmp(action, "rename_floor")) {
1878 } else if (!strcasecmp(action, "create_floor")) {
1880 } else if (!strcasecmp(action, "display_editfloorpic")) {
1881 snprintf(buf, SIZ, "UIMG 0|_floorpic_|%s",
1882 bstr("which_floor"));
1883 display_graphics_upload(_("the icon for this floor"),
1886 } else if (!strcasecmp(action, "editfloorpic")) {
1887 snprintf(buf, SIZ, "UIMG 1|_floorpic_|%s",
1888 bstr("which_floor"));
1889 do_graphics_upload(buf);
1890 } else if (!strcasecmp(action, "display_reg")) {
1892 } else if (!strcasecmp(action, "display_changepw")) {
1894 } else if (!strcasecmp(action, "changepw")) {
1896 } else if (!strcasecmp(action, "display_edit_node")) {
1897 display_edit_node();
1898 } else if (!strcasecmp(action, "edit_node")) {
1900 } else if (!strcasecmp(action, "display_netconf")) {
1902 } else if (!strcasecmp(action, "display_confirm_delete_node")) {
1903 display_confirm_delete_node();
1904 } else if (!strcasecmp(action, "delete_node")) {
1906 } else if (!strcasecmp(action, "display_add_node")) {
1908 } else if (!strcasecmp(action, "terminate_session")) {
1910 terminate_session();
1911 } else if (!strcasecmp(action, "edit_me")) {
1913 } else if (!strcasecmp(action, "display_siteconfig")) {
1914 display_siteconfig();
1915 } else if (!strcasecmp(action, "chat_recv")) {
1917 } else if (!strcasecmp(action, "chat_send")) {
1919 } else if (!strcasecmp(action, "siteconfig")) {
1921 } else if (!strcasecmp(action, "display_generic")) {
1923 } else if (!strcasecmp(action, "do_generic")) {
1925 } else if (!strcasecmp(action, "ajax_servcmd")) {
1927 } else if (!strcasecmp(action, "display_menubar")) {
1929 } else if (!strcasecmp(action, "mimepart")) {
1930 mimepart(index[1], index[2], 0);
1931 } else if (!strcasecmp(action, "mimepart_download")) {
1932 mimepart(index[1], index[2], 1);
1933 } else if (!strcasecmp(action, "edit_vcard")) {
1935 } else if (!strcasecmp(action, "submit_vcard")) {
1937 } else if (!strcasecmp(action, "select_user_to_edit")) {
1938 select_user_to_edit(NULL, NULL);
1939 } else if (!strcasecmp(action, "display_edituser")) {
1940 display_edituser(NULL, 0);
1941 } else if (!strcasecmp(action, "edituser")) {
1943 } else if (!strcasecmp(action, "create_user")) {
1945 } else if (!strcasecmp(action, "changeview")) {
1947 } else if (!strcasecmp(action, "change_start_page")) {
1948 change_start_page();
1949 } else if (!strcasecmp(action, "display_floorconfig")) {
1950 display_floorconfig(NULL);
1951 } else if (!strcasecmp(action, "toggle_self_service")) {
1952 toggle_self_service();
1953 } else if (!strcasecmp(action, "display_edit_task")) {
1954 display_edit_task();
1955 } else if (!strcasecmp(action, "save_task")) {
1957 } else if (!strcasecmp(action, "display_edit_event")) {
1958 display_edit_event();
1959 } else if (!strcasecmp(action, "save_event")) {
1961 } else if (!strcasecmp(action, "respond_to_request")) {
1962 respond_to_request();
1963 } else if (!strcasecmp(action, "handle_rsvp")) {
1965 } else if (!strcasecmp(action, "summary")) {
1967 } else if (!strcasecmp(action, "summary_inner_div")) {
1968 begin_ajax_response();
1969 summary_inner_div();
1970 end_ajax_response();
1971 } else if (!strcasecmp(action, "display_customize_iconbar")) {
1972 display_customize_iconbar();
1973 } else if (!strcasecmp(action, "commit_iconbar")) {
1975 } else if (!strcasecmp(action, "set_room_policy")) {
1977 } else if (!strcasecmp(action, "display_inetconf")) {
1979 } else if (!strcasecmp(action, "save_inetconf")) {
1981 } else if (!strcasecmp(action, "display_smtpqueue")) {
1982 display_smtpqueue();
1983 } else if (!strcasecmp(action, "display_smtpqueue_inner_div")) {
1984 display_smtpqueue_inner_div();
1985 } else if (!strcasecmp(action, "display_sieve")) {
1987 } else if (!strcasecmp(action, "save_sieve")) {
1989 } else if (!strcasecmp(action, "display_pushemail")) {
1990 display_pushemail();
1991 } else if (!strcasecmp(action, "save_pushemail")) {
1993 } else if (!strcasecmp(action, "display_add_remove_scripts")) {
1994 display_add_remove_scripts(NULL);
1995 } else if (!strcasecmp(action, "create_script")) {
1997 } else if (!strcasecmp(action, "delete_script")) {
1999 } else if (!strcasecmp(action, "setup_wizard")) {
2001 } else if (!strcasecmp(action, "display_preferences")) {
2002 display_preferences();
2003 } else if (!strcasecmp(action, "set_preferences")) {
2005 } else if (!strcasecmp(action, "recp_autocomplete")) {
2006 recp_autocomplete(bstr("recp"));
2007 } else if (!strcasecmp(action, "cc_autocomplete")) {
2008 recp_autocomplete(bstr("cc"));
2009 } else if (!strcasecmp(action, "bcc_autocomplete")) {
2010 recp_autocomplete(bstr("bcc"));
2011 } else if (!strcasecmp(action, "display_address_book_middle_div")) {
2012 display_address_book_middle_div();
2013 } else if (!strcasecmp(action, "display_address_book_inner_div")) {
2014 display_address_book_inner_div();
2015 } else if (!strcasecmp(action, "set_floordiv_expanded")) {
2016 set_floordiv_expanded(index[1]);
2017 } else if (!strcasecmp(action, "diagnostics")) {
2018 output_headers(1, 1, 1, 0, 0, 0);
2019 wprintf("Session: %d<hr />\n", WC->wc_session);
2020 wprintf("Command: <br /><PRE>\n");
2022 wprintf("</PRE><hr />\n");
2023 wprintf("Variables: <br /><PRE>\n");
2025 wprintf("</PRE><hr />\n");
2027 } else if (!strcasecmp(action, "updatenote")) {
2029 } else if (!strcasecmp(action, "ajax_update_note")) {
2031 } else if (!strcasecmp(action, "display_room_directory")) {
2032 display_room_directory();
2033 } else if (!strcasecmp(action, "display_pictureview")) {
2034 display_pictureview();
2035 } else if (!strcasecmp(action, "download_file")) {
2036 download_file(index[1]);
2037 } else if (!strcasecmp(action, "upload_file")) {
2041 /** When all else fais, display the main menu. */
2043 display_main_menu();
2048 if (content != NULL) {
2053 if (WC->upload_length > 0) {
2055 WC->upload_length = 0;
2060 * \brief Replacement for sleep() that uses select() in order to avoid SIGALRM
2061 * \param seconds how many seconds should we sleep?
2063 void sleeeeeeeeeep(int seconds)
2067 tv.tv_sec = seconds;
2069 select(0, NULL, NULL, NULL, &tv);