Moved cdb_ prototypes from berkeley_db.c to database.c where they belong
authorArt Cancro <ajc@citadel.org>
Wed, 9 Aug 2023 15:41:23 +0000 (11:41 -0400)
committerArt Cancro <ajc@citadel.org>
Wed, 9 Aug 2023 15:41:23 +0000 (11:41 -0400)
citadel/server/backends/berkeley_db/berkeley_db.c
citadel/server/database.c

index dec082234c31057f46896cbf0027980929d1bea6..edf7a902c63119fb66ecbe25cd186b05a00e47ed 100644 (file)
 #include <dirent.h>
 #include <zlib.h>
 #include <db.h>
-
-#if DB_VERSION_MAJOR < 18
-#error Citadel requires Berkeley DB v18.0 or newer.  Please upgrade.
-#endif
-
 #include <libcitadel.h>
 #include "../../ctdl_module.h"
 #include "../../control.h"
 #include "../../config.h"
 #include "berkeley_db.h"
 
-void                   (*cdb_open_databases)(void)                             = NULL;
-void                   (*cdb_close_databases)(void)                            = NULL;
-int                    (*cdb_store)(int, const void *, int, void *, int)       = NULL;
-int                    (*cdb_delete)(int, void *, int)                         = NULL;
-void                   (*cdb_free)(struct cdbdata *)                           = NULL;
-struct cdbdata *       (*cdb_next_item)(int)                                   = NULL;
-void                   (*cdb_close_cursor)(int)                                = NULL;
-void                   (*cdb_begin_transaction)(void)                          = NULL;
-void                   (*cdb_end_transaction)(void)                            = NULL;
-void                   (*cdb_check_handles)(void)                              = NULL;
-void                   (*cdb_trunc)(int)                                       = NULL;
-void                   (*cdb_chmod_data)(void)                                 = NULL;
-void                   (*check_handles)(void *)                                = NULL;
-void                   (*cdb_compact)(void)                                    = NULL;
-void                   (*cdb_checkpoint)(void)                                 = NULL;
-void                   (*cdb_rewind)(int)                                      = NULL;
-struct cdbdata *       (*cdb_fetch)(int, const void *, int)                    = NULL;
+#if DB_VERSION_MAJOR < 18
+#error Citadel requires Berkeley DB v18.0 or newer.  Please upgrade.
+#endif
+
 
 static DB *dbp[MAXCDB];                // One DB handle for each Citadel database
 static DB_ENV *dbenv;          // The DB environment (global)
index 2ba0102ca7e3e8be49cb594bc46f6c8f0ccb8863..5aa7d0e27ebd496efc9ebc8a719e830d01d76ceb 100644 (file)
@@ -5,7 +5,6 @@
 // The functions in this file handle the selection and activation of a storage backend for Citadel Server.
 // Right now, it simply activates Berkeley DB because that's the only one we have.
 
-
 #include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
 #include "citserver.h"
 #include "config.h"
 
+// Header files for all available backends must be included here.
 #include "backends/berkeley_db/berkeley_db.h"
 
+// Backends must include implementations of all these functions, but with their own prefix instead of "cdb_".
+// The initialization function of the selected backend will map them.
+void                   (*cdb_open_databases)(void)                             = NULL;
+void                   (*cdb_close_databases)(void)                            = NULL;
+int                    (*cdb_store)(int, const void *, int, void *, int)       = NULL;
+int                    (*cdb_delete)(int, void *, int)                         = NULL;
+void                   (*cdb_free)(struct cdbdata *)                           = NULL;
+struct cdbdata *       (*cdb_next_item)(int)                                   = NULL;
+void                   (*cdb_close_cursor)(int)                                = NULL;
+void                   (*cdb_begin_transaction)(void)                          = NULL;
+void                   (*cdb_end_transaction)(void)                            = NULL;
+void                   (*cdb_check_handles)(void)                              = NULL;
+void                   (*cdb_trunc)(int)                                       = NULL;
+void                   (*cdb_chmod_data)(void)                                 = NULL;
+void                   (*check_handles)(void *)                                = NULL;
+void                   (*cdb_compact)(void)                                    = NULL;
+void                   (*cdb_checkpoint)(void)                                 = NULL;
+void                   (*cdb_rewind)(int)                                      = NULL;
+struct cdbdata *       (*cdb_fetch)(int, const void *, int)                    = NULL;
+
+// This function is responsible for choosing and initializing a back end.
 void cdb_init_backends(void) {
-       bdb_init_backend();
+       bdb_init_backend();             // for now, this is the only one, so we select it always.
 }