* --pedantic cleanup.
[citadel.git] / webcit / context_loop.c
index c2943f07e221142ce7fb28f89edebf4f3ab777b2..dab22a9dec5ca80f923513db079be354799f8584 100644 (file)
 /* Only one thread may manipulate SessionList at a time... */
 pthread_mutex_t SessionListMutex;
 
-struct wcsession *SessionList = NULL; /**< our sessions ????*/
+wcsession *SessionList = NULL; /**< our sessions ????*/
 
 pthread_key_t MyConKey;         /**< TSD key for MySession() */
 
 
-/*
- * free the memory used for viewing atachments
- */
-void free_attachment(void *vattach) {
-       wc_attachment *att = (wc_attachment*) vattach;
-       FreeStrBuf(&att->content_type);
-       FreeStrBuf(&att->filename);
-       free(att->data);
-       free(att);
-}
 
-
-void DestroySession(struct wcsession **sessions_to_kill)
+void DestroySession(wcsession **sessions_to_kill)
 {
        close((*sessions_to_kill)->serv_sock);
        close((*sessions_to_kill)->chat_sock);
+/*
 //             if ((*sessions_to_kill)->preferences != NULL) {
 //                     free((*sessions_to_kill)->preferences);
 //             }
+*/
        if ((*sessions_to_kill)->cache_fold != NULL) {
                free((*sessions_to_kill)->cache_fold);
        }
@@ -48,6 +39,7 @@ void DestroySession(struct wcsession **sessions_to_kill)
        DeleteHash(&((*sessions_to_kill)->ServCfg));
        FreeStrBuf(&((*sessions_to_kill)->UrlFragment1));
        FreeStrBuf(&((*sessions_to_kill)->UrlFragment2));
+       FreeStrBuf(&((*sessions_to_kill)->UrlFragment3));
        FreeStrBuf(&((*sessions_to_kill)->WBuf));
        FreeStrBuf(&((*sessions_to_kill)->HBuf));
        FreeStrBuf(&((*sessions_to_kill)->CLineBuf));
@@ -57,7 +49,7 @@ void DestroySession(struct wcsession **sessions_to_kill)
 
 void shutdown_sessions(void)
 {
-       struct wcsession *sptr;
+       wcsession *sptr;
        
        for (sptr = SessionList; sptr != NULL; sptr = sptr->next) {
                        sptr->killthis = 1;
@@ -66,8 +58,8 @@ void shutdown_sessions(void)
 
 void do_housekeeping(void)
 {
-       struct wcsession *sptr, *ss;
-       struct wcsession *sessions_to_kill = NULL;
+       wcsession *sptr, *ss;
+       wcsession *sessions_to_kill = NULL;
        int num_sessions = 0;
        static int num_threads = MIN_WORKER_THREADS;
 
@@ -164,45 +156,6 @@ int GenerateSessionID(void)
        return ++seq;
 }
 
-
-/*
- * Collapse multiple cookies on one line
- */
-////int req_gets(int *sock, char *buf, char *hold, size_t hlen)
-////{
-////   int a, b;
-////
-////   if (IsEmptyStr(hold)) {
-////           strcpy(buf, "");
-////           a = client_getln(sock, buf, SIZ);
-////           if (a<1) return(-1);
-////   } else {
-////           safestrncpy(buf, hold, SIZ);
-////   }
-////   strcpy(hold, "");
-////
-////   if (!strncasecmp(buf, "Cookie: ", 8)) {
-////           int len;
-////           len = strlen(buf);
-////           for (a = 0; a < len; ++a)
-////                   if (buf[a] == ';') {
-////                           // we don't refresh len, because of we 
-////                           // only exit from here.
-////                           snprintf(hold, hlen, "Cookie: %s", &buf[a + 1]);
-////                           buf[a] = 0;
-////                           b = 8;
-////                           while (isspace(hold[b]))
-////                                   b++;
-////                           
-////                           memmove(&hold[8], &hold[b], len - b + 1);
-////                           return(0);
-////                   }
-////   }
-////
-////   return(0);
-////}
-
-
 /*
  * Collapse multiple cookies on one line
  */
@@ -261,12 +214,7 @@ int lingering_close(int fd)
 int is_bogus(StrBuf *http_cmd) {
        const char *url;
        int i, max;
-
-       url = ChrPtr(http_cmd);
-       if (IsEmptyStr(url)) return(1);
-       ++url;
-
-       char *bogus_prefixes[] = {
+       const char *bogus_prefixes[] = {
                "/scripts/root.exe",    /**< Worms and trojans and viruses, oh my! */
                "/c/winnt",
                "/MSADC/",
@@ -274,6 +222,11 @@ int is_bogus(StrBuf *http_cmd) {
                "/MSOffice"             /**< Stoopid MSOffice thinks everyone is IIS */
        };
 
+       url = ChrPtr(http_cmd);
+       if (IsEmptyStr(url)) return(1);
+       ++url;
+
+
        max = sizeof(bogus_prefixes) / sizeof(char *);
 
        for (i=0; i<max; ++i) {
@@ -307,7 +260,7 @@ void context_loop(int *sock)
        int desired_session = 0;
        int got_cookie = 0;
        int gzip_ok = 0;
-       struct wcsession *TheSession, *sptr;
+       wcsession *TheSession, *sptr;
        char httpauth_string[1024];
        char httpauth_user[1024];
        char httpauth_pass[1024];
@@ -356,7 +309,7 @@ void context_loop(int *sock)
                    (isspace(*ChrPtr(Line)))) {
                        pch = pchs = ChrPtr(Line);
                        pche = pchs + StrLength(Line);
-                       while (isspace(pch) && (pch < pche))
+                       while (isspace(*pch) && (pch < pche))
                                pch ++;
                        StrBufCutLeft(Line, pch - pchs);
                        StrBufAppendBuf(LastLine, Line, 0);
@@ -365,7 +318,7 @@ void context_loop(int *sock)
                }
 
                StrBufExtract_token(HeaderName, Line, 0, ':');
-       //// TODO: filter bad chars!
+               /*/// TODO: filter bad chars! */
 
                pchs = ChrPtr(Line);
                pch = pchs + StrLength(HeaderName) + 1;
@@ -380,7 +333,7 @@ void context_loop(int *sock)
        } while (LineLen > 0);
        FreeStrBuf(&HeaderName);
 
-////   dbg_PrintHash(HTTPHeaders, nix, NULL);
+/*///  dbg_PrintHash(HTTPHeaders, nix, NULL); */
 
 
        /**
@@ -395,7 +348,9 @@ void context_loop(int *sock)
        }
 
        /**
-        * Browser-based sessions use cookies for session authentication
+        * Browser-based sessions use cookies for session 
+
+authentication
         */
        if (GetHash(HTTPHeaders, HKEY("COOKIE"), &vLine) && 
            (vLine != NULL)) {
@@ -410,14 +365,14 @@ void context_loop(int *sock)
        if (GetHash(HTTPHeaders, HKEY("AUTHORIZATION"), &vLine) && 
            (vLine != NULL)) {
                Line = (StrBuf*)vLine;
-               if (strncasecmp(ChrPtr(Line), "Basic ", 6)) {
+               if (strncasecmp(ChrPtr(Line), "Basic", 5) == 0) {
                        StrBufCutLeft(Line, 6);
                        CtdlDecodeBase64(httpauth_string, ChrPtr(Line), StrLength(Line));
                        extract_token(httpauth_user, httpauth_string, 0, ':', sizeof httpauth_user);
                        extract_token(httpauth_pass, httpauth_string, 1, ':', sizeof httpauth_pass);
                }
                else 
-                       lprintf(1, "Authentication sheme not supported! [%s]\n", ChrPtr(Line));
+                       lprintf(1, "Authentication scheme not supported! [%s]\n", ChrPtr(Line));
        }
 
        if (GetHash(HTTPHeaders, HKEY("IF-MODIFIED-SINCE"), &vLine) && 
@@ -444,7 +399,7 @@ void context_loop(int *sock)
        StrBufCutLeft(ReqLine, StrLength(ReqType) + 1);
        StrBufCutRight(ReqLine, StrLength(HTTPVersion) + 1);
 
-       if ((StrLength(ReqLine) >= 8) &&
+       if ((follow_xff == 1) && (StrLength(ReqLine) >= 8) &&
            (ptr = strstr(ChrPtr(ReqLine), "/webcit/"), /*< Handle "/webcit/" */
             (ptr != NULL))) {
                StrBufCutLeft(ReqLine, 7);
@@ -454,6 +409,7 @@ void context_loop(int *sock)
 #ifdef TECH_PREVIEW
        if ((strncmp(ChrPtr(ReqLine), "/sslg", 5) != 0) &&
            (strncmp(ChrPtr(ReqLine), "/static/", 8) != 0) &&
+           (strncmp(ChrPtr(ReqLine), "/tiny_mce/", 10) != 0) &&
            (strncmp(ChrPtr(ReqLine), "/wholist_section", 16) != 0) &&
            (strstr(ChrPtr(ReqLine), "wholist_section") == NULL)) {
 #endif
@@ -536,9 +492,9 @@ void context_loop(int *sock)
         */
        if (TheSession == NULL) {
                lprintf(3, "Creating a new session\n");
-               TheSession = (struct wcsession *)
-                       malloc(sizeof(struct wcsession));
-               memset(TheSession, 0, sizeof(struct wcsession));
+               TheSession = (wcsession *)
+                       malloc(sizeof(wcsession));
+               memset(TheSession, 0, sizeof(wcsession));
                TheSession->serv_sock = (-1);
                TheSession->chat_sock = (-1);
        
@@ -622,7 +578,7 @@ void context_loop(int *sock)
 
 void tmpl_nonce(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
 {
-       struct wcsession *WCC = WC;
+       wcsession *WCC = WC;
        StrBufAppendPrintf(Target, "%ld",
                           (WCC != NULL)? WCC->nonce:0);                   
 }