Tue Aug 18 00:42:33 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
[citadel.git] / citadel / database.c
index d81726affdfe0b9645c38c36c42151dd2927cc7d..3f47453bd651056a1a3e09bb66e05af403f6c189 100644 (file)
@@ -16,6 +16,7 @@
 #include "citadel.h"
 #include "server.h"
 #include "proto.h"
+#include "database.h"
 
 
 /*
@@ -35,22 +36,23 @@ datum dtkey[MAXKEYS];
  * Reclaim unused space in the databases.  We need to do each one of
  * these discretely, rather than in a loop.
  */
-void defrag_databases() {
+void defrag_databases(void) {
 
        /* defrag the message base */
        begin_critical_section(S_MSGMAIN);
        gdbm_reorganize(gdbms[CDB_MSGMAIN]);
        end_critical_section(S_MSGMAIN);
 
-       /* defrag the user file */
+       /* defrag the user file and mailboxes */
        begin_critical_section(S_USERSUPP);
        gdbm_reorganize(gdbms[CDB_USERSUPP]);
+       gdbm_reorganize(gdbms[CDB_MAILBOXES]);
        end_critical_section(S_USERSUPP);
 
-       /* defrag the room files */
+       /* defrag the room files and message lists */
        begin_critical_section(S_QUICKROOM);
        gdbm_reorganize(gdbms[CDB_QUICKROOM]);
-       gdbm_reorganize(gdbms[CDB_FULLROOM]);
+       gdbm_reorganize(gdbms[CDB_MSGLISTS]);
        end_critical_section(S_QUICKROOM);
 
        /* defrag the floor table */
@@ -64,50 +66,56 @@ void defrag_databases() {
  * Open the various gdbm databases we'll be using.  Any database which
  * does not exist should be created.
  */
-void open_databases() {
+void open_databases(void) {
        int a;
 
        gdbms[CDB_MSGMAIN] = gdbm_open("msgmain.gdbm", 8192,
-               GDBM_WRCREAT, 0700, NULL);
+               GDBM_WRCREAT, 0600, NULL);
        if (gdbms[CDB_MSGMAIN] == NULL) {
                lprintf(2, "Cannot open msgmain: %s\n",
                        gdbm_strerror(gdbm_errno));
                }
 
        gdbms[CDB_USERSUPP] = gdbm_open("usersupp.gdbm", 0,
-               GDBM_WRCREAT, 0700, NULL);
+               GDBM_WRCREAT, 0600, NULL);
        if (gdbms[CDB_USERSUPP] == NULL) {
                lprintf(2, "Cannot open usersupp: %s\n",
                        gdbm_strerror(gdbm_errno));
                }
 
        gdbms[CDB_QUICKROOM] = gdbm_open("quickroom.gdbm", 0,
-               GDBM_WRCREAT, 0700, NULL);
+               GDBM_WRCREAT, 0600, NULL);
        if (gdbms[CDB_QUICKROOM] == NULL) {
                lprintf(2, "Cannot open quickroom: %s\n",
                        gdbm_strerror(gdbm_errno));
                }
 
-       gdbms[CDB_FULLROOM] = gdbm_open("fullroom.gdbm", 0,
-               GDBM_WRCREAT, 0700, NULL);
-       if (gdbms[CDB_FULLROOM] == NULL) {
-               lprintf(2, "Cannot open fullroom: %s\n",
-                       gdbm_strerror(gdbm_errno));
-               }
-
        gdbms[CDB_FLOORTAB] = gdbm_open("floortab.gdbm", 0,
-               GDBM_WRCREAT, 0700, NULL);
+               GDBM_WRCREAT, 0600, NULL);
        if (gdbms[CDB_FLOORTAB] == NULL) {
                lprintf(2, "Cannot open floortab: %s\n",
                        gdbm_strerror(gdbm_errno));
                }
 
+       gdbms[CDB_MSGLISTS] = gdbm_open("msglists.gdbm", 0,
+               GDBM_WRCREAT, 0600, NULL);
+       if (gdbms[CDB_MSGLISTS] == NULL) {
+               lprintf(2, "Cannot open msglists: %s\n",
+                       gdbm_strerror(gdbm_errno));
+               }
+
+       gdbms[CDB_MAILBOXES] = gdbm_open("mailboxes.gdbm", 0,
+               GDBM_WRCREAT, 0600, NULL);
+       if (gdbms[CDB_MAILBOXES] == NULL) {
+               lprintf(2, "Cannot open mailboxes: %s\n",
+                       gdbm_strerror(gdbm_errno));
+               }
+
        for (a=0; a<MAXKEYS; ++a) {
                dtkey[a].dsize = 0;
                dtkey[a].dptr = NULL;
                }
 
-
        }
 
 
@@ -115,7 +123,7 @@ void open_databases() {
  * Close all of the gdbm database files we've opened.  This can be done
  * in a loop, since it's just a bunch of closes.
  */
-void close_databases() {
+void close_databases(void) {
        int a;
 
        defrag_databases();
@@ -138,8 +146,8 @@ void close_databases() {
  * datum already exists it should be overwritten.
  */
 int cdb_store(int cdb,
-               char *key, int keylen,
-               char *data, int datalen) {
+               void *key, int keylen,
+               void *data, int datalen) {
 
        datum dkey, ddata;
 
@@ -160,7 +168,7 @@ int cdb_store(int cdb,
 /*
  * Delete a piece of data.  Returns 0 if the operation was successful.
  */
-int cdb_delete(int cdb, char *key, int keylen) {
+int cdb_delete(int cdb, void *key, int keylen) {
 
        datum dkey;
 
@@ -179,7 +187,7 @@ int cdb_delete(int cdb, char *key, int keylen) {
  * 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, char *key, int keylen) {
+struct cdbdata *cdb_fetch(int cdb, void *key, int keylen) {
        
        struct cdbdata *tempcdb;
        datum dkey, dret;