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-2012 by the citadel.org team
9 * This program is open source software. You can redistribute it and/or
10 * modify it under the terms of the GNU General Public License version 3.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
19 #include "webserver.h"
20 #include "modules_init.h"
22 /* Only one thread may manipulate SessionList at a time... */
23 pthread_mutex_t SessionListMutex;
25 wcsession *SessionList = NULL; /* Linked list of all webcit sessions */
27 pthread_key_t MyConKey; /* TSD key for MySession() */
28 HashList *HttpReqTypes = NULL;
29 HashList *HttpHeaderHandler = NULL;
30 extern HashList *HandlerHash;
32 /* the following two values start at 1 because the initial parent thread counts as one. */
33 int num_threads_existing = 1; /* Number of worker threads which exist. */
34 int num_threads_executing = 1; /* Number of worker threads currently executing. */
36 extern void session_loop(void);
37 void spawn_another_worker_thread(void);
40 void DestroyHttpHeaderHandler(void *V)
43 pHdr = (OneHttpHeader*) V;
44 FreeStrBuf(&pHdr->Val);
48 void shutdown_sessions(void)
52 for (sptr = SessionList; sptr != NULL; sptr = sptr->next) {
57 void do_housekeeping(void)
60 wcsession *sessions_to_kill = NULL;
63 * Lock the session list, moving any candidates for euthanasia into
66 CtdlLogResult(pthread_mutex_lock(&SessionListMutex));
67 for (sptr = SessionList; sptr != NULL; sptr = sptr->next) {
69 /* Kill idle sessions */
70 if ((time(NULL) - (sptr->lastreq)) > (time_t) WEBCIT_TIMEOUT) {
71 syslog(LOG_DEBUG, "Timeout session %d", sptr->wc_session);
75 /* Remove sessions flagged for kill */
78 /* remove session from linked list */
79 if (sptr == SessionList) {
80 SessionList = SessionList->next;
82 else for (ss=SessionList;ss!=NULL;ss=ss->next) {
83 if (ss->next == sptr) {
84 ss->next = ss->next->next;
88 sptr->next = sessions_to_kill;
89 sessions_to_kill = sptr;
92 CtdlLogResult(pthread_mutex_unlock(&SessionListMutex));
95 * Now free up and destroy the culled sessions.
97 while (sessions_to_kill != NULL) {
98 syslog(LOG_DEBUG, "Destroying session %d", sessions_to_kill->wc_session);
99 sptr = sessions_to_kill->next;
100 session_destroy_modules(&sessions_to_kill);
101 sessions_to_kill = sptr;
106 * Check the size of our thread pool. If all threads are executing, spawn another.
108 void check_thread_pool_size(void)
110 if (time_to_die) return; /* don't expand the thread pool during shutdown */
112 begin_critical_section(S_SPAWNER); /* only one of these should run at a time */
114 (num_threads_executing >= num_threads_existing)
115 && (num_threads_existing < MAX_WORKER_THREADS)
117 syslog(LOG_DEBUG, "%d of %d threads are executing. Adding another worker thread.",
118 num_threads_executing,
121 spawn_another_worker_thread();
123 end_critical_section(S_SPAWNER);
128 * Wake up occasionally and clean house
130 void housekeeping_loop(void)
133 sleeeeeeeeeep(HOUSEKEEPING);
140 * Create a Session id
141 * Generate a unique WebCit session ID (which is not the same thing as the
142 * Citadel session ID).
144 int GenerateSessionID(void)
146 static int seq = (-1);
149 seq = (int) time(NULL);
155 wcsession *FindSession(wcsession **wclist, ParsedHttpHdrs *Hdr, pthread_mutex_t *ListMutex)
157 wcsession *sptr = NULL;
158 wcsession *TheSession = NULL;
160 if (Hdr->HR.got_auth == AUTH_BASIC) {
164 CtdlLogResult(pthread_mutex_lock(ListMutex));
165 for (sptr = *wclist; ((sptr != NULL) && (TheSession == NULL)); sptr = sptr->next) {
167 /* If HTTP-AUTH, look for a session with matching credentials */
168 switch (Hdr->HR.got_auth)
171 if ( (!strcasecmp(ChrPtr(Hdr->c_username), ChrPtr(sptr->wc_username)))
172 && (!strcasecmp(ChrPtr(Hdr->c_password), ChrPtr(sptr->wc_password)))
173 && (sptr->killthis == 0)
175 syslog(LOG_DEBUG, "Matched a session with the same http-auth");
180 /* If cookie-session, look for a session with matching session ID */
181 if ( (Hdr->HR.desired_session != 0)
182 && (sptr->wc_session == Hdr->HR.desired_session)
184 syslog(LOG_DEBUG, "Matched a session with the same cookie");
189 /* Any unbound session is a candidate */
190 if ( (sptr->wc_session == 0) && (sptr->inuse == 0) ) {
191 syslog(LOG_DEBUG, "Reusing an unbound session");
197 CtdlLogResult(pthread_mutex_unlock(ListMutex));
198 if (TheSession == NULL) {
199 syslog(LOG_DEBUG, "No existing session was matched");
204 wcsession *CreateSession(int Lockable, int Static, wcsession **wclist, ParsedHttpHdrs *Hdr, pthread_mutex_t *ListMutex)
206 wcsession *TheSession;
207 TheSession = (wcsession *) malloc(sizeof(wcsession));
208 memset(TheSession, 0, sizeof(wcsession));
209 TheSession->Hdr = Hdr;
210 TheSession->serv_sock = (-1);
212 pthread_setspecific(MyConKey, (void *)TheSession);
214 /* If we're recreating a session that expired, it's best to give it the same
215 * session number that it had before. The client browser ought to pick up
216 * the new session number and start using it, but in some rare situations it
217 * doesn't, and that's a Bad Thing because it causes lots of spurious sessions
220 if (Hdr->HR.desired_session == 0) {
221 TheSession->wc_session = GenerateSessionID();
222 syslog(LOG_DEBUG, "Created new session %d", TheSession->wc_session);
225 TheSession->wc_session = Hdr->HR.desired_session;
226 syslog(LOG_DEBUG, "Re-created session %d", TheSession->wc_session);
228 Hdr->HR.Static = Static;
229 session_new_modules(TheSession);
232 pthread_mutex_init(&TheSession->SessionMutex, NULL);
234 if (ListMutex != NULL)
235 CtdlLogResult(pthread_mutex_lock(ListMutex));
237 if (wclist != NULL) {
238 TheSession->nonce = rand();
239 TheSession->next = *wclist;
240 *wclist = TheSession;
242 if (ListMutex != NULL)
243 CtdlLogResult(pthread_mutex_unlock(ListMutex));
249 /* If it's a "force 404" situation then display the error and bail. */
252 hprintf("HTTP/1.1 404 Not found\r\n");
253 hprintf("Content-Type: text/plain\r\n");
254 wc_printf("Not found\r\n");
258 int ReadHttpSubject(ParsedHttpHdrs *Hdr, StrBuf *Line, StrBuf *Buf)
261 void *vLine, *vHandler;
262 const char *Pos = NULL;
264 Hdr->HR.ReqLine = Line;
265 /* The requesttype... GET, POST... */
266 StrBufExtract_token(Buf, Hdr->HR.ReqLine, 0, ' ');
267 if (GetHash(HttpReqTypes, SKEY(Buf), &vLine) &&
270 Hdr->HR.eReqType = *(long*)vLine;
273 Hdr->HR.eReqType = eGET;
276 StrBufCutLeft(Hdr->HR.ReqLine, StrLength(Buf) + 1);
278 /* the HTTP Version... */
279 StrBufExtract_token(Buf, Hdr->HR.ReqLine, 1, ' ');
280 StrBufCutRight(Hdr->HR.ReqLine, StrLength(Buf) + 1);
282 if (StrLength(Buf) == 0) {
283 Hdr->HR.eReqType = eGET;
287 StrBufAppendBuf(Hdr->this_page, Hdr->HR.ReqLine, 0);
289 /* chop Filename / query arguments */
290 Args = strchr(ChrPtr(Hdr->HR.ReqLine), '?');
291 if (Args == NULL) /* whe're not that picky about params... TODO: this will spoil '&' in filenames.*/
292 Args = strchr(ChrPtr(Hdr->HR.ReqLine), '&');
294 Args ++; /* skip the ? */
295 StrBufPlain(Hdr->PlainArgs,
297 StrLength(Hdr->HR.ReqLine) -
298 (Args - ChrPtr(Hdr->HR.ReqLine)));
299 StrBufCutAt(Hdr->HR.ReqLine, 0, Args - 1);
300 } /* don't parse them yet, maybe we don't even care... */
302 /* now lookup what we are going to do with this... */
303 /* skip first slash */
304 StrBufExtract_NextToken(Buf, Hdr->HR.ReqLine, &Pos, '/');
306 StrBufExtract_NextToken(Buf, Hdr->HR.ReqLine, &Pos, '/');
308 GetHash(HandlerHash, SKEY(Buf), &vHandler),
309 Hdr->HR.Handler = (WebcitHandler*) vHandler;
310 if (Hdr->HR.Handler == NULL)
313 * If the request is prefixed by "/webcit" then chop that off. This
314 * allows a front end web server to forward all /webcit requests to us
315 * while still using the same web server port for other things.
317 if ((Hdr->HR.Handler->Flags & URLNAMESPACE) != 0)
321 /* remove the handlername from the URL */
322 if ((Pos != NULL) && (Pos != StrBufNOTNULL)){
323 StrBufCutLeft(Hdr->HR.ReqLine,
324 Pos - ChrPtr(Hdr->HR.ReqLine));
327 if (Hdr->HR.Handler != NULL) {
328 if ((Hdr->HR.Handler->Flags & BOGUS) != 0) {
331 Hdr->HR.DontNeedAuth = (
332 ((Hdr->HR.Handler->Flags & ISSTATIC) != 0) ||
333 ((Hdr->HR.Handler->Flags & ANONYMOUS) != 0)
337 /* If this is a "flat" request for the root, display the configured landing page. */
339 StrBuf *NewLine = NewStrBuf();
340 Hdr->HR.DontNeedAuth = 1;
341 StrBufAppendPrintf(NewLine, "GET /landing?go=%s HTTP/1.0", ChrPtr(Buf));
342 syslog(LOG_DEBUG, "Replacing with: %s", ChrPtr(NewLine));
343 return_value = ReadHttpSubject(Hdr, NewLine, Buf);
344 FreeStrBuf(&NewLine);
351 int AnalyseHeaders(ParsedHttpHdrs *Hdr)
357 HashPos *at = GetNewHashPos(Hdr->HTTPHeaders, 0);
359 while (GetNextHashPos(Hdr->HTTPHeaders, at, &HKLen, &HashKey, &vHdr) &&
361 pHdr = (OneHttpHeader *)vHdr;
362 if (pHdr->HaveEvaluator)
363 pHdr->H(pHdr->Val, Hdr);
370 /*const char *nix(void *vptr) {return ChrPtr( (StrBuf*)vptr);}*/
373 * Read in the request
375 int ReadHTTPRequest (ParsedHttpHdrs *Hdr)
377 const char *pch, *pchs, *pche;
379 StrBuf *Line, *LastLine, *HeaderName;
384 HeaderName = NewStrBuf();
388 Line = NewStrBufPlain(NULL, SIZ / 4);
390 if (ClientGetLine(Hdr, Line) < 0) return 1;
392 if (StrLength(Line) == 0) {
397 Hdr->HTTPHeaders = NewHash(1, NULL);
398 pHdr = (OneHttpHeader*) malloc(sizeof(OneHttpHeader));
399 memset(pHdr, 0, sizeof(OneHttpHeader));
401 Put(Hdr->HTTPHeaders, HKEY("GET /"), pHdr, DestroyHttpHeaderHandler);
402 syslog(LOG_DEBUG, "%s", ChrPtr(Line));
403 isbogus = ReadHttpSubject(Hdr, Line, HeaderName);
408 /* Do we need to Unfold? */
409 if ((LastLine != NULL) &&
410 (isspace(*ChrPtr(Line)))) {
411 pch = pchs = ChrPtr(Line);
412 pche = pchs + StrLength(Line);
413 while (isspace(*pch) && (pch < pche))
415 StrBufCutLeft(Line, pch - pchs);
416 StrBufAppendBuf(LastLine, Line, 0);
422 StrBufSanitizeAscii(Line, '§');
423 StrBufExtract_token(HeaderName, Line, 0, ':');
426 pche = pchs + StrLength(Line);
427 pch = pchs + StrLength(HeaderName) + 1;
428 pche = pchs + StrLength(Line);
429 while ((pch < pche) && isspace(*pch))
431 StrBufCutLeft(Line, pch - pchs);
433 StrBufUpCase(HeaderName);
435 pHdr = (OneHttpHeader*) malloc(sizeof(OneHttpHeader));
436 memset(pHdr, 0, sizeof(OneHttpHeader));
439 if (GetHash(HttpHeaderHandler, SKEY(HeaderName), &vF) &&
442 OneHttpHeader *FHdr = (OneHttpHeader*) vF;
444 pHdr->HaveEvaluator = 1;
446 Put(Hdr->HTTPHeaders, SKEY(HeaderName), pHdr, DestroyHttpHeaderHandler);
448 } while (Line != NULL);
450 FreeStrBuf(&HeaderName);
455 void OverrideRequest(ParsedHttpHdrs *Hdr, const char *Line, long len)
457 StrBuf *Buf = NewStrBuf();
459 if (Hdr->HR.ReqLine != NULL) {
460 FlushStrBuf(Hdr->HR.ReqLine);
461 StrBufPlain(Hdr->HR.ReqLine, Line, len);
464 Hdr->HR.ReqLine = NewStrBufPlain(Line, len);
466 ReadHttpSubject(Hdr, Hdr->HR.ReqLine, Buf);
474 * This loop gets called once for every HTTP connection made to WebCit. At
475 * this entry point we have an HTTP socket with a browser allegedly on the
476 * other end, but we have not yet bound to a WebCit session.
478 * The job of this function is to locate the correct session and bind to it,
479 * or create a session if necessary and bind to it, then run the WebCit
480 * transaction loop. Afterwards, we unbind from the session. When this
481 * function returns, the worker thread is then free to handle another
484 void context_loop(ParsedHttpHdrs *Hdr)
487 wcsession *TheSession;
488 struct timeval tx_start;
489 struct timeval tx_finish;
490 int session_may_be_reused = 1;
492 gettimeofday(&tx_start, NULL); /* start a stopwatch for performance timing */
495 * Find out what it is that the web browser is asking for
497 isbogus = ReadHTTPRequest(Hdr);
499 Hdr->HR.dav_depth = 32767; /* TODO: find a general way to have non-0 defaults */
502 isbogus = AnalyseHeaders(Hdr);
506 || ((Hdr->HR.Handler != NULL)
507 && ((Hdr->HR.Handler->Flags & BOGUS) != 0))
510 Bogus = CreateSession(0, 1, NULL, Hdr, NULL);
512 syslog(LOG_WARNING, "HTTP: 404 [%ld.%06ld] %s %s",
513 ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) / 1000000,
514 ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) % 1000000,
515 ReqStrs[Hdr->HR.eReqType],
516 ChrPtr(Hdr->this_page)
518 session_detach_modules(Bogus);
519 session_destroy_modules(&Bogus);
523 if ((Hdr->HR.Handler != NULL) && ((Hdr->HR.Handler->Flags & ISSTATIC) != 0))
526 Static = CreateSession(0, 1, NULL, Hdr, NULL);
528 Hdr->HR.Handler->F();
530 /* How long did this transaction take? */
531 gettimeofday(&tx_finish, NULL);
533 syslog(LOG_DEBUG, "HTTP: 200 [%ld.%06ld] %s %s",
534 ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) / 1000000,
535 ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) % 1000000,
536 ReqStrs[Hdr->HR.eReqType],
537 ChrPtr(Hdr->this_page)
539 session_detach_modules(Static);
540 session_destroy_modules(&Static);
544 if (Hdr->HR.got_auth == AUTH_BASIC) {
548 if (Hdr->HR.got_auth) {
549 session_may_be_reused = 0;
553 * See if there's an existing session open with any of:
554 * - The desired Session ID
555 * - A matching http-auth username and password
556 * - An unbound session flagged as reusable
558 TheSession = FindSession(&SessionList, Hdr, &SessionListMutex);
561 * If there were no qualifying sessions, then create a new one.
563 if (TheSession == NULL) {
564 TheSession = CreateSession(1, 0, &SessionList, Hdr, &SessionListMutex);
568 * Reject transactions which require http-auth, if http-auth was not provided
570 if ( (StrLength(Hdr->c_username) == 0)
571 && (!Hdr->HR.DontNeedAuth)
572 && (Hdr->HR.Handler != NULL)
573 && ((XHTTP_COMMANDS & Hdr->HR.Handler->Flags) == XHTTP_COMMANDS)
575 syslog(LOG_DEBUG, "http-auth required but not provided");
576 OverrideRequest(Hdr, HKEY("GET /401 HTTP/1.0"));
577 Hdr->HR.prohibit_caching = 1;
581 * A future improvement might be to check the session integrity
582 * at this point before continuing.
586 * Bind to the session and perform the transaction
588 CtdlLogResult(pthread_mutex_lock(&TheSession->SessionMutex));
589 pthread_setspecific(MyConKey, (void *)TheSession);
591 TheSession->inuse = 1; /* mark the session as bound */
592 TheSession->lastreq = time(NULL); /* log */
593 TheSession->Hdr = Hdr;
596 * If a language was requested via a cookie, select that language now.
598 if (StrLength(Hdr->c_language) > 0) {
599 syslog(LOG_DEBUG, "Session cookie requests language '%s'", ChrPtr(Hdr->c_language));
600 set_selected_language(ChrPtr(Hdr->c_language));
601 go_selected_language();
607 session_attach_modules(TheSession);
610 /* How long did this transaction take? */
611 gettimeofday(&tx_finish, NULL);
613 syslog(LOG_INFO, "HTTP: 200 [%ld.%06ld] %s %s",
614 ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) / 1000000,
615 ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) % 1000000,
616 ReqStrs[Hdr->HR.eReqType],
617 ChrPtr(Hdr->this_page)
620 session_detach_modules(TheSession);
622 /* If *this* very transaction did not explicitly specify a session cookie,
623 * and it did not log in, we want to flag the session as a candidate for
624 * re-use by the next unbound client that comes along. This keeps our session
625 * table from getting bombarded with new sessions when, for example, a web
626 * spider crawls the site without using cookies.
628 if ((session_may_be_reused) && (!WC->logged_in)) {
629 WC->wc_session = 0; /* flag as available for re-use */
630 TheSession->selected_language = 0; /* clear any non-default language setting */
633 TheSession->Hdr = NULL;
634 TheSession->inuse = 0; /* mark the session as unbound */
635 CtdlLogResult(pthread_mutex_unlock(&TheSession->SessionMutex));
638 void tmplput_nonce(StrBuf *Target, WCTemplputParams *TP)
641 StrBufAppendPrintf(Target, "%ld",
642 (WCC != NULL)? WCC->nonce:0);
645 void tmplput_current_user(StrBuf *Target, WCTemplputParams *TP)
647 StrBufAppendTemplate(Target, TP, WC->wc_fullname, 0);
650 void Header_HandleContentLength(StrBuf *Line, ParsedHttpHdrs *hdr)
652 hdr->HR.ContentLength = StrToi(Line);
655 void Header_HandleContentType(StrBuf *Line, ParsedHttpHdrs *hdr)
657 hdr->HR.ContentType = Line;
661 void Header_HandleHost(StrBuf *Line, ParsedHttpHdrs *hdr)
663 if (hdr->HostHeader != NULL) {
664 FreeStrBuf(&hdr->HostHeader);
666 hdr->HostHeader = NewStrBuf();
667 StrBufAppendPrintf(hdr->HostHeader, "%s://", (is_https ? "https" : "http") );
668 StrBufAppendBuf(hdr->HostHeader, Line, 0);
671 void Header_HandleXFFHost(StrBuf *Line, ParsedHttpHdrs *hdr)
673 if (!follow_xff) return;
675 if (hdr->HostHeader != NULL) {
676 FreeStrBuf(&hdr->HostHeader);
679 hdr->HostHeader = NewStrBuf();
680 StrBufAppendPrintf(hdr->HostHeader, "http://"); /* this is naive; do something about it */
681 StrBufAppendBuf(hdr->HostHeader, Line, 0);
685 void Header_HandleXFF(StrBuf *Line, ParsedHttpHdrs *hdr)
687 hdr->HR.browser_host = Line;
689 while (StrBufNum_tokens(hdr->HR.browser_host, ',') > 1) {
690 StrBufRemove_token(hdr->HR.browser_host, 0, ',');
692 StrBufTrim(hdr->HR.browser_host);
695 void Header_HandleIfModSince(StrBuf *Line, ParsedHttpHdrs *hdr)
697 hdr->HR.if_modified_since = httpdate_to_timestamp(Line);
700 void Header_HandleAcceptEncoding(StrBuf *Line, ParsedHttpHdrs *hdr)
705 if (strstr(&ChrPtr(Line)[16], "gzip")) {
709 const char *ReqStrs[eNONE] = {
723 ServerStartModule_CONTEXT
727 HttpReqTypes = NewHash(1, NULL);
728 HttpHeaderHandler = NewHash(1, NULL);
730 v = malloc(sizeof(long));
732 Put(HttpReqTypes, HKEY("GET"), v, NULL);
734 v = malloc(sizeof(long));
736 Put(HttpReqTypes, HKEY("POST"), v, NULL);
738 v = malloc(sizeof(long));
740 Put(HttpReqTypes, HKEY("OPTIONS"), v, NULL);
742 v = malloc(sizeof(long));
744 Put(HttpReqTypes, HKEY("PROPFIND"), v, NULL);
746 v = malloc(sizeof(long));
748 Put(HttpReqTypes, HKEY("PUT"), v, NULL);
750 v = malloc(sizeof(long));
752 Put(HttpReqTypes, HKEY("DELETE"), v, NULL);
754 v = malloc(sizeof(long));
756 Put(HttpReqTypes, HKEY("HEAD"), v, NULL);
758 v = malloc(sizeof(long));
760 Put(HttpReqTypes, HKEY("MOVE"), v, NULL);
762 v = malloc(sizeof(long));
764 Put(HttpReqTypes, HKEY("COPY"), v, NULL);
766 v = malloc(sizeof(long));
768 Put(HttpReqTypes, HKEY("REPORT"), 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("X-FORWARDED-HOST"), Header_HandleXFFHost); /* Apache way... */
796 RegisterHeaderHandler(HKEY("X-REAL-IP"), Header_HandleXFFHost); /* NGinX way... */
797 RegisterHeaderHandler(HKEY("HOST"), Header_HandleHost);
798 RegisterHeaderHandler(HKEY("X-FORWARDED-FOR"), Header_HandleXFF);
799 RegisterHeaderHandler(HKEY("ACCEPT-ENCODING"), Header_HandleAcceptEncoding);
800 RegisterHeaderHandler(HKEY("IF-MODIFIED-SINCE"), Header_HandleIfModSince);
802 RegisterNamespace("CURRENT_USER", 0, 1, tmplput_current_user, NULL, CTX_NONE);
803 RegisterNamespace("NONCE", 0, 0, tmplput_nonce, NULL, 0);
805 WebcitAddUrlHandler(HKEY("404"), "", 0, do_404, ANONYMOUS|COOKIEUNNEEDED);
807 * Look for commonly-found probes of malware such as worms, viruses, trojans, and Microsoft Office.
808 * Short-circuit these requests so we don't have to send them through the full processing loop.
810 WebcitAddUrlHandler(HKEY("scripts"), "", 0, do_404, ANONYMOUS|BOGUS); /* /root.exe - Worms and trojans and viruses, oh my! */
811 WebcitAddUrlHandler(HKEY("c"), "", 0, do_404, ANONYMOUS|BOGUS); /* /winnt */
812 WebcitAddUrlHandler(HKEY("MSADC"), "", 0, do_404, ANONYMOUS|BOGUS);
813 WebcitAddUrlHandler(HKEY("_vti"), "", 0, do_404, ANONYMOUS|BOGUS); /* Broken Microsoft DAV implementation */
814 WebcitAddUrlHandler(HKEY("MSOffice"), "", 0, do_404, ANONYMOUS|BOGUS); /* Stoopid MSOffice thinks everyone is IIS */
815 WebcitAddUrlHandler(HKEY("nonexistenshit"), "", 0, do_404, ANONYMOUS|BOGUS); /* Exploit found in the wild January 2009 */
820 HttpNewModule_CONTEXT
821 (ParsedHttpHdrs *httpreq)
823 httpreq->PlainArgs = NewStrBufPlain(NULL, SIZ);
824 httpreq->this_page = NewStrBufPlain(NULL, SIZ);
828 HttpDetachModule_CONTEXT
829 (ParsedHttpHdrs *httpreq)
831 FlushStrBuf(httpreq->PlainArgs);
832 FlushStrBuf(httpreq->HostHeader);
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 FreeStrBuf(&httpreq->HostHeader);
848 DeleteHash(&httpreq->HTTPHeaders);