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, version 3.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #define SHOW_ME_VAPPEND_PRINTF
22 #include "webserver.h"
24 StrBuf *csslocal = NULL;
25 HashList *HandlerHash = NULL;
27 void stuff_to_cookie(int unset_cookie);
28 extern int GetConnected(void);
31 void PutRequestLocalMem(void *Data, DeleteHashDataFunc DeleteIt)
36 n = GetCount(WCC->Hdr->HTTPHeaders);
37 Put(WCC->Hdr->HTTPHeaders, IKEY(n), Data, DeleteIt);
40 void DeleteWebcitHandler(void *vHandler)
42 WebcitHandler *Handler = (WebcitHandler*) vHandler;
43 FreeStrBuf(&Handler->Name);
44 FreeStrBuf(&Handler->DisplayName);
48 void WebcitAddUrlHandler(const char * UrlString, long UrlSLen,
49 const char *DisplayName, long dslen,
53 WebcitHandler *NewHandler;
54 NewHandler = (WebcitHandler*) malloc(sizeof(WebcitHandler));
56 NewHandler->Flags = Flags;
57 NewHandler->Name = NewStrBufPlain(UrlString, UrlSLen);
58 StrBufShrinkToFit(NewHandler->Name, 1);
59 NewHandler->DisplayName = NewStrBufPlain(DisplayName, dslen);
60 StrBufShrinkToFit(NewHandler->DisplayName, 1);
61 Put(HandlerHash, UrlString, UrlSLen, NewHandler, DeleteWebcitHandler);
64 void tmplput_HANDLER_DISPLAYNAME(StrBuf *Target, WCTemplputParams *TP)
67 if (WCC->Hdr->HR.Handler != NULL)
68 StrBufAppendTemplate(Target, TP, WCC->Hdr->HR.Handler->DisplayName, 0);
73 * web-printing funcion. uses our vsnprintf wrapper
75 #ifdef UBER_VERBOSE_DEBUGGING
76 void wcc_printf(const char *FILE, const char *FUNCTION, long LINE, const char *format,...)
78 void wc_printf(const char *format,...)
84 if (WCC->WBuf == NULL)
85 WCC->WBuf = NewStrBuf();
86 #ifdef UBER_VERBOSE_DEBUGGING
87 StrBufAppendPrintf(WCC->WBuf, "\n%s:%s:%d[", FILE, FUNCTION, LINE);
90 va_start(arg_ptr, format);
91 StrBufVAppendPrintf(WCC->WBuf, format, arg_ptr);
93 #ifdef UBER_VERBOSE_DEBUGGING
94 StrBufAppendPrintf(WCC->WBuf, "]\n");
99 * http-header-printing funcion. uses our vsnprintf wrapper
101 void hprintf(const char *format,...)
106 va_start(arg_ptr, format);
107 StrBufVAppendPrintf(WCC->HBuf, format, arg_ptr);
114 * wrap up an HTTP session, closes tags, etc.
116 * print_standard_html_footer should be set to:
117 * 0 - to transmit only,
118 * nonzero - to append the closing tags
120 void wDumpContent(int print_standard_html_footer)
122 if (print_standard_html_footer) {
123 wc_printf("</div> <!-- end of 'content' div -->\n");
124 do_template("trailing");
127 /* If we've been saving it all up for one big output burst,
128 * go ahead and do that now.
137 * Output HTTP headers and leading HTML for a page
139 void output_headers( int do_httpheaders, /* 1 = output HTTP headers */
140 int do_htmlhead, /* 1 = output HTML <head> section and <body> opener */
142 int do_room_banner, /* 0=no, 1=yes,
143 * 2 = I'm going to embed my own, so don't open the
144 * <div id="content"> either.
147 int unset_cookies, /* 1 = session is terminating, so unset the cookies */
148 int suppress_check, /* 1 = suppress check for instant messages */
149 int cache /* 1 = allow browser to cache this page */
154 hprintf("HTTP/1.1 200 OK\n");
155 http_datestring(httpnow, sizeof httpnow, time(NULL));
157 if (do_httpheaders) {
158 if (WCC->serv_info != NULL)
159 hprintf("Content-type: text/html; charset=utf-8\r\n"
161 "Connection: close\r\n",
163 ChrPtr(WCC->serv_info->serv_software));
165 hprintf("Content-type: text/html; charset=utf-8\r\n"
166 "Server: %s / [n/a]\n"
167 "Connection: close\r\n",
172 char httpTomorow[128];
174 http_datestring(httpTomorow, sizeof httpTomorow,
175 time(NULL) + 60 * 60 * 24 * 2);
177 hprintf("Pragma: public\r\n"
178 "Cache-Control: max-age=3600, must-revalidate\r\n"
179 "Last-modified: %s\r\n"
186 hprintf("Pragma: no-cache\r\n"
187 "Cache-Control: no-store\r\n"
192 if (cache < 2) stuff_to_cookie(unset_cookies);
198 /* check for ImportantMessages (these display in a div overlaying the main screen) */
199 if (StrLength(WCC->ImportantMsg) > 0) {
200 wc_printf("<div id=\"important_message\">\n"
201 "<span class=\"imsg\">");
202 StrEscAppend(WCC->WBuf, WCC->ImportantMsg, NULL, 0, 0);
203 wc_printf("</span><br>\n"
206 StrBufAppendBufPlain(WCC->trailing_javascript,
207 HKEY("setTimeout('hide_imsg_popup()', 5000); \n"),
210 FlushStrBuf(WCC->ImportantMsg);
212 if ( (WCC->logged_in) && (!unset_cookies) ) {
213 DoTemplate(HKEY("paging"), NULL, &NoCtx);
216 if (do_room_banner == 1) {
217 tmplput_roombanner(NULL, NULL);
221 if (do_room_banner == 1) {
222 wc_printf("<div id=\"content\">\n");
226 void output_custom_content_header(const char *ctype) {
227 hprintf("HTTP/1.1 200 OK\r\n");
228 hprintf("Content-type: %s; charset=utf-8\r\n",ctype);
229 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
230 hprintf("Connection: close\r\n");
235 * Generic function to do an HTTP redirect. Easy and fun.
237 void http_redirect(const char *whichpage) {
238 hprintf("HTTP/1.1 302 Moved Temporarily\n");
239 hprintf("Location: %s\r\n", whichpage);
240 hprintf("URI: %s\r\n", whichpage);
241 hprintf("Content-type: text/html; charset=utf-8\r\n");
244 wc_printf("<html><body>");
245 wc_printf("Go <a href=\"%s\">here</A>.", whichpage);
246 wc_printf("</body></html>\n");
253 * Output a piece of content to the web browser using conformant HTTP and MIME semantics
255 void http_transmit_thing(const char *content_type, int is_static)
258 syslog(9, "http_transmit_thing(%s)%s", content_type, ((is_static > 0) ? " (static)" : ""));
259 output_headers(0, 0, 0, 0, 0, is_static);
261 hprintf("Content-type: %s\r\n"
263 "Connection: close\r\n",
272 * Convenience functions to display a page containing only a string
274 * titlebarcolor color of the titlebar of the frame
275 * titlebarmsg text to display in the title bar
276 * messagetext body of the box
278 void convenience_page(const char *titlebarcolor, const char *titlebarmsg, const char *messagetext)
280 hprintf("HTTP/1.1 200 OK\n");
281 output_headers(1, 1, 2, 0, 0, 0);
282 wc_printf("<div id=\"banner\">\n");
283 wc_printf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
284 wc_printf("<span class=\"titlebar\">%s</span>\n", titlebarmsg);
285 wc_printf("</td></tr></table>\n");
286 wc_printf("</div>\n<div id=\"content\">\n");
287 escputs(messagetext);
289 wc_printf("<hr />\n");
295 * Display a blank page.
297 void blank_page(void) {
298 output_headers(1, 1, 0, 0, 0, 0);
304 * A template has been requested
306 void url_do_template(void) {
307 const StrBuf *MimeType;
308 const StrBuf *Tmpl = sbstr("template");
310 MimeType = DoTemplate(SKEY(Tmpl), NULL, &NoCtx);
311 http_transmit_thing(ChrPtr(MimeType), 0);
317 * convenience function to indicate success
319 void display_success(const char *successmessage)
321 convenience_page("007700", "OK", successmessage);
326 * Authorization required page (sends a 401, causing the browser to request login credentials)
328 void authorization_required(void)
331 const char *message = "";
333 hprintf("HTTP/1.1 401 Authorization Required\r\n");
335 "Server: %s / %s\r\n"
336 "Connection: close\r\n",
337 PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software)
339 hprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n", ChrPtr(WC->serv_info->serv_humannode));
340 hprintf("Content-Type: text/html\r\n");
343 wc_printf(_("Authorization Required"));
344 wc_printf("</h1>\r\n");
346 if (WCC->ImportantMsg != NULL) {
347 message = ChrPtr(WCC->ImportantMsg);
351 _("The resource you requested requires a valid username and password. "
352 "You could not be logged in: %s\n"),
360 * Convenience functions to wrap around asynchronous ajax responses
362 void begin_ajax_response(void) {
365 FlushStrBuf(WCC->HBuf);
366 output_headers(0, 0, 0, 0, 0, 0);
368 hprintf("Content-type: text/html; charset=UTF-8\r\n"
370 "Connection: close\r\n"
378 * print ajax response footer
380 void end_ajax_response(void) {
386 * Wraps a Citadel server command in an AJAX transaction.
388 void ajax_servcmd(void)
396 syslog(LOG_DEBUG, "ajax_servcmd() g_cmd=\"%s\"", bstr("g_cmd") );
397 begin_ajax_response();
399 serv_puts(bstr("g_cmd"));
400 StrBuf_ServGetln(Buf);
401 StrBufAppendBuf(WCC->WBuf, Buf, 0);
402 StrBufAppendBufPlain(WCC->WBuf, HKEY("\n"), 0);
404 switch (GetServerStatus(Buf, NULL)) {
406 serv_puts("\n\n000");
407 if ( (StrLength(Buf)==3) &&
408 !strcmp(ChrPtr(Buf), "000")) {
409 StrBufAppendBufPlain(WCC->WBuf, HKEY("\000"), 0);
414 if (StrBuf_ServGetln(Buf) < 0)
416 if ( (StrLength(Buf)==3) &&
417 !strcmp(ChrPtr(Buf), "000")) {
420 StrBufAppendBuf(WCC->WBuf, Buf, 0);
421 StrBufAppendBufPlain(WCC->WBuf, HKEY("\n"), 0);
425 text_to_server(bstr("g_input"));
429 len = atol(&ChrPtr(Buf)[4]);
430 StrBuf_ServGetBLOBBuffered(Buf, len);
433 len = atol(&ChrPtr(Buf)[4]);
435 memset(junk, 0, len);
436 serv_write(junk, len);
443 * This is kind of an ugly hack, but this is the only place it can go.
444 * If the command was GEXP, then the instant messenger window must be
445 * running, so reset the "last_pager_check" watchdog timer so
446 * that page_popup() doesn't try to open it a second time. TODO: page_popup isn't with us anymore.
448 if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) {
449 WCC->last_pager_check = time(NULL);
456 * Helper function for the asynchronous check to see if we need
457 * to open the instant messenger window.
459 void seconds_since_last_gexp(void)
463 if ( (time(NULL) - WC->last_pager_check) < 30) {
469 serv_getln(buf, sizeof buf);
481 * Save a URL destination so we can go to it later
483 void push_destination(void) {
487 wc_printf("no session");
491 FreeStrBuf(&WCC->PushedDestination);
492 WCC->PushedDestination = NewStrBufDup(SBSTR("url"));
493 syslog(9, "Push: %s", ChrPtr(WCC->PushedDestination));
499 * Go to the URL saved by push_destination()
501 void pop_destination(void) {
505 * If we are in the middle of a new user signup, the server may request that
506 * we first pass through a registration screen.
508 if ((WCC) && (WCC->need_regi)) {
509 if ((WCC->PushedDestination != NULL) && (StrLength(WCC->PushedDestination) > 0)) {
510 /* Registering will take us to the My Citadel Config room, so save our place */
511 StrBufAppendBufPlain(WCC->PushedDestination, HKEY("?go="), 0);
512 StrBufUrlescAppend(WCC->PushedDestination, WCC->CurRoom.name, NULL);
520 * Do something reasonable if we somehow ended up requesting a pop without
521 * having first done a push.
523 if ( (!WCC) || (WCC->PushedDestination == NULL) || (StrLength(WCC->PushedDestination) == 0) ) {
529 * All righty then! We have a destination saved, so go there now.
531 syslog(9, "Pop: %s", ChrPtr(WCC->PushedDestination));
532 http_redirect(ChrPtr(WCC->PushedDestination));
537 int ReadPostData(void)
540 int urlencoded_post = 0;
542 StrBuf *content = NULL;
544 urlencoded_post = (strncasecmp(ChrPtr(WCC->Hdr->HR.ContentType), "application/x-www-form-urlencoded", 33) == 0) ;
546 content = NewStrBufPlain(NULL, WCC->Hdr->HR.ContentLength + 256);
548 if (!urlencoded_post)
550 StrBufPrintf(content,
552 "Content-length: %ld\n\n",
553 ChrPtr(WCC->Hdr->HR.ContentType),
554 WCC->Hdr->HR.ContentLength);
557 /** Read the entire input data at once. */
558 rc = client_read_to(WCC->Hdr, content,
559 WCC->Hdr->HR.ContentLength,
565 if (urlencoded_post) {
566 ParseURLParams(content);
567 } else if (!strncasecmp(ChrPtr(WCC->Hdr->HR.ContentType), "multipart", 9)) {
572 len = StrLength(content);
573 Buf = SmashStrBuf(&content);
575 mime_parser(Buf, BufEnd, *upload_handler, NULL, NULL, NULL, 0);
577 } else if (WCC->Hdr->HR.ContentLength > 0) {
578 WCC->upload = content;
579 WCC->upload_length = StrLength(WCC->upload);
582 FreeStrBuf(&content);
587 int Conditional_REST_DEPTH(StrBuf *Target, WCTemplputParams *TP)
593 if (WCC->Hdr->HR.Handler != NULL)
595 Depth = GetTemplateTokenNumber(Target, TP, 2, 0);
596 IsDepth = GetCount(WCC->Directory) + offset;
598 // LogTemplateError(Target, "bla", 1, TP, "REST_DEPTH: %ld : %ld\n", Depth, IsDepth);
601 return IsDepth > Depth;
604 return Depth == IsDepth;
610 * Entry point for WebCit transaction
612 void session_loop(void)
618 * We stuff these with the values coming from the client cookies,
619 * so we can use them to reconnect a timed out session if we have to.
624 WCC->upload_length = 0;
626 WCC->Hdr->nWildfireHeaders = 0;
628 if (WCC->Hdr->HR.ContentLength > 0) {
629 if (ReadPostData() < 0) {
635 WCC->trailing_javascript = NewStrBuf();
637 /* Convert base64-encoded URL's back to plain text */
638 if (!strncmp(ChrPtr(WCC->Hdr->this_page), "/B64", 4)) {
639 StrBufCutLeft(WCC->Hdr->this_page, 4);
640 StrBufDecodeBase64(WCC->Hdr->this_page);
641 http_redirect(ChrPtr(WCC->Hdr->this_page));
642 goto SKIP_ALL_THIS_CRAP;
645 /* If there are variables in the URL, we must grab them now */
646 if (WCC->Hdr->PlainArgs != NULL)
647 ParseURLParams(WCC->Hdr->PlainArgs);
649 /* If the client sent a nonce that is incorrect, kill the request. */
650 if (havebstr("nonce")) {
651 syslog(9, "Comparing supplied nonce %s to session nonce %d",
652 bstr("nonce"), WCC->nonce
654 if (ibstr("nonce") != WCC->nonce) {
655 syslog(9, "Ignoring request with mismatched nonce.");
656 hprintf("HTTP/1.1 404 Security check failed\r\n");
657 hprintf("Content-Type: text/plain\r\n");
659 wc_printf("Security check failed.\r\n");
661 goto SKIP_ALL_THIS_CRAP;
666 * If we're not connected to a Citadel server, try to hook up the connection now.
668 if (!WCC->connected) {
669 if (GetConnected()) {
670 hprintf("HTTP/1.1 503 Service Unavailable\r\n");
671 hprintf("Content-Type: text/html\r\n");
673 wc_printf("<html><head><title>503 Service Unavailable</title></head><body>\n");
674 wc_printf(_("This program was unable to connect or stay "
675 "connected to the Citadel server. Please report "
676 "this problem to your system administrator.")
679 wc_printf("<a href=\"http://www.citadel.org/doku.php/"
680 "faq:generalquestions:webcit_unable_to_connect\">%s</a>",
683 wc_printf("</body></html>\n");
685 goto SKIP_ALL_THIS_CRAP;
690 * If we're not logged in, but we have authentication data (either from
691 * a cookie or from http-auth), try logging in to Citadel using that.
693 if ( (!WCC->logged_in)
694 && (StrLength(WCC->Hdr->c_username) > 0)
695 && (StrLength(WCC->Hdr->c_password) > 0)
700 serv_printf("USER %s", ChrPtr(WCC->Hdr->c_username));
701 StrBuf_ServGetln(Buf);
702 if (GetServerStatus(Buf, &Status) == 3) {
703 serv_printf("PASS %s", ChrPtr(WCC->Hdr->c_password));
704 StrBuf_ServGetln(Buf);
705 if (GetServerStatus(Buf, NULL) == 2) {
706 become_logged_in(WCC->Hdr->c_username,
707 WCC->Hdr->c_password, Buf);
709 /* Should only display when password is wrong */
710 WCC->ImportantMsg = NewStrBufPlain(ChrPtr(Buf) + 4, StrLength(Buf) - 4);
711 authorization_required();
713 goto SKIP_ALL_THIS_CRAP;
716 else if (Status == 541) {
721 xhttp = (WCC->Hdr->HR.eReqType != eGET) &&
722 (WCC->Hdr->HR.eReqType != ePOST) &&
723 (WCC->Hdr->HR.eReqType != eHEAD);
726 * If a 'go' (or 'gotofirst') parameter has been specified, attempt to goto that room
727 * prior to doing anything else.
729 if (havebstr("go")) {
731 syslog(9, "Explicit room selection: %s", bstr("go"));
732 ret = gotoroom(sbstr("go")); /* do quietly to avoid session output! */
733 if ((ret/100) != 2) {
734 syslog(1, "Unable to change to [%s]; Reason: %d", bstr("go"), ret);
737 else if (havebstr("gotofirst")) {
739 syslog(9, "Explicit room selection: %s", bstr("gotofirst"));
740 ret = gotoroom(sbstr("gotofirst")); /* do quietly to avoid session output! */
741 if ((ret/100) != 2) {
742 syslog(1, "Unable to change to [%s]; Reason: %d", bstr("gotofirst"), ret);
747 * If we aren't in any room yet, but we have cookie data telling us where we're
748 * supposed to be, and 'go' was not specified, then go there.
750 else if ( (StrLength(WCC->CurRoom.name) == 0) && ( (StrLength(WCC->Hdr->c_roomname) > 0) )) {
753 syslog(9, "We are in '%s' but cookie indicates '%s', going there...",
754 ChrPtr(WCC->CurRoom.name),
755 ChrPtr(WCC->Hdr->c_roomname)
757 ret = gotoroom(WCC->Hdr->c_roomname); /* do quietly to avoid session output! */
758 if ((ret/100) != 2) {
759 syslog(1, "COOKIEGOTO: Unable to change to [%s]; Reason: %d",
760 ChrPtr(WCC->Hdr->c_roomname), ret);
764 if (WCC->Hdr->HR.Handler != NULL) {
765 if ( (!WCC->logged_in)
766 && ((WCC->Hdr->HR.Handler->Flags & ANONYMOUS) == 0)
767 && (WCC->serv_info->serv_supports_guest == 0)
772 if ((WCC->Hdr->HR.Handler->Flags & AJAX) != 0) {
773 begin_ajax_response();
775 WCC->Hdr->HR.Handler->F();
776 if ((WCC->Hdr->HR.Handler->Flags & AJAX) != 0) {
781 /* When all else fails, display the default landing page or a main menu. */
784 * ordinary browser users get a nice login screen, DAV etc. requsets
785 * are given a 401 so they can handle it appropriate.
787 if (!WCC->logged_in) {
789 authorization_required();
792 display_default_landing_page();
796 * Toplevel dav requests? or just a flat browser request?
816 * Display the appropriate landing page for this site.
818 void display_default_landing_page(void) {
821 if (WCC && WCC->serv_info && WCC->serv_info->serv_supports_guest) {
824 if (havebstr("go")) {
825 syslog(9, "Explicit room selection: %s", bstr("go"));
826 StrBuf *teh_room = NewStrBufPlain(bstr("go"), strlen(bstr("go")));
827 smart_goto(teh_room);
828 FreeStrBuf(&teh_room);
830 else if (default_landing_page) {
831 http_redirect(default_landing_page);
834 StrBuf *teh_lobby = NewStrBufPlain(HKEY("_BASEROOM_"));
835 smart_goto(teh_lobby);
836 FreeStrBuf(&teh_lobby);
846 * Replacement for sleep() that uses select() in order to avoid SIGALRM
848 void sleeeeeeeeeep(int seconds)
854 select(0, NULL, NULL, NULL, &tv);
857 int Conditional_IS_HTTPS(StrBuf *Target, WCTemplputParams *TP)
859 return is_https != 0;
862 void AppendImportantMessage(const char *pch, long len)
866 if (StrLength(WCC->ImportantMsg) > 0) {
867 StrBufAppendBufPlain(WCC->ImportantMsg, HKEY("\n"), 0);
870 StrBufAppendBufPlain(WCC->ImportantMsg, pch, len, 0);
873 int ConditionalImportantMesage(StrBuf *Target, WCTemplputParams *TP)
877 return (StrLength(WCC->ImportantMsg) > 0);
882 void tmplput_importantmessage(StrBuf *Target, WCTemplputParams *TP)
887 if (StrLength(WCC->ImportantMsg) > 0) {
888 StrEscAppend(Target, WCC->ImportantMsg, NULL, 0, 0);
889 FlushStrBuf(WCC->ImportantMsg);
894 void tmplput_trailing_javascript(StrBuf *Target, WCTemplputParams *TP)
899 StrBufAppendTemplate(Target, TP, WCC->trailing_javascript, 0);
902 void tmplput_csslocal(StrBuf *Target, WCTemplputParams *TP)
904 StrBufAppendBuf(Target,
908 void tmplput_packagestring(StrBuf *Target, WCTemplputParams *TP)
910 StrBufAppendBufPlain(Target,
911 HKEY(PACKAGE_STRING), 0);
914 extern char static_local_dir[PATH_MAX];
922 WebcitAddUrlHandler(HKEY("blank"), "", 0, blank_page, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC);
923 WebcitAddUrlHandler(HKEY("landing"), "", 0, display_default_landing_page, ANONYMOUS|COOKIEUNNEEDED);
924 WebcitAddUrlHandler(HKEY("do_template"), "", 0, url_do_template, ANONYMOUS);
925 WebcitAddUrlHandler(HKEY("sslg"), "", 0, seconds_since_last_gexp, AJAX|LOGCHATTY);
926 WebcitAddUrlHandler(HKEY("ajax_servcmd"), "", 0, ajax_servcmd, 0);
927 WebcitAddUrlHandler(HKEY("webcit"), "", 0, blank_page, URLNAMESPACE);
928 WebcitAddUrlHandler(HKEY("push"), "", 0, push_destination, AJAX);
929 WebcitAddUrlHandler(HKEY("pop"), "", 0, pop_destination, 0);
931 WebcitAddUrlHandler(HKEY("401"), "", 0, authorization_required, ANONYMOUS|COOKIEUNNEEDED);
932 RegisterConditional(HKEY("COND:IMPMSG"), 0, ConditionalImportantMesage, CTX_NONE);
933 RegisterConditional(HKEY("COND:REST:DEPTH"), 0, Conditional_REST_DEPTH, CTX_NONE);
934 RegisterConditional(HKEY("COND:IS_HTTPS"), 0, Conditional_IS_HTTPS, CTX_NONE);
936 RegisterNamespace("CSSLOCAL", 0, 0, tmplput_csslocal, NULL, CTX_NONE);
937 RegisterNamespace("IMPORTANTMESSAGE", 0, 0, tmplput_importantmessage, NULL, CTX_NONE);
938 RegisterNamespace("TRAILING_JAVASCRIPT", 0, 0, tmplput_trailing_javascript, NULL, CTX_NONE);
939 RegisterNamespace("URL:DISPLAYNAME", 0, 1, tmplput_HANDLER_DISPLAYNAME, NULL, CTX_NONE);
940 RegisterNamespace("PACKAGESTRING", 0, 1, tmplput_packagestring, NULL, CTX_NONE);
943 snprintf(dir, SIZ, "%s/webcit.css", static_local_dir);
944 if (!access(dir, R_OK)) {
945 syslog(9, "Using local Stylesheet [%s]", dir);
946 csslocal = NewStrBufPlain(HKEY("<link href=\"static.local/webcit.css\" rel=\"stylesheet\" type=\"text/css\" />"));
949 syslog(9, "No Site-local Stylesheet [%s] installed.", dir);
954 ServerStartModule_WEBCIT
957 HandlerHash = NewHash(1, NULL);
962 ServerShutdownModule_WEBCIT
965 FreeStrBuf(&csslocal);
966 DeleteHash(&HandlerHash);
972 SessionNewModule_WEBCIT
975 sess->ImportantMsg = NewStrBuf();
976 sess->WBuf = NewStrBufPlain(NULL, SIZ * 4);
977 sess->HBuf = NewStrBufPlain(NULL, SIZ / 4);
981 SessionDetachModule_WEBCIT
984 DeleteHash(&sess->Directory);
986 FreeStrBuf(&sess->upload);
987 sess->upload_length = 0;
989 FreeStrBuf(&sess->trailing_javascript);
991 if (StrLength(sess->WBuf) > SIZ * 30) /* Bigger than 120K? release. */
993 FreeStrBuf(&sess->WBuf);
994 sess->WBuf = NewStrBuf();
997 FlushStrBuf(sess->WBuf);
998 FlushStrBuf(sess->HBuf);
1002 SessionDestroyModule_WEBCIT
1005 FreeStrBuf(&sess->WBuf);
1006 FreeStrBuf(&sess->HBuf);
1007 FreeStrBuf(&sess->ImportantMsg);
1008 FreeStrBuf(&sess->PushedDestination);