2 * This is the other half of the webserver. It handles the task of hooking
3 * up HTTP requests with the sessions they belong to, using HTTP cookies to
4 * keep track of things. If the HTTP request doesn't belong to any currently
5 * active session, a new session is started.
7 * Copyright (c) 1996-2010 by the citadel.org team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "webserver.h"
26 #include "modules_init.h"
28 /* Only one thread may manipulate SessionList at a time... */
29 pthread_mutex_t SessionListMutex;
31 wcsession *SessionList = NULL; /* Linked list of all webcit sessions */
33 pthread_key_t MyConKey; /* TSD key for MySession() */
34 HashList *HttpReqTypes = NULL;
35 HashList *HttpHeaderHandler = NULL;
36 extern HashList *HandlerHash;
38 /* the following two values start at 1 because the initial parent thread counts as one. */
39 int num_threads_existing = 1; /* Number of worker threads which exist. */
40 int num_threads_executing = 1; /* Number of worker threads currently executing. */
42 void DestroyHttpHeaderHandler(void *V)
45 pHdr = (OneHttpHeader*) V;
46 FreeStrBuf(&pHdr->Val);
50 void shutdown_sessions(void)
54 for (sptr = SessionList; sptr != NULL; sptr = sptr->next) {
59 void do_housekeeping(void)
62 wcsession *sessions_to_kill = NULL;
65 * Lock the session list, moving any candidates for euthanasia into
68 pthread_mutex_lock(&SessionListMutex);
69 for (sptr = SessionList; sptr != NULL; sptr = sptr->next) {
71 /* Kill idle sessions */
72 if ((time(NULL) - (sptr->lastreq)) > (time_t) WEBCIT_TIMEOUT) {
76 /* Remove sessions flagged for kill */
79 /** remove session from linked list */
80 if (sptr == SessionList) {
81 SessionList = SessionList->next;
83 else for (ss=SessionList;ss!=NULL;ss=ss->next) {
84 if (ss->next == sptr) {
85 ss->next = ss->next->next;
89 sptr->next = sessions_to_kill;
90 sessions_to_kill = sptr;
93 pthread_mutex_unlock(&SessionListMutex);
96 * Now free up and destroy the culled sessions.
98 while (sessions_to_kill != NULL) {
99 lprintf(3, "Destroying session %d\n", sessions_to_kill->wc_session);
100 pthread_mutex_lock(&sessions_to_kill->SessionMutex);
101 pthread_mutex_unlock(&sessions_to_kill->SessionMutex);
102 sptr = sessions_to_kill->next;
104 session_destroy_modules(&sessions_to_kill);
105 sessions_to_kill = sptr;
110 * Check the size of our thread pool. If all threads are executing, spawn another.
112 void check_thread_pool_size(void)
114 if (time_to_die) return; /* don't expand the thread pool during shutdown */
116 begin_critical_section(S_SPAWNER); /* only one of these should run at a time */
118 (num_threads_executing >= num_threads_existing)
119 && (num_threads_existing < MAX_WORKER_THREADS)
121 lprintf(3, "%d of %d threads are executing. Adding another worker thread.\n",
122 num_threads_executing,
125 spawn_another_worker_thread();
127 end_critical_section(S_SPAWNER);
132 * Wake up occasionally and clean house
134 void housekeeping_loop(void)
137 sleeeeeeeeeep(HOUSEKEEPING);
144 * Create a Session id
145 * Generate a unique WebCit session ID (which is not the same thing as the
146 * Citadel session ID).
148 int GenerateSessionID(void)
150 static int seq = (-1);
153 seq = (int) time(NULL);
159 wcsession *FindSession(wcsession **wclist, ParsedHttpHdrs *Hdr, pthread_mutex_t *ListMutex)
161 wcsession *sptr = NULL;
162 wcsession *TheSession = NULL;
164 if (Hdr->HR.got_auth == AUTH_BASIC) {
168 pthread_mutex_lock(ListMutex);
169 for (sptr = *wclist; ((sptr != NULL) && (TheSession == NULL)); sptr = sptr->next) {
171 /* If HTTP-AUTH, look for a session with matching credentials */
172 switch (Hdr->HR.got_auth)
175 if ( (Hdr->HR.SessionKey != sptr->SessionKey))
177 if ((!strcasecmp(ChrPtr(Hdr->c_username), ChrPtr(sptr->wc_username))) &&
178 (!strcasecmp(ChrPtr(Hdr->c_password), ChrPtr(sptr->wc_password))) ) {
181 if (TheSession == NULL)
182 lprintf(1, "found sessionkey [%ld], but credentials for [%s|%s] didn't match\n",
183 Hdr->HR.SessionKey,ChrPtr(Hdr->c_username), ChrPtr(sptr->wc_username));
186 /* If cookie-session, look for a session with matching session ID */
187 if ( (Hdr->HR.desired_session != 0) &&
188 (sptr->wc_session == Hdr->HR.desired_session)) {
196 pthread_mutex_unlock(ListMutex);
197 if (TheSession == NULL)
198 lprintf(1, "didn't find sessionkey [%ld] for user [%s]\n",
199 Hdr->HR.SessionKey,ChrPtr(Hdr->c_username));
203 wcsession *CreateSession(int Lockable, int Static, wcsession **wclist, ParsedHttpHdrs *Hdr, pthread_mutex_t *ListMutex)
205 wcsession *TheSession;
207 lprintf(3, "Creating a new session\n");
208 TheSession = (wcsession *) malloc(sizeof(wcsession));
209 memset(TheSession, 0, sizeof(wcsession));
210 TheSession->Hdr = Hdr;
211 TheSession->SessionKey = Hdr->HR.SessionKey;
212 TheSession->serv_sock = (-1);
213 TheSession->is_mobile = -1;
215 pthread_setspecific(MyConKey, (void *)TheSession);
217 /* If we're recreating a session that expired, it's best to give it the same
218 * session number that it had before. The client browser ought to pick up
219 * the new session number and start using it, but in some rare situations it
220 * doesn't, and that's a Bad Thing because it causes lots of spurious sessions
223 if (Hdr->HR.desired_session == 0) {
224 TheSession->wc_session = GenerateSessionID();
227 TheSession->wc_session = Hdr->HR.desired_session;
229 Hdr->HR.Static = Static;
230 session_new_modules(TheSession);
233 pthread_mutex_init(&TheSession->SessionMutex, NULL);
235 if (ListMutex != NULL)
236 pthread_mutex_lock(ListMutex);
238 if (wclist != NULL) {
239 TheSession->nonce = rand();
240 TheSession->next = *wclist;
241 *wclist = TheSession;
243 if (ListMutex != NULL)
244 pthread_mutex_unlock(ListMutex);
251 * Detects a 'mobile' user agent
253 int is_mobile_ua(char *user_agent) {
254 if (strstr(user_agent,"iPhone OS") != NULL) {
256 } else if (strstr(user_agent,"Windows CE") != NULL) {
258 } else if (strstr(user_agent,"SymbianOS") != NULL) {
260 } else if (strstr(user_agent, "Opera Mobi") != NULL) {
262 } else if (strstr(user_agent, "Firefox/2.0.0 Opera 9.51 Beta") != NULL) {
263 /* For some reason a new install of Opera 9.51beta decided to spoof. */
269 /* If it's a "force 404" situation then display the error and bail. */
272 hprintf("HTTP/1.1 404 Not found\r\n");
273 hprintf("Content-Type: text/plain\r\n");
274 wc_printf("Not found\r\n");
278 int ReadHttpSubject(ParsedHttpHdrs *Hdr, StrBuf *Line, StrBuf *Buf)
281 void *vLine, *vHandler;
282 const char *Pos = NULL;
285 Hdr->HR.ReqLine = Line;
286 /* The requesttype... GET, POST... */
287 StrBufExtract_token(Buf, Hdr->HR.ReqLine, 0, ' ');
288 if (GetHash(HttpReqTypes, SKEY(Buf), &vLine) &&
291 Hdr->HR.eReqType = *(long*)vLine;
294 Hdr->HR.eReqType = eGET;
297 StrBufCutLeft(Hdr->HR.ReqLine, StrLength(Buf) + 1);
299 /* the HTTP Version... */
300 StrBufExtract_token(Buf, Hdr->HR.ReqLine, 1, ' ');
301 StrBufCutRight(Hdr->HR.ReqLine, StrLength(Buf) + 1);
303 if (StrLength(Buf) == 0) {
304 Hdr->HR.eReqType = eGET;
308 StrBufAppendBuf(Hdr->this_page, Hdr->HR.ReqLine, 0);
310 /* chop Filename / query arguments */
311 Args = strchr(ChrPtr(Hdr->HR.ReqLine), '?');
312 if (Args == NULL) /* whe're not that picky about params... TODO: this will spoil '&' in filenames.*/
313 Args = strchr(ChrPtr(Hdr->HR.ReqLine), '&');
315 Args ++; /* skip the ? */
316 StrBufPlain(Hdr->PlainArgs,
318 StrLength(Hdr->HR.ReqLine) -
319 (Args - ChrPtr(Hdr->HR.ReqLine)));
320 StrBufCutAt(Hdr->HR.ReqLine, 0, Args - 1);
321 } /* don't parse them yet, maybe we don't even care... */
323 /* now lookup what we are going to do with this... */
324 /* skip first slash */
325 StrBufExtract_NextToken(Buf, Hdr->HR.ReqLine, &Pos, '/');
327 StrBufExtract_NextToken(Buf, Hdr->HR.ReqLine, &Pos, '/');
329 GetHash(HandlerHash, SKEY(Buf), &vHandler),
330 Hdr->HR.Handler = (WebcitHandler*) vHandler;
331 if (Hdr->HR.Handler == NULL)
334 * If the request is prefixed by "/webcit" then chop that off. This
335 * allows a front end web server to forward all /webcit requests to us
336 * while still using the same web server port for other things.
338 if ((Hdr->HR.Handler->Flags & URLNAMESPACE) != 0)
342 /* remove the handlername from the URL */
343 if ((Pos != NULL) && (Pos != StrBufNOTNULL)){
344 StrBufCutLeft(Hdr->HR.ReqLine,
345 Pos - ChrPtr(Hdr->HR.ReqLine));
348 if (Hdr->HR.Handler != NULL) {
349 if ((Hdr->HR.Handler->Flags & BOGUS) != 0)
351 Hdr->HR.DontNeedAuth = (
352 ((Hdr->HR.Handler->Flags & ISSTATIC) != 0) ||
353 ((Hdr->HR.Handler->Flags & ANONYMOUS) != 0)
357 Hdr->HR.DontNeedAuth = 1; /* Flat request? show him the login screen... */
363 int AnalyseHeaders(ParsedHttpHdrs *Hdr)
369 HashPos *at = GetNewHashPos(Hdr->HTTPHeaders, 0);
371 while (GetNextHashPos(Hdr->HTTPHeaders, at, &HKLen, &HashKey, &vHdr) &&
373 pHdr = (OneHttpHeader *)vHdr;
374 if (pHdr->HaveEvaluator)
375 pHdr->H(pHdr->Val, Hdr);
382 /*const char *nix(void *vptr) {return ChrPtr( (StrBuf*)vptr);}*/
385 * Read in the request
387 int ReadHTTPRequest (ParsedHttpHdrs *Hdr)
389 const char *pch, *pchs, *pche;
391 StrBuf *Line, *LastLine, *HeaderName;
396 HeaderName = NewStrBuf();
400 Line = NewStrBufPlain(NULL, SIZ / 4);
402 if (ClientGetLine(Hdr, Line) < 0) return 1;
404 if (StrLength(Line) == 0) {
409 Hdr->HTTPHeaders = NewHash(1, NULL);
410 pHdr = (OneHttpHeader*) malloc(sizeof(OneHttpHeader));
411 memset(pHdr, 0, sizeof(OneHttpHeader));
413 Put(Hdr->HTTPHeaders, HKEY("GET /"), pHdr, DestroyHttpHeaderHandler);
414 lprintf(9, "%s\n", ChrPtr(Line));
415 isbogus = ReadHttpSubject(Hdr, Line, HeaderName);
420 /* Do we need to Unfold? */
421 if ((LastLine != NULL) &&
422 (isspace(*ChrPtr(Line)))) {
423 pch = pchs = ChrPtr(Line);
424 pche = pchs + StrLength(Line);
425 while (isspace(*pch) && (pch < pche))
427 StrBufCutLeft(Line, pch - pchs);
428 StrBufAppendBuf(LastLine, Line, 0);
434 StrBufSanitizeAscii(Line, '§');
435 StrBufExtract_token(HeaderName, Line, 0, ':');
438 pche = pchs + StrLength(Line);
439 pch = pchs + StrLength(HeaderName) + 1;
440 pche = pchs + StrLength(Line);
441 while ((pch < pche) && isspace(*pch))
443 StrBufCutLeft(Line, pch - pchs);
445 StrBufUpCase(HeaderName);
447 pHdr = (OneHttpHeader*) malloc(sizeof(OneHttpHeader));
448 memset(pHdr, 0, sizeof(OneHttpHeader));
451 if (GetHash(HttpHeaderHandler, SKEY(HeaderName), &vF) &&
454 OneHttpHeader *FHdr = (OneHttpHeader*) vF;
456 pHdr->HaveEvaluator = 1;
458 Put(Hdr->HTTPHeaders, SKEY(HeaderName), pHdr, DestroyHttpHeaderHandler);
460 } while (Line != NULL);
462 FreeStrBuf(&HeaderName);
467 void OverrideRequest(ParsedHttpHdrs *Hdr, const char *Line, long len)
469 StrBuf *Buf = NewStrBuf();
471 if (Hdr->HR.ReqLine != NULL) {
472 FlushStrBuf(Hdr->HR.ReqLine);
473 StrBufPlain(Hdr->HR.ReqLine, Line, len);
476 Hdr->HR.ReqLine = NewStrBufPlain(Line, len);
478 ReadHttpSubject(Hdr, Hdr->HR.ReqLine, Buf);
486 * This loop gets called once for every HTTP connection made to WebCit. At
487 * this entry point we have an HTTP socket with a browser allegedly on the
488 * other end, but we have not yet bound to a WebCit session.
490 * The job of this function is to locate the correct session and bind to it,
491 * or create a session if necessary and bind to it, then run the WebCit
492 * transaction loop. Afterwards, we unbind from the session. When this
493 * function returns, the worker thread is then free to handle another
496 void context_loop(ParsedHttpHdrs *Hdr)
499 wcsession *TheSession;
500 struct timeval tx_start;
501 struct timeval tx_finish;
503 gettimeofday(&tx_start, NULL); /* start a stopwatch for performance timing */
506 * Find out what it is that the web browser is asking for
508 isbogus = ReadHTTPRequest(Hdr);
510 Hdr->HR.dav_depth = 32767; /* TODO: find a general way to have non-0 defaults */
512 isbogus = AnalyseHeaders(Hdr);
515 ((Hdr->HR.Handler != NULL) &&
516 ((Hdr->HR.Handler->Flags & BOGUS) != 0)))
520 Bogus = CreateSession(0, 1, NULL, Hdr, NULL);
524 lprintf(9, "HTTP: 404 [%ld.%06ld] %s %s \n",
525 ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) / 1000000,
526 ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) % 1000000,
527 ReqStrs[Hdr->HR.eReqType],
528 ChrPtr(Hdr->this_page)
530 session_detach_modules(Bogus);
531 session_destroy_modules(&Bogus);
535 if ((Hdr->HR.Handler != NULL) && ((Hdr->HR.Handler->Flags & ISSTATIC) != 0))
538 Static = CreateSession(0, 1, NULL, Hdr, NULL);
540 Hdr->HR.Handler->F();
542 /* How long did this transaction take? */
543 gettimeofday(&tx_finish, NULL);
546 if ((Hdr->HR.Handler != NULL) ||
547 ((Hdr->HR.Handler->Flags & LOGCHATTY) == 0))
549 lprintf(9, "HTTP: 200 [%ld.%06ld] %s %s \n",
550 ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) / 1000000,
551 ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) % 1000000,
552 ReqStrs[Hdr->HR.eReqType],
553 ChrPtr(Hdr->this_page)
555 session_detach_modules(Static);
556 session_destroy_modules(&Static);
560 if (Hdr->HR.got_auth == AUTH_BASIC) {
565 * See if there's an existing session open with the desired ID or user/pass
567 TheSession = FindSession(&SessionList, Hdr, &SessionListMutex);
570 * Create a new session if we have to
572 if (TheSession == NULL) {
573 TheSession = CreateSession(1, 0, &SessionList, Hdr, &SessionListMutex);
575 if ((StrLength(Hdr->c_username) == 0) && (!Hdr->HR.DontNeedAuth)) {
577 if ((Hdr->HR.Handler != NULL) &&
578 (XHTTP_COMMANDS & Hdr->HR.Handler->Flags) == XHTTP_COMMANDS) {
579 OverrideRequest(Hdr, HKEY("GET /401 HTTP/1.0"));
580 Hdr->HR.prohibit_caching = 1;
583 OverrideRequest(Hdr, HKEY("GET /static/nocookies.html?force_close_session=yes HTTP/1.0"));
584 Hdr->HR.prohibit_caching = 1;
588 if (StrLength(Hdr->c_language) > 0) {
589 lprintf(9, "Session cookie requests language '%s'\n", ChrPtr(Hdr->c_language));
590 set_selected_language(ChrPtr(Hdr->c_language));
591 go_selected_language();
596 * A future improvement might be to check the session integrity
597 * at this point before continuing.
601 * Bind to the session and perform the transaction
603 pthread_mutex_lock(&TheSession->SessionMutex); /* bind */
604 pthread_setspecific(MyConKey, (void *)TheSession);
606 TheSession->lastreq = time(NULL); /* log */
607 TheSession->Hdr = Hdr;
609 session_attach_modules(TheSession);
610 session_loop(); /* do transaction */
613 /* How long did this transaction take? */
614 gettimeofday(&tx_finish, NULL);
618 if ((Hdr->HR.Handler != NULL) &&
619 ((Hdr->HR.Handler->Flags & LOGCHATTY) == 0))
621 lprintf(9, "HTTP: 200 [%ld.%06ld] %s %s \n",
622 ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) / 1000000,
623 ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) % 1000000,
624 ReqStrs[Hdr->HR.eReqType],
625 ChrPtr(Hdr->this_page)
628 session_detach_modules(TheSession);
630 TheSession->Hdr = NULL;
631 pthread_mutex_unlock(&TheSession->SessionMutex); /* unbind */
634 void tmplput_nonce(StrBuf *Target, WCTemplputParams *TP)
637 StrBufAppendPrintf(Target, "%ld",
638 (WCC != NULL)? WCC->nonce:0);
641 void tmplput_current_user(StrBuf *Target, WCTemplputParams *TP)
643 StrBufAppendTemplate(Target, TP, WC->wc_fullname, 0);
646 void Header_HandleContentLength(StrBuf *Line, ParsedHttpHdrs *hdr)
648 hdr->HR.ContentLength = StrToi(Line);
651 void Header_HandleContentType(StrBuf *Line, ParsedHttpHdrs *hdr)
653 hdr->HR.ContentType = Line;
656 void Header_HandleUserAgent(StrBuf *Line, ParsedHttpHdrs *hdr)
658 hdr->HR.user_agent = Line;
660 /* TODO: do this later on session creating
661 if ((WCC->is_mobile < 0) && is_mobile_ua(&buf[12])) {
672 void Header_HandleHost(StrBuf *Line, ParsedHttpHdrs *hdr)
674 if (site_prefix == NULL) {
675 site_prefix = NewStrBuf();
676 StrBufAppendPrintf(site_prefix, "%s://", (is_https ? "https" : "http") );
677 StrBufAppendBuf(site_prefix, Line, 0);
678 lprintf(CTDL_DEBUG, "\033[33m [%s] \033[0m\n", ChrPtr(site_prefix));
682 void Header_HandleXFFHost(StrBuf *Line, ParsedHttpHdrs *hdr)
685 /* FIXME do something here */
690 void Header_HandleXFF(StrBuf *Line, ParsedHttpHdrs *hdr)
692 hdr->HR.browser_host = Line;
694 while (StrBufNum_tokens(hdr->HR.browser_host, ',') > 1) {
695 StrBufRemove_token(hdr->HR.browser_host, 0, ',');
697 StrBufTrim(hdr->HR.browser_host);
700 void Header_HandleIfModSince(StrBuf *Line, ParsedHttpHdrs *hdr)
702 hdr->HR.if_modified_since = httpdate_to_timestamp(Line);
705 void Header_HandleAcceptEncoding(StrBuf *Line, ParsedHttpHdrs *hdr)
710 if (strstr(&ChrPtr(Line)[16], "gzip")) {
714 const char *ReqStrs[eNONE] = {
727 ServerStartModule_CONTEXT
731 HttpReqTypes = NewHash(1, NULL);
732 HttpHeaderHandler = NewHash(1, NULL);
734 v = malloc(sizeof(long));
736 Put(HttpReqTypes, HKEY("GET"), v, NULL);
738 v = malloc(sizeof(long));
740 Put(HttpReqTypes, HKEY("POST"), v, NULL);
742 v = malloc(sizeof(long));
744 Put(HttpReqTypes, HKEY("OPTIONS"), v, NULL);
746 v = malloc(sizeof(long));
748 Put(HttpReqTypes, HKEY("PROPFIND"), v, NULL);
750 v = malloc(sizeof(long));
752 Put(HttpReqTypes, HKEY("PUT"), v, NULL);
754 v = malloc(sizeof(long));
756 Put(HttpReqTypes, HKEY("DELETE"), v, NULL);
758 v = malloc(sizeof(long));
760 Put(HttpReqTypes, HKEY("HEAD"), v, NULL);
762 v = malloc(sizeof(long));
764 Put(HttpReqTypes, HKEY("MOVE"), v, NULL);
766 v = malloc(sizeof(long));
768 Put(HttpReqTypes, HKEY("COPY"), v, NULL);
772 ServerShutdownModule_CONTEXT
775 DeleteHash(&HttpReqTypes);
776 DeleteHash(&HttpHeaderHandler);
779 void RegisterHeaderHandler(const char *Name, long Len, Header_Evaluator F)
782 pHdr = (OneHttpHeader*) malloc(sizeof(OneHttpHeader));
783 memset(pHdr, 0, sizeof(OneHttpHeader));
785 Put(HttpHeaderHandler, Name, Len, pHdr, DestroyHttpHeaderHandler);
793 RegisterHeaderHandler(HKEY("CONTENT-LENGTH"), Header_HandleContentLength);
794 RegisterHeaderHandler(HKEY("CONTENT-TYPE"), Header_HandleContentType);
795 RegisterHeaderHandler(HKEY("USER-AGENT"), Header_HandleUserAgent);
796 RegisterHeaderHandler(HKEY("X-FORWARDED-HOST"), Header_HandleXFFHost); /* Apache way... */
797 RegisterHeaderHandler(HKEY("X-REAL-IP"), Header_HandleXFFHost); /* NGinX way... */
798 RegisterHeaderHandler(HKEY("HOST"), Header_HandleHost);
799 RegisterHeaderHandler(HKEY("X-FORWARDED-FOR"), Header_HandleXFF);
800 RegisterHeaderHandler(HKEY("ACCEPT-ENCODING"), Header_HandleAcceptEncoding);
801 RegisterHeaderHandler(HKEY("IF-MODIFIED-SINCE"), Header_HandleIfModSince);
803 RegisterNamespace("CURRENT_USER", 0, 1, tmplput_current_user, NULL, CTX_NONE);
804 RegisterNamespace("NONCE", 0, 0, tmplput_nonce, NULL, 0);
806 WebcitAddUrlHandler(HKEY("404"), "", 0, do_404, ANONYMOUS|COOKIEUNNEEDED);
808 * Look for commonly-found probes of malware such as worms, viruses, trojans, and Microsoft Office.
809 * Short-circuit these requests so we don't have to send them through the full processing loop.
811 WebcitAddUrlHandler(HKEY("scripts"), "", 0, do_404, ANONYMOUS|BOGUS); /* /root.exe - Worms and trojans and viruses, oh my! */
812 WebcitAddUrlHandler(HKEY("c"), "", 0, do_404, ANONYMOUS|BOGUS); /* /winnt */
813 WebcitAddUrlHandler(HKEY("MSADC"), "", 0, do_404, ANONYMOUS|BOGUS);
814 WebcitAddUrlHandler(HKEY("_vti"), "", 0, do_404, ANONYMOUS|BOGUS); /* Broken Microsoft DAV implementation */
815 WebcitAddUrlHandler(HKEY("MSOffice"), "", 0, do_404, ANONYMOUS|BOGUS); /* Stoopid MSOffice thinks everyone is IIS */
816 WebcitAddUrlHandler(HKEY("nonexistenshit"), "", 0, do_404, ANONYMOUS|BOGUS); /* Exploit found in the wild January 2009 */
821 HttpNewModule_CONTEXT
822 (ParsedHttpHdrs *httpreq)
824 httpreq->PlainArgs = NewStrBufPlain(NULL, SIZ);
825 httpreq->this_page = NewStrBufPlain(NULL, SIZ);
829 HttpDetachModule_CONTEXT
830 (ParsedHttpHdrs *httpreq)
832 FlushStrBuf(httpreq->PlainArgs);
833 FlushStrBuf(httpreq->this_page);
834 FlushStrBuf(httpreq->PlainArgs);
835 DeleteHash(&httpreq->HTTPHeaders);
836 memset(&httpreq->HR, 0, sizeof(HdrRefs));
840 HttpDestroyModule_CONTEXT
841 (ParsedHttpHdrs *httpreq)
843 FreeStrBuf(&httpreq->this_page);
844 FreeStrBuf(&httpreq->PlainArgs);
845 FreeStrBuf(&httpreq->this_page);
846 FreeStrBuf(&httpreq->PlainArgs);
847 DeleteHash(&httpreq->HTTPHeaders);