*
* 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-2015 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
* 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
#include "msgbase.h"
#include "user_ops.h"
#include "control.h"
-#include "serv_network.h" /* Needed for definition of UseTable */
#include "threads.h"
#include "context.h"
for (a=0; a<num_msgs; ++a) {
delnum = msglist[a];
- msg = CtdlFetchMessage(delnum, 0); /* dont need body */
+ msg = CtdlFetchMessage(delnum, 0, 1); /* dont need body */
if (msg != NULL) {
- xtime = atol(msg->cm_fields['T']);
- CtdlFreeMessage(msg);
+ xtime = atol(msg->cm_fields[eTimestamp]);
+ CM_Free(msg);
} else {
xtime = 0L;
}
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;
/* 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. */
/* 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;
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;
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;
}
* Purge the use table of old entries.
*
*/
-int PurgeUseTable(void) {
+int PurgeUseTable(StrBuf *ErrMsg) {
int purged = 0;
struct cdbdata *cdbut;
struct UseTable ut;
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
- */
- memcpy(&ut, cdbut->ptr,
- ((cdbut->len > sizeof(struct UseTable)) ?
- sizeof(struct UseTable) : cdbut->len));
- cdb_free(cdbut);
+ /*
+ * 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
+ */
+ if (cdbut->len > sizeof(struct UseTable))
+ memcpy(&ut, cdbut->ptr, sizeof(struct UseTable));
+ else {
+ memset(&ut, 0, sizeof(struct UseTable));
+ memcpy(&ut, cdbut->ptr, cdbut->len);
+ }
+ cdb_free(cdbut);
if ( (time(NULL) - ut.ut_timestamp) > USETABLE_RETAIN ) {
uptr = (struct UPurgeList *) malloc(sizeof(struct UPurgeList));
memcpy(&msgnum, cdbei->ptr, sizeof(long));
- msg = CtdlFetchMessage(msgnum, 0);
+ msg = CtdlFetchMessage(msgnum, 0, 1);
if (msg != NULL) {
- CtdlFreeMessage(msg); /* it still exists, so do nothing */
+ CM_Free(msg); /* it still exists, so do nothing */
}
else {
eptr = (struct EPurgeList *) malloc(sizeof(struct EPurgeList));
*/
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;
}
if (!server_shutting_down)
{
- retval = PurgeUseTable();
+ StrBuf *ErrMsg;
+
+ ErrMsg = NewStrBuf ();
+ retval = PurgeUseTable(ErrMsg);
syslog(LOG_NOTICE, "Purged %d entries from the use table.", retval);
+////TODO: fix errmsg
+ FreeStrBuf(&ErrMsg);
}
if (!server_shutting_down)
CtdlRegisterProtoHook(cmd_tdap, "TDAP", "Manually initiate auto-purger");
CtdlRegisterProtoHook(cmd_gpex, "GPEX", "Get expire policy");
CtdlRegisterProtoHook(cmd_spex, "SPEX", "Set expire policy");
- CtdlRegisterSessionHook(purge_databases, EVT_TIMER);
+ CtdlRegisterSessionHook(purge_databases, EVT_TIMER, PRIO_CLEANUP + 20);
}
- /* return our Subversion id for the Log */
+ /* return our module name for the log */
return "expire";
}