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';
145 #ifdef DEBUG_URLSTRINGS
146 lprintf(9, "%s = [%ld] %s\n", u->url_key, u->url_data_size, u->url_data);
152 * free urlstring memory
156 DeleteHash(&WC->urlstrings);
160 * Diagnostic function to display the contents of all variables
165 struct wcsession *WCC = WC;
172 Cursor = GetNewHashPos ();
173 while (GetNextHashPos(WCC->urlstrings, Cursor, &HKLen, &HKey, &U)) {
175 wprintf("%38s = %s\n", u->url_key, u->url_data);
180 * Return the value of a variable supplied to the current web page (from the url or a form)
183 const char *XBstr(char *key, size_t keylen, size_t *len)
187 if ((WC->urlstrings != NULL) &&
188 GetHash(WC->urlstrings, key, keylen, &U)) {
189 *len = ((urlcontent *)U)->url_data_size;
190 return ((urlcontent *)U)->url_data;
198 const char *XBSTR(char *key, size_t *len)
202 if ((WC->urlstrings != NULL) &&
203 GetHash(WC->urlstrings, key, strlen (key), &U)){
204 *len = ((urlcontent *)U)->url_data_size;
205 return ((urlcontent *)U)->url_data;
214 const char *BSTR(char *key)
218 if ((WC->urlstrings != NULL) &&
219 GetHash(WC->urlstrings, key, strlen (key), &U))
220 return ((urlcontent *)U)->url_data;
225 const char *Bstr(char *key, size_t keylen)
229 if ((WC->urlstrings != NULL) &&
230 GetHash(WC->urlstrings, key, keylen, &U))
231 return ((urlcontent *)U)->url_data;
236 long LBstr(char *key, size_t keylen)
240 if ((WC->urlstrings != NULL) &&
241 GetHash(WC->urlstrings, key, keylen, &U))
242 return atol(((urlcontent *)U)->url_data);
247 long LBSTR(char *key)
251 if ((WC->urlstrings != NULL) &&
252 GetHash(WC->urlstrings, key, strlen(key), &U))
253 return atol(((urlcontent *)U)->url_data);
258 int IBstr(char *key, size_t keylen)
262 if ((WC->urlstrings != NULL) &&
263 GetHash(WC->urlstrings, key, keylen, &U))
264 return atoi(((urlcontent *)U)->url_data);
273 if ((WC->urlstrings != NULL) &&
274 GetHash(WC->urlstrings, key, strlen(key), &U))
275 return atoi(((urlcontent *)U)->url_data);
280 int HaveBstr(char *key, size_t keylen)
284 if ((WC->urlstrings != NULL) &&
285 GetHash(WC->urlstrings, key, keylen, &U))
286 return ((urlcontent *)U)->url_data_size != 0;
291 int HAVEBSTR(char *key)
295 if ((WC->urlstrings != NULL) &&
296 GetHash(WC->urlstrings, key, strlen(key), &U))
297 return ((urlcontent *)U)->url_data_size != 0;
303 int YesBstr(char *key, size_t keylen)
307 if ((WC->urlstrings != NULL) &&
308 GetHash(WC->urlstrings, key, keylen, &U))
309 return strcmp( ((urlcontent *)U)->url_data, "yes") == 0;
314 int YESBSTR(char *key)
318 if ((WC->urlstrings != NULL) &&
319 GetHash(WC->urlstrings, key, strlen(key), &U))
320 return strcmp( ((urlcontent *)U)->url_data, "yes") == 0;
326 * web-printing funcion. uses our vsnprintf wrapper
328 void wprintf(const char *format,...)
333 va_start(arg_ptr, format);
334 vsnprintf(wbuf, sizeof wbuf, format, arg_ptr);
337 client_write(wbuf, strlen(wbuf));
342 * wrap up an HTTP session, closes tags, etc.
344 * print_standard_html_footer should be set to:
345 * 0 to transmit only,
346 * 1 to append the main menu and closing tags,
347 * 2 to append the closing tags only.
349 void wDumpContent(int print_standard_html_footer)
351 if (print_standard_html_footer) {
352 wprintf("</div>\n"); /* end of "text" div */
353 do_template("trailing");
356 /* If we've been saving it all up for one big output burst,
357 * go ahead and do that now.
364 * Copy a string, escaping characters which have meaning in HTML.
366 * target target buffer
367 * strbuf source buffer
368 * nbsp If nonzero, spaces are converted to non-breaking spaces.
369 * nolinebreaks if set, linebreaks are removed from the string.
371 long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks)
373 char *aptr, *bptr, *eptr;
378 eptr = target + tSize - 6; // our biggest unit to put in...
380 while ((bptr < eptr) && !IsEmptyStr(aptr) ){
382 memcpy(bptr, "<", 4);
385 else if (*aptr == '>') {
386 memcpy(bptr, ">", 4);
389 else if (*aptr == '&') {
390 memcpy(bptr, "&", 5);
393 else if (*aptr == '\"') {
394 memcpy(bptr, """, 6);
397 else if (*aptr == '\'') {
398 memcpy(bptr, "'", 5);
401 else if (*aptr == LB) {
405 else if (*aptr == RB) {
409 else if (*aptr == QU) {
413 else if ((*aptr == 32) && (nbsp == 1)) {
414 memcpy(bptr, " ", 6);
417 else if ((*aptr == '\n') && (nolinebreaks)) {
418 *bptr='\0'; /* nothing */
420 else if ((*aptr == '\r') && (nolinebreaks)) {
421 *bptr='\0'; /* nothing */
430 if ((bptr = eptr - 1 ) && !IsEmptyStr(aptr) )
432 return (bptr - target);
435 void escputs1(char *strbuf, int nbsp, int nolinebreaks)
440 if (strbuf == NULL) return;
441 Siz = (3 * strlen(strbuf)) + SIZ ;
443 stresc(buf, Siz, strbuf, nbsp, nolinebreaks);
449 * static wrapper for ecsputs1
451 void escputs(char *strbuf)
453 escputs1(strbuf, 0, 0);
458 * urlescape buffer and print it to the client
460 void urlescputs(char *strbuf)
464 urlesc(outbuf, SIZ, strbuf);
465 wprintf("%s", outbuf);
470 * Copy a string, escaping characters for JavaScript strings.
472 void jsesc(char *target, size_t tlen, char *strbuf)
481 len = strlen (strbuf);
483 tend = target + tlen;
487 while (!IsEmptyStr(sptr) &&
493 else if (*sptr == '>')
495 else if (*sptr == '\'') {
501 else if (*sptr == '"') {
511 else if (*sptr == '&') {
528 * escape and print javascript
530 void jsescputs(char *strbuf)
534 jsesc(outbuf, SIZ, strbuf);
535 wprintf("%s", outbuf);
539 * Copy a string, escaping characters for message text hold
541 void msgesc(char *target, size_t tlen, char *strbuf)
550 len = strlen (strbuf);
552 tend = target + tlen;
556 while (!IsEmptyStr(sptr) &&
562 else if (*sptr == '\r')
564 else if (*sptr == '\'') {
581 * \brief print a string to the client after cleaning it with msgesc() and stresc()
582 * \param strbuf string to be printed
584 void msgescputs1( char *strbuf)
590 if (strbuf == NULL) return;
591 buflen = 3 * strlen(strbuf) + SIZ;
592 outbuf = malloc( buflen);
593 outbuf2 = malloc( buflen);
594 msgesc(outbuf, buflen, strbuf);
595 stresc(outbuf2, buflen, outbuf, 0, 0);
596 wprintf("%s", outbuf2);
602 * \brief print a string to the client after cleaning it with msgesc()
603 * \param strbuf string to be printed
605 void msgescputs(char *strbuf) {
609 if (strbuf == NULL) return;
610 len = (3 * strlen(strbuf)) + SIZ;
611 outbuf = malloc(len);
612 msgesc(outbuf, len, strbuf);
613 wprintf("%s", outbuf);
621 * Output HTTP headers and leading HTML for a page
623 void output_headers( int do_httpheaders, /* 1 = output HTTP headers */
624 int do_htmlhead, /* 1 = output HTML <head> section and <body> opener */
626 int do_room_banner, /* 0=no, 1=yes,
627 * 2 = I'm going to embed my own, so don't open the
628 * <div id="content"> either.
631 int unset_cookies, /* 1 = session is terminating, so unset the cookies */
632 int suppress_check, /* 1 = suppress check for instant messages */
633 int cache /* 1 = allow browser to cache this page */
638 wprintf("HTTP/1.1 200 OK\n");
639 http_datestring(httpnow, sizeof httpnow, time(NULL));
641 if (do_httpheaders) {
642 wprintf("Content-type: text/html; charset=utf-8\r\n"
644 "Connection: close\r\n",
645 PACKAGE_STRING, serv_info.serv_software
650 wprintf("Pragma: public\r\n"
651 "Cache-Control: max-age=3600, must-revalidate\r\n"
652 "Last-modified: %s\r\n",
657 wprintf("Pragma: no-cache\r\n"
658 "Cache-Control: no-store\r\n"
663 stuff_to_cookie(cookie, 1024, WC->wc_session, WC->wc_username,
664 WC->wc_password, WC->wc_roomname);
667 wprintf("Set-cookie: webcit=%s; path=/\r\n", unset);
669 wprintf("Set-cookie: webcit=%s; path=/\r\n", cookie);
670 if (server_cookie != NULL) {
671 wprintf("%s\n", server_cookie);
677 if (!access("static.local/webcit.css", R_OK)) {
678 svprintf(HKEY("CSSLOCAL"), WCS_STRING,
679 "<link href=\"static.local/webcit.css\" rel=\"stylesheet\" type=\"text/css\">"
689 /* check for ImportantMessages (these display in a div overlaying the main screen) */
690 if (!IsEmptyStr(WC->ImportantMessage)) {
691 wprintf("<div id=\"important_message\">\n"
692 "<span class=\"imsg\">");
693 escputs(WC->ImportantMessage);
694 wprintf("</span><br />\n"
696 "<script type=\"text/javascript\">\n"
697 " setTimeout('hide_imsg_popup()', 5000); \n"
699 WC->ImportantMessage[0] = 0;
702 if ( (WC->logged_in) && (!unset_cookies) ) {
703 wprintf("<div id=\"iconbar\">");
704 do_selected_iconbar();
705 /** check for instant messages (these display in a new window) */
710 if (do_room_banner == 1) {
711 wprintf("<div id=\"banner\">\n");
712 embed_room_banner(NULL, navbar_default);
717 if (do_room_banner == 1) {
718 wprintf("<div id=\"content\">\n");
724 * Generic function to do an HTTP redirect. Easy and fun.
726 void http_redirect(char *whichpage) {
727 wprintf("HTTP/1.1 302 Moved Temporarily\n");
728 wprintf("Location: %s\r\n", whichpage);
729 wprintf("URI: %s\r\n", whichpage);
730 wprintf("Content-type: text/html; charset=utf-8\r\n\r\n");
731 wprintf("<html><body>");
732 wprintf("Go <a href=\"%s\">here</A>.", whichpage);
733 wprintf("</body></html>\n");
739 * Output a piece of content to the web browser using conformant HTTP and MIME semantics
741 void http_transmit_thing(char *thing, size_t length, const char *content_type,
744 output_headers(0, 0, 0, 0, 0, is_static);
746 wprintf("Content-type: %s\r\n"
748 "Connection: close\r\n",
753 /* If we can send the data out compressed, please do so. */
755 char *compressed_data = NULL;
756 size_t compressed_len;
758 compressed_len = ((length * 101) / 100) + 100;
759 compressed_data = malloc(compressed_len);
761 if (compress_gzip((Bytef *) compressed_data,
764 (uLongf) length, Z_BEST_SPEED) == Z_OK) {
765 wprintf("Content-encoding: gzip\r\n"
766 "Content-length: %ld\r\n"
768 (long) compressed_len
770 client_write(compressed_data, (size_t)compressed_len);
771 free(compressed_data);
777 /* No compression ... just send it out as-is */
778 wprintf("Content-length: %ld\r\n"
782 client_write(thing, (size_t)length);
786 * \brief print menu box like used in the floor view or admin interface.
787 * This function takes pair of strings as va_args,
788 * \param Title Title string of the box
789 * \param Class CSS Class for the box
790 * \param nLines How many string pairs should we print? (URL, UrlText)
791 * \param ... Pairs of URL Strings and their Names
793 void print_menu_box(char* Title, char *Class, int nLines, ...)
798 svput("BOXTITLE", WCS_STRING, Title);
799 do_template("beginbox");
801 wprintf("<ul class=\"%s\">", Class);
803 va_start(arg_list, nLines);
804 for (i = 0; i < nLines; ++i)
806 wprintf("<li><a href=\"%s\">", va_arg(arg_list, char *));
807 wprintf((char *) va_arg(arg_list, char *));
808 wprintf("</a></li>\n");
812 wprintf("</a></li>\n");
816 do_template("endbox");
821 * \brief dump out static pages from disk
822 * \param what the file urs to print
824 void output_static(char *what)
832 const char *content_type;
835 fp = fopen(what, "rb");
837 lprintf(9, "output_static('%s') -- NOT FOUND --\n", what);
838 wprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
839 wprintf("Content-Type: text/plain\r\n");
841 wprintf("Cannot open %s: %s\r\n", what, strerror(errno));
844 content_type = GuessMimeByFilename(what, len);
846 if (fstat(fileno(fp), &statbuf) == -1) {
847 lprintf(9, "output_static('%s') -- FSTAT FAILED --\n", what);
848 wprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
849 wprintf("Content-Type: text/plain\r\n");
851 wprintf("Cannot fstat %s: %s\n", what, strerror(errno));
856 bytes = statbuf.st_size;
857 if ((bigbuffer = malloc(bytes + 2)) == NULL) {
858 lprintf(9, "output_static('%s') -- MALLOC FAILED (%s) --\n", what, strerror(errno));
859 wprintf("HTTP/1.1 500 internal server error\r\n");
860 wprintf("Content-Type: text/plain\r\n");
864 while (count < bytes) {
865 if ((res = fread(bigbuffer + count, 1, bytes - count, fp)) == 0) {
866 lprintf(9, "output_static('%s') -- FREAD FAILED (%s) %zu bytes of %zu --\n", what, strerror(errno), bytes - count, bytes);
867 wprintf("HTTP/1.1 500 internal server error \r\n");
868 wprintf("Content-Type: text/plain\r\n");
877 lprintf(9, "output_static('%s') %s\n", what, content_type);
878 http_transmit_thing(bigbuffer, (size_t)bytes, content_type, 1);
881 if (yesbstr("force_close_session")) {
882 end_webcit_session();
887 * \brief When the browser requests an image file from the Citadel server,
888 * this function is called to transmit it.
893 char *xferbuf = NULL;
895 const char *MimeType;
897 serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
898 serv_getln(buf, sizeof buf);
900 bytes = extract_long(&buf[4], 0);
901 xferbuf = malloc(bytes + 2);
903 /** Read it from the server */
904 read_server_binary(xferbuf, bytes);
906 serv_getln(buf, sizeof buf);
908 MimeType = GuessMimeType (xferbuf, bytes);
909 /** Write it to the browser */
910 if (!IsEmptyStr(MimeType))
912 http_transmit_thing(xferbuf,
919 /* hm... unknown mimetype? fallback to blank gif */
925 * Instead of an ugly 404, send a 1x1 transparent GIF
926 * when there's no such image on the server.
929 snprintf (blank_gif, SIZ, "%s%s", static_dirs[0], "/blank.gif");
930 output_static(blank_gif);
934 * \brief Extract an embedded photo from a vCard for display on the client
938 void display_vcard_photo_img(char *msgnum_as_string)
946 const char *contentType;
948 msgnum = atol(msgnum_as_string);
950 vcard = load_mimepart(msgnum,"1");
951 v = vcard_load(vcard);
953 photosrc = vcard_get_prop(v, "PHOTO", 1,0,0);
954 xferbuf = malloc(strlen(photosrc));
955 if (xferbuf == NULL) {
956 lprintf(5, "xferbuf malloc failed\n");
959 memset(xferbuf, 1, SIZ);
960 decoded = CtdlDecodeBase64(
964 contentType = GuessMimeType(xferbuf, decoded);
965 http_transmit_thing(xferbuf, decoded, contentType, 0);
972 * \brief Generic function to output an arbitrary MIME part from an arbitrary
973 * message number on the server.
975 * \param msgnum Number of the item on the citadel server
976 * \param partnum The MIME part to be output
977 * \param force_download Nonzero to force set the Content-Type: header
978 * to "application/octet-stream"
980 void mimepart(char *msgnum, char *partnum, int force_download)
984 char content_type[256];
985 char *content = NULL;
987 serv_printf("OPNA %s|%s", msgnum, partnum);
988 serv_getln(buf, sizeof buf);
990 bytes = extract_long(&buf[4], 0);
991 content = malloc(bytes + 2);
992 if (force_download) {
993 strcpy(content_type, "application/octet-stream");
996 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
998 output_headers(0, 0, 0, 0, 0, 0);
999 read_server_binary(content, bytes);
1001 serv_getln(buf, sizeof buf);
1002 http_transmit_thing(content, bytes, content_type, 0);
1005 wprintf("HTTP/1.1 404 %s\n", &buf[4]);
1006 output_headers(0, 0, 0, 0, 0, 0);
1007 wprintf("Content-Type: text/plain\r\n");
1009 wprintf(_("An error occurred while retrieving this part: %s\n"), &buf[4]);
1016 * \brief Read any MIME part of a message, from the server, into memory.
1017 * \param msgnum number of the message on the citadel server
1018 * \param partnum the MIME part to be loaded
1020 char *load_mimepart(long msgnum, char *partnum)
1024 char content_type[SIZ];
1027 serv_printf("DLAT %ld|%s", msgnum, partnum);
1028 serv_getln(buf, sizeof buf);
1029 if (buf[0] == '6') {
1030 bytes = extract_long(&buf[4], 0);
1031 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
1033 content = malloc(bytes + 2);
1034 serv_read(content, bytes);
1036 content[bytes] = 0; /* null terminate for good measure */
1047 * \brief Convenience functions to display a page containing only a string
1048 * \param titlebarcolor color of the titlebar of the frame
1049 * \param titlebarmsg text to display in the title bar
1050 * \param messagetext body of the box
1052 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
1054 wprintf("HTTP/1.1 200 OK\n");
1055 output_headers(1, 1, 2, 0, 0, 0);
1056 wprintf("<div id=\"banner\">\n");
1057 wprintf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
1058 wprintf("<span class=\"titlebar\">%s</span>\n", titlebarmsg);
1059 wprintf("</td></tr></table>\n");
1060 wprintf("</div>\n<div id=\"content\">\n");
1061 escputs(messagetext);
1063 wprintf("<hr />\n");
1069 * \brief Display a blank page.
1071 void blank_page(void) {
1072 output_headers(1, 1, 0, 0, 0, 0);
1078 * \brief A template has been requested
1080 void url_do_template(void) {
1081 do_template(bstr("template"));
1087 * \brief Offer to make any page the user's "start page."
1089 void offer_start_page(void) {
1090 wprintf("<a href=\"change_start_page?startpage=");
1091 urlescputs(WC->this_page);
1093 wprintf(_("Make this my start page"));
1096 wprintf("<br/><a href=\"rss?room=");
1097 urlescputs(WC->wc_roomname);
1098 wprintf("\" title=\"RSS 2.0 feed for ");
1099 escputs(WC->wc_roomname);
1100 wprintf("\"><img alt=\"RSS\" border=\"0\" src=\"static/xml_button.gif\"/></a>\n");
1106 * \brief Change the user's start page
1108 void change_start_page(void) {
1110 if (bstr("startpage") == NULL) {
1111 safestrncpy(WC->ImportantMessage,
1112 _("You no longer have a start page selected."),
1113 sizeof WC->ImportantMessage);
1114 display_main_menu();
1118 set_preference("startpage", bstr("startpage"), 1);
1120 output_headers(1, 1, 0, 0, 0, 0);
1121 do_template("newstartpage");
1128 * \brief convenience function to indicate success
1129 * \param successmessage the mesage itself
1131 void display_success(char *successmessage)
1133 convenience_page("007700", "OK", successmessage);
1138 * \brief Authorization required page
1139 * This is probably temporary and should be revisited
1140 * \param message message to put in header
1142 void authorization_required(const char *message)
1144 wprintf("HTTP/1.1 401 Authorization Required\r\n");
1145 wprintf("WWW-Authenticate: Basic realm=\"\"\r\n", serv_info.serv_humannode);
1146 wprintf("Content-Type: text/html\r\n\r\n");
1148 wprintf(_("Authorization Required"));
1149 wprintf("</h1>\r\n");
1150 wprintf(_("The resource you requested requires a valid username and password. "
1151 "You could not be logged in: %s\n"), message);
1156 * \brief This function is called by the MIME parser to handle data uploaded by
1157 * the browser. Form data, uploaded files, and the data from HTTP PUT
1158 * operations (such as those found in GroupDAV) all arrive this way.
1160 * \param name Name of the item being uploaded
1161 * \param filename Filename of the item being uploaded
1162 * \param partnum MIME part identifier (not needed)
1163 * \param disp MIME content disposition (not needed)
1164 * \param content The actual data
1165 * \param cbtype MIME content-type
1166 * \param cbcharset Character set
1167 * \param length Content length
1168 * \param encoding MIME encoding type (not needed)
1169 * \param userdata Not used here
1171 void upload_handler(char *name, char *filename, char *partnum, char *disp,
1172 void *content, char *cbtype, char *cbcharset,
1173 size_t length, char *encoding, void *userdata)
1177 lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n", name, cbtype, length);
1179 if (WC->urlstrings == NULL)
1180 WC->urlstrings = NewHash(1, NULL);
1183 if ( (length > 0) && (IsEmptyStr(cbtype)) ) {
1184 u = (urlcontent *) malloc(sizeof(urlcontent));
1186 safestrncpy(u->url_key, name, sizeof(u->url_key));
1187 u->url_data = malloc(length + 1);
1188 u->url_data_size = length;
1189 memcpy(u->url_data, content, length);
1190 u->url_data[length] = 0;
1191 Put(WC->urlstrings, u->url_key, strlen(u->url_key), u, free_url);
1193 /* lprintf(9, "Key: <%s> len: [%ld] Data: <%s>\n", u->url_key, u->url_data_size, u->url_data);*/
1196 /** Uploaded files */
1197 if ( (length > 0) && (!IsEmptyStr(cbtype)) ) {
1198 WC->upload = malloc(length);
1199 if (WC->upload != NULL) {
1200 WC->upload_length = length;
1201 safestrncpy(WC->upload_filename, filename,
1202 sizeof(WC->upload_filename));
1203 safestrncpy(WC->upload_content_type, cbtype,
1204 sizeof(WC->upload_content_type));
1205 memcpy(WC->upload, content, length);
1208 lprintf(3, "malloc() failed: %s\n", strerror(errno));
1215 * \brief Convenience functions to wrap around asynchronous ajax responses
1217 void begin_ajax_response(void) {
1218 output_headers(0, 0, 0, 0, 0, 0);
1220 wprintf("Content-type: text/html; charset=UTF-8\r\n"
1222 "Connection: close\r\n"
1223 "Pragma: no-cache\r\n"
1224 "Cache-Control: no-cache\r\n"
1232 * \brief print ajax response footer
1234 void end_ajax_response(void) {
1240 * \brief Wraps a Citadel server command in an AJAX transaction.
1242 void ajax_servcmd(void)
1245 char gcontent[1024];
1249 begin_ajax_response();
1251 serv_printf("%s", bstr("g_cmd"));
1252 serv_getln(buf, sizeof buf);
1253 wprintf("%s\n", buf);
1255 if (buf[0] == '8') {
1256 serv_printf("\n\n000");
1258 if ((buf[0] == '1') || (buf[0] == '8')) {
1259 while (serv_getln(gcontent, sizeof gcontent), strcmp(gcontent, "000")) {
1260 wprintf("%s\n", gcontent);
1264 if (buf[0] == '4') {
1265 text_to_server(bstr("g_input"));
1268 if (buf[0] == '6') {
1269 len = atol(&buf[4]);
1271 serv_read(junk, len);
1274 if (buf[0] == '7') {
1275 len = atol(&buf[4]);
1277 memset(junk, 0, len);
1278 serv_write(junk, len);
1282 end_ajax_response();
1285 * This is kind of an ugly hack, but this is the only place it can go.
1286 * If the command was GEXP, then the instant messenger window must be
1287 * running, so reset the "last_pager_check" watchdog timer so
1288 * that page_popup() doesn't try to open it a second time.
1290 if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) {
1291 WC->last_pager_check = time(NULL);
1297 * \brief Helper function for the asynchronous check to see if we need
1298 * to open the instant messenger window.
1300 void seconds_since_last_gexp(void)
1304 begin_ajax_response();
1305 if ( (time(NULL) - WC->last_pager_check) < 30) {
1310 serv_getln(buf, sizeof buf);
1311 if (buf[3] == '*') {
1318 end_ajax_response();
1325 * \brief Entry point for WebCit transaction
1327 void session_loop(struct httprequest *req)
1335 char request_method[128];
1336 char pathname[1024];
1337 int a, b, nBackDots, nEmpty;
1338 int ContentLength = 0;
1340 char ContentType[512];
1341 char *content = NULL;
1342 char *content_end = NULL;
1343 struct httprequest *hptr;
1344 char browser_host[256];
1345 char user_agent[256];
1351 * We stuff these with the values coming from the client cookies,
1352 * so we can use them to reconnect a timed out session if we have to.
1354 char c_username[SIZ];
1355 char c_password[SIZ];
1356 char c_roomname[SIZ];
1357 char c_httpauth_string[SIZ];
1358 char c_httpauth_user[SIZ];
1359 char c_httpauth_pass[SIZ];
1362 safestrncpy(c_username, "", sizeof c_username);
1363 safestrncpy(c_password, "", sizeof c_password);
1364 safestrncpy(c_roomname, "", sizeof c_roomname);
1365 safestrncpy(c_httpauth_string, "", sizeof c_httpauth_string);
1366 safestrncpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER, sizeof c_httpauth_user);
1367 safestrncpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS, sizeof c_httpauth_pass);
1368 strcpy(browser_host, "");
1370 WC->upload_length = 0;
1375 if (hptr == NULL) return;
1377 safestrncpy(cmd, hptr->line, sizeof cmd);
1379 extract_token(request_method, cmd, 0, ' ', sizeof request_method);
1380 extract_token(pathname, cmd, 1, ' ', sizeof pathname);
1382 /** Figure out the action */
1384 sizes[0] = sizeof action;
1387 index[a] = arg[a-1];
1388 sizes[a] = sizeof arg[a-1];
1390 //// index[9] = &foo; todo
1393 for ( a = 0; a < 9; ++a)
1395 extract_token(index[a], pathname, a + 1, '/', sizes[a]);
1396 if (strstr(index[a], "?")) *strstr(index[a], "?") = 0;
1397 if (strstr(index[a], "&")) *strstr(index[a], "&") = 0;
1398 if (strstr(index[a], " ")) *strstr(index[a], " ") = 0;
1399 if ((index[a][0] == '.') && (index[a][1] == '.'))
1401 if (index[a][0] == '\0')
1405 while (hptr != NULL) {
1406 safestrncpy(buf, hptr->line, sizeof buf);
1407 /* lprintf(9, "HTTP HEADER: %s\n", buf); */
1410 if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
1411 safestrncpy(cookie, &buf[15], sizeof cookie);
1412 cookie_to_stuff(cookie, NULL,
1413 c_username, sizeof c_username,
1414 c_password, sizeof c_password,
1415 c_roomname, sizeof c_roomname);
1417 else if (!strncasecmp(buf, "Authorization: Basic ", 21)) {
1418 CtdlDecodeBase64(c_httpauth_string, &buf[21], strlen(&buf[21]));
1419 extract_token(c_httpauth_user, c_httpauth_string, 0, ':', sizeof c_httpauth_user);
1420 extract_token(c_httpauth_pass, c_httpauth_string, 1, ':', sizeof c_httpauth_pass);
1422 else if (!strncasecmp(buf, "Content-length: ", 16)) {
1423 ContentLength = atoi(&buf[16]);
1425 else if (!strncasecmp(buf, "Content-type: ", 14)) {
1426 safestrncpy(ContentType, &buf[14], sizeof ContentType);
1428 else if (!strncasecmp(buf, "User-agent: ", 12)) {
1429 safestrncpy(user_agent, &buf[12], sizeof user_agent);
1431 else if (!strncasecmp(buf, "X-Forwarded-Host: ", 18)) {
1433 safestrncpy(WC->http_host, &buf[18], sizeof WC->http_host);
1436 else if (!strncasecmp(buf, "Host: ", 6)) {
1437 if (IsEmptyStr(WC->http_host)) {
1438 safestrncpy(WC->http_host, &buf[6], sizeof WC->http_host);
1441 else if (!strncasecmp(buf, "X-Forwarded-For: ", 17)) {
1442 safestrncpy(browser_host, &buf[17], sizeof browser_host);
1443 while (num_tokens(browser_host, ',') > 1) {
1444 remove_token(browser_host, 0, ',');
1446 striplt(browser_host);
1448 /** Only WAP gateways explicitly name this content-type */
1449 else if (strstr(buf, "text/vnd.wap.wml")) {
1454 if (ContentLength > 0) {
1455 content = malloc(ContentLength + SIZ);
1456 memset(content, 0, ContentLength + SIZ);
1457 snprintf(content, ContentLength + SIZ, "Content-type: %s\n"
1458 "Content-length: %d\n\n",
1459 ContentType, ContentLength);
1460 body_start = strlen(content);
1462 /** Read the entire input data at once. */
1463 client_read(WC->http_sock, &content[BytesRead+body_start], ContentLength);
1465 if (!strncasecmp(ContentType, "application/x-www-form-urlencoded", 33)) {
1466 addurls(&content[body_start]);
1467 } else if (!strncasecmp(ContentType, "multipart", 9)) {
1468 content_end = content + ContentLength + body_start;
1469 mime_parser(content, content_end, *upload_handler, NULL, NULL, NULL, 0);
1475 /** make a note of where we are in case the user wants to save it */
1476 safestrncpy(WC->this_page, cmd, sizeof(WC->this_page));
1477 remove_token(WC->this_page, 2, ' ');
1478 remove_token(WC->this_page, 0, ' ');
1480 /** If there are variables in the URL, we must grab them now */
1482 for (a = 0; a < len; ++a) {
1483 if ((cmd[a] == '?') || (cmd[a] == '&')) {
1484 for (b = a; b < len; ++b) {
1485 if (isspace(cmd[b])){
1490 addurls(&cmd[a + 1]);
1496 /** If it's a "force 404" situation then display the error and bail. */
1497 if (!strcmp(action, "404")) {
1498 wprintf("HTTP/1.1 404 Not found\r\n");
1499 wprintf("Content-Type: text/plain\r\n");
1501 wprintf("Not found\r\n");
1502 goto SKIP_ALL_THIS_CRAP;
1505 /** Static content can be sent without connecting to Citadel. */
1507 for (a=0; a<ndirs; ++a) {
1508 if (!strcasecmp(action, (char*)static_content_dirs[a])) { /* map web to disk location */
1516 snprintf(buf, sizeof buf, "%s/%s/%s/%s/%s/%s/%s/%s",
1517 static_dirs[n_static],
1518 index[1], index[2], index[3], index[4], index[5], index[6], index[7]);
1519 for (a=0; a<8; ++a) {
1520 if (buf[strlen(buf)-1] == '/') {
1521 buf[strlen(buf)-1] = 0;
1524 for (a = 0; a < strlen(buf); ++a) {
1525 if (isspace(buf[a])) {
1533 lprintf(9, "Suspicious request. Ignoring.");
1534 wprintf("HTTP/1.1 404 Security check failed\r\n");
1535 wprintf("Content-Type: text/plain\r\n");
1537 wprintf("You have sent a malformed or invalid request.\r\n");
1539 goto SKIP_ALL_THIS_CRAP; /* Don't try to connect */
1542 /* If the client sent a nonce that is incorrect, kill the request. */
1543 if (strlen(bstr("nonce")) > 0) {
1544 lprintf(9, "Comparing supplied nonce %s to session nonce %ld\n",
1545 bstr("nonce"), WC->nonce);
1546 if (ibstr("nonce") != WC->nonce) {
1547 lprintf(9, "Ignoring request with mismatched nonce.\n");
1548 wprintf("HTTP/1.1 404 Security check failed\r\n");
1549 wprintf("Content-Type: text/plain\r\n");
1551 wprintf("Security check failed.\r\n");
1552 goto SKIP_ALL_THIS_CRAP;
1557 * If we're not connected to a Citadel server, try to hook up the
1560 if (!WC->connected) {
1561 if (!strcasecmp(ctdlhost, "uds")) {
1562 /* unix domain socket */
1563 snprintf(buf, SIZ, "%s/citadel.socket", ctdlport);
1564 WC->serv_sock = uds_connectsock(buf);
1568 WC->serv_sock = tcp_connectsock(ctdlhost, ctdlport);
1571 if (WC->serv_sock < 0) {
1573 goto SKIP_ALL_THIS_CRAP;
1577 serv_getln(buf, sizeof buf); /** get the server welcome message */
1580 * From what host is our user connecting? Go with
1581 * the host at the other end of the HTTP socket,
1582 * unless we are following X-Forwarded-For: headers
1583 * and such a header has already turned up something.
1585 if ( (!follow_xff) || (strlen(browser_host) == 0) ) {
1586 locate_host(browser_host, WC->http_sock);
1589 get_serv_info(browser_host, user_agent);
1590 if (serv_info.serv_rev_level < MINIMUM_CIT_VERSION) {
1591 wprintf(_("You are connected to a Citadel "
1592 "server running Citadel %d.%02d. \n"
1593 "In order to run this version of WebCit "
1594 "you must also have Citadel %d.%02d or"
1596 serv_info.serv_rev_level / 100,
1597 serv_info.serv_rev_level % 100,
1598 MINIMUM_CIT_VERSION / 100,
1599 MINIMUM_CIT_VERSION % 100
1601 end_webcit_session();
1602 goto SKIP_ALL_THIS_CRAP;
1608 * Functions which can be performed without logging in
1610 if (!strcasecmp(action, "listsub")) {
1612 goto SKIP_ALL_THIS_CRAP;
1614 if (!strcasecmp(action, "freebusy")) {
1616 goto SKIP_ALL_THIS_CRAP;
1620 * If we're not logged in, but we have HTTP Authentication data,
1621 * try logging in to Citadel using that.
1623 if ((!WC->logged_in)
1624 && (strlen(c_httpauth_user) > 0)
1625 && (strlen(c_httpauth_pass) > 0)) {
1626 serv_printf("USER %s", c_httpauth_user);
1627 serv_getln(buf, sizeof buf);
1628 if (buf[0] == '3') {
1629 serv_printf("PASS %s", c_httpauth_pass);
1630 serv_getln(buf, sizeof buf);
1631 if (buf[0] == '2') {
1632 become_logged_in(c_httpauth_user,
1633 c_httpauth_pass, buf);
1634 safestrncpy(WC->httpauth_user, c_httpauth_user, sizeof WC->httpauth_user);
1635 safestrncpy(WC->httpauth_pass, c_httpauth_pass, sizeof WC->httpauth_pass);
1637 /** Should only display when password is wrong */
1638 authorization_required(&buf[4]);
1639 goto SKIP_ALL_THIS_CRAP;
1644 /** This needs to run early */
1646 if (!strcasecmp(action, "rss")) {
1647 display_rss(bstr("room"), request_method);
1648 goto SKIP_ALL_THIS_CRAP;
1653 * The GroupDAV stuff relies on HTTP authentication instead of
1654 * our session's authentication.
1656 if (!strncasecmp(action, "groupdav", 8)) {
1657 groupdav_main(req, ContentType, /* do GroupDAV methods */
1658 ContentLength, content+body_start);
1659 if (!WC->logged_in) {
1660 WC->killthis = 1; /* If not logged in, don't */
1661 } /* keep the session active */
1662 goto SKIP_ALL_THIS_CRAP;
1667 * Automatically send requests with any method other than GET or
1668 * POST to the GroupDAV code as well.
1670 if ((strcasecmp(request_method, "GET")) && (strcasecmp(request_method, "POST"))) {
1671 groupdav_main(req, ContentType, /** do GroupDAV methods */
1672 ContentLength, content+body_start);
1673 if (!WC->logged_in) {
1674 WC->killthis = 1; /** If not logged in, don't */
1675 } /** keep the session active */
1676 goto SKIP_ALL_THIS_CRAP;
1680 * If we're not logged in, but we have username and password cookies
1681 * supplied by the browser, try using them to log in.
1683 if ((!WC->logged_in)
1684 && (!IsEmptyStr(c_username))
1685 && (!IsEmptyStr(c_password))) {
1686 serv_printf("USER %s", c_username);
1687 serv_getln(buf, sizeof buf);
1688 if (buf[0] == '3') {
1689 serv_printf("PASS %s", c_password);
1690 serv_getln(buf, sizeof buf);
1691 if (buf[0] == '2') {
1692 become_logged_in(c_username, c_password, buf);
1697 * If we don't have a current room, but a cookie specifying the
1698 * current room is supplied, make an effort to go there.
1700 if ((IsEmptyStr(WC->wc_roomname)) && (!IsEmptyStr(c_roomname))) {
1701 serv_printf("GOTO %s", c_roomname);
1702 serv_getln(buf, sizeof buf);
1703 if (buf[0] == '2') {
1704 safestrncpy(WC->wc_roomname, c_roomname, sizeof WC->wc_roomname);
1708 if (!strcasecmp(action, "image")) {
1710 } else if (!strcasecmp(action, "display_mime_icon")) {
1711 display_mime_icon();
1714 * All functions handled below this point ... make sure we log in
1715 * before doing anything else!
1717 } else if ((!WC->logged_in) && (!strcasecmp(action, "login"))) {
1719 } else if ((!WC->logged_in) && (!strcasecmp(action, "display_openid_login"))) {
1720 display_openid_login(NULL);
1721 } else if ((!WC->logged_in) && (!strcasecmp(action, "openid_login"))) {
1723 } else if ((!WC->logged_in) && (!strcasecmp(action, "finish_openid_login"))) {
1724 finish_openid_login();
1725 } else if (!WC->logged_in) {
1726 display_login(NULL);
1730 * Various commands...
1735 WebcitHandler *Handler;
1737 GetHash(HandlerHash, action, strlen(action) /* TODO*/, &vHandler),
1738 Handler = (WebcitHandler*) vHandler;
1739 if (Handler != NULL) {
1740 if (Handler->IsAjax)
1741 begin_ajax_response();
1743 if (Handler->IsAjax)
1744 end_ajax_response();
1748 else if (!strcasecmp(action, "do_welcome")) {
1750 } else if (!strcasecmp(action, "blank")) {
1752 } else if (!strcasecmp(action, "do_template")) {
1754 } else if (!strcasecmp(action, "display_aide_menu")) {
1755 display_aide_menu();
1756 } else if (!strcasecmp(action, "server_shutdown")) {
1758 } else if (!strcasecmp(action, "display_main_menu")) {
1759 display_main_menu();
1760 } else if (!strcasecmp(action, "who")) {
1762 } else if (!strcasecmp(action, "sslg")) {
1763 seconds_since_last_gexp();
1764 } else if (!strcasecmp(action, "who_inner_html")) {
1765 begin_ajax_response();
1767 end_ajax_response();
1768 } else if (!strcasecmp(action, "wholist_section")) {
1769 begin_ajax_response();
1771 end_ajax_response();
1772 } else if (!strcasecmp(action, "new_messages_html")) {
1773 begin_ajax_response();
1774 new_messages_section();
1775 end_ajax_response();
1776 } else if (!strcasecmp(action, "tasks_inner_html")) {
1777 begin_ajax_response();
1779 end_ajax_response();
1780 } else if (!strcasecmp(action, "calendar_inner_html")) {
1781 begin_ajax_response();
1783 end_ajax_response();
1784 } else if (!strcasecmp(action, "mini_calendar")) {
1785 begin_ajax_response();
1786 ajax_mini_calendar();
1787 end_ajax_response();
1788 } else if (!strcasecmp(action, "iconbar_ajax_menu")) {
1789 begin_ajax_response();
1791 end_ajax_response();
1792 } else if (!strcasecmp(action, "iconbar_ajax_rooms")) {
1793 begin_ajax_response();
1794 do_iconbar_roomlist();
1795 end_ajax_response();
1796 } else if (!strcasecmp(action, "knrooms")) {
1798 } else if (!strcasecmp(action, "gotonext")) {
1801 } else if (!strcasecmp(action, "skip")) {
1803 } else if (!strcasecmp(action, "ungoto")) {
1805 } else if (!strcasecmp(action, "dotgoto")) {
1806 if (WC->wc_view != VIEW_MAILBOX) { /* dotgoto acts like dotskip when we're in a mailbox view */
1809 smart_goto(bstr("room"));
1810 } else if (!strcasecmp(action, "dotskip")) {
1811 smart_goto(bstr("room"));
1812 } else if (!strcasecmp(action, "termquit")) {
1814 } else if (!strcasecmp(action, "readnew")) {
1815 readloop("readnew");
1816 } else if (!strcasecmp(action, "readold")) {
1817 readloop("readold");
1818 } else if (!strcasecmp(action, "readfwd")) {
1819 readloop("readfwd");
1820 } else if (!strcasecmp(action, "headers")) {
1821 readloop("headers");
1822 } else if (!strcasecmp(action, "do_search")) {
1823 readloop("do_search");
1824 } else if (!strcasecmp(action, "msg")) {
1825 embed_message(index[1]);
1826 } else if (!strcasecmp(action, "printmsg")) {
1827 print_message(index[1]);
1828 } else if (!strcasecmp(action, "msgheaders")) {
1829 display_headers(index[1]);
1830 } else if (!strcasecmp(action, "vcardphoto")) {
1831 display_vcard_photo_img(index[1]);
1832 } else if (!strcasecmp(action, "wiki")) {
1833 display_wiki_page();
1834 } else if (!strcasecmp(action, "display_enter")) {
1836 } else if (!strcasecmp(action, "post")) {
1838 } else if (!strcasecmp(action, "move_msg")) {
1840 } else if (!strcasecmp(action, "delete_msg")) {
1842 } else if (!strcasecmp(action, "userlist")) {
1844 } else if (!strcasecmp(action, "showuser")) {
1846 } else if (!strcasecmp(action, "display_page")) {
1848 } else if (!strcasecmp(action, "page_user")) {
1850 } else if (!strcasecmp(action, "chat")) {
1852 } else if (!strcasecmp(action, "display_private")) {
1853 display_private("", 0);
1854 } else if (!strcasecmp(action, "goto_private")) {
1856 } else if (!strcasecmp(action, "zapped_list")) {
1858 } else if (!strcasecmp(action, "display_zap")) {
1860 } else if (!strcasecmp(action, "zap")) {
1862 } else if (!strcasecmp(action, "display_entroom")) {
1864 } else if (!strcasecmp(action, "entroom")) {
1866 } else if (!strcasecmp(action, "display_whok")) {
1868 } else if (!strcasecmp(action, "do_invt_kick")) {
1870 } else if (!strcasecmp(action, "display_editroom")) {
1872 } else if (!strcasecmp(action, "netedit")) {
1874 } else if (!strcasecmp(action, "editroom")) {
1876 } else if (!strcasecmp(action, "display_editinfo")) {
1877 display_edit(_("Room info"), "EINF 0", "RINF", "editinfo", 1);
1878 } else if (!strcasecmp(action, "editinfo")) {
1879 save_edit(_("Room info"), "EINF 1", 1);
1880 } else if (!strcasecmp(action, "display_editbio")) {
1881 snprintf(buf, SIZ, "RBIO %s", WC->wc_fullname);
1882 display_edit(_("Your bio"), "NOOP", buf, "editbio", 3);
1883 } else if (!strcasecmp(action, "editbio")) {
1884 save_edit(_("Your bio"), "EBIO", 0);
1885 } else if (!strcasecmp(action, "confirm_move_msg")) {
1887 } else if (!strcasecmp(action, "delete_room")) {
1889 } else if (!strcasecmp(action, "validate")) {
1891 /* The users photo display / upload facility */
1892 } else if (!strcasecmp(action, "display_editpic")) {
1893 display_graphics_upload(_("your photo"),
1896 } else if (!strcasecmp(action, "editpic")) {
1897 do_graphics_upload("_userpic_");
1898 /* room picture dispay / upload facility */
1899 } else if (!strcasecmp(action, "display_editroompic")) {
1900 display_graphics_upload(_("the icon for this room"),
1903 } else if (!strcasecmp(action, "editroompic")) {
1904 do_graphics_upload("_roompic_");
1905 /* the greetingpage hello pic */
1906 } else if (!strcasecmp(action, "display_edithello")) {
1907 display_graphics_upload(_("the Greetingpicture for the login prompt"),
1910 } else if (!strcasecmp(action, "edithellopic")) {
1911 do_graphics_upload("hello");
1912 /* the logoff banner */
1913 } else if (!strcasecmp(action, "display_editgoodbyepic")) {
1914 display_graphics_upload(_("the Logoff banner picture"),
1915 "UIMG 0|%s|goodbuye",
1917 } else if (!strcasecmp(action, "editgoodbuyepic")) {
1918 do_graphics_upload("UIMG 1|%s|goodbuye");
1920 } else if (!strcasecmp(action, "delete_floor")) {
1922 } else if (!strcasecmp(action, "rename_floor")) {
1924 } else if (!strcasecmp(action, "create_floor")) {
1926 } else if (!strcasecmp(action, "display_editfloorpic")) {
1927 snprintf(buf, SIZ, "UIMG 0|_floorpic_|%s",
1928 bstr("which_floor"));
1929 display_graphics_upload(_("the icon for this floor"),
1932 } else if (!strcasecmp(action, "editfloorpic")) {
1933 snprintf(buf, SIZ, "UIMG 1|_floorpic_|%s",
1934 bstr("which_floor"));
1935 do_graphics_upload(buf);
1936 } else if (!strcasecmp(action, "display_reg")) {
1938 } else if (!strcasecmp(action, "display_changepw")) {
1940 } else if (!strcasecmp(action, "changepw")) {
1942 } else if (!strcasecmp(action, "display_edit_node")) {
1943 display_edit_node();
1944 } else if (!strcasecmp(action, "edit_node")) {
1946 } else if (!strcasecmp(action, "display_netconf")) {
1948 } else if (!strcasecmp(action, "display_confirm_delete_node")) {
1949 display_confirm_delete_node();
1950 } else if (!strcasecmp(action, "delete_node")) {
1952 } else if (!strcasecmp(action, "display_add_node")) {
1954 } else if (!strcasecmp(action, "terminate_session")) {
1956 terminate_session();
1957 } else if (!strcasecmp(action, "edit_me")) {
1959 } else if (!strcasecmp(action, "display_siteconfig")) {
1960 display_siteconfig();
1961 } else if (!strcasecmp(action, "chat_recv")) {
1963 } else if (!strcasecmp(action, "chat_send")) {
1965 } else if (!strcasecmp(action, "siteconfig")) {
1967 } else if (!strcasecmp(action, "display_generic")) {
1969 } else if (!strcasecmp(action, "do_generic")) {
1971 } else if (!strcasecmp(action, "ajax_servcmd")) {
1973 } else if (!strcasecmp(action, "display_menubar")) {
1975 } else if (!strcasecmp(action, "mimepart")) {
1976 mimepart(index[1], index[2], 0);
1977 } else if (!strcasecmp(action, "mimepart_download")) {
1978 mimepart(index[1], index[2], 1);
1979 } else if (!strcasecmp(action, "edit_vcard")) {
1981 } else if (!strcasecmp(action, "submit_vcard")) {
1983 } else if (!strcasecmp(action, "select_user_to_edit")) {
1984 select_user_to_edit(NULL, NULL);
1985 } else if (!strcasecmp(action, "display_edituser")) {
1986 display_edituser(NULL, 0);
1987 } else if (!strcasecmp(action, "edituser")) {
1989 } else if (!strcasecmp(action, "create_user")) {
1991 } else if (!strcasecmp(action, "changeview")) {
1993 } else if (!strcasecmp(action, "change_start_page")) {
1994 change_start_page();
1995 } else if (!strcasecmp(action, "display_floorconfig")) {
1996 display_floorconfig(NULL);
1997 } else if (!strcasecmp(action, "toggle_self_service")) {
1998 toggle_self_service();
1999 } else if (!strcasecmp(action, "display_edit_task")) {
2000 display_edit_task();
2001 } else if (!strcasecmp(action, "save_task")) {
2003 } else if (!strcasecmp(action, "display_edit_event")) {
2004 display_edit_event();
2005 } else if (!strcasecmp(action, "save_event")) {
2007 } else if (!strcasecmp(action, "respond_to_request")) {
2008 respond_to_request();
2009 } else if (!strcasecmp(action, "handle_rsvp")) {
2011 } else if (!strcasecmp(action, "summary")) {
2013 } else if (!strcasecmp(action, "summary_inner_div")) {
2014 begin_ajax_response();
2015 summary_inner_div();
2016 end_ajax_response();
2017 } else if (!strcasecmp(action, "display_customize_iconbar")) {
2018 display_customize_iconbar();
2019 } else if (!strcasecmp(action, "commit_iconbar")) {
2021 } else if (!strcasecmp(action, "set_room_policy")) {
2023 } else if (!strcasecmp(action, "display_inetconf")) {
2025 } else if (!strcasecmp(action, "save_inetconf")) {
2027 } else if (!strcasecmp(action, "display_smtpqueue")) {
2028 display_smtpqueue();
2029 } else if (!strcasecmp(action, "display_smtpqueue_inner_div")) {
2030 display_smtpqueue_inner_div();
2031 } else if (!strcasecmp(action, "display_sieve")) {
2033 } else if (!strcasecmp(action, "save_sieve")) {
2035 } else if (!strcasecmp(action, "display_pushemail")) {
2036 display_pushemail();
2037 } else if (!strcasecmp(action, "save_pushemail")) {
2039 } else if (!strcasecmp(action, "display_add_remove_scripts")) {
2040 display_add_remove_scripts(NULL);
2041 } else if (!strcasecmp(action, "create_script")) {
2043 } else if (!strcasecmp(action, "delete_script")) {
2045 } else if (!strcasecmp(action, "setup_wizard")) {
2047 } else if (!strcasecmp(action, "display_preferences")) {
2048 display_preferences();
2049 } else if (!strcasecmp(action, "set_preferences")) {
2051 } else if (!strcasecmp(action, "recp_autocomplete")) {
2052 recp_autocomplete(bstr("recp"));
2053 } else if (!strcasecmp(action, "cc_autocomplete")) {
2054 recp_autocomplete(bstr("cc"));
2055 } else if (!strcasecmp(action, "bcc_autocomplete")) {
2056 recp_autocomplete(bstr("bcc"));
2057 } else if (!strcasecmp(action, "display_address_book_middle_div")) {
2058 display_address_book_middle_div();
2059 } else if (!strcasecmp(action, "display_address_book_inner_div")) {
2060 display_address_book_inner_div();
2061 } else if (!strcasecmp(action, "set_floordiv_expanded")) {
2062 set_floordiv_expanded(index[1]);
2063 } else if (!strcasecmp(action, "diagnostics")) {
2064 output_headers(1, 1, 1, 0, 0, 0);
2065 wprintf("Session: %d<hr />\n", WC->wc_session);
2066 wprintf("Command: <br /><PRE>\n");
2068 wprintf("</PRE><hr />\n");
2069 wprintf("Variables: <br /><PRE>\n");
2071 wprintf("</PRE><hr />\n");
2073 } else if (!strcasecmp(action, "add_new_note")) {
2075 } else if (!strcasecmp(action, "ajax_update_note")) {
2077 } else if (!strcasecmp(action, "display_room_directory")) {
2078 display_room_directory();
2079 } else if (!strcasecmp(action, "display_pictureview")) {
2080 display_pictureview();
2081 } else if (!strcasecmp(action, "download_file")) {
2082 download_file(index[1]);
2083 } else if (!strcasecmp(action, "upload_file")) {
2087 /** When all else fais, display the main menu. */
2089 display_main_menu();
2094 if (content != NULL) {
2099 if (WC->upload_length > 0) {
2101 WC->upload_length = 0;
2106 * \brief Replacement for sleep() that uses select() in order to avoid SIGALRM
2107 * \param seconds how many seconds should we sleep?
2109 void sleeeeeeeeeep(int seconds)
2113 tv.tv_sec = seconds;
2115 select(0, NULL, NULL, NULL, &tv);