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-2018 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)
30 n = GetCount(WC->Hdr->HTTPHeaders);
31 Put(WC->Hdr->HTTPHeaders, IKEY(n), Data, DeleteIt);
34 void DeleteWebcitHandler(void *vHandler)
36 WebcitHandler *Handler = (WebcitHandler*) vHandler;
37 FreeStrBuf(&Handler->Name);
38 FreeStrBuf(&Handler->DisplayName);
42 void WebcitAddUrlHandler(const char * UrlString, long UrlSLen,
43 const char *DisplayName, long dslen,
47 WebcitHandler *NewHandler;
48 NewHandler = (WebcitHandler*) malloc(sizeof(WebcitHandler));
50 NewHandler->Flags = Flags;
51 NewHandler->Name = NewStrBufPlain(UrlString, UrlSLen);
52 StrBufShrinkToFit(NewHandler->Name, 1);
53 NewHandler->DisplayName = NewStrBufPlain(DisplayName, dslen);
54 StrBufShrinkToFit(NewHandler->DisplayName, 1);
55 Put(HandlerHash, UrlString, UrlSLen, NewHandler, DeleteWebcitHandler);
58 void tmplput_HANDLER_DISPLAYNAME(StrBuf *Target, WCTemplputParams *TP)
60 if (WC->Hdr->HR.Handler != NULL)
61 StrBufAppendTemplate(Target, TP, WC->Hdr->HR.Handler->DisplayName, 0);
66 * web-printing funcion. uses our vsnprintf wrapper
68 #ifdef UBER_VERBOSE_DEBUGGING
69 void wcc_printf(const char *FILE, const char *FUNCTION, long LINE, const char *format,...)
71 void wc_printf(const char *format,...)
77 WC->WBuf = NewStrBuf();
78 #ifdef UBER_VERBOSE_DEBUGGING
79 StrBufAppendPrintf(WC->WBuf, "\n%s:%s:%d[", FILE, FUNCTION, LINE);
82 va_start(arg_ptr, format);
83 StrBufVAppendPrintf(WC->WBuf, format, arg_ptr);
85 #ifdef UBER_VERBOSE_DEBUGGING
86 StrBufAppendPrintf(WC->WBuf, "]\n");
91 * http-header-printing funcion. uses our vsnprintf wrapper
93 void hprintf(const char *format,...)
97 va_start(arg_ptr, format);
98 StrBufVAppendPrintf(WC->HBuf, format, arg_ptr);
105 * wrap up an HTTP session, closes tags, etc.
107 * print_standard_html_footer should be set to:
108 * 0 - to transmit only,
109 * nonzero - to append the closing tags
111 void wDumpContent(int print_standard_html_footer)
113 if (print_standard_html_footer) {
114 wc_printf("</div> <!-- end of 'content' div -->\n");
115 do_template("trailing");
118 /* If we've been saving it all up for one big output burst,
119 * go ahead and do that now.
128 * Output HTTP headers and leading HTML for a page
130 void output_headers( int do_httpheaders, /* 1 = output HTTP headers */
131 int do_htmlhead, /* 1 = output HTML <head> section and <body> opener */
132 int do_room_banner, /* 1 = include the room banner and <div id="content"></div> */
133 int unset_cookies, /* 1 = session is terminating, so unset the cookies */
134 int suppress_check, /* 1 = suppress check for instant messages */
135 int cache /* 1 = allow browser to cache this page */
140 hprintf("HTTP/2.2 500 Internal Server Error");
141 else if (WC->Hdr->HaveRange > 1)
142 hprintf("HTTP/1.1 206 Partial Content\r\n");
144 hprintf("HTTP/1.1 200 OK\r\n");
146 http_datestring(httpnow, sizeof httpnow, time(NULL));
148 if (do_httpheaders) {
149 if (WC->serv_info != NULL)
150 hprintf("Content-type: text/html; charset=utf-8\r\n"
152 "Connection: close\r\n",
154 ChrPtr(WC->serv_info->serv_software));
156 hprintf("Content-type: text/html; charset=utf-8\r\n"
157 "Server: %s / [n/a]\n"
158 "Connection: close\r\n",
163 char httpTomorow[128];
165 http_datestring(httpTomorow, sizeof httpTomorow,
166 time(NULL) + 60 * 60 * 24 * 2);
168 hprintf("Pragma: public\r\n"
169 "Cache-Control: max-age=3600, must-revalidate\r\n"
170 "Last-modified: %s\r\n"
177 hprintf("Pragma: no-cache\r\n"
178 "Cache-Control: no-store\r\n"
183 if (cache < 2) stuff_to_cookie(unset_cookies);
188 if ( (WC->logged_in) && (!unset_cookies) ) {
189 DoTemplate(HKEY("paging"), NULL, &NoCtx);
191 if (do_room_banner) {
192 tmplput_roombanner(NULL, NULL);
196 if (do_room_banner) {
197 wc_printf("<div id=\"content\">\n");
201 void output_custom_content_header(const char *ctype) {
202 hprintf("HTTP/1.1 200 OK\r\n");
203 hprintf("Content-type: %s; charset=utf-8\r\n",ctype);
204 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
205 hprintf("Connection: close\r\n");
210 * Generic function to do an HTTP redirect. Easy and fun.
212 void http_redirect(const char *whichpage) {
213 hprintf("HTTP/1.1 302 Moved Temporarily\n");
214 hprintf("Location: %s\r\n", whichpage);
215 hprintf("URI: %s\r\n", whichpage);
216 hprintf("Content-type: text/html; charset=utf-8\r\n");
219 wc_printf("<html><body>");
220 wc_printf("Go <a href=\"%s\">here</A>.", whichpage);
221 wc_printf("</body></html>\n");
228 * Output a piece of content to the web browser using conformant HTTP and MIME semantics.
230 * If this function is called, it is expected that begin_burst() has already been called
231 * and some sort of content has been fed into the buffer. This function will transmit a
232 * bunch of headers to the client. end_burst() will add some headers of its own, and then
233 * transmit the buffered content to the client.
235 void http_transmit_thing(const char *content_type, int is_static)
238 syslog(LOG_DEBUG, "http_transmit_thing(%s)%s", content_type, ((is_static > 0) ? " (static)" : ""));
239 output_headers(0, 0, 0, 0, 0, is_static);
241 hprintf("Content-type: %s\r\n"
243 "Connection: close\r\n",
250 void http_transmit_headers(const char *content_type, int is_static, long is_chunked, int is_gzip)
253 syslog(LOG_DEBUG, "http_transmit_thing(%s)%s", content_type, ((is_static > 0) ? " (static)" : ""));
254 output_headers(0, 0, 0, 0, 0, is_static);
257 hprintf("Content-encoding: gzip\r\n");
259 if (WC->Hdr->HaveRange)
260 hprintf("Accept-Ranges: bytes\r\n"
261 "Content-Range: bytes %ld-%ld/%ld\r\n",
264 WC->Hdr->TotalBytes);
266 hprintf("Content-type: %s\r\n"
267 "Server: "PACKAGE_STRING"\r\n"
269 "Connection: close\r\n\r\n",
271 (is_chunked)?"Transfer-Encoding: chunked\r\n":"");
276 * Convenience functions to display a page containing only a string
278 * titlebarcolor color of the titlebar of the frame
279 * titlebarmsg text to display in the title bar
280 * messagetext body of the box
282 void convenience_page(const char *titlebarcolor, const char *titlebarmsg, const char *messagetext)
284 hprintf("HTTP/1.1 200 OK\n");
285 output_headers(1, 1, 1, 0, 0, 0);
286 wc_printf("<div id=\"room_banner_override\">\n");
287 wc_printf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
288 wc_printf("<span class=\"titlebar\">%s</span>\n", titlebarmsg);
289 wc_printf("</td></tr></table>\n");
290 wc_printf("</div>\n<div id=\"content\">\n");
291 escputs(messagetext);
292 wc_printf("<hr />\n");
298 * Display a blank page.
300 void blank_page(void) {
301 output_headers(1, 1, 0, 0, 0, 0);
307 * A template has been requested
309 void url_do_template(void) {
310 const StrBuf *MimeType;
311 const StrBuf *Tmpl = sbstr("template");
313 MimeType = DoTemplate(SKEY(Tmpl), NULL, &NoCtx);
314 http_transmit_thing(ChrPtr(MimeType), 0);
320 * convenience function to indicate success
322 void display_success(const char *successmessage)
324 convenience_page("007700", "OK", successmessage);
329 * Authorization required page (sends a 401, causing the browser to request login credentials)
331 void authorization_required(void)
333 const char *message = "";
335 hprintf("HTTP/1.1 401 Authorization Required\r\n");
337 "Server: %s / %s\r\n"
338 "Connection: close\r\n",
339 PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software)
341 hprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n", ChrPtr(WC->serv_info->serv_humannode));
343 /* if this is a false cookie authentication, remove it to avoid endless loops. */
344 if (StrLength(WC->Hdr->HR.RawCookie) > 0)
347 hprintf("Content-Type: text/html\r\n");
350 wc_printf(_("Authorization Required"));
351 wc_printf("</h1>\r\n");
353 if (WC->ImportantMsg != NULL) {
354 message = ChrPtr(WC->ImportantMsg);
358 _("The resource you requested requires a valid username and password. "
359 "You could not be logged in: %s\n"),
367 * Convenience functions to wrap around asynchronous ajax responses
369 void begin_ajax_response(void) {
371 FlushStrBuf(WC->HBuf);
372 output_headers(0, 0, 0, 0, 0, 0);
374 hprintf("Content-type: text/html; charset=UTF-8\r\n"
376 "Connection: close\r\n"
384 * print ajax response footer
386 void end_ajax_response(void) {
392 * Wraps a Citadel server command in an AJAX transaction.
394 void ajax_servcmd(void)
402 syslog(LOG_DEBUG, "ajax_servcmd() g_cmd=\"%s\"", bstr("g_cmd") );
403 begin_ajax_response();
405 serv_puts(bstr("g_cmd"));
406 StrBuf_ServGetln(Buf);
407 StrBufAppendBuf(WC->WBuf, Buf, 0);
408 StrBufAppendBufPlain(WC->WBuf, HKEY("\n"), 0);
410 switch (GetServerStatus(Buf, NULL)) {
412 serv_puts("\n\n000");
413 if ( (StrLength(Buf)==3) &&
414 !strcmp(ChrPtr(Buf), "000")) {
415 StrBufAppendBufPlain(WC->WBuf, HKEY("\000"), 0);
420 if (StrBuf_ServGetln(Buf) < 0)
422 if ( (StrLength(Buf)==3) &&
423 !strcmp(ChrPtr(Buf), "000")) {
426 StrBufAppendBuf(WC->WBuf, Buf, 0);
427 StrBufAppendBufPlain(WC->WBuf, HKEY("\n"), 0);
431 text_to_server(bstr("g_input"));
435 len = atol(&ChrPtr(Buf)[4]);
436 StrBuf_ServGetBLOBBuffered(Buf, len);
439 len = atol(&ChrPtr(Buf)[4]);
441 memset(junk, 0, len);
442 serv_write(junk, len);
449 * This is kind of an ugly hack, but this is the only place it can go.
450 * If the command was GEXP, then the instant messenger window must be
451 * running, so reset the "last_pager_check" watchdog timer so
452 * that page_popup() doesn't try to open it a second time. TODO: page_popup isn't with us anymore.
454 if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) {
455 WC->last_pager_check = time(NULL);
462 * Helper function for the asynchronous check to see if we need
463 * to open the instant messenger window.
465 void seconds_since_last_gexp(void)
469 if ( (time(NULL) - WC->last_pager_check) < 30) {
475 serv_getln(buf, sizeof buf);
487 * Save a URL destination so we can go to it later
489 void push_destination(void) {
492 wc_printf("no session");
496 FreeStrBuf(&WC->PushedDestination);
497 WC->PushedDestination = NewStrBufDup(sbstr("url"));
499 syslog(LOG_DEBUG, "Push: %s", ChrPtr(WC->PushedDestination));
505 * Go to the URL saved by push_destination()
507 void pop_destination(void) {
509 * If we are in the middle of a new user signup, the server may request that
510 * we first pass through a registration screen.
512 if ((WC) && (WC->need_regi)) {
513 if ((WC->PushedDestination != NULL) && (StrLength(WC->PushedDestination) > 0)) {
514 /* Registering will take us to the My Citadel Config room, so save our place */
515 StrBufAppendBufPlain(WC->PushedDestination, HKEY("?go="), 0);
516 StrBufUrlescAppend(WC->PushedDestination, WC->CurRoom.name, NULL);
524 * Do something reasonable if we somehow ended up requesting a pop without
525 * having first done a push.
527 if ( (!WC) || (WC->PushedDestination == NULL) || (StrLength(WC->PushedDestination) == 0) ) {
533 * All righty then! We have a destination saved, so go there now.
536 syslog(LOG_DEBUG, "Pop: %s", ChrPtr(WC->PushedDestination));
538 http_redirect(ChrPtr(WC->PushedDestination));
542 int ReadPostData(void) {
545 int urlencoded_post = 0;
546 StrBuf *content = NULL;
548 urlencoded_post = (strncasecmp(ChrPtr(WC->Hdr->HR.ContentType), "application/x-www-form-urlencoded", 33) == 0) ;
550 content = NewStrBufPlain(NULL, WC->Hdr->HR.ContentLength + 256);
552 if (!urlencoded_post) {
553 StrBufPrintf(content,
555 "Content-length: %ld\n\n",
556 ChrPtr(WC->Hdr->HR.ContentType),
557 WC->Hdr->HR.ContentLength
561 /* Read the entire input data at once. */
562 rc = client_read_to(WC->Hdr, content, WC->Hdr->HR.ContentLength, SLEEPING);
567 if (urlencoded_post) {
568 ParseURLParams(content);
570 else if (!strncasecmp(ChrPtr(WC->Hdr->HR.ContentType), "multipart", 9)) {
575 len = StrLength(content);
576 Buf = SmashStrBuf(&content);
578 mime_parser(Buf, BufEnd, *upload_handler, NULL, NULL, NULL, 0);
581 else if (WC->Hdr->HR.ContentLength > 0) {
582 WC->upload = content;
583 WC->upload_length = StrLength(WC->upload);
586 FreeStrBuf(&content);
591 int Conditional_REST_DEPTH(StrBuf *Target, WCTemplputParams *TP)
596 if (WC->Hdr->HR.Handler != NULL)
598 Depth = GetTemplateTokenNumber(Target, TP, 2, 0);
599 IsDepth = GetCount(WC->Directory) + offset;
601 // LogTemplateError(Target, "bla", 1, TP, "REST_DEPTH: %ld : %ld\n", Depth, IsDepth);
604 return IsDepth > Depth;
607 return Depth == IsDepth;
613 * Entry point for WebCit transaction
615 void session_loop(void)
621 * We stuff these with the values coming from the client cookies,
622 * so we can use them to reconnect a timed out session if we have to.
624 WC->upload_length = 0;
626 WC->Hdr->nWildfireHeaders = 0;
628 if (WC->Hdr->HR.ContentLength > 0) {
629 if (ReadPostData() < 0) {
635 WC->trailing_javascript = NewStrBuf();
637 /* Convert base64-encoded URL's back to plain text */
638 if (!strncmp(ChrPtr(WC->Hdr->this_page), "/B64", 4)) {
639 StrBufCutLeft(WC->Hdr->this_page, 4);
640 StrBufDecodeBase64(WC->Hdr->this_page);
641 http_redirect(ChrPtr(WC->Hdr->this_page));
642 goto SKIP_ALL_THIS_CRAP;
645 /* If there are variables in the URL, we must grab them now */
646 if (WC->Hdr->PlainArgs != NULL)
647 ParseURLParams(WC->Hdr->PlainArgs);
649 /* If the client sent a nonce that is incorrect, kill the request. */
650 if (havebstr("nonce")) {
652 syslog(LOG_DEBUG, "Comparing supplied nonce %s to session nonce %d",
653 bstr("nonce"), WC->nonce
655 if (ibstr("nonce") != WC->nonce) {
656 syslog(LOG_INFO, "Ignoring request with mismatched nonce.");
657 hprintf("HTTP/1.1 404 Security check failed\r\n");
658 hprintf("Content-Type: text/plain\r\n");
660 wc_printf("Security check failed.\r\n");
662 goto SKIP_ALL_THIS_CRAP;
667 * If we're not connected to a Citadel server, try to hook up the connection now.
669 if (!WC->connected) {
670 if (GetConnected()) {
671 hprintf("HTTP/1.1 503 Service Unavailable\r\n");
672 hprintf("Content-Type: text/html\r\n");
674 wc_printf("<html><head><title>503 Service Unavailable</title></head><body>\n");
675 wc_printf(_("This program was unable to connect or stay "
676 "connected to the Citadel server. Please report "
677 "this problem to your system administrator.")
680 wc_printf("<a href=\"http://www.citadel.org/doku.php/"
681 "faq:generalquestions:webcit_unable_to_connect\">%s</a>",
684 wc_printf("</body></html>\n");
686 goto SKIP_ALL_THIS_CRAP;
691 * If we're not logged in, but we have authentication data (either from
692 * a cookie or from http-auth), try logging in to Citadel using that.
694 if ( (!WC->logged_in)
695 && (StrLength(WC->Hdr->c_username) > 0)
696 && (StrLength(WC->Hdr->c_password) > 0)
701 serv_printf("USER %s", ChrPtr(WC->Hdr->c_username));
702 StrBuf_ServGetln(Buf);
703 if (GetServerStatus(Buf, &Status) == 3) {
704 serv_printf("PASS %s", ChrPtr(WC->Hdr->c_password));
705 StrBuf_ServGetln(Buf);
706 if (GetServerStatus(Buf, NULL) == 2) {
707 become_logged_in(WC->Hdr->c_username,
708 WC->Hdr->c_password, Buf);
710 /* Should only display when password is wrong */
711 WC->ImportantMsg = NewStrBufPlain(ChrPtr(Buf) + 4, StrLength(Buf) - 4);
712 authorization_required();
714 goto SKIP_ALL_THIS_CRAP;
717 else if (Status == 541) {
722 xhttp = (WC->Hdr->HR.eReqType != eGET) &&
723 (WC->Hdr->HR.eReqType != ePOST) &&
724 (WC->Hdr->HR.eReqType != eHEAD);
727 * If a 'go' (or 'gotofirst') parameter has been specified, attempt to goto that room
728 * prior to doing anything else.
730 if (havebstr("go")) {
733 syslog(LOG_DEBUG, "Explicit room selection: %s", bstr("go"));
734 ret = gotoroom(sbstr("go")); /* do quietly to avoid session output! */
735 if ((ret/100) != 2) {
737 syslog(LOG_DEBUG, "Unable to change to [%s]; Reason: %d", bstr("go"), ret);
740 else if (havebstr("gotofirst")) {
743 syslog(LOG_DEBUG, "Explicit room selection: %s", bstr("gotofirst"));
744 ret = gotoroom(sbstr("gotofirst")); /* do quietly to avoid session output! */
745 if ((ret/100) != 2) {
746 syslog(LOG_INFO, "Unable to change to [%s]; Reason: %d", bstr("gotofirst"), ret);
751 * If we aren't in any room yet, but we have cookie data telling us where we're
752 * supposed to be, and 'go' was not specified, then go there.
754 else if ( (StrLength(WC->CurRoom.name) == 0) && ( (StrLength(WC->Hdr->c_roomname) > 0) )) {
758 syslog(LOG_DEBUG, "We are in '%s' but cookie indicates '%s', going there...",
759 ChrPtr(WC->CurRoom.name),
760 ChrPtr(WC->Hdr->c_roomname)
762 ret = gotoroom(WC->Hdr->c_roomname); /* do quietly to avoid session output! */
763 if ((ret/100) != 2) {
765 syslog(LOG_DEBUG, "COOKIEGOTO: Unable to change to [%s]; Reason: %d",
766 ChrPtr(WC->Hdr->c_roomname), ret);
770 if (WC->Hdr->HR.Handler != NULL) {
771 if ( (!WC->logged_in)
772 && ((WC->Hdr->HR.Handler->Flags & ANONYMOUS) == 0)
773 && (WC->serv_info != NULL)
774 && (WC->serv_info->serv_supports_guest == 0)
779 if ((WC->Hdr->HR.Handler->Flags & AJAX) != 0) {
780 begin_ajax_response();
782 WC->Hdr->HR.Handler->F();
783 if ((WC->Hdr->HR.Handler->Flags & AJAX) != 0) {
788 /* When all else fails, display the default landing page or a main menu. */
791 * ordinary browser users get a nice login screen, DAV etc. requsets
792 * are given a 401 so they can handle it appropriate.
794 if (!WC->logged_in) {
796 authorization_required();
799 display_default_landing_page();
803 * Toplevel dav requests? or just a flat browser request?
823 * Display the appropriate landing page for this site.
825 void display_default_landing_page(void) {
826 if (WC && WC->serv_info && WC->serv_info->serv_supports_guest) {
829 if (havebstr("go")) {
831 syslog(LOG_DEBUG, "Explicit room selection: %s", bstr("go"));
832 smart_goto(sbstr("go"));
834 else if (default_landing_page) {
835 http_redirect(default_landing_page);
838 StrBuf *teh_lobby = NewStrBufPlain(HKEY("_BASEROOM_"));
839 smart_goto(teh_lobby);
840 FreeStrBuf(&teh_lobby);
850 * Replacement for sleep() that uses select() in order to avoid SIGALRM
852 void sleeeeeeeeeep(int seconds)
858 select(0, NULL, NULL, NULL, &tv);
861 int Conditional_IS_HTTPS(StrBuf *Target, WCTemplputParams *TP)
863 return is_https != 0;
866 void AppendImportantMessage(const char *pch, long len)
869 if (StrLength(WC->ImportantMsg) > 0) {
870 StrBufAppendBufPlain(WC->ImportantMsg, HKEY("\n"), 0);
873 StrBufAppendBufPlain(WC->ImportantMsg, pch, len, 0);
876 int ConditionalImportantMesage(StrBuf *Target, WCTemplputParams *TP)
879 return (StrLength(WC->ImportantMsg) > 0);
886 void tmplput_importantmessage(StrBuf *Target, WCTemplputParams *TP)
890 if (StrLength(WC->ImportantMsg) > 0) {
891 StrBufAppendTemplate(Target, TP, WC->ImportantMsg, 0);
896 void tmplput_trailing_javascript(StrBuf *Target, WCTemplputParams *TP)
900 StrBufAppendTemplate(Target, TP, WC->trailing_javascript, 0);
904 void tmplput_csslocal(StrBuf *Target, WCTemplputParams *TP)
906 StrBufAppendBuf(Target,
910 void tmplput_packagestring(StrBuf *Target, WCTemplputParams *TP) {
911 StrBufAppendBufPlain(Target, 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("COND:IMPMSG", 0, ConditionalImportantMesage, CTX_NONE);
933 RegisterConditional("COND:REST:DEPTH", 0, Conditional_REST_DEPTH, CTX_NONE);
934 RegisterConditional("COND:IS_HTTPS", 0, Conditional_IS_HTTPS, CTX_NONE);
936 RegisterNamespace("CSSLOCAL", 0, 0, tmplput_csslocal, NULL, CTX_NONE);
937 RegisterNamespace("IMPORTANTMESSAGE", 0, 1, 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(LOG_INFO, "Using local Stylesheet [%s]", dir);
946 csslocal = NewStrBufPlain(HKEY("<link href=\"static.local/webcit.css\" rel=\"stylesheet\" type=\"text/css\" />"));
949 syslog(LOG_INFO, "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);
999 if (StrLength(sess->ImportantMsg) > 0) {
1000 FlushStrBuf(sess->ImportantMsg);
1006 SessionDestroyModule_WEBCIT
1009 FreeStrBuf(&sess->WBuf);
1010 FreeStrBuf(&sess->HBuf);
1011 FreeStrBuf(&sess->ImportantMsg);
1012 FreeStrBuf(&sess->PushedDestination);