* *** HUGE CHANGES *** *** WARNING: NOT FULLY FUNCTIONAL ***
[citadel.git] / webcit / context_loop.c
index c5b6d85616e38ec0a147eec84eaf38ae8f1c6f0c..e9ea3772ac210c8bc348c62a564ce6945b1bc2b1 100644 (file)
@@ -102,6 +102,7 @@ BREAKOUT:   pthread_mutex_unlock(&SessionListMutex);
                if (session_to_kill != NULL) {
                        pthread_mutex_lock(&session_to_kill->SessionMutex);
                        close(session_to_kill->serv_sock);
+                       close(session_to_kill->chat_sock);
                        if (session_to_kill->preferences != NULL) {
                                free(session_to_kill->preferences);
                        }
@@ -168,7 +169,7 @@ int req_gets(int sock, char *buf, char *hold)
                a = client_gets(sock, buf);
                if (a<1) return(-1);
        } else {
-               strcpy(buf, hold);
+               safestrncpy(buf, hold, SIZ);
        }
        strcpy(hold, "");
 
@@ -262,7 +263,6 @@ void context_loop(int sock)
        int desired_session = 0;
        int got_cookie = 0;
        struct wcsession *TheSession, *sptr;
-       int outside_frameset_allowed = 0;
 
        /*
         * Find out what it is that the web browser is asking for
@@ -286,11 +286,11 @@ void context_loop(int sock)
                hptr->next = NULL;
                last = hptr;
 
-               strcpy(hptr->line, buf);
+               safestrncpy(hptr->line, buf, sizeof hptr->line);
 
        } while (strlen(buf) > 0);
 
-       strcpy(buf, req->line);
+       safestrncpy(buf, req->line, sizeof buf);
        lprintf(5, "HTTP: %s\n", buf);
 
        /* Check for bogus requests */
@@ -308,12 +308,15 @@ void context_loop(int sock)
 
        /*
         * While we're at it, gracefully handle requests for the
-        * robots.txt file...
+        * robots.txt and favicon.ico files.
         */
        if (!strncasecmp(buf, "/robots.txt", 11)) {
                strcpy(req->line, "GET /static/robots.txt"
                                "?force_close_session=yes HTTP/1.0");
        }
+       else if (!strncasecmp(buf, "/favicon.ico", 12)) {
+               strcpy(req->line, "GET /static/favicon.ico");
+       }
 
        /* These are the URL's which may be executed without a
         * session cookie already set.  If it's not one of these,
@@ -323,29 +326,12 @@ void context_loop(int sock)
        else if ( (strcmp(buf, "/"))
                && (strncasecmp(buf, "/listsub", 8))
                && (strncasecmp(buf, "/freebusy", 9))
+               && (strncasecmp(buf, "/do_logout", 10))
                && (got_cookie == 0)) {
                strcpy(req->line, "GET /static/nocookies.html"
                                "?force_close_session=yes HTTP/1.0");
        }
 
-       /* These are the URL's which may be executed outside of the
-        * main frameset.  If it's not one of these, the page will
-        * need JavaScript added to force the frameset to reload.
-        */
-       if ( (!strcasecmp(buf, "/"))
-          || (!strcasecmp(buf, "/static/mainframeset.html"))
-          || (!strcasecmp(buf, "/static/robots.txt"))
-          || (!strncasecmp(buf, "/do_welcome", 11))
-          || (!strncasecmp(buf, "/page_popup", 11))
-          || (!strncasecmp(buf, "/listsub", 8))
-          || (!strncasecmp(buf, "/freebusy", 9))
-          || (!strncasecmp(buf, "/termquit", 9)) ) {
-               outside_frameset_allowed = 1;
-       }
-       else {
-               outside_frameset_allowed = 0;
-       }
-
        /*
         * See if there's an existing session open with the desired ID
         */
@@ -368,6 +354,8 @@ void context_loop(int sock)
                TheSession = (struct wcsession *)
                        malloc(sizeof(struct wcsession));
                memset(TheSession, 0, sizeof(struct wcsession));
+               TheSession->serv_sock = (-1);
+               TheSession->chat_sock = (-1);
                TheSession->wc_session = GenerateSessionID();
                pthread_mutex_init(&TheSession->SessionMutex, NULL);
 
@@ -389,8 +377,7 @@ void context_loop(int sock)
        pthread_setspecific(MyConKey, (void *)TheSession);
        TheSession->http_sock = sock;
        TheSession->lastreq = time(NULL);                       /* log */
-       TheSession->outside_frameset_allowed = outside_frameset_allowed;
-       session_loop(req);                                      /* do transaction */
+       session_loop(req);                              /* do transaction */
        pthread_mutex_unlock(&TheSession->SessionMutex);        /* unbind */
 
        /* Free the request buffer */
@@ -399,4 +386,9 @@ bail:       while (req != NULL) {
                free(req);
                req = hptr;
        }
+
+       /* Free up any session-local substitution variables which
+        * were set during this transaction
+        */
+       clear_local_substs();
 }