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 tmplput_trailing_javascript(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
387 struct wcsession *WCC = WC;
390 StrBufAppendTemplate(Target, nArgs, Tokens, vContext, ContextType,
391 WCC->trailing_javascript, 0);
395 * wrap up an HTTP session, closes tags, etc.
397 * print_standard_html_footer should be set to:
398 * 0 - to transmit only,
399 * nonzero - to append the closing tags
401 void wDumpContent(int print_standard_html_footer)
403 if (print_standard_html_footer) {
404 wprintf("</div> <!-- end of 'content' div -->\n");
405 do_template("trailing", NULL);
408 /* If we've been saving it all up for one big output burst,
409 * go ahead and do that now.
417 * Copy a string, escaping characters which have meaning in HTML.
419 * target target buffer
420 * strbuf source buffer
421 * nbsp If nonzero, spaces are converted to non-breaking spaces.
422 * nolinebreaks if set, linebreaks are removed from the string.
424 long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks)
426 char *aptr, *bptr, *eptr;
431 eptr = target + tSize - 6; // our biggest unit to put in...
434 while ((bptr < eptr) && !IsEmptyStr(aptr) ){
436 memcpy(bptr, "<", 4);
439 else if (*aptr == '>') {
440 memcpy(bptr, ">", 4);
443 else if (*aptr == '&') {
444 memcpy(bptr, "&", 5);
447 else if (*aptr == '\"') {
448 memcpy(bptr, """, 6);
451 else if (*aptr == '\'') {
452 memcpy(bptr, "'", 5);
455 else if (*aptr == LB) {
459 else if (*aptr == RB) {
463 else if (*aptr == QU) {
467 else if ((*aptr == 32) && (nbsp == 1)) {
468 memcpy(bptr, " ", 6);
471 else if ((*aptr == '\n') && (nolinebreaks)) {
472 *bptr='\0'; /* nothing */
474 else if ((*aptr == '\r') && (nolinebreaks)) {
475 *bptr='\0'; /* nothing */
484 if ((bptr = eptr - 1 ) && !IsEmptyStr(aptr) )
486 return (bptr - target);
490 void escputs1(char *strbuf, int nbsp, int nolinebreaks)
492 StrEscAppend(WC->WBuf, NULL, strbuf, nbsp, nolinebreaks);
495 void StrEscputs1(const StrBuf *strbuf, int nbsp, int nolinebreaks)
497 StrEscAppend(WC->WBuf, strbuf, NULL, nbsp, nolinebreaks);
501 * static wrapper for ecsputs1
503 void escputs(char *strbuf)
505 escputs1(strbuf, 0, 0);
510 * static wrapper for ecsputs1
512 void StrEscPuts(const StrBuf *strbuf)
514 StrEscputs1(strbuf, 0, 0);
519 * urlescape buffer and print it to the client
521 void urlescputs(const char *strbuf)
523 StrBufUrlescAppend(WC->WBuf, NULL, strbuf);
527 * urlescape buffer and print it to the client
529 void UrlescPutStrBuf(const StrBuf *strbuf)
531 StrBufUrlescAppend(WC->WBuf, strbuf, NULL);
535 * urlescape buffer and print it as header
537 void hurlescputs(const char *strbuf)
539 StrBufUrlescAppend(WC->HBuf, NULL, strbuf);
544 * Copy a string, escaping characters for JavaScript strings.
546 void jsesc(char *target, size_t tlen, char *strbuf)
555 len = strlen (strbuf);
557 tend = target + tlen;
561 while (!IsEmptyStr(sptr) &&
567 else if (*sptr == '>')
569 else if (*sptr == '\'') {
575 else if (*sptr == '"') {
585 else if (*sptr == '&') {
602 * escape and print javascript
604 void jsescputs(char *strbuf)
608 jsesc(outbuf, SIZ, strbuf);
609 wprintf("%s", outbuf);
613 * print a string to the client after cleaning it with msgesc() and stresc()
615 void msgescputs1( char *strbuf)
619 if ((strbuf == NULL) || IsEmptyStr(strbuf))
621 OutBuf = NewStrBuf();
622 StrMsgEscAppend(OutBuf, NULL, strbuf);
623 StrEscAppend(WC->WBuf, OutBuf, NULL, 0, 0);
628 * print a string to the client after cleaning it with msgesc()
630 void msgescputs(char *strbuf) {
631 if ((strbuf != NULL) && !IsEmptyStr(strbuf))
632 StrMsgEscAppend(WC->WBuf, NULL, strbuf);
639 * Output HTTP headers and leading HTML for a page
641 void output_headers( int do_httpheaders, /* 1 = output HTTP headers */
642 int do_htmlhead, /* 1 = output HTML <head> section and <body> opener */
644 int do_room_banner, /* 0=no, 1=yes,
645 * 2 = I'm going to embed my own, so don't open the
646 * <div id="content"> either.
649 int unset_cookies, /* 1 = session is terminating, so unset the cookies */
650 int suppress_check, /* 1 = suppress check for instant messages */
651 int cache /* 1 = allow browser to cache this page */
656 hprintf("HTTP/1.1 200 OK\n");
657 http_datestring(httpnow, sizeof httpnow, time(NULL));
659 if (do_httpheaders) {
660 hprintf("Content-type: text/html; charset=utf-8\r\n"
662 "Connection: close\r\n",
663 PACKAGE_STRING, serv_info.serv_software
668 char httpTomorow[128];
670 http_datestring(httpTomorow, sizeof httpTomorow,
671 time(NULL) + 60 * 60 * 24 * 2);
673 hprintf("Pragma: public\r\n"
674 "Cache-Control: max-age=3600, must-revalidate\r\n"
675 "Last-modified: %s\r\n"
682 hprintf("Pragma: no-cache\r\n"
683 "Cache-Control: no-store\r\n"
688 stuff_to_cookie(cookie, 1024, WC->wc_session, WC->wc_username,
689 WC->wc_password, WC->wc_roomname);
692 hprintf("Set-cookie: webcit=%s; path=/\r\n", unset);
694 hprintf("Set-cookie: webcit=%s; path=/\r\n", cookie);
695 if (server_cookie != NULL) {
696 hprintf("%s\n", server_cookie);
702 do_template("head", NULL);
709 /* check for ImportantMessages (these display in a div overlaying the main screen) */
710 if (!IsEmptyStr(WC->ImportantMessage)) {
711 wprintf("<div id=\"important_message\">\n"
712 "<span class=\"imsg\">");
713 escputs(WC->ImportantMessage);
714 wprintf("</span><br />\n"
716 "<script type=\"text/javascript\">\n"
717 " setTimeout('hide_imsg_popup()', 5000); \n"
719 WC->ImportantMessage[0] = 0;
722 if ( (WC->logged_in) && (!unset_cookies) ) {
723 wprintf("<div id=\"iconbar\">");
724 do_selected_iconbar();
725 /** check for instant messages (these display in a new window) */
730 if (do_room_banner == 1) {
731 wprintf("<div id=\"banner\">\n");
732 embed_room_banner(NULL, navbar_default);
737 if (do_room_banner == 1) {
738 wprintf("<div id=\"content\">\n");
744 * Generic function to do an HTTP redirect. Easy and fun.
746 void http_redirect(const char *whichpage) {
747 hprintf("HTTP/1.1 302 Moved Temporarily\n");
748 hprintf("Location: %s\r\n", whichpage);
749 hprintf("URI: %s\r\n", whichpage);
750 hprintf("Content-type: text/html; charset=utf-8\r\n");
751 wprintf("<html><body>");
752 wprintf("Go <a href=\"%s\">here</A>.", whichpage);
753 wprintf("</body></html>\n");
760 * Output a piece of content to the web browser using conformant HTTP and MIME semantics
762 void http_transmit_thing(const char *content_type,
766 lprintf(9, "http_transmit_thing(%s)%s\n",
768 (is_static ? " (static)" : "")
771 output_headers(0, 0, 0, 0, 0, is_static);
773 hprintf("Content-type: %s\r\n"
775 "Connection: close\r\n",
783 * print menu box like used in the floor view or admin interface.
784 * This function takes pair of strings as va_args,
785 * Title Title string of the box
786 * Class CSS Class for the box
787 * nLines How many string pairs should we print? (URL, UrlText)
788 * ... Pairs of URL Strings and their Names
790 void print_menu_box(char* Title, char *Class, int nLines, ...)
795 svput("BOXTITLE", WCS_STRING, Title);
796 do_template("beginbox", NULL);
798 wprintf("<ul class=\"%s\">", Class);
800 va_start(arg_list, nLines);
801 for (i = 0; i < nLines; ++i)
803 wprintf("<li><a href=\"%s\">", va_arg(arg_list, char *));
804 wprintf((char *) va_arg(arg_list, char *));
805 wprintf("</a></li>\n");
809 wprintf("</a></li>\n");
813 do_template("endbox", NULL);
818 * dump out static pages from disk
820 void output_static(char *what)
826 const char *content_type;
830 fd = open(what, O_RDONLY);
832 lprintf(9, "output_static('%s') -- NOT FOUND --\n", what);
833 hprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
834 hprintf("Content-Type: text/plain\r\n");
835 wprintf("Cannot open %s: %s\r\n", what, strerror(errno));
839 content_type = GuessMimeByFilename(what, len);
841 if (fstat(fd, &statbuf) == -1) {
842 lprintf(9, "output_static('%s') -- FSTAT FAILED --\n", what);
843 hprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
844 hprintf("Content-Type: text/plain\r\n");
845 wprintf("Cannot fstat %s: %s\n", what, strerror(errno));
851 bytes = statbuf.st_size;
853 if (StrBufReadBLOB(WC->WBuf, &fd, 1, bytes, &Err) < 0)
855 if (fd > 0) close(fd);
856 lprintf(9, "output_static('%s') -- FREAD FAILED (%s) --\n", what, strerror(errno));
857 hprintf("HTTP/1.1 500 internal server error \r\n");
858 hprintf("Content-Type: text/plain\r\n");
866 lprintf(9, "output_static('%s') %s\n", what, content_type);
868 http_transmit_thing(content_type, 1);
870 if (yesbstr("force_close_session")) {
871 end_webcit_session();
876 * When the browser requests an image file from the Citadel server,
877 * this function is called to transmit it.
881 struct wcsession *WCC = WC;
884 const char *MimeType;
886 serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
887 serv_getln(buf, sizeof buf);
889 bytes = extract_long(&buf[4], 0);
891 /** Read it from the server */
893 if (read_server_binary(WCC->WBuf, bytes) > 0) {
895 serv_getln(buf, sizeof buf);
897 MimeType = GuessMimeType (ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
898 /** Write it to the browser */
899 if (!IsEmptyStr(MimeType))
901 http_transmit_thing(MimeType, 0);
905 /* hm... unknown mimetype? fallback to blank gif */
910 * Instead of an ugly 404, send a 1x1 transparent GIF
911 * when there's no such image on the server.
914 snprintf (blank_gif, SIZ, "%s%s", static_dirs[0], "/blank.gif");
915 output_static(blank_gif);
919 * Extract an embedded photo from a vCard for display on the client
921 void display_vcard_photo_img(void)
927 const char *contentType;
928 struct wcsession *WCC = WC;
930 msgnum = StrTol(WCC->UrlFragment1);
932 vcard = load_mimepart(msgnum,"1");
933 v = vcard_load(vcard);
935 photosrc = vcard_get_prop(v, "PHOTO", 1,0,0);
936 FlushStrBuf(WCC->WBuf);
937 StrBufAppendBufPlain(WCC->WBuf, photosrc, -1, 0);
938 if (StrBufDecodeBase64(WCC->WBuf) <= 0) {
939 FlushStrBuf(WCC->WBuf);
941 hprintf("HTTP/1.1 500 %s\n","Unable to get photo");
942 output_headers(0, 0, 0, 0, 0, 0);
943 hprintf("Content-Type: text/plain\r\n");
944 wprintf(_("Could Not decode vcard photo\n"));
948 contentType = GuessMimeType(ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
949 http_transmit_thing(contentType, 0);
955 * Generic function to output an arbitrary MIME attachment from
956 * message being composed
958 * partnum The MIME part to be output
959 * filename Fake filename to give
960 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
962 void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
965 char content_type[256];
968 if (GetHash(WC->attachments, SKEY(partnum), &vPart) &&
970 part = (wc_attachment*) vPart;
971 if (force_download) {
972 strcpy(content_type, "application/octet-stream");
975 strncpy(content_type, ChrPtr(part->content_type), sizeof content_type);
977 output_headers(0, 0, 0, 0, 0, 0);
978 StrBufAppendBufPlain(WC->WBuf, part->data, part->length, 0);
979 http_transmit_thing(content_type, 0);
981 hprintf("HTTP/1.1 404 %s\n", ChrPtr(partnum));
982 output_headers(0, 0, 0, 0, 0, 0);
983 hprintf("Content-Type: text/plain\r\n");
984 wprintf(_("An error occurred while retrieving this part: %s/%s\n"),
985 ChrPtr(partnum), ChrPtr(filename));
992 * Generic function to output an arbitrary MIME part from an arbitrary
993 * message number on the server.
995 * msgnum Number of the item on the citadel server
996 * partnum The MIME part to be output
997 * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
999 void mimepart(const char *msgnum, const char *partnum, int force_download)
1003 char content_type[256];
1005 serv_printf("OPNA %s|%s", msgnum, partnum);
1006 serv_getln(buf, sizeof buf);
1007 if (buf[0] == '2') {
1008 bytes = extract_long(&buf[4], 0);
1009 if (force_download) {
1010 strcpy(content_type, "application/octet-stream");
1013 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
1015 output_headers(0, 0, 0, 0, 0, 0);
1017 read_server_binary(WC->WBuf, bytes);
1019 serv_getln(buf, sizeof buf);
1020 http_transmit_thing(content_type, 0);
1022 hprintf("HTTP/1.1 404 %s\n", &buf[4]);
1023 output_headers(0, 0, 0, 0, 0, 0);
1024 hprintf("Content-Type: text/plain\r\n");
1025 wprintf(_("An error occurred while retrieving this part: %s\n"), &buf[4]);
1032 * Read any MIME part of a message, from the server, into memory.
1034 char *load_mimepart(long msgnum, char *partnum)
1038 char content_type[SIZ];
1041 serv_printf("DLAT %ld|%s", msgnum, partnum);
1042 serv_getln(buf, sizeof buf);
1043 if (buf[0] == '6') {
1044 bytes = extract_long(&buf[4], 0);
1045 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
1047 content = malloc(bytes + 2);
1048 serv_read(content, bytes);
1050 content[bytes] = 0; /* null terminate for good measure */
1059 * Read any MIME part of a message, from the server, into memory.
1061 void MimeLoadData(wc_mime_attachment *Mime)
1065 //// TODO: is there a chance the contenttype is different to the one we know?
1066 serv_printf("DLAT %ld|%s", Mime->msgnum, ChrPtr(Mime->PartNum));
1067 serv_getln(buf, sizeof buf);
1068 if (buf[0] == '6') {
1069 bytes = extract_long(&buf[4], 0);
1071 if (Mime->Data == NULL)
1072 Mime->Data = NewStrBufPlain(NULL, bytes);
1073 StrBuf_ServGetBLOB(Mime->Data, bytes);
1077 FlushStrBuf(Mime->Data);
1078 /// TODO XImportant message
1084 * Convenience functions to display a page containing only a string
1086 * titlebarcolor color of the titlebar of the frame
1087 * titlebarmsg text to display in the title bar
1088 * messagetext body of the box
1090 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
1092 hprintf("HTTP/1.1 200 OK\n");
1093 output_headers(1, 1, 2, 0, 0, 0);
1094 wprintf("<div id=\"banner\">\n");
1095 wprintf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
1096 wprintf("<span class=\"titlebar\">%s</span>\n", titlebarmsg);
1097 wprintf("</td></tr></table>\n");
1098 wprintf("</div>\n<div id=\"content\">\n");
1099 escputs(messagetext);
1101 wprintf("<hr />\n");
1107 * Display a blank page.
1109 void blank_page(void) {
1110 output_headers(1, 1, 0, 0, 0, 0);
1116 * A template has been requested
1118 void url_do_template(void) {
1119 const StrBuf *Tmpl = sbstr("template");
1121 output_headers(1, 0, 0, 0, 1, 0);
1122 DoTemplate(ChrPtr(Tmpl), StrLength(Tmpl), NULL, NULL, 0);
1129 * Offer to make any page the user's "start page."
1131 void offer_start_page(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType) {
1132 wprintf("<a href=\"change_start_page?startpage=");
1133 urlescputs(WC->this_page);
1135 wprintf(_("Make this my start page"));
1138 wprintf("<br/><a href=\"rss?room=");
1139 urlescputs(WC->wc_roomname);
1140 wprintf("\" title=\"RSS 2.0 feed for ");
1141 escputs(WC->wc_roomname);
1142 wprintf("\"><img alt=\"RSS\" border=\"0\" src=\"static/xml_button.gif\"/></a>\n");
1148 * Change the user's start page
1150 void change_start_page(void) {
1152 if (bstr("startpage") == NULL) {
1153 safestrncpy(WC->ImportantMessage,
1154 _("You no longer have a start page selected."),
1155 sizeof WC->ImportantMessage);
1156 display_main_menu();
1160 set_preference("startpage", NewStrBufPlain(bstr("startpage"), -1), 1);
1162 output_headers(1, 1, 0, 0, 0, 0);
1163 do_template("newstartpage", NULL);
1170 * convenience function to indicate success
1172 void display_success(char *successmessage)
1174 convenience_page("007700", "OK", successmessage);
1179 * Authorization required page
1180 * This is probably temporary and should be revisited
1182 void authorization_required(const char *message)
1184 hprintf("HTTP/1.1 401 Authorization Required\r\n");
1185 hprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n", serv_info.serv_humannode);
1186 hprintf("Content-Type: text/html\r\n");
1188 wprintf(_("Authorization Required"));
1189 wprintf("</h1>\r\n");
1190 wprintf(_("The resource you requested requires a valid username and password. "
1191 "You could not be logged in: %s\n"), message);
1197 * This function is called by the MIME parser to handle data uploaded by
1198 * the browser. Form data, uploaded files, and the data from HTTP PUT
1199 * operations (such as those found in GroupDAV) all arrive this way.
1201 * name Name of the item being uploaded
1202 * filename Filename of the item being uploaded
1203 * partnum MIME part identifier (not needed)
1204 * disp MIME content disposition (not needed)
1205 * content The actual data
1206 * cbtype MIME content-type
1207 * cbcharset Character set
1208 * length Content length
1209 * encoding MIME encoding type (not needed)
1210 * cbid Content ID (not needed)
1211 * userdata Not used here
1213 void upload_handler(char *name, char *filename, char *partnum, char *disp,
1214 void *content, char *cbtype, char *cbcharset,
1215 size_t length, char *encoding, char *cbid, void *userdata)
1218 #ifdef DEBUG_URLSTRINGS
1219 lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n", name, cbtype, length);
1221 if (WC->urlstrings == NULL)
1222 WC->urlstrings = NewHash(1, NULL);
1225 if ( (length > 0) && (IsEmptyStr(cbtype)) ) {
1226 u = (urlcontent *) malloc(sizeof(urlcontent));
1228 safestrncpy(u->url_key, name, sizeof(u->url_key));
1229 u->url_data = NewStrBufPlain(content, length);
1231 Put(WC->urlstrings, u->url_key, strlen(u->url_key), u, free_url);
1232 #ifdef DEBUG_URLSTRINGS
1233 lprintf(9, "Key: <%s> len: [%ld] Data: <%s>\n",
1235 StrLength(u->url_data),
1236 ChrPtr(u->url_data));
1240 /** Uploaded files */
1241 if ( (length > 0) && (!IsEmptyStr(cbtype)) ) {
1242 WC->upload = malloc(length);
1243 if (WC->upload != NULL) {
1244 WC->upload_length = length;
1245 safestrncpy(WC->upload_filename, filename,
1246 sizeof(WC->upload_filename));
1247 safestrncpy(WC->upload_content_type, cbtype,
1248 sizeof(WC->upload_content_type));
1249 memcpy(WC->upload, content, length);
1252 lprintf(3, "malloc() failed: %s\n", strerror(errno));
1259 * Convenience functions to wrap around asynchronous ajax responses
1261 void begin_ajax_response(void) {
1262 struct wcsession *WCC = WC;
1264 FlushStrBuf(WCC->HBuf);
1265 output_headers(0, 0, 0, 0, 0, 0);
1267 hprintf("Content-type: text/html; charset=UTF-8\r\n"
1269 "Connection: close\r\n"
1276 * print ajax response footer
1278 void end_ajax_response(void) {
1283 * Wraps a Citadel server command in an AJAX transaction.
1285 void ajax_servcmd(void)
1288 char gcontent[1024];
1292 begin_ajax_response();
1294 serv_printf("%s", bstr("g_cmd"));
1295 serv_getln(buf, sizeof buf);
1296 wprintf("%s\n", buf);
1298 if (buf[0] == '8') {
1299 serv_printf("\n\n000");
1301 if ((buf[0] == '1') || (buf[0] == '8')) {
1302 while (serv_getln(gcontent, sizeof gcontent), strcmp(gcontent, "000")) {
1303 wprintf("%s\n", gcontent);
1307 if (buf[0] == '4') {
1308 text_to_server(bstr("g_input"));
1311 if (buf[0] == '6') {
1312 len = atol(&buf[4]);
1314 serv_read(junk, len);
1317 if (buf[0] == '7') {
1318 len = atol(&buf[4]);
1320 memset(junk, 0, len);
1321 serv_write(junk, len);
1325 end_ajax_response();
1328 * This is kind of an ugly hack, but this is the only place it can go.
1329 * If the command was GEXP, then the instant messenger window must be
1330 * running, so reset the "last_pager_check" watchdog timer so
1331 * that page_popup() doesn't try to open it a second time.
1333 if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) {
1334 WC->last_pager_check = time(NULL);
1340 * Helper function for the asynchronous check to see if we need
1341 * to open the instant messenger window.
1343 void seconds_since_last_gexp(void)
1347 if ( (time(NULL) - WC->last_pager_check) < 30) {
1353 serv_getln(buf, sizeof buf);
1354 if (buf[3] == '*') {
1364 * \brief Detects a 'mobile' user agent
1366 int is_mobile_ua(char *user_agent) {
1367 if (strstr(user_agent,"iPhone OS") != NULL) {
1369 } else if (strstr(user_agent,"Windows CE") != NULL) {
1371 } else if (strstr(user_agent,"SymbianOS") != NULL) {
1373 } else if (strstr(user_agent, "Opera Mobi") != NULL) {
1375 } else if (strstr(user_agent, "Firefox/2.0.0 Opera 9.51 Beta") != NULL) {
1376 // For some reason a new install of Opera 9.51beta decided to spoof.
1384 * Entry point for WebCit transaction
1386 void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method, StrBuf *ReadBuf)
1388 const char *pch, *pchs, *pche;
1395 int a, nBackDots, nEmpty;
1396 int ContentLength = 0;
1397 StrBuf *ContentType = NULL;
1398 StrBuf *UrlLine = NULL;
1399 StrBuf *content = NULL;
1400 const char *content_end = NULL;
1401 char browser_host[256];
1402 char user_agent[256];
1408 * We stuff these with the values coming from the client cookies,
1409 * so we can use them to reconnect a timed out session if we have to.
1411 char c_username[SIZ];
1412 char c_password[SIZ];
1413 char c_roomname[SIZ];
1414 char c_httpauth_string[SIZ];
1415 char c_httpauth_user[SIZ];
1416 char c_httpauth_pass[SIZ];
1417 struct wcsession *WCC;
1419 safestrncpy(c_username, "", sizeof c_username);
1420 safestrncpy(c_password, "", sizeof c_password);
1421 safestrncpy(c_roomname, "", sizeof c_roomname);
1422 safestrncpy(c_httpauth_string, "", sizeof c_httpauth_string);
1423 safestrncpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER, sizeof c_httpauth_user);
1424 safestrncpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS, sizeof c_httpauth_pass);
1425 strcpy(browser_host, "");
1428 if (WCC->WBuf == NULL)
1429 WC->WBuf = NewStrBufPlain(NULL, 32768);
1430 FlushStrBuf(WCC->WBuf);
1432 if (WCC->HBuf == NULL)
1433 WCC->HBuf = NewStrBuf();
1434 FlushStrBuf(WCC->HBuf);
1436 WCC->upload_length = 0;
1439 WCC->trailing_javascript = NewStrBuf();
1441 /** Figure out the action */
1443 sizes[0] = sizeof action;
1446 index[a] = arg[a-1];
1447 sizes[a] = sizeof arg[a-1];
1449 //// index[9] = &foo; todo
1452 for ( a = 0; a < 9; ++a)
1454 extract_token(index[a], ChrPtr(ReqLine), a + 1, '/', sizes[a]);
1455 if (strstr(index[a], "?")) *strstr(index[a], "?") = 0;
1456 if (strstr(index[a], "&")) *strstr(index[a], "&") = 0;
1457 if (strstr(index[a], " ")) *strstr(index[a], " ") = 0;
1458 if ((index[a][0] == '.') && (index[a][1] == '.'))
1460 if (index[a][0] == '\0')
1465 if (GetHash(HTTPHeaders, HKEY("COOKIE"), &vLine) &&
1467 cookie_to_stuff((StrBuf *)vLine, NULL,
1468 c_username, sizeof c_username,
1469 c_password, sizeof c_password,
1470 c_roomname, sizeof c_roomname);
1472 if (GetHash(HTTPHeaders, HKEY("AUTHORIZATION"), &vLine) &&
1474 CtdlDecodeBase64(c_httpauth_string, ChrPtr((StrBuf*)vLine), StrLength((StrBuf*)vLine));
1475 extract_token(c_httpauth_user, c_httpauth_string, 0, ':', sizeof c_httpauth_user);
1476 extract_token(c_httpauth_pass, c_httpauth_string, 1, ':', sizeof c_httpauth_pass);
1478 if (GetHash(HTTPHeaders, HKEY("CONTENT-LENGTH"), &vLine) &&
1480 ContentLength = StrToi((StrBuf*)vLine);
1482 if (GetHash(HTTPHeaders, HKEY("CONTENT-TYPE"), &vLine) &&
1484 ContentType = (StrBuf*)vLine;
1486 if (GetHash(HTTPHeaders, HKEY("USER-AGENT"), &vLine) &&
1488 safestrncpy(user_agent, ChrPtr((StrBuf*)vLine), sizeof user_agent);
1490 if ((WCC->is_mobile < 0) && is_mobile_ua(&buf[12])) {
1499 GetHash(HTTPHeaders, HKEY("X-FORWARDED-HOST"), &vLine) &&
1501 safestrncpy(WCC->http_host,
1502 ChrPtr((StrBuf*)vLine),
1503 sizeof WCC->http_host);
1505 if (IsEmptyStr(WCC->http_host) &&
1506 GetHash(HTTPHeaders, HKEY("HOST"), &vLine) &&
1508 safestrncpy(WCC->http_host,
1509 ChrPtr((StrBuf*)vLine),
1510 sizeof WCC->http_host);
1513 if (GetHash(HTTPHeaders, HKEY("X-FORWARDED-FOR"), &vLine) &&
1515 safestrncpy(browser_host,
1516 ChrPtr((StrBuf*) vLine),
1517 sizeof browser_host);
1518 while (num_tokens(browser_host, ',') > 1) {
1519 remove_token(browser_host, 0, ',');
1521 striplt(browser_host);
1524 if (ContentLength > 0) {
1525 content = NewStrBuf();
1526 StrBufPrintf(content, "Content-type: %s\n"
1527 "Content-length: %d\n\n",
1528 ChrPtr(ContentType), ContentLength);
1530 hprintf("Content-type: %s\n"
1531 "Content-length: %d\n\n",
1532 ContentType, ContentLength);
1534 body_start = StrLength(content);
1536 /** Read the entire input data at once. */
1537 client_read(&WCC->http_sock, content, ReadBuf, ContentLength + body_start);
1539 if (!strncasecmp(ChrPtr(ContentType), "application/x-www-form-urlencoded", 33)) {
1540 StrBufCutLeft(content, body_start);
1541 ParseURLParams(content);
1542 } else if (!strncasecmp(ChrPtr(ContentType), "multipart", 9)) {
1543 content_end = ChrPtr(content) + ContentLength + body_start;
1544 mime_parser(ChrPtr(content), content_end, *upload_handler, NULL, NULL, NULL, 0);
1550 /* make a note of where we are in case the user wants to save it */
1551 safestrncpy(WCC->this_page, ChrPtr(ReqLine), sizeof(WCC->this_page));
1552 remove_token(WCC->this_page, 2, ' ');
1553 remove_token(WCC->this_page, 0, ' ');
1555 /* If there are variables in the URL, we must grab them now */
1556 UrlLine = NewStrBufDup(ReqLine);
1557 len = StrLength(UrlLine);
1558 pch = pchs = ChrPtr(UrlLine);
1560 while (pch < pche) {
1561 if ((*pch == '?') || (*pch == '&')) {
1562 StrBufCutLeft(UrlLine, pch - pchs + 1);
1563 ParseURLParams(UrlLine);
1568 FreeStrBuf(&UrlLine);
1570 /* If it's a "force 404" situation then display the error and bail. */
1571 if (!strcmp(action, "404")) {
1572 hprintf("HTTP/1.1 404 Not found\r\n");
1573 hprintf("Content-Type: text/plain\r\n");
1574 wprintf("Not found\r\n");
1576 goto SKIP_ALL_THIS_CRAP;
1579 /* Static content can be sent without connecting to Citadel. */
1581 for (a=0; a<ndirs && ! is_static; ++a) {
1582 if (!strcasecmp(action, (char*)static_content_dirs[a])) { /* map web to disk location */
1590 snprintf(buf, sizeof buf, "%s/%s/%s/%s/%s/%s/%s/%s",
1591 static_dirs[n_static],
1592 index[1], index[2], index[3], index[4], index[5], index[6], index[7]);
1593 for (a=0; a<8; ++a) {
1594 if (buf[strlen(buf)-1] == '/') {
1595 buf[strlen(buf)-1] = 0;
1598 for (a = 0; a < strlen(buf); ++a) {
1599 if (isspace(buf[a])) {
1607 lprintf(9, "Suspicious request. Ignoring.");
1608 hprintf("HTTP/1.1 404 Security check failed\r\n");
1609 hprintf("Content-Type: text/plain\r\n");
1610 wprintf("You have sent a malformed or invalid request.\r\n");
1613 goto SKIP_ALL_THIS_CRAP; /* Don't try to connect */
1616 /* If the client sent a nonce that is incorrect, kill the request. */
1617 if (strlen(bstr("nonce")) > 0) {
1618 lprintf(9, "Comparing supplied nonce %s to session nonce %ld\n",
1619 bstr("nonce"), WCC->nonce);
1620 if (ibstr("nonce") != WCC->nonce) {
1621 lprintf(9, "Ignoring request with mismatched nonce.\n");
1622 hprintf("HTTP/1.1 404 Security check failed\r\n");
1623 hprintf("Content-Type: text/plain\r\n");
1624 wprintf("Security check failed.\r\n");
1626 goto SKIP_ALL_THIS_CRAP;
1631 * If we're not connected to a Citadel server, try to hook up the
1634 if (!WCC->connected) {
1635 if (!strcasecmp(ctdlhost, "uds")) {
1636 /* unix domain socket */
1637 snprintf(buf, SIZ, "%s/citadel.socket", ctdlport);
1638 WCC->serv_sock = uds_connectsock(buf);
1642 WCC->serv_sock = tcp_connectsock(ctdlhost, ctdlport);
1645 if (WCC->serv_sock < 0) {
1647 goto SKIP_ALL_THIS_CRAP;
1651 serv_getln(buf, sizeof buf); /** get the server welcome message */
1654 * From what host is our user connecting? Go with
1655 * the host at the other end of the HTTP socket,
1656 * unless we are following X-Forwarded-For: headers
1657 * and such a header has already turned up something.
1659 if ( (!follow_xff) || (strlen(browser_host) == 0) ) {
1660 locate_host(browser_host, WCC->http_sock);
1663 get_serv_info(browser_host, user_agent);
1664 if (serv_info.serv_rev_level < MINIMUM_CIT_VERSION) {
1666 wprintf(_("You are connected to a Citadel "
1667 "server running Citadel %d.%02d. \n"
1668 "In order to run this version of WebCit "
1669 "you must also have Citadel %d.%02d or"
1671 serv_info.serv_rev_level / 100,
1672 serv_info.serv_rev_level % 100,
1673 MINIMUM_CIT_VERSION / 100,
1674 MINIMUM_CIT_VERSION % 100
1677 end_webcit_session();
1678 goto SKIP_ALL_THIS_CRAP;
1682 ////////todo: restore language in this case
1684 * Functions which can be performed without logging in
1686 if (!strcasecmp(action, "listsub")) {
1688 goto SKIP_ALL_THIS_CRAP;
1690 if (!strcasecmp(action, "freebusy")) {
1691 do_freebusy(ChrPtr(ReqLine));
1692 goto SKIP_ALL_THIS_CRAP;
1696 * If we're not logged in, but we have HTTP Authentication data,
1697 * try logging in to Citadel using that.
1699 if ((!WCC->logged_in)
1700 && (strlen(c_httpauth_user) > 0)
1701 && (strlen(c_httpauth_pass) > 0)) {
1702 serv_printf("USER %s", c_httpauth_user);
1703 serv_getln(buf, sizeof buf);
1704 if (buf[0] == '3') {
1705 serv_printf("PASS %s", c_httpauth_pass);
1706 serv_getln(buf, sizeof buf);
1707 if (buf[0] == '2') {
1708 become_logged_in(c_httpauth_user,
1709 c_httpauth_pass, buf);
1710 safestrncpy(WCC->httpauth_user, c_httpauth_user, sizeof WCC->httpauth_user);
1711 safestrncpy(WCC->httpauth_pass, c_httpauth_pass, sizeof WCC->httpauth_pass);
1713 /* Should only display when password is wrong */
1714 authorization_required(&buf[4]);
1715 goto SKIP_ALL_THIS_CRAP;
1720 /* This needs to run early */
1722 if (!strcasecmp(action, "rss")) {
1723 display_rss(bstr("room"), request_method);
1724 goto SKIP_ALL_THIS_CRAP;
1729 * The GroupDAV stuff relies on HTTP authentication instead of
1730 * our session's authentication.
1732 if (!strncasecmp(action, "groupdav", 8)) {
1733 groupdav_main(HTTPHeaders,
1734 ReqLine, request_method,
1735 ContentType, /* do GroupDAV methods */
1736 ContentLength, content, body_start);
1737 if (!WCC->logged_in) {
1738 WCC->killthis = 1; /* If not logged in, don't */
1739 } /* keep the session active */
1740 goto SKIP_ALL_THIS_CRAP;
1745 * Automatically send requests with any method other than GET or
1746 * POST to the GroupDAV code as well.
1748 if ((strcasecmp(ChrPtr(request_method), "GET")) && (strcasecmp(ChrPtr(request_method), "POST"))) {
1749 groupdav_main(HTTPHeaders, ReqLine,
1750 request_method, ContentType, /** do GroupDAV methods */
1751 ContentLength, content, body_start);
1752 if (!WCC->logged_in) {
1753 WCC->killthis = 1; /** If not logged in, don't */
1754 } /** keep the session active */
1755 goto SKIP_ALL_THIS_CRAP;
1759 * If we're not logged in, but we have username and password cookies
1760 * supplied by the browser, try using them to log in.
1762 if ((!WCC->logged_in)
1763 && (!IsEmptyStr(c_username))
1764 && (!IsEmptyStr(c_password))) {
1765 serv_printf("USER %s", c_username);
1766 serv_getln(buf, sizeof buf);
1767 if (buf[0] == '3') {
1768 serv_printf("PASS %s", c_password);
1769 serv_getln(buf, sizeof buf);
1770 if (buf[0] == '2') {
1772 become_logged_in(c_username, c_password, buf);
1773 if (get_preference("language", &Lang)) {
1774 set_selected_language(ChrPtr(Lang));
1775 go_selected_language(); /* set locale */
1777 get_preference("default_header_charset", &WCC->DefaultCharset);
1782 * If we don't have a current room, but a cookie specifying the
1783 * current room is supplied, make an effort to go there.
1785 if ((IsEmptyStr(WCC->wc_roomname)) && (!IsEmptyStr(c_roomname))) {
1786 serv_printf("GOTO %s", c_roomname);
1787 serv_getln(buf, sizeof buf);
1788 if (buf[0] == '2') {
1789 safestrncpy(WCC->wc_roomname, c_roomname, sizeof WCC->wc_roomname);
1793 if (!strcasecmp(action, "image")) {
1795 } else if (!strcasecmp(action, "display_mime_icon")) {
1796 display_mime_icon();
1800 WebcitHandler *Handler;
1802 GetHash(HandlerHash, action, strlen(action) /* TODO*/, &vHandler),
1803 Handler = (WebcitHandler*) vHandler;
1804 if (Handler != NULL) {
1805 if (!WCC->logged_in && ((Handler->Flags & ANONYMOUS) == 0)) {
1806 display_login(NULL);
1809 if((Handler->Flags & NEED_URL)) {
1810 if (WCC->UrlFragment1 == NULL)
1811 WCC->UrlFragment1 = NewStrBuf();
1812 if (WCC->UrlFragment2 == NULL)
1813 WCC->UrlFragment2 = NewStrBuf();
1814 StrBufPrintf(WCC->UrlFragment1, "%s", index[1]);
1815 StrBufPrintf(WCC->UrlFragment2, "%s", index[2]);
1817 if ((Handler->Flags & AJAX) != 0)
1818 begin_ajax_response();
1820 if ((Handler->Flags & AJAX) != 0)
1821 end_ajax_response();
1824 /* When all else fais, display the main menu. */
1826 if (!WCC->logged_in)
1827 display_login(NULL);
1829 display_main_menu();
1834 if (content != NULL) {
1835 FreeStrBuf(&content);
1839 if (WCC->upload_length > 0) {
1841 WCC->upload_length = 0;
1843 FreeStrBuf(&WCC->trailing_javascript);
1848 * Replacement for sleep() that uses select() in order to avoid SIGALRM
1850 void sleeeeeeeeeep(int seconds)
1854 tv.tv_sec = seconds;
1856 select(0, NULL, NULL, NULL, &tv);
1859 void diagnostics(void)
1861 output_headers(1, 1, 1, 0, 0, 0);
1862 wprintf("Session: %d<hr />\n", WC->wc_session);
1863 wprintf("Command: <br /><PRE>\n");
1864 StrEscPuts(WC->UrlFragment1);
1865 wprintf("<br />\n");
1866 StrEscPuts(WC->UrlFragment2);
1867 wprintf("</PRE><hr />\n");
1868 wprintf("Variables: <br /><PRE>\n");
1870 wprintf("</PRE><hr />\n");
1874 void view_mimepart(void) {
1875 mimepart(ChrPtr(WC->UrlFragment1),
1876 ChrPtr(WC->UrlFragment2),
1880 void download_mimepart(void) {
1881 mimepart(ChrPtr(WC->UrlFragment1),
1882 ChrPtr(WC->UrlFragment2),
1886 void view_postpart(void) {
1887 postpart(WC->UrlFragment1,
1892 void download_postpart(void) {
1893 postpart(WC->UrlFragment1,
1899 int ConditionalImportantMesage(WCTemplateToken *Tokens, void *Context, int ContextType)
1901 struct wcsession *WCC = WC;
1903 return (!IsEmptyStr(WCC->ImportantMessage));
1908 void tmplput_importantmessage(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
1910 struct wcsession *WCC = WC;
1914 StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType,
1915 WCC->ImportantMessage, 0);
1917 WCC->ImportantMessage[0] = '\0';
1918 StrEscAppend(Target, NULL, WCC->ImportantMessage, 0, 0);
1919 WCC->ImportantMessage[0] = '\0';
1923 int ConditionalBstr(WCTemplateToken *Tokens, void *Context, int ContextType)
1925 if(Tokens->nParameters == 3)
1926 return HaveBstr(Tokens->Params[2]->Start,
1927 Tokens->Params[2]->len);
1929 return strcmp(Bstr(Tokens->Params[2]->Start,
1930 Tokens->Params[2]->len),
1931 Tokens->Params[3]->Start) == 0;
1934 void tmplput_bstr(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
1936 const StrBuf *Buf = SBstr(Tokens->Params[0]->Start,
1937 Tokens->Params[0]->len);
1939 StrBufAppendTemplate(Target, nArgs, Tokens,
1940 Context, ContextType,
1945 void tmplput_csslocal(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
1947 extern StrBuf *csslocal;
1948 StrBufAppendBuf(Target,
1961 WebcitAddUrlHandler(HKEY("blank"), blank_page, ANONYMOUS);
1962 WebcitAddUrlHandler(HKEY("do_template"), url_do_template, ANONYMOUS);
1963 WebcitAddUrlHandler(HKEY("sslg"), seconds_since_last_gexp, AJAX);
1964 WebcitAddUrlHandler(HKEY("ajax_servcmd"), ajax_servcmd, 0);
1965 WebcitAddUrlHandler(HKEY("change_start_page"), change_start_page, 0);
1966 WebcitAddUrlHandler(HKEY("toggle_self_service"), toggle_self_service, 0);
1967 WebcitAddUrlHandler(HKEY("vcardphoto"), display_vcard_photo_img, NEED_URL);
1968 WebcitAddUrlHandler(HKEY("mimepart"), view_mimepart, NEED_URL);
1969 WebcitAddUrlHandler(HKEY("mimepart_download"), download_mimepart, NEED_URL);
1970 WebcitAddUrlHandler(HKEY("postpart"), view_postpart, NEED_URL);
1971 WebcitAddUrlHandler(HKEY("postpart_download"), download_postpart, NEED_URL);
1972 WebcitAddUrlHandler(HKEY("diagnostics"), diagnostics, NEED_URL);
1974 RegisterConditional(HKEY("COND:IMPMSG"), 0, ConditionalImportantMesage, CTX_NONE);
1975 RegisterConditional(HKEY("COND:BSTR"), 1, ConditionalBstr, CTX_NONE);
1976 RegisterNamespace("BSTR", 1, 2, tmplput_bstr, CTX_NONE);
1977 RegisterNamespace("CSSLOCAL", 0, 0, tmplput_csslocal, CTX_NONE);
1978 RegisterNamespace("IMPORTANTMESSAGE", 0, 0, tmplput_importantmessage, CTX_NONE);
1979 RegisterNamespace("OFFERSTARTPAGE", 0, 0, offer_start_page, CTX_NONE);
1980 RegisterNamespace("TRAILING_JAVASCRIPT", 0, 0, tmplput_trailing_javascript, CTX_NONE);