]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/bdb.c
numornull becomes edit_num_or_null
[bacula/bacula] / bacula / src / cats / bdb.c
index ae1819abf41061033e31f8d837d24b69b33a5b8a..cd2bbb24a3667b87d6023626a3fd1eaa92418473 100644 (file)
@@ -14,7 +14,7 @@
 
 
 /*
-   Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+   Copyright (C) 2000-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
@@ -44,6 +44,8 @@
 
 #ifdef HAVE_BACULA_DB
 
+uint32_t bacula_db_version = 0;
+
 /* Forward referenced functions */
 
 extern char *working_directory;
@@ -100,7 +102,8 @@ 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)
 {
    B_DB *mdb;
    P(mutex);                         /* lock DB queue */
@@ -114,7 +117,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 +131,9 @@ 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, _("WARNING!!!! The Internal Database is for TESTING ONLY!\n"));
+   Jmsg(jcr, M_WARNING, 0, _("You should use either SQLite or MySQL\n"));
+
    return mdb;
 }
 
@@ -136,18 +142,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 +164,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 +219,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 +237,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 +266,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 +278,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)
@@ -443,11 +451,11 @@ void _db_unlock(char *file, int line, B_DB *mdb)
  *  much more efficient. Usually started when inserting 
  *  file attributes.
  */
-void db_start_transaction(B_DB *mdb)
+void db_start_transaction(JCR *jcr, B_DB *mdb)
 {
 }
 
-void db_end_transaction(B_DB *mdb)
+void db_end_transaction(JCR *jcr, B_DB *mdb)
 {
 }