EVT_LOGOUT hooks are now called with the thread's current
authorArt Cancro <ajc@citadel.org>
Wed, 19 Mar 2008 19:28:48 +0000 (19:28 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 19 Mar 2008 19:28:48 +0000 (19:28 +0000)
CitContext set to that of the session being logged out, even when
killing a session administratively.  This allows the identity of the
user to be passed along to module hooks.  This fixes the problem in
the Jabber server where buddy 'ghosts' whould remain visible to
clients if the user disconnected without logging off.

citadel/citadel_ipc.c
citadel/citserver.c
citadel/user_ops.c
citadel/user_ops.h

index a402ec1295512182d806217ea9e6ee99f5b9b941..9e0c43377e7e6bfa7990523c0ea5ed10b1d46936 100644 (file)
@@ -142,7 +142,7 @@ int CtdlIPCQuit(CtdlIPC *ipc)
 
 
 /*
- * Asks the server to logout.  Should always return 200, even if no user
+ * Asks the server to log out.  Should always return 200, even if no user
  * was logged in.  The user will not be logged in after this!
  */
 int CtdlIPCLogout(CtdlIPC *ipc)
index 6dba619936c800ab85004676a4f547c02d10d46d..2ec71080903b30562e41d753f29d9eeecfac2c4d 100644 (file)
@@ -248,13 +248,10 @@ void RemoveContext (struct CitContext *con)
         *       might make references to "CC" assuming it's the right one.
         */
        become_session(con);
+       logout();
        PerformSessionHooks(EVT_STOP);
        become_session(NULL);
 
-       /* Now handle all of the administrivia. */
-       lprintf(CTDL_DEBUG, "Calling logout(%d)\n", con->cs_pid);
-       logout(con);
-
        lprintf(CTDL_NOTICE, "[%3d] Session ended.\n", con->cs_pid);
 
        /* If the client is still connected, blow 'em away. */
@@ -1085,7 +1082,7 @@ void do_command_loop(void) {
        }
 
        else if (!strncasecmp(cmdbuf,"LOUT",4)) {
-               if (CC->logged_in) logout(CC);
+               if (CC->logged_in) logout();
                cprintf("%d logged out.\n", CIT_OK);
        }
 
index 8b2b9d19a0980beb8dabdabd548ed4a696ceaabd..b638ccc209cfa2667d2789325af39e24adbbf56e 100644 (file)
@@ -619,50 +619,51 @@ void logged_in_response(void)
 /* 
  * misc things to be taken care of when a user is logged out
  */
-void logout(struct CitContext *who)
+void logout(void)
 {
-       /*
-        * Clear out some session data.  Most likely, the CitContext for this
-        * session is about to get nuked when the session disconnects, but
-        * since it's possible to log in again without reconnecting, we cannot
-        * make that assumption.
-        */
-       strcpy(who->fake_username, "");
-       strcpy(who->fake_hostname, "");
-       strcpy(who->fake_roomname, "");
-       who->logged_in = 0;
-
+       struct CitContext *CCC = CC;    /* CachedCitContext - performance boost */
        /*
         * If there is a download in progress, abort it.
         */
-       if (who->download_fp != NULL) {
-               fclose(who->download_fp);
-               who->download_fp = NULL;
+       if (CCC->download_fp != NULL) {
+               fclose(CCC->download_fp);
+               CCC->download_fp = NULL;
        }
 
        /*
         * If there is an upload in progress, abort it.
         */
-       if (who->upload_fp != NULL) {
-               abort_upl(who);
+       if (CCC->upload_fp != NULL) {
+               abort_upl(CCC);
        }
 
        /*
         * If we were talking to a network node, we're not anymore...
         */
-       if (!IsEmptyStr(who->net_node)) {
-               network_talking_to(who->net_node, NTT_REMOVE);
+       if (!IsEmptyStr(CCC->net_node)) {
+               network_talking_to(CCC->net_node, NTT_REMOVE);
        }
 
-       /* Do modular stuff... */
+       /* Run any hooks registered by modules... */
        PerformSessionHooks(EVT_LOGOUT);
        
+       /*
+        * Clear out some session data.  Most likely, the CitContext for this
+        * session is about to get nuked when the session disconnects, but
+        * since it's possible to log in again without reconnecting, we cannot
+        * make that assumption.
+        */
+       strcpy(CCC->fake_username, "");
+       strcpy(CCC->fake_hostname, "");
+       strcpy(CCC->fake_roomname, "");
+       CCC->logged_in = 0;
+
        /* Check to see if the user was deleted whilst logged in and purge them if necessary */
-       if (who->user.axlevel == 0)
-               purge_user(who->user.fullname);
+       if (CCC->user.axlevel == 0)
+               purge_user(CCC->user.fullname);
 
        /* Free any output buffers */
-       if (who->output_buffer != NULL) {
+       if (CCC->output_buffer != NULL) {
                unbuffer_output();
        }
 }
index be1d4716d9f71f12553e558b755b5155fad26462..9aad99642d3f280fcb5f4a41e05913305105e069 100644 (file)
@@ -9,7 +9,7 @@ int is_room_aide (void);
 int getuserbynumber (struct ctdluser *usbuf, long int number);
 void cmd_user (char *cmdbuf);
 void session_startup (void);
-void logout (struct CitContext *who);
+void logout (void);
 void cmd_pass (char *buf);
 int purge_user (char *pname);
 int create_user (char *newusername, int become_user);