room expires
authorArt Cancro <ajc@citadel.org>
Sat, 21 Nov 1998 02:52:01 +0000 (02:52 +0000)
committerArt Cancro <ajc@citadel.org>
Sat, 21 Nov 1998 02:52:01 +0000 (02:52 +0000)
citadel/citadel.h
citadel/citserver.c
citadel/control.c
citadel/database.c
citadel/routines2.c
citadel/serv_expire.c
citadel/techdoc/session.txt

index f18162ef1849ab9441ec7cae8aa633cb91bebf86..ef8cf236f3883affe88e2d56f298000250793036 100644 (file)
@@ -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
index 885c8a15acec1b9bdb71c3c2b3c01f27d659c2dc..3bbcf1a3a33216be23166535c38934f642b25f18 100644 (file)
@@ -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) {
index f902bb169f9be782775d31f39cc8bb9cfbb90d70..79a155526d0115642c7c44deaf46ff558050e729 100644 (file)
@@ -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;
                    }
index 98da2e38c536189c9b6a09710632e11d2f890e55..aea8961b3bffc5bd0bce7159e3b601b51704030c 100644 (file)
@@ -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 <stdlib.h>
 #include <unistd.h>
index 4724ca79d4bf172de25c0a9d389fc23ee0ac1cda..08bc6da18a6bf71057cec59ca5f72ee79532b61e 100644 (file)
@@ -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 {
index 3a9d1e9d8a4521b29aef78078cf60c457e215d81..1083e0e25ea5db4116d5b9d6e9c2d12d3e967d88 100644 (file)
@@ -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")) {
index e858e6f3b36ae74e015b5cdccf763cfd4999a026..0dfdb51f8bac82fa8f25852ebcc9be519dca6226 100644 (file)
@@ -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