* user_ops.c: added PurgeStaleRelationships() to do processing at
authorArt Cancro <ajc@citadel.org>
Fri, 9 Oct 1998 22:35:17 +0000 (22:35 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 9 Oct 1998 22:35:17 +0000 (22:35 +0000)
          session logout time to remove visits for rooms which no longer exist

citadel/ChangeLog
citadel/citserver.c
citadel/user_ops.c
citadel/user_ops.h

index 44995495a2c085e41ec0196f8b0a3a681af61720..8e79c0a066f900d1a4ffd6a491ec974d6d011bed 100644 (file)
@@ -1,3 +1,7 @@
+Fri Oct  9 18:34:06 EDT 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
+       * user_ops.c: added PurgeStaleRelationships() to do processing at
+         session logout time to remove visits for rooms which no longer exist
+
 1998-10-09 Nathan Bryant <bryant@cs.usm.maine.edu>
        * serv_chat.c: fix buffer overrun that was resulting in segv's
 
index 68011009c586b2777cb5266c5cbd7ad5ffa55cc1..72e881e73dff4d3ab44ce124d33662e5c28473b7 100644 (file)
@@ -113,8 +113,11 @@ void cleanup_stuff(void *arg)
        /* Deallocate any message list we might have in memory */
        if (CC->msglist != NULL) free(CC->msglist);
 
+       /* Purge any stale user/room relationships */
+       PurgeStaleRelationships();
+
        /* Now get rid of the session and context */
-       lprintf(7, "cleanup_stuff() is calling RemoveContext(%d)\n", CC->cs_pid);
+       lprintf(7, "cleanup_stuff() calling RemoveContext(%d)\n", CC->cs_pid);
        RemoveContext(CC);
 
        /* While we still have an extra thread with no user attached to it,
index 53ed06818265264c3a38d067dd7aa26784f9a8e2..0222522708bede7f52bcfa66c7a3fe90cbbc612d 100644 (file)
@@ -198,6 +198,60 @@ void CtdlGetRelationship(struct visit *vbuf,
        }
 
 
+void PurgeStaleRelationships(void) {
+
+       struct cdbdata *cdbvisit;
+       struct visit *visits;
+       struct quickroom qrbuf;
+       int num_visits;
+       int a, purge;
+
+       cdbvisit = cdb_fetch(CDB_VISIT, &CC->usersupp.usernum, sizeof(long));
+       if (cdbvisit != NULL) {
+               if ((num_visits = cdbvisit->len / sizeof(struct visit)) == 0) {
+                       cdb_free(cdbvisit);
+                       return;
+                       }
+               visits = (struct visit *)
+                       malloc(num_visits * sizeof(struct visit));
+               memcpy(visits, cdbvisit->ptr,
+                       (num_visits * sizeof(struct visit)));
+               cdb_free(cdbvisit);
+               }
+       else return;
+
+       for (a=0; a<num_visits; ++a) {
+               if (getroom(&qrbuf, visits[a].v_roomname)!=0) {
+                       purge = 1;
+                       }
+               else if (qrbuf.QRgen != visits[a].v_generation) {
+                       purge = 1;
+                       }
+               else {
+                       purge = 0;
+                       }
+               lprintf(9, "U/R REL: <%s> <%ld> <%ld> <%d> %s\n",
+                       visits[a].v_roomname,
+                       visits[a].v_generation,
+                       visits[a].v_lastseen,
+                       visits[a].v_flags,
+                       (purge ? "**purging**" : "") );
+
+               if (purge) {
+                       memcpy(&visits[a], &visits[a+1],
+                               (((num_visits-a)-1) * sizeof(struct visit)) );
+                       --num_visits;
+                       }
+
+               }
+       
+       cdb_store(CDB_VISIT, &CC->usersupp.usernum, sizeof(long),
+                       visits, (num_visits * sizeof(struct visit)));
+       free(visits);
+       }
+
+
+
 void MailboxName(char *buf, struct usersupp *who, char *prefix) {
        sprintf(buf, "%010ld.%s", who->usernum, prefix);
        }
index bb1def76cffc372f0813509cf4e7aa710d935496..9054665d100ae25a829c7090bc19876dbb97af4d 100644 (file)
@@ -41,3 +41,4 @@ void CtdlSetRelationship(struct visit *newvisit,
                         struct usersupp *rel_user,
                         struct quickroom *rel_room);
 void MailboxName(char *buf, struct usersupp *who, char *prefix);
+void PurgeStaleRelationships(void);