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-2012 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.
12 #define SHOW_ME_VAPPEND_PRINTF
17 #include "webserver.h"
19 StrBuf *csslocal = NULL;
20 HashList *HandlerHash = NULL;
22 void stuff_to_cookie(int unset_cookie);
23 extern int GetConnected(void);
26 void PutRequestLocalMem(void *Data, DeleteHashDataFunc DeleteIt)
31 n = GetCount(WCC->Hdr->HTTPHeaders);
32 Put(WCC->Hdr->HTTPHeaders, IKEY(n), Data, DeleteIt);
35 void DeleteWebcitHandler(void *vHandler)
37 WebcitHandler *Handler = (WebcitHandler*) vHandler;
38 FreeStrBuf(&Handler->Name);
39 FreeStrBuf(&Handler->DisplayName);
43 void WebcitAddUrlHandler(const char * UrlString, long UrlSLen,
44 const char *DisplayName, long dslen,
48 WebcitHandler *NewHandler;
49 NewHandler = (WebcitHandler*) malloc(sizeof(WebcitHandler));
51 NewHandler->Flags = Flags;
52 NewHandler->Name = NewStrBufPlain(UrlString, UrlSLen);
53 StrBufShrinkToFit(NewHandler->Name, 1);
54 NewHandler->DisplayName = NewStrBufPlain(DisplayName, dslen);
55 StrBufShrinkToFit(NewHandler->DisplayName, 1);
56 Put(HandlerHash, UrlString, UrlSLen, NewHandler, DeleteWebcitHandler);
59 void tmplput_HANDLER_DISPLAYNAME(StrBuf *Target, WCTemplputParams *TP)
62 if (WCC->Hdr->HR.Handler != NULL)
63 StrBufAppendTemplate(Target, TP, WCC->Hdr->HR.Handler->DisplayName, 0);
68 * web-printing funcion. uses our vsnprintf wrapper
70 #ifdef UBER_VERBOSE_DEBUGGING
71 void wcc_printf(const char *FILE, const char *FUNCTION, long LINE, const char *format,...)
73 void wc_printf(const char *format,...)
79 if (WCC->WBuf == NULL)
80 WCC->WBuf = NewStrBuf();
81 #ifdef UBER_VERBOSE_DEBUGGING
82 StrBufAppendPrintf(WCC->WBuf, "\n%s:%s:%d[", FILE, FUNCTION, LINE);
85 va_start(arg_ptr, format);
86 StrBufVAppendPrintf(WCC->WBuf, format, arg_ptr);
88 #ifdef UBER_VERBOSE_DEBUGGING
89 StrBufAppendPrintf(WCC->WBuf, "]\n");
94 * http-header-printing funcion. uses our vsnprintf wrapper
96 void hprintf(const char *format,...)
101 va_start(arg_ptr, format);
102 StrBufVAppendPrintf(WCC->HBuf, format, arg_ptr);
109 * wrap up an HTTP session, closes tags, etc.
111 * print_standard_html_footer should be set to:
112 * 0 - to transmit only,
113 * nonzero - to append the closing tags
115 void wDumpContent(int print_standard_html_footer)
117 if (print_standard_html_footer) {
118 wc_printf("</div> <!-- end of 'content' div -->\n");
119 do_template("trailing");
122 /* If we've been saving it all up for one big output burst,
123 * go ahead and do that now.
132 * Output HTTP headers and leading HTML for a page
134 void output_headers( int do_httpheaders, /* 1 = output HTTP headers */
135 int do_htmlhead, /* 1 = output HTML <head> section and <body> opener */
136 int do_room_banner, /* 1 = include the room banner and <div id="content"></div> */
137 int unset_cookies, /* 1 = session is terminating, so unset the cookies */
138 int suppress_check, /* 1 = suppress check for instant messages */
139 int cache /* 1 = allow browser to cache this page */
144 hprintf("HTTP/1.1 200 OK\n");
145 http_datestring(httpnow, sizeof httpnow, time(NULL));
147 if (do_httpheaders) {
148 if (WCC->serv_info != NULL)
149 hprintf("Content-type: text/html; charset=utf-8\r\n"
151 "Connection: close\r\n",
153 ChrPtr(WCC->serv_info->serv_software));
155 hprintf("Content-type: text/html; charset=utf-8\r\n"
156 "Server: %s / [n/a]\n"
157 "Connection: close\r\n",
162 char httpTomorow[128];
164 http_datestring(httpTomorow, sizeof httpTomorow,
165 time(NULL) + 60 * 60 * 24 * 2);
167 hprintf("Pragma: public\r\n"
168 "Cache-Control: max-age=3600, must-revalidate\r\n"
169 "Last-modified: %s\r\n"
176 hprintf("Pragma: no-cache\r\n"
177 "Cache-Control: no-store\r\n"
182 if (cache < 2) stuff_to_cookie(unset_cookies);
187 if ( (WCC->logged_in) && (!unset_cookies) ) {
188 DoTemplate(HKEY("paging"), NULL, &NoCtx);
190 if (do_room_banner) {
191 tmplput_roombanner(NULL, NULL);
195 if (do_room_banner) {
196 wc_printf("<div id=\"content\">\n");
200 void output_custom_content_header(const char *ctype) {
201 hprintf("HTTP/1.1 200 OK\r\n");
202 hprintf("Content-type: %s; charset=utf-8\r\n",ctype);
203 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
204 hprintf("Connection: close\r\n");
209 * Generic function to do an HTTP redirect. Easy and fun.
211 void http_redirect(const char *whichpage) {
212 hprintf("HTTP/1.1 302 Moved Temporarily\n");
213 hprintf("Location: %s\r\n", whichpage);
214 hprintf("URI: %s\r\n", whichpage);
215 hprintf("Content-type: text/html; charset=utf-8\r\n");
218 wc_printf("<html><body>");
219 wc_printf("Go <a href=\"%s\">here</A>.", whichpage);
220 wc_printf("</body></html>\n");
227 * Output a piece of content to the web browser using conformant HTTP and MIME semantics.
229 * If this function is called, it is expected that begin_burst() has already been called
230 * and some sort of content has been fed into the buffer. This function will transmit a
231 * bunch of headers to the client. end_burst() will add some headers of its own, and then
232 * transmit the buffered content to the client.
234 void http_transmit_thing(const char *content_type, int is_static)
236 syslog(LOG_DEBUG, "http_transmit_thing(%s)%s", content_type, ((is_static > 0) ? " (static)" : ""));
237 output_headers(0, 0, 0, 0, 0, is_static);
239 hprintf("Content-type: %s\r\n"
241 "Connection: close\r\n",
250 * Convenience functions to display a page containing only a string
252 * titlebarcolor color of the titlebar of the frame
253 * titlebarmsg text to display in the title bar
254 * messagetext body of the box
256 void convenience_page(const char *titlebarcolor, const char *titlebarmsg, const char *messagetext)
258 hprintf("HTTP/1.1 200 OK\n");
259 output_headers(1, 1, 1, 0, 0, 0);
260 wc_printf("<div id=\"room_banner_override\">\n");
261 wc_printf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
262 wc_printf("<span class=\"titlebar\">%s</span>\n", titlebarmsg);
263 wc_printf("</td></tr></table>\n");
264 wc_printf("</div>\n<div id=\"content\">\n");
265 escputs(messagetext);
266 wc_printf("<hr />\n");
272 * Display a blank page.
274 void blank_page(void) {
275 output_headers(1, 1, 0, 0, 0, 0);
281 * A template has been requested
283 void url_do_template(void) {
284 const StrBuf *MimeType;
285 const StrBuf *Tmpl = sbstr("template");
287 MimeType = DoTemplate(SKEY(Tmpl), NULL, &NoCtx);
288 http_transmit_thing(ChrPtr(MimeType), 0);
294 * convenience function to indicate success
296 void display_success(const char *successmessage)
298 convenience_page("007700", "OK", successmessage);
303 * Authorization required page (sends a 401, causing the browser to request login credentials)
305 void authorization_required(void)
308 const char *message = "";
310 hprintf("HTTP/1.1 401 Authorization Required\r\n");
312 "Server: %s / %s\r\n"
313 "Connection: close\r\n",
314 PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software)
316 hprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n", ChrPtr(WC->serv_info->serv_humannode));
317 hprintf("Content-Type: text/html\r\n");
320 wc_printf(_("Authorization Required"));
321 wc_printf("</h1>\r\n");
323 if (WCC->ImportantMsg != NULL) {
324 message = ChrPtr(WCC->ImportantMsg);
328 _("The resource you requested requires a valid username and password. "
329 "You could not be logged in: %s\n"),
337 * Convenience functions to wrap around asynchronous ajax responses
339 void begin_ajax_response(void) {
342 FlushStrBuf(WCC->HBuf);
343 output_headers(0, 0, 0, 0, 0, 0);
345 hprintf("Content-type: text/html; charset=UTF-8\r\n"
347 "Connection: close\r\n"
355 * print ajax response footer
357 void end_ajax_response(void) {
363 * Wraps a Citadel server command in an AJAX transaction.
365 void ajax_servcmd(void)
373 syslog(LOG_DEBUG, "ajax_servcmd() g_cmd=\"%s\"", bstr("g_cmd") );
374 begin_ajax_response();
376 serv_puts(bstr("g_cmd"));
377 StrBuf_ServGetln(Buf);
378 StrBufAppendBuf(WCC->WBuf, Buf, 0);
379 StrBufAppendBufPlain(WCC->WBuf, HKEY("\n"), 0);
381 switch (GetServerStatus(Buf, NULL)) {
383 serv_puts("\n\n000");
384 if ( (StrLength(Buf)==3) &&
385 !strcmp(ChrPtr(Buf), "000")) {
386 StrBufAppendBufPlain(WCC->WBuf, HKEY("\000"), 0);
391 if (StrBuf_ServGetln(Buf) < 0)
393 if ( (StrLength(Buf)==3) &&
394 !strcmp(ChrPtr(Buf), "000")) {
397 StrBufAppendBuf(WCC->WBuf, Buf, 0);
398 StrBufAppendBufPlain(WCC->WBuf, HKEY("\n"), 0);
402 text_to_server(bstr("g_input"));
406 len = atol(&ChrPtr(Buf)[4]);
407 StrBuf_ServGetBLOBBuffered(Buf, len);
410 len = atol(&ChrPtr(Buf)[4]);
412 memset(junk, 0, len);
413 serv_write(junk, len);
420 * This is kind of an ugly hack, but this is the only place it can go.
421 * If the command was GEXP, then the instant messenger window must be
422 * running, so reset the "last_pager_check" watchdog timer so
423 * that page_popup() doesn't try to open it a second time. TODO: page_popup isn't with us anymore.
425 if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) {
426 WCC->last_pager_check = time(NULL);
433 * Helper function for the asynchronous check to see if we need
434 * to open the instant messenger window.
436 void seconds_since_last_gexp(void)
440 if ( (time(NULL) - WC->last_pager_check) < 30) {
446 serv_getln(buf, sizeof buf);
458 * Save a URL destination so we can go to it later
460 void push_destination(void) {
464 wc_printf("no session");
468 FreeStrBuf(&WCC->PushedDestination);
469 WCC->PushedDestination = NewStrBufDup(SBSTR("url"));
470 syslog(9, "Push: %s", ChrPtr(WCC->PushedDestination));
476 * Go to the URL saved by push_destination()
478 void pop_destination(void) {
482 * If we are in the middle of a new user signup, the server may request that
483 * we first pass through a registration screen.
485 if ((WCC) && (WCC->need_regi)) {
486 if ((WCC->PushedDestination != NULL) && (StrLength(WCC->PushedDestination) > 0)) {
487 /* Registering will take us to the My Citadel Config room, so save our place */
488 StrBufAppendBufPlain(WCC->PushedDestination, HKEY("?go="), 0);
489 StrBufUrlescAppend(WCC->PushedDestination, WCC->CurRoom.name, NULL);
497 * Do something reasonable if we somehow ended up requesting a pop without
498 * having first done a push.
500 if ( (!WCC) || (WCC->PushedDestination == NULL) || (StrLength(WCC->PushedDestination) == 0) ) {
506 * All righty then! We have a destination saved, so go there now.
508 syslog(9, "Pop: %s", ChrPtr(WCC->PushedDestination));
509 http_redirect(ChrPtr(WCC->PushedDestination));
514 int ReadPostData(void)
517 int urlencoded_post = 0;
519 StrBuf *content = NULL;
521 urlencoded_post = (strncasecmp(ChrPtr(WCC->Hdr->HR.ContentType), "application/x-www-form-urlencoded", 33) == 0) ;
523 content = NewStrBufPlain(NULL, WCC->Hdr->HR.ContentLength + 256);
525 if (!urlencoded_post)
527 StrBufPrintf(content,
529 "Content-length: %ld\n\n",
530 ChrPtr(WCC->Hdr->HR.ContentType),
531 WCC->Hdr->HR.ContentLength);
534 /** Read the entire input data at once. */
535 rc = client_read_to(WCC->Hdr, content,
536 WCC->Hdr->HR.ContentLength,
542 if (urlencoded_post) {
543 ParseURLParams(content);
544 } else if (!strncasecmp(ChrPtr(WCC->Hdr->HR.ContentType), "multipart", 9)) {
549 len = StrLength(content);
550 Buf = SmashStrBuf(&content);
552 mime_parser(Buf, BufEnd, *upload_handler, NULL, NULL, NULL, 0);
554 } else if (WCC->Hdr->HR.ContentLength > 0) {
555 WCC->upload = content;
556 WCC->upload_length = StrLength(WCC->upload);
559 FreeStrBuf(&content);
564 int Conditional_REST_DEPTH(StrBuf *Target, WCTemplputParams *TP)
570 if (WCC->Hdr->HR.Handler != NULL)
572 Depth = GetTemplateTokenNumber(Target, TP, 2, 0);
573 IsDepth = GetCount(WCC->Directory) + offset;
575 // LogTemplateError(Target, "bla", 1, TP, "REST_DEPTH: %ld : %ld\n", Depth, IsDepth);
578 return IsDepth > Depth;
581 return Depth == IsDepth;
587 * Entry point for WebCit transaction
589 void session_loop(void)
595 * We stuff these with the values coming from the client cookies,
596 * so we can use them to reconnect a timed out session if we have to.
601 WCC->upload_length = 0;
603 WCC->Hdr->nWildfireHeaders = 0;
605 if (WCC->Hdr->HR.ContentLength > 0) {
606 if (ReadPostData() < 0) {
612 WCC->trailing_javascript = NewStrBuf();
614 /* Convert base64-encoded URL's back to plain text */
615 if (!strncmp(ChrPtr(WCC->Hdr->this_page), "/B64", 4)) {
616 StrBufCutLeft(WCC->Hdr->this_page, 4);
617 StrBufDecodeBase64(WCC->Hdr->this_page);
618 http_redirect(ChrPtr(WCC->Hdr->this_page));
619 goto SKIP_ALL_THIS_CRAP;
622 /* If there are variables in the URL, we must grab them now */
623 if (WCC->Hdr->PlainArgs != NULL)
624 ParseURLParams(WCC->Hdr->PlainArgs);
626 /* If the client sent a nonce that is incorrect, kill the request. */
627 if (havebstr("nonce")) {
628 syslog(9, "Comparing supplied nonce %s to session nonce %d",
629 bstr("nonce"), WCC->nonce
631 if (ibstr("nonce") != WCC->nonce) {
632 syslog(9, "Ignoring request with mismatched nonce.");
633 hprintf("HTTP/1.1 404 Security check failed\r\n");
634 hprintf("Content-Type: text/plain\r\n");
636 wc_printf("Security check failed.\r\n");
638 goto SKIP_ALL_THIS_CRAP;
643 * If we're not connected to a Citadel server, try to hook up the connection now.
645 if (!WCC->connected) {
646 if (GetConnected()) {
647 hprintf("HTTP/1.1 503 Service Unavailable\r\n");
648 hprintf("Content-Type: text/html\r\n");
650 wc_printf("<html><head><title>503 Service Unavailable</title></head><body>\n");
651 wc_printf(_("This program was unable to connect or stay "
652 "connected to the Citadel server. Please report "
653 "this problem to your system administrator.")
656 wc_printf("<a href=\"http://www.citadel.org/doku.php/"
657 "faq:generalquestions:webcit_unable_to_connect\">%s</a>",
660 wc_printf("</body></html>\n");
662 goto SKIP_ALL_THIS_CRAP;
667 * If we're not logged in, but we have authentication data (either from
668 * a cookie or from http-auth), try logging in to Citadel using that.
670 if ( (!WCC->logged_in)
671 && (StrLength(WCC->Hdr->c_username) > 0)
672 && (StrLength(WCC->Hdr->c_password) > 0)
677 serv_printf("USER %s", ChrPtr(WCC->Hdr->c_username));
678 StrBuf_ServGetln(Buf);
679 if (GetServerStatus(Buf, &Status) == 3) {
680 serv_printf("PASS %s", ChrPtr(WCC->Hdr->c_password));
681 StrBuf_ServGetln(Buf);
682 if (GetServerStatus(Buf, NULL) == 2) {
683 become_logged_in(WCC->Hdr->c_username,
684 WCC->Hdr->c_password, Buf);
686 /* Should only display when password is wrong */
687 WCC->ImportantMsg = NewStrBufPlain(ChrPtr(Buf) + 4, StrLength(Buf) - 4);
688 authorization_required();
690 goto SKIP_ALL_THIS_CRAP;
693 else if (Status == 541) {
698 xhttp = (WCC->Hdr->HR.eReqType != eGET) &&
699 (WCC->Hdr->HR.eReqType != ePOST) &&
700 (WCC->Hdr->HR.eReqType != eHEAD);
703 * If a 'go' (or 'gotofirst') parameter has been specified, attempt to goto that room
704 * prior to doing anything else.
706 if (havebstr("go")) {
708 syslog(9, "Explicit room selection: %s", bstr("go"));
709 ret = gotoroom(sbstr("go")); /* do quietly to avoid session output! */
710 if ((ret/100) != 2) {
711 syslog(1, "Unable to change to [%s]; Reason: %d", bstr("go"), ret);
714 else if (havebstr("gotofirst")) {
716 syslog(9, "Explicit room selection: %s", bstr("gotofirst"));
717 ret = gotoroom(sbstr("gotofirst")); /* do quietly to avoid session output! */
718 if ((ret/100) != 2) {
719 syslog(1, "Unable to change to [%s]; Reason: %d", bstr("gotofirst"), ret);
724 * If we aren't in any room yet, but we have cookie data telling us where we're
725 * supposed to be, and 'go' was not specified, then go there.
727 else if ( (StrLength(WCC->CurRoom.name) == 0) && ( (StrLength(WCC->Hdr->c_roomname) > 0) )) {
730 syslog(9, "We are in '%s' but cookie indicates '%s', going there...",
731 ChrPtr(WCC->CurRoom.name),
732 ChrPtr(WCC->Hdr->c_roomname)
734 ret = gotoroom(WCC->Hdr->c_roomname); /* do quietly to avoid session output! */
735 if ((ret/100) != 2) {
736 syslog(1, "COOKIEGOTO: Unable to change to [%s]; Reason: %d",
737 ChrPtr(WCC->Hdr->c_roomname), ret);
741 if (WCC->Hdr->HR.Handler != NULL) {
742 if ( (!WCC->logged_in)
743 && ((WCC->Hdr->HR.Handler->Flags & ANONYMOUS) == 0)
744 && (WCC->serv_info != NULL)
745 && (WCC->serv_info->serv_supports_guest == 0)
750 if ((WCC->Hdr->HR.Handler->Flags & AJAX) != 0) {
751 begin_ajax_response();
753 WCC->Hdr->HR.Handler->F();
754 if ((WCC->Hdr->HR.Handler->Flags & AJAX) != 0) {
759 /* When all else fails, display the default landing page or a main menu. */
762 * ordinary browser users get a nice login screen, DAV etc. requsets
763 * are given a 401 so they can handle it appropriate.
765 if (!WCC->logged_in) {
767 authorization_required();
770 display_default_landing_page();
774 * Toplevel dav requests? or just a flat browser request?
794 * Display the appropriate landing page for this site.
796 void display_default_landing_page(void) {
799 if (WCC && WCC->serv_info && WCC->serv_info->serv_supports_guest) {
802 if (havebstr("go")) {
803 syslog(9, "Explicit room selection: %s", bstr("go"));
804 StrBuf *teh_room = NewStrBufPlain(bstr("go"), strlen(bstr("go")));
805 smart_goto(teh_room);
806 FreeStrBuf(&teh_room);
808 else if (default_landing_page) {
809 http_redirect(default_landing_page);
812 StrBuf *teh_lobby = NewStrBufPlain(HKEY("_BASEROOM_"));
813 smart_goto(teh_lobby);
814 FreeStrBuf(&teh_lobby);
824 * Replacement for sleep() that uses select() in order to avoid SIGALRM
826 void sleeeeeeeeeep(int seconds)
832 select(0, NULL, NULL, NULL, &tv);
835 int Conditional_IS_HTTPS(StrBuf *Target, WCTemplputParams *TP)
837 return is_https != 0;
840 void AppendImportantMessage(const char *pch, long len)
844 if (StrLength(WCC->ImportantMsg) > 0) {
845 StrBufAppendBufPlain(WCC->ImportantMsg, HKEY("\n"), 0);
848 StrBufAppendBufPlain(WCC->ImportantMsg, pch, len, 0);
851 int ConditionalImportantMesage(StrBuf *Target, WCTemplputParams *TP)
855 return (StrLength(WCC->ImportantMsg) > 0);
860 void tmplput_importantmessage(StrBuf *Target, WCTemplputParams *TP)
865 if (StrLength(WCC->ImportantMsg) > 0) {
866 StrEscAppend(Target, WCC->ImportantMsg, NULL, 0, 0);
871 void tmplput_trailing_javascript(StrBuf *Target, WCTemplputParams *TP)
876 StrBufAppendTemplate(Target, TP, WCC->trailing_javascript, 0);
879 void tmplput_csslocal(StrBuf *Target, WCTemplputParams *TP)
881 StrBufAppendBuf(Target,
885 void tmplput_packagestring(StrBuf *Target, WCTemplputParams *TP)
887 StrBufAppendBufPlain(Target,
888 HKEY(PACKAGE_STRING), 0);
891 extern char static_local_dir[PATH_MAX];
899 WebcitAddUrlHandler(HKEY("blank"), "", 0, blank_page, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC);
900 WebcitAddUrlHandler(HKEY("landing"), "", 0, display_default_landing_page, ANONYMOUS|COOKIEUNNEEDED);
901 WebcitAddUrlHandler(HKEY("do_template"), "", 0, url_do_template, ANONYMOUS);
902 WebcitAddUrlHandler(HKEY("sslg"), "", 0, seconds_since_last_gexp, AJAX|LOGCHATTY);
903 WebcitAddUrlHandler(HKEY("ajax_servcmd"), "", 0, ajax_servcmd, 0);
904 WebcitAddUrlHandler(HKEY("webcit"), "", 0, blank_page, URLNAMESPACE);
905 WebcitAddUrlHandler(HKEY("push"), "", 0, push_destination, AJAX);
906 WebcitAddUrlHandler(HKEY("pop"), "", 0, pop_destination, 0);
908 WebcitAddUrlHandler(HKEY("401"), "", 0, authorization_required, ANONYMOUS|COOKIEUNNEEDED);
909 RegisterConditional(HKEY("COND:IMPMSG"), 0, ConditionalImportantMesage, CTX_NONE);
910 RegisterConditional(HKEY("COND:REST:DEPTH"), 0, Conditional_REST_DEPTH, CTX_NONE);
911 RegisterConditional(HKEY("COND:IS_HTTPS"), 0, Conditional_IS_HTTPS, CTX_NONE);
913 RegisterNamespace("CSSLOCAL", 0, 0, tmplput_csslocal, NULL, CTX_NONE);
914 RegisterNamespace("IMPORTANTMESSAGE", 0, 0, tmplput_importantmessage, NULL, CTX_NONE);
915 RegisterNamespace("TRAILING_JAVASCRIPT", 0, 0, tmplput_trailing_javascript, NULL, CTX_NONE);
916 RegisterNamespace("URL:DISPLAYNAME", 0, 1, tmplput_HANDLER_DISPLAYNAME, NULL, CTX_NONE);
917 RegisterNamespace("PACKAGESTRING", 0, 1, tmplput_packagestring, NULL, CTX_NONE);
920 snprintf(dir, SIZ, "%s/webcit.css", static_local_dir);
921 if (!access(dir, R_OK)) {
922 syslog(9, "Using local Stylesheet [%s]", dir);
923 csslocal = NewStrBufPlain(HKEY("<link href=\"static.local/webcit.css\" rel=\"stylesheet\" type=\"text/css\" />"));
926 syslog(9, "No Site-local Stylesheet [%s] installed.", dir);
931 ServerStartModule_WEBCIT
934 HandlerHash = NewHash(1, NULL);
939 ServerShutdownModule_WEBCIT
942 FreeStrBuf(&csslocal);
943 DeleteHash(&HandlerHash);
949 SessionNewModule_WEBCIT
952 sess->ImportantMsg = NewStrBuf();
953 sess->WBuf = NewStrBufPlain(NULL, SIZ * 4);
954 sess->HBuf = NewStrBufPlain(NULL, SIZ / 4);
958 SessionDetachModule_WEBCIT
961 DeleteHash(&sess->Directory);
963 FreeStrBuf(&sess->upload);
964 sess->upload_length = 0;
966 FreeStrBuf(&sess->trailing_javascript);
968 if (StrLength(sess->WBuf) > SIZ * 30) /* Bigger than 120K? release. */
970 FreeStrBuf(&sess->WBuf);
971 sess->WBuf = NewStrBuf();
974 FlushStrBuf(sess->WBuf);
975 FlushStrBuf(sess->HBuf);
976 if (StrLength(sess->ImportantMsg) > 0) {
977 FlushStrBuf(sess->ImportantMsg);
983 SessionDestroyModule_WEBCIT
986 FreeStrBuf(&sess->WBuf);
987 FreeStrBuf(&sess->HBuf);
988 FreeStrBuf(&sess->ImportantMsg);
989 FreeStrBuf(&sess->PushedDestination);