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.
9 #define SHOW_ME_VAPPEND_PRINTF
12 #include "webserver.h"
18 * String to unset the cookie.
19 * Any date "in the past" will work, so I chose my birthday, right down to
20 * the exact minute. :)
22 static char *unset = "; expires=28-May-1971 18:10:00 GMT";
24 HashList *HandlerHash = NULL;
26 void WebcitAddUrlHandler(const char * UrlString,
31 WebcitHandler *NewHandler;
33 if (HandlerHash == NULL)
34 HandlerHash = NewHash(1, NULL);
36 NewHandler = (WebcitHandler*) malloc(sizeof(WebcitHandler));
38 NewHandler->Flags = Flags;
39 Put(HandlerHash, UrlString, UrlSLen, NewHandler, NULL);
43 * remove escaped strings from i.e. the url string (like %20 for blanks)
45 long unescape_input(char *buf)
54 while ((buflen > 0) && (isspace(buf[buflen - 1]))){
64 /* don't let % chars through, rather truncate the input. */
74 sscanf(hex, "%02x", &b);
78 memmove(&buf[a + 1], &buf[a + 3], len);
88 void free_url(void *U)
90 urlcontent *u = (urlcontent*) U;
91 FreeStrBuf(&u->url_data);
96 * Extract variables from the URL.
98 void ParseURLParams(StrBuf *url)
100 const char *aptr, *bptr, *eptr, *up;
103 struct wcsession *WCC = WC;
105 if (WCC->urlstrings == NULL)
106 WCC->urlstrings = NewHash(1, NULL);
107 eptr = ChrPtr(url) + StrLength(url);
109 while ((up < eptr) && (!IsEmptyStr(up))) {
111 while ((aptr < eptr) && (*aptr != '\0') && (*aptr != '='))
118 while ((bptr < eptr) && (*bptr != '\0')
119 && (*bptr != '&') && (*bptr != '?') && (*bptr != ' ')) {
122 keylen = aptr - up - 1; /* -1 -> '=' */
123 if(keylen > sizeof(u->url_key)) {
124 lprintf(1, "URLkey to long! [%s]", up);
128 u = (urlcontent *) malloc(sizeof(urlcontent));
129 memcpy(u->url_key, up, keylen);
130 u->url_key[keylen] = '\0';
132 lprintf(1, "URLkey to long! [%s]", up);
137 Put(WCC->urlstrings, u->url_key, keylen, u, free_url);
139 u->url_data = NewStrBufPlain(aptr, len);
140 StrBufUnescape(u->url_data, 1);
144 #ifdef DEBUG_URLSTRINGS
145 lprintf(9, "%s = [%ld] %s\n",
147 StrLength(u->url_data),
148 ChrPtr(u->url_data));
154 * free urlstring memory
158 DeleteHash(&WC->urlstrings);
162 * Diagnostic function to display the contents of all variables
167 struct wcsession *WCC = WC;
174 Cursor = GetNewHashPos ();
175 while (GetNextHashPos(WCC->urlstrings, Cursor, &HKLen, &HKey, &U)) {
177 wprintf("%38s = %s\n", u->url_key, ChrPtr(u->url_data));
182 * Return the value of a variable supplied to the current web page (from the url or a form)
185 const char *XBstr(const char *key, size_t keylen, size_t *len)
189 if ((WC->urlstrings != NULL) &&
190 GetHash(WC->urlstrings, key, keylen, &U)) {
191 *len = StrLength(((urlcontent *)U)->url_data);
192 return ChrPtr(((urlcontent *)U)->url_data);
200 const char *XBSTR(const char *key, size_t *len)
204 if ((WC->urlstrings != NULL) &&
205 GetHash(WC->urlstrings, key, strlen (key), &U)){
206 *len = StrLength(((urlcontent *)U)->url_data);
207 return ChrPtr(((urlcontent *)U)->url_data);
216 const char *BSTR(const char *key)
220 if ((WC->urlstrings != NULL) &&
221 GetHash(WC->urlstrings, key, strlen (key), &U))
222 return ChrPtr(((urlcontent *)U)->url_data);
227 const char *Bstr(const char *key, size_t keylen)
231 if ((WC->urlstrings != NULL) &&
232 GetHash(WC->urlstrings, key, keylen, &U))
233 return ChrPtr(((urlcontent *)U)->url_data);
238 const StrBuf *SBSTR(const char *key)
242 if ((WC->urlstrings != NULL) &&
243 GetHash(WC->urlstrings, key, strlen (key), &U))
244 return ((urlcontent *)U)->url_data;
249 const StrBuf *SBstr(const char *key, size_t keylen)
253 if ((WC->urlstrings != NULL) &&
254 GetHash(WC->urlstrings, key, keylen, &U))
255 return ((urlcontent *)U)->url_data;
260 long LBstr(const char *key, size_t keylen)
264 if ((WC->urlstrings != NULL) &&
265 GetHash(WC->urlstrings, key, keylen, &U))
266 return StrTol(((urlcontent *)U)->url_data);
271 long LBSTR(const char *key)
275 if ((WC->urlstrings != NULL) &&
276 GetHash(WC->urlstrings, key, strlen(key), &U))
277 return StrTol(((urlcontent *)U)->url_data);
282 int IBstr(const char *key, size_t keylen)
286 if ((WC->urlstrings != NULL) &&
287 GetHash(WC->urlstrings, key, keylen, &U))
288 return StrTol(((urlcontent *)U)->url_data);
293 int IBSTR(const char *key)
297 if ((WC->urlstrings != NULL) &&
298 GetHash(WC->urlstrings, key, strlen(key), &U))
299 return StrToi(((urlcontent *)U)->url_data);
304 int HaveBstr(const char *key, size_t keylen)
308 if ((WC->urlstrings != NULL) &&
309 GetHash(WC->urlstrings, key, keylen, &U))
310 return (StrLength(((urlcontent *)U)->url_data) != 0);
315 int HAVEBSTR(const char *key)
319 if ((WC->urlstrings != NULL) &&
320 GetHash(WC->urlstrings, key, strlen(key), &U))
321 return (StrLength(((urlcontent *)U)->url_data) != 0);
327 int YesBstr(const char *key, size_t keylen)
331 if ((WC->urlstrings != NULL) &&
332 GetHash(WC->urlstrings, key, keylen, &U))
333 return strcmp( ChrPtr(((urlcontent *)U)->url_data), "yes") == 0;
338 int YESBSTR(const char *key)
342 if ((WC->urlstrings != NULL) &&
343 GetHash(WC->urlstrings, key, strlen(key), &U))
344 return strcmp( ChrPtr(((urlcontent *)U)->url_data), "yes") == 0;
350 * web-printing funcion. uses our vsnprintf wrapper
352 void wprintf(const char *format,...)
354 struct wcsession *WCC = WC;
357 if (WCC->WBuf == NULL)
358 WCC->WBuf = NewStrBuf();
360 va_start(arg_ptr, format);
361 StrBufVAppendPrintf(WCC->WBuf, format, arg_ptr);
364 /// if (StrLength(WCC-WBuf) > 2048)
365 ///client_write(wbuf, strlen(wbuf));
369 * http-header-printing funcion. uses our vsnprintf wrapper
371 void hprintf(const char *format,...)
373 struct wcsession *WCC = WC;
376 va_start(arg_ptr, format);
377 StrBufVAppendPrintf(WCC->HBuf, format, arg_ptr);
380 /// if (StrLength(WCC-WBuf) > 2048)
381 ///client_write(wbuf, strlen(wbuf));
385 void put_trailing_javascript(void) {
386 wprintf("%s", ChrPtr(WC->trailing_javascript));
390 * wrap up an HTTP session, closes tags, etc.
392 * print_standard_html_footer should be set to:
393 * 0 - to transmit only,
394 * nonzero - to append the closing tags
396 void wDumpContent(int print_standard_html_footer)
398 if (print_standard_html_footer) {
399 wprintf("</div> <!-- end of 'content' div -->\n");
400 svcallback("TRAILING_JAVASCRIPT", put_trailing_javascript);
401 do_template("trailing", NULL);
404 /* If we've been saving it all up for one big output burst,
405 * go ahead and do that now.
413 * Copy a string, escaping characters which have meaning in HTML.
415 * target target buffer
416 * strbuf source buffer
417 * nbsp If nonzero, spaces are converted to non-breaking spaces.
418 * nolinebreaks if set, linebreaks are removed from the string.
420 long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks)
422 char *aptr, *bptr, *eptr;
427 eptr = target + tSize - 6; // our biggest unit to put in...
430 while ((bptr < eptr) && !IsEmptyStr(aptr) ){
432 memcpy(bptr, "<", 4);
435 else if (*aptr == '>') {
436 memcpy(bptr, ">", 4);
439 else if (*aptr == '&') {
440 memcpy(bptr, "&", 5);
443 else if (*aptr == '\"') {
444 memcpy(bptr, """, 6);
447 else if (*aptr == '\'') {
448 memcpy(bptr, "'", 5);
451 else if (*aptr == LB) {
455 else if (*aptr == RB) {
459 else if (*aptr == QU) {
463 else if ((*aptr == 32) && (nbsp == 1)) {
464 memcpy(bptr, " ", 6);
467 else if ((*aptr == '\n') && (nolinebreaks)) {
468 *bptr='\0'; /* nothing */
470 else if ((*aptr == '\r') && (nolinebreaks)) {
471 *bptr='\0'; /* nothing */
480 if ((bptr = eptr - 1 ) && !IsEmptyStr(aptr) )
482 return (bptr - target);
486 void escputs1(char *strbuf, int nbsp, int nolinebreaks)
488 StrEscAppend(WC->WBuf, NULL, strbuf, nbsp, nolinebreaks);
491 void StrEscputs1(const StrBuf *strbuf, int nbsp, int nolinebreaks)
493 StrEscAppend(WC->WBuf, strbuf, NULL, nbsp, nolinebreaks);
497 * static wrapper for ecsputs1
499 void escputs(char *strbuf)
501 escputs1(strbuf, 0, 0);
506 * static wrapper for ecsputs1
508 void StrEscPuts(const StrBuf *strbuf)
510 StrEscputs1(strbuf, 0, 0);
515 * urlescape buffer and print it to the client
517 void urlescputs(const char *strbuf)
519 StrBufUrlescAppend(WC->WBuf, NULL, strbuf);
523 * urlescape buffer and print it to the client
525 void UrlescPutStrBuf(const StrBuf *strbuf)
527 StrBufUrlescAppend(WC->WBuf, strbuf, NULL);
531 * urlescape buffer and print it as header
533 void hurlescputs(const char *strbuf)
535 StrBufUrlescAppend(WC->HBuf, NULL, strbuf);
540 * Copy a string, escaping characters for JavaScript strings.
542 void jsesc(char *target, size_t tlen, char *strbuf)
551 len = strlen (strbuf);
553 tend = target + tlen;
557 while (!IsEmptyStr(sptr) &&
563 else if (*sptr == '>')
565 else if (*sptr == '\'') {
571 else if (*sptr == '"') {
581 else if (*sptr == '&') {
598 * escape and print javascript
600 void jsescputs(char *strbuf)
604 jsesc(outbuf, SIZ, strbuf);
605 wprintf("%s", outbuf);
609 * print a string to the client after cleaning it with msgesc() and stresc()
611 void msgescputs1( char *strbuf)
615 if ((strbuf == NULL) || IsEmptyStr(strbuf))
617 OutBuf = NewStrBuf();
618 StrMsgEscAppend(OutBuf, NULL, strbuf);
619 StrEscAppend(WC->WBuf, OutBuf, NULL, 0, 0);
624 * print a string to the client after cleaning it with msgesc()
626 void msgescputs(char *strbuf) {
627 if ((strbuf != NULL) && !IsEmptyStr(strbuf))
628 StrMsgEscAppend(WC->WBuf, NULL, strbuf);
635 * Output HTTP headers and leading HTML for a page
637 void output_headers( int do_httpheaders, /* 1 = output HTTP headers */
638 int do_htmlhead, /* 1 = output HTML <head> section and <body> opener */
640 int do_room_banner, /* 0=no, 1=yes,
641 * 2 = I'm going to embed my own, so don't open the
642 * <div id="content"> either.
645 int unset_cookies, /* 1 = session is terminating, so unset the cookies */
646 int suppress_check, /* 1 = suppress check for instant messages */
647 int cache /* 1 = allow browser to cache this page */
652 hprintf("HTTP/1.1 200 OK\n");
653 http_datestring(httpnow, sizeof httpnow, time(NULL));
655 if (do_httpheaders) {
656 hprintf("Content-type: text/html; charset=utf-8\r\n"
658 "Connection: close\r\n",
659 PACKAGE_STRING, serv_info.serv_software
664 char httpTomorow[128];
666 http_datestring(httpTomorow, sizeof httpTomorow,
667 time(NULL) + 60 * 60 * 24 * 2);
669 hprintf("Pragma: public\r\n"
670 "Cache-Control: max-age=3600, must-revalidate\r\n"
671 "Last-modified: %s\r\n"
678 hprintf("Pragma: no-cache\r\n"
679 "Cache-Control: no-store\r\n"
684 stuff_to_cookie(cookie, 1024, WC->wc_session, WC->wc_username,
685 WC->wc_password, WC->wc_roomname);
688 hprintf("Set-cookie: webcit=%s; path=/\r\n", unset);
690 hprintf("Set-cookie: webcit=%s; path=/\r\n", cookie);
691 if (server_cookie != NULL) {
692 hprintf("%s\n", server_cookie);
698 do_template("head", NULL);
705 /* check for ImportantMessages (these display in a div overlaying the main screen) */
706 if (!IsEmptyStr(WC->ImportantMessage)) {
707 wprintf("<div id=\"important_message\">\n"
708 "<span class=\"imsg\">");
709 escputs(WC->ImportantMessage);
710 wprintf("</span><br />\n"
712 "<script type=\"text/javascript\">\n"
713 " setTimeout('hide_imsg_popup()', 5000); \n"
715 WC->ImportantMessage[0] = 0;
718 if ( (WC->logged_in) && (!unset_cookies) ) {
719 wprintf("<div id=\"iconbar\">");
720 do_selected_iconbar();
721 /** check for instant messages (these display in a new window) */
726 if (do_room_banner == 1) {
727 wprintf("<div id=\"banner\">\n");
728 embed_room_banner(NULL, navbar_default);
733 if (do_room_banner == 1) {
734 wprintf("<div id=\"content\">\n");
740 * Generic function to do an HTTP redirect. Easy and fun.
742 void http_redirect(const char *whichpage) {
743 hprintf("HTTP/1.1 302 Moved Temporarily\n");
744 hprintf("Location: %s\r\n", whichpage);
745 hprintf("URI: %s\r\n", whichpage);
746 hprintf("Content-type: text/html; charset=utf-8\r\n");
747 wprintf("<html><body>");
748 wprintf("Go <a href=\"%s\">here</A>.", whichpage);
749 wprintf("</body></html>\n");
756 * Output a piece of content to the web browser using conformant HTTP and MIME semantics
758 void http_transmit_thing(const char *content_type,
762 lprintf(9, "http_transmit_thing(%s)%s\n",
764 (is_static ? " (static)" : "")
767 output_headers(0, 0, 0, 0, 0, is_static);
769 hprintf("Content-type: %s\r\n"
771 "Connection: close\r\n",
779 * print menu box like used in the floor view or admin interface.
780 * This function takes pair of strings as va_args,
781 * Title Title string of the box
782 * Class CSS Class for the box
783 * nLines How many string pairs should we print? (URL, UrlText)
784 * ... Pairs of URL Strings and their Names
786 void print_menu_box(char* Title, char *Class, int nLines, ...)
791 svput("BOXTITLE", WCS_STRING, Title);
792 do_template("beginbox", NULL);
794 wprintf("<ul class=\"%s\">", Class);
796 va_start(arg_list, nLines);
797 for (i = 0; i < nLines; ++i)
799 wprintf("<li><a href=\"%s\">", va_arg(arg_list, char *));
800 wprintf((char *) va_arg(arg_list, char *));
801 wprintf("</a></li>\n");
805 wprintf("</a></li>\n");
809 do_template("endbox", NULL);
814 * dump out static pages from disk
816 void output_static(char *what)
822 const char *content_type;
826 fd = open(what, O_RDONLY);
828 lprintf(9, "output_static('%s') -- NOT FOUND --\n", what);
829 hprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
830 hprintf("Content-Type: text/plain\r\n");
831 wprintf("Cannot open %s: %s\r\n", what, strerror(errno));
835 content_type = GuessMimeByFilename(what, len);
837 if (fstat(fd, &statbuf) == -1) {
838 lprintf(9, "output_static('%s') -- FSTAT FAILED --\n", what);
839 hprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
840 hprintf("Content-Type: text/plain\r\n");
841 wprintf("Cannot fstat %s: %s\n", what, strerror(errno));
847 bytes = statbuf.st_size;
849 if (StrBufReadBLOB(WC->WBuf, &fd, 1, bytes, &Err) < 0)
851 if (fd > 0) close(fd);
852 lprintf(9, "output_static('%s') -- FREAD FAILED (%s) --\n", what, strerror(errno));
853 hprintf("HTTP/1.1 500 internal server error \r\n");
854 hprintf("Content-Type: text/plain\r\n");
862 lprintf(9, "output_static('%s') %s\n", what, content_type);
864 http_transmit_thing(content_type, 1);
866 if (yesbstr("force_close_session")) {
867 end_webcit_session();
872 * When the browser requests an image file from the Citadel server,
873 * this function is called to transmit it.
877 struct wcsession *WCC = WC;
880 const char *MimeType;
882 serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
883 serv_getln(buf, sizeof buf);
885 bytes = extract_long(&buf[4], 0);
887 /** Read it from the server */
889 if (read_server_binary(WCC->WBuf, bytes) > 0) {
891 serv_getln(buf, sizeof buf);
893 MimeType = GuessMimeType (ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
894 /** Write it to the browser */
895 if (!IsEmptyStr(MimeType))
897 http_transmit_thing(MimeType, 0);
901 /* hm... unknown mimetype? fallback to blank gif */
906 * Instead of an ugly 404, send a 1x1 transparent GIF
907 * when there's no such image on the server.
910 snprintf (blank_gif, SIZ, "%s%s", static_dirs[0], "/blank.gif");
911 output_static(blank_gif);
915 * Extract an embedded photo from a vCard for display on the client
917 void display_vcard_photo_img(void)
923 const char *contentType;
924 struct wcsession *WCC = WC;
926 msgnum = StrTol(WCC->UrlFragment1);
928 vcard = load_mimepart(msgnum,"1");
929 v = vcard_load(vcard);
931 photosrc = vcard_get_prop(v, "PHOTO", 1,0,0);
932 FlushStrBuf(WCC->WBuf);
933 StrBufAppendBufPlain(WCC->WBuf, photosrc, -1, 0);
934 if (StrBufDecodeBase64(WCC->WBuf) <= 0) {
935 FlushStrBuf(WCC->WBuf);
937 hprintf("HTTP/1.1 500 %s\n","Unable to get photo");
938 output_headers(0, 0, 0, 0, 0, 0);
939 hprintf("Content-Type: text/plain\r\n");
940 wprintf(_("Could Not decode vcard photo\n"));
944 contentType = GuessMimeType(ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
945 http_transmit_thing(contentType, 0);
951 * Generic function to output an arbitrary MIME attachment from
952 * message being composed
954 * partnum The MIME part to be output
955 * filename Fake filename to give
956 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
958 void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
961 char content_type[256];
964 if (GetHash(WC->attachments, SKEY(partnum), &vPart) &&
966 part = (wc_attachment*) vPart;
967 if (force_download) {
968 strcpy(content_type, "application/octet-stream");
971 strncpy(content_type, ChrPtr(part->content_type), sizeof content_type);
973 output_headers(0, 0, 0, 0, 0, 0);
974 StrBufAppendBufPlain(WC->WBuf, part->data, part->length, 0);
975 http_transmit_thing(content_type, 0);
977 hprintf("HTTP/1.1 404 %s\n", ChrPtr(partnum));
978 output_headers(0, 0, 0, 0, 0, 0);
979 hprintf("Content-Type: text/plain\r\n");
980 wprintf(_("An error occurred while retrieving this part: %s/%s\n"),
981 ChrPtr(partnum), ChrPtr(filename));
988 * Generic function to output an arbitrary MIME part from an arbitrary
989 * message number on the server.
991 * msgnum Number of the item on the citadel server
992 * partnum The MIME part to be output
993 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
995 void mimepart(const char *msgnum, const char *partnum, int force_download)
999 char content_type[256];
1001 serv_printf("OPNA %s|%s", msgnum, partnum);
1002 serv_getln(buf, sizeof buf);
1003 if (buf[0] == '2') {
1004 bytes = extract_long(&buf[4], 0);
1005 if (force_download) {
1006 strcpy(content_type, "application/octet-stream");
1009 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
1011 output_headers(0, 0, 0, 0, 0, 0);
1013 read_server_binary(WC->WBuf, bytes);
1015 serv_getln(buf, sizeof buf);
1016 http_transmit_thing(content_type, 0);
1018 hprintf("HTTP/1.1 404 %s\n", &buf[4]);
1019 output_headers(0, 0, 0, 0, 0, 0);
1020 hprintf("Content-Type: text/plain\r\n");
1021 wprintf(_("An error occurred while retrieving this part: %s\n"), &buf[4]);
1028 * Read any MIME part of a message, from the server, into memory.
1030 char *load_mimepart(long msgnum, char *partnum)
1034 char content_type[SIZ];
1037 serv_printf("DLAT %ld|%s", msgnum, partnum);
1038 serv_getln(buf, sizeof buf);
1039 if (buf[0] == '6') {
1040 bytes = extract_long(&buf[4], 0);
1041 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
1043 content = malloc(bytes + 2);
1044 serv_read(content, bytes);
1046 content[bytes] = 0; /* null terminate for good measure */
1055 * Read any MIME part of a message, from the server, into memory.
1057 void MimeLoadData(wc_mime_attachment *Mime)
1061 //// TODO: is there a chance the contenttype is different to the one we know?
1062 serv_printf("DLAT %ld|%s", Mime->msgnum, ChrPtr(Mime->PartNum));
1063 serv_getln(buf, sizeof buf);
1064 if (buf[0] == '6') {
1065 bytes = extract_long(&buf[4], 0);
1067 if (Mime->Data == NULL)
1068 Mime->Data = NewStrBufPlain(NULL, bytes);
1069 StrBuf_ServGetBLOB(Mime->Data, bytes);
1073 FlushStrBuf(Mime->Data);
1074 /// TODO XImportant message
1080 * Convenience functions to display a page containing only a string
1082 * titlebarcolor color of the titlebar of the frame
1083 * titlebarmsg text to display in the title bar
1084 * messagetext body of the box
1086 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
1088 hprintf("HTTP/1.1 200 OK\n");
1089 output_headers(1, 1, 2, 0, 0, 0);
1090 wprintf("<div id=\"banner\">\n");
1091 wprintf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
1092 wprintf("<span class=\"titlebar\">%s</span>\n", titlebarmsg);
1093 wprintf("</td></tr></table>\n");
1094 wprintf("</div>\n<div id=\"content\">\n");
1095 escputs(messagetext);
1097 wprintf("<hr />\n");
1103 * Display a blank page.
1105 void blank_page(void) {
1106 output_headers(1, 1, 0, 0, 0, 0);
1112 * A template has been requested
1114 void url_do_template(void) {
1115 const StrBuf *Tmpl = sbstr("template");
1117 output_headers(1, 0, 0, 0, 1, 0);
1118 DoTemplate(ChrPtr(Tmpl), StrLength(Tmpl), NULL, NULL, 0);
1125 * Offer to make any page the user's "start page."
1127 void offer_start_page(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType) {
1128 wprintf("<a href=\"change_start_page?startpage=");
1129 urlescputs(WC->this_page);
1131 wprintf(_("Make this my start page"));
1134 wprintf("<br/><a href=\"rss?room=");
1135 urlescputs(WC->wc_roomname);
1136 wprintf("\" title=\"RSS 2.0 feed for ");
1137 escputs(WC->wc_roomname);
1138 wprintf("\"><img alt=\"RSS\" border=\"0\" src=\"static/xml_button.gif\"/></a>\n");
1144 * Change the user's start page
1146 void change_start_page(void) {
1148 if (bstr("startpage") == NULL) {
1149 safestrncpy(WC->ImportantMessage,
1150 _("You no longer have a start page selected."),
1151 sizeof WC->ImportantMessage);
1152 display_main_menu();
1156 set_preference("startpage", NewStrBufPlain(bstr("startpage"), -1), 1);
1158 output_headers(1, 1, 0, 0, 0, 0);
1159 do_template("newstartpage", NULL);
1166 * convenience function to indicate success
1168 void display_success(char *successmessage)
1170 convenience_page("007700", "OK", successmessage);
1175 * Authorization required page
1176 * This is probably temporary and should be revisited
1178 void authorization_required(const char *message)
1180 hprintf("HTTP/1.1 401 Authorization Required\r\n");
1181 hprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n", serv_info.serv_humannode);
1182 hprintf("Content-Type: text/html\r\n");
1184 wprintf(_("Authorization Required"));
1185 wprintf("</h1>\r\n");
1186 wprintf(_("The resource you requested requires a valid username and password. "
1187 "You could not be logged in: %s\n"), message);
1193 * This function is called by the MIME parser to handle data uploaded by
1194 * the browser. Form data, uploaded files, and the data from HTTP PUT
1195 * operations (such as those found in GroupDAV) all arrive this way.
1197 * name Name of the item being uploaded
1198 * filename Filename of the item being uploaded
1199 * partnum MIME part identifier (not needed)
1200 * disp MIME content disposition (not needed)
1201 * content The actual data
1202 * cbtype MIME content-type
1203 * cbcharset Character set
1204 * length Content length
1205 * encoding MIME encoding type (not needed)
1206 * cbid Content ID (not needed)
1207 * userdata Not used here
1209 void upload_handler(char *name, char *filename, char *partnum, char *disp,
1210 void *content, char *cbtype, char *cbcharset,
1211 size_t length, char *encoding, char *cbid, void *userdata)
1214 #ifdef DEBUG_URLSTRINGS
1215 lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n", name, cbtype, length);
1217 if (WC->urlstrings == NULL)
1218 WC->urlstrings = NewHash(1, NULL);
1221 if ( (length > 0) && (IsEmptyStr(cbtype)) ) {
1222 u = (urlcontent *) malloc(sizeof(urlcontent));
1224 safestrncpy(u->url_key, name, sizeof(u->url_key));
1225 u->url_data = NewStrBufPlain(content, length);
1227 Put(WC->urlstrings, u->url_key, strlen(u->url_key), u, free_url);
1228 #ifdef DEBUG_URLSTRINGS
1229 lprintf(9, "Key: <%s> len: [%ld] Data: <%s>\n",
1231 StrLength(u->url_data),
1232 ChrPtr(u->url_data));
1236 /** Uploaded files */
1237 if ( (length > 0) && (!IsEmptyStr(cbtype)) ) {
1238 WC->upload = malloc(length);
1239 if (WC->upload != NULL) {
1240 WC->upload_length = length;
1241 safestrncpy(WC->upload_filename, filename,
1242 sizeof(WC->upload_filename));
1243 safestrncpy(WC->upload_content_type, cbtype,
1244 sizeof(WC->upload_content_type));
1245 memcpy(WC->upload, content, length);
1248 lprintf(3, "malloc() failed: %s\n", strerror(errno));
1255 * Convenience functions to wrap around asynchronous ajax responses
1257 void begin_ajax_response(void) {
1258 struct wcsession *WCC = WC;
1260 FlushStrBuf(WCC->HBuf);
1261 output_headers(0, 0, 0, 0, 0, 0);
1263 hprintf("Content-type: text/html; charset=UTF-8\r\n"
1265 "Connection: close\r\n"
1272 * print ajax response footer
1274 void end_ajax_response(void) {
1279 * Wraps a Citadel server command in an AJAX transaction.
1281 void ajax_servcmd(void)
1284 char gcontent[1024];
1288 begin_ajax_response();
1290 serv_printf("%s", bstr("g_cmd"));
1291 serv_getln(buf, sizeof buf);
1292 wprintf("%s\n", buf);
1294 if (buf[0] == '8') {
1295 serv_printf("\n\n000");
1297 if ((buf[0] == '1') || (buf[0] == '8')) {
1298 while (serv_getln(gcontent, sizeof gcontent), strcmp(gcontent, "000")) {
1299 wprintf("%s\n", gcontent);
1303 if (buf[0] == '4') {
1304 text_to_server(bstr("g_input"));
1307 if (buf[0] == '6') {
1308 len = atol(&buf[4]);
1310 serv_read(junk, len);
1313 if (buf[0] == '7') {
1314 len = atol(&buf[4]);
1316 memset(junk, 0, len);
1317 serv_write(junk, len);
1321 end_ajax_response();
1324 * This is kind of an ugly hack, but this is the only place it can go.
1325 * If the command was GEXP, then the instant messenger window must be
1326 * running, so reset the "last_pager_check" watchdog timer so
1327 * that page_popup() doesn't try to open it a second time.
1329 if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) {
1330 WC->last_pager_check = time(NULL);
1336 * Helper function for the asynchronous check to see if we need
1337 * to open the instant messenger window.
1339 void seconds_since_last_gexp(void)
1343 if ( (time(NULL) - WC->last_pager_check) < 30) {
1349 serv_getln(buf, sizeof buf);
1350 if (buf[3] == '*') {
1360 * \brief Detects a 'mobile' user agent
1362 int is_mobile_ua(char *user_agent) {
1363 if (strstr(user_agent,"iPhone OS") != NULL) {
1365 } else if (strstr(user_agent,"Windows CE") != NULL) {
1367 } else if (strstr(user_agent,"SymbianOS") != NULL) {
1369 } else if (strstr(user_agent, "Opera Mobi") != NULL) {
1371 } else if (strstr(user_agent, "Firefox/2.0.0 Opera 9.51 Beta") != NULL) {
1372 // For some reason a new install of Opera 9.51beta decided to spoof.
1380 * Entry point for WebCit transaction
1382 void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method, StrBuf *ReadBuf)
1384 const char *pch, *pchs, *pche;
1391 int a, nBackDots, nEmpty;
1392 int ContentLength = 0;
1393 StrBuf *ContentType = NULL;
1394 StrBuf *UrlLine = NULL;
1395 StrBuf *content = NULL;
1396 const char *content_end = NULL;
1397 char browser_host[256];
1398 char user_agent[256];
1404 * We stuff these with the values coming from the client cookies,
1405 * so we can use them to reconnect a timed out session if we have to.
1407 char c_username[SIZ];
1408 char c_password[SIZ];
1409 char c_roomname[SIZ];
1410 char c_httpauth_string[SIZ];
1411 char c_httpauth_user[SIZ];
1412 char c_httpauth_pass[SIZ];
1413 struct wcsession *WCC;
1415 safestrncpy(c_username, "", sizeof c_username);
1416 safestrncpy(c_password, "", sizeof c_password);
1417 safestrncpy(c_roomname, "", sizeof c_roomname);
1418 safestrncpy(c_httpauth_string, "", sizeof c_httpauth_string);
1419 safestrncpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER, sizeof c_httpauth_user);
1420 safestrncpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS, sizeof c_httpauth_pass);
1421 strcpy(browser_host, "");
1424 if (WCC->WBuf == NULL)
1425 WC->WBuf = NewStrBufPlain(NULL, 32768);
1426 FlushStrBuf(WCC->WBuf);
1428 if (WCC->HBuf == NULL)
1429 WCC->HBuf = NewStrBuf();
1430 FlushStrBuf(WCC->HBuf);
1432 WCC->upload_length = 0;
1435 WCC->trailing_javascript = NewStrBuf();
1437 /** Figure out the action */
1439 sizes[0] = sizeof action;
1442 index[a] = arg[a-1];
1443 sizes[a] = sizeof arg[a-1];
1445 //// index[9] = &foo; todo
1448 for ( a = 0; a < 9; ++a)
1450 extract_token(index[a], ChrPtr(ReqLine), a + 1, '/', sizes[a]);
1451 if (strstr(index[a], "?")) *strstr(index[a], "?") = 0;
1452 if (strstr(index[a], "&")) *strstr(index[a], "&") = 0;
1453 if (strstr(index[a], " ")) *strstr(index[a], " ") = 0;
1454 if ((index[a][0] == '.') && (index[a][1] == '.'))
1456 if (index[a][0] == '\0')
1461 if (GetHash(HTTPHeaders, HKEY("COOKIE"), &vLine) &&
1463 cookie_to_stuff((StrBuf *)vLine, NULL,
1464 c_username, sizeof c_username,
1465 c_password, sizeof c_password,
1466 c_roomname, sizeof c_roomname);
1468 if (GetHash(HTTPHeaders, HKEY("AUTHORIZATION"), &vLine) &&
1470 CtdlDecodeBase64(c_httpauth_string, ChrPtr((StrBuf*)vLine), StrLength((StrBuf*)vLine));
1471 extract_token(c_httpauth_user, c_httpauth_string, 0, ':', sizeof c_httpauth_user);
1472 extract_token(c_httpauth_pass, c_httpauth_string, 1, ':', sizeof c_httpauth_pass);
1474 if (GetHash(HTTPHeaders, HKEY("CONTENT-LENGTH"), &vLine) &&
1476 ContentLength = StrToi((StrBuf*)vLine);
1478 if (GetHash(HTTPHeaders, HKEY("CONTENT-TYPE"), &vLine) &&
1480 ContentType = (StrBuf*)vLine;
1482 if (GetHash(HTTPHeaders, HKEY("USER-AGENT"), &vLine) &&
1484 safestrncpy(user_agent, ChrPtr((StrBuf*)vLine), sizeof user_agent);
1486 if ((WCC->is_mobile < 0) && is_mobile_ua(&buf[12])) {
1495 GetHash(HTTPHeaders, HKEY("X-FORWARDED-HOST"), &vLine) &&
1497 safestrncpy(WCC->http_host,
1498 ChrPtr((StrBuf*)vLine),
1499 sizeof WCC->http_host);
1501 if (IsEmptyStr(WCC->http_host) &&
1502 GetHash(HTTPHeaders, HKEY("HOST"), &vLine) &&
1504 safestrncpy(WCC->http_host,
1505 ChrPtr((StrBuf*)vLine),
1506 sizeof WCC->http_host);
1509 if (GetHash(HTTPHeaders, HKEY("X-FORWARDED-FOR"), &vLine) &&
1511 safestrncpy(browser_host,
1512 ChrPtr((StrBuf*) vLine),
1513 sizeof browser_host);
1514 while (num_tokens(browser_host, ',') > 1) {
1515 remove_token(browser_host, 0, ',');
1517 striplt(browser_host);
1520 if (ContentLength > 0) {
1521 content = NewStrBuf();
1522 StrBufPrintf(content, "Content-type: %s\n"
1523 "Content-length: %d\n\n",
1524 ChrPtr(ContentType), ContentLength);
1526 hprintf("Content-type: %s\n"
1527 "Content-length: %d\n\n",
1528 ContentType, ContentLength);
1530 body_start = StrLength(content);
1532 /** Read the entire input data at once. */
1533 client_read(&WCC->http_sock, content, ReadBuf, ContentLength + body_start);
1535 if (!strncasecmp(ChrPtr(ContentType), "application/x-www-form-urlencoded", 33)) {
1536 StrBufCutLeft(content, body_start);
1537 ParseURLParams(content);
1538 } else if (!strncasecmp(ChrPtr(ContentType), "multipart", 9)) {
1539 content_end = ChrPtr(content) + ContentLength + body_start;
1540 mime_parser(ChrPtr(content), content_end, *upload_handler, NULL, NULL, NULL, 0);
1546 /* make a note of where we are in case the user wants to save it */
1547 safestrncpy(WCC->this_page, ChrPtr(ReqLine), sizeof(WCC->this_page));
1548 remove_token(WCC->this_page, 2, ' ');
1549 remove_token(WCC->this_page, 0, ' ');
1551 /* If there are variables in the URL, we must grab them now */
1552 UrlLine = NewStrBufDup(ReqLine);
1553 len = StrLength(UrlLine);
1554 pch = pchs = ChrPtr(UrlLine);
1556 while (pch < pche) {
1557 if ((*pch == '?') || (*pch == '&')) {
1558 StrBufCutLeft(UrlLine, pch - pchs + 1);
1559 ParseURLParams(UrlLine);
1564 FreeStrBuf(&UrlLine);
1566 /* If it's a "force 404" situation then display the error and bail. */
1567 if (!strcmp(action, "404")) {
1568 hprintf("HTTP/1.1 404 Not found\r\n");
1569 hprintf("Content-Type: text/plain\r\n");
1570 wprintf("Not found\r\n");
1572 goto SKIP_ALL_THIS_CRAP;
1575 /* Static content can be sent without connecting to Citadel. */
1577 for (a=0; a<ndirs && ! is_static; ++a) {
1578 if (!strcasecmp(action, (char*)static_content_dirs[a])) { /* map web to disk location */
1586 snprintf(buf, sizeof buf, "%s/%s/%s/%s/%s/%s/%s/%s",
1587 static_dirs[n_static],
1588 index[1], index[2], index[3], index[4], index[5], index[6], index[7]);
1589 for (a=0; a<8; ++a) {
1590 if (buf[strlen(buf)-1] == '/') {
1591 buf[strlen(buf)-1] = 0;
1594 for (a = 0; a < strlen(buf); ++a) {
1595 if (isspace(buf[a])) {
1603 lprintf(9, "Suspicious request. Ignoring.");
1604 hprintf("HTTP/1.1 404 Security check failed\r\n");
1605 hprintf("Content-Type: text/plain\r\n");
1606 wprintf("You have sent a malformed or invalid request.\r\n");
1609 goto SKIP_ALL_THIS_CRAP; /* Don't try to connect */
1612 /* If the client sent a nonce that is incorrect, kill the request. */
1613 if (strlen(bstr("nonce")) > 0) {
1614 lprintf(9, "Comparing supplied nonce %s to session nonce %ld\n",
1615 bstr("nonce"), WCC->nonce);
1616 if (ibstr("nonce") != WCC->nonce) {
1617 lprintf(9, "Ignoring request with mismatched nonce.\n");
1618 hprintf("HTTP/1.1 404 Security check failed\r\n");
1619 hprintf("Content-Type: text/plain\r\n");
1620 wprintf("Security check failed.\r\n");
1622 goto SKIP_ALL_THIS_CRAP;
1627 * If we're not connected to a Citadel server, try to hook up the
1630 if (!WCC->connected) {
1631 if (!strcasecmp(ctdlhost, "uds")) {
1632 /* unix domain socket */
1633 snprintf(buf, SIZ, "%s/citadel.socket", ctdlport);
1634 WCC->serv_sock = uds_connectsock(buf);
1638 WCC->serv_sock = tcp_connectsock(ctdlhost, ctdlport);
1641 if (WCC->serv_sock < 0) {
1643 goto SKIP_ALL_THIS_CRAP;
1647 serv_getln(buf, sizeof buf); /** get the server welcome message */
1650 * From what host is our user connecting? Go with
1651 * the host at the other end of the HTTP socket,
1652 * unless we are following X-Forwarded-For: headers
1653 * and such a header has already turned up something.
1655 if ( (!follow_xff) || (strlen(browser_host) == 0) ) {
1656 locate_host(browser_host, WCC->http_sock);
1659 get_serv_info(browser_host, user_agent);
1660 if (serv_info.serv_rev_level < MINIMUM_CIT_VERSION) {
1662 wprintf(_("You are connected to a Citadel "
1663 "server running Citadel %d.%02d. \n"
1664 "In order to run this version of WebCit "
1665 "you must also have Citadel %d.%02d or"
1667 serv_info.serv_rev_level / 100,
1668 serv_info.serv_rev_level % 100,
1669 MINIMUM_CIT_VERSION / 100,
1670 MINIMUM_CIT_VERSION % 100
1673 end_webcit_session();
1674 goto SKIP_ALL_THIS_CRAP;
1678 ////////todo: restore language in this case
1680 * Functions which can be performed without logging in
1682 if (!strcasecmp(action, "listsub")) {
1684 goto SKIP_ALL_THIS_CRAP;
1686 if (!strcasecmp(action, "freebusy")) {
1687 do_freebusy(ChrPtr(ReqLine));
1688 goto SKIP_ALL_THIS_CRAP;
1692 * If we're not logged in, but we have HTTP Authentication data,
1693 * try logging in to Citadel using that.
1695 if ((!WCC->logged_in)
1696 && (strlen(c_httpauth_user) > 0)
1697 && (strlen(c_httpauth_pass) > 0)) {
1698 serv_printf("USER %s", c_httpauth_user);
1699 serv_getln(buf, sizeof buf);
1700 if (buf[0] == '3') {
1701 serv_printf("PASS %s", c_httpauth_pass);
1702 serv_getln(buf, sizeof buf);
1703 if (buf[0] == '2') {
1704 become_logged_in(c_httpauth_user,
1705 c_httpauth_pass, buf);
1706 safestrncpy(WCC->httpauth_user, c_httpauth_user, sizeof WCC->httpauth_user);
1707 safestrncpy(WCC->httpauth_pass, c_httpauth_pass, sizeof WCC->httpauth_pass);
1709 /* Should only display when password is wrong */
1710 authorization_required(&buf[4]);
1711 goto SKIP_ALL_THIS_CRAP;
1716 /* This needs to run early */
1718 if (!strcasecmp(action, "rss")) {
1719 display_rss(bstr("room"), request_method);
1720 goto SKIP_ALL_THIS_CRAP;
1725 * The GroupDAV stuff relies on HTTP authentication instead of
1726 * our session's authentication.
1728 if (!strncasecmp(action, "groupdav", 8)) {
1729 groupdav_main(HTTPHeaders,
1730 ReqLine, request_method,
1731 ContentType, /* do GroupDAV methods */
1732 ContentLength, content, body_start);
1733 if (!WCC->logged_in) {
1734 WCC->killthis = 1; /* If not logged in, don't */
1735 } /* keep the session active */
1736 goto SKIP_ALL_THIS_CRAP;
1741 * Automatically send requests with any method other than GET or
1742 * POST to the GroupDAV code as well.
1744 if ((strcasecmp(ChrPtr(request_method), "GET")) && (strcasecmp(ChrPtr(request_method), "POST"))) {
1745 groupdav_main(HTTPHeaders, ReqLine,
1746 request_method, ContentType, /** do GroupDAV methods */
1747 ContentLength, content, body_start);
1748 if (!WCC->logged_in) {
1749 WCC->killthis = 1; /** If not logged in, don't */
1750 } /** keep the session active */
1751 goto SKIP_ALL_THIS_CRAP;
1755 * If we're not logged in, but we have username and password cookies
1756 * supplied by the browser, try using them to log in.
1758 if ((!WCC->logged_in)
1759 && (!IsEmptyStr(c_username))
1760 && (!IsEmptyStr(c_password))) {
1761 serv_printf("USER %s", c_username);
1762 serv_getln(buf, sizeof buf);
1763 if (buf[0] == '3') {
1764 serv_printf("PASS %s", c_password);
1765 serv_getln(buf, sizeof buf);
1766 if (buf[0] == '2') {
1768 become_logged_in(c_username, c_password, buf);
1769 if (get_preference("language", &Lang)) {
1770 set_selected_language(ChrPtr(Lang));
1771 go_selected_language(); /* set locale */
1773 get_preference("default_header_charset", &WCC->DefaultCharset);
1778 * If we don't have a current room, but a cookie specifying the
1779 * current room is supplied, make an effort to go there.
1781 if ((IsEmptyStr(WCC->wc_roomname)) && (!IsEmptyStr(c_roomname))) {
1782 serv_printf("GOTO %s", c_roomname);
1783 serv_getln(buf, sizeof buf);
1784 if (buf[0] == '2') {
1785 safestrncpy(WCC->wc_roomname, c_roomname, sizeof WCC->wc_roomname);
1789 if (!strcasecmp(action, "image")) {
1791 } else if (!strcasecmp(action, "display_mime_icon")) {
1792 display_mime_icon();
1796 WebcitHandler *Handler;
1798 GetHash(HandlerHash, action, strlen(action) /* TODO*/, &vHandler),
1799 Handler = (WebcitHandler*) vHandler;
1800 if (Handler != NULL) {
1801 if (!WCC->logged_in && ((Handler->Flags & ANONYMOUS) == 0)) {
1802 display_login(NULL);
1805 if((Handler->Flags & NEED_URL)) {
1806 if (WCC->UrlFragment1 == NULL)
1807 WCC->UrlFragment1 = NewStrBuf();
1808 if (WCC->UrlFragment2 == NULL)
1809 WCC->UrlFragment2 = NewStrBuf();
1810 StrBufPrintf(WCC->UrlFragment1, "%s", index[1]);
1811 StrBufPrintf(WCC->UrlFragment2, "%s", index[2]);
1813 if ((Handler->Flags & AJAX) != 0)
1814 begin_ajax_response();
1816 if ((Handler->Flags & AJAX) != 0)
1817 end_ajax_response();
1820 /* When all else fais, display the main menu. */
1822 if (!WCC->logged_in)
1823 display_login(NULL);
1825 display_main_menu();
1830 if (content != NULL) {
1831 FreeStrBuf(&content);
1835 if (WCC->upload_length > 0) {
1837 WCC->upload_length = 0;
1839 FreeStrBuf(&WCC->trailing_javascript);
1844 * Replacement for sleep() that uses select() in order to avoid SIGALRM
1846 void sleeeeeeeeeep(int seconds)
1850 tv.tv_sec = seconds;
1852 select(0, NULL, NULL, NULL, &tv);
1855 void diagnostics(void)
1857 output_headers(1, 1, 1, 0, 0, 0);
1858 wprintf("Session: %d<hr />\n", WC->wc_session);
1859 wprintf("Command: <br /><PRE>\n");
1860 StrEscPuts(WC->UrlFragment1);
1861 wprintf("<br />\n");
1862 StrEscPuts(WC->UrlFragment2);
1863 wprintf("</PRE><hr />\n");
1864 wprintf("Variables: <br /><PRE>\n");
1866 wprintf("</PRE><hr />\n");
1870 void view_mimepart(void) {
1871 mimepart(ChrPtr(WC->UrlFragment1),
1872 ChrPtr(WC->UrlFragment2),
1876 void download_mimepart(void) {
1877 mimepart(ChrPtr(WC->UrlFragment1),
1878 ChrPtr(WC->UrlFragment2),
1882 void view_postpart(void) {
1883 postpart(WC->UrlFragment1,
1888 void download_postpart(void) {
1889 postpart(WC->UrlFragment1,
1895 int ConditionalImportantMesage(WCTemplateToken *Tokens, void *Context, int ContextType)
1897 struct wcsession *WCC = WC;
1899 return (!IsEmptyStr(WCC->ImportantMessage));
1904 void tmplput_importantmessage(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
1906 struct wcsession *WCC = WC;
1909 StrEscAppend(Target, NULL, WCC->ImportantMessage, 0, 0);
1910 WCC->ImportantMessage[0] = '\0';
1914 int ConditionalBstr(WCTemplateToken *Tokens, void *Context, int ContextType)
1916 if(Tokens->nParameters == 3)
1917 return HaveBstr(Tokens->Params[2]->Start,
1918 Tokens->Params[2]->len);
1920 return strcmp(Bstr(Tokens->Params[2]->Start,
1921 Tokens->Params[2]->len),
1922 Tokens->Params[3]->Start) == 0;
1925 void tmplput_bstr(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
1927 StrBufAppendBuf(Target,
1928 SBstr(Tokens->Params[0]->Start,
1929 Tokens->Params[0]->len), 0);
1933 void tmplput_csslocal(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
1935 extern StrBuf *csslocal;
1936 StrBufAppendBuf(Target,
1949 WebcitAddUrlHandler(HKEY("blank"), blank_page, ANONYMOUS);
1950 WebcitAddUrlHandler(HKEY("do_template"), url_do_template, ANONYMOUS);
1951 WebcitAddUrlHandler(HKEY("sslg"), seconds_since_last_gexp, AJAX);
1952 WebcitAddUrlHandler(HKEY("ajax_servcmd"), ajax_servcmd, 0);
1953 WebcitAddUrlHandler(HKEY("change_start_page"), change_start_page, 0);
1954 WebcitAddUrlHandler(HKEY("toggle_self_service"), toggle_self_service, 0);
1955 WebcitAddUrlHandler(HKEY("vcardphoto"), display_vcard_photo_img, NEED_URL);
1956 WebcitAddUrlHandler(HKEY("mimepart"), view_mimepart, NEED_URL);
1957 WebcitAddUrlHandler(HKEY("mimepart_download"), download_mimepart, NEED_URL);
1958 WebcitAddUrlHandler(HKEY("postpart"), view_postpart, NEED_URL);
1959 WebcitAddUrlHandler(HKEY("postpart_download"), download_postpart, NEED_URL);
1960 WebcitAddUrlHandler(HKEY("diagnostics"), diagnostics, NEED_URL);
1962 RegisterConditional(HKEY("COND:IMPMSG"), 0, ConditionalImportantMesage, CTX_NONE);
1963 RegisterConditional(HKEY("COND:BSTR"), 1, ConditionalBstr, CTX_NONE);
1964 RegisterNamespace("BSTR", 1, 2, tmplput_bstr, CTX_NONE);
1965 RegisterNamespace("CSSLOCAL", 0, 0, tmplput_csslocal, CTX_NONE);
1966 RegisterNamespace("IMPORTANTMESSAGE", 0, 0, tmplput_importantmessage, CTX_NONE);
1967 RegisterNamespace("OFFERSTARTPAGE", 0, 0, offer_start_page, CTX_NONE);