]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_expire.c
* Changed the comments at the beginning of each file to a consistent format
[citadel.git] / citadel / serv_expire.c
index e70117a384480af9bf1e410b2b70ff663e3f4263..1918ce958306350ff9cfdc927c508d714c76a550 100644 (file)
@@ -1,9 +1,8 @@
 /*
- * serv_expire.c
+ * $Id$
  *
  * This module handles the expiry of old messages and the purging of old users.
  *
- * $Id$
  */
 
 
@@ -84,12 +83,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 +233,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 +498,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")) {
@@ -531,10 +530,97 @@ 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
+ */
+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("\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));
+               if (cdbmsg != NULL) {
+                       cdb_free(cdbmsg);
+                       cprintf("Message %7ld    ", msgnum);
+
+                       GetSuppMsgInfo(&smi, msgnum);
+                       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");
+
+}
+
+
+
 
+/*****************************************************************************/
 
 char *Dynamic_Module_Init(void)
 {
        CtdlRegisterProtoHook(cmd_expi, "EXPI", "Expire old system objects");
+       CtdlRegisterProtoHook(cmd_fsck, "FSCK", "Check message ref counts");
        return "$Id$";
 }