]> code.citadel.org Git - citadel.git/blobdiff - webcit/context_loop.c
Session Cleanup: init timestamp properly.
[citadel.git] / webcit / context_loop.c
index bcab1154cce277f7f441e5196b9c9b8624878bf4..47c5610f33d712c9f22c0be48b419b98c1069e27 100644 (file)
@@ -4,7 +4,7 @@
  * keep track of things.  If the HTTP request doesn't belong to any currently
  * active session, a new session is started.
  *
- * Copyright (c) 1996-2011 by the citadel.org team
+ * Copyright (c) 1996-2012 by the citadel.org team
  *
  * This program is open source software.  You can redistribute it and/or
  * modify it under the terms of the GNU General Public License version 3.
@@ -58,16 +58,21 @@ void do_housekeeping(void)
 {
        wcsession *sptr, *ss;
        wcsession *sessions_to_kill = NULL;
+       time_t the_time;
 
        /*
         * Lock the session list, moving any candidates for euthanasia into
         * a separate list.
         */
+       the_time = 0;
        CtdlLogResult(pthread_mutex_lock(&SessionListMutex));
        for (sptr = SessionList; sptr != NULL; sptr = sptr->next) {
-
+               if (the_time == 0)
+                       the_time = time(NULL);
                /* Kill idle sessions */
-               if ((time(NULL) - (sptr->lastreq)) > (time_t) WEBCIT_TIMEOUT) {
+               if ((sptr->inuse == 0) && 
+                   ((the_time - (sptr->lastreq)) > (time_t) WEBCIT_TIMEOUT))
+               {
                        syslog(3, "Timeout session %d", sptr->wc_session);
                        sptr->killthis = 1;
                }
@@ -208,6 +213,7 @@ wcsession *CreateSession(int Lockable, int Static, wcsession **wclist, ParsedHtt
        memset(TheSession, 0, sizeof(wcsession));
        TheSession->Hdr = Hdr;
        TheSession->serv_sock = (-1);
+       TheSession->lastreq = time(NULL);;
 
        pthread_setspecific(MyConKey, (void *)TheSession);
        
@@ -334,12 +340,13 @@ int ReadHttpSubject(ParsedHttpHdrs *Hdr, StrBuf *Line, StrBuf *Buf)
                );
        }
        else {
-               Hdr->HR.DontNeedAuth = 1; /* Flat request? show him the login screen... */
-               StrBuf *NewLine = NewStrBufPlain(HKEY("GET /do_template?template=login"));
-               StrBufUrlescAppend(NewLine, Buf, NULL);
-               StrBufAppendBufPlain(NewLine, HKEY(" HTTP/1.0"), 0);
+               /* If this is a "flat" request for the root, display the configured landing page. */
+               int return_value;
+               StrBuf *NewLine = NewStrBuf();
+               Hdr->HR.DontNeedAuth = 1;
+               StrBufAppendPrintf(NewLine, "GET /landing?go=%s HTTP/1.0", ChrPtr(Buf));
                syslog(LOG_DEBUG, "Replacing with: %s", ChrPtr(NewLine));
-               int return_value = ReadHttpSubject(Hdr, NewLine, Buf);
+               return_value = ReadHttpSubject(Hdr, NewLine, Buf);
                FreeStrBuf(&NewLine);
                return return_value;
        }
@@ -487,6 +494,7 @@ void context_loop(ParsedHttpHdrs *Hdr)
        struct timeval tx_start;
        struct timeval tx_finish;
        int session_may_be_reused = 1;
+       time_t now;
        
        gettimeofday(&tx_start, NULL);          /* start a stopwatch for performance timing */
 
@@ -559,7 +567,7 @@ void context_loop(ParsedHttpHdrs *Hdr)
        /*
         * If there were no qualifying sessions, then create a new one.
         */
-       if (TheSession == NULL) {
+       if ((TheSession == NULL) || (TheSession->killthis != 0)) {
                TheSession = CreateSession(1, 0, &SessionList, Hdr, &SessionListMutex);
        }
 
@@ -584,11 +592,12 @@ void context_loop(ParsedHttpHdrs *Hdr)
        /*
         * Bind to the session and perform the transaction
         */
+       now = time(NULL);;
        CtdlLogResult(pthread_mutex_lock(&TheSession->SessionMutex));
        pthread_setspecific(MyConKey, (void *)TheSession);
        
-       TheSession->inuse = 1;                                  /* mark the session as bound */
-       TheSession->lastreq = time(NULL);                       /* log */
+       TheSession->inuse = 1;                          /* mark the session as bound */
+       TheSession->lastreq = now;                      /* log */
        TheSession->Hdr = Hdr;
 
        /*