2 * This is a data store backend for the Citadel server which uses Berkeley DB.
4 * Copyright (c) 1987-2015 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 /*****************************************************************************
17 Tunable configuration parameters for the Berkeley DB back end
18 *****************************************************************************/
20 /* Citadel will checkpoint the db at the end of every session, but only if
21 * the specified number of kilobytes has been written, or if the specified
22 * number of minutes has passed, since the last checkpoint.
24 #define MAX_CHECKPOINT_KBYTES 256
25 #define MAX_CHECKPOINT_MINUTES 15
27 /*****************************************************************************/
36 #elif defined(HAVE_DB4_DB_H)
39 #error Neither <db.h> nor <db4/db.h> was found by configure. Install db4-devel.
43 #if DB_VERSION_MAJOR < 4 || DB_VERSION_MINOR < 1
44 #error Citadel requires Berkeley DB v4.1 or newer. Please upgrade.
48 #include <libcitadel.h>
50 #include "ctdl_module.h"
52 #include "citserver.h"
56 static DB *dbp[MAXCDB]; /* One DB handle for each Citadel database */
57 static DB_ENV *dbenv; /* The DB environment (global) */
60 void cdb_abort(void) {
62 "citserver is stopping in order to prevent data loss. uid=%d gid=%d euid=%d egid=%d",
73 /* Verbose logging callback */
74 void cdb_verbose_log(const DB_ENV *dbenv, const char *msg)
76 if (!IsEmptyStr(msg)) {
77 syslog(LOG_DEBUG, "DB: %s", msg);
83 /* Verbose logging callback */
84 void cdb_verbose_err(const DB_ENV *dbenv, const char *errpfx, const char *msg)
87 syslog(LOG_ALERT, "DB: %s", msg);
93 /* just a little helper function */
94 static void txabort(DB_TXN * tid)
98 ret = tid->abort(tid);
101 syslog(LOG_EMERG, "bdb(): txn_abort: %s", db_strerror(ret));
106 /* this one is even more helpful than the last. */
107 static void txcommit(DB_TXN * tid)
111 ret = tid->commit(tid, 0);
114 syslog(LOG_EMERG, "bdb(): txn_commit: %s", db_strerror(ret));
119 /* are you sensing a pattern yet? */
120 static void txbegin(DB_TXN ** tid)
124 ret = dbenv->txn_begin(dbenv, NULL, tid, 0);
127 syslog(LOG_EMERG, "bdb(): txn_begin: %s", db_strerror(ret));
132 static void dbpanic(DB_ENV * env, int errval)
134 syslog(LOG_EMERG, "bdb(): PANIC: %s", db_strerror(errval));
138 static void cclose(DBC * cursor)
142 if ((ret = cursor->c_close(cursor))) {
143 syslog(LOG_EMERG, "bdb(): c_close: %s", db_strerror(ret));
148 static void bailIfCursor(DBC ** cursors, const char *msg)
152 for (i = 0; i < MAXCDB; i++)
153 if (cursors[i] != NULL) {
154 syslog(LOG_EMERG, "bdb(): cursor still in progress on cdb %02x: %s", i, msg);
160 void cdb_check_handles(void)
162 bailIfCursor(TSD->cursors, "in check_handles");
164 if (TSD->tid != NULL) {
165 syslog(LOG_EMERG, "bdb(): transaction still in progress!");
172 * Cull the database logs
174 void cdb_cull_logs(void)
183 /* Get the list of names. */
184 if ((ret = dbenv->log_archive(dbenv, &list, flags)) != 0) {
185 syslog(LOG_ERR, "cdb_cull_logs: %s", db_strerror(ret));
189 /* Print the list of names. */
191 for (file = list; *file != NULL; ++file) {
192 syslog(LOG_DEBUG, "Deleting log: %s", *file);
195 snprintf(errmsg, sizeof(errmsg),
196 " ** ERROR **\n \n \n "
197 "Citadel was unable to delete the "
198 "database log file '%s' because of the "
199 "following error:\n \n %s\n \n"
200 " This log file is no longer in use "
201 "and may be safely deleted.\n",
202 *file, strerror(errno));
203 CtdlAideMessage(errmsg, "Database Warning Message");
212 * Request a checkpoint of the database. Called once per minute by the thread manager.
214 void cdb_checkpoint(void)
218 syslog(LOG_DEBUG, "-- db checkpoint --");
219 ret = dbenv->txn_checkpoint(dbenv, MAX_CHECKPOINT_KBYTES, MAX_CHECKPOINT_MINUTES, 0);
222 syslog(LOG_EMERG, "cdb_checkpoint: txn_checkpoint: %s", db_strerror(ret));
226 /* After a successful checkpoint, we can cull the unused logs */
227 if (CtdlGetConfigInt("c_auto_cull")) {
235 * Open the various databases we'll be using. Any database which
236 * does not exist should be created. Note that we don't need a
237 * critical section here, because there aren't any active threads
238 * manipulating the database yet.
240 void open_databases(void)
246 int dbversion_major, dbversion_minor, dbversion_patch;
248 syslog(LOG_DEBUG, "bdb(): open_databases() starting");
249 syslog(LOG_DEBUG, "Compiled db: %s", DB_VERSION_STRING);
250 syslog(LOG_INFO, " Linked db: %s", db_version(&dbversion_major, &dbversion_minor, &dbversion_patch));
251 syslog(LOG_INFO, "Linked zlib: %s\n", zlibVersion());
254 * Silently try to create the database subdirectory. If it's
255 * already there, no problem.
257 if ((mkdir(ctdl_data_dir, 0700) != 0) && (errno != EEXIST)){
259 "unable to create database directory [%s]: %s",
260 ctdl_data_dir, strerror(errno));
262 if (chmod(ctdl_data_dir, 0700) != 0){
264 "unable to set database directory accessrights [%s]: %s",
265 ctdl_data_dir, strerror(errno));
267 if (chown(ctdl_data_dir, CTDLUID, (-1)) != 0){
269 "unable to set the owner for [%s]: %s",
270 ctdl_data_dir, strerror(errno));
272 syslog(LOG_DEBUG, "bdb(): Setting up DB environment\n");
273 /* db_env_set_func_yield((int (*)(u_long, u_long))sched_yield); */
274 ret = db_env_create(&dbenv, 0);
276 syslog(LOG_EMERG, "bdb(): db_env_create: %s\n", db_strerror(ret));
277 syslog(LOG_EMERG, "exit code %d\n", ret);
280 dbenv->set_errpfx(dbenv, "citserver");
281 dbenv->set_paniccall(dbenv, dbpanic);
282 dbenv->set_errcall(dbenv, cdb_verbose_err);
283 dbenv->set_errpfx(dbenv, "ctdl");
284 #if (DB_VERSION_MAJOR == 4) && (DB_VERSION_MINOR >= 3)
285 dbenv->set_msgcall(dbenv, cdb_verbose_log);
287 dbenv->set_verbose(dbenv, DB_VERB_DEADLOCK, 1);
288 dbenv->set_verbose(dbenv, DB_VERB_RECOVERY, 1);
291 * We want to specify the shared memory buffer pool cachesize,
292 * but everything else is the default.
294 ret = dbenv->set_cachesize(dbenv, 0, 64 * 1024, 0);
296 syslog(LOG_EMERG, "bdb(): set_cachesize: %s\n", db_strerror(ret));
297 dbenv->close(dbenv, 0);
298 syslog(LOG_EMERG, "exit code %d\n", ret);
302 if ((ret = dbenv->set_lk_detect(dbenv, DB_LOCK_DEFAULT))) {
303 syslog(LOG_EMERG, "bdb(): set_lk_detect: %s\n", db_strerror(ret));
304 dbenv->close(dbenv, 0);
305 syslog(LOG_EMERG, "exit code %d\n", ret);
309 flags = DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE | DB_INIT_TXN | DB_INIT_LOCK | DB_THREAD | DB_RECOVER;
310 syslog(LOG_DEBUG, "dbenv->open(dbenv, %s, %d, 0)\n", ctdl_data_dir, flags);
311 ret = dbenv->open(dbenv, ctdl_data_dir, flags, 0);
312 if (ret == DB_RUNRECOVERY) {
313 syslog(LOG_ALERT, "dbenv->open: %s\n", db_strerror(ret));
314 syslog(LOG_ALERT, "Attempting recovery...\n");
316 ret = dbenv->open(dbenv, ctdl_data_dir, flags, 0);
318 if (ret == DB_RUNRECOVERY) {
319 syslog(LOG_ALERT, "dbenv->open: %s\n", db_strerror(ret));
320 syslog(LOG_ALERT, "Attempting catastrophic recovery...\n");
321 flags &= ~DB_RECOVER;
322 flags |= DB_RECOVER_FATAL;
323 ret = dbenv->open(dbenv, ctdl_data_dir, flags, 0);
326 syslog(LOG_EMERG, "dbenv->open: %s\n", db_strerror(ret));
327 dbenv->close(dbenv, 0);
328 syslog(LOG_EMERG, "exit code %d\n", ret);
332 syslog(LOG_INFO, "Starting up DB\n");
334 for (i = 0; i < MAXCDB; ++i) {
336 /* Create a database handle */
337 ret = db_create(&dbp[i], dbenv, 0);
339 syslog(LOG_EMERG, "db_create: %s\n", db_strerror(ret));
340 syslog(LOG_EMERG, "exit code %d\n", ret);
345 /* Arbitrary names for our tables -- we reference them by
346 * number, so we don't have string names for them.
348 snprintf(dbfilename, sizeof dbfilename, "cdb.%02x", i);
350 ret = dbp[i]->open(dbp[i],
355 DB_CREATE | DB_AUTO_COMMIT | DB_THREAD,
359 syslog(LOG_EMERG, "db_open[%02x]: %s\n", i, db_strerror(ret));
361 syslog(LOG_EMERG, "You may need to tune your database; please read http://www.citadel.org/doku.php?id=faq:troubleshooting:out_of_lock_entries for more information.");
363 syslog(LOG_EMERG, "exit code %d\n", ret);
371 /* Make sure we own all the files, because in a few milliseconds
372 * we're going to drop root privs.
374 void cdb_chmod_data(void) {
377 char filename[PATH_MAX];
379 dp = opendir(ctdl_data_dir);
381 while (d = readdir(dp), d != NULL) {
382 if (d->d_name[0] != '.') {
383 snprintf(filename, sizeof filename,
384 "%s/%s", ctdl_data_dir, d->d_name);
385 syslog(LOG_DEBUG, "chmod(%s, 0600) returned %d\n",
386 filename, chmod(filename, 0600)
388 syslog(LOG_DEBUG, "chown(%s, CTDLUID, -1) returned %d\n",
389 filename, chown(filename, CTDLUID, (-1))
396 syslog(LOG_DEBUG, "open_databases() finished\n");
401 * Close all of the db database files we've opened. This can be done
402 * in a loop, since it's just a bunch of closes.
404 void close_databases(void)
409 if ((ret = dbenv->txn_checkpoint(dbenv, 0, 0, 0))) {
411 "txn_checkpoint: %s\n", db_strerror(ret));
414 /* print some statistics... */
416 dbenv->lock_stat_print(dbenv, DB_STAT_ALL);
419 /* close the tables */
420 for (a = 0; a < MAXCDB; ++a) {
421 syslog(LOG_INFO, "Closing database %02x\n", a);
422 ret = dbp[a]->close(dbp[a], 0);
424 syslog(LOG_EMERG, "db_close: %s\n", db_strerror(ret));
429 /* Close the handle. */
430 ret = dbenv->close(dbenv, 0);
432 syslog(LOG_EMERG, "DBENV->close: %s\n", db_strerror(ret));
438 * Decompress a database item if it was compressed on disk
440 void cdb_decompress_if_necessary(struct cdbdata *cdb)
442 static int magic = COMPRESS_MAGIC;
445 (cdb->ptr == NULL) ||
446 (cdb->len < sizeof(magic)) ||
447 (memcmp(cdb->ptr, &magic, sizeof(magic))))
450 /* At this point we know we're looking at a compressed item. */
452 struct CtdlCompressHeader zheader;
453 char *uncompressed_data;
454 char *compressed_data;
455 uLongf destLen, sourceLen;
458 memset(&zheader, 0, sizeof(struct CtdlCompressHeader));
459 cplen = sizeof(struct CtdlCompressHeader);
460 if (sizeof(struct CtdlCompressHeader) > cdb->len)
462 memcpy(&zheader, cdb->ptr, cplen);
464 compressed_data = cdb->ptr;
465 compressed_data += sizeof(struct CtdlCompressHeader);
467 sourceLen = (uLongf) zheader.compressed_len;
468 destLen = (uLongf) zheader.uncompressed_len;
469 uncompressed_data = malloc(zheader.uncompressed_len);
471 if (uncompress((Bytef *) uncompressed_data,
472 (uLongf *) & destLen,
473 (const Bytef *) compressed_data,
474 (uLong) sourceLen) != Z_OK) {
475 syslog(LOG_EMERG, "uncompress() error\n");
480 cdb->len = (size_t) destLen;
481 cdb->ptr = uncompressed_data;
487 * Store a piece of data. Returns 0 if the operation was successful. If a
488 * key already exists it should be overwritten.
490 int cdb_store(int cdb, const void *ckey, int ckeylen, void *cdata, int cdatalen)
497 struct CtdlCompressHeader zheader;
498 char *compressed_data = NULL;
500 size_t buffer_len = 0;
503 memset(&dkey, 0, sizeof(DBT));
504 memset(&ddata, 0, sizeof(DBT));
506 /* no, we don't care for this error. */
509 ddata.size = cdatalen;
512 /* Only compress Visit records. Everything else is uncompressed. */
513 if (cdb == CDB_VISIT) {
515 zheader.magic = COMPRESS_MAGIC;
516 zheader.uncompressed_len = cdatalen;
517 buffer_len = ((cdatalen * 101) / 100) + 100
518 + sizeof(struct CtdlCompressHeader);
519 destLen = (uLongf) buffer_len;
520 compressed_data = malloc(buffer_len);
521 if (compress2((Bytef *) (compressed_data + sizeof(struct CtdlCompressHeader)),
522 &destLen, (Bytef *) cdata, (uLongf) cdatalen, 1) != Z_OK)
524 syslog(LOG_EMERG, "compress2() error\n");
527 zheader.compressed_len = (size_t) destLen;
528 memcpy(compressed_data, &zheader, sizeof(struct CtdlCompressHeader));
529 ddata.size = (size_t) (sizeof(struct CtdlCompressHeader) + zheader.compressed_len);
530 ddata.data = compressed_data;
533 if (TSD->tid != NULL) {
534 ret = dbp[cdb]->put(dbp[cdb], /* db */
535 TSD->tid, /* transaction ID */
540 syslog(LOG_EMERG, "cdb_store(%d): %s", cdb, db_strerror(ret));
544 free(compressed_data);
548 bailIfCursor(TSD->cursors, "attempt to write during r/o cursor");
553 if ((ret = dbp[cdb]->put(dbp[cdb], /* db */
554 tid, /* transaction ID */
558 if (ret == DB_LOCK_DEADLOCK) {
562 syslog(LOG_EMERG, "cdb_store(%d): %s", cdb, db_strerror(ret));
568 free(compressed_data);
578 * Delete a piece of data. Returns 0 if the operation was successful.
580 int cdb_delete(int cdb, void *key, int keylen)
587 memset(&dkey, 0, sizeof dkey);
591 if (TSD->tid != NULL) {
592 ret = dbp[cdb]->del(dbp[cdb], TSD->tid, &dkey, 0);
594 syslog(LOG_EMERG, "cdb_delete(%d): %s\n", cdb, db_strerror(ret));
595 if (ret != DB_NOTFOUND) {
600 bailIfCursor(TSD->cursors, "attempt to delete during r/o cursor");
605 if ((ret = dbp[cdb]->del(dbp[cdb], tid, &dkey, 0))
606 && ret != DB_NOTFOUND) {
607 if (ret == DB_LOCK_DEADLOCK) {
611 syslog(LOG_EMERG, "cdb_delete(%d): %s\n",
612 cdb, db_strerror(ret));
622 static DBC *localcursor(int cdb)
627 if (TSD->cursors[cdb] == NULL)
628 ret = dbp[cdb]->cursor(dbp[cdb], TSD->tid, &curs, 0);
630 ret = TSD->cursors[cdb]->c_dup(TSD->cursors[cdb], &curs, DB_POSITION);
633 syslog(LOG_EMERG, "localcursor: %s\n", db_strerror(ret));
642 * Fetch a piece of data. If not found, returns NULL. Otherwise, it returns
643 * a struct cdbdata which it is the caller's responsibility to free later on
644 * using the cdb_free() routine.
646 struct cdbdata *cdb_fetch(int cdb, const void *key, int keylen)
648 struct cdbdata *tempcdb;
652 memset(&dkey, 0, sizeof(DBT));
654 /* no we don't care about this error. */
657 if (TSD->tid != NULL) {
658 memset(&dret, 0, sizeof(DBT));
659 dret.flags = DB_DBT_MALLOC;
660 ret = dbp[cdb]->get(dbp[cdb], TSD->tid, &dkey, &dret, 0);
665 memset(&dret, 0, sizeof(DBT));
666 dret.flags = DB_DBT_MALLOC;
668 curs = localcursor(cdb);
670 ret = curs->c_get(curs, &dkey, &dret, DB_SET);
673 while (ret == DB_LOCK_DEADLOCK);
677 if ((ret != 0) && (ret != DB_NOTFOUND)) {
678 syslog(LOG_EMERG, "cdb_fetch(%d): %s\n", cdb, db_strerror(ret));
684 tempcdb = (struct cdbdata *) malloc(sizeof(struct cdbdata));
686 if (tempcdb == NULL) {
687 syslog(LOG_EMERG, "cdb_fetch: Cannot allocate memory for tempcdb\n");
689 return NULL; /* make it easier for static analysis... */
693 tempcdb->len = dret.size;
694 tempcdb->ptr = dret.data;
695 cdb_decompress_if_necessary(tempcdb);
702 * Free a cdbdata item.
704 * Note that we only free the 'ptr' portion if it is not NULL. This allows
705 * other code to assume ownership of that memory simply by storing the
706 * pointer elsewhere and then setting 'ptr' to NULL. cdb_free() will then
709 void cdb_free(struct cdbdata *cdb)
717 void cdb_close_cursor(int cdb)
719 if (TSD->cursors[cdb] != NULL) {
720 cclose(TSD->cursors[cdb]);
723 TSD->cursors[cdb] = NULL;
727 * Prepare for a sequential search of an entire database.
728 * (There is guaranteed to be no more than one traversal in
729 * progress per thread at any given time.)
731 void cdb_rewind(int cdb)
735 if (TSD->cursors[cdb] != NULL) {
737 "cdb_rewind: must close cursor on database %d before reopening.\n", cdb);
739 /* cclose(TSD->cursors[cdb]); */
743 * Now initialize the cursor
745 ret = dbp[cdb]->cursor(dbp[cdb], TSD->tid, &TSD->cursors[cdb], 0);
747 syslog(LOG_EMERG, "cdb_rewind: db_cursor: %s\n", db_strerror(ret));
754 * Fetch the next item in a sequential search. Returns a pointer to a
755 * cdbdata structure, or NULL if we've hit the end.
757 struct cdbdata *cdb_next_item(int cdb)
760 struct cdbdata *cdbret;
763 /* Initialize the key/data pair so the flags aren't set. */
764 memset(&key, 0, sizeof(key));
765 memset(&data, 0, sizeof(data));
766 data.flags = DB_DBT_MALLOC;
768 ret = TSD->cursors[cdb]->c_get(TSD->cursors[cdb], &key, &data, DB_NEXT);
771 if (ret != DB_NOTFOUND) {
772 syslog(LOG_EMERG, "cdb_next_item(%d): %s\n", cdb, db_strerror(ret));
775 cdb_close_cursor(cdb);
776 return NULL; /* presumably, end of file */
779 cdbret = (struct cdbdata *) malloc(sizeof(struct cdbdata));
780 cdbret->len = data.size;
781 cdbret->ptr = data.data;
782 cdb_decompress_if_necessary(cdbret);
790 * Transaction-based stuff. I'm writing this as I bake cookies...
793 void cdb_begin_transaction(void)
796 bailIfCursor(TSD->cursors, "can't begin transaction during r/o cursor");
798 if (TSD->tid != NULL) {
799 syslog(LOG_EMERG, "cdb_begin_transaction: ERROR: nested transaction\n");
806 void cdb_end_transaction(void)
810 for (i = 0; i < MAXCDB; i++)
811 if (TSD->cursors[i] != NULL) {
813 "cdb_end_transaction: WARNING: cursor %d still open at transaction end\n",
815 cclose(TSD->cursors[i]);
816 TSD->cursors[i] = NULL;
819 if (TSD->tid == NULL) {
821 "cdb_end_transaction: ERROR: txcommit(NULL) !!\n");
831 * Truncate (delete every record)
833 void cdb_trunc(int cdb)
839 if (TSD->tid != NULL) {
840 syslog(LOG_EMERG, "cdb_trunc must not be called in a transaction.");
843 bailIfCursor(TSD->cursors, "attempt to write during r/o cursor");
848 if ((ret = dbp[cdb]->truncate(dbp[cdb], /* db */
849 NULL, /* transaction ID */
850 &count, /* #rows deleted */
852 if (ret == DB_LOCK_DEADLOCK) {
856 syslog(LOG_EMERG, "cdb_truncate(%d): %s\n", cdb, db_strerror(ret));
858 syslog(LOG_EMERG, "You may need to tune your database; please read http://www.citadel.org/doku.php?id=faq:troubleshooting:out_of_lock_entries for more information.");
868 int SeentDebugEnabled = 0;
870 #define DBGLOG(LEVEL) if ((LEVEL != LOG_DEBUG) || (SeentDebugEnabled != 0))
871 #define SEENM_syslog(LEVEL, FORMAT) \
872 DBGLOG(LEVEL) syslog(LEVEL, \
873 "%s[%ld]CC[%ld] SEEN[%s][%d] " FORMAT, \
874 IOSTR, ioid, ccid, Facility, cType)
876 #define SEEN_syslog(LEVEL, FORMAT, ...) \
877 DBGLOG(LEVEL) syslog(LEVEL, \
878 "%s[%ld]CC[%ld] SEEN[%s][%d] " FORMAT, \
879 IOSTR, ioid, ccid, Facility, cType, \
882 time_t CheckIfAlreadySeen(const char *Facility,
890 time_t InDBTimeStamp = 0;
892 struct cdbdata *cdbut;
896 SEEN_syslog(LOG_DEBUG, "Loading [%s]", ChrPtr(guid));
897 cdbut = cdb_fetch(CDB_USETABLE, SKEY(guid));
898 if ((cdbut != NULL) && (cdbut->ptr != NULL)) {
899 memcpy(&ut, cdbut->ptr,
900 ((cdbut->len > sizeof(struct UseTable)) ?
901 sizeof(struct UseTable) : cdbut->len));
902 InDBTimeStamp = now - ut.ut_timestamp;
904 if (InDBTimeStamp < antiexpire)
906 SEEN_syslog(LOG_DEBUG, "Found - Not expired %ld < %ld", InDBTimeStamp, antiexpire);
908 return InDBTimeStamp;
912 SEEN_syslog(LOG_DEBUG, "Found - Expired. %ld >= %ld", InDBTimeStamp, antiexpire);
918 if (cdbut) cdb_free(cdbut);
920 SEENM_syslog(LOG_DEBUG, "not Found");
921 if (cType == eCheckUpdate)
925 if (cType == eCheckExist)
926 return InDBTimeStamp;
929 memcpy(ut.ut_msgid, SKEY(guid));
930 ut.ut_timestamp = now;
932 SEENM_syslog(LOG_DEBUG, "Saving new Timestamp");
933 /* rewrite the record anyway, to update the timestamp */
934 cdb_store(CDB_USETABLE,
936 &ut, sizeof(struct UseTable) );
938 SEENM_syslog(LOG_DEBUG, "Done Saving");
939 return InDBTimeStamp;
943 void cmd_rsen(char *argbuf) {
949 struct cdbdata *cdbut;
951 if (CtdlAccessCheck(ac_aide)) return;
953 TLen = extract_token(Token, argbuf, 1, '|', sizeof Token);
954 if (strncmp(argbuf, "GET", 3) == 0) {
955 cdbut = cdb_fetch(CDB_USETABLE, Token, TLen);
957 memcpy(&ut, cdbut->ptr,
958 ((cdbut->len > sizeof(struct UseTable)) ?
959 sizeof(struct UseTable) : cdbut->len));
961 cprintf("%d %ld\n", CIT_OK, ut.ut_timestamp);
964 cprintf("%d not found\n", ERROR + NOT_HERE);
968 else if (strncmp(argbuf, "SET", 3) == 0) {
969 memcpy(ut.ut_msgid, Token, TLen);
970 extract_token(Time, argbuf, 2, '|', sizeof Time);
971 ut.ut_timestamp = atol(Time);
972 cdb_store(CDB_USETABLE,
974 &ut, sizeof(struct UseTable) );
975 cprintf("%d token updated\n", CIT_OK);
977 else if (strncmp(argbuf, "DEL", 3) == 0) {
978 if (cdb_delete(CDB_USETABLE, Token, TLen))
979 cprintf("%d not found\n", ERROR + NOT_HERE);
981 cprintf("%d deleted.\n", CIT_OK);
985 cprintf("%d Usage: [GET|SET|DEL]|Token|timestamp\n", ERROR);
989 void LogDebugEnableSeenEnable(const int n)
991 SeentDebugEnabled = n;
994 CTDL_MODULE_INIT(database)
998 CtdlRegisterDebugFlagHook(HKEY("SeenDebug"), LogDebugEnableSeenEnable, &SeentDebugEnabled);
999 CtdlRegisterProtoHook(cmd_rsen, "RSEN", "manipulate Aggregators seen database");
1002 /* return our module id for the log */