From 08f832558a0decab92c495dc7c38e432c5cff1bf Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sat, 21 Nov 1998 02:52:01 +0000 Subject: [PATCH] room expires --- citadel/citadel.h | 1 + citadel/citserver.c | 2 +- citadel/control.c | 3 ++ citadel/database.c | 9 ++++ citadel/routines2.c | 5 ++- citadel/serv_expire.c | 87 ++++++++++++++++++++++++++----------- citadel/techdoc/session.txt | 1 + 7 files changed, 80 insertions(+), 28 deletions(-) diff --git a/citadel/citadel.h b/citadel/citadel.h index f18162ef1..ef8cf236f 100644 --- a/citadel/citadel.h +++ b/citadel/citadel.h @@ -72,6 +72,7 @@ struct config { int c_ipgm_secret; /* Internal program authentication */ struct ExpirePolicy c_ep; /* System default msg expire policy */ int c_userpurge; /* System default user purge (days) */ + int c_roompurge; /* System default room purge (days) */ }; #define NODENAME config.c_nodename diff --git a/citadel/citserver.c b/citadel/citserver.c index 885c8a15a..3bbcf1a3a 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -700,7 +700,7 @@ void *context_loop(struct CitContext *con) session_num = session_count(); CC->nologin = 0; - if ((config.c_maxsessions > 0)&&(session_num >= config.c_maxsessions)) + if ((config.c_maxsessions > 0)&&(session_num > config.c_maxsessions)) CC->nologin = 1; if (CC->nologin==1) { diff --git a/citadel/control.c b/citadel/control.c index f902bb169..79a155526 100644 --- a/citadel/control.c +++ b/citadel/control.c @@ -141,6 +141,7 @@ void cmd_conf(char *argbuf) { cprintf("%d\n", config.c_maxsessions); cprintf("%s\n", config.c_net_password); cprintf("%d\n", config.c_userpurge); + cprintf("%d\n", config.c_roompurge); cprintf("000\n"); } @@ -194,6 +195,8 @@ void cmd_conf(char *argbuf) { break; case 16: config.c_userpurge = atoi(buf); break; + case 17: config.c_roompurge = atoi(buf); + break; } ++a; } diff --git a/citadel/database.c b/citadel/database.c index 98da2e38c..aea8961b3 100644 --- a/citadel/database.c +++ b/citadel/database.c @@ -5,6 +5,15 @@ * $Id$ */ +/* + * Note that each call to a GDBM function is wrapped in an S_DATABASE critical + * section. This is done because GDBM is not threadsafe. This is the ONLY + * place in the entire Citadel server where any code enters two different + * classes of critical sections at the same time; this is why the GDBM calls + * are *tightly* wrapped in S_DATABASE. Opening multiple concurrent critical + * sections elsewhere in the code can, and probably will, cause deadlock + * conditions to occur. (Deadlock is bad. Eliminate.) + */ #include #include diff --git a/citadel/routines2.c b/citadel/routines2.c index 4724ca79d..08bc6da18 100644 --- a/citadel/routines2.c +++ b/citadel/routines2.c @@ -575,7 +575,7 @@ void read_bio(void) { */ void do_system_configuration(void) { char buf[256]; - char sc[17][256]; + char sc[18][256]; int expire_mode = 0; int expire_value = 0; int a; @@ -589,7 +589,7 @@ void do_system_configuration(void) { if (buf[0] == '1') { a = 0; while (serv_gets(buf), strcmp(buf, "000")) { - if (a<17) strcpy(&sc[a][0], buf); + if (a<18) strcpy(&sc[a][0], buf); ++a; } } @@ -636,6 +636,7 @@ void do_system_configuration(void) { strprompt("Maximum concurrent sessions", &sc[14][0], 4); strprompt("Server-to-server networking password", &sc[15][0], 19); strprompt("Default user purge time (days)", &sc[16][0], 5); + strprompt("Default room purge time (days)", &sc[17][0], 5); /* Angels and demons dancing in my head... */ do { diff --git a/citadel/serv_expire.c b/citadel/serv_expire.c index 3a9d1e9d8..1083e0e25 100644 --- a/citadel/serv_expire.c +++ b/citadel/serv_expire.c @@ -43,15 +43,13 @@ struct oldvisit { unsigned int v_flags; }; - - - -struct PurgedUser { - struct PurgedUser *next; - char name[26]; +struct PurgeList { + struct PurgeList *next; + char name[ROOMNAMELEN]; /* use the larger of username or roomname */ }; -struct PurgedUser *plist = NULL; +struct PurgeList *UserPurgeList = NULL; +struct PurgeList *RoomPurgeList = NULL; extern struct CitContext *ContextList; @@ -136,15 +134,54 @@ void PurgeMessages(void) { void DoPurgeRooms(struct quickroom *qrbuf) { - lprintf(9, "%30s (%5ld) %s", - qrbuf->QRname, - qrbuf->QRnumber, - asctime(localtime(&qrbuf->QRmtime))); + time_t now, age; + struct PurgeList *pptr; + + /* Any of these attributes render a room non-purgable */ + if (qrbuf->QRflags & QR_PERMANENT) return; + if (qrbuf->QRflags & QR_DIRECTORY) return; + if (qrbuf->QRflags & QR_NETWORK) return; + if (qrbuf->QRflags & QR_MAILBOX) return; + if (is_noneditable(qrbuf)) return; + + /* Otherwise, check the date of last modification */ + time(&now); + age = now - (qrbuf->QRmtime); + lprintf(9, "<%s> is <%ld> seconds old\n", qrbuf->QRname, age); + if ( (qrbuf->QRmtime > 0L) + && (age > (time_t)(config.c_roompurge * 86400L))) { + + pptr = (struct PurgeList *) malloc(sizeof(struct PurgeList)); + pptr->next = RoomPurgeList; + strcpy(pptr->name, qrbuf->QRname); + RoomPurgeList = pptr; + + } } -void PurgeRooms(void) { - ForEachRoom(DoPurgeRooms); +int PurgeRooms(void) { + struct PurgeList *pptr; + int num_rooms_purged = 0; + struct quickroom qrbuf; + + lprintf(5, "PurgeRooms() called\n"); + if (config.c_roompurge > 0) { + ForEachRoom(DoPurgeRooms); + } + + while (RoomPurgeList != NULL) { + if (getroom(&qrbuf, RoomPurgeList->name) == 0) { + delete_room(&qrbuf); + } + pptr = RoomPurgeList->next; + free(RoomPurgeList); + RoomPurgeList = pptr; + ++num_rooms_purged; + } + + lprintf(5, "Purged %d rooms.\n", num_rooms_purged); + return(num_rooms_purged); } @@ -152,7 +189,7 @@ void do_user_purge(struct usersupp *us) { int purge; time_t now; time_t purge_time; - struct PurgedUser *pptr; + struct PurgeList *pptr; /* Set purge time; if the user overrides the system default, use it */ if (us->USuserpurge > 0) { @@ -192,10 +229,10 @@ void do_user_purge(struct usersupp *us) { if (us->timescalled == 0) purge = 1; if (purge == 1) { - pptr = (struct PurgedUser *) malloc(sizeof(struct PurgedUser)); - pptr->next = plist; + pptr = (struct PurgeList *) malloc(sizeof(struct PurgeList)); + pptr->next = UserPurgeList; strcpy(pptr->name, us->fullname); - plist = pptr; + UserPurgeList = pptr; } } @@ -203,7 +240,7 @@ void do_user_purge(struct usersupp *us) { int PurgeUsers(void) { - struct PurgedUser *pptr; + struct PurgeList *pptr; int num_users_purged = 0; lprintf(5, "PurgeUsers() called\n"); @@ -211,11 +248,11 @@ int PurgeUsers(void) { ForEachUser(do_user_purge); } - while (plist != NULL) { - purge_user(plist->name); - pptr = plist->next; - free(plist); - plist = pptr; + while (UserPurgeList != NULL) { + purge_user(UserPurgeList->name); + pptr = UserPurgeList->next; + free(UserPurgeList); + UserPurgeList = pptr; ++num_users_purged; } @@ -275,8 +312,8 @@ void cmd_expi(char *argbuf) { return; } else if (!strcasecmp(cmd, "rooms")) { - PurgeRooms(); - cprintf("%d Finished purging rooms.\n", OK); + retval = PurgeRooms(); + cprintf("%d Purged %d rooms.\n", OK, retval); return; } else if (!strcasecmp(cmd, "visits")) { diff --git a/citadel/techdoc/session.txt b/citadel/techdoc/session.txt index e858e6f3b..0dfdb51f8 100644 --- a/citadel/techdoc/session.txt +++ b/citadel/techdoc/session.txt @@ -1677,6 +1677,7 @@ fails for any reason, ERROR is returned. 15. Number of maximum concurrent sessions allowed on the server 16. Password for server-to-server networking 17. Default purge time (in days) for users + 18. Default purge time (in days) for rooms -- 2.39.2