]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/bdb.c
Massive SD calling sequence reorganization
[bacula/bacula] / bacula / src / cats / bdb.c
index 490506a2a032947e21ea5910d77894ead5d11459..143d32d995c38792f7fbabb39349d97030a64a32 100644 (file)
@@ -14,7 +14,7 @@
 
 
 /*
-   Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+   Copyright (C) 2001-2003 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
 
 #ifdef HAVE_BACULA_DB
 
+uint32_t bacula_db_version = 0;
+
 /* Forward referenced functions */
 
-extern char *working_directory;
+extern const char *working_directory;
 
 /* List of open databases */
 static BQUEUE db_list = {&db_list, &db_list};
@@ -79,7 +81,7 @@ static POOLMEM *make_filename(B_DB *mdb, char *name)
    } else {
       sep = '/'; 
    }
-   Mmsg(&dbf, "%s%c%s-%s", working_directory, sep, mdb->db_name, name);
+   Mmsg(dbf, "%s%c%s-%s", working_directory, sep, mdb->db_name, name);
    return dbf;
 }
 
@@ -100,7 +102,9 @@ int bdb_write_control_file(B_DB *mdb)
  * never have errors, or it is really fatal.
  */
 B_DB *
-db_init_database(char *db_name, char *db_user, char *db_password)
+db_init_database(JCR *jcr, char *db_name, char *db_user, char *db_password,
+                char *db_address, int db_port, char *db_socket, 
+                int mult_db_connections)
 {
    B_DB *mdb;
    P(mutex);                         /* lock DB queue */
@@ -114,7 +118,7 @@ db_init_database(char *db_name, char *db_user, char *db_password)
       }
    }
    Dmsg0(200, "db_open first time\n");
-   mdb = (B_DB *) malloc(sizeof(B_DB));
+   mdb = (B_DB *)malloc(sizeof(B_DB));
    memset(mdb, 0, sizeof(B_DB));
    Dmsg0(200, "DB struct init\n");
    mdb->db_name = bstrdup(db_name);
@@ -128,6 +132,10 @@ db_init_database(char *db_name, char *db_user, char *db_password)
    Dmsg0(200, "Done db_open_database()\n");
    mdb->cfd = -1;
    V(mutex);
+   Jmsg(jcr, M_WARNING, 0, _("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"));
+   Jmsg(jcr, M_WARNING, 0, _("WARNING!!!! The Internal Database is for TESTING ONLY!\n"));
+   Jmsg(jcr, M_WARNING, 0, _("You should use SQLite, PostgreSQL, or MySQL\n"));
+
    return mdb;
 }
 
@@ -136,18 +144,19 @@ db_init_database(char *db_name, char *db_user, char *db_password)
  * which are returned in the errmsg
  */
 int
-db_open_database(B_DB *mdb)
+db_open_database(JCR *jcr, B_DB *mdb)
 {
    char *dbf;
    int fd, badctl;
    off_t filend;
+   int errstat;
 
    Dmsg1(200, "db_open_database() %s\n", mdb->db_name);
 
    P(mutex);
 
-   if (rwl_init(&mdb->lock) != 0) {
-      Mmsg1(&mdb->errmsg, "Unable to initialize DB lock. ERR=%s\n", strerror(errno));
+   if ((errstat=rwl_init(&mdb->lock)) != 0) {
+      Mmsg1(&mdb->errmsg, _("Unable to initialize DB lock. ERR=%s\n"), strerror(errstat));
       V(mutex);
       return 0;
    }
@@ -157,7 +166,7 @@ db_open_database(B_DB *mdb)
    mdb->cfd = open(dbf, O_CREAT|O_RDWR, 0600); 
    free_memory(dbf);
    if (mdb->cfd < 0) {
-      Mmsg2(&mdb->errmsg, "Unable to open Catalog DB control file %s: ERR=%s\n"
+      Mmsg2(&mdb->errmsg, _("Unable to open Catalog DB control file %s: ERR=%s\n")
         dbf, strerror(errno));
       V(mutex);
       return 0;
@@ -212,15 +221,16 @@ db_open_database(B_DB *mdb)
    badctl = 0;
    lseek(mdb->cfd, 0, SEEK_SET);      /* seek to begining of control file */
    if (read(mdb->cfd, &mdb->control, sizeof(mdb->control)) != sizeof(mdb->control)) {
-      Mmsg1(&mdb->errmsg, "Error reading catalog DB control file. ERR=%s\n", strerror(errno));
+      Mmsg1(&mdb->errmsg, _("Error reading catalog DB control file. ERR=%s\n"), strerror(errno));
       badctl = 1;
    } else if (mdb->control.bdb_version != BDB_VERSION) {
-      Mmsg2(&mdb->errmsg, "Error, catalog DB control file wrong version. \
+      Mmsg2(&mdb->errmsg, _("Error, catalog DB control file wrong version. \
 Wanted %d, got %d\n\
-Please reinitialize the working directory.\n", 
+Please reinitialize the working directory.\n")
         BDB_VERSION, mdb->control.bdb_version);
       badctl = 1;
    }
+   bacula_db_version = mdb->control.bdb_version;
    if (badctl) {
       V(mutex);
       return 0;
@@ -229,7 +239,7 @@ Please reinitialize the working directory.\n",
    return 1;
 }
 
-void db_close_database(B_DB *mdb)           
+void db_close_database(JCR *jcr, B_DB *mdb)           
 {
    P(mutex);
    mdb->ref_count--;
@@ -258,7 +268,6 @@ void db_close_database(B_DB *mdb)
       if (mdb->filesetfd) {
         fclose(mdb->filesetfd);
       }
-/*    pthread_mutex_destroy(&mdb->mutex); */
       rwl_destroy(&mdb->lock);      
       free_pool_memory(mdb->errmsg);
       free_pool_memory(mdb->cmd);
@@ -271,7 +280,8 @@ void db_close_database(B_DB *mdb)
 
 void db_escape_string(char *snew, char *old, int len)
 {
-   strcpy(snew, old);
+   memset(snew, 0, len);
+   bstrncpy(snew, old, len);
 }
 
 char *db_strerror(B_DB *mdb)
@@ -438,4 +448,18 @@ void _db_unlock(char *file, int line, B_DB *mdb)
    }
 }    
 
+/*
+ * Start a transaction. This groups inserts and makes things
+ *  much more efficient. Usually started when inserting 
+ *  file attributes.
+ */
+void db_start_transaction(JCR *jcr, B_DB *mdb)
+{
+}
+
+void db_end_transaction(JCR *jcr, B_DB *mdb)
+{
+}
+
+
 #endif /* HAVE_BACULA_DB */