]> code.citadel.org Git - citadel.git/blobdiff - citadel/context.c
Fix warnings all over citserver; handle function replies; remove unused code.
[citadel.git] / citadel / context.c
index 3b7e3ccd75f7010cfa99ec018dec1ff7b3bb4e47..695b2a0a7efde70a47fd31e2cd59bf878832b4aa 100644 (file)
@@ -276,30 +276,31 @@ void terminate_idle_sessions(void)
 {
        CitContext *ccptr;
        time_t now;
-       int session_to_kill;
        int killed = 0;
        int longrunners = 0;
 
        now = time(NULL);
-       session_to_kill = 0;
        begin_critical_section(S_SESSION_TABLE);
        for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
-               if (  (ccptr!=CC)
-               && (config.c_sleeping > 0)
-               && (now - (ccptr->lastcmd) > config.c_sleeping) ) {
+               if (
+                       (ccptr != CC)
+                       && (config.c_sleeping > 0)
+                       && (now - (ccptr->lastcmd) > config.c_sleeping)
+               ) {
                        if (!ccptr->dont_term) {
                                ccptr->kill_me = KILLME_IDLE;
                                ++killed;
                        }
-                       else 
-                               longrunners ++;
+                       else {
+                               ++longrunners;
+                       }
                }
        }
        end_critical_section(S_SESSION_TABLE);
        if (killed > 0)
-               syslog(LOG_INFO, "Terminated %d idle sessions\n", killed);
+               syslog(LOG_INFO, "Terminated %d idle sessions", killed);
        if (longrunners > 0)
-               syslog(LOG_INFO, "Didn't terminate %d protected idle sessions;\n", killed);
+               syslog(LOG_INFO, "Didn't terminate %d protected idle sessions", longrunners);
 }
 
 
@@ -335,15 +336,16 @@ void terminate_all_sessions(void)
 void RemoveContext (CitContext *con)
 {
        const char *c;
-       if (con==NULL) {
-               syslog(LOG_ERR, "WARNING: RemoveContext() called with NULL!\n");
+       if (con == NULL) {
+               syslog(LOG_ERR, "WARNING: RemoveContext() called with NULL!");
                return;
        }
        c = con->ServiceName;
-       if (c == NULL)
+       if (c == NULL) {
                c = "WTF?";
-       syslog(LOG_DEBUG, "RemoveContext(%s) session %d\n", c, con->cs_pid);
-       cit_backtrace ();
+       }
+       syslog(LOG_DEBUG, "RemoveContext(%s) session %d", c, con->cs_pid);
+       cit_backtrace();
 
        /* Run any cleanup routines registered by loadable modules.
         * Note: We have to "become_session()" because the cleanup functions
@@ -352,12 +354,20 @@ void RemoveContext (CitContext *con)
        become_session(con);
        CtdlUserLogout();
        PerformSessionHooks(EVT_STOP);
+       client_close();                         /* If the client is still connected, blow 'em away. */
        become_session(NULL);
 
-       syslog(LOG_NOTICE, "[%3d] Session ended.\n", con->cs_pid);
+       syslog(LOG_NOTICE, "[%3d] Session ended.", con->cs_pid);
 
-       /* If the client is still connected, blow 'em away. */
-       client_close();
+       /* 
+        * If the client is still connected, blow 'em away. 
+        * if the socket is 0 or -1, its already gone or was never there.
+        */
+       if (con->client_socket > 0)
+       {
+               syslog(LOG_NOTICE, "Closing socket %d", con->client_socket);
+               close(con->client_socket);
+       }
 
        /* If using AUTHMODE_LDAP, free the DN */
        if (con->ldap_dn) {
@@ -371,7 +381,7 @@ void RemoveContext (CitContext *con)
                free(con->cached_msglist);
        }
 
-       syslog(LOG_DEBUG, "Done with RemoveContext()\n");
+       syslog(LOG_DEBUG, "Done with RemoveContext()");
 }
 
 
@@ -450,52 +460,6 @@ CitContext *CtdlGetContextArray(int *count)
 }
 
 
-
-/*
- * This function fills in a context and its user field correctly
- * Then creates/loads that user
- */
-void CtdlFillSystemContext(CitContext *context, char *name)
-{
-       char sysname[SIZ];
-       long len;
-
-       memset(context, 0, sizeof(CitContext));
-       context->internal_pgm = 1;
-       context->cs_pid = 0;
-       strcpy (sysname, "SYS_");
-       strcat (sysname, name);
-       len = cutuserkey(sysname);
-       memcpy(context->curr_user, sysname, len + 1);
-       context->client_socket = (-1);
-
-       /* internal_create_user has the side effect of loading the user regardless of wether they
-        * already existed or needed to be created
-        */
-       internal_create_user (sysname, len, &(context->user), -1) ;
-       
-       /* Check to see if the system user needs upgrading */
-       if (context->user.usernum == 0)
-       {       /* old system user with number 0, upgrade it */
-               context->user.usernum = get_new_user_number();
-               syslog(LOG_DEBUG, "Upgrading system user \"%s\" from user number 0 to user number %ld\n", context->user.fullname, context->user.usernum);
-               /* add user to the database */
-               CtdlPutUser(&(context->user));
-               cdb_store(CDB_USERSBYNUMBER, &(context->user.usernum), sizeof(long), context->user.fullname, strlen(context->user.fullname)+1);
-       }
-}
-
-/*
- * flush it again...
- */
-void CtdlClearSystemContext(void)
-{
-       CitContext *CCC = MyContext();
-
-       memset(CCC, 0, sizeof(CitContext));
-       pthread_setspecific(MyConKey, NULL);
-}
-
 /*
  * Cleanup any contexts that are left lying around
  */