2 * This is the main transaction loop of the web service. It maintains a
3 * persistent session to the Citadel server, handling HTTP WebCit requests as
4 * they arrive and presenting a user interface.
6 * Copyright (c) 1996-2011 by the citadel.org team
8 * This program is open source software. You can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 3 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #define SHOW_ME_VAPPEND_PRINTF
28 #include "webserver.h"
30 StrBuf *csslocal = NULL;
31 HashList *HandlerHash = NULL;
33 void PutRequestLocalMem(void *Data, DeleteHashDataFunc DeleteIt)
38 n = GetCount(WCC->Hdr->HTTPHeaders);
39 Put(WCC->Hdr->HTTPHeaders, IKEY(n), Data, DeleteIt);
42 void DeleteWebcitHandler(void *vHandler)
44 WebcitHandler *Handler = (WebcitHandler*) vHandler;
45 FreeStrBuf(&Handler->Name);
46 FreeStrBuf(&Handler->DisplayName);
50 void WebcitAddUrlHandler(const char * UrlString, long UrlSLen,
51 const char *DisplayName, long dslen,
55 WebcitHandler *NewHandler;
56 NewHandler = (WebcitHandler*) malloc(sizeof(WebcitHandler));
58 NewHandler->Flags = Flags;
59 NewHandler->Name = NewStrBufPlain(UrlString, UrlSLen);
60 StrBufShrinkToFit(NewHandler->Name, 1);
61 NewHandler->DisplayName = NewStrBufPlain(DisplayName, dslen);
62 StrBufShrinkToFit(NewHandler->DisplayName, 1);
63 Put(HandlerHash, UrlString, UrlSLen, NewHandler, DeleteWebcitHandler);
66 void tmplput_HANDLER_DISPLAYNAME(StrBuf *Target, WCTemplputParams *TP)
69 if (WCC->Hdr->HR.Handler != NULL)
70 StrBufAppendTemplate(Target, TP, WCC->Hdr->HR.Handler->DisplayName, 0);
75 * web-printing funcion. uses our vsnprintf wrapper
77 #ifdef UBER_VERBOSE_DEBUGGING
78 void wcc_printf(const char *FILE, const char *FUNCTION, long LINE, const char *format,...)
80 void wc_printf(const char *format,...)
86 if (WCC->WBuf == NULL)
87 WCC->WBuf = NewStrBuf();
88 #ifdef UBER_VERBOSE_DEBUGGING
89 StrBufAppendPrintf(WCC->WBuf, "\n%s:%s:%d[", FILE, FUNCTION, LINE);
92 va_start(arg_ptr, format);
93 StrBufVAppendPrintf(WCC->WBuf, format, arg_ptr);
95 #ifdef UBER_VERBOSE_DEBUGGING
96 StrBufAppendPrintf(WCC->WBuf, "]\n");
101 * http-header-printing funcion. uses our vsnprintf wrapper
103 void hprintf(const char *format,...)
108 va_start(arg_ptr, format);
109 StrBufVAppendPrintf(WCC->HBuf, format, arg_ptr);
116 * wrap up an HTTP session, closes tags, etc.
118 * print_standard_html_footer should be set to:
119 * 0 - to transmit only,
120 * nonzero - to append the closing tags
122 void wDumpContent(int print_standard_html_footer)
124 if (print_standard_html_footer) {
125 wc_printf("</div> <!-- end of 'content' div -->\n");
126 do_template("trailing", NULL);
129 /* If we've been saving it all up for one big output burst,
130 * go ahead and do that now.
139 * Output HTTP headers and leading HTML for a page
141 void output_headers( int do_httpheaders, /* 1 = output HTTP headers */
142 int do_htmlhead, /* 1 = output HTML <head> section and <body> opener */
144 int do_room_banner, /* 0=no, 1=yes,
145 * 2 = I'm going to embed my own, so don't open the
146 * <div id="content"> either.
149 int unset_cookies, /* 1 = session is terminating, so unset the cookies */
150 int suppress_check, /* 1 = suppress check for instant messages */
151 int cache /* 1 = allow browser to cache this page */
156 hprintf("HTTP/1.1 200 OK\n");
157 http_datestring(httpnow, sizeof httpnow, time(NULL));
159 if (do_httpheaders) {
160 if (WCC->serv_info != NULL)
161 hprintf("Content-type: text/html; charset=utf-8\r\n"
163 "Connection: close\r\n",
165 ChrPtr(WCC->serv_info->serv_software));
167 hprintf("Content-type: text/html; charset=utf-8\r\n"
168 "Server: %s / [n/a]\n"
169 "Connection: close\r\n",
174 char httpTomorow[128];
176 http_datestring(httpTomorow, sizeof httpTomorow,
177 time(NULL) + 60 * 60 * 24 * 2);
179 hprintf("Pragma: public\r\n"
180 "Cache-Control: max-age=3600, must-revalidate\r\n"
181 "Last-modified: %s\r\n"
188 hprintf("Pragma: no-cache\r\n"
189 "Cache-Control: no-store\r\n"
194 if (cache < 2) stuff_to_cookie(unset_cookies);
198 do_template("head", NULL);
200 /* check for ImportantMessages (these display in a div overlaying the main screen) */
201 if (!IsEmptyStr(WCC->ImportantMessage)) {
202 wc_printf("<div id=\"important_message\">\n"
203 "<span class=\"imsg\">");
204 StrEscAppend(WCC->WBuf, NULL, WCC->ImportantMessage, 0, 0);
205 wc_printf("</span><br>\n"
208 StrBufAppendBufPlain(WCC->trailing_javascript,
209 HKEY("setTimeout('hide_imsg_popup()', 5000); \n"),
212 WCC->ImportantMessage[0] = 0;
214 else if (StrLength(WCC->ImportantMsg) > 0) {
215 wc_printf("<div id=\"important_message\">\n"
216 "<span class=\"imsg\">");
217 StrEscAppend(WCC->WBuf, WCC->ImportantMsg, NULL, 0, 0);
218 wc_printf("</span><br>\n"
221 StrBufAppendBufPlain(WCC->trailing_javascript,
222 HKEY("setTimeout('hide_imsg_popup()', 5000); \n"),
225 FlushStrBuf(WCC->ImportantMsg);
227 if ( (WCC->logged_in) && (!unset_cookies) ) {
228 DoTemplate(HKEY("paging"), NULL, &NoCtx);
231 if (do_room_banner == 1) {
232 tmplput_roombanner(NULL, NULL);
236 if (do_room_banner == 1) {
237 wc_printf("<div id=\"content\">\n");
241 void output_custom_content_header(const char *ctype) {
242 hprintf("HTTP/1.1 200 OK\r\n");
243 hprintf("Content-type: %s; charset=utf-8\r\n",ctype);
244 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
245 hprintf("Connection: close\r\n");
250 * Generic function to do an HTTP redirect. Easy and fun.
252 void http_redirect(const char *whichpage) {
253 hprintf("HTTP/1.1 302 Moved Temporarily\n");
254 hprintf("Location: %s\r\n", whichpage);
255 hprintf("URI: %s\r\n", whichpage);
256 hprintf("Content-type: text/html; charset=utf-8\r\n");
258 wc_printf("<html><body>");
259 wc_printf("Go <a href=\"%s\">here</A>.", whichpage);
260 wc_printf("</body></html>\n");
267 * Output a piece of content to the web browser using conformant HTTP and MIME semantics
269 void http_transmit_thing(const char *content_type, int is_static)
272 syslog(9, "http_transmit_thing(%s)%s\n", content_type, ((is_static > 0) ? " (static)" : ""));
273 output_headers(0, 0, 0, 0, 0, is_static);
275 hprintf("Content-type: %s\r\n"
277 "Connection: close\r\n",
286 * Convenience functions to display a page containing only a string
288 * titlebarcolor color of the titlebar of the frame
289 * titlebarmsg text to display in the title bar
290 * messagetext body of the box
292 void convenience_page(const char *titlebarcolor, const char *titlebarmsg, const char *messagetext)
294 hprintf("HTTP/1.1 200 OK\n");
295 output_headers(1, 1, 2, 0, 0, 0);
296 wc_printf("<div id=\"banner\">\n");
297 wc_printf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
298 wc_printf("<span class=\"titlebar\">%s</span>\n", titlebarmsg);
299 wc_printf("</td></tr></table>\n");
300 wc_printf("</div>\n<div id=\"content\">\n");
301 escputs(messagetext);
303 wc_printf("<hr />\n");
309 * Display a blank page.
311 void blank_page(void) {
312 output_headers(1, 1, 0, 0, 0, 0);
318 * A template has been requested
320 void url_do_template(void) {
321 const StrBuf *MimeType;
322 const StrBuf *Tmpl = sbstr("template");
324 MimeType = DoTemplate(SKEY(Tmpl), NULL, &NoCtx);
325 http_transmit_thing(ChrPtr(MimeType), 0);
331 * convenience function to indicate success
333 void display_success(char *successmessage)
335 convenience_page("007700", "OK", successmessage);
340 * Authorization required page (sends a 401, causing the browser to request login credentials)
342 void authorization_required(void)
345 const char *message = "";
347 hprintf("HTTP/1.1 401 Authorization Required\r\n");
349 "Server: %s / %s\r\n"
350 "Connection: close\r\n",
351 PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software)
353 hprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n", ChrPtr(WC->serv_info->serv_humannode));
354 hprintf("Content-Type: text/html\r\n");
357 wc_printf(_("Authorization Required"));
358 wc_printf("</h1>\r\n");
361 if (WCC->ImportantMsg != NULL)
362 message = ChrPtr(WCC->ImportantMsg);
363 else if (WCC->ImportantMessage != NULL)
364 message = WCC->ImportantMessage;
366 wc_printf(_("The resource you requested requires a valid username and password. "
367 "You could not be logged in: %s\n"), message);
369 end_webcit_session();
373 * Convenience functions to wrap around asynchronous ajax responses
375 void begin_ajax_response(void) {
378 FlushStrBuf(WCC->HBuf);
379 output_headers(0, 0, 0, 0, 0, 0);
381 hprintf("Content-type: text/html; charset=UTF-8\r\n"
383 "Connection: close\r\n"
390 * print ajax response footer
392 void end_ajax_response(void) {
399 * Wraps a Citadel server command in an AJAX transaction.
401 void ajax_servcmd(void)
409 syslog(LOG_DEBUG, "ajax_servcmd() g_cmd=\"%s\"\n", bstr("g_cmd") );
410 begin_ajax_response();
412 serv_puts(bstr("g_cmd"));
413 StrBuf_ServGetln(Buf);
414 StrBufAppendBuf(WCC->WBuf, Buf, 0);
415 StrBufAppendBufPlain(WCC->WBuf, HKEY("\n"), 0);
417 switch (GetServerStatus(Buf, NULL)) {
419 serv_puts("\n\n000");
420 if ( (StrLength(Buf)==3) &&
421 !strcmp(ChrPtr(Buf), "000")) {
422 StrBufAppendBufPlain(WCC->WBuf, HKEY("\000"), 0);
427 StrBuf_ServGetln(Buf);
428 if ( (StrLength(Buf)==3) &&
429 !strcmp(ChrPtr(Buf), "000")) {
432 StrBufAppendBuf(WCC->WBuf, Buf, 0);
433 StrBufAppendBufPlain(WCC->WBuf, HKEY("\n"), 0);
437 text_to_server(bstr("g_input"));
441 len = atol(&ChrPtr(Buf)[4]);
442 StrBuf_ServGetBLOBBuffered(Buf, len);
445 len = atol(&ChrPtr(Buf)[4]);
447 memset(junk, 0, len);
448 serv_write(junk, len);
455 * This is kind of an ugly hack, but this is the only place it can go.
456 * If the command was GEXP, then the instant messenger window must be
457 * running, so reset the "last_pager_check" watchdog timer so
458 * that page_popup() doesn't try to open it a second time.
460 if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) {
461 WCC->last_pager_check = time(NULL);
468 * Helper function for the asynchronous check to see if we need
469 * to open the instant messenger window.
471 void seconds_since_last_gexp(void)
475 if ( (time(NULL) - WC->last_pager_check) < 30) {
481 serv_getln(buf, sizeof buf);
493 * Save a URL destination so we can go to it later
495 void push_destination(void) {
499 wc_printf("no session");
503 FreeStrBuf(&WCC->PushedDestination);
504 WCC->PushedDestination = NewStrBufDup(SBSTR("url"));
505 syslog(9, "Push: %s\n", ChrPtr(WCC->PushedDestination));
510 * Go to the URL saved by push_destination()
512 void pop_destination(void) {
515 if ((WCC) && (WCC->need_regi)) {
521 if ( (!WCC) || (WCC->PushedDestination == NULL) || (StrLength(WCC->PushedDestination) == 0) ) {
526 syslog(9, "Pop: %s\n", ChrPtr(WCC->PushedDestination));
527 http_redirect(ChrPtr(WCC->PushedDestination));
532 int ReadPostData(void)
535 int urlencoded_post = 0;
537 StrBuf *content = NULL;
539 urlencoded_post = (strncasecmp(ChrPtr(WCC->Hdr->HR.ContentType), "application/x-www-form-urlencoded", 33) == 0) ;
541 content = NewStrBufPlain(NULL, WCC->Hdr->HR.ContentLength + 256);
543 if (!urlencoded_post)
545 StrBufPrintf(content,
547 "Content-length: %ld\n\n",
548 ChrPtr(WCC->Hdr->HR.ContentType),
549 WCC->Hdr->HR.ContentLength);
552 /** Read the entire input data at once. */
553 rc = client_read_to(WCC->Hdr, content,
554 WCC->Hdr->HR.ContentLength,
560 if (urlencoded_post) {
561 ParseURLParams(content);
562 } else if (!strncasecmp(ChrPtr(WCC->Hdr->HR.ContentType), "multipart", 9)) {
567 len = StrLength(content);
568 Buf = SmashStrBuf(&content);
570 mime_parser(Buf, BufEnd, *upload_handler, NULL, NULL, NULL, 0);
572 } else if (WCC->Hdr->HR.ContentLength > 0) {
573 WCC->upload = content;
574 WCC->upload_length = StrLength(WCC->upload);
577 FreeStrBuf(&content);
582 void ParseREST_URL(void)
585 StrBuf *pFloor = NULL;
588 const char *pCh = NULL;
592 syslog(1, "parsing rest URL: %s\n", ChrPtr(WCC->Hdr->HR.ReqLine));
594 WCC->Directory = NewHash(1, Flathash);
595 WCC->CurrentFloor = NULL;
598 while (StrBufExtract_NextToken(Buf, WCC->Hdr->HR.ReqLine, &pCh, '/') >= 0)
600 if (StrLength(Buf) != 0) {
601 /* ignore empty path segments */
602 StrBufUnescape(Buf, 1);
603 Put(WCC->Directory, IKEY(i), Buf, HFreeStrBuf);
614 Floors = GetFloorListHash(NULL, NULL);
618 if (GetHash(WCC->FloorsByName, SKEY(pFloor), &vFloor))
619 WCC->CurrentFloor = (Floor*) vFloor;
624 int Conditional_REST_DEPTH(StrBuf *Target, WCTemplputParams *TP)
630 if (WCC->Hdr->HR.Handler != NULL)
632 Depth = GetTemplateTokenNumber(Target, TP, 2, 0);
633 IsDepth = GetCount(WCC->Directory) + offset;
635 // LogTemplateError(Target, "bla", 1, TP, "REST_DEPTH: %ld : %ld\n", Depth, IsDepth);
638 return IsDepth > Depth;
641 return Depth == IsDepth;
647 * Entry point for WebCit transaction
649 void session_loop(void)
656 * We stuff these with the values coming from the client cookies,
657 * so we can use them to reconnect a timed out session if we have to.
662 WCC->upload_length = 0;
664 WCC->Hdr->nWildfireHeaders = 0;
665 if (WCC->Hdr->HR.Handler != NULL)
666 Flags = WCC->Hdr->HR.Handler->Flags; /* so we can temporarily add our own... */
668 if (WCC->Hdr->HR.ContentLength > 0) {
669 if (ReadPostData() < 0) {
675 WCC->trailing_javascript = NewStrBuf();
677 /* Convert base64-encoded URL's back to plain text */
678 if (!strncmp(ChrPtr(WCC->Hdr->this_page), "/B64", 4)) {
679 StrBufCutLeft(WCC->Hdr->this_page, 4);
680 StrBufDecodeBase64(WCC->Hdr->this_page);
681 http_redirect(ChrPtr(WCC->Hdr->this_page));
682 goto SKIP_ALL_THIS_CRAP;
685 /* If there are variables in the URL, we must grab them now */
686 if (WCC->Hdr->PlainArgs != NULL)
687 ParseURLParams(WCC->Hdr->PlainArgs);
689 /* If the client sent a nonce that is incorrect, kill the request. */
690 if (havebstr("nonce")) {
691 syslog(9, "Comparing supplied nonce %s to session nonce %d\n",
692 bstr("nonce"), WCC->nonce
694 if (ibstr("nonce") != WCC->nonce) {
695 syslog(9, "Ignoring request with mismatched nonce.\n");
696 hprintf("HTTP/1.1 404 Security check failed\r\n");
697 hprintf("Content-Type: text/plain\r\n");
699 wc_printf("Security check failed.\r\n");
701 goto SKIP_ALL_THIS_CRAP;
706 * If we're not connected to a Citadel server, try to hook up the connection now.
708 if (!WCC->connected) {
709 if (GetConnected()) {
710 hprintf("HTTP/1.1 503 Service Unavailable\r\n");
711 hprintf("Content-Type: text/html\r\n");
713 wc_printf("<html><head><title>503 Service Unavailable</title></head><body>\n");
714 wc_printf(_("This program was unable to connect or stay "
715 "connected to the Citadel server. Please report "
716 "this problem to your system administrator.")
719 wc_printf("<a href=\"http://www.citadel.org/doku.php/"
720 "faq:generalquestions:webcit_unable_to_connect\">%s</a>",
723 wc_printf("</body></html>\n");
725 goto SKIP_ALL_THIS_CRAP;
730 * If we're not logged in, but we have authentication data (either from
731 * a cookie or from http-auth), try logging in to Citadel using that.
733 if ((!WCC->logged_in)
734 && (StrLength(WCC->Hdr->c_username) > 0)
735 && (StrLength(WCC->Hdr->c_password) > 0))
740 serv_printf("USER %s", ChrPtr(WCC->Hdr->c_username));
741 StrBuf_ServGetln(Buf);
742 if (GetServerStatus(Buf, &Status) == 3) {
743 serv_printf("PASS %s", ChrPtr(WCC->Hdr->c_password));
744 StrBuf_ServGetln(Buf);
745 if (GetServerStatus(Buf, NULL) == 2) {
746 become_logged_in(WCC->Hdr->c_username,
747 WCC->Hdr->c_password, Buf);
749 /* Should only display when password is wrong */
750 WCC->ImportantMsg = NewStrBufPlain(ChrPtr(Buf) + 4, StrLength(Buf) - 4);
751 authorization_required();
753 goto SKIP_ALL_THIS_CRAP;
756 else if (Status == 541) {
761 xhttp = (WCC->Hdr->HR.eReqType != eGET) &&
762 (WCC->Hdr->HR.eReqType != ePOST) &&
763 (WCC->Hdr->HR.eReqType != eHEAD);
766 * If a 'go' (or 'gotofirst') parameter has been specified, attempt to goto that room
767 * prior to doing anything else.
769 if (havebstr("go")) {
771 syslog(9, "Explicit room selection: %s\n", bstr("go"));
772 ret = gotoroom(sbstr("go")); /* do quietly to avoid session output! */
773 if ((ret/100) != 2) {
774 syslog(1, "Unable to change to [%s]; Reason: %d\n", bstr("go"), ret);
777 else if (havebstr("gotofirst")) {
779 syslog(9, "Explicit room selection: %s\n", bstr("gotofirst"));
780 ret = gotoroom(sbstr("gotofirst")); /* do quietly to avoid session output! */
781 if ((ret/100) != 2) {
782 syslog(1, "Unable to change to [%s]; Reason: %d\n", bstr("gotofirst"), ret);
787 * If we aren't in any room yet, but we have cookie data telling us where we're
788 * supposed to be, and 'go' was not specified, then go there.
790 else if ( (StrLength(WCC->CurRoom.name) == 0) && ( (StrLength(WCC->Hdr->c_roomname) > 0) )) {
793 syslog(9, "We are in '%s' but cookie indicates '%s', going there...\n",
794 ChrPtr(WCC->CurRoom.name),
795 ChrPtr(WCC->Hdr->c_roomname)
797 ret = gotoroom(WCC->Hdr->c_roomname); /* do quietly to avoid session output! */
798 if ((ret/100) != 2) {
799 syslog(1, "COOKIEGOTO: Unable to change to [%s]; Reason: %d\n",
800 ChrPtr(WCC->Hdr->c_roomname), ret);
804 if (WCC->Hdr->HR.Handler != NULL) {
805 if ( (!WCC->logged_in)
806 && ((WCC->Hdr->HR.Handler->Flags & ANONYMOUS) == 0)
807 && (WCC->serv_info->serv_supports_guest == 0)
813 if ((WCC->Hdr->HR.Handler->Flags & PARSE_REST_URL) != 0)
816 if ((WCC->Hdr->HR.Handler->Flags & AJAX) != 0)
817 begin_ajax_response();
818 WCC->Hdr->HR.Handler->F();
819 if ((WCC->Hdr->HR.Handler->Flags & AJAX) != 0)
823 /* When all else fails, display the default landing page or a main menu. */
826 * ordinary browser users get a nice login screen, DAV etc. requsets
827 * are given a 401 so they can handle it appropriate.
829 if (!WCC->logged_in) {
831 authorization_required();
834 display_default_landing_page();
838 * Toplevel dav requests? or just a flat browser request?
856 * Display the appropriate landing page for this site.
858 void display_default_landing_page(void) {
859 if (WC->serv_info->serv_supports_guest) {
860 /* default action. probably revisit this. */
861 StrBuf *teh_lobby = NewStrBufPlain(HKEY("_BASEROOM_"));
862 smart_goto(teh_lobby);
863 FreeStrBuf(&teh_lobby);
872 * Replacement for sleep() that uses select() in order to avoid SIGALRM
874 void sleeeeeeeeeep(int seconds)
880 select(0, NULL, NULL, NULL, &tv);
883 int Conditional_IS_HTTPS(StrBuf *Target, WCTemplputParams *TP)
885 return is_https != 0;
888 void AppendImportantMessage(const char *pch, long len)
892 if (StrLength(WCC->ImportantMsg) > 0) {
893 StrBufAppendBufPlain(WCC->ImportantMsg, HKEY("\n"), 0);
896 StrBufAppendBufPlain(WCC->ImportantMsg, pch, len, 0);
899 int ConditionalImportantMesage(StrBuf *Target, WCTemplputParams *TP)
903 return ((!IsEmptyStr(WCC->ImportantMessage)) ||
904 (StrLength(WCC->ImportantMsg) > 0));
909 void tmplput_importantmessage(StrBuf *Target, WCTemplputParams *TP)
914 if (!IsEmptyStr(WCC->ImportantMessage)) {
915 StrEscAppend(Target, NULL, WCC->ImportantMessage, 0, 0);
916 WCC->ImportantMessage[0] = '\0';
918 else if (StrLength(WCC->ImportantMsg) > 0) {
919 StrEscAppend(Target, WCC->ImportantMsg, NULL, 0, 0);
920 FlushStrBuf(WCC->ImportantMsg);
925 void tmplput_trailing_javascript(StrBuf *Target, WCTemplputParams *TP)
930 StrBufAppendTemplate(Target, TP, WCC->trailing_javascript, 0);
933 void tmplput_csslocal(StrBuf *Target, WCTemplputParams *TP)
935 StrBufAppendBuf(Target,
939 extern char static_local_dir[PATH_MAX];
947 WebcitAddUrlHandler(HKEY("blank"), "", 0, blank_page, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC);
948 WebcitAddUrlHandler(HKEY("do_template"), "", 0, url_do_template, ANONYMOUS);
949 WebcitAddUrlHandler(HKEY("sslg"), "", 0, seconds_since_last_gexp, AJAX|LOGCHATTY);
950 WebcitAddUrlHandler(HKEY("ajax_servcmd"), "", 0, ajax_servcmd, 0);
951 WebcitAddUrlHandler(HKEY("webcit"), "", 0, blank_page, URLNAMESPACE);
952 WebcitAddUrlHandler(HKEY("push"), "", 0, push_destination, AJAX);
953 WebcitAddUrlHandler(HKEY("pop"), "", 0, pop_destination, 0);
955 WebcitAddUrlHandler(HKEY("401"), "", 0, authorization_required, ANONYMOUS|COOKIEUNNEEDED);
956 RegisterConditional(HKEY("COND:IMPMSG"), 0, ConditionalImportantMesage, CTX_NONE);
957 RegisterConditional(HKEY("COND:REST:DEPTH"), 0, Conditional_REST_DEPTH, CTX_NONE);
958 RegisterConditional(HKEY("COND:IS_HTTPS"), 0, Conditional_IS_HTTPS, CTX_NONE);
960 RegisterNamespace("CSSLOCAL", 0, 0, tmplput_csslocal, NULL, CTX_NONE);
961 RegisterNamespace("IMPORTANTMESSAGE", 0, 0, tmplput_importantmessage, NULL, CTX_NONE);
962 RegisterNamespace("TRAILING_JAVASCRIPT", 0, 0, tmplput_trailing_javascript, NULL, CTX_NONE);
963 RegisterNamespace("URL:DISPLAYNAME", 0, 1, tmplput_HANDLER_DISPLAYNAME, NULL, CTX_NONE);
966 snprintf(dir, SIZ, "%s/webcit.css", static_local_dir);
967 if (!access(dir, R_OK)) {
968 syslog(9, "Using local Stylesheet [%s]\n", dir);
969 csslocal = NewStrBufPlain(HKEY("<link href=\"static.local/webcit.css\" rel=\"stylesheet\" type=\"text/css\" />"));
972 syslog(9, "No Site-local Stylesheet [%s] installed. \n", dir);
977 ServerStartModule_WEBCIT
980 HandlerHash = NewHash(1, NULL);
985 ServerShutdownModule_WEBCIT
988 FreeStrBuf(&csslocal);
989 DeleteHash(&HandlerHash);
995 SessionNewModule_WEBCIT
998 sess->ImportantMsg = NewStrBuf();
999 sess->WBuf = NewStrBufPlain(NULL, SIZ * 4);
1000 sess->HBuf = NewStrBufPlain(NULL, SIZ / 4);
1004 SessionDetachModule_WEBCIT
1007 DeleteHash(&sess->Directory);
1009 FreeStrBuf(&sess->upload);
1010 sess->upload_length = 0;
1012 FreeStrBuf(&sess->trailing_javascript);
1014 if (StrLength(sess->WBuf) > SIZ * 30) /* Bigger than 120K? release. */
1016 FreeStrBuf(&sess->WBuf);
1017 sess->WBuf = NewStrBuf();
1020 FlushStrBuf(sess->WBuf);
1021 FlushStrBuf(sess->HBuf);
1025 SessionDestroyModule_WEBCIT
1028 FreeStrBuf(&sess->WBuf);
1029 FreeStrBuf(&sess->HBuf);
1030 FreeStrBuf(&sess->ImportantMsg);
1031 FreeStrBuf(&sess->PushedDestination);