* move policy.c into modules/expire/expire_policy.c, since it just controls this.
[citadel.git] / citadel / modules / expire / serv_expire.c
index dd994e3b07296ac1a3c7c6632f8838159ebc5af4..6bdf67068894fb25c67efd1be0d0646081cc6a77 100644 (file)
@@ -6,7 +6,21 @@
  * You might also see this module affectionately referred to as the DAP (the Dreaded Auto-Purger).
  *
  * Copyright (c) 1988-2009 by citadel.org (Art Cancro, Wilifried Goesgens, and others)
- * Brought to you, our happy user community, under the terms of the GNU General Public License v3
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
  *
  * A brief technical discussion:
  *
@@ -61,7 +75,6 @@
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
-#include "room_ops.h"
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
@@ -69,6 +82,7 @@
 #include "control.h"
 #include "serv_network.h"      /* Needed for definition of UseTable */
 #include "threads.h"
+#include "context.h"
 
 #include "ctdl_module.h"
 
@@ -123,7 +137,6 @@ int users_not_purged;
 char *users_corrupt_msg = NULL;
 char *users_zero_msg = NULL;
 struct ctdlroomref *rr = NULL;
-extern struct CitContext *ContextList;
 int force_purge_now = 0;                       /* set to nonzero to force a run right now */
 
 
@@ -246,7 +259,7 @@ void PurgeMessages(void) {
                return;
        }
 
-       ForEachRoom(GatherPurgeMessages, (void *)purgelist );
+       CtdlForEachRoom(GatherPurgeMessages, (void *)purgelist );
        DoPurgeMessages(purgelist);
        fclose(purgelist);
 }
@@ -297,7 +310,7 @@ void DoPurgeRooms(struct ctdlroom *qrbuf, void *data) {
                if (qrbuf->QRflags & QR_NETWORK) return;
                if (qrbuf->QRflags2 & QR2_SYSTEM) return;
                if (!strcasecmp(qrbuf->QRname, SYSCONFIGROOM)) return;
-               if (is_noneditable(qrbuf)) return;
+               if (CtdlIsNonEditable(qrbuf)) return;
 
                /* If we don't know the modification date, be safe and don't purge */
                if (qrbuf->QRmtime <= (time_t)0) return;
@@ -339,7 +352,7 @@ int PurgeRooms(void) {
        ForEachUser(AddValidUser, NULL);
 
        /* Then cycle through the room file */
-       ForEachRoom(DoPurgeRooms, NULL);
+       CtdlForEachRoom(DoPurgeRooms, NULL);
 
        /* Free the valid user list */
        while (ValidUserList != NULL) {
@@ -353,11 +366,11 @@ int PurgeRooms(void) {
        strcpy(transcript, "The following rooms have been auto-purged:\n");
 
        while (RoomPurgeList != NULL) {
-               if (getroom(&qrbuf, RoomPurgeList->name) == 0) {
+               if (CtdlGetRoom(&qrbuf, RoomPurgeList->name) == 0) {
                        transcript=realloc(transcript, strlen(transcript)+SIZ);
                        snprintf(&transcript[strlen(transcript)], SIZ, " %s\n",
                                qrbuf.QRname);
-                       delete_room(&qrbuf);
+                       CtdlDeleteRoom(&qrbuf);
                }
                pptr = RoomPurgeList->next;
                free(RoomPurgeList);
@@ -365,7 +378,7 @@ int PurgeRooms(void) {
                ++num_rooms_purged;
        }
 
-       if (num_rooms_purged > 0) aide_message(transcript, "Room Autopurger Message");
+       if (num_rooms_purged > 0) CtdlAideMessage(transcript, "Room Autopurger Message");
        free(transcript);
 
        CtdlLogPrintf(CTDL_DEBUG, "Purged %d rooms.\n", num_rooms_purged);
@@ -565,19 +578,19 @@ int PurgeUsers(void) {
                }
        }
 
-       if (num_users_purged > 0) aide_message(transcript, "User Purge Message");
+       if (num_users_purged > 0) CtdlAideMessage(transcript, "User Purge Message");
        free(transcript);
 
        if(users_corrupt_msg)
        {
-               aide_message(users_corrupt_msg, "User Corruption Message");
+               CtdlAideMessage(users_corrupt_msg, "User Corruption Message");
                free (users_corrupt_msg);
                users_corrupt_msg = NULL;
        }
        
        if(users_zero_msg)
        {
-               aide_message(users_zero_msg, "User Zero Message");
+               CtdlAideMessage(users_zero_msg, "User Zero Message");
                free (users_zero_msg);
                users_zero_msg = NULL;
        }
@@ -612,7 +625,7 @@ int PurgeVisits(void) {
        int RoomIsValid, UserIsValid;
 
        /* First, load up a table full of valid room/gen combinations */
-       ForEachRoom(AddValidRoom, NULL);
+       CtdlForEachRoom(AddValidRoom, NULL);
 
        /* Then load up a table full of valid user numbers */
        ForEachUser(AddValidUser, NULL);
@@ -806,6 +819,7 @@ int PurgeStaleOpenIDassociations(void) {
        void *Value;
        const char *Key;
        int num_deleted = 0;
+       long usernum = 0L;
 
        keys = NewHash(1, NULL);
        if (!keys) return(0);
@@ -814,9 +828,8 @@ int PurgeStaleOpenIDassociations(void) {
        cdb_rewind(CDB_OPENID);
        while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) {
                if (cdboi->len > sizeof(long)) {
-                       long usernum;
-                       usernum = ((long)*(cdboi->ptr));
-                       if (getuserbynumber(&usbuf, usernum) != 0) {
+                       memcpy(&usernum, cdboi->ptr, sizeof(long));
+                       if (CtdlGetUserByNumber(&usbuf, usernum) != 0) {
                                deleteme = strdup(cdboi->ptr + sizeof(long)),
                                Put(keys, deleteme, strlen(deleteme), deleteme, generic_free_handler);
                        }
@@ -952,7 +965,7 @@ void do_fsck_msg(long msgnum, void *userdata) {
 
 void do_fsck_room(struct ctdlroom *qrbuf, void *data)
 {
-       getroom(&CC->room, qrbuf->QRname);
+       CtdlGetRoom(&CC->room, qrbuf->QRname);
        CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL, do_fsck_msg, NULL);
 }
 
@@ -978,7 +991,7 @@ void cmd_fsck(char *argbuf) {
 
        cprintf("\nThis could take a while.  Please be patient!\n\n");
        cprintf("Gathering pointers...\n");
-       ForEachRoom(do_fsck_room, NULL);
+       CtdlForEachRoom(do_fsck_room, NULL);
 
        get_control();
        cprintf("Checking message base...\n");
@@ -1039,6 +1052,9 @@ CTDL_MODULE_INIT(expire)
        {
                /* CtdlRegisterProtoHook(cmd_fsck, "FSCK", "Check message ref counts"); */
                CtdlRegisterProtoHook(cmd_tdap, "TDAP", "Manually initiate auto-purger");
+
+               CtdlRegisterProtoHook(cmd_gpex, "GPEX", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_spex, "SPEX", "Autoconverted. TODO: document me.");
        }
        else
                CtdlThreadCreate("Auto Purger", CTDLTHREAD_BIGSTACK, purge_databases, NULL);