X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fexpire%2Fserv_expire.c;h=7fd28e6b4a699217d90d094fc8f8ee6ac9866ee1;hb=dbee11a35d5d217f356279fa400d7f9deab86cb0;hp=583b86dd504019e844aa0ccbe9c5a906b246b976;hpb=4db4fc48793f3680c5defd28ea32c97044a2b569;p=citadel.git diff --git a/citadel/modules/expire/serv_expire.c b/citadel/modules/expire/serv_expire.c index 583b86dd5..7fd28e6b4 100644 --- a/citadel/modules/expire/serv_expire.c +++ b/citadel/modules/expire/serv_expire.c @@ -3,7 +3,7 @@ * * You might also see this module affectionately referred to as the DAP (the Dreaded Auto-Purger). * - * Copyright (c) 1988-2011 by citadel.org (Art Cancro, Wilifried Goesgens, and others) + * Copyright (c) 1988-2017 by citadel.org (Art Cancro, Wilifried Goesgens, and others) * * This program is open source software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as published @@ -15,11 +15,6 @@ * 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: * * Several of the purge operations found in this module operate in two @@ -107,7 +102,6 @@ struct ValidUser { long vu_usernum; }; - struct ctdlroomref { struct ctdlroomref *next; long msgnum; @@ -181,7 +175,6 @@ void GatherPurgeMessages(struct ctdlroom *qrbuf, void *data) { return; } - /* If the room is set to expire by count, do that */ if (epbuf.expire_mode == EXPIRE_NUMMSGS) { if (num_msgs > epbuf.expire_value) { @@ -197,7 +190,7 @@ void GatherPurgeMessages(struct ctdlroom *qrbuf, void *data) { for (a=0; acm_fields[eTimestamp]); CM_Free(msg); @@ -312,11 +305,11 @@ void DoPurgeRooms(struct ctdlroom *qrbuf, void *data) { if (qrbuf->QRmtime <= (time_t)0) return; /* If no room purge time is set, be safe and don't purge */ - if (config.c_roompurge < 0) return; + if (CtdlGetConfigLong("c_roompurge") < 0) return; /* Otherwise, check the date of last modification */ age = time(NULL) - (qrbuf->QRmtime); - purge_secs = (time_t)config.c_roompurge * (time_t)86400; + purge_secs = CtdlGetConfigLong("c_roompurge") * 86400; if (purge_secs <= (time_t)0) return; syslog(LOG_DEBUG, "<%s> is <%ld> seconds old", qrbuf->QRname, (long)age); if (age > purge_secs) do_purge = 1; @@ -332,7 +325,6 @@ void DoPurgeRooms(struct ctdlroom *qrbuf, void *data) { } - int PurgeRooms(void) { struct PurgeList *pptr; int num_rooms_purged = 0; @@ -342,7 +334,6 @@ int PurgeRooms(void) { syslog(LOG_DEBUG, "PurgeRooms() called"); - /* Load up a table full of valid user numbers so we can delete * user-owned rooms for users who no longer exist */ ForEachUser(AddValidUser, NULL); @@ -357,7 +348,6 @@ int PurgeRooms(void) { ValidUserList = vuptr; } - transcript = malloc(SIZ); strcpy(transcript, "The following rooms have been auto-purged:\n"); @@ -404,8 +394,6 @@ void do_uid_user_purge(struct ctdluser *us, void *data) { } - - /* * Back end function to check user accounts for expiration. */ @@ -417,10 +405,10 @@ void do_user_purge(struct ctdluser *us, void *data) { /* Set purge time; if the user overrides the system default, use it */ if (us->USuserpurge > 0) { - purge_time = ((time_t)us->USuserpurge) * 86400L; + purge_time = ((time_t)us->USuserpurge) * 86400; } else { - purge_time = ((time_t)config.c_userpurge) * 86400L; + purge_time = CtdlGetConfigLong("c_userpurge") * 86400; } /* The default rule is to not purge. */ @@ -429,7 +417,7 @@ void do_user_purge(struct ctdluser *us, void *data) { /* If the user hasn't called in two months and expiring of accounts is turned on, his/her account * has expired, so purge the record. */ - if (config.c_userpurge > 0) + if (CtdlGetConfigLong("c_userpurge") > 0) { now = time(NULL); if ((now - us->lastcall) > purge_time) purge = 1; @@ -519,7 +507,6 @@ void do_user_purge(struct ctdluser *us, void *data) { } - int PurgeUsers(void) { struct PurgeList *pptr; int num_users_purged = 0; @@ -528,7 +515,7 @@ int PurgeUsers(void) { syslog(LOG_DEBUG, "PurgeUsers() called"); users_not_purged = 0; - switch(config.c_auth_mode) { + switch(CtdlGetConfigInt("c_auth_mode")) { case AUTHMODE_NATIVE: ForEachUser(do_user_purge, NULL); break; @@ -536,8 +523,7 @@ int PurgeUsers(void) { ForEachUser(do_uid_user_purge, NULL); break; default: - syslog(LOG_DEBUG, "User purge for auth mode %d is not implemented.", - config.c_auth_mode); + syslog(LOG_DEBUG, "User purge for auth mode %d is not implemented.", CtdlGetConfigInt("c_auth_mode")); break; } @@ -690,6 +676,7 @@ int PurgeVisits(void) { return(purged); } + /* * Purge the use table of old entries. * @@ -702,32 +689,25 @@ int PurgeUseTable(StrBuf *ErrMsg) { struct UPurgeList *uptr; /* Phase 1: traverse through the table, discovering old records... */ - if (CheckTDAPVeto(CDB_USETABLE, ErrMsg)) - { - syslog(LOG_DEBUG, "Purge use table: VETO!"); - return 0; - } syslog(LOG_DEBUG, "Purge use table: phase 1"); cdb_rewind(CDB_USETABLE); - while(cdbut = cdb_next_item(CDB_USETABLE), cdbut != NULL) { - - /* - * TODODRW: change this to create a new function time_t cdb_get_timestamp( struct cdbdata *) - * this will release this file from the serv_network.h - * Maybe it could be a macro that extracts and casts the reult - */ + while(cdbut = cdb_next_item(CDB_USETABLE), cdbut != NULL) + { if (cdbut->len > sizeof(struct UseTable)) memcpy(&ut, cdbut->ptr, sizeof(struct UseTable)); - else { + else + { memset(&ut, 0, sizeof(struct UseTable)); memcpy(&ut, cdbut->ptr, cdbut->len); } cdb_free(cdbut); - if ( (time(NULL) - ut.ut_timestamp) > USETABLE_RETAIN ) { + if ( (time(NULL) - ut.ut_timestamp) > USETABLE_RETAIN ) + { uptr = (struct UPurgeList *) malloc(sizeof(struct UPurgeList)); - if (uptr != NULL) { + if (uptr != NULL) + { uptr->next = ul; safestrncpy(uptr->up_key, ut.ut_msgid, sizeof uptr->up_key); ul = uptr; @@ -751,7 +731,6 @@ int PurgeUseTable(StrBuf *ErrMsg) { } - /* * Purge the EUID Index of old records. * @@ -771,7 +750,7 @@ int PurgeEuidIndexTable(void) { memcpy(&msgnum, cdbei->ptr, sizeof(long)); - msg = CtdlFetchMessage(msgnum, 0); + msg = CtdlFetchMessage(msgnum, 0, 1); if (msg != NULL) { CM_Free(msg); /* it still exists, so do nothing */ } @@ -806,7 +785,6 @@ int PurgeEuidIndexTable(void) { } - /* * Purge OpenID assocations for missing users (theoretically this will never delete anything) */ @@ -854,9 +832,6 @@ int PurgeStaleOpenIDassociations(void) { } - - - void purge_databases(void) { int retval; @@ -870,10 +845,8 @@ void purge_databases(void) */ now = time(NULL); localtime_r(&now, &tm); - if ( - ((tm.tm_hour != config.c_purge_hour) || ((now - last_purge) < 43200)) - && (force_purge_now == 0) - ) { + if (((tm.tm_hour != CtdlGetConfigInt("c_purge_hour")) || ((now - last_purge) < 43200)) && (force_purge_now == 0)) + { return; } @@ -932,6 +905,13 @@ void purge_databases(void) syslog(LOG_NOTICE, "Processed %d message reference count adjustments.", retval); } + // Enable this after we've tested it and make it a site-configurable option. + // This will allow the database files to shrink when they can. + // if (!server_shutting_down) + // { + // cdb_compact(); + // } + if (!server_shutting_down) { syslog(LOG_INFO, "Auto-purger: finished."); @@ -954,7 +934,6 @@ void cmd_tdap(char *argbuf) { } - CTDL_MODULE_INIT(expire) { if (!threading)