]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_expire.c
* Replaced most of the very repetitive and very redundant access level checks
[citadel.git] / citadel / serv_expire.c
index 3f3cc05aa33f982ebcc29f0668cd89b15df64333..f8f2366e182d96b36a96d42ec14c0159ffc780a6 100644 (file)
@@ -84,12 +84,21 @@ struct ValidUser {
        long vu_usernum;
 };
 
+
+struct roomref {
+       struct roomref *next;
+       long msgnum;
+};
+
+
 struct PurgeList *UserPurgeList = NULL;
 struct PurgeList *RoomPurgeList = NULL;
 struct ValidRoom *ValidRoomList = NULL;
 struct ValidUser *ValidUserList = NULL;
 int messages_purged;
 
+struct roomref *rr = NULL;
+
 extern struct CitContext *ContextList;
 
 void DoPurgeMessages(struct quickroom *qrbuf, void *data) {
@@ -225,6 +234,7 @@ void DoPurgeRooms(struct quickroom *qrbuf, void *data) {
        if (qrbuf->QRflags & QR_PERMANENT) return;
        if (qrbuf->QRflags & QR_DIRECTORY) return;
        if (qrbuf->QRflags & QR_NETWORK) return;
+       if (!strcasecmp(qrbuf->QRname, SYSCONFIGROOM)) return;
        if (is_noneditable(qrbuf)) return;
 
        /* If we don't know the modification date, be safe and don't purge */
@@ -489,17 +499,7 @@ void cmd_expi(char *argbuf) {
        char cmd[256];
        int retval;
 
-
-       if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
-               cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
-               return;
-       }
-
-       if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
-               cprintf("%d Higher access required.\n",
-                       ERROR+HIGHER_ACCESS_REQUIRED);
-               return;
-       }
+       if (CtdlAccessCheck(ac_aide)) return;
 
        extract(cmd, argbuf, 0);
        if (!strcasecmp(cmd, "users")) {
@@ -534,16 +534,47 @@ void cmd_expi(char *argbuf) {
 /*****************************************************************************/
 
 
+void do_fsck_msg(long msgnum) {
+       struct roomref *ptr;
+
+       ptr = (struct roomref *)mallok(sizeof(struct roomref));
+       ptr->next = rr;
+       ptr->msgnum = msgnum;
+       rr = ptr;
+}
+
+void do_fsck_room(struct quickroom *qrbuf, void *data)
+{
+       getroom(&CC->quickroom, qrbuf->QRname);
+       CtdlForEachMessage(MSGS_ALL, 0L, (-127), NULL, NULL, do_fsck_msg);
+}
+
 /*
- * Check message reference counts (FIXME ... not yet finished)
+ * Check message reference counts
+ */
 void cmd_fsck(char *argbuf) {
        long msgnum;
        struct cdbdata *cdbmsg;
        struct SuppMsgInfo smi;
+       struct roomref *ptr;
+       int realcount;
+
+       if (CtdlAccessCheck(ac_aide)) return;
+
+       /* Lame way of checking whether anyone else is doing this now */
+       if (rr != NULL) {
+               cprintf("%d Another FSCK is already running.\n", ERROR);
+               return;
+       }
+
+       cprintf("%d Checking message reference counts\n", LISTING_FOLLOWS);
 
-       cprintf("%d This is not done yet.\n", LISTING_FOLLOWS);
+       cprintf("\nThis could take a while.  Please be patient!\n\n");
+       cprintf("Gathering pointers...\n");
+       ForEachRoom(do_fsck_room, NULL);
 
        get_control();
+       cprintf("Checking message base...\n");
        for (msgnum = 0L; msgnum <= CitControl.MMhighest; ++msgnum) {
 
                cdbmsg = cdb_fetch(CDB_MSGMAIN, &msgnum, sizeof(long));
@@ -552,15 +583,36 @@ void cmd_fsck(char *argbuf) {
                        cprintf("Message %7ld    ", msgnum);
 
                        GetSuppMsgInfo(&smi, msgnum);
-                       cprintf("refcount=%-2d   \n", smi.smi_refcount);
+                       cprintf("refcount=%-2d   ", smi.smi_refcount);
+
+                       realcount = 0;
+                       for (ptr = rr; ptr != NULL; ptr = ptr->next) {
+                               if (ptr->msgnum == msgnum) ++realcount;
+                       }
+                       cprintf("realcount=%-2d\n", realcount);
+
+                       if ( (smi.smi_refcount != realcount)
+                          || (realcount == 0) ) {
+                               smi.smi_refcount = realcount;
+                               PutSuppMsgInfo(&smi);
+                               AdjRefCount(msgnum, 0); /* deletes if needed */
+                       }
+
                }
 
        }
 
+       cprintf("Freeing memory...\n");
+       while (rr != NULL) {
+               ptr = rr->next;
+               phree(rr);
+               rr = ptr;
+       }
+
+       cprintf("Done!\n");
        cprintf("000\n");
 
 }
- */
 
 
 
@@ -570,6 +622,6 @@ void cmd_fsck(char *argbuf) {
 char *Dynamic_Module_Init(void)
 {
        CtdlRegisterProtoHook(cmd_expi, "EXPI", "Expire old system objects");
-/* CtdlRegisterProtoHook(cmd_fsck, "FSCK", "Check message ref counts"); */
+       CtdlRegisterProtoHook(cmd_fsck, "FSCK", "Check message ref counts");
        return "$Id$";
 }