From 05615f0a9026d1485c513ca22df279e9b7096958 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 13 Feb 2008 18:50:49 +0000 Subject: [PATCH] Implement parsing of db_driver to give db_type index. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6413 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/cats/bdb.c | 8 +++----- bacula/src/cats/cats.h | 6 ++++++ bacula/src/cats/protos.h | 2 ++ bacula/src/cats/sql.c | 37 +++++++++++++++++++++++++++++++------ bacula/technotes-2.3 | 3 +++ 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/bacula/src/cats/bdb.c b/bacula/src/cats/bdb.c index 57be8be5de..f52cc74899 100644 --- a/bacula/src/cats/bdb.c +++ b/bacula/src/cats/bdb.c @@ -51,7 +51,8 @@ #ifdef HAVE_BACULA_DB uint32_t bacula_db_version = 0; -char db_driver[100]; + +int db_type = 0; /* List of open databases */ static BQUEUE db_list = {&db_list, &db_list}; @@ -74,13 +75,10 @@ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; #define DB_FILESET_FILENAME "fileset.db" -B_DB *db_init(JCR *jcr, const char *adb_driver, const char *db_name, const char *db_user, +B_DB *db_init(JCR *jcr, const char *db_driver, const char *db_name, const char *db_user, const char *db_password, const char *db_address, int db_port, const char *db_socket, int mult_db_connections) { - if (adb_driver) { - bstrncpy(db_driver, adb_driver, sizeof(db_driver)); - } return db_init_database(jcr, db_name, db_user, db_password, db_address, db_port, db_socket, mult_db_connections); } diff --git a/bacula/src/cats/cats.h b/bacula/src/cats/cats.h index 0f0056ae99..4c39626f97 100644 --- a/bacula/src/cats/cats.h +++ b/bacula/src/cats/cats.h @@ -69,6 +69,12 @@ #ifndef __SQL_H_ #define __SQL_H_ 1 +enum { + SQL_TYPE_MYSQL = 0, + SQL_TYPE_POSTGRE = 1, + SQL_TYPE_SQLITE = 2 +}; + typedef void (DB_LIST_HANDLER)(void *, const char *); typedef int (DB_RESULT_HANDLER)(void *, int, char **); diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index de80996149..c09cbbf1b0 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -38,6 +38,8 @@ #include "cats.h" +extern int db_type; /* DB engine type */ + /* Database prototypes */ /* sql.c */ diff --git a/bacula/src/cats/sql.c b/bacula/src/cats/sql.c index b5df87083b..201485d27f 100644 --- a/bacula/src/cats/sql.c +++ b/bacula/src/cats/sql.c @@ -46,23 +46,48 @@ #include "bacula.h" #include "cats.h" -#if HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL +#if HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL || HAVE_DBI uint32_t bacula_db_version = 0; -char db_driver[100]; +int db_type = -1; /* Forward referenced subroutines */ void print_dashes(B_DB *mdb); void print_result(B_DB *mdb); -B_DB *db_init(JCR *jcr, const char *adb_driver, const char *db_name, const char *db_user, +B_DB *db_init(JCR *jcr, const char *db_driver, const char *db_name, const char *db_user, const char *db_password, const char *db_address, int db_port, const char *db_socket, int mult_db_connections) { - if (adb_driver) { - bstrncpy(db_driver, adb_driver, sizeof(db_driver)); - } +#ifdef HAVE_DBI + char *p; + if (!db_driver) { + Jmsg0(jcr, M_ABORT, 0, _("Driver type not specified in Catalog resource.\n")); + } + if (strlen(db_driver) < 5 || db_driver[3] != ':' || strncasecmp(db_driver, "dbi", 3) != 0) { + Jmsg0(jcr, M_ABORT, 0, _("Invalid driver type, must be \"dbi:\"\n")); + } + p = (char *)(db_driver + 4); + if (strcasecmp(p, "mysql") == 0) { + db_type = SQL_TYPE_MYSQL; + } else if (strcasecmp(p, "postgresql") == 0) { + db_type = SQL_TYPE_POSTGRE; + } else if (strcasecmp(p, "sqlite") == 0) { + db_type = SQL_TYPE_SQLITE; + } else { + Jmsg1(jcr, M_ABORT, 0, _("Unknown database type: %s\n"), p); + } +#elif HAVE_MYSQL + db_type = SQL_TYPE_MYSQL; +#elif HAVE_POSTGRESQL + db_type = SQL_TYPE_POSTGRE; +#elif HAVE_SQLITE + db_type = SQL_TYPE_SQLITE; +#elif HAVE_SQLITE3 + db_type = SQL_TYPE_SQLITE; +#endif + return db_init_database(jcr, db_name, db_user, db_password, db_address, db_port, db_socket, mult_db_connections); } diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index 4ab6ca0061..25d3d70137 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -1,6 +1,9 @@ Technical notes on version 2.3 General: +13Feb08 +kes Implement plugin restore. +kes Implement parsing of db_driver to give db_type index. 10Feb08 kes First cut of plugin restore code. kes Fix bug #1047, which had a heap overrun when stripping certain paths, -- 2.39.5