X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fdatabase.c;h=dbcccf5b16b1a51ce3b7c17136d08f3f849022f7;hb=30a4090b04dff1084df3789efe78afd1e2bf6d90;hp=e2654b6e65fb010219e41d8807a1df2842579774;hpb=b67d55104f43ee422e5f0ad1108bf6ba8f39bdd4;p=citadel.git diff --git a/citadel/database.c b/citadel/database.c index e2654b6e6..dbcccf5b1 100644 --- a/citadel/database.c +++ b/citadel/database.c @@ -27,16 +27,8 @@ /*****************************************************************************/ #include "sysdep.h" -#include -#include #include -#include -#include -#include -#include -#include #include -#include #include #ifdef HAVE_DB_H @@ -54,17 +46,10 @@ #include -#include "citadel.h" -#include "server.h" -#include "citserver.h" -#include "database.h" -#include "msgbase.h" -#include "sysdep_decls.h" -#include "threads.h" -#include "config.h" -#include "control.h" #include "ctdl_module.h" +#include "control.h" +#include "citserver.h" static DB *dbp[MAXCDB]; /* One DB handle for each Citadel database */ @@ -97,8 +82,10 @@ void cdb_verbose_log(const DB_ENV *dbenv, const char *msg) /* Verbose logging callback */ void cdb_verbose_err(const DB_ENV *dbenv, const char *errpfx, const char *msg) { + int *FOO = NULL; syslog(LOG_ALERT, "DB: %s", msg); cit_backtrace(); + *FOO = 1; } @@ -183,7 +170,7 @@ void cdb_check_handles(void) /* * Cull the database logs */ -static void cdb_cull_logs(void) +void cdb_cull_logs(void) { u_int32_t flags; int ret; @@ -219,15 +206,6 @@ static void cdb_cull_logs(void) } } -/* - * Manually initiate log file cull. - */ -void cmd_cull(char *argbuf) { - if (CtdlAccessCheck(ac_internal)) return; - cdb_cull_logs(); - cprintf("%d Database log file cull completed.\n", CIT_OK); -} - /* * Request a checkpoint of the database. Called once per minute by the thread manager. @@ -435,7 +413,6 @@ void cdb_chmod_data(void) { } syslog(LOG_DEBUG, "open_databases() finished\n"); - CtdlRegisterProtoHook(cmd_cull, "CULL", "Cull database logs"); } @@ -906,3 +883,141 @@ void cdb_trunc(int cdb) } } } + +int SeentDebugEnabled = 0; + +#define DBGLOG(LEVEL) if ((LEVEL != LOG_DEBUG) || (SeentDebugEnabled != 0)) +#define SEENM_syslog(LEVEL, FORMAT) \ + DBGLOG(LEVEL) syslog(LEVEL, \ + "%s[%ld]CC[%ld] SEEN[%s][%d] " FORMAT, \ + IOSTR, ioid, ccid, Facility, cType) + +#define SEEN_syslog(LEVEL, FORMAT, ...) \ + DBGLOG(LEVEL) syslog(LEVEL, \ + "%s[%ld]CC[%ld] SEEN[%s][%d] " FORMAT, \ + IOSTR, ioid, ccid, Facility, cType, \ + __VA_ARGS__) + +time_t CheckIfAlreadySeen(const char *Facility, + StrBuf *guid, + time_t now, + time_t antiexpire, + eCheckType cType, + long ccid, + long ioid) +{ + time_t InDBTimeStamp = 0; + struct UseTable ut; + struct cdbdata *cdbut; + + if (cType != eWrite) + { + SEEN_syslog(LOG_DEBUG, "Loading [%s]", ChrPtr(guid)); + cdbut = cdb_fetch(CDB_USETABLE, SKEY(guid)); + if ((cdbut != NULL) && (cdbut->ptr != NULL)) { + memcpy(&ut, cdbut->ptr, + ((cdbut->len > sizeof(struct UseTable)) ? + sizeof(struct UseTable) : cdbut->len)); + InDBTimeStamp = now - ut.ut_timestamp; + + if (InDBTimeStamp < antiexpire) + { + SEEN_syslog(LOG_DEBUG, "Found - Not expired %ld < %ld", InDBTimeStamp, antiexpire); + cdb_free(cdbut); + return InDBTimeStamp; + } + else + { + SEEN_syslog(LOG_DEBUG, "Found - Expired. %ld >= %ld", InDBTimeStamp, antiexpire); + cdb_free(cdbut); + } + } + else + { + if (cdbut) cdb_free(cdbut); + + SEENM_syslog(LOG_DEBUG, "not Found"); + if (cType == eCheckUpdate) + return 0; + } + + if (cType == eCheckExist) + return InDBTimeStamp; + } + + memcpy(ut.ut_msgid, SKEY(guid)); + ut.ut_timestamp = now; + + SEENM_syslog(LOG_DEBUG, "Saving new Timestamp"); + /* rewrite the record anyway, to update the timestamp */ + cdb_store(CDB_USETABLE, + SKEY(guid), + &ut, sizeof(struct UseTable) ); + + SEENM_syslog(LOG_DEBUG, "Done Saving"); + return InDBTimeStamp; +} + + +void cmd_rsen(char *argbuf) { + char Token[SIZ]; + long TLen; + char Time[SIZ]; + + struct UseTable ut; + struct cdbdata *cdbut; + + if (CtdlAccessCheck(ac_aide)) return; + + TLen = extract_token(Token, argbuf, 1, '|', sizeof Token); + if (strncmp(argbuf, "GET", 3) == 0) { + cdbut = cdb_fetch(CDB_USETABLE, Token, TLen); + if (cdbut != NULL) { + memcpy(&ut, cdbut->ptr, + ((cdbut->len > sizeof(struct UseTable)) ? + sizeof(struct UseTable) : cdbut->len)); + + cprintf("%d %ld\n", CIT_OK, ut.ut_timestamp); + } + else { + cprintf("%d not found\n", ERROR + NOT_HERE); + } + + } + else if (strncmp(argbuf, "SET", 3) == 0) { + memcpy(ut.ut_msgid, Token, TLen); + extract_token(Time, argbuf, 2, '|', sizeof Time); + ut.ut_timestamp = atol(Time); + cdb_store(CDB_USETABLE, + Token, TLen, + &ut, sizeof(struct UseTable) ); + cprintf("%d token updated\n", CIT_OK); + } + else if (strncmp(argbuf, "DEL", 3) == 0) { + if (cdb_delete(CDB_USETABLE, Token, TLen)) + cprintf("%d not found\n", ERROR + NOT_HERE); + else + cprintf("%d deleted.\n", CIT_OK); + + } + else { + cprintf("%d Usage: [GET|SET|DEL]|Token|timestamp\n", ERROR); + } + +} +void LogDebugEnableSeenEnable(const int n) +{ + SeentDebugEnabled = n; +} + +CTDL_MODULE_INIT(database) +{ + if (!threading) + { + CtdlRegisterDebugFlagHook(HKEY("SeenDebug"), LogDebugEnableSeenEnable, &SeentDebugEnabled); + CtdlRegisterProtoHook(cmd_rsen, "RSEN", "manipulate Aggregators seen database"); + } + + /* return our module id for the log */ + return "database"; +}