X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fcontext_loop.c;h=d492ce09b5db076c79e72ad2fd1a101c134425a7;hb=f233f19ac6c7260469d86e442c53ad1b1fd374b9;hp=ca72387d7d791c6af8d03121cafd98674cb8c366;hpb=5825ba704f333af3df36eab870b9e78430a3c724;p=citadel.git diff --git a/webcit/context_loop.c b/webcit/context_loop.c index ca72387d7..d492ce09b 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -6,10 +6,10 @@ * * Copyright (c) 1996-2010 by the citadel.org team * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. + * This program is open source software. You can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "webcit.h" @@ -65,7 +65,7 @@ void do_housekeeping(void) * Lock the session list, moving any candidates for euthanasia into * a separate list. */ - pthread_mutex_lock(&SessionListMutex); + CtdlLogResult(pthread_mutex_lock(&SessionListMutex)); for (sptr = SessionList; sptr != NULL; sptr = sptr->next) { /* Kill idle sessions */ @@ -90,7 +90,7 @@ void do_housekeeping(void) sessions_to_kill = sptr; } } - pthread_mutex_unlock(&SessionListMutex); + CtdlLogResult(pthread_mutex_unlock(&SessionListMutex)); /* * Now free up and destroy the culled sessions. @@ -114,7 +114,7 @@ void check_thread_pool_size(void) if (time_to_die) return; /* don't expand the thread pool during shutdown */ begin_critical_section(S_SPAWNER); /* only one of these should run at a time */ - while ( + if ( (num_threads_executing >= num_threads_existing) && (num_threads_existing < MAX_WORKER_THREADS) ) { @@ -165,7 +165,7 @@ wcsession *FindSession(wcsession **wclist, ParsedHttpHdrs *Hdr, pthread_mutex_t GetAuthBasic(Hdr); } - pthread_mutex_lock(ListMutex); + CtdlLogResult(pthread_mutex_lock(ListMutex)); for (sptr = *wclist; ((sptr != NULL) && (TheSession == NULL)); sptr = sptr->next) { /* If HTTP-AUTH, look for a session with matching credentials */ @@ -193,7 +193,7 @@ wcsession *FindSession(wcsession **wclist, ParsedHttpHdrs *Hdr, pthread_mutex_t break; } } - pthread_mutex_unlock(ListMutex); + CtdlLogResult(pthread_mutex_unlock(ListMutex)); if (TheSession == NULL) lprintf(1, "didn't find sessionkey [%ld] for user [%s]\n", Hdr->HR.SessionKey,ChrPtr(Hdr->c_username)); @@ -233,7 +233,7 @@ wcsession *CreateSession(int Lockable, int Static, wcsession **wclist, ParsedHtt pthread_mutex_init(&TheSession->SessionMutex, NULL); if (ListMutex != NULL) - pthread_mutex_lock(ListMutex); + CtdlLogResult(pthread_mutex_lock(ListMutex)); if (wclist != NULL) { TheSession->nonce = rand(); @@ -241,7 +241,7 @@ wcsession *CreateSession(int Lockable, int Static, wcsession **wclist, ParsedHtt *wclist = TheSession; } if (ListMutex != NULL) - pthread_mutex_unlock(ListMutex); + CtdlLogResult(pthread_mutex_unlock(ListMutex)); } return TheSession; } @@ -572,17 +572,13 @@ void context_loop(ParsedHttpHdrs *Hdr) if (TheSession == NULL) { TheSession = CreateSession(1, 0, &SessionList, Hdr, &SessionListMutex); - if ((StrLength(Hdr->c_username) == 0) && (!Hdr->HR.DontNeedAuth)) { - - if ((Hdr->HR.Handler != NULL) && - (XHTTP_COMMANDS & Hdr->HR.Handler->Flags) == XHTTP_COMMANDS) { - OverrideRequest(Hdr, HKEY("GET /401 HTTP/1.0")); - Hdr->HR.prohibit_caching = 1; - } - else { - OverrideRequest(Hdr, HKEY("GET /static/nocookies.html?force_close_session=yes HTTP/1.0")); - Hdr->HR.prohibit_caching = 1; - } + if ( (StrLength(Hdr->c_username) == 0) + && (!Hdr->HR.DontNeedAuth) + && (Hdr->HR.Handler != NULL) + && ((XHTTP_COMMANDS & Hdr->HR.Handler->Flags) == XHTTP_COMMANDS) + ) { + OverrideRequest(Hdr, HKEY("GET /401 HTTP/1.0")); + Hdr->HR.prohibit_caching = 1; } if (StrLength(Hdr->c_language) > 0) { @@ -600,7 +596,7 @@ void context_loop(ParsedHttpHdrs *Hdr) /* * Bind to the session and perform the transaction */ - pthread_mutex_lock(&TheSession->SessionMutex); /* bind */ + CtdlLogResult(pthread_mutex_lock(&TheSession->SessionMutex)); pthread_setspecific(MyConKey, (void *)TheSession); TheSession->lastreq = time(NULL); /* log */ @@ -628,7 +624,7 @@ void context_loop(ParsedHttpHdrs *Hdr) session_detach_modules(TheSession); TheSession->Hdr = NULL; - pthread_mutex_unlock(&TheSession->SessionMutex); /* unbind */ + CtdlLogResult(pthread_mutex_unlock(&TheSession->SessionMutex)); } void tmplput_nonce(StrBuf *Target, WCTemplputParams *TP) @@ -671,16 +667,20 @@ void Header_HandleUserAgent(StrBuf *Line, ParsedHttpHdrs *hdr) void Header_HandleHost(StrBuf *Line, ParsedHttpHdrs *hdr) { - if ((follow_xff) && (hdr->HR.http_host != NULL)) - return; - else - hdr->HR.http_host = Line; + if (site_prefix == NULL) { + site_prefix = NewStrBuf(); + StrBufAppendPrintf(site_prefix, "%s://", (is_https ? "https" : "http") ); + StrBufAppendBuf(site_prefix, Line, 0); + } } void Header_HandleXFFHost(StrBuf *Line, ParsedHttpHdrs *hdr) { - if (follow_xff) - hdr->HR.http_host = Line; + if ( (follow_xff) && (site_prefix == NULL)) { + site_prefix = NewStrBuf(); + StrBufAppendPrintf(site_prefix, "http://"); /* this is naive; do something about it */ + StrBufAppendBuf(site_prefix, Line, 0); + } }