* Detect when the client browser is capable of gzip encoding
authorArt Cancro <ajc@citadel.org>
Fri, 13 Sep 2002 20:40:53 +0000 (20:40 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 13 Sep 2002 20:40:53 +0000 (20:40 +0000)
  (actual encoding is not implemented yet)

webcit/ChangeLog
webcit/configure.in
webcit/context_loop.c
webcit/webcit.c
webcit/webcit.h
webcit/webserver.c

index 5f51d5bac08069dcf4ea405d54fc81ed5c2efe3a..f5efca2168e0826d0ef009f0b6d7d9350a49897e 100644 (file)
@@ -1,4 +1,8 @@
 $Log$
+Revision 400.3  2002/09/13 20:40:53  ajc
+* Detect when the client browser is capable of gzip encoding
+  (actual encoding is not implemented yet)
+
 Revision 400.2  2002/09/13 15:54:40  ajc
 * Reversed the above change because I broke it somehow
 
@@ -943,3 +947,4 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
+
index 4f1feed6098a2f590b073012a991031bc397b208..7ae8530be6a396d47a20948a4309da9cc1d93281 100644 (file)
@@ -4,6 +4,8 @@ AC_INIT(webserver.c)
 
 AC_CANONICAL_HOST
 
+AC_ARG_WITH(with_zlib, [  --with-zlib       use zlib compression if present])
+
 dnl Set some system-specific variables which are OK to set before compiler
 dnl checks:
 PTHREAD_DEFS=-D_REENTRANT
@@ -69,5 +71,19 @@ dnl AC_FUNC_VPRINTF
 dnl AC_CHECK_FUNCS(strerror)
 AC_REPLACE_FUNCS(snprintf)
 
+dnl Checks for the zlib compression library.
+if test "x$with_zlib" != xno ; then
+       AC_CHECK_HEADERS(zlib.h,
+               [AC_CHECK_LIB(z, zlibVersion,
+                       [ok_zlib=yes],,
+       )])
+fi
+
+if test "x$ok_zlib" != xno ; then
+       LIBS="-lz $LIBS"
+       CFLAGS="-DWITH_ZLIB $CFLAGS"
+       AC_DEFINE(HAVE_ZLIB)
+fi
+
 AC_OUTPUT(Makefile)
 
index 5f67f93859d8af908764c26e0784e02c90b4cefa..9b744f13f12708675abade12df20fa94ff8f489d 100644 (file)
 #include <stdarg.h>
 #include <pthread.h>
 #include <signal.h>
+
+#ifdef WITH_ZLIB
+#include <zlib.h>
+#endif
+
 #include "webcit.h"
 #include "webserver.h"
 
@@ -152,6 +157,7 @@ int req_gets(int sock, char *buf, char *hold)
                                return(0);
                        }
        }
+
        return(0);
 }
 
@@ -231,6 +237,10 @@ void context_loop(int sock)
        int desired_session = 0;
        int got_cookie = 0;
        struct wcsession *TheSession, *sptr;
+       char enc[SIZ];
+       char encodings[SIZ];
+       int gzip = 0;
+       int i;
 
        /*
         * Find out what it is that the web browser is asking for
@@ -238,12 +248,23 @@ void context_loop(int sock)
        memset(hold, 0, sizeof(hold));
        do {
                if (req_gets(sock, buf, hold) < 0) return;
+
                if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
                        cookie_to_stuff(&buf[15], &desired_session,
                                NULL, NULL, NULL);
                        got_cookie = 1;
                }
 
+               if (!strncasecmp(buf, "Accept-encoding: ", 17)) {
+                       extract_token(encodings, &buf[17], 0, ';');
+                       for (i=0; i<num_tokens(encodings, ','); ++i) {
+                               extract_token(enc, encodings, i, ',');
+                               if (!strcasecmp(enc, "gzip")) {
+                                       gzip = 1;
+                               }
+                       }
+               }
+
                hptr = (struct httprequest *)
                        malloc(sizeof(struct httprequest));
                if (req == NULL)
@@ -334,7 +355,7 @@ void context_loop(int sock)
        pthread_setspecific(MyConKey, (void *)TheSession);
        TheSession->http_sock = sock;
        TheSession->lastreq = time(NULL);                       /* log */
-       session_loop(req);              /* perform the requested transaction */
+       session_loop(req, gzip);        /* perform the requested transaction */
        pthread_mutex_unlock(&TheSession->SessionMutex);        /* unbind */
 
        /* Free the request buffer */
index 47b909a78e60f2b0f4e8f74905443ee0274eafea..46623d1dafbd7630d76ee4b42e553011f4631808 100644 (file)
@@ -768,7 +768,7 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
 /*
  * Entry point for WebCit transaction
  */
-void session_loop(struct httprequest *req)
+void session_loop(struct httprequest *req, int gzip)
 {
        char cmd[SIZ];
        char action[SIZ];
index a7c8363cb5391af325915135b87bdbc46ba84264..a442b725e810e958937c5bf8cb595609f4382583 100644 (file)
@@ -285,7 +285,7 @@ void display_menubar(int);
 void embed_room_banner(char *);
 void smart_goto(char *);
 void worker_entry(void);
-void session_loop(struct httprequest *);
+void session_loop(struct httprequest *, int gzip);
 void fmt_date(char *buf, time_t thetime);
 void httpdate(char *buf, time_t thetime);
 void end_webcit_session(void);
index ef7612272af7fb4d96880fc3f3f5a67cf6a6b9a4..7cc4f3f9674aea93b1913efb630dcb22592d89de 100644 (file)
@@ -35,6 +35,7 @@
 #include <stdarg.h>
 #include <pthread.h>
 #include <signal.h>
+
 #include "webcit.h"
 #include "webserver.h"