The 'nocookies' error page is no longer needed
[citadel.git] / webcit / context_loop.c
index ca72387d7d791c6af8d03121cafd98674cb8c366..26f6505f3f41f5c94e3721350390d3e2b72e8acc 100644 (file)
@@ -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;
 }
@@ -579,10 +579,16 @@ void context_loop(ParsedHttpHdrs *Hdr)
                                OverrideRequest(Hdr, HKEY("GET /401 HTTP/1.0"));
                                Hdr->HR.prohibit_caching = 1;                           
                        }
+
+                       /*
+                        * I don't think we need this anymore now that guest mode is working
+                        * ajc 2011jan07
+                        *
                        else {
                                OverrideRequest(Hdr, HKEY("GET /static/nocookies.html?force_close_session=yes HTTP/1.0"));
                                Hdr->HR.prohibit_caching = 1;
                        }
+                        */
                }
                
                if (StrLength(Hdr->c_language) > 0) {
@@ -600,7 +606,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 +634,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 +677,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);
+       }
 }