2 * This is a data store backend for the Citadel server which uses Berkeley DB.
4 * Copyright (c) 1987-2016 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 <db5/db.h> was found by configure. Install db5-devel.
42 #if DB_VERSION_MAJOR < 5
43 #error Citadel requires Berkeley DB v5.0 or newer. Please upgrade.
46 #include <libcitadel.h>
48 #include "ctdl_module.h"
50 #include "citserver.h"
53 static DB *dbp[MAXCDB]; /* One DB handle for each Citadel database */
54 static DB_ENV *dbenv; /* The DB environment (global) */
57 void cdb_abort(void) {
59 "citserver is stopping in order to prevent data loss. uid=%d gid=%d euid=%d egid=%d",
70 /* Verbose logging callback */
71 void cdb_verbose_log(const DB_ENV *dbenv, const char *msg)
73 if (!IsEmptyStr(msg)) {
74 syslog(LOG_DEBUG, "DB: %s", msg);
80 /* Verbose logging callback */
81 void cdb_verbose_err(const DB_ENV *dbenv, const char *errpfx, const char *msg)
84 syslog(LOG_ALERT, "DB: %s", msg);
90 /* just a little helper function */
91 static void txabort(DB_TXN * tid)
95 ret = tid->abort(tid);
98 syslog(LOG_EMERG, "bdb(): txn_abort: %s", db_strerror(ret));
103 /* this one is even more helpful than the last. */
104 static void txcommit(DB_TXN * tid)
108 ret = tid->commit(tid, 0);
111 syslog(LOG_EMERG, "bdb(): txn_commit: %s", db_strerror(ret));
116 /* are you sensing a pattern yet? */
117 static void txbegin(DB_TXN ** tid)
121 ret = dbenv->txn_begin(dbenv, NULL, tid, 0);
124 syslog(LOG_EMERG, "bdb(): txn_begin: %s", db_strerror(ret));
129 static void dbpanic(DB_ENV * env, int errval)
131 syslog(LOG_EMERG, "bdb(): PANIC: %s", db_strerror(errval));
135 static void cclose(DBC * cursor)
139 if ((ret = cursor->c_close(cursor))) {
140 syslog(LOG_EMERG, "bdb(): c_close: %s", db_strerror(ret));
145 static void bailIfCursor(DBC ** cursors, const char *msg)
149 for (i = 0; i < MAXCDB; i++)
150 if (cursors[i] != NULL) {
151 syslog(LOG_EMERG, "bdb(): cursor still in progress on cdb %02x: %s", i, msg);
157 void cdb_check_handles(void)
159 bailIfCursor(TSD->cursors, "in check_handles");
161 if (TSD->tid != NULL) {
162 syslog(LOG_EMERG, "bdb(): transaction still in progress!");
169 * Cull the database logs
171 void cdb_cull_logs(void)
180 /* Get the list of names. */
181 if ((ret = dbenv->log_archive(dbenv, &list, flags)) != 0) {
182 syslog(LOG_ERR, "cdb_cull_logs: %s", db_strerror(ret));
186 /* Print the list of names. */
188 for (file = list; *file != NULL; ++file) {
189 syslog(LOG_DEBUG, "Deleting log: %s", *file);
192 snprintf(errmsg, sizeof(errmsg),
193 " ** ERROR **\n \n \n "
194 "Citadel was unable to delete the "
195 "database log file '%s' because of the "
196 "following error:\n \n %s\n \n"
197 " This log file is no longer in use "
198 "and may be safely deleted.\n",
199 *file, strerror(errno));
200 CtdlAideMessage(errmsg, "Database Warning Message");
209 * Request a checkpoint of the database. Called once per minute by the thread manager.
211 void cdb_checkpoint(void)
215 MARKM_syslog(LOG_DEBUG, "-- db checkpoint --");
216 ret = dbenv->txn_checkpoint(dbenv, MAX_CHECKPOINT_KBYTES, MAX_CHECKPOINT_MINUTES, 0);
219 syslog(LOG_EMERG, "cdb_checkpoint: txn_checkpoint: %s", db_strerror(ret));
223 /* After a successful checkpoint, we can cull the unused logs */
224 if (CtdlGetConfigInt("c_auto_cull")) {
232 * Open the various databases we'll be using. Any database which
233 * does not exist should be created. Note that we don't need a
234 * critical section here, because there aren't any active threads
235 * manipulating the database yet.
237 void open_databases(void)
243 int dbversion_major, dbversion_minor, dbversion_patch;
245 syslog(LOG_DEBUG, "bdb(): open_databases() starting");
246 syslog(LOG_DEBUG, "Compiled db: %s", DB_VERSION_STRING);
247 syslog(LOG_INFO, " Linked db: %s", db_version(&dbversion_major, &dbversion_minor, &dbversion_patch));
248 syslog(LOG_INFO, "Linked zlib: %s\n", zlibVersion());
251 * Silently try to create the database subdirectory. If it's
252 * already there, no problem.
254 if ((mkdir(ctdl_data_dir, 0700) != 0) && (errno != EEXIST)){
256 "unable to create database directory [%s]: %s",
257 ctdl_data_dir, strerror(errno));
259 if (chmod(ctdl_data_dir, 0700) != 0){
261 "unable to set database directory accessrights [%s]: %s",
262 ctdl_data_dir, strerror(errno));
264 if (chown(ctdl_data_dir, CTDLUID, (-1)) != 0){
266 "unable to set the owner for [%s]: %s",
267 ctdl_data_dir, strerror(errno));
269 syslog(LOG_DEBUG, "bdb(): Setting up DB environment\n");
270 /* db_env_set_func_yield((int (*)(u_long, u_long))sched_yield); */
271 ret = db_env_create(&dbenv, 0);
273 syslog(LOG_EMERG, "bdb(): db_env_create: %s\n", db_strerror(ret));
274 syslog(LOG_EMERG, "exit code %d\n", ret);
277 dbenv->set_errpfx(dbenv, "citserver");
278 dbenv->set_paniccall(dbenv, dbpanic);
279 dbenv->set_errcall(dbenv, cdb_verbose_err);
280 dbenv->set_errpfx(dbenv, "ctdl");
281 dbenv->set_msgcall(dbenv, cdb_verbose_log);
282 dbenv->set_verbose(dbenv, DB_VERB_DEADLOCK, 1);
283 dbenv->set_verbose(dbenv, DB_VERB_RECOVERY, 1);
286 * We want to specify the shared memory buffer pool cachesize,
287 * but everything else is the default.
289 ret = dbenv->set_cachesize(dbenv, 0, 64 * 1024, 0);
291 syslog(LOG_EMERG, "bdb(): set_cachesize: %s\n", db_strerror(ret));
292 dbenv->close(dbenv, 0);
293 syslog(LOG_EMERG, "exit code %d\n", ret);
297 if ((ret = dbenv->set_lk_detect(dbenv, DB_LOCK_DEFAULT))) {
298 syslog(LOG_EMERG, "bdb(): set_lk_detect: %s\n", db_strerror(ret));
299 dbenv->close(dbenv, 0);
300 syslog(LOG_EMERG, "exit code %d\n", ret);
304 flags = DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE | DB_INIT_TXN | DB_INIT_LOCK | DB_THREAD | DB_RECOVER;
305 syslog(LOG_DEBUG, "dbenv->open(dbenv, %s, %d, 0)\n", ctdl_data_dir, flags);
306 ret = dbenv->open(dbenv, ctdl_data_dir, flags, 0);
307 if (ret == DB_RUNRECOVERY) {
308 syslog(LOG_ALERT, "dbenv->open: %s\n", db_strerror(ret));
309 syslog(LOG_ALERT, "Attempting recovery...\n");
311 ret = dbenv->open(dbenv, ctdl_data_dir, flags, 0);
313 if (ret == DB_RUNRECOVERY) {
314 syslog(LOG_ALERT, "dbenv->open: %s\n", db_strerror(ret));
315 syslog(LOG_ALERT, "Attempting catastrophic recovery...\n");
316 flags &= ~DB_RECOVER;
317 flags |= DB_RECOVER_FATAL;
318 ret = dbenv->open(dbenv, ctdl_data_dir, flags, 0);
321 syslog(LOG_EMERG, "dbenv->open: %s\n", db_strerror(ret));
322 dbenv->close(dbenv, 0);
323 syslog(LOG_EMERG, "exit code %d\n", ret);
327 syslog(LOG_INFO, "Starting up DB\n");
329 for (i = 0; i < MAXCDB; ++i) {
331 /* Create a database handle */
332 ret = db_create(&dbp[i], dbenv, 0);
334 syslog(LOG_EMERG, "db_create: %s\n", db_strerror(ret));
335 syslog(LOG_EMERG, "exit code %d\n", ret);
340 /* Arbitrary names for our tables -- we reference them by
341 * number, so we don't have string names for them.
343 snprintf(dbfilename, sizeof dbfilename, "cdb.%02x", i);
345 ret = dbp[i]->open(dbp[i],
350 DB_CREATE | DB_AUTO_COMMIT | DB_THREAD,
354 syslog(LOG_EMERG, "db_open[%02x]: %s\n", i, db_strerror(ret));
356 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.");
358 syslog(LOG_EMERG, "exit code %d\n", ret);
366 /* Make sure we own all the files, because in a few milliseconds
367 * we're going to drop root privs.
369 void cdb_chmod_data(void) {
372 char filename[PATH_MAX];
374 dp = opendir(ctdl_data_dir);
376 while (d = readdir(dp), d != NULL) {
377 if (d->d_name[0] != '.') {
378 snprintf(filename, sizeof filename,
379 "%s/%s", ctdl_data_dir, d->d_name);
380 syslog(LOG_DEBUG, "chmod(%s, 0600) returned %d\n",
381 filename, chmod(filename, 0600)
383 syslog(LOG_DEBUG, "chown(%s, CTDLUID, -1) returned %d\n",
384 filename, chown(filename, CTDLUID, (-1))
391 syslog(LOG_DEBUG, "open_databases() finished\n");
396 * Close all of the db database files we've opened. This can be done
397 * in a loop, since it's just a bunch of closes.
399 void close_databases(void)
404 if ((ret = dbenv->txn_checkpoint(dbenv, 0, 0, 0))) {
406 "txn_checkpoint: %s\n", db_strerror(ret));
409 /* print some statistics... */
411 dbenv->lock_stat_print(dbenv, DB_STAT_ALL);
414 /* close the tables */
415 for (a = 0; a < MAXCDB; ++a) {
416 syslog(LOG_INFO, "Closing database %02x\n", a);
417 ret = dbp[a]->close(dbp[a], 0);
419 syslog(LOG_EMERG, "db_close: %s\n", db_strerror(ret));
424 /* Close the handle. */
425 ret = dbenv->close(dbenv, 0);
427 syslog(LOG_EMERG, "DBENV->close: %s\n", db_strerror(ret));
433 * Decompress a database item if it was compressed on disk
435 void cdb_decompress_if_necessary(struct cdbdata *cdb)
437 static int magic = COMPRESS_MAGIC;
440 (cdb->ptr == NULL) ||
441 (cdb->len < sizeof(magic)) ||
442 (memcmp(cdb->ptr, &magic, sizeof(magic))))
445 /* At this point we know we're looking at a compressed item. */
447 struct CtdlCompressHeader zheader;
448 char *uncompressed_data;
449 char *compressed_data;
450 uLongf destLen, sourceLen;
453 memset(&zheader, 0, sizeof(struct CtdlCompressHeader));
454 cplen = sizeof(struct CtdlCompressHeader);
455 if (sizeof(struct CtdlCompressHeader) > cdb->len)
457 memcpy(&zheader, cdb->ptr, cplen);
459 compressed_data = cdb->ptr;
460 compressed_data += sizeof(struct CtdlCompressHeader);
462 sourceLen = (uLongf) zheader.compressed_len;
463 destLen = (uLongf) zheader.uncompressed_len;
464 uncompressed_data = malloc(zheader.uncompressed_len);
466 if (uncompress((Bytef *) uncompressed_data,
467 (uLongf *) & destLen,
468 (const Bytef *) compressed_data,
469 (uLong) sourceLen) != Z_OK) {
470 syslog(LOG_EMERG, "uncompress() error\n");
475 cdb->len = (size_t) destLen;
476 cdb->ptr = uncompressed_data;
482 * Store a piece of data. Returns 0 if the operation was successful. If a
483 * key already exists it should be overwritten.
485 int cdb_store(int cdb, const void *ckey, int ckeylen, void *cdata, int cdatalen)
492 struct CtdlCompressHeader zheader;
493 char *compressed_data = NULL;
495 size_t buffer_len = 0;
498 memset(&dkey, 0, sizeof(DBT));
499 memset(&ddata, 0, sizeof(DBT));
501 /* no, we don't care for this error. */
504 ddata.size = cdatalen;
507 /* Only compress Visit records. Everything else is uncompressed. */
508 if (cdb == CDB_VISIT) {
510 zheader.magic = COMPRESS_MAGIC;
511 zheader.uncompressed_len = cdatalen;
512 buffer_len = ((cdatalen * 101) / 100) + 100
513 + sizeof(struct CtdlCompressHeader);
514 destLen = (uLongf) buffer_len;
515 compressed_data = malloc(buffer_len);
516 if (compress2((Bytef *) (compressed_data + sizeof(struct CtdlCompressHeader)),
517 &destLen, (Bytef *) cdata, (uLongf) cdatalen, 1) != Z_OK)
519 syslog(LOG_EMERG, "compress2() error\n");
522 zheader.compressed_len = (size_t) destLen;
523 memcpy(compressed_data, &zheader, sizeof(struct CtdlCompressHeader));
524 ddata.size = (size_t) (sizeof(struct CtdlCompressHeader) + zheader.compressed_len);
525 ddata.data = compressed_data;
528 if (TSD->tid != NULL) {
529 ret = dbp[cdb]->put(dbp[cdb], /* db */
530 TSD->tid, /* transaction ID */
535 syslog(LOG_EMERG, "cdb_store(%d): %s", cdb, db_strerror(ret));
539 free(compressed_data);
543 bailIfCursor(TSD->cursors, "attempt to write during r/o cursor");
548 if ((ret = dbp[cdb]->put(dbp[cdb], /* db */
549 tid, /* transaction ID */
553 if (ret == DB_LOCK_DEADLOCK) {
557 syslog(LOG_EMERG, "cdb_store(%d): %s", cdb, db_strerror(ret));
563 free(compressed_data);
573 * Delete a piece of data. Returns 0 if the operation was successful.
575 int cdb_delete(int cdb, void *key, int keylen)
582 memset(&dkey, 0, sizeof dkey);
586 if (TSD->tid != NULL) {
587 ret = dbp[cdb]->del(dbp[cdb], TSD->tid, &dkey, 0);
589 syslog(LOG_EMERG, "cdb_delete(%d): %s\n", cdb, db_strerror(ret));
590 if (ret != DB_NOTFOUND) {
595 bailIfCursor(TSD->cursors, "attempt to delete during r/o cursor");
600 if ((ret = dbp[cdb]->del(dbp[cdb], tid, &dkey, 0))
601 && ret != DB_NOTFOUND) {
602 if (ret == DB_LOCK_DEADLOCK) {
606 syslog(LOG_EMERG, "cdb_delete(%d): %s\n",
607 cdb, db_strerror(ret));
617 static DBC *localcursor(int cdb)
622 if (TSD->cursors[cdb] == NULL)
623 ret = dbp[cdb]->cursor(dbp[cdb], TSD->tid, &curs, 0);
625 ret = TSD->cursors[cdb]->c_dup(TSD->cursors[cdb], &curs, DB_POSITION);
628 syslog(LOG_EMERG, "localcursor: %s\n", db_strerror(ret));
637 * Fetch a piece of data. If not found, returns NULL. Otherwise, it returns
638 * a struct cdbdata which it is the caller's responsibility to free later on
639 * using the cdb_free() routine.
641 struct cdbdata *cdb_fetch(int cdb, const void *key, int keylen)
643 struct cdbdata *tempcdb;
647 memset(&dkey, 0, sizeof(DBT));
649 /* no we don't care about this error. */
652 if (TSD->tid != NULL) {
653 memset(&dret, 0, sizeof(DBT));
654 dret.flags = DB_DBT_MALLOC;
655 ret = dbp[cdb]->get(dbp[cdb], TSD->tid, &dkey, &dret, 0);
660 memset(&dret, 0, sizeof(DBT));
661 dret.flags = DB_DBT_MALLOC;
663 curs = localcursor(cdb);
665 ret = curs->c_get(curs, &dkey, &dret, DB_SET);
668 while (ret == DB_LOCK_DEADLOCK);
672 if ((ret != 0) && (ret != DB_NOTFOUND)) {
673 syslog(LOG_EMERG, "cdb_fetch(%d): %s\n", cdb, db_strerror(ret));
679 tempcdb = (struct cdbdata *) malloc(sizeof(struct cdbdata));
681 if (tempcdb == NULL) {
682 syslog(LOG_EMERG, "cdb_fetch: Cannot allocate memory for tempcdb\n");
684 return NULL; /* make it easier for static analysis... */
688 tempcdb->len = dret.size;
689 tempcdb->ptr = dret.data;
690 cdb_decompress_if_necessary(tempcdb);
697 * Free a cdbdata item.
699 * Note that we only free the 'ptr' portion if it is not NULL. This allows
700 * other code to assume ownership of that memory simply by storing the
701 * pointer elsewhere and then setting 'ptr' to NULL. cdb_free() will then
704 void cdb_free(struct cdbdata *cdb)
712 void cdb_close_cursor(int cdb)
714 if (TSD->cursors[cdb] != NULL) {
715 cclose(TSD->cursors[cdb]);
718 TSD->cursors[cdb] = NULL;
722 * Prepare for a sequential search of an entire database.
723 * (There is guaranteed to be no more than one traversal in
724 * progress per thread at any given time.)
726 void cdb_rewind(int cdb)
730 if (TSD->cursors[cdb] != NULL) {
732 "cdb_rewind: must close cursor on database %d before reopening.\n", cdb);
734 /* cclose(TSD->cursors[cdb]); */
738 * Now initialize the cursor
740 ret = dbp[cdb]->cursor(dbp[cdb], TSD->tid, &TSD->cursors[cdb], 0);
742 syslog(LOG_EMERG, "cdb_rewind: db_cursor: %s\n", db_strerror(ret));
749 * Fetch the next item in a sequential search. Returns a pointer to a
750 * cdbdata structure, or NULL if we've hit the end.
752 struct cdbdata *cdb_next_item(int cdb)
755 struct cdbdata *cdbret;
758 /* Initialize the key/data pair so the flags aren't set. */
759 memset(&key, 0, sizeof(key));
760 memset(&data, 0, sizeof(data));
761 data.flags = DB_DBT_MALLOC;
763 ret = TSD->cursors[cdb]->c_get(TSD->cursors[cdb], &key, &data, DB_NEXT);
766 if (ret != DB_NOTFOUND) {
767 syslog(LOG_EMERG, "cdb_next_item(%d): %s\n", cdb, db_strerror(ret));
770 cdb_close_cursor(cdb);
771 return NULL; /* presumably, end of file */
774 cdbret = (struct cdbdata *) malloc(sizeof(struct cdbdata));
775 cdbret->len = data.size;
776 cdbret->ptr = data.data;
777 cdb_decompress_if_necessary(cdbret);
785 * Transaction-based stuff. I'm writing this as I bake cookies...
788 void cdb_begin_transaction(void)
791 bailIfCursor(TSD->cursors, "can't begin transaction during r/o cursor");
793 if (TSD->tid != NULL) {
794 syslog(LOG_EMERG, "cdb_begin_transaction: ERROR: nested transaction\n");
801 void cdb_end_transaction(void)
805 for (i = 0; i < MAXCDB; i++)
806 if (TSD->cursors[i] != NULL) {
808 "cdb_end_transaction: WARNING: cursor %d still open at transaction end\n",
810 cclose(TSD->cursors[i]);
811 TSD->cursors[i] = NULL;
814 if (TSD->tid == NULL) {
816 "cdb_end_transaction: ERROR: txcommit(NULL) !!\n");
826 * Truncate (delete every record)
828 void cdb_trunc(int cdb)
834 if (TSD->tid != NULL) {
835 syslog(LOG_EMERG, "cdb_trunc must not be called in a transaction.");
838 bailIfCursor(TSD->cursors, "attempt to write during r/o cursor");
843 if ((ret = dbp[cdb]->truncate(dbp[cdb], /* db */
844 NULL, /* transaction ID */
845 &count, /* #rows deleted */
847 if (ret == DB_LOCK_DEADLOCK) {
851 syslog(LOG_EMERG, "cdb_truncate(%d): %s\n", cdb, db_strerror(ret));
853 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.");
863 int SeentDebugEnabled = 0;
865 #define DBGLOG(LEVEL) if ((LEVEL != LOG_DEBUG) || (SeentDebugEnabled != 0))
866 #define SEENM_syslog(LEVEL, FORMAT) \
867 DBGLOG(LEVEL) syslog(LEVEL, \
868 "%s[%ld]CC[%ld] SEEN[%s][%d] " FORMAT, \
869 IOSTR, ioid, ccid, Facility, cType)
871 #define SEEN_syslog(LEVEL, FORMAT, ...) \
872 DBGLOG(LEVEL) syslog(LEVEL, \
873 "%s[%ld]CC[%ld] SEEN[%s][%d] " FORMAT, \
874 IOSTR, ioid, ccid, Facility, cType, \
877 time_t CheckIfAlreadySeen(const char *Facility,
885 time_t InDBTimeStamp = 0;
887 struct cdbdata *cdbut;
891 SEEN_syslog(LOG_DEBUG, "Loading [%s]", ChrPtr(guid));
892 cdbut = cdb_fetch(CDB_USETABLE, SKEY(guid));
893 if ((cdbut != NULL) && (cdbut->ptr != NULL)) {
894 memcpy(&ut, cdbut->ptr,
895 ((cdbut->len > sizeof(struct UseTable)) ?
896 sizeof(struct UseTable) : cdbut->len));
897 InDBTimeStamp = now - ut.ut_timestamp;
899 if (InDBTimeStamp < antiexpire)
901 SEEN_syslog(LOG_DEBUG, "Found - Not expired %ld < %ld", InDBTimeStamp, antiexpire);
903 return InDBTimeStamp;
907 SEEN_syslog(LOG_DEBUG, "Found - Expired. %ld >= %ld", InDBTimeStamp, antiexpire);
913 if (cdbut) cdb_free(cdbut);
915 SEENM_syslog(LOG_DEBUG, "not Found");
916 if (cType == eCheckUpdate)
920 if (cType == eCheckExist)
921 return InDBTimeStamp;
924 memcpy(ut.ut_msgid, SKEY(guid));
925 ut.ut_timestamp = now;
927 SEENM_syslog(LOG_DEBUG, "Saving new Timestamp");
928 /* rewrite the record anyway, to update the timestamp */
929 cdb_store(CDB_USETABLE,
931 &ut, sizeof(struct UseTable) );
933 SEENM_syslog(LOG_DEBUG, "Done Saving");
934 return InDBTimeStamp;
938 void cmd_rsen(char *argbuf) {
944 struct cdbdata *cdbut;
946 if (CtdlAccessCheck(ac_aide)) return;
948 TLen = extract_token(Token, argbuf, 1, '|', sizeof Token);
949 if (strncmp(argbuf, "GET", 3) == 0) {
950 cdbut = cdb_fetch(CDB_USETABLE, Token, TLen);
952 memcpy(&ut, cdbut->ptr,
953 ((cdbut->len > sizeof(struct UseTable)) ?
954 sizeof(struct UseTable) : cdbut->len));
956 cprintf("%d %ld\n", CIT_OK, ut.ut_timestamp);
959 cprintf("%d not found\n", ERROR + NOT_HERE);
963 else if (strncmp(argbuf, "SET", 3) == 0) {
964 memcpy(ut.ut_msgid, Token, TLen);
965 extract_token(Time, argbuf, 2, '|', sizeof Time);
966 ut.ut_timestamp = atol(Time);
967 cdb_store(CDB_USETABLE,
969 &ut, sizeof(struct UseTable) );
970 cprintf("%d token updated\n", CIT_OK);
972 else if (strncmp(argbuf, "DEL", 3) == 0) {
973 if (cdb_delete(CDB_USETABLE, Token, TLen))
974 cprintf("%d not found\n", ERROR + NOT_HERE);
976 cprintf("%d deleted.\n", CIT_OK);
980 cprintf("%d Usage: [GET|SET|DEL]|Token|timestamp\n", ERROR);
984 void LogDebugEnableSeenEnable(const int n)
986 SeentDebugEnabled = n;
989 CTDL_MODULE_INIT(database)
993 CtdlRegisterDebugFlagHook(HKEY("SeenDebug"), LogDebugEnableSeenEnable, &SeentDebugEnabled);
994 CtdlRegisterProtoHook(cmd_rsen, "RSEN", "manipulate Aggregators seen database");
997 /* return our module id for the log */