]> code.citadel.org Git - citadel.git/blobdiff - webcit/context_loop.c
* several memoryleaks
[citadel.git] / webcit / context_loop.c
index b693ff992676dd15632bdc45dcc9209fcfedf549..4fe4a2dda75dddaf8b1874df42f954e47aff8cbd 100644 (file)
@@ -1,20 +1,17 @@
 /*
  * $Id$
- */
-/**
- * \defgroup WebServerII some of the webserver stuff.
+ *
  * This is the other half of the webserver.  It handles the task of hooking
  * up HTTP requests with the sessions they belong to, using HTTP cookies to
  * keep track of things.  If the HTTP request doesn't belong to any currently
  * active session, a new session is started.
- * \ingroup WebcitHttpServer 
  *
  */
-/*@{*/
+
 #include "webcit.h"
 #include "webserver.h"
 
-/** Only one thread may manipulate SessionList at a time... */
+/* Only one thread may manipulate SessionList at a time... */
 pthread_mutex_t SessionListMutex;
 
 struct wcsession *SessionList = NULL; /**< our sessions ????*/
@@ -22,9 +19,8 @@ struct wcsession *SessionList = NULL; /**< our sessions ????*/
 pthread_key_t MyConKey;         /**< TSD key for MySession() */
 
 
-/**
- * \brief free the memory used for viewing atachments
- * \param sess the session object to destroy
+/*
+ * free the memory used for viewing atachments
  */
 void free_attachments(struct wcsession *sess) {
        struct wc_attachment *att;
@@ -37,9 +33,16 @@ void free_attachments(struct wcsession *sess) {
        }
 }
 
-/**
- * \brief what??????
- */
+
+void shutdown_sessions(void)
+{
+       struct wcsession *sptr;
+       
+       for (sptr = SessionList; sptr != NULL; sptr = sptr->next) {
+                       sptr->killthis = 1;
+       }
+}
+
 void do_housekeeping(void)
 {
        struct wcsession *sptr, *ss;
@@ -89,14 +92,21 @@ void do_housekeeping(void)
                pthread_mutex_lock(&sessions_to_kill->SessionMutex);
                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->preferences != NULL) {
+//                     free(sessions_to_kill->preferences);
+//             }
                if (sessions_to_kill->cache_fold != NULL) {
                        free(sessions_to_kill->cache_fold);
                }
                free_attachments(sessions_to_kill);
                free_march_list(sessions_to_kill);
+               DeleteHash(&(sessions_to_kill->hash_prefs));
+               DeleteHash(&(sessions_to_kill->IconBarSetttings));
+               FreeStrBuf(&(sessions_to_kill->UrlFragment1));
+               FreeStrBuf(&(sessions_to_kill->UrlFragment2));
+               FreeStrBuf(&(sessions_to_kill->WBuf));
+               FreeStrBuf(&(sessions_to_kill->HBuf));
+
                pthread_mutex_unlock(&sessions_to_kill->SessionMutex);
                sptr = sessions_to_kill->next;
                free(sessions_to_kill);
@@ -150,14 +160,10 @@ int GenerateSessionID(void)
 }
 
 
-/**
- * \brief Collapse multiple cookies on one line
- * \param sock a socket?
- * \param buf some bunch of chars?
- * \param hold hold what?
- * TODO: get this comment right
+/*
+ * Collapse multiple cookies on one line
  */
-int req_gets(int sock, char *buf, char *hold)
+int req_gets(int sock, char *buf, char *hold, size_t hlen)
 {
        int a, b;
 
@@ -177,7 +183,7 @@ int req_gets(int sock, char *buf, char *hold)
                        if (buf[a] == ';') {
                                // we don't refresh len, because of we 
                                // only exit from here.
-                               sprintf(hold, "Cookie: %s", &buf[a + 1]);
+                               snprintf(hold, hlen, "Cookie: %s", &buf[a + 1]);
                                buf[a] = 0;
                                b = 8;
                                while (isspace(hold[b]))
@@ -191,14 +197,10 @@ int req_gets(int sock, char *buf, char *hold)
        return(0);
 }
 
-/**
- * \brief close some fd for some reason???
- * \param fd the fd to close??????
+/*
  * lingering_close() a`la Apache. see
  * http://www.apache.org/docs/misc/fin_wait_2.html for rationale
- * TODO: get this comment precise.
  */
-
 int lingering_close(int fd)
 {
        char buf[SIZ];
@@ -307,7 +309,7 @@ void context_loop(int sock)
         */
        memset(hold, 0, sizeof(hold));
        do {
-               if (req_gets(sock, buf, hold) < 0) return;
+               if (req_gets(sock, buf, hold, SIZ) < 0) return;
 
                /**
                 * Can we compress?
@@ -475,8 +477,11 @@ void context_loop(int sock)
 
                strcpy(TheSession->httpauth_user, httpauth_user);
                strcpy(TheSession->httpauth_pass, httpauth_pass);
+               TheSession->hash_prefs = NewHash(1,NULL);       /* Get a hash table for the user preferences */
                pthread_mutex_init(&TheSession->SessionMutex, NULL);
                pthread_mutex_lock(&SessionListMutex);
+               TheSession->urlstrings = NULL;
+               TheSession->vars = NULL;
                TheSession->nonce = rand();
                TheSession->next = SessionList;
                SessionList = TheSession;
@@ -484,42 +489,51 @@ void context_loop(int sock)
                session_is_new = 1;
        }
 
-       /**
+       /*
         * A future improvement might be to check the session integrity
         * at this point before continuing.
         */
 
-       /**
+       /*
         * Bind to the session and perform the transaction
         */
-       pthread_mutex_lock(&TheSession->SessionMutex);          /*< bind */
+       pthread_mutex_lock(&TheSession->SessionMutex);          /* bind */
        pthread_setspecific(MyConKey, (void *)TheSession);
+       
+       TheSession->urlstrings = NewHash(1,NULL);
+       TheSession->vars = NewHash(1,NULL);
        TheSession->http_sock = sock;
-       TheSession->lastreq = time(NULL);                       /*< log */
+       TheSession->lastreq = time(NULL);                       /* log */
        TheSession->gzip_ok = gzip_ok;
 #ifdef ENABLE_NLS
        if (session_is_new) {
                httplang_to_locale(accept_language);
        }
-       go_selected_language();                         /*< set locale */
+       go_selected_language();                                 /* set locale */
 #endif
-       session_loop(req);                              /*< do transaction */
+       session_loop(req);                                      /* do transaction */
 #ifdef ENABLE_NLS
-       stop_selected_language();                       /*< unset locale */
+       stop_selected_language();                               /* unset locale */
 #endif
-       pthread_mutex_unlock(&TheSession->SessionMutex);        /*< unbind */
+       DeleteHash(&TheSession->urlstrings);
+       DeleteHash(&TheSession->vars);
+       FreeStrBuf(&TheSession->WBuf);
+       FreeStrBuf(&TheSession->HBuf);
+       
+       
+       pthread_mutex_unlock(&TheSession->SessionMutex);        /* unbind */
 
-       /** Free the request buffer */
+       /* Free the request buffer */
        while (req != NULL) {
                hptr = req->next;
                free(req);
                req = hptr;
        }
 
-       /**
+       /*
         * Free up any session-local substitution variables which
         * were set during this transaction
         */
-       clear_local_substs();
+       
+       
 }
-/*@}*/