From 23f7d6ee03f2f6e1029df6c820587004905b4069 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 9 Oct 1998 22:35:17 +0000 Subject: [PATCH] * user_ops.c: added PurgeStaleRelationships() to do processing at session logout time to remove visits for rooms which no longer exist --- citadel/ChangeLog | 4 ++++ citadel/citserver.c | 5 ++++- citadel/user_ops.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ citadel/user_ops.h | 1 + 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 44995495a..8e79c0a06 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,3 +1,7 @@ +Fri Oct 9 18:34:06 EDT 1998 Art Cancro + * 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 * serv_chat.c: fix buffer overrun that was resulting in segv's diff --git a/citadel/citserver.c b/citadel/citserver.c index 68011009c..72e881e73 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -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, diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 53ed06818..022252270 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -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 <%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); } diff --git a/citadel/user_ops.h b/citadel/user_ops.h index bb1def76c..9054665d1 100644 --- a/citadel/user_ops.h +++ b/citadel/user_ops.h @@ -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); -- 2.30.2