1 // This is the main transaction loop of the web service. It maintains a
2 // persistent session to the Citadel server, handling HTTP WebCit requests as
3 // they arrive and presenting a user interface.
5 // Copyright (c) 1996-2021 by the citadel.org team
7 // This program is open source software. You can redistribute it and/or
8 // modify it under the terms of the GNU General Public License, version 3.
11 #define SHOW_ME_VAPPEND_PRINTF
16 #include "webserver.h"
18 StrBuf *csslocal = NULL;
19 HashList *HandlerHash = NULL;
21 void stuff_to_cookie(int unset_cookie);
22 extern int GetConnected(void);
25 void PutRequestLocalMem(void *Data, DeleteHashDataFunc DeleteIt)
29 n = GetCount(WC->Hdr->HTTPHeaders);
30 Put(WC->Hdr->HTTPHeaders, IKEY(n), Data, DeleteIt);
33 void DeleteWebcitHandler(void *vHandler)
35 WebcitHandler *Handler = (WebcitHandler*) vHandler;
36 FreeStrBuf(&Handler->Name);
37 FreeStrBuf(&Handler->DisplayName);
41 void WebcitAddUrlHandler(const char * UrlString, long UrlSLen,
42 const char *DisplayName, long dslen,
46 WebcitHandler *NewHandler;
47 NewHandler = (WebcitHandler*) malloc(sizeof(WebcitHandler));
49 NewHandler->Flags = Flags;
50 NewHandler->Name = NewStrBufPlain(UrlString, UrlSLen);
51 StrBufShrinkToFit(NewHandler->Name, 1);
52 NewHandler->DisplayName = NewStrBufPlain(DisplayName, dslen);
53 StrBufShrinkToFit(NewHandler->DisplayName, 1);
54 Put(HandlerHash, UrlString, UrlSLen, NewHandler, DeleteWebcitHandler);
57 void tmplput_HANDLER_DISPLAYNAME(StrBuf *Target, WCTemplputParams *TP)
59 if (WC->Hdr->HR.Handler != NULL)
60 StrBufAppendTemplate(Target, TP, WC->Hdr->HR.Handler->DisplayName, 0);
65 * web-printing funcion. uses our vsnprintf wrapper
67 #ifdef UBER_VERBOSE_DEBUGGING
68 void wcc_printf(const char *FILE, const char *FUNCTION, long LINE, const char *format,...)
70 void wc_printf(const char *format,...)
76 WC->WBuf = NewStrBuf();
77 #ifdef UBER_VERBOSE_DEBUGGING
78 StrBufAppendPrintf(WC->WBuf, "\n%s:%s:%d[", FILE, FUNCTION, LINE);
81 va_start(arg_ptr, format);
82 StrBufVAppendPrintf(WC->WBuf, format, arg_ptr);
84 #ifdef UBER_VERBOSE_DEBUGGING
85 StrBufAppendPrintf(WC->WBuf, "]\n");
90 * http-header-printing funcion. uses our vsnprintf wrapper
92 void hprintf(const char *format,...)
96 va_start(arg_ptr, format);
97 StrBufVAppendPrintf(WC->HBuf, format, arg_ptr);
104 * wrap up an HTTP session, closes tags, etc.
106 * print_standard_html_footer should be set to:
107 * 0 - to transmit only,
108 * nonzero - to append the closing tags
110 void wDumpContent(int print_standard_html_footer)
112 if (print_standard_html_footer) {
113 wc_printf("</div> <!-- end of 'content' div -->\n");
114 do_template("trailing");
117 /* If we've been saving it all up for one big output burst,
118 * go ahead and do that now.
127 * Output HTTP headers and leading HTML for a page
129 void output_headers( int do_httpheaders, /* 1 = output HTTP headers */
130 int do_htmlhead, /* 1 = output HTML <head> section and <body> opener */
131 int do_room_banner, /* 1 = include the room banner and <div id="content"></div> */
132 int unset_cookies, /* 1 = session is terminating, so unset the cookies */
133 int suppress_check, /* 1 = suppress check for instant messages */
134 int cache /* 1 = allow browser to cache this page */
139 hprintf("HTTP/2.2 500 Internal Server Error");
140 else if (WC->Hdr->HaveRange > 1)
141 hprintf("HTTP/1.1 206 Partial Content\r\n");
143 hprintf("HTTP/1.1 200 OK\r\n");
145 http_datestring(httpnow, sizeof httpnow, time(NULL));
147 if (do_httpheaders) {
148 if (WC->serv_info != NULL)
149 hprintf("Content-type: text/html; charset=utf-8\r\n"
151 "Connection: close\r\n",
153 ChrPtr(WC->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 ( (WC->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)
237 syslog(LOG_DEBUG, "http_transmit_thing(%s)%s", content_type, ((is_static > 0) ? " (static)" : ""));
238 output_headers(0, 0, 0, 0, 0, is_static);
240 hprintf("Content-type: %s\r\n"
242 "Connection: close\r\n",
249 void http_transmit_headers(const char *content_type, int is_static, long is_chunked, int is_gzip)
252 syslog(LOG_DEBUG, "http_transmit_thing(%s)%s", content_type, ((is_static > 0) ? " (static)" : ""));
253 output_headers(0, 0, 0, 0, 0, is_static);
256 hprintf("Content-encoding: gzip\r\n");
258 if (WC->Hdr->HaveRange)
259 hprintf("Accept-Ranges: bytes\r\n"
260 "Content-Range: bytes %ld-%ld/%ld\r\n",
263 WC->Hdr->TotalBytes);
265 hprintf("Content-type: %s\r\n"
266 "Server: "PACKAGE_STRING"\r\n"
268 "Connection: close\r\n\r\n",
270 (is_chunked)?"Transfer-Encoding: chunked\r\n":"");
275 * Convenience functions to display a page containing only a string
277 * titlebarcolor color of the titlebar of the frame
278 * titlebarmsg text to display in the title bar
279 * messagetext body of the box
281 void convenience_page(const char *titlebarcolor, const char *titlebarmsg, const char *messagetext)
283 hprintf("HTTP/1.1 200 OK\n");
284 output_headers(1, 1, 1, 0, 0, 0);
285 wc_printf("<div id=\"room_banner_override\">\n");
286 wc_printf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
287 wc_printf("<span class=\"titlebar\">%s</span>\n", titlebarmsg);
288 wc_printf("</td></tr></table>\n");
289 wc_printf("</div>\n<div id=\"content\">\n");
290 escputs(messagetext);
291 wc_printf("<hr />\n");
297 * Display a blank page.
299 void blank_page(void) {
300 output_headers(1, 1, 0, 0, 0, 0);
306 * A template has been requested
308 void url_do_template(void) {
309 const StrBuf *MimeType;
310 const StrBuf *Tmpl = sbstr("template");
312 MimeType = DoTemplate(SKEY(Tmpl), NULL, &NoCtx);
313 http_transmit_thing(ChrPtr(MimeType), 0);
319 * convenience function to indicate success
321 void display_success(const char *successmessage)
323 convenience_page("007700", "OK", successmessage);
328 * Authorization required page (sends a 401, causing the browser to request login credentials)
330 void authorization_required(void)
332 const char *message = "";
334 hprintf("HTTP/1.1 401 Authorization Required\r\n");
336 "Server: %s / %s\r\n"
337 "Connection: close\r\n",
338 PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software)
340 hprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n", ChrPtr(WC->serv_info->serv_humannode));
342 /* if this is a false cookie authentication, remove it to avoid endless loops. */
343 if (StrLength(WC->Hdr->HR.RawCookie) > 0)
346 hprintf("Content-Type: text/html\r\n");
349 wc_printf(_("Authorization Required"));
350 wc_printf("</h1>\r\n");
352 if (WC->ImportantMsg != NULL) {
353 message = ChrPtr(WC->ImportantMsg);
357 _("The resource you requested requires a valid username and password. "
358 "You could not be logged in: %s\n"),
366 * Convenience functions to wrap around asynchronous ajax responses
368 void begin_ajax_response(void) {
370 FlushStrBuf(WC->HBuf);
371 output_headers(0, 0, 0, 0, 0, 0);
373 hprintf("Content-type: text/html; charset=UTF-8\r\n"
375 "Connection: close\r\n"
383 * print ajax response footer
385 void end_ajax_response(void) {
391 * Wraps a Citadel server command in an AJAX transaction.
393 void ajax_servcmd(void) {
400 syslog(LOG_DEBUG, "ajax_servcmd() g_cmd=\"%s\"", bstr("g_cmd") );
402 begin_ajax_response();
404 serv_puts(bstr("g_cmd"));
405 StrBuf_ServGetln(Buf);
406 StrBufAppendBuf(WC->WBuf, Buf, 0);
407 StrBufAppendBufPlain(WC->WBuf, HKEY("\n"), 0);
409 switch (GetServerStatus(Buf, NULL)) {
411 serv_puts("\n\n000");
412 if ( (StrLength(Buf)==3) &&
413 !strcmp(ChrPtr(Buf), "000")) {
414 StrBufAppendBufPlain(WC->WBuf, HKEY("\000"), 0);
419 if (StrBuf_ServGetln(Buf) < 0)
421 if ( (StrLength(Buf)==3) &&
422 !strcmp(ChrPtr(Buf), "000")) {
425 StrBufAppendBuf(WC->WBuf, Buf, 0);
426 StrBufAppendBufPlain(WC->WBuf, HKEY("\n"), 0);
430 text_to_server(bstr("g_input"));
434 len = atol(&ChrPtr(Buf)[4]);
435 StrBuf_ServGetBLOBBuffered(Buf, len);
438 len = atol(&ChrPtr(Buf)[4]);
440 memset(junk, 0, len);
441 serv_write(junk, len);
448 * This is kind of an ugly hack, but this is the only place it can go.
449 * If the command was GEXP, then the instant messenger window must be
450 * running, so reset the "last_pager_check" watchdog timer so
451 * that page_popup() doesn't try to open it a second time. TODO: page_popup isn't with us anymore.
453 if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) {
454 WC->last_pager_check = time(NULL);
461 * Helper function for the asynchronous check to see if we need
462 * to open the instant messenger window.
464 void seconds_since_last_gexp(void)
468 if ( (time(NULL) - WC->last_pager_check) < 30) {
474 serv_getln(buf, sizeof buf);
486 * Save a URL destination so we can go to it later
488 void push_destination(void) {
491 wc_printf("no session");
495 FreeStrBuf(&WC->PushedDestination);
496 WC->PushedDestination = NewStrBufDup(sbstr("url"));
498 syslog(LOG_DEBUG, "Push: %s", ChrPtr(WC->PushedDestination));
504 * Go to the URL saved by push_destination()
506 void pop_destination(void) {
508 * If we are in the middle of a new user signup, the server may request that
509 * we first pass through a registration screen.
511 if ((WC) && (WC->need_regi)) {
512 if ((WC->PushedDestination != NULL) && (StrLength(WC->PushedDestination) > 0)) {
513 /* Registering will take us to the My Citadel Config room, so save our place */
514 StrBufAppendBufPlain(WC->PushedDestination, HKEY("?go="), 0);
515 StrBufUrlescAppend(WC->PushedDestination, WC->CurRoom.name, NULL);
523 * Do something reasonable if we somehow ended up requesting a pop without
524 * having first done a push.
526 if ( (!WC) || (WC->PushedDestination == NULL) || (StrLength(WC->PushedDestination) == 0) ) {
532 * All righty then! We have a destination saved, so go there now.
535 syslog(LOG_DEBUG, "Pop: %s", ChrPtr(WC->PushedDestination));
537 http_redirect(ChrPtr(WC->PushedDestination));
541 int ReadPostData(void) {
543 int urlencoded_post = 0;
544 StrBuf *content = NULL;
546 urlencoded_post = (strncasecmp(ChrPtr(WC->Hdr->HR.ContentType), "application/x-www-form-urlencoded", 33) == 0) ;
548 content = NewStrBufPlain(NULL, WC->Hdr->HR.ContentLength + 256);
550 if (!urlencoded_post) {
551 StrBufPrintf(content,
553 "Content-length: %ld\n\n",
554 ChrPtr(WC->Hdr->HR.ContentType),
555 WC->Hdr->HR.ContentLength
559 /* Read the entire input data at once. */
560 rc = client_read_to(WC->Hdr, content, WC->Hdr->HR.ContentLength, SLEEPING);
565 if (urlencoded_post) {
566 ParseURLParams(content);
568 else if (!strncasecmp(ChrPtr(WC->Hdr->HR.ContentType), "multipart", 9)) {
573 len = StrLength(content);
574 Buf = SmashStrBuf(&content);
576 mime_parser(Buf, BufEnd, *upload_handler, NULL, NULL, NULL, 0);
579 else if (WC->Hdr->HR.ContentLength > 0) {
580 WC->upload = content;
581 WC->upload_length = StrLength(WC->upload);
584 FreeStrBuf(&content);
589 int Conditional_REST_DEPTH(StrBuf *Target, WCTemplputParams *TP)
594 if (WC->Hdr->HR.Handler != NULL)
596 Depth = GetTemplateTokenNumber(Target, TP, 2, 0);
597 IsDepth = GetCount(WC->Directory) + offset;
599 // LogTemplateError(Target, "bla", 1, TP, "REST_DEPTH: %ld : %ld\n", Depth, IsDepth);
602 return IsDepth > Depth;
605 return Depth == IsDepth;
611 * Entry point for WebCit transaction
613 void session_loop(void)
619 * We stuff these with the values coming from the client cookies,
620 * so we can use them to reconnect a timed out session if we have to.
622 WC->upload_length = 0;
624 WC->Hdr->nWildfireHeaders = 0;
626 if (WC->Hdr->HR.ContentLength > 0) {
627 if (ReadPostData() < 0) {
633 WC->trailing_javascript = NewStrBuf();
635 /* Convert base64-encoded URL's back to plain text */
636 if (!strncmp(ChrPtr(WC->Hdr->this_page), "/B64", 4)) {
637 StrBufCutLeft(WC->Hdr->this_page, 4);
638 StrBufDecodeBase64(WC->Hdr->this_page);
639 http_redirect(ChrPtr(WC->Hdr->this_page));
640 goto SKIP_ALL_THIS_CRAP;
643 /* If there are variables in the URL, we must grab them now */
644 if (WC->Hdr->PlainArgs != NULL) {
645 ParseURLParams(WC->Hdr->PlainArgs);
648 /* If the client sent a nonce that is incorrect, kill the request. */
649 if (havebstr("nonce")) {
651 syslog(LOG_DEBUG, "Comparing supplied nonce %s to session nonce %d", bstr("nonce"), WC->nonce);
653 if (ibstr("nonce") != WC->nonce) {
654 syslog(LOG_INFO, "Ignoring request with mismatched nonce.");
655 hprintf("HTTP/1.1 404 Security check failed\r\n");
656 hprintf("Content-Type: text/plain\r\n");
658 wc_printf("Security check failed.\r\n");
660 goto SKIP_ALL_THIS_CRAP;
665 * If we're not connected to a Citadel server, try to hook up the connection now.
667 if (!WC->connected) {
668 if (GetConnected()) {
669 hprintf("HTTP/1.1 503 Service Unavailable\r\n");
670 hprintf("Content-Type: text/html\r\n");
672 wc_printf("<html><head><title>503 Service Unavailable</title></head><body>\n");
673 wc_printf(_("This program was unable to connect or stay "
674 "connected to the Citadel server. Please report "
675 "this problem to your system administrator.")
678 wc_printf("<a href=\"http://www.citadel.org/doku.php/"
679 "faq:generalquestions:webcit_unable_to_connect\">%s</a>",
682 wc_printf("</body></html>\n");
684 goto SKIP_ALL_THIS_CRAP;
689 * If we're not logged in, but we have authentication data (either from
690 * a cookie or from http-auth), try logging in to Citadel using that.
692 if ( (!WC->logged_in)
693 && (StrLength(WC->Hdr->c_username) > 0)
694 && (StrLength(WC->Hdr->c_password) > 0)
699 serv_printf("USER %s", ChrPtr(WC->Hdr->c_username));
700 StrBuf_ServGetln(Buf);
701 if (GetServerStatus(Buf, &Status) == 3) {
702 serv_printf("PASS %s", ChrPtr(WC->Hdr->c_password));
703 StrBuf_ServGetln(Buf);
704 if (GetServerStatus(Buf, NULL) == 2) {
705 become_logged_in(WC->Hdr->c_username, WC->Hdr->c_password, Buf);
708 /* Should only display when password is wrong */
709 WC->ImportantMsg = NewStrBufPlain(ChrPtr(Buf) + 4, StrLength(Buf) - 4);
710 authorization_required();
712 goto SKIP_ALL_THIS_CRAP;
715 else if (Status == 541) {
720 xhttp = (WC->Hdr->HR.eReqType != eGET) &&
721 (WC->Hdr->HR.eReqType != ePOST) &&
722 (WC->Hdr->HR.eReqType != eHEAD);
725 * If a 'go' (or 'gotofirst') parameter has been specified, attempt to goto that room
726 * prior to doing anything else.
728 if (havebstr("go")) {
731 syslog(LOG_DEBUG, "Explicit room selection: %s", bstr("go"));
732 ret = gotoroom(sbstr("go")); /* do quietly to avoid session output! */
733 if ((ret/100) != 2) {
735 syslog(LOG_DEBUG, "Unable to change to [%s]; Reason: %d", bstr("go"), ret);
738 else if (havebstr("gotofirst")) {
741 syslog(LOG_DEBUG, "Explicit room selection: %s", bstr("gotofirst"));
742 ret = gotoroom(sbstr("gotofirst")); /* do quietly to avoid session output! */
743 if ((ret/100) != 2) {
744 syslog(LOG_INFO, "Unable to change to [%s]; Reason: %d", bstr("gotofirst"), ret);
749 * If we aren't in any room yet, but we have cookie data telling us where we're
750 * supposed to be, and 'go' was not specified, then go there.
752 else if ( (StrLength(WC->CurRoom.name) == 0) && ( (StrLength(WC->Hdr->c_roomname) > 0) )) {
756 syslog(LOG_DEBUG, "We are in '%s' but cookie indicates '%s', going there...",
757 ChrPtr(WC->CurRoom.name),
758 ChrPtr(WC->Hdr->c_roomname)
760 ret = gotoroom(WC->Hdr->c_roomname); /* do quietly to avoid session output! */
761 if ((ret/100) != 2) {
763 syslog(LOG_DEBUG, "COOKIEGOTO: Unable to change to [%s]; Reason: %d",
764 ChrPtr(WC->Hdr->c_roomname), ret);
768 if (WC->Hdr->HR.Handler != NULL) {
769 if ( (!WC->logged_in)
770 && ((WC->Hdr->HR.Handler->Flags & ANONYMOUS) == 0)
771 && (WC->serv_info != NULL)
772 && (WC->serv_info->serv_supports_guest == 0)
777 if ((WC->Hdr->HR.Handler->Flags & AJAX) != 0) {
778 begin_ajax_response();
780 WC->Hdr->HR.Handler->F();
781 if ((WC->Hdr->HR.Handler->Flags & AJAX) != 0) {
786 /* When all else fails, display the default landing page or a main menu. */
789 * ordinary browser users get a nice login screen, DAV etc. requsets
790 * are given a 401 so they can handle it appropriate.
792 if (!WC->logged_in) {
794 authorization_required();
797 display_default_landing_page();
801 * Toplevel dav requests? or just a flat browser request?
821 * Display the appropriate landing page for this site.
823 void display_default_landing_page(void) {
824 if (WC && WC->serv_info && WC->serv_info->serv_supports_guest) {
827 if (havebstr("go")) {
829 syslog(LOG_DEBUG, "Explicit room selection: %s", bstr("go"));
830 smart_goto(sbstr("go"));
832 else if (default_landing_page) {
833 http_redirect(default_landing_page);
836 StrBuf *teh_lobby = NewStrBufPlain(HKEY("_BASEROOM_"));
837 smart_goto(teh_lobby);
838 FreeStrBuf(&teh_lobby);
848 * Replacement for sleep() that uses select() in order to avoid SIGALRM
850 void sleeeeeeeeeep(int seconds)
856 select(0, NULL, NULL, NULL, &tv);
859 int Conditional_IS_HTTPS(StrBuf *Target, WCTemplputParams *TP)
861 return is_https != 0;
864 void AppendImportantMessage(const char *pch, long len)
867 if (StrLength(WC->ImportantMsg) > 0) {
868 StrBufAppendBufPlain(WC->ImportantMsg, HKEY("\n"), 0);
871 StrBufAppendBufPlain(WC->ImportantMsg, pch, len, 0);
874 int ConditionalImportantMesage(StrBuf *Target, WCTemplputParams *TP)
877 return (StrLength(WC->ImportantMsg) > 0);
884 void tmplput_importantmessage(StrBuf *Target, WCTemplputParams *TP)
888 if (StrLength(WC->ImportantMsg) > 0) {
889 StrBufAppendTemplate(Target, TP, WC->ImportantMsg, 0);
894 void tmplput_trailing_javascript(StrBuf *Target, WCTemplputParams *TP)
898 StrBufAppendTemplate(Target, TP, WC->trailing_javascript, 0);
902 void tmplput_csslocal(StrBuf *Target, WCTemplputParams *TP)
904 StrBufAppendBuf(Target,
908 void tmplput_packagestring(StrBuf *Target, WCTemplputParams *TP) {
909 StrBufAppendBufPlain(Target, HKEY(PACKAGE_STRING), 0);
912 extern char static_local_dir[PATH_MAX];
920 WebcitAddUrlHandler(HKEY("blank"), "", 0, blank_page, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC);
921 WebcitAddUrlHandler(HKEY("landing"), "", 0, display_default_landing_page, ANONYMOUS|COOKIEUNNEEDED);
922 WebcitAddUrlHandler(HKEY("do_template"), "", 0, url_do_template, ANONYMOUS);
923 WebcitAddUrlHandler(HKEY("sslg"), "", 0, seconds_since_last_gexp, AJAX|LOGCHATTY);
924 WebcitAddUrlHandler(HKEY("ajax_servcmd"), "", 0, ajax_servcmd, 0);
925 WebcitAddUrlHandler(HKEY("webcit"), "", 0, blank_page, URLNAMESPACE);
926 WebcitAddUrlHandler(HKEY("push"), "", 0, push_destination, AJAX);
927 WebcitAddUrlHandler(HKEY("pop"), "", 0, pop_destination, 0);
929 WebcitAddUrlHandler(HKEY("401"), "", 0, authorization_required, ANONYMOUS|COOKIEUNNEEDED);
930 RegisterConditional("COND:IMPMSG", 0, ConditionalImportantMesage, CTX_NONE);
931 RegisterConditional("COND:REST:DEPTH", 0, Conditional_REST_DEPTH, CTX_NONE);
932 RegisterConditional("COND:IS_HTTPS", 0, Conditional_IS_HTTPS, CTX_NONE);
934 RegisterNamespace("CSSLOCAL", 0, 0, tmplput_csslocal, NULL, CTX_NONE);
935 RegisterNamespace("IMPORTANTMESSAGE", 0, 1, tmplput_importantmessage, NULL, CTX_NONE);
936 RegisterNamespace("TRAILING_JAVASCRIPT", 0, 0, tmplput_trailing_javascript, NULL, CTX_NONE);
937 RegisterNamespace("URL:DISPLAYNAME", 0, 1, tmplput_HANDLER_DISPLAYNAME, NULL, CTX_NONE);
938 RegisterNamespace("PACKAGESTRING", 0, 1, tmplput_packagestring, NULL, CTX_NONE);
941 snprintf(dir, SIZ, "%s/webcit.css", static_local_dir);
942 if (!access(dir, R_OK)) {
943 syslog(LOG_INFO, "Using local Stylesheet [%s]", dir);
944 csslocal = NewStrBufPlain(HKEY("<link href=\"static.local/webcit.css\" rel=\"stylesheet\" type=\"text/css\" />"));
947 syslog(LOG_INFO, "No Site-local Stylesheet [%s] installed.", dir);
952 ServerStartModule_WEBCIT
955 HandlerHash = NewHash(1, NULL);
960 ServerShutdownModule_WEBCIT
963 FreeStrBuf(&csslocal);
964 DeleteHash(&HandlerHash);
970 SessionNewModule_WEBCIT
973 sess->ImportantMsg = NewStrBuf();
974 sess->WBuf = NewStrBufPlain(NULL, SIZ * 4);
975 sess->HBuf = NewStrBufPlain(NULL, SIZ / 4);
979 SessionDetachModule_WEBCIT
982 DeleteHash(&sess->Directory);
984 FreeStrBuf(&sess->upload);
985 sess->upload_length = 0;
987 FreeStrBuf(&sess->trailing_javascript);
989 if (StrLength(sess->WBuf) > SIZ * 30) /* Bigger than 120K? release. */
991 FreeStrBuf(&sess->WBuf);
992 sess->WBuf = NewStrBuf();
995 FlushStrBuf(sess->WBuf);
996 FlushStrBuf(sess->HBuf);
997 if (StrLength(sess->ImportantMsg) > 0) {
998 FlushStrBuf(sess->ImportantMsg);
1004 SessionDestroyModule_WEBCIT
1007 FreeStrBuf(&sess->WBuf);
1008 FreeStrBuf(&sess->HBuf);
1009 FreeStrBuf(&sess->ImportantMsg);
1010 FreeStrBuf(&sess->PushedDestination);