]> code.citadel.org Git - citadel.git/blobdiff - webcit/context_loop.c
* Discovered that Prototype makes it easy to auto-refresh, so I switched
[citadel.git] / webcit / context_loop.c
index 9389591d693d2c0b2a4d7529c797c8cfeeaa2b4d..a3541dd87cf56a15933d843e38ef4bb2bcbc19f1 100644 (file)
@@ -8,32 +8,6 @@
  *
  */
 
-#include <ctype.h>
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <stdio.h>
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/socket.h>
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-#ifdef HAVE_LIMITS_H
-#include <limits.h>
-#endif
-#include <netinet/in.h>
-#include <netdb.h>
-#include <string.h>
-#include <errno.h>
-#include <stdarg.h>
-#include <pthread.h>
-#include <signal.h>
 #include "webcit.h"
 #include "webserver.h"
 
@@ -113,7 +87,7 @@ void do_housekeeping(void)
                pthread_mutex_unlock(&sessions_to_kill->SessionMutex);
                sptr = sessions_to_kill->next;
                free(sessions_to_kill);
-               sessions_to_kill = sessions_to_kill->next;
+               sessions_to_kill = sptr;
                --num_sessions;
        }
 
@@ -267,6 +241,7 @@ void context_loop(int sock)
        char buf[SIZ], hold[SIZ];
        int desired_session = 0;
        int got_cookie = 0;
+       int gzip_ok = 0;
        struct wcsession *TheSession, *sptr;
        char httpauth_string[SIZ];
        char httpauth_user[SIZ];
@@ -283,12 +258,21 @@ void context_loop(int sock)
        do {
                if (req_gets(sock, buf, hold) < 0) return;
 
+               /*
+                * Can we compress?
+                */
+               if (!strncasecmp(buf, "Accept-encoding:", 16)) {
+                       if (strstr(&buf[16], "gzip")) {
+                               gzip_ok = 1;
+                       }
+               }
+
                /*
                 * Browser-based sessions use cookies for session authentication
                 */
                if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
                        cookie_to_stuff(&buf[15], &desired_session,
-                               NULL, NULL, NULL);
+                               NULL, 0, NULL, 0, NULL, 0);
                        got_cookie = 1;
                }
 
@@ -297,8 +281,12 @@ void context_loop(int sock)
                 */
                if (!strncasecmp(buf, "Authorization: Basic ", 21)) {
                        CtdlDecodeBase64(httpauth_string, &buf[21], strlen(&buf[21]));
-                       extract_token(httpauth_user, httpauth_string, 0, ':');
-                       extract_token(httpauth_pass, httpauth_string, 1, ':');
+                       extract_token(httpauth_user, httpauth_string, 0, ':', sizeof httpauth_user);
+                       extract_token(httpauth_pass, httpauth_string, 1, ':', sizeof httpauth_pass);
+               }
+
+               if (!strncasecmp(buf, "If-Modified-Since: ", 19)) {
+                       if_modified_since = httpdate_to_timestamp(&buf[19]);
                }
 
                /*
@@ -337,7 +325,7 @@ void context_loop(int sock)
         */
        if (!strncasecmp(buf, "/robots.txt", 11)) {
                strcpy(req->line, "GET /static/robots.txt"
-                               "?force_close_session=yes HTTP/1.0");
+                               "?force_close_session=yes HTTP/1.1");
        }
        else if (!strncasecmp(buf, "/favicon.ico", 12)) {
                strcpy(req->line, "GET /static/favicon.ico");
@@ -353,9 +341,10 @@ void context_loop(int sock)
                && (strncasecmp(buf, "/freebusy", 9))
                && (strncasecmp(buf, "/do_logout", 10))
                && (strncasecmp(buf, "/groupdav", 9))
+               && (strncasecmp(buf, "/rss", 4))
                && (got_cookie == 0)) {
                strcpy(req->line, "GET /static/nocookies.html"
-                               "?force_close_session=yes HTTP/1.0");
+                               "?force_close_session=yes HTTP/1.1");
        }
 
        /*
@@ -412,14 +401,12 @@ void context_loop(int sock)
        /*
         * Bind to the session and perform the transaction
         */
-       lprintf(9, "LOCKING SESSION %d\n", TheSession->wc_session);
        pthread_mutex_lock(&TheSession->SessionMutex);          /* bind */
-       lprintf(9, "LOCKKED SESSION %d\n", TheSession->wc_session);
        pthread_setspecific(MyConKey, (void *)TheSession);
        TheSession->http_sock = sock;
        TheSession->lastreq = time(NULL);                       /* log */
+       TheSession->gzip_ok = gzip_ok;
        session_loop(req);                              /* do transaction */
-       lprintf(9, "UNLKING SESSION %d\n", TheSession->wc_session);
        pthread_mutex_unlock(&TheSession->SessionMutex);        /* unbind */
 
        /* Free the request buffer */