/*
* This is a data store backend for the Citadel server which uses Berkeley DB.
*
- * Copyright (c) 1987-2019 by the citadel.org team
+ * Copyright (c) 1987-2020 by the citadel.org team
*
* This program is open source software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 3.
static DB_ENV *dbenv; /* The DB environment (global) */
-void cdb_abort(void)
-{
+void cdb_abort(void) {
syslog(LOG_DEBUG, "db: citserver is stopping in order to prevent data loss. uid=%d gid=%d euid=%d egid=%d",
getuid(), getgid(), geteuid(), getegid()
);
/* Verbose logging callback */
-void cdb_verbose_log(const DB_ENV * dbenv, const char *msg)
-{
+void cdb_verbose_log(const DB_ENV * dbenv, const char *msg) {
if (!IsEmptyStr(msg)) {
syslog(LOG_DEBUG, "db: %s", msg);
}
/* Verbose logging callback */
-void cdb_verbose_err(const DB_ENV * dbenv, const char *errpfx, const char *msg)
-{
+void cdb_verbose_err(const DB_ENV * dbenv, const char *errpfx, const char *msg) {
syslog(LOG_ERR, "db: %s", msg);
}
/* wrapper for txn_abort() that logs/aborts on error */
-static void txabort(DB_TXN *tid)
-{
+static void txabort(DB_TXN *tid) {
int ret;
ret = tid->abort(tid);
/* wrapper for txn_commit() that logs/aborts on error */
-static void txcommit(DB_TXN *tid)
-{
+static void txcommit(DB_TXN *tid) {
int ret;
ret = tid->commit(tid, 0);
/* wrapper for txn_begin() that logs/aborts on error */
-static void txbegin(DB_TXN **tid)
-{
+static void txbegin(DB_TXN **tid) {
int ret;
ret = dbenv->txn_begin(dbenv, NULL, tid, 0);
/* panic callback */
-static void dbpanic(DB_ENV * env, int errval)
-{
+static void dbpanic(DB_ENV * env, int errval) {
syslog(LOG_ERR, "db: PANIC: %s", db_strerror(errval));
}
-static void cclose(DBC * cursor)
-{
+static void cclose(DBC * cursor) {
int ret;
if ((ret = cursor->c_close(cursor))) {
}
-static void bailIfCursor(DBC ** cursors, const char *msg)
-{
+static void bailIfCursor(DBC ** cursors, const char *msg) {
int i;
for (i = 0; i < MAXCDB; i++)
}
-void cdb_check_handles(void)
-{
+void cdb_check_handles(void) {
bailIfCursor(TSD->cursors, "in check_handles");
if (TSD->tid != NULL) {
/*
* Request a checkpoint of the database. Called once per minute by the thread manager.
*/
-void cdb_checkpoint(void)
-{
+void cdb_checkpoint(void) {
int ret;
syslog(LOG_DEBUG, "db: -- checkpoint --");
* critical section here, because there aren't any active threads
* manipulating the database yet.
*/
-void open_databases(void)
-{
+void open_databases(void) {
int ret;
int i;
char dbfilename[32];
/*
* Make sure we own all the files, because in a few milliseconds we're going to drop root privs.
*/
-void cdb_chmod_data(void)
-{
+void cdb_chmod_data(void) {
DIR *dp;
struct dirent *d;
char filename[PATH_MAX];
* Close all of the db database files we've opened. This can be done
* in a loop, since it's just a bunch of closes.
*/
-void close_databases(void)
-{
+void close_databases(void) {
int i;
int ret;
/*
* Decompress a database item if it was compressed on disk
*/
-void cdb_decompress_if_necessary(struct cdbdata *cdb)
-{
+void cdb_decompress_if_necessary(struct cdbdata *cdb) {
static int magic = COMPRESS_MAGIC;
if ((cdb == NULL) || (cdb->ptr == NULL) || (cdb->len < sizeof(magic)) || (memcmp(cdb->ptr, &magic, sizeof(magic)))) {
* Store a piece of data. Returns 0 if the operation was successful. If a
* key already exists it should be overwritten.
*/
-int cdb_store(int cdb, const void *ckey, int ckeylen, void *cdata, int cdatalen)
-{
+int cdb_store(int cdb, const void *ckey, int ckeylen, void *cdata, int cdatalen) {
DBT dkey, ddata;
DB_TXN *tid = NULL;
/*
* Delete a piece of data. Returns 0 if the operation was successful.
*/
-int cdb_delete(int cdb, void *key, int keylen)
-{
-
+int cdb_delete(int cdb, void *key, int keylen) {
DBT dkey;
DB_TXN *tid;
int ret;
}
-static DBC *localcursor(int cdb)
-{
+static DBC *localcursor(int cdb) {
int ret;
DBC *curs;
* a struct cdbdata which it is the caller's responsibility to free later on
* using the cdb_free() routine.
*/
-struct cdbdata *cdb_fetch(int cdb, const void *key, int keylen)
-{
+struct cdbdata *cdb_fetch(int cdb, const void *key, int keylen) {
struct cdbdata *tempcdb;
DBT dkey, dret;
int ret;
* pointer elsewhere and then setting 'ptr' to NULL. cdb_free() will then
* avoid freeing it.
*/
-void cdb_free(struct cdbdata *cdb)
-{
+void cdb_free(struct cdbdata *cdb) {
if (cdb->ptr) {
free(cdb->ptr);
}
}
-void cdb_close_cursor(int cdb)
-{
+void cdb_close_cursor(int cdb) {
if (TSD->cursors[cdb] != NULL) {
cclose(TSD->cursors[cdb]);
}
* (There is guaranteed to be no more than one traversal in
* progress per thread at any given time.)
*/
-void cdb_rewind(int cdb)
-{
+void cdb_rewind(int cdb) {
int ret = 0;
if (TSD->cursors[cdb] != NULL) {
* Fetch the next item in a sequential search. Returns a pointer to a
* cdbdata structure, or NULL if we've hit the end.
*/
-struct cdbdata *cdb_next_item(int cdb)
-{
+struct cdbdata *cdb_next_item(int cdb) {
DBT key, data;
struct cdbdata *cdbret;
int ret = 0;
/*
* Transaction-based stuff. I'm writing this as I bake cookies...
*/
-void cdb_begin_transaction(void)
-{
-
+void cdb_begin_transaction(void) {
bailIfCursor(TSD->cursors, "can't begin transaction during r/o cursor");
if (TSD->tid != NULL) {
}
-void cdb_end_transaction(void)
-{
+void cdb_end_transaction(void) {
int i;
for (i = 0; i < MAXCDB; i++)
/*
* Truncate (delete every record)
*/
-void cdb_trunc(int cdb)
-{
+void cdb_trunc(int cdb) {
/* DB_TXN *tid; */
int ret;
u_int32_t count;
/*
* compact (defragment) the database , possibly returning space back to the underlying filesystem
*/
-void cdb_compact(void)
-{
+void cdb_compact(void) {
int ret;
int i;
// Has an item already been seen (is it in the CDB_USETABLE) ?
// Returns 0 if it hasn't, 1 if it has
// In either case, writes the item to the database for next time.
-int CheckIfAlreadySeen(StrBuf *guid)
-{
+int CheckIfAlreadySeen(StrBuf *guid) {
int found = 0;
struct UseTable ut;
struct cdbdata *cdbut;
}
-void cmd_rsen(char *argbuf)
-{
+void cmd_rsen(char *argbuf) {
char Token[SIZ];
long TLen;
char Time[SIZ];
*/
now = time(NULL);
localtime_r(&now, &tm);
- if (((tm.tm_hour != CtdlGetConfigInt("c_purge_hour")) || ((now - last_purge) < 43200)) && (force_purge_now == 0))
- {
- return;
+ if (((tm.tm_hour != CtdlGetConfigInt("c_purge_hour")) || ((now - last_purge) < 43200)) && (force_purge_now == 0)) {
+ return;
}
syslog(LOG_INFO, "Auto-purger: starting.");
- if (!server_shutting_down)
- {
+ if (!server_shutting_down) {
retval = PurgeUsers();
syslog(LOG_NOTICE, "Purged %d users.", retval);
}
- if (!server_shutting_down)
- {
+ if (!server_shutting_down) {
PurgeMessages();
syslog(LOG_NOTICE, "Expired %d messages.", messages_purged);
}
- if (!server_shutting_down)
- {
+ if (!server_shutting_down) {
retval = PurgeRooms();
syslog(LOG_NOTICE, "Expired %d rooms.", retval);
}
- if (!server_shutting_down)
- {
+ if (!server_shutting_down) {
retval = PurgeVisits();
syslog(LOG_NOTICE, "Purged %d visits.", retval);
}
- if (!server_shutting_down)
- {
+ if (!server_shutting_down) {
StrBuf *ErrMsg;
-
- ErrMsg = NewStrBuf ();
+ ErrMsg = NewStrBuf();
retval = PurgeUseTable(ErrMsg);
syslog(LOG_NOTICE, "Purged %d entries from the use table.", retval);
FreeStrBuf(&ErrMsg);
}
- if (!server_shutting_down)
- {
- retval = PurgeEuidIndexTable();
- syslog(LOG_NOTICE, "Purged %d entries from the EUID index.", retval);
+ if (!server_shutting_down) {
+ retval = PurgeEuidIndexTable();
+ syslog(LOG_NOTICE, "Purged %d entries from the EUID index.", retval);
}
- if (!server_shutting_down)
- {
+ if (!server_shutting_down) {
retval = PurgeStaleExtAuthAssociations();
syslog(LOG_NOTICE, "Purged %d stale external auth associations.", retval);
}
- //if (!server_shutting_down)
- //{
+ //if (!server_shutting_down) {
// FIXME this is where we could do a non-interactive delete of zero-refcount messages
//}
- if ( (!server_shutting_down) && (CtdlGetConfigInt("c_shrink_db_files") != 0) )
- {
+ if ( (!server_shutting_down) && (CtdlGetConfigInt("c_shrink_db_files") != 0) ) {
cdb_compact(); // Shrink the DB files on disk
}
- if (!server_shutting_down)
- {
+ if (!server_shutting_down) {
syslog(LOG_INFO, "Auto-purger: finished.");
last_purge = now; // So we don't do it again soon
force_purge_now = 0;