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, long ulen)
98 char *aptr, *bptr, *eptr;
103 struct wcsession *WCC = WC;
105 if (WCC->urlstrings == NULL)
106 WCC->urlstrings = NewHash(1, NULL);
107 buf = (char*) malloc (ulen + 1);
108 memcpy(buf, url, ulen);
112 while (!IsEmptyStr(up)) {
114 while ((aptr < eptr) && (*aptr != '\0') && (*aptr != '='))
121 while ((bptr < eptr) && (*bptr != '\0')
122 && (*bptr != '&') && (*bptr != '?') && (*bptr != ' ')) {
126 u = (urlcontent *) malloc(sizeof(urlcontent));
128 keylen = safestrncpy(u->url_key, up, sizeof u->url_key);
130 lprintf(1, "URLkey to long! [%s]", up);
134 Put(WCC->urlstrings, u->url_key, keylen, u, free_url);
136 u->url_data = malloc(len + 2);
137 safestrncpy(u->url_data, aptr, len + 2);
138 u->url_data_size = unescape_input(u->url_data);
139 u->url_data[u->url_data_size] = '\0';
142 #ifdef DEBUG_URLSTRINGS
143 lprintf(9, "%s = [%ld] %s\n", u->url_key, u->url_data_size, u->url_data);
149 * free urlstring memory
153 DeleteHash(&WC->urlstrings);
157 * Diagnostic function to display the contents of all variables
162 struct wcsession *WCC = WC;
169 Cursor = GetNewHashPos ();
170 while (GetNextHashPos(WCC->urlstrings, Cursor, &HKLen, &HKey, &U)) {
172 wprintf("%38s = %s\n", u->url_key, u->url_data);
177 * Return the value of a variable supplied to the current web page (from the url or a form)
180 const char *XBstr(char *key, size_t keylen, size_t *len)
184 if ((WC->urlstrings != NULL) &&
185 GetHash(WC->urlstrings, key, keylen, &U)) {
186 *len = ((urlcontent *)U)->url_data_size;
187 return ((urlcontent *)U)->url_data;
195 const char *XBSTR(char *key, size_t *len)
199 if ((WC->urlstrings != NULL) &&
200 GetHash(WC->urlstrings, key, strlen (key), &U)){
201 *len = ((urlcontent *)U)->url_data_size;
202 return ((urlcontent *)U)->url_data;
211 const char *BSTR(char *key)
215 if ((WC->urlstrings != NULL) &&
216 GetHash(WC->urlstrings, key, strlen (key), &U))
217 return ((urlcontent *)U)->url_data;
222 const char *Bstr(char *key, size_t keylen)
226 if ((WC->urlstrings != NULL) &&
227 GetHash(WC->urlstrings, key, keylen, &U))
228 return ((urlcontent *)U)->url_data;
233 long LBstr(char *key, size_t keylen)
237 if ((WC->urlstrings != NULL) &&
238 GetHash(WC->urlstrings, key, keylen, &U))
239 return atol(((urlcontent *)U)->url_data);
244 long LBSTR(char *key)
248 if ((WC->urlstrings != NULL) &&
249 GetHash(WC->urlstrings, key, strlen(key), &U))
250 return atol(((urlcontent *)U)->url_data);
255 int IBstr(char *key, size_t keylen)
259 if ((WC->urlstrings != NULL) &&
260 GetHash(WC->urlstrings, key, keylen, &U))
261 return atoi(((urlcontent *)U)->url_data);
270 if ((WC->urlstrings != NULL) &&
271 GetHash(WC->urlstrings, key, strlen(key), &U))
272 return atoi(((urlcontent *)U)->url_data);
277 int HaveBstr(char *key, size_t keylen)
281 if ((WC->urlstrings != NULL) &&
282 GetHash(WC->urlstrings, key, keylen, &U))
283 return ((urlcontent *)U)->url_data_size != 0;
288 int HAVEBSTR(char *key)
292 if ((WC->urlstrings != NULL) &&
293 GetHash(WC->urlstrings, key, strlen(key), &U))
294 return ((urlcontent *)U)->url_data_size != 0;
300 int YesBstr(char *key, size_t keylen)
304 if ((WC->urlstrings != NULL) &&
305 GetHash(WC->urlstrings, key, keylen, &U))
306 return strcmp( ((urlcontent *)U)->url_data, "yes") == 0;
311 int YESBSTR(char *key)
315 if ((WC->urlstrings != NULL) &&
316 GetHash(WC->urlstrings, key, strlen(key), &U))
317 return strcmp( ((urlcontent *)U)->url_data, "yes") == 0;
323 * web-printing funcion. uses our vsnprintf wrapper
325 void wprintf(const char *format,...)
330 va_start(arg_ptr, format);
331 vsnprintf(wbuf, sizeof wbuf, format, arg_ptr);
334 client_write(wbuf, strlen(wbuf));
339 * wrap up an HTTP session, closes tags, etc.
341 * print_standard_html_footer should be set to:
342 * 0 to transmit only,
343 * 1 to append the main menu and closing tags,
344 * 2 to append the closing tags only.
346 void wDumpContent(int print_standard_html_footer)
348 if (print_standard_html_footer) {
349 wprintf("</div>\n"); /* end of "text" div */
350 do_template("trailing");
353 /* If we've been saving it all up for one big output burst,
354 * go ahead and do that now.
361 * Copy a string, escaping characters which have meaning in HTML.
363 * target target buffer
364 * strbuf source buffer
365 * nbsp If nonzero, spaces are converted to non-breaking spaces.
366 * nolinebreaks if set, linebreaks are removed from the string.
368 long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks)
370 char *aptr, *bptr, *eptr;
375 eptr = target + tSize - 6; // our biggest unit to put in...
377 while ((bptr < eptr) && !IsEmptyStr(aptr) ){
379 memcpy(bptr, "<", 4);
382 else if (*aptr == '>') {
383 memcpy(bptr, ">", 4);
386 else if (*aptr == '&') {
387 memcpy(bptr, "&", 5);
390 else if (*aptr == '\"') {
391 memcpy(bptr, """, 6);
394 else if (*aptr == '\'') {
395 memcpy(bptr, "'", 5);
398 else if (*aptr == LB) {
402 else if (*aptr == RB) {
406 else if (*aptr == QU) {
410 else if ((*aptr == 32) && (nbsp == 1)) {
411 memcpy(bptr, " ", 6);
414 else if ((*aptr == '\n') && (nolinebreaks)) {
415 *bptr='\0'; /* nothing */
417 else if ((*aptr == '\r') && (nolinebreaks)) {
418 *bptr='\0'; /* nothing */
427 if ((bptr = eptr - 1 ) && !IsEmptyStr(aptr) )
429 return (bptr - target);
432 void escputs1(char *strbuf, int nbsp, int nolinebreaks)
437 if (strbuf == NULL) return;
438 Siz = (3 * strlen(strbuf)) + SIZ ;
440 stresc(buf, Siz, strbuf, nbsp, nolinebreaks);
446 * static wrapper for ecsputs1
448 void escputs(char *strbuf)
450 escputs1(strbuf, 0, 0);
455 * urlescape buffer and print it to the client
457 void urlescputs(char *strbuf)
461 urlesc(outbuf, SIZ, strbuf);
462 wprintf("%s", outbuf);
467 * Copy a string, escaping characters for JavaScript strings.
469 void jsesc(char *target, size_t tlen, char *strbuf)
478 len = strlen (strbuf);
480 tend = target + tlen;
484 while (!IsEmptyStr(sptr) &&
490 else if (*sptr == '>')
492 else if (*sptr == '\'') {
498 else if (*sptr == '"') {
508 else if (*sptr == '&') {
525 * escape and print javascript
527 void jsescputs(char *strbuf)
531 jsesc(outbuf, SIZ, strbuf);
532 wprintf("%s", outbuf);
536 * Copy a string, escaping characters for message text hold
538 void msgesc(char *target, size_t tlen, char *strbuf)
547 len = strlen (strbuf);
549 tend = target + tlen;
553 while (!IsEmptyStr(sptr) &&
559 else if (*sptr == '\r')
561 else if (*sptr == '\'') {
578 * print a string to the client after cleaning it with msgesc() and stresc()
580 void msgescputs1( char *strbuf)
586 if (strbuf == NULL) return;
587 buflen = 3 * strlen(strbuf) + SIZ;
588 outbuf = malloc( buflen);
589 outbuf2 = malloc( buflen);
590 msgesc(outbuf, buflen, strbuf);
591 stresc(outbuf2, buflen, outbuf, 0, 0);
592 wprintf("%s", outbuf2);
598 * print a string to the client after cleaning it with msgesc()
600 void msgescputs(char *strbuf) {
604 if (strbuf == NULL) return;
605 len = (3 * strlen(strbuf)) + SIZ;
606 outbuf = malloc(len);
607 msgesc(outbuf, len, strbuf);
608 wprintf("%s", outbuf);
616 * Output HTTP headers and leading HTML for a page
618 void output_headers( int do_httpheaders, /* 1 = output HTTP headers */
619 int do_htmlhead, /* 1 = output HTML <head> section and <body> opener */
621 int do_room_banner, /* 0=no, 1=yes,
622 * 2 = I'm going to embed my own, so don't open the
623 * <div id="content"> either.
626 int unset_cookies, /* 1 = session is terminating, so unset the cookies */
627 int suppress_check, /* 1 = suppress check for instant messages */
628 int cache /* 1 = allow browser to cache this page */
633 wprintf("HTTP/1.1 200 OK\n");
634 http_datestring(httpnow, sizeof httpnow, time(NULL));
636 if (do_httpheaders) {
637 wprintf("Content-type: text/html; charset=utf-8\r\n"
639 "Connection: close\r\n",
640 PACKAGE_STRING, serv_info.serv_software
645 char httpTomorow[128];
647 http_datestring(httpTomorow, sizeof httpTomorow,
648 time(NULL) + 60 * 60 * 24 * 2);
650 wprintf("Pragma: public\r\n"
651 "Cache-Control: max-age=3600, must-revalidate\r\n"
652 "Last-modified: %s\r\n"
659 wprintf("Pragma: no-cache\r\n"
660 "Cache-Control: no-store\r\n"
665 stuff_to_cookie(cookie, 1024, WC->wc_session, WC->wc_username,
666 WC->wc_password, WC->wc_roomname);
669 wprintf("Set-cookie: webcit=%s; path=/\r\n", unset);
671 wprintf("Set-cookie: webcit=%s; path=/\r\n", cookie);
672 if (server_cookie != NULL) {
673 wprintf("%s\n", server_cookie);
679 if (!access("static.local/webcit.css", R_OK)) {
680 svprintf(HKEY("CSSLOCAL"), WCS_STRING,
681 "<link href=\"static.local/webcit.css\" rel=\"stylesheet\" type=\"text/css\">"
691 /* check for ImportantMessages (these display in a div overlaying the main screen) */
692 if (!IsEmptyStr(WC->ImportantMessage)) {
693 wprintf("<div id=\"important_message\">\n"
694 "<span class=\"imsg\">");
695 escputs(WC->ImportantMessage);
696 wprintf("</span><br />\n"
698 "<script type=\"text/javascript\">\n"
699 " setTimeout('hide_imsg_popup()', 5000); \n"
701 WC->ImportantMessage[0] = 0;
704 if ( (WC->logged_in) && (!unset_cookies) ) {
705 wprintf("<div id=\"iconbar\">");
706 do_selected_iconbar();
707 /** check for instant messages (these display in a new window) */
712 if (do_room_banner == 1) {
713 wprintf("<div id=\"banner\">\n");
714 embed_room_banner(NULL, navbar_default);
719 if (do_room_banner == 1) {
720 wprintf("<div id=\"content\">\n");
726 * Generic function to do an HTTP redirect. Easy and fun.
728 void http_redirect(char *whichpage) {
729 wprintf("HTTP/1.1 302 Moved Temporarily\n");
730 wprintf("Location: %s\r\n", whichpage);
731 wprintf("URI: %s\r\n", whichpage);
732 wprintf("Content-type: text/html; charset=utf-8\r\n\r\n");
733 wprintf("<html><body>");
734 wprintf("Go <a href=\"%s\">here</A>.", whichpage);
735 wprintf("</body></html>\n");
741 * Output a piece of content to the web browser using conformant HTTP and MIME semantics
743 void http_transmit_thing(char *thing, size_t length, const char *content_type,
746 output_headers(0, 0, 0, 0, 0, is_static);
748 wprintf("Content-type: %s\r\n"
750 "Connection: close\r\n",
755 /* If we can send the data out compressed, please do so. */
757 char *compressed_data = NULL;
758 size_t compressed_len;
760 compressed_len = ((length * 101) / 100) + 100;
761 compressed_data = malloc(compressed_len);
763 if (compress_gzip((Bytef *) compressed_data,
766 (uLongf) length, Z_BEST_SPEED) == Z_OK) {
767 wprintf("Content-encoding: gzip\r\n"
768 "Content-length: %ld\r\n"
770 (long) compressed_len
772 client_write(compressed_data, (size_t)compressed_len);
773 free(compressed_data);
779 /* No compression ... just send it out as-is */
780 wprintf("Content-length: %ld\r\n"
784 client_write(thing, (size_t)length);
788 * print menu box like used in the floor view or admin interface.
789 * This function takes pair of strings as va_args,
790 * Title Title string of the box
791 * Class CSS Class for the box
792 * nLines How many string pairs should we print? (URL, UrlText)
793 * ... Pairs of URL Strings and their Names
795 void print_menu_box(char* Title, char *Class, int nLines, ...)
800 svput("BOXTITLE", WCS_STRING, Title);
801 do_template("beginbox");
803 wprintf("<ul class=\"%s\">", Class);
805 va_start(arg_list, nLines);
806 for (i = 0; i < nLines; ++i)
808 wprintf("<li><a href=\"%s\">", va_arg(arg_list, char *));
809 wprintf((char *) va_arg(arg_list, char *));
810 wprintf("</a></li>\n");
814 wprintf("</a></li>\n");
818 do_template("endbox");
823 * dump out static pages from disk
825 void output_static(char *what)
833 const char *content_type;
836 fp = fopen(what, "rb");
838 lprintf(9, "output_static('%s') -- NOT FOUND --\n", what);
839 wprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
840 wprintf("Content-Type: text/plain\r\n");
842 wprintf("Cannot open %s: %s\r\n", what, strerror(errno));
845 content_type = GuessMimeByFilename(what, len);
847 if (fstat(fileno(fp), &statbuf) == -1) {
848 lprintf(9, "output_static('%s') -- FSTAT FAILED --\n", what);
849 wprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
850 wprintf("Content-Type: text/plain\r\n");
852 wprintf("Cannot fstat %s: %s\n", what, strerror(errno));
857 bytes = statbuf.st_size;
858 if ((bigbuffer = malloc(bytes + 2)) == NULL) {
859 lprintf(9, "output_static('%s') -- MALLOC FAILED (%s) --\n", what, strerror(errno));
860 wprintf("HTTP/1.1 500 internal server error\r\n");
861 wprintf("Content-Type: text/plain\r\n");
865 while (count < bytes) {
866 if ((res = fread(bigbuffer + count, 1, bytes - count, fp)) == 0) {
867 lprintf(9, "output_static('%s') -- FREAD FAILED (%s) %zu bytes of %zu --\n", what, strerror(errno), bytes - count, bytes);
868 wprintf("HTTP/1.1 500 internal server error \r\n");
869 wprintf("Content-Type: text/plain\r\n");
878 lprintf(9, "output_static('%s') %s\n", what, content_type);
879 http_transmit_thing(bigbuffer, (size_t)bytes, content_type, 1);
882 if (yesbstr("force_close_session")) {
883 end_webcit_session();
888 * When the browser requests an image file from the Citadel server,
889 * this function is called to transmit it.
894 char *xferbuf = NULL;
896 const char *MimeType;
898 serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
899 serv_getln(buf, sizeof buf);
901 bytes = extract_long(&buf[4], 0);
902 xferbuf = malloc(bytes + 2);
904 /** Read it from the server */
905 read_server_binary(xferbuf, bytes);
907 serv_getln(buf, sizeof buf);
909 MimeType = GuessMimeType (xferbuf, bytes);
910 /** Write it to the browser */
911 if (!IsEmptyStr(MimeType))
913 http_transmit_thing(xferbuf,
920 /* hm... unknown mimetype? fallback to blank gif */
926 * Instead of an ugly 404, send a 1x1 transparent GIF
927 * when there's no such image on the server.
930 snprintf (blank_gif, SIZ, "%s%s", static_dirs[0], "/blank.gif");
931 output_static(blank_gif);
935 * Extract an embedded photo from a vCard for display on the client
937 void display_vcard_photo_img(char *msgnum_as_string)
945 const char *contentType;
947 msgnum = atol(msgnum_as_string);
949 vcard = load_mimepart(msgnum,"1");
950 v = vcard_load(vcard);
952 photosrc = vcard_get_prop(v, "PHOTO", 1,0,0);
953 xferbuf = malloc(strlen(photosrc));
954 if (xferbuf == NULL) {
955 lprintf(5, "xferbuf malloc failed\n");
958 memset(xferbuf, 1, SIZ);
959 decoded = CtdlDecodeBase64(
963 contentType = GuessMimeType(xferbuf, decoded);
964 http_transmit_thing(xferbuf, decoded, contentType, 0);
971 * Generic function to output an arbitrary MIME part from an arbitrary
972 * message number on the server.
974 * msgnum Number of the item on the citadel server
975 * partnum The MIME part to be output
976 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
978 void mimepart(char *msgnum, char *partnum, int force_download)
982 char content_type[256];
983 char *content = NULL;
985 serv_printf("OPNA %s|%s", msgnum, partnum);
986 serv_getln(buf, sizeof buf);
988 bytes = extract_long(&buf[4], 0);
989 content = malloc(bytes + 2);
990 if (force_download) {
991 strcpy(content_type, "application/octet-stream");
994 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
996 output_headers(0, 0, 0, 0, 0, 0);
997 read_server_binary(content, bytes);
999 serv_getln(buf, sizeof buf);
1000 http_transmit_thing(content, bytes, content_type, 0);
1003 wprintf("HTTP/1.1 404 %s\n", &buf[4]);
1004 output_headers(0, 0, 0, 0, 0, 0);
1005 wprintf("Content-Type: text/plain\r\n");
1007 wprintf(_("An error occurred while retrieving this part: %s\n"), &buf[4]);
1014 * Read any MIME part of a message, from the server, into memory.
1016 char *load_mimepart(long msgnum, char *partnum)
1020 char content_type[SIZ];
1023 serv_printf("DLAT %ld|%s", msgnum, partnum);
1024 serv_getln(buf, sizeof buf);
1025 if (buf[0] == '6') {
1026 bytes = extract_long(&buf[4], 0);
1027 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
1029 content = malloc(bytes + 2);
1030 serv_read(content, bytes);
1032 content[bytes] = 0; /* null terminate for good measure */
1043 * Convenience functions to display a page containing only a string
1045 * titlebarcolor color of the titlebar of the frame
1046 * titlebarmsg text to display in the title bar
1047 * messagetext body of the box
1049 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
1051 wprintf("HTTP/1.1 200 OK\n");
1052 output_headers(1, 1, 2, 0, 0, 0);
1053 wprintf("<div id=\"banner\">\n");
1054 wprintf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
1055 wprintf("<span class=\"titlebar\">%s</span>\n", titlebarmsg);
1056 wprintf("</td></tr></table>\n");
1057 wprintf("</div>\n<div id=\"content\">\n");
1058 escputs(messagetext);
1060 wprintf("<hr />\n");
1066 * Display a blank page.
1068 void blank_page(void) {
1069 output_headers(1, 1, 0, 0, 0, 0);
1075 * A template has been requested
1077 void url_do_template(void) {
1078 do_template(bstr("template"));
1084 * Offer to make any page the user's "start page."
1086 void offer_start_page(void) {
1087 wprintf("<a href=\"change_start_page?startpage=");
1088 urlescputs(WC->this_page);
1090 wprintf(_("Make this my start page"));
1093 wprintf("<br/><a href=\"rss?room=");
1094 urlescputs(WC->wc_roomname);
1095 wprintf("\" title=\"RSS 2.0 feed for ");
1096 escputs(WC->wc_roomname);
1097 wprintf("\"><img alt=\"RSS\" border=\"0\" src=\"static/xml_button.gif\"/></a>\n");
1103 * Change the user's start page
1105 void change_start_page(void) {
1107 if (bstr("startpage") == NULL) {
1108 safestrncpy(WC->ImportantMessage,
1109 _("You no longer have a start page selected."),
1110 sizeof WC->ImportantMessage);
1111 display_main_menu();
1115 set_preference("startpage", bstr("startpage"), 1);
1117 output_headers(1, 1, 0, 0, 0, 0);
1118 do_template("newstartpage");
1125 * convenience function to indicate success
1127 void display_success(char *successmessage)
1129 convenience_page("007700", "OK", successmessage);
1134 * Authorization required page
1135 * This is probably temporary and should be revisited
1137 void authorization_required(const char *message)
1139 wprintf("HTTP/1.1 401 Authorization Required\r\n");
1140 wprintf("WWW-Authenticate: Basic realm=\"\"\r\n", serv_info.serv_humannode);
1141 wprintf("Content-Type: text/html\r\n\r\n");
1143 wprintf(_("Authorization Required"));
1144 wprintf("</h1>\r\n");
1145 wprintf(_("The resource you requested requires a valid username and password. "
1146 "You could not be logged in: %s\n"), message);
1151 * This function is called by the MIME parser to handle data uploaded by
1152 * the browser. Form data, uploaded files, and the data from HTTP PUT
1153 * operations (such as those found in GroupDAV) all arrive this way.
1155 * name Name of the item being uploaded
1156 * filename Filename of the item being uploaded
1157 * partnum MIME part identifier (not needed)
1158 * disp MIME content disposition (not needed)
1159 * content The actual data
1160 * cbtype MIME content-type
1161 * cbcharset Character set
1162 * length Content length
1163 * encoding MIME encoding type (not needed)
1164 * userdata Not used here
1166 void upload_handler(char *name, char *filename, char *partnum, char *disp,
1167 void *content, char *cbtype, char *cbcharset,
1168 size_t length, char *encoding, void *userdata)
1171 #ifdef DEBUG_URLSTRINGS
1172 lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n", name, cbtype, length);
1174 if (WC->urlstrings == NULL)
1175 WC->urlstrings = NewHash(1, NULL);
1178 if ( (length > 0) && (IsEmptyStr(cbtype)) ) {
1179 u = (urlcontent *) malloc(sizeof(urlcontent));
1181 safestrncpy(u->url_key, name, sizeof(u->url_key));
1182 u->url_data = malloc(length + 1);
1183 u->url_data_size = length;
1184 memcpy(u->url_data, content, length);
1185 u->url_data[length] = 0;
1186 Put(WC->urlstrings, u->url_key, strlen(u->url_key), u, free_url);
1187 #ifdef DEBUG_URLSTRINGS
1188 lprintf(9, "Key: <%s> len: [%ld] Data: <%s>\n", u->url_key, u->url_data_size, u->url_data);
1192 /** Uploaded files */
1193 if ( (length > 0) && (!IsEmptyStr(cbtype)) ) {
1194 WC->upload = malloc(length);
1195 if (WC->upload != NULL) {
1196 WC->upload_length = length;
1197 safestrncpy(WC->upload_filename, filename,
1198 sizeof(WC->upload_filename));
1199 safestrncpy(WC->upload_content_type, cbtype,
1200 sizeof(WC->upload_content_type));
1201 memcpy(WC->upload, content, length);
1204 lprintf(3, "malloc() failed: %s\n", strerror(errno));
1211 * Convenience functions to wrap around asynchronous ajax responses
1213 void begin_ajax_response(void) {
1214 output_headers(0, 0, 0, 0, 0, 0);
1216 wprintf("Content-type: text/html; charset=UTF-8\r\n"
1218 "Connection: close\r\n"
1219 "Pragma: no-cache\r\n"
1220 "Cache-Control: no-cache\r\n"
1228 * print ajax response footer
1230 void end_ajax_response(void) {
1236 * Wraps a Citadel server command in an AJAX transaction.
1238 void ajax_servcmd(void)
1241 char gcontent[1024];
1245 begin_ajax_response();
1247 serv_printf("%s", bstr("g_cmd"));
1248 serv_getln(buf, sizeof buf);
1249 wprintf("%s\n", buf);
1251 if (buf[0] == '8') {
1252 serv_printf("\n\n000");
1254 if ((buf[0] == '1') || (buf[0] == '8')) {
1255 while (serv_getln(gcontent, sizeof gcontent), strcmp(gcontent, "000")) {
1256 wprintf("%s\n", gcontent);
1260 if (buf[0] == '4') {
1261 text_to_server(bstr("g_input"));
1264 if (buf[0] == '6') {
1265 len = atol(&buf[4]);
1267 serv_read(junk, len);
1270 if (buf[0] == '7') {
1271 len = atol(&buf[4]);
1273 memset(junk, 0, len);
1274 serv_write(junk, len);
1278 end_ajax_response();
1281 * This is kind of an ugly hack, but this is the only place it can go.
1282 * If the command was GEXP, then the instant messenger window must be
1283 * running, so reset the "last_pager_check" watchdog timer so
1284 * that page_popup() doesn't try to open it a second time.
1286 if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) {
1287 WC->last_pager_check = time(NULL);
1293 * Helper function for the asynchronous check to see if we need
1294 * to open the instant messenger window.
1296 void seconds_since_last_gexp(void)
1300 begin_ajax_response();
1301 if ( (time(NULL) - WC->last_pager_check) < 30) {
1306 serv_getln(buf, sizeof buf);
1307 if (buf[3] == '*') {
1314 end_ajax_response();
1321 * Entry point for WebCit transaction
1323 void session_loop(struct httprequest *req)
1331 char request_method[128];
1332 char pathname[1024];
1333 int a, b, nBackDots, nEmpty;
1334 int ContentLength = 0;
1335 char ContentType[512];
1336 char *content = NULL;
1337 char *content_end = NULL;
1338 struct httprequest *hptr;
1339 char browser_host[256];
1340 char user_agent[256];
1346 * We stuff these with the values coming from the client cookies,
1347 * so we can use them to reconnect a timed out session if we have to.
1349 char c_username[SIZ];
1350 char c_password[SIZ];
1351 char c_roomname[SIZ];
1352 char c_httpauth_string[SIZ];
1353 char c_httpauth_user[SIZ];
1354 char c_httpauth_pass[SIZ];
1357 safestrncpy(c_username, "", sizeof c_username);
1358 safestrncpy(c_password, "", sizeof c_password);
1359 safestrncpy(c_roomname, "", sizeof c_roomname);
1360 safestrncpy(c_httpauth_string, "", sizeof c_httpauth_string);
1361 safestrncpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER, sizeof c_httpauth_user);
1362 safestrncpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS, sizeof c_httpauth_pass);
1363 strcpy(browser_host, "");
1365 WC->upload_length = 0;
1370 if (hptr == NULL) return;
1372 safestrncpy(cmd, hptr->line, sizeof cmd);
1374 extract_token(request_method, cmd, 0, ' ', sizeof request_method);
1375 extract_token(pathname, cmd, 1, ' ', sizeof pathname);
1377 /** Figure out the action */
1379 sizes[0] = sizeof action;
1382 index[a] = arg[a-1];
1383 sizes[a] = sizeof arg[a-1];
1385 //// index[9] = &foo; todo
1388 for ( a = 0; a < 9; ++a)
1390 extract_token(index[a], pathname, a + 1, '/', sizes[a]);
1391 if (strstr(index[a], "?")) *strstr(index[a], "?") = 0;
1392 if (strstr(index[a], "&")) *strstr(index[a], "&") = 0;
1393 if (strstr(index[a], " ")) *strstr(index[a], " ") = 0;
1394 if ((index[a][0] == '.') && (index[a][1] == '.'))
1396 if (index[a][0] == '\0')
1400 while (hptr != NULL) {
1401 safestrncpy(buf, hptr->line, sizeof buf);
1402 /* lprintf(9, "HTTP HEADER: %s\n", buf); */
1405 if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
1406 safestrncpy(cookie, &buf[15], sizeof cookie);
1407 cookie_to_stuff(cookie, NULL,
1408 c_username, sizeof c_username,
1409 c_password, sizeof c_password,
1410 c_roomname, sizeof c_roomname);
1412 else if (!strncasecmp(buf, "Authorization: Basic ", 21)) {
1413 CtdlDecodeBase64(c_httpauth_string, &buf[21], strlen(&buf[21]));
1414 extract_token(c_httpauth_user, c_httpauth_string, 0, ':', sizeof c_httpauth_user);
1415 extract_token(c_httpauth_pass, c_httpauth_string, 1, ':', sizeof c_httpauth_pass);
1417 else if (!strncasecmp(buf, "Content-length: ", 16)) {
1418 ContentLength = atoi(&buf[16]);
1420 else if (!strncasecmp(buf, "Content-type: ", 14)) {
1421 safestrncpy(ContentType, &buf[14], sizeof ContentType);
1423 else if (!strncasecmp(buf, "User-agent: ", 12)) {
1424 safestrncpy(user_agent, &buf[12], sizeof user_agent);
1426 else if (!strncasecmp(buf, "X-Forwarded-Host: ", 18)) {
1428 safestrncpy(WC->http_host, &buf[18], sizeof WC->http_host);
1431 else if (!strncasecmp(buf, "Host: ", 6)) {
1432 if (IsEmptyStr(WC->http_host)) {
1433 safestrncpy(WC->http_host, &buf[6], sizeof WC->http_host);
1436 else if (!strncasecmp(buf, "X-Forwarded-For: ", 17)) {
1437 safestrncpy(browser_host, &buf[17], sizeof browser_host);
1438 while (num_tokens(browser_host, ',') > 1) {
1439 remove_token(browser_host, 0, ',');
1441 striplt(browser_host);
1443 /** Only WAP gateways explicitly name this content-type */
1444 else if (strstr(buf, "text/vnd.wap.wml")) {
1445 /* since we don't have wap pages we disable this.
1451 if (ContentLength > 0) {
1454 BuffSize = ContentLength + SIZ;
1455 content = malloc(BuffSize);
1456 memset(content, 0, BuffSize);
1457 snprintf(content, BuffSize, "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[body_start], ContentLength);
1465 if (!strncasecmp(ContentType, "application/x-www-form-urlencoded", 33)) {
1466 addurls(&content[body_start], ContentLength);
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], len - a);
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 (!strcasecmp(action, "finalize_openid_login")) {
1724 finalize_openid_login();
1725 } else if (!strcasecmp(action, "openid_manual_create")) {
1726 openid_manual_create();
1727 } else if (!WC->logged_in) {
1728 display_login(NULL);
1732 * Various commands...
1737 WebcitHandler *Handler;
1739 GetHash(HandlerHash, action, strlen(action) /* TODO*/, &vHandler),
1740 Handler = (WebcitHandler*) vHandler;
1741 if (Handler != NULL) {
1742 if (Handler->IsAjax)
1743 begin_ajax_response();
1745 if (Handler->IsAjax)
1746 end_ajax_response();
1750 else if (!strcasecmp(action, "do_welcome")) {
1752 } else if (!strcasecmp(action, "blank")) {
1754 } else if (!strcasecmp(action, "do_template")) {
1756 } else if (!strcasecmp(action, "display_aide_menu")) {
1757 display_aide_menu();
1758 } else if (!strcasecmp(action, "server_shutdown")) {
1760 } else if (!strcasecmp(action, "display_main_menu")) {
1761 display_main_menu();
1762 } else if (!strcasecmp(action, "who")) {
1764 } else if (!strcasecmp(action, "sslg")) {
1765 seconds_since_last_gexp();
1766 } else if (!strcasecmp(action, "who_inner_html")) {
1767 begin_ajax_response();
1769 end_ajax_response();
1770 } else if (!strcasecmp(action, "wholist_section")) {
1771 begin_ajax_response();
1773 end_ajax_response();
1774 } else if (!strcasecmp(action, "new_messages_html")) {
1775 begin_ajax_response();
1776 new_messages_section();
1777 end_ajax_response();
1778 } else if (!strcasecmp(action, "tasks_inner_html")) {
1779 begin_ajax_response();
1781 end_ajax_response();
1782 } else if (!strcasecmp(action, "calendar_inner_html")) {
1783 begin_ajax_response();
1785 end_ajax_response();
1786 } else if (!strcasecmp(action, "mini_calendar")) {
1787 begin_ajax_response();
1788 ajax_mini_calendar();
1789 end_ajax_response();
1790 } else if (!strcasecmp(action, "iconbar_ajax_menu")) {
1791 begin_ajax_response();
1793 end_ajax_response();
1794 } else if (!strcasecmp(action, "iconbar_ajax_rooms")) {
1795 begin_ajax_response();
1796 do_iconbar_roomlist();
1797 end_ajax_response();
1798 } else if (!strcasecmp(action, "knrooms")) {
1800 } else if (!strcasecmp(action, "gotonext")) {
1803 } else if (!strcasecmp(action, "skip")) {
1805 } else if (!strcasecmp(action, "ungoto")) {
1807 } else if (!strcasecmp(action, "dotgoto")) {
1808 if (WC->wc_view != VIEW_MAILBOX) { /* dotgoto acts like dotskip when we're in a mailbox view */
1811 smart_goto(bstr("room"));
1812 } else if (!strcasecmp(action, "dotskip")) {
1813 smart_goto(bstr("room"));
1814 } else if (!strcasecmp(action, "termquit")) {
1816 } else if (!strcasecmp(action, "readnew")) {
1817 readloop("readnew");
1818 } else if (!strcasecmp(action, "readold")) {
1819 readloop("readold");
1820 } else if (!strcasecmp(action, "readfwd")) {
1821 readloop("readfwd");
1822 } else if (!strcasecmp(action, "headers")) {
1823 readloop("headers");
1824 } else if (!strcasecmp(action, "do_search")) {
1825 readloop("do_search");
1826 } else if (!strcasecmp(action, "msg")) {
1827 embed_message(index[1]);
1828 } else if (!strcasecmp(action, "printmsg")) {
1829 print_message(index[1]);
1830 } else if (!strcasecmp(action, "msgheaders")) {
1831 display_headers(index[1]);
1832 } else if (!strcasecmp(action, "vcardphoto")) {
1833 display_vcard_photo_img(index[1]);
1834 } else if (!strcasecmp(action, "wiki")) {
1835 display_wiki_page();
1836 } else if (!strcasecmp(action, "display_enter")) {
1838 } else if (!strcasecmp(action, "post")) {
1840 } else if (!strcasecmp(action, "move_msg")) {
1842 } else if (!strcasecmp(action, "delete_msg")) {
1844 } else if (!strcasecmp(action, "userlist")) {
1846 } else if (!strcasecmp(action, "showuser")) {
1848 } else if (!strcasecmp(action, "display_page")) {
1850 } else if (!strcasecmp(action, "page_user")) {
1852 } else if (!strcasecmp(action, "chat")) {
1854 } else if (!strcasecmp(action, "display_private")) {
1855 display_private("", 0);
1856 } else if (!strcasecmp(action, "goto_private")) {
1858 } else if (!strcasecmp(action, "zapped_list")) {
1860 } else if (!strcasecmp(action, "display_zap")) {
1862 } else if (!strcasecmp(action, "zap")) {
1864 } else if (!strcasecmp(action, "display_entroom")) {
1866 } else if (!strcasecmp(action, "entroom")) {
1868 } else if (!strcasecmp(action, "display_whok")) {
1870 } else if (!strcasecmp(action, "do_invt_kick")) {
1872 } else if (!strcasecmp(action, "display_editroom")) {
1874 } else if (!strcasecmp(action, "netedit")) {
1876 } else if (!strcasecmp(action, "editroom")) {
1878 } else if (!strcasecmp(action, "display_editinfo")) {
1879 display_edit(_("Room info"), "EINF 0", "RINF", "editinfo", 1);
1880 } else if (!strcasecmp(action, "editinfo")) {
1881 save_edit(_("Room info"), "EINF 1", 1);
1882 } else if (!strcasecmp(action, "display_editbio")) {
1883 snprintf(buf, SIZ, "RBIO %s", WC->wc_fullname);
1884 display_edit(_("Your bio"), "NOOP", buf, "editbio", 3);
1885 } else if (!strcasecmp(action, "editbio")) {
1886 save_edit(_("Your bio"), "EBIO", 0);
1887 } else if (!strcasecmp(action, "confirm_move_msg")) {
1889 } else if (!strcasecmp(action, "delete_room")) {
1891 } else if (!strcasecmp(action, "validate")) {
1893 /* The users photo display / upload facility */
1894 } else if (!strcasecmp(action, "display_editpic")) {
1895 display_graphics_upload(_("your photo"),
1898 } else if (!strcasecmp(action, "editpic")) {
1899 do_graphics_upload("_userpic_");
1900 /* room picture dispay / upload facility */
1901 } else if (!strcasecmp(action, "display_editroompic")) {
1902 display_graphics_upload(_("the icon for this room"),
1905 } else if (!strcasecmp(action, "editroompic")) {
1906 do_graphics_upload("_roompic_");
1907 /* the greetingpage hello pic */
1908 } else if (!strcasecmp(action, "display_edithello")) {
1909 display_graphics_upload(_("the Greetingpicture for the login prompt"),
1912 } else if (!strcasecmp(action, "edithellopic")) {
1913 do_graphics_upload("hello");
1914 /* the logoff banner */
1915 } else if (!strcasecmp(action, "display_editgoodbyepic")) {
1916 display_graphics_upload(_("the Logoff banner picture"),
1917 "UIMG 0|%s|goodbuye",
1919 } else if (!strcasecmp(action, "editgoodbuyepic")) {
1920 do_graphics_upload("UIMG 1|%s|goodbuye");
1922 } else if (!strcasecmp(action, "delete_floor")) {
1924 } else if (!strcasecmp(action, "rename_floor")) {
1926 } else if (!strcasecmp(action, "create_floor")) {
1928 } else if (!strcasecmp(action, "display_editfloorpic")) {
1929 snprintf(buf, SIZ, "UIMG 0|_floorpic_|%s",
1930 bstr("which_floor"));
1931 display_graphics_upload(_("the icon for this floor"),
1934 } else if (!strcasecmp(action, "editfloorpic")) {
1935 snprintf(buf, SIZ, "UIMG 1|_floorpic_|%s",
1936 bstr("which_floor"));
1937 do_graphics_upload(buf);
1938 } else if (!strcasecmp(action, "display_reg")) {
1940 } else if (!strcasecmp(action, "display_changepw")) {
1942 } else if (!strcasecmp(action, "changepw")) {
1944 } else if (!strcasecmp(action, "display_edit_node")) {
1945 display_edit_node();
1946 } else if (!strcasecmp(action, "edit_node")) {
1948 } else if (!strcasecmp(action, "display_netconf")) {
1950 } else if (!strcasecmp(action, "display_confirm_delete_node")) {
1951 display_confirm_delete_node();
1952 } else if (!strcasecmp(action, "delete_node")) {
1954 } else if (!strcasecmp(action, "display_add_node")) {
1956 } else if (!strcasecmp(action, "terminate_session")) {
1958 terminate_session();
1959 } else if (!strcasecmp(action, "edit_me")) {
1961 } else if (!strcasecmp(action, "display_siteconfig")) {
1962 display_siteconfig();
1963 } else if (!strcasecmp(action, "chat_recv")) {
1965 } else if (!strcasecmp(action, "chat_send")) {
1967 } else if (!strcasecmp(action, "siteconfig")) {
1969 } else if (!strcasecmp(action, "display_generic")) {
1971 } else if (!strcasecmp(action, "do_generic")) {
1973 } else if (!strcasecmp(action, "ajax_servcmd")) {
1975 } else if (!strcasecmp(action, "display_menubar")) {
1977 } else if (!strcasecmp(action, "mimepart")) {
1978 mimepart(index[1], index[2], 0);
1979 } else if (!strcasecmp(action, "mimepart_download")) {
1980 mimepart(index[1], index[2], 1);
1981 } else if (!strcasecmp(action, "edit_vcard")) {
1983 } else if (!strcasecmp(action, "submit_vcard")) {
1985 } else if (!strcasecmp(action, "select_user_to_edit")) {
1986 select_user_to_edit(NULL, NULL);
1987 } else if (!strcasecmp(action, "display_edituser")) {
1988 display_edituser(NULL, 0);
1989 } else if (!strcasecmp(action, "edituser")) {
1991 } else if (!strcasecmp(action, "create_user")) {
1993 } else if (!strcasecmp(action, "changeview")) {
1995 } else if (!strcasecmp(action, "change_start_page")) {
1996 change_start_page();
1997 } else if (!strcasecmp(action, "display_floorconfig")) {
1998 display_floorconfig(NULL);
1999 } else if (!strcasecmp(action, "toggle_self_service")) {
2000 toggle_self_service();
2001 } else if (!strcasecmp(action, "display_edit_task")) {
2002 display_edit_task();
2003 } else if (!strcasecmp(action, "save_task")) {
2005 } else if (!strcasecmp(action, "display_edit_event")) {
2006 display_edit_event();
2007 } else if (!strcasecmp(action, "save_event")) {
2009 } else if (!strcasecmp(action, "respond_to_request")) {
2010 respond_to_request();
2011 } else if (!strcasecmp(action, "handle_rsvp")) {
2013 } else if (!strcasecmp(action, "summary")) {
2015 } else if (!strcasecmp(action, "summary_inner_div")) {
2016 begin_ajax_response();
2017 summary_inner_div();
2018 end_ajax_response();
2019 } else if (!strcasecmp(action, "display_customize_iconbar")) {
2020 display_customize_iconbar();
2021 } else if (!strcasecmp(action, "commit_iconbar")) {
2023 } else if (!strcasecmp(action, "set_room_policy")) {
2025 } else if (!strcasecmp(action, "display_inetconf")) {
2027 } else if (!strcasecmp(action, "save_inetconf")) {
2029 } else if (!strcasecmp(action, "display_smtpqueue")) {
2030 display_smtpqueue();
2031 } else if (!strcasecmp(action, "display_smtpqueue_inner_div")) {
2032 display_smtpqueue_inner_div();
2033 } else if (!strcasecmp(action, "display_sieve")) {
2035 } else if (!strcasecmp(action, "save_sieve")) {
2037 } else if (!strcasecmp(action, "display_pushemail")) {
2038 display_pushemail();
2039 } else if (!strcasecmp(action, "save_pushemail")) {
2041 } else if (!strcasecmp(action, "display_add_remove_scripts")) {
2042 display_add_remove_scripts(NULL);
2043 } else if (!strcasecmp(action, "create_script")) {
2045 } else if (!strcasecmp(action, "delete_script")) {
2047 } else if (!strcasecmp(action, "setup_wizard")) {
2049 } else if (!strcasecmp(action, "display_preferences")) {
2050 display_preferences();
2051 } else if (!strcasecmp(action, "set_preferences")) {
2053 } else if (!strcasecmp(action, "recp_autocomplete")) {
2054 recp_autocomplete(bstr("recp"));
2055 } else if (!strcasecmp(action, "cc_autocomplete")) {
2056 recp_autocomplete(bstr("cc"));
2057 } else if (!strcasecmp(action, "bcc_autocomplete")) {
2058 recp_autocomplete(bstr("bcc"));
2059 } else if (!strcasecmp(action, "display_address_book_middle_div")) {
2060 display_address_book_middle_div();
2061 } else if (!strcasecmp(action, "display_address_book_inner_div")) {
2062 display_address_book_inner_div();
2063 } else if (!strcasecmp(action, "set_floordiv_expanded")) {
2064 set_floordiv_expanded(index[1]);
2065 } else if (!strcasecmp(action, "diagnostics")) {
2066 output_headers(1, 1, 1, 0, 0, 0);
2067 wprintf("Session: %d<hr />\n", WC->wc_session);
2068 wprintf("Command: <br /><PRE>\n");
2070 wprintf("</PRE><hr />\n");
2071 wprintf("Variables: <br /><PRE>\n");
2073 wprintf("</PRE><hr />\n");
2075 } else if (!strcasecmp(action, "add_new_note")) {
2077 } else if (!strcasecmp(action, "ajax_update_note")) {
2079 } else if (!strcasecmp(action, "display_room_directory")) {
2080 display_room_directory();
2081 } else if (!strcasecmp(action, "display_pictureview")) {
2082 display_pictureview();
2083 } else if (!strcasecmp(action, "download_file")) {
2084 download_file(index[1]);
2085 } else if (!strcasecmp(action, "upload_file")) {
2087 } else if (!strcasecmp(action, "display_openids")) {
2089 } else if (!strcasecmp(action, "openid_attach")) {
2091 } else if (!strcasecmp(action, "openid_detach")) {
2095 /* When all else fais, display the main menu. */
2097 display_main_menu();
2102 if (content != NULL) {
2107 if (WC->upload_length > 0) {
2109 WC->upload_length = 0;
2114 * Replacement for sleep() that uses select() in order to avoid SIGALRM
2116 void sleeeeeeeeeep(int seconds)
2120 tv.tv_sec = seconds;
2122 select(0, NULL, NULL, NULL, &tv);