/*****************************************************************************/
#include "sysdep.h"
-#include <stdlib.h>
-#include <unistd.h>
#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
#include <dirent.h>
-#include <syslog.h>
#include <zlib.h>
#ifdef HAVE_DB_H
#include <libcitadel.h>
-#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 */
{
if (!IsEmptyStr(msg)) {
syslog(LOG_DEBUG, "DB: %s", msg);
+ cit_backtrace();
}
}
/* 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;
}
static void dbpanic(DB_ENV * env, int errval)
{
syslog(LOG_EMERG, "bdb(): PANIC: %s", db_strerror(errval));
+ cit_backtrace();
}
static void cclose(DBC * cursor)
/*
* Cull the database logs
*/
-static void cdb_cull_logs(void)
+void cdb_cull_logs(void)
{
u_int32_t flags;
int ret;
}
}
-/*
- * 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.
}
syslog(LOG_DEBUG, "open_databases() finished\n");
- CtdlRegisterProtoHook(cmd_cull, "CULL", "Cull database logs");
}
if (tempcdb == NULL) {
syslog(LOG_EMERG, "cdb_fetch: Cannot allocate memory for tempcdb\n");
cdb_abort();
+ return NULL; /* make it easier for static analysis... */
+ }
+ else
+ {
+ tempcdb->len = dret.size;
+ tempcdb->ptr = dret.data;
+ cdb_decompress_if_necessary(tempcdb);
+ return (tempcdb);
}
-
- tempcdb->len = dret.size;
- tempcdb->ptr = dret.data;
- cdb_decompress_if_necessary(tempcdb);
- return (tempcdb);
}
if (TSD->cursors[cdb] != NULL) {
syslog(LOG_EMERG,
- "cdb_rewind: must close cursor on database %d before reopening.\n", cdb);
+ "cdb_rewind: must close cursor on database %d before reopening.\n", cdb);
cdb_abort();
/* cclose(TSD->cursors[cdb]); */
}
}
}
}
+
+int SeentDebugEnabled = 0;
+
+#define DBGLOG(LEVEL) if ((LEVEL != LOG_DEBUG) || (SeentDebugEnabled != 0))
+#define SEENM_syslog(LEVEL, FORMAT) \
+ DBGLOG(LEVEL) syslog(LEVEL, \
+ "IO[%ld]CC[%ld] SEEN[%s][%d] " FORMAT, \
+ ioid, ccid, Facility, cType)
+
+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)
+ {
+ SEENM_syslog(LOG_DEBUG, "Loading");
+ 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 = ut.ut_timestamp;
+
+ if (InDBTimeStamp < antiexpire)
+ {
+ SEENM_syslog(LOG_DEBUG, "Found - Not expired.");
+ cdb_free(cdbut);
+ return InDBTimeStamp;
+ }
+ else
+ {
+ SEENM_syslog(LOG_DEBUG, "Found - Expired.");
+ InDBTimeStamp = ut.ut_timestamp;
+ cdb_free(cdbut);
+ }
+ }
+ else
+ {
+ if (cdbut) cdb_free(cdbut);
+
+ SEENM_syslog(LOG_DEBUG, "not Found");
+ }
+
+ if (cType == eCheckExist)
+ return InDBTimeStamp;
+ }
+
+ memcpy(ut.ut_msgid, SKEY(guid));
+ ut.ut_timestamp = now;
+
+ SEENM_syslog(LOG_DEBUG, "Saving");
+ /* 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 LogDebugEnableSeenEnable(const int n)
+{
+ SeentDebugEnabled = n;
+}
+
+CTDL_MODULE_INIT(database)
+{
+ if (!threading)
+ {
+ CtdlRegisterDebugFlagHook(HKEY("SeenDebug"), LogDebugEnableSeenEnable, &SeentDebugEnabled);
+ }
+
+ /* return our module id for the log */
+ return "database";
+}