]> code.citadel.org Git - citadel.git/blobdiff - citadel/database.c
* Fixed a small bug in the GDBM backend (deprecated, but the bug was very
[citadel.git] / citadel / database.c
index ae16edc64e3230c130e743ae9d43e26db4651aa3..934cd69e13c315596d89eb61988ce25004c7a6cd 100644 (file)
  * conditions to occur.  (Deadlock is bad.  Eliminate.)
  */
 
+#ifdef DLL_EXPORT
+#define IN_LIBCIT
+#endif
+
 #include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
-#include <time.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
 #include <ctype.h>
 #include <string.h>
 #include <errno.h>
@@ -51,11 +66,9 @@ void defrag_databases(void)
 
        /* defrag the message base */
        lprintf(7, "Defragmenting message base\n");
-       begin_critical_section(S_MSGMAIN);
        begin_critical_section(S_DATABASE);
        gdbm_reorganize(gdbms[CDB_MSGMAIN]);
        end_critical_section(S_DATABASE);
-       end_critical_section(S_MSGMAIN);
 
        /* defrag the user file, mailboxes, and user/room relationships */
        lprintf(7, "Defragmenting user file\n");
@@ -82,6 +95,16 @@ void defrag_databases(void)
        gdbm_reorganize(gdbms[CDB_FLOORTAB]);
        end_critical_section(S_DATABASE);
        end_critical_section(S_FLOORTAB);
+
+       /* defrag the directory */
+       lprintf(7, "Defragmenting the directory\n");
+       begin_critical_section(S_DIRECTORY);
+       gdbm_reorganize(gdbms[CDB_DIRECTORY]);
+       end_critical_section(S_DIRECTORY);
+
+       /* defrag the use table */
+       lprintf(7, "Defragmenting the use table\n");
+       gdbm_reorganize(gdbms[CDB_USETABLE]);
 }
 
 
@@ -148,6 +171,21 @@ void open_databases(void)
                        gdbm_strerror(gdbm_errno));
                exit(1);
        }
+       gdbms[CDB_DIRECTORY] = gdbm_open("data/directory.gdbm", 0,
+                                       GDBM_WRCREAT, 0600, NULL);
+       if (gdbms[CDB_DIRECTORY] == NULL) {
+               lprintf(2, "Cannot open directory: %s\n",
+                       gdbm_strerror(gdbm_errno));
+               exit(1);
+       }
+       gdbms[CDB_USETABLE] = gdbm_open("data/usetable.gdbm", 0,
+                                       GDBM_WRCREAT, 0600, NULL);
+       if (gdbms[CDB_USETABLE] == NULL) {
+               lprintf(2, "Cannot open use table: %s\n",
+                       gdbm_strerror(gdbm_errno));
+               exit(1);
+       }
+
        /*
           end_critical_section(S_DATABASE);
         */
@@ -269,6 +307,28 @@ void cdb_free(struct cdbdata *cdb)
        phree(cdb);
 }
 
+void cdb_close_cursor(cdb)
+{
+        while (max_keys <= CC->cs_pid) {
+                ++max_keys;
+                if (dtkey == NULL) {
+                        dtkey = (datum *)
+                            mallok((sizeof(datum) * max_keys));
+                } else {
+                        dtkey = (datum *)
+                            reallok(dtkey, (sizeof(datum) * max_keys));
+                }
+                dtkey[max_keys - 1].dsize = 0;
+                dtkey[max_keys - 1].dptr = NULL;
+        }
+
+        if (dtkey[CC->cs_pid].dptr != NULL) {
+                phree(dtkey[CC->cs_pid].dptr);
+        }
+       dtkey[CC->cs_pid].dptr = NULL;
+       dtkey[CC->cs_pid].dsize = 0;
+}
+
 
 /* 
  * Prepare for a sequential search of an entire database.  (In the gdbm model,
@@ -339,9 +399,24 @@ struct cdbdata *cdb_next_item(int cdb)
 }
 
 
+/*
+ * Truncate (delete every record)
+ */
+void cdb_trunc(int cdb) {
+       datum key;
+
+       begin_critical_section(S_DATABASE);
+       key = gdbm_firstkey (gdbms[cdb]);
+       while (key = gdbm_firstkey(gdbms[cdb], key.dptr) {
+               gdbm_delete(gdbms[cdb], key);
+       }
+       end_critical_section(S_DATABASE);
+}
+
+
 
 /*
- * GDBM doesn't support transaction-based logging.  Stub out these functions.
+ * empty functions because GDBM doesn't have transaction support
  */
 
 void cdb_begin_transaction(void) {
@@ -349,3 +424,12 @@ void cdb_begin_transaction(void) {
 
 void cdb_end_transaction(void) {
 }
+
+void cdb_allocate_tsd(void) {
+}
+
+void cdb_free_tsd(void) {
+}
+
+void cdb_check_handles(void) {
+}