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-2011 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 as
11 * published by the Free Software Foundation; either version 3 of the
12 * License, or (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 extern void session_loop(void);
43 void spawn_another_worker_thread(void);
46 void DestroyHttpHeaderHandler(void *V)
49 pHdr = (OneHttpHeader*) V;
50 FreeStrBuf(&pHdr->Val);
54 void shutdown_sessions(void)
58 for (sptr = SessionList; sptr != NULL; sptr = sptr->next) {
63 void do_housekeeping(void)
66 wcsession *sessions_to_kill = NULL;
69 * Lock the session list, moving any candidates for euthanasia into
72 CtdlLogResult(pthread_mutex_lock(&SessionListMutex));
73 for (sptr = SessionList; sptr != NULL; sptr = sptr->next) {
75 /* Kill idle sessions */
76 if ((time(NULL) - (sptr->lastreq)) > (time_t) WEBCIT_TIMEOUT) {
77 syslog(3, "Timeout session %d\n", sptr->wc_session);
81 /* Remove sessions flagged for kill */
84 /* remove session from linked list */
85 if (sptr == SessionList) {
86 SessionList = SessionList->next;
88 else for (ss=SessionList;ss!=NULL;ss=ss->next) {
89 if (ss->next == sptr) {
90 ss->next = ss->next->next;
94 sptr->next = sessions_to_kill;
95 sessions_to_kill = sptr;
98 CtdlLogResult(pthread_mutex_unlock(&SessionListMutex));
101 * Now free up and destroy the culled sessions.
103 while (sessions_to_kill != NULL) {
104 syslog(3, "Destroying session %d\n", sessions_to_kill->wc_session);
105 sptr = sessions_to_kill->next;
106 session_destroy_modules(&sessions_to_kill);
107 sessions_to_kill = sptr;
112 * Check the size of our thread pool. If all threads are executing, spawn another.
114 void check_thread_pool_size(void)
116 if (time_to_die) return; /* don't expand the thread pool during shutdown */
118 begin_critical_section(S_SPAWNER); /* only one of these should run at a time */
120 (num_threads_executing >= num_threads_existing)
121 && (num_threads_existing < MAX_WORKER_THREADS)
123 syslog(3, "%d of %d threads are executing. Adding another worker thread.\n",
124 num_threads_executing,
127 spawn_another_worker_thread();
129 end_critical_section(S_SPAWNER);
134 * Wake up occasionally and clean house
136 void housekeeping_loop(void)
139 sleeeeeeeeeep(HOUSEKEEPING);
146 * Create a Session id
147 * Generate a unique WebCit session ID (which is not the same thing as the
148 * Citadel session ID).
150 int GenerateSessionID(void)
152 static int seq = (-1);
155 seq = (int) time(NULL);
161 wcsession *FindSession(wcsession **wclist, ParsedHttpHdrs *Hdr, pthread_mutex_t *ListMutex)
163 wcsession *sptr = NULL;
164 wcsession *TheSession = NULL;
166 if (Hdr->HR.got_auth == AUTH_BASIC) {
170 CtdlLogResult(pthread_mutex_lock(ListMutex));
171 for (sptr = *wclist; ((sptr != NULL) && (TheSession == NULL)); sptr = sptr->next) {
173 /* If HTTP-AUTH, look for a session with matching credentials */
174 switch (Hdr->HR.got_auth)
177 if ( (Hdr->HR.SessionKey != sptr->SessionKey))
179 if ((!strcasecmp(ChrPtr(Hdr->c_username), ChrPtr(sptr->wc_username))) &&
180 (!strcasecmp(ChrPtr(Hdr->c_password), ChrPtr(sptr->wc_password))) ) {
181 syslog(LOG_DEBUG, "-- matched a session with the same http-auth");
184 if (TheSession == NULL)
185 syslog(1, "found sessionkey [%d], but credentials for [%s|%s] didn't match",
187 ChrPtr(Hdr->c_username),
188 ChrPtr(sptr->wc_username)
192 /* If cookie-session, look for a session with matching session ID */
193 if ( (Hdr->HR.desired_session != 0) &&
194 (sptr->wc_session == Hdr->HR.desired_session))
196 syslog(LOG_DEBUG, "-- matched a session with the same cookie");
201 /* Any unbound session is a candidate */
202 if ( (sptr->wc_session == 0) && (sptr->inuse == 0) ) {
203 syslog(LOG_DEBUG, "-- reusing an unbound session");
209 CtdlLogResult(pthread_mutex_unlock(ListMutex));
210 if (TheSession == NULL) {
211 syslog(1, "didn't find sessionkey [%d] for user [%s]",
212 Hdr->HR.SessionKey, ChrPtr(Hdr->c_username)
218 wcsession *CreateSession(int Lockable, int Static, wcsession **wclist, ParsedHttpHdrs *Hdr, pthread_mutex_t *ListMutex)
220 wcsession *TheSession;
221 TheSession = (wcsession *) malloc(sizeof(wcsession));
222 memset(TheSession, 0, sizeof(wcsession));
223 TheSession->Hdr = Hdr;
224 TheSession->SessionKey = Hdr->HR.SessionKey;
225 TheSession->serv_sock = (-1);
227 pthread_setspecific(MyConKey, (void *)TheSession);
229 /* If we're recreating a session that expired, it's best to give it the same
230 * session number that it had before. The client browser ought to pick up
231 * the new session number and start using it, but in some rare situations it
232 * doesn't, and that's a Bad Thing because it causes lots of spurious sessions
235 if (Hdr->HR.desired_session == 0) {
236 TheSession->wc_session = GenerateSessionID();
237 syslog(3, "Created new session %d", TheSession->wc_session);
240 TheSession->wc_session = Hdr->HR.desired_session;
241 syslog(3, "Re-created session %d", TheSession->wc_session);
243 Hdr->HR.Static = Static;
244 session_new_modules(TheSession);
247 pthread_mutex_init(&TheSession->SessionMutex, NULL);
249 if (ListMutex != NULL)
250 CtdlLogResult(pthread_mutex_lock(ListMutex));
252 if (wclist != NULL) {
253 TheSession->nonce = rand();
254 TheSession->next = *wclist;
255 *wclist = TheSession;
257 if (ListMutex != NULL)
258 CtdlLogResult(pthread_mutex_unlock(ListMutex));
264 /* If it's a "force 404" situation then display the error and bail. */
267 hprintf("HTTP/1.1 404 Not found\r\n");
268 hprintf("Content-Type: text/plain\r\n");
269 wc_printf("Not found\r\n");
273 int ReadHttpSubject(ParsedHttpHdrs *Hdr, StrBuf *Line, StrBuf *Buf)
276 void *vLine, *vHandler;
277 const char *Pos = NULL;
280 Hdr->HR.ReqLine = Line;
281 /* The requesttype... GET, POST... */
282 StrBufExtract_token(Buf, Hdr->HR.ReqLine, 0, ' ');
283 if (GetHash(HttpReqTypes, SKEY(Buf), &vLine) &&
286 Hdr->HR.eReqType = *(long*)vLine;
289 Hdr->HR.eReqType = eGET;
292 StrBufCutLeft(Hdr->HR.ReqLine, StrLength(Buf) + 1);
294 /* the HTTP Version... */
295 StrBufExtract_token(Buf, Hdr->HR.ReqLine, 1, ' ');
296 StrBufCutRight(Hdr->HR.ReqLine, StrLength(Buf) + 1);
298 if (StrLength(Buf) == 0) {
299 Hdr->HR.eReqType = eGET;
303 StrBufAppendBuf(Hdr->this_page, Hdr->HR.ReqLine, 0);
305 /* chop Filename / query arguments */
306 Args = strchr(ChrPtr(Hdr->HR.ReqLine), '?');
307 if (Args == NULL) /* whe're not that picky about params... TODO: this will spoil '&' in filenames.*/
308 Args = strchr(ChrPtr(Hdr->HR.ReqLine), '&');
310 Args ++; /* skip the ? */
311 StrBufPlain(Hdr->PlainArgs,
313 StrLength(Hdr->HR.ReqLine) -
314 (Args - ChrPtr(Hdr->HR.ReqLine)));
315 StrBufCutAt(Hdr->HR.ReqLine, 0, Args - 1);
316 } /* don't parse them yet, maybe we don't even care... */
318 /* now lookup what we are going to do with this... */
319 /* skip first slash */
320 StrBufExtract_NextToken(Buf, Hdr->HR.ReqLine, &Pos, '/');
322 StrBufExtract_NextToken(Buf, Hdr->HR.ReqLine, &Pos, '/');
324 GetHash(HandlerHash, SKEY(Buf), &vHandler),
325 Hdr->HR.Handler = (WebcitHandler*) vHandler;
326 if (Hdr->HR.Handler == NULL)
329 * If the request is prefixed by "/webcit" then chop that off. This
330 * allows a front end web server to forward all /webcit requests to us
331 * while still using the same web server port for other things.
333 if ((Hdr->HR.Handler->Flags & URLNAMESPACE) != 0)
337 /* remove the handlername from the URL */
338 if ((Pos != NULL) && (Pos != StrBufNOTNULL)){
339 StrBufCutLeft(Hdr->HR.ReqLine,
340 Pos - ChrPtr(Hdr->HR.ReqLine));
343 if (Hdr->HR.Handler != NULL) {
344 if ((Hdr->HR.Handler->Flags & BOGUS) != 0)
346 Hdr->HR.DontNeedAuth = (
347 ((Hdr->HR.Handler->Flags & ISSTATIC) != 0) ||
348 ((Hdr->HR.Handler->Flags & ANONYMOUS) != 0)
352 Hdr->HR.DontNeedAuth = 1; /* Flat request? show him the login screen... */
358 int AnalyseHeaders(ParsedHttpHdrs *Hdr)
364 HashPos *at = GetNewHashPos(Hdr->HTTPHeaders, 0);
366 while (GetNextHashPos(Hdr->HTTPHeaders, at, &HKLen, &HashKey, &vHdr) &&
368 pHdr = (OneHttpHeader *)vHdr;
369 if (pHdr->HaveEvaluator)
370 pHdr->H(pHdr->Val, Hdr);
377 /*const char *nix(void *vptr) {return ChrPtr( (StrBuf*)vptr);}*/
380 * Read in the request
382 int ReadHTTPRequest (ParsedHttpHdrs *Hdr)
384 const char *pch, *pchs, *pche;
386 StrBuf *Line, *LastLine, *HeaderName;
391 HeaderName = NewStrBuf();
395 Line = NewStrBufPlain(NULL, SIZ / 4);
397 if (ClientGetLine(Hdr, Line) < 0) return 1;
399 if (StrLength(Line) == 0) {
404 Hdr->HTTPHeaders = NewHash(1, NULL);
405 pHdr = (OneHttpHeader*) malloc(sizeof(OneHttpHeader));
406 memset(pHdr, 0, sizeof(OneHttpHeader));
408 Put(Hdr->HTTPHeaders, HKEY("GET /"), pHdr, DestroyHttpHeaderHandler);
409 syslog(9, "%s\n", ChrPtr(Line));
410 isbogus = ReadHttpSubject(Hdr, Line, HeaderName);
415 /* Do we need to Unfold? */
416 if ((LastLine != NULL) &&
417 (isspace(*ChrPtr(Line)))) {
418 pch = pchs = ChrPtr(Line);
419 pche = pchs + StrLength(Line);
420 while (isspace(*pch) && (pch < pche))
422 StrBufCutLeft(Line, pch - pchs);
423 StrBufAppendBuf(LastLine, Line, 0);
429 StrBufSanitizeAscii(Line, '§');
430 StrBufExtract_token(HeaderName, Line, 0, ':');
433 pche = pchs + StrLength(Line);
434 pch = pchs + StrLength(HeaderName) + 1;
435 pche = pchs + StrLength(Line);
436 while ((pch < pche) && isspace(*pch))
438 StrBufCutLeft(Line, pch - pchs);
440 StrBufUpCase(HeaderName);
442 pHdr = (OneHttpHeader*) malloc(sizeof(OneHttpHeader));
443 memset(pHdr, 0, sizeof(OneHttpHeader));
446 if (GetHash(HttpHeaderHandler, SKEY(HeaderName), &vF) &&
449 OneHttpHeader *FHdr = (OneHttpHeader*) vF;
451 pHdr->HaveEvaluator = 1;
453 Put(Hdr->HTTPHeaders, SKEY(HeaderName), pHdr, DestroyHttpHeaderHandler);
455 } while (Line != NULL);
457 FreeStrBuf(&HeaderName);
462 void OverrideRequest(ParsedHttpHdrs *Hdr, const char *Line, long len)
464 StrBuf *Buf = NewStrBuf();
466 if (Hdr->HR.ReqLine != NULL) {
467 FlushStrBuf(Hdr->HR.ReqLine);
468 StrBufPlain(Hdr->HR.ReqLine, Line, len);
471 Hdr->HR.ReqLine = NewStrBufPlain(Line, len);
473 ReadHttpSubject(Hdr, Hdr->HR.ReqLine, Buf);
481 * This loop gets called once for every HTTP connection made to WebCit. At
482 * this entry point we have an HTTP socket with a browser allegedly on the
483 * other end, but we have not yet bound to a WebCit session.
485 * The job of this function is to locate the correct session and bind to it,
486 * or create a session if necessary and bind to it, then run the WebCit
487 * transaction loop. Afterwards, we unbind from the session. When this
488 * function returns, the worker thread is then free to handle another
491 void context_loop(ParsedHttpHdrs *Hdr)
494 wcsession *TheSession;
495 struct timeval tx_start;
496 struct timeval tx_finish;
497 int session_may_be_reused = 1;
499 gettimeofday(&tx_start, NULL); /* start a stopwatch for performance timing */
502 * Find out what it is that the web browser is asking for
504 isbogus = ReadHTTPRequest(Hdr);
506 Hdr->HR.dav_depth = 32767; /* TODO: find a general way to have non-0 defaults */
508 isbogus = AnalyseHeaders(Hdr);
511 ((Hdr->HR.Handler != NULL) &&
512 ((Hdr->HR.Handler->Flags & BOGUS) != 0)))
516 Bogus = CreateSession(0, 1, NULL, Hdr, NULL);
520 syslog(9, "HTTP: 404 [%ld.%06ld] %s %s \n",
521 ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) / 1000000,
522 ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) % 1000000,
523 ReqStrs[Hdr->HR.eReqType],
524 ChrPtr(Hdr->this_page)
526 session_detach_modules(Bogus);
527 session_destroy_modules(&Bogus);
531 if ((Hdr->HR.Handler != NULL) && ((Hdr->HR.Handler->Flags & ISSTATIC) != 0))
534 Static = CreateSession(0, 1, NULL, Hdr, NULL);
536 Hdr->HR.Handler->F();
538 /* How long did this transaction take? */
539 gettimeofday(&tx_finish, NULL);
541 syslog(9, "HTTP: 200 [%ld.%06ld] %s %s \n",
542 ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) / 1000000,
543 ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) % 1000000,
544 ReqStrs[Hdr->HR.eReqType],
545 ChrPtr(Hdr->this_page)
547 session_detach_modules(Static);
548 session_destroy_modules(&Static);
552 if (Hdr->HR.got_auth == AUTH_BASIC) {
556 if (Hdr->HR.got_auth) {
557 session_may_be_reused = 0;
561 * See if there's an existing session open with the desired ID or user/pass
563 TheSession = FindSession(&SessionList, Hdr, &SessionListMutex);
566 * Create a new session if we have to
568 if (TheSession == NULL) {
569 TheSession = CreateSession(1, 0, &SessionList, Hdr, &SessionListMutex);
571 if ( (StrLength(Hdr->c_username) == 0)
572 && (!Hdr->HR.DontNeedAuth)
573 && (Hdr->HR.Handler != NULL)
574 && ((XHTTP_COMMANDS & Hdr->HR.Handler->Flags) == XHTTP_COMMANDS)
576 OverrideRequest(Hdr, HKEY("GET /401 HTTP/1.0"));
577 Hdr->HR.prohibit_caching = 1;
580 if (StrLength(Hdr->c_language) > 0) {
581 syslog(9, "Session cookie requests language '%s'\n", ChrPtr(Hdr->c_language));
582 set_selected_language(ChrPtr(Hdr->c_language));
583 go_selected_language();
588 * A future improvement might be to check the session integrity
589 * at this point before continuing.
593 * Bind to the session and perform the transaction
595 CtdlLogResult(pthread_mutex_lock(&TheSession->SessionMutex));
596 pthread_setspecific(MyConKey, (void *)TheSession);
598 TheSession->inuse = 1; /* mark the session as bound */
599 TheSession->lastreq = time(NULL); /* log */
600 TheSession->Hdr = Hdr;
602 session_attach_modules(TheSession);
603 session_loop(); /* do transaction */
605 /* How long did this transaction take? */
606 gettimeofday(&tx_finish, NULL);
608 syslog(9, "HTTP: 200 [%ld.%06ld] %s %s \n",
609 ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) / 1000000,
610 ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) % 1000000,
611 ReqStrs[Hdr->HR.eReqType],
612 ChrPtr(Hdr->this_page)
615 session_detach_modules(TheSession);
617 /* If *this* very transaction did not explicitly specify a session cookie,
618 * and it did not log in, we want to flag the session as a candidate for
619 * re-use by the next unbound client that comes along. This keeps our session
620 * table from getting bombarded with new sessions when, for example, a web
621 * spider crawls the site without using cookies.
623 if ((session_may_be_reused) && (!WC->logged_in)) {
624 WC->wc_session = 0; /* flag as available for re-use */
625 TheSession->selected_language = 0; /* clear any non-default language setting */
628 TheSession->Hdr = NULL;
629 TheSession->inuse = 0; /* mark the session as unbound */
630 CtdlLogResult(pthread_mutex_unlock(&TheSession->SessionMutex));
633 void tmplput_nonce(StrBuf *Target, WCTemplputParams *TP)
636 StrBufAppendPrintf(Target, "%ld",
637 (WCC != NULL)? WCC->nonce:0);
640 void tmplput_current_user(StrBuf *Target, WCTemplputParams *TP)
642 StrBufAppendTemplate(Target, TP, WC->wc_fullname, 0);
645 void Header_HandleContentLength(StrBuf *Line, ParsedHttpHdrs *hdr)
647 hdr->HR.ContentLength = StrToi(Line);
650 void Header_HandleContentType(StrBuf *Line, ParsedHttpHdrs *hdr)
652 hdr->HR.ContentType = Line;
656 void Header_HandleHost(StrBuf *Line, ParsedHttpHdrs *hdr)
658 if (hdr->HostHeader != NULL) {
659 FreeStrBuf(&hdr->HostHeader);
661 hdr->HostHeader = NewStrBuf();
662 StrBufAppendPrintf(hdr->HostHeader, "%s://", (is_https ? "https" : "http") );
663 StrBufAppendBuf(hdr->HostHeader, Line, 0);
666 void Header_HandleXFFHost(StrBuf *Line, ParsedHttpHdrs *hdr)
668 if (!follow_xff) return;
670 if (hdr->HostHeader != NULL) {
671 FreeStrBuf(&hdr->HostHeader);
674 hdr->HostHeader = NewStrBuf();
675 StrBufAppendPrintf(hdr->HostHeader, "http://"); /* this is naive; do something about it */
676 StrBufAppendBuf(hdr->HostHeader, Line, 0);
680 void Header_HandleXFF(StrBuf *Line, ParsedHttpHdrs *hdr)
682 hdr->HR.browser_host = Line;
684 while (StrBufNum_tokens(hdr->HR.browser_host, ',') > 1) {
685 StrBufRemove_token(hdr->HR.browser_host, 0, ',');
687 StrBufTrim(hdr->HR.browser_host);
690 void Header_HandleIfModSince(StrBuf *Line, ParsedHttpHdrs *hdr)
692 hdr->HR.if_modified_since = httpdate_to_timestamp(Line);
695 void Header_HandleAcceptEncoding(StrBuf *Line, ParsedHttpHdrs *hdr)
700 if (strstr(&ChrPtr(Line)[16], "gzip")) {
704 const char *ReqStrs[eNONE] = {
717 ServerStartModule_CONTEXT
721 HttpReqTypes = NewHash(1, NULL);
722 HttpHeaderHandler = NewHash(1, NULL);
724 v = malloc(sizeof(long));
726 Put(HttpReqTypes, HKEY("GET"), v, NULL);
728 v = malloc(sizeof(long));
730 Put(HttpReqTypes, HKEY("POST"), v, NULL);
732 v = malloc(sizeof(long));
734 Put(HttpReqTypes, HKEY("OPTIONS"), v, NULL);
736 v = malloc(sizeof(long));
738 Put(HttpReqTypes, HKEY("PROPFIND"), v, NULL);
740 v = malloc(sizeof(long));
742 Put(HttpReqTypes, HKEY("PUT"), v, NULL);
744 v = malloc(sizeof(long));
746 Put(HttpReqTypes, HKEY("DELETE"), v, NULL);
748 v = malloc(sizeof(long));
750 Put(HttpReqTypes, HKEY("HEAD"), v, NULL);
752 v = malloc(sizeof(long));
754 Put(HttpReqTypes, HKEY("MOVE"), v, NULL);
756 v = malloc(sizeof(long));
758 Put(HttpReqTypes, HKEY("COPY"), v, NULL);
762 ServerShutdownModule_CONTEXT
765 DeleteHash(&HttpReqTypes);
766 DeleteHash(&HttpHeaderHandler);
769 void RegisterHeaderHandler(const char *Name, long Len, Header_Evaluator F)
772 pHdr = (OneHttpHeader*) malloc(sizeof(OneHttpHeader));
773 memset(pHdr, 0, sizeof(OneHttpHeader));
775 Put(HttpHeaderHandler, Name, Len, pHdr, DestroyHttpHeaderHandler);
783 RegisterHeaderHandler(HKEY("CONTENT-LENGTH"), Header_HandleContentLength);
784 RegisterHeaderHandler(HKEY("CONTENT-TYPE"), Header_HandleContentType);
785 RegisterHeaderHandler(HKEY("X-FORWARDED-HOST"), Header_HandleXFFHost); /* Apache way... */
786 RegisterHeaderHandler(HKEY("X-REAL-IP"), Header_HandleXFFHost); /* NGinX way... */
787 RegisterHeaderHandler(HKEY("HOST"), Header_HandleHost);
788 RegisterHeaderHandler(HKEY("X-FORWARDED-FOR"), Header_HandleXFF);
789 RegisterHeaderHandler(HKEY("ACCEPT-ENCODING"), Header_HandleAcceptEncoding);
790 RegisterHeaderHandler(HKEY("IF-MODIFIED-SINCE"), Header_HandleIfModSince);
792 RegisterNamespace("CURRENT_USER", 0, 1, tmplput_current_user, NULL, CTX_NONE);
793 RegisterNamespace("NONCE", 0, 0, tmplput_nonce, NULL, 0);
795 WebcitAddUrlHandler(HKEY("404"), "", 0, do_404, ANONYMOUS|COOKIEUNNEEDED);
797 * Look for commonly-found probes of malware such as worms, viruses, trojans, and Microsoft Office.
798 * Short-circuit these requests so we don't have to send them through the full processing loop.
800 WebcitAddUrlHandler(HKEY("scripts"), "", 0, do_404, ANONYMOUS|BOGUS); /* /root.exe - Worms and trojans and viruses, oh my! */
801 WebcitAddUrlHandler(HKEY("c"), "", 0, do_404, ANONYMOUS|BOGUS); /* /winnt */
802 WebcitAddUrlHandler(HKEY("MSADC"), "", 0, do_404, ANONYMOUS|BOGUS);
803 WebcitAddUrlHandler(HKEY("_vti"), "", 0, do_404, ANONYMOUS|BOGUS); /* Broken Microsoft DAV implementation */
804 WebcitAddUrlHandler(HKEY("MSOffice"), "", 0, do_404, ANONYMOUS|BOGUS); /* Stoopid MSOffice thinks everyone is IIS */
805 WebcitAddUrlHandler(HKEY("nonexistenshit"), "", 0, do_404, ANONYMOUS|BOGUS); /* Exploit found in the wild January 2009 */
810 HttpNewModule_CONTEXT
811 (ParsedHttpHdrs *httpreq)
813 httpreq->PlainArgs = NewStrBufPlain(NULL, SIZ);
814 httpreq->this_page = NewStrBufPlain(NULL, SIZ);
818 HttpDetachModule_CONTEXT
819 (ParsedHttpHdrs *httpreq)
821 FlushStrBuf(httpreq->PlainArgs);
822 FlushStrBuf(httpreq->HostHeader);
823 FlushStrBuf(httpreq->this_page);
824 FlushStrBuf(httpreq->PlainArgs);
825 DeleteHash(&httpreq->HTTPHeaders);
826 memset(&httpreq->HR, 0, sizeof(HdrRefs));
830 HttpDestroyModule_CONTEXT
831 (ParsedHttpHdrs *httpreq)
833 FreeStrBuf(&httpreq->this_page);
834 FreeStrBuf(&httpreq->PlainArgs);
835 FreeStrBuf(&httpreq->this_page);
836 FreeStrBuf(&httpreq->PlainArgs);
837 FreeStrBuf(&httpreq->HostHeader);
838 DeleteHash(&httpreq->HTTPHeaders);