]> code.citadel.org Git - citadel.git/blobdiff - citadel/user_ops.c
Moved BumpNewMailCounter() into context.c because it manipulates contexts.
[citadel.git] / citadel / user_ops.c
index 7c9ed32b33630c7cd32926a0ef1a37a9ba0e1eab..118ee60618459d4fc56efe2946c11781717e76cf 100644 (file)
@@ -197,25 +197,12 @@ void lputuser(struct ctdluser *usbuf)
  *
  */
 int rename_user(char *oldname, char *newname) {
-       CitContext *cptr;
        int retcode = RENAMEUSER_OK;
        struct ctdluser usbuf;
 
        char oldnamekey[USERNAME_SIZE];
        char newnamekey[USERNAME_SIZE];
 
-       /* We cannot rename a user who is currently logged in */
-/* FIXME: This is very broken!!!!
- * We check that the user is not already logged in because we can't rename them
- * if they are logged in.
- * BUT THEN WE LEAVE A HUGE WINDOW FOR THEM TO LOG IN BEFORE WE LOCK TO RENAME THEM!!!!!
- */
-       for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
-               if (!strcasecmp(cptr->user.fullname, oldname)) {
-                       return(RENAMEUSER_LOGGED_IN);
-               }
-       }
-
        /* Create the database keys... */
        makeuserkey(oldnamekey, oldname);
        makeuserkey(newnamekey, newname);
@@ -223,6 +210,12 @@ int rename_user(char *oldname, char *newname) {
        /* Lock up and get going */
        begin_critical_section(S_USERS);
 
+       /* We cannot rename a user who is currently logged in */
+       if (CtdlIsUserLoggedIn(oldname)) {
+               end_critical_section(S_USERS);
+               return RENAMEUSER_LOGGED_IN;
+       }
+
        if (CtdlGetUser(&usbuf, newname) == 0) {
                retcode = RENAMEUSER_ALREADY_EXISTS;
        }
@@ -780,6 +773,12 @@ void logged_in_response(void)
  * misc things to be taken care of when a user is logged out
  */
 void logout(void)
+{
+       CtdlUserLogout();
+}
+
+
+void CtdlUserLogout(void)
 {
        CitContext *CCC = CC;   /* CachedCitContext - performance boost */
        /*
@@ -1028,8 +1027,6 @@ int purge_user(char pname[])
        char filename[64];
        struct ctdluser usbuf;
        char usernamekey[USERNAME_SIZE];
-       CitContext *ccptr;
-       int user_is_logged_in = 0;
 
        makeuserkey(usernamekey, pname);
 
@@ -1045,15 +1042,7 @@ int purge_user(char pname[])
         * set the access level to 0, and let the account get swept up
         * during the next purge.
         */
-       user_is_logged_in = 0;
-       begin_critical_section(S_SESSION_TABLE);
-       for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
-               if (ccptr->user.usernum == usbuf.usernum) {
-                       user_is_logged_in = 1;
-               }
-       }
-       end_critical_section(S_SESSION_TABLE);
-       if (user_is_logged_in == 1) {
+       if (CtdlIsUserLoggedInByNum(usbuf.usernum)) {
                CtdlLogPrintf(CTDL_WARNING, "User <%s> is logged in; not deleting.\n", pname);
                usbuf.axlevel = 0;
                CtdlPutUser(&usbuf);
@@ -1061,6 +1050,16 @@ int purge_user(char pname[])
        }
        CtdlLogPrintf(CTDL_NOTICE, "Deleting user <%s>\n", pname);
 
+/*
+ * FIXME:
+ * This should all be wrapped in a S_USERS mutex.
+ * Without the mutex the user could log in before we get to the next function
+ * That would truly mess things up :-(
+ * I would like to see the S_USERS start before the CtdlIsUserLoggedInByNum() above
+ * and end after the user has been deleted from the database, below.
+ * Question is should we enter the EVT_PURGEUSER whilst S_USERS is active?
+ */
+
        /* Perform any purge functions registered by server extensions */
        PerformUserHooks(&usbuf, EVT_PURGEUSER);
 
@@ -1934,26 +1933,6 @@ void cmd_asup(char *cmdbuf)
 
 
 
-/*
- * Check to see if the user who we just sent mail to is logged in.  If yes,
- * bump the 'new mail' counter for their session.  That enables them to
- * receive a new mail notification without having to hit the database.
- */
-void BumpNewMailCounter(long which_user) {
-       CitContext *ptr;
-
-       begin_critical_section(S_SESSION_TABLE);
-
-       for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
-               if (ptr->user.usernum == which_user) {
-                       ptr->newmail += 1;
-               }
-       }
-
-       end_critical_section(S_SESSION_TABLE);
-}
-
-
 /*
  * Count the number of new mail messages the user has
  */