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 stuff_to_cookie(int unset_cookie);
34 int GetConnected(void);
37 void PutRequestLocalMem(void *Data, DeleteHashDataFunc DeleteIt)
42 n = GetCount(WCC->Hdr->HTTPHeaders);
43 Put(WCC->Hdr->HTTPHeaders, IKEY(n), Data, DeleteIt);
46 void DeleteWebcitHandler(void *vHandler)
48 WebcitHandler *Handler = (WebcitHandler*) vHandler;
49 FreeStrBuf(&Handler->Name);
50 FreeStrBuf(&Handler->DisplayName);
54 void WebcitAddUrlHandler(const char * UrlString, long UrlSLen,
55 const char *DisplayName, long dslen,
59 WebcitHandler *NewHandler;
60 NewHandler = (WebcitHandler*) malloc(sizeof(WebcitHandler));
62 NewHandler->Flags = Flags;
63 NewHandler->Name = NewStrBufPlain(UrlString, UrlSLen);
64 StrBufShrinkToFit(NewHandler->Name, 1);
65 NewHandler->DisplayName = NewStrBufPlain(DisplayName, dslen);
66 StrBufShrinkToFit(NewHandler->DisplayName, 1);
67 Put(HandlerHash, UrlString, UrlSLen, NewHandler, DeleteWebcitHandler);
70 void tmplput_HANDLER_DISPLAYNAME(StrBuf *Target, WCTemplputParams *TP)
73 if (WCC->Hdr->HR.Handler != NULL)
74 StrBufAppendTemplate(Target, TP, WCC->Hdr->HR.Handler->DisplayName, 0);
79 * web-printing funcion. uses our vsnprintf wrapper
81 #ifdef UBER_VERBOSE_DEBUGGING
82 void wcc_printf(const char *FILE, const char *FUNCTION, long LINE, const char *format,...)
84 void wc_printf(const char *format,...)
90 if (WCC->WBuf == NULL)
91 WCC->WBuf = NewStrBuf();
92 #ifdef UBER_VERBOSE_DEBUGGING
93 StrBufAppendPrintf(WCC->WBuf, "\n%s:%s:%d[", FILE, FUNCTION, LINE);
96 va_start(arg_ptr, format);
97 StrBufVAppendPrintf(WCC->WBuf, format, arg_ptr);
99 #ifdef UBER_VERBOSE_DEBUGGING
100 StrBufAppendPrintf(WCC->WBuf, "]\n");
105 * http-header-printing funcion. uses our vsnprintf wrapper
107 void hprintf(const char *format,...)
112 va_start(arg_ptr, format);
113 StrBufVAppendPrintf(WCC->HBuf, format, arg_ptr);
120 * wrap up an HTTP session, closes tags, etc.
122 * print_standard_html_footer should be set to:
123 * 0 - to transmit only,
124 * nonzero - to append the closing tags
126 void wDumpContent(int print_standard_html_footer)
128 if (print_standard_html_footer) {
129 wc_printf("</div> <!-- end of 'content' div -->\n");
130 do_template("trailing");
133 /* If we've been saving it all up for one big output burst,
134 * go ahead and do that now.
143 * Output HTTP headers and leading HTML for a page
145 void output_headers( int do_httpheaders, /* 1 = output HTTP headers */
146 int do_htmlhead, /* 1 = output HTML <head> section and <body> opener */
148 int do_room_banner, /* 0=no, 1=yes,
149 * 2 = I'm going to embed my own, so don't open the
150 * <div id="content"> either.
153 int unset_cookies, /* 1 = session is terminating, so unset the cookies */
154 int suppress_check, /* 1 = suppress check for instant messages */
155 int cache /* 1 = allow browser to cache this page */
160 hprintf("HTTP/1.1 200 OK\n");
161 http_datestring(httpnow, sizeof httpnow, time(NULL));
163 if (do_httpheaders) {
164 if (WCC->serv_info != NULL)
165 hprintf("Content-type: text/html; charset=utf-8\r\n"
167 "Connection: close\r\n",
169 ChrPtr(WCC->serv_info->serv_software));
171 hprintf("Content-type: text/html; charset=utf-8\r\n"
172 "Server: %s / [n/a]\n"
173 "Connection: close\r\n",
178 char httpTomorow[128];
180 http_datestring(httpTomorow, sizeof httpTomorow,
181 time(NULL) + 60 * 60 * 24 * 2);
183 hprintf("Pragma: public\r\n"
184 "Cache-Control: max-age=3600, must-revalidate\r\n"
185 "Last-modified: %s\r\n"
192 hprintf("Pragma: no-cache\r\n"
193 "Cache-Control: no-store\r\n"
198 if (cache < 2) stuff_to_cookie(unset_cookies);
204 /* check for ImportantMessages (these display in a div overlaying the main screen) */
205 if (StrLength(WCC->ImportantMsg) > 0) {
206 wc_printf("<div id=\"important_message\">\n"
207 "<span class=\"imsg\">");
208 StrEscAppend(WCC->WBuf, WCC->ImportantMsg, NULL, 0, 0);
209 wc_printf("</span><br>\n"
212 StrBufAppendBufPlain(WCC->trailing_javascript,
213 HKEY("setTimeout('hide_imsg_popup()', 5000); \n"),
216 FlushStrBuf(WCC->ImportantMsg);
218 if ( (WCC->logged_in) && (!unset_cookies) ) {
219 DoTemplate(HKEY("paging"), NULL, &NoCtx);
222 if (do_room_banner == 1) {
223 tmplput_roombanner(NULL, NULL);
227 if (do_room_banner == 1) {
228 wc_printf("<div id=\"content\">\n");
232 void output_custom_content_header(const char *ctype) {
233 hprintf("HTTP/1.1 200 OK\r\n");
234 hprintf("Content-type: %s; charset=utf-8\r\n",ctype);
235 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
236 hprintf("Connection: close\r\n");
241 * Generic function to do an HTTP redirect. Easy and fun.
243 void http_redirect(const char *whichpage) {
244 hprintf("HTTP/1.1 302 Moved Temporarily\n");
245 hprintf("Location: %s\r\n", whichpage);
246 hprintf("URI: %s\r\n", whichpage);
247 hprintf("Content-type: text/html; charset=utf-8\r\n");
249 wc_printf("<html><body>");
250 wc_printf("Go <a href=\"%s\">here</A>.", whichpage);
251 wc_printf("</body></html>\n");
258 * Output a piece of content to the web browser using conformant HTTP and MIME semantics
260 void http_transmit_thing(const char *content_type, int is_static)
263 syslog(9, "http_transmit_thing(%s)%s\n", content_type, ((is_static > 0) ? " (static)" : ""));
264 output_headers(0, 0, 0, 0, 0, is_static);
266 hprintf("Content-type: %s\r\n"
268 "Connection: close\r\n",
277 * Convenience functions to display a page containing only a string
279 * titlebarcolor color of the titlebar of the frame
280 * titlebarmsg text to display in the title bar
281 * messagetext body of the box
283 void convenience_page(const char *titlebarcolor, const char *titlebarmsg, const char *messagetext)
285 hprintf("HTTP/1.1 200 OK\n");
286 output_headers(1, 1, 2, 0, 0, 0);
287 wc_printf("<div id=\"banner\">\n");
288 wc_printf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
289 wc_printf("<span class=\"titlebar\">%s</span>\n", titlebarmsg);
290 wc_printf("</td></tr></table>\n");
291 wc_printf("</div>\n<div id=\"content\">\n");
292 escputs(messagetext);
294 wc_printf("<hr />\n");
300 * Display a blank page.
302 void blank_page(void) {
303 output_headers(1, 1, 0, 0, 0, 0);
309 * A template has been requested
311 void url_do_template(void) {
312 const StrBuf *MimeType;
313 const StrBuf *Tmpl = sbstr("template");
315 MimeType = DoTemplate(SKEY(Tmpl), NULL, &NoCtx);
316 http_transmit_thing(ChrPtr(MimeType), 0);
322 * convenience function to indicate success
324 void display_success(const char *successmessage)
326 convenience_page("007700", "OK", successmessage);
331 * Authorization required page (sends a 401, causing the browser to request login credentials)
333 void authorization_required(void)
336 const char *message = "";
338 hprintf("HTTP/1.1 401 Authorization Required\r\n");
340 "Server: %s / %s\r\n"
341 "Connection: close\r\n",
342 PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software)
344 hprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n", ChrPtr(WC->serv_info->serv_humannode));
345 hprintf("Content-Type: text/html\r\n");
348 wc_printf(_("Authorization Required"));
349 wc_printf("</h1>\r\n");
352 if (WCC->ImportantMsg != NULL)
353 message = ChrPtr(WCC->ImportantMsg);
355 wc_printf(_("The resource you requested requires a valid username and password. "
356 "You could not be logged in: %s\n"), message);
358 end_webcit_session();
362 * Convenience functions to wrap around asynchronous ajax responses
364 void begin_ajax_response(void) {
367 FlushStrBuf(WCC->HBuf);
368 output_headers(0, 0, 0, 0, 0, 0);
370 hprintf("Content-type: text/html; charset=UTF-8\r\n"
372 "Connection: close\r\n"
379 * print ajax response footer
381 void end_ajax_response(void) {
388 * Wraps a Citadel server command in an AJAX transaction.
390 void ajax_servcmd(void)
398 syslog(LOG_DEBUG, "ajax_servcmd() g_cmd=\"%s\"\n", bstr("g_cmd") );
399 begin_ajax_response();
401 serv_puts(bstr("g_cmd"));
402 StrBuf_ServGetln(Buf);
403 StrBufAppendBuf(WCC->WBuf, Buf, 0);
404 StrBufAppendBufPlain(WCC->WBuf, HKEY("\n"), 0);
406 switch (GetServerStatus(Buf, NULL)) {
408 serv_puts("\n\n000");
409 if ( (StrLength(Buf)==3) &&
410 !strcmp(ChrPtr(Buf), "000")) {
411 StrBufAppendBufPlain(WCC->WBuf, HKEY("\000"), 0);
416 if (StrBuf_ServGetln(Buf) < 0)
418 if ( (StrLength(Buf)==3) &&
419 !strcmp(ChrPtr(Buf), "000")) {
422 StrBufAppendBuf(WCC->WBuf, Buf, 0);
423 StrBufAppendBufPlain(WCC->WBuf, HKEY("\n"), 0);
427 text_to_server(bstr("g_input"));
431 len = atol(&ChrPtr(Buf)[4]);
432 StrBuf_ServGetBLOBBuffered(Buf, len);
435 len = atol(&ChrPtr(Buf)[4]);
437 memset(junk, 0, len);
438 serv_write(junk, len);
445 * This is kind of an ugly hack, but this is the only place it can go.
446 * If the command was GEXP, then the instant messenger window must be
447 * running, so reset the "last_pager_check" watchdog timer so
448 * that page_popup() doesn't try to open it a second time. TODO: page_popup isn't with us anymore.
450 if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) {
451 WCC->last_pager_check = time(NULL);
458 * Helper function for the asynchronous check to see if we need
459 * to open the instant messenger window.
461 void seconds_since_last_gexp(void)
465 if ( (time(NULL) - WC->last_pager_check) < 30) {
471 serv_getln(buf, sizeof buf);
483 * Save a URL destination so we can go to it later
485 void push_destination(void) {
489 wc_printf("no session");
493 FreeStrBuf(&WCC->PushedDestination);
494 WCC->PushedDestination = NewStrBufDup(SBSTR("url"));
495 syslog(9, "Push: %s\n", ChrPtr(WCC->PushedDestination));
500 * Go to the URL saved by push_destination()
502 void pop_destination(void) {
506 * If we are in the middle of a new user signup, the server may request that
507 * we first pass through a registration screen.
509 if ((WCC) && (WCC->need_regi)) {
510 if ((WCC->PushedDestination != NULL) && (StrLength(WCC->PushedDestination) > 0)) {
511 /* Registering will take us to the My Citadel Config room, so save our place */
512 StrBufAppendBufPlain(WCC->PushedDestination, HKEY("?go="), 0);
513 StrBufUrlescAppend(WCC->PushedDestination, WCC->CurRoom.name, NULL);
521 * Do something reasonable if we somehow ended up requesting a pop without
522 * having first done a push.
524 if ( (!WCC) || (WCC->PushedDestination == NULL) || (StrLength(WCC->PushedDestination) == 0) ) {
530 * All righty then! We have a destination saved, so go there now.
532 syslog(9, "Pop: %s\n", ChrPtr(WCC->PushedDestination));
533 http_redirect(ChrPtr(WCC->PushedDestination));
538 int ReadPostData(void)
541 int urlencoded_post = 0;
543 StrBuf *content = NULL;
545 urlencoded_post = (strncasecmp(ChrPtr(WCC->Hdr->HR.ContentType), "application/x-www-form-urlencoded", 33) == 0) ;
547 content = NewStrBufPlain(NULL, WCC->Hdr->HR.ContentLength + 256);
549 if (!urlencoded_post)
551 StrBufPrintf(content,
553 "Content-length: %ld\n\n",
554 ChrPtr(WCC->Hdr->HR.ContentType),
555 WCC->Hdr->HR.ContentLength);
558 /** Read the entire input data at once. */
559 rc = client_read_to(WCC->Hdr, content,
560 WCC->Hdr->HR.ContentLength,
566 if (urlencoded_post) {
567 ParseURLParams(content);
568 } else if (!strncasecmp(ChrPtr(WCC->Hdr->HR.ContentType), "multipart", 9)) {
573 len = StrLength(content);
574 Buf = SmashStrBuf(&content);
576 mime_parser(Buf, BufEnd, *upload_handler, NULL, NULL, NULL, 0);
578 } else if (WCC->Hdr->HR.ContentLength > 0) {
579 WCC->upload = content;
580 WCC->upload_length = StrLength(WCC->upload);
583 FreeStrBuf(&content);
588 void ParseREST_URL(void)
591 StrBuf *pFloor = NULL;
594 const char *pCh = NULL;
598 syslog(1, "parsing rest URL: %s\n", ChrPtr(WCC->Hdr->HR.ReqLine));
600 WCC->Directory = NewHash(1, Flathash);
601 WCC->CurrentFloor = NULL;
604 while (StrBufExtract_NextToken(Buf, WCC->Hdr->HR.ReqLine, &pCh, '/') >= 0)
606 if (StrLength(Buf) != 0) {
607 /* ignore empty path segments */
608 StrBufUnescape(Buf, 1);
609 Put(WCC->Directory, IKEY(i), Buf, HFreeStrBuf);
620 Floors = GetFloorListHash(NULL, NULL);
624 if (GetHash(WCC->FloorsByName, SKEY(pFloor), &vFloor))
625 WCC->CurrentFloor = (Floor*) vFloor;
630 int Conditional_REST_DEPTH(StrBuf *Target, WCTemplputParams *TP)
636 if (WCC->Hdr->HR.Handler != NULL)
638 Depth = GetTemplateTokenNumber(Target, TP, 2, 0);
639 IsDepth = GetCount(WCC->Directory) + offset;
641 // LogTemplateError(Target, "bla", 1, TP, "REST_DEPTH: %ld : %ld\n", Depth, IsDepth);
644 return IsDepth > Depth;
647 return Depth == IsDepth;
653 * Entry point for WebCit transaction
655 void session_loop(void)
661 * We stuff these with the values coming from the client cookies,
662 * so we can use them to reconnect a timed out session if we have to.
667 WCC->upload_length = 0;
669 WCC->Hdr->nWildfireHeaders = 0;
671 if (WCC->Hdr->HR.ContentLength > 0) {
672 if (ReadPostData() < 0) {
678 WCC->trailing_javascript = NewStrBuf();
680 /* Convert base64-encoded URL's back to plain text */
681 if (!strncmp(ChrPtr(WCC->Hdr->this_page), "/B64", 4)) {
682 StrBufCutLeft(WCC->Hdr->this_page, 4);
683 StrBufDecodeBase64(WCC->Hdr->this_page);
684 http_redirect(ChrPtr(WCC->Hdr->this_page));
685 goto SKIP_ALL_THIS_CRAP;
688 /* If there are variables in the URL, we must grab them now */
689 if (WCC->Hdr->PlainArgs != NULL)
690 ParseURLParams(WCC->Hdr->PlainArgs);
692 /* If the client sent a nonce that is incorrect, kill the request. */
693 if (havebstr("nonce")) {
694 syslog(9, "Comparing supplied nonce %s to session nonce %d\n",
695 bstr("nonce"), WCC->nonce
697 if (ibstr("nonce") != WCC->nonce) {
698 syslog(9, "Ignoring request with mismatched nonce.\n");
699 hprintf("HTTP/1.1 404 Security check failed\r\n");
700 hprintf("Content-Type: text/plain\r\n");
702 wc_printf("Security check failed.\r\n");
704 goto SKIP_ALL_THIS_CRAP;
709 * If we're not connected to a Citadel server, try to hook up the connection now.
711 if (!WCC->connected) {
712 if (GetConnected()) {
713 hprintf("HTTP/1.1 503 Service Unavailable\r\n");
714 hprintf("Content-Type: text/html\r\n");
716 wc_printf("<html><head><title>503 Service Unavailable</title></head><body>\n");
717 wc_printf(_("This program was unable to connect or stay "
718 "connected to the Citadel server. Please report "
719 "this problem to your system administrator.")
722 wc_printf("<a href=\"http://www.citadel.org/doku.php/"
723 "faq:generalquestions:webcit_unable_to_connect\">%s</a>",
726 wc_printf("</body></html>\n");
728 goto SKIP_ALL_THIS_CRAP;
733 * If we're not logged in, but we have authentication data (either from
734 * a cookie or from http-auth), try logging in to Citadel using that.
736 if ((!WCC->logged_in)
737 && (StrLength(WCC->Hdr->c_username) > 0)
738 && (StrLength(WCC->Hdr->c_password) > 0))
743 serv_printf("USER %s", ChrPtr(WCC->Hdr->c_username));
744 StrBuf_ServGetln(Buf);
745 if (GetServerStatus(Buf, &Status) == 3) {
746 serv_printf("PASS %s", ChrPtr(WCC->Hdr->c_password));
747 StrBuf_ServGetln(Buf);
748 if (GetServerStatus(Buf, NULL) == 2) {
749 become_logged_in(WCC->Hdr->c_username,
750 WCC->Hdr->c_password, Buf);
752 /* Should only display when password is wrong */
753 WCC->ImportantMsg = NewStrBufPlain(ChrPtr(Buf) + 4, StrLength(Buf) - 4);
754 authorization_required();
756 goto SKIP_ALL_THIS_CRAP;
759 else if (Status == 541) {
764 xhttp = (WCC->Hdr->HR.eReqType != eGET) &&
765 (WCC->Hdr->HR.eReqType != ePOST) &&
766 (WCC->Hdr->HR.eReqType != eHEAD);
769 * If a 'go' (or 'gotofirst') parameter has been specified, attempt to goto that room
770 * prior to doing anything else.
772 if (havebstr("go")) {
774 syslog(9, "Explicit room selection: %s\n", bstr("go"));
775 ret = gotoroom(sbstr("go")); /* do quietly to avoid session output! */
776 if ((ret/100) != 2) {
777 syslog(1, "Unable to change to [%s]; Reason: %d\n", bstr("go"), ret);
780 else if (havebstr("gotofirst")) {
782 syslog(9, "Explicit room selection: %s\n", bstr("gotofirst"));
783 ret = gotoroom(sbstr("gotofirst")); /* do quietly to avoid session output! */
784 if ((ret/100) != 2) {
785 syslog(1, "Unable to change to [%s]; Reason: %d\n", bstr("gotofirst"), ret);
790 * If we aren't in any room yet, but we have cookie data telling us where we're
791 * supposed to be, and 'go' was not specified, then go there.
793 else if ( (StrLength(WCC->CurRoom.name) == 0) && ( (StrLength(WCC->Hdr->c_roomname) > 0) )) {
796 syslog(9, "We are in '%s' but cookie indicates '%s', going there...\n",
797 ChrPtr(WCC->CurRoom.name),
798 ChrPtr(WCC->Hdr->c_roomname)
800 ret = gotoroom(WCC->Hdr->c_roomname); /* do quietly to avoid session output! */
801 if ((ret/100) != 2) {
802 syslog(1, "COOKIEGOTO: Unable to change to [%s]; Reason: %d\n",
803 ChrPtr(WCC->Hdr->c_roomname), ret);
807 if (WCC->Hdr->HR.Handler != NULL) {
808 if ( (!WCC->logged_in)
809 && ((WCC->Hdr->HR.Handler->Flags & ANONYMOUS) == 0)
810 && (WCC->serv_info->serv_supports_guest == 0)
816 if ((WCC->Hdr->HR.Handler->Flags & PARSE_REST_URL) != 0)
819 if ((WCC->Hdr->HR.Handler->Flags & AJAX) != 0)
820 begin_ajax_response();
821 WCC->Hdr->HR.Handler->F();
822 if ((WCC->Hdr->HR.Handler->Flags & AJAX) != 0)
826 /* When all else fails, display the default landing page or a main menu. */
829 * ordinary browser users get a nice login screen, DAV etc. requsets
830 * are given a 401 so they can handle it appropriate.
832 if (!WCC->logged_in) {
834 authorization_required();
837 display_default_landing_page();
841 * Toplevel dav requests? or just a flat browser request?
859 * Display the appropriate landing page for this site.
861 void display_default_landing_page(void) {
864 if (WCC && WCC->serv_info && WCC->serv_info->serv_supports_guest) {
867 if (default_landing_page) {
868 http_redirect(default_landing_page);
871 StrBuf *teh_lobby = NewStrBufPlain(HKEY("_BASEROOM_"));
872 smart_goto(teh_lobby);
873 FreeStrBuf(&teh_lobby);
883 * Replacement for sleep() that uses select() in order to avoid SIGALRM
885 void sleeeeeeeeeep(int seconds)
891 select(0, NULL, NULL, NULL, &tv);
894 int Conditional_IS_HTTPS(StrBuf *Target, WCTemplputParams *TP)
896 return is_https != 0;
899 void AppendImportantMessage(const char *pch, long len)
903 if (StrLength(WCC->ImportantMsg) > 0) {
904 StrBufAppendBufPlain(WCC->ImportantMsg, HKEY("\n"), 0);
907 StrBufAppendBufPlain(WCC->ImportantMsg, pch, len, 0);
910 int ConditionalImportantMesage(StrBuf *Target, WCTemplputParams *TP)
914 return (StrLength(WCC->ImportantMsg) > 0);
919 void tmplput_importantmessage(StrBuf *Target, WCTemplputParams *TP)
924 if (StrLength(WCC->ImportantMsg) > 0) {
925 StrEscAppend(Target, WCC->ImportantMsg, NULL, 0, 0);
926 FlushStrBuf(WCC->ImportantMsg);
931 void tmplput_trailing_javascript(StrBuf *Target, WCTemplputParams *TP)
936 StrBufAppendTemplate(Target, TP, WCC->trailing_javascript, 0);
939 void tmplput_csslocal(StrBuf *Target, WCTemplputParams *TP)
941 StrBufAppendBuf(Target,
945 void tmplput_packagestring(StrBuf *Target, WCTemplputParams *TP)
947 StrBufAppendBufPlain(Target,
948 HKEY(PACKAGE_STRING), 0);
951 extern char static_local_dir[PATH_MAX];
959 WebcitAddUrlHandler(HKEY("blank"), "", 0, blank_page, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC);
960 WebcitAddUrlHandler(HKEY("do_template"), "", 0, url_do_template, ANONYMOUS);
961 WebcitAddUrlHandler(HKEY("sslg"), "", 0, seconds_since_last_gexp, AJAX|LOGCHATTY);
962 WebcitAddUrlHandler(HKEY("ajax_servcmd"), "", 0, ajax_servcmd, 0);
963 WebcitAddUrlHandler(HKEY("webcit"), "", 0, blank_page, URLNAMESPACE);
964 WebcitAddUrlHandler(HKEY("push"), "", 0, push_destination, AJAX);
965 WebcitAddUrlHandler(HKEY("pop"), "", 0, pop_destination, 0);
967 WebcitAddUrlHandler(HKEY("401"), "", 0, authorization_required, ANONYMOUS|COOKIEUNNEEDED);
968 RegisterConditional(HKEY("COND:IMPMSG"), 0, ConditionalImportantMesage, CTX_NONE);
969 RegisterConditional(HKEY("COND:REST:DEPTH"), 0, Conditional_REST_DEPTH, CTX_NONE);
970 RegisterConditional(HKEY("COND:IS_HTTPS"), 0, Conditional_IS_HTTPS, CTX_NONE);
972 RegisterNamespace("CSSLOCAL", 0, 0, tmplput_csslocal, NULL, CTX_NONE);
973 RegisterNamespace("IMPORTANTMESSAGE", 0, 0, tmplput_importantmessage, NULL, CTX_NONE);
974 RegisterNamespace("TRAILING_JAVASCRIPT", 0, 0, tmplput_trailing_javascript, NULL, CTX_NONE);
975 RegisterNamespace("URL:DISPLAYNAME", 0, 1, tmplput_HANDLER_DISPLAYNAME, NULL, CTX_NONE);
976 RegisterNamespace("PACKAGESTRING", 0, 1, tmplput_packagestring, NULL, CTX_NONE);
979 snprintf(dir, SIZ, "%s/webcit.css", static_local_dir);
980 if (!access(dir, R_OK)) {
981 syslog(9, "Using local Stylesheet [%s]\n", dir);
982 csslocal = NewStrBufPlain(HKEY("<link href=\"static.local/webcit.css\" rel=\"stylesheet\" type=\"text/css\" />"));
985 syslog(9, "No Site-local Stylesheet [%s] installed. \n", dir);
990 ServerStartModule_WEBCIT
993 HandlerHash = NewHash(1, NULL);
998 ServerShutdownModule_WEBCIT
1001 FreeStrBuf(&csslocal);
1002 DeleteHash(&HandlerHash);
1008 SessionNewModule_WEBCIT
1011 sess->ImportantMsg = NewStrBuf();
1012 sess->WBuf = NewStrBufPlain(NULL, SIZ * 4);
1013 sess->HBuf = NewStrBufPlain(NULL, SIZ / 4);
1017 SessionDetachModule_WEBCIT
1020 DeleteHash(&sess->Directory);
1022 FreeStrBuf(&sess->upload);
1023 sess->upload_length = 0;
1025 FreeStrBuf(&sess->trailing_javascript);
1027 if (StrLength(sess->WBuf) > SIZ * 30) /* Bigger than 120K? release. */
1029 FreeStrBuf(&sess->WBuf);
1030 sess->WBuf = NewStrBuf();
1033 FlushStrBuf(sess->WBuf);
1034 FlushStrBuf(sess->HBuf);
1038 SessionDestroyModule_WEBCIT
1041 FreeStrBuf(&sess->WBuf);
1042 FreeStrBuf(&sess->HBuf);
1043 FreeStrBuf(&sess->ImportantMsg);
1044 FreeStrBuf(&sess->PushedDestination);