]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/cats.h
Fix bug in bvfs_update function, should work much better now
[bacula/bacula] / bacula / src / cats / cats.h
index 4613b67b5c0f05e8367928052b8e02b17dad6d4e..e6861f567062de8e079ccc2fdd2f22eaf643038b 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2009 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
@@ -38,7 +38,6 @@
  * for the external world. This is control with
  * the define __SQL_C, which is defined only in sql.c
  *
- *    Version $Id$
  */
 
 /*
@@ -73,7 +72,8 @@ enum {
    SQL_TYPE_MYSQL      = 0,
    SQL_TYPE_POSTGRESQL = 1,
    SQL_TYPE_SQLITE     = 2,
-   SQL_TYPE_SQLITE3
+   SQL_TYPE_SQLITE3    = 3,
+   SQL_TYPE_INGRES     = 4
 };
 
 
@@ -87,8 +87,9 @@ typedef int (DB_RESULT_HANDLER)(void *, int, char **);
 
 #if defined(BUILDING_CATS)
 #ifdef HAVE_SQLITE
+#error "SQLite2 is now deprecated, use SQLite3 instead."
 
-#define BDB_VERSION 11
+#define BDB_VERSION 12
 
 #include <sqlite.h>
 
@@ -115,7 +116,7 @@ typedef struct s_sql_field {
  *                    S Q L I T E
  */
 struct B_DB {
-   BQUEUE bq;                         /* queue control */
+   dlink link;                        /* queue control */
    brwlock_t lock;                    /* transaction lock */
    struct sqlite *db;
    char **result;
@@ -210,7 +211,7 @@ extern const char* my_sqlite_batch_fill_path_query;
 #ifdef HAVE_SQLITE3
 
 
-#define BDB_VERSION 11
+#define BDB_VERSION 12
 
 #include <sqlite3.h>
 
@@ -237,7 +238,7 @@ typedef struct s_sql_field {
  *                    S Q L I T E
  */
 struct B_DB {
-   BQUEUE bq;                         /* queue control */
+   dlink link;                        /* queue control */
    brwlock_t lock;                    /* transaction lock */
    struct sqlite3 *db;
    char **result;
@@ -337,7 +338,7 @@ extern const char* my_sqlite_batch_fill_path_query;
 
 #ifdef HAVE_MYSQL
 
-#define BDB_VERSION 11
+#define BDB_VERSION 12
 
 #include <mysql.h>
 
@@ -349,7 +350,7 @@ extern const char* my_sqlite_batch_fill_path_query;
  *                     M Y S Q L
  */
 struct B_DB {
-   BQUEUE bq;                         /* queue control */
+   dlink link;                        /* queue control */
    brwlock_t lock;                    /* transaction lock */
    MYSQL mysql;
    MYSQL *db;
@@ -421,7 +422,7 @@ extern void  my_mysql_free_result(B_DB *mdb);
 
 #ifdef HAVE_POSTGRESQL
 
-#define BDB_VERSION 11
+#define BDB_VERSION 12
 
 #include <libpq-fe.h>
 
@@ -446,7 +447,7 @@ typedef struct pg_field {
  *                     P O S T G R E S Q L
  */
 struct B_DB {
-   BQUEUE bq;                         /* queue control */
+   dlink link;                        /* queue control */
    brwlock_t lock;                    /* transaction lock */
    PGconn *db;
    PGresult *result;
@@ -534,9 +535,118 @@ extern const char* my_pg_batch_fill_path_query;
 
 #else
 
+#ifdef HAVE_INGRES
+
+#include "myingres.h"
+
+#define BDB_VERSION 12
+
+/* TEMP: the following is taken from select OID, typname from pg_type; */ /*SRE: huh? */
+#define IS_NUM(x)        ((x) == 20 || (x) == 21 || (x) == 23 || (x) == 700 || (x) == 701)
+#define IS_NOT_NULL(x)   ((x) == 1)
+
+typedef char **INGRES_ROW;
+
+/*
+ * This is the "real" definition that should only be
+ * used inside sql.c and associated database interface
+ * subroutines.
+ *
+ *                     I N G R E S
+ */
+struct B_DB {
+   dlink link;                        /* queue control */
+   brwlock_t lock;                    /* transaction lock */
+   INGconn *db;
+   INGresult *result;
+   int status;
+   INGRES_ROW row;
+   INGRES_FIELD *fields;
+   int num_rows;
+   int row_size;                  /* size of malloced rows */
+   int num_fields;
+   int fields_size;               /* size of malloced fields */
+   int row_number;                /* row number from my_ingres_data_seek */
+   int field_number;              /* field number from my_ingres_field_seek */
+   int ref_count;
+   char *db_name;
+   char *db_user;
+   char *db_password;
+   char *db_address;              /* host address */
+   char *db_socket;               /* socket for local access */
+   int db_port;                   /* port of host address */
+   int have_insert_id;            /* do have insert_id() */
+   bool connected;
+   POOLMEM *errmsg;               /* nicely edited error message */
+   POOLMEM *cmd;                  /* SQL command string */
+   POOLMEM *cached_path;
+   int cached_path_len;           /* length of cached path */
+   uint32_t cached_path_id;
+   bool allow_transactions;       /* transactions allowed */
+   bool transaction;              /* transaction started */
+   int changes;                   /* changes made to db */
+   POOLMEM *fname;                /* Filename only */
+   POOLMEM *path;                 /* Path only */
+   POOLMEM *esc_name;             /* Escaped file name */
+   POOLMEM *esc_path;             /* Escaped path name */
+   int fnl;                       /* file name length */
+   int pnl;                       /* path name length */
+};
+
+void               my_ingres_free_result(B_DB *mdb);
+INGRES_ROW         my_ingres_fetch_row  (B_DB *mdb);
+int                my_ingres_query      (B_DB *mdb, const char *query);
+void               my_ingres_data_seek  (B_DB *mdb, int row);
+int                my_ingres_currval    (B_DB *mdb, const char *table_name);
+void               my_ingres_field_seek (B_DB *mdb, int row);
+INGRES_FIELD *     my_ingres_fetch_field(B_DB *mdb);
+void               my_ingres_close      (B_DB *mdb);
+
+int my_ingres_batch_start(JCR *jcr, B_DB *mdb);
+int my_ingres_batch_end(JCR *jcr, B_DB *mdb, const char *error);
+typedef struct ATTR_DBR ATTR_DBR;
+int my_ingres_batch_insert(JCR *jcr, B_DB *mdb, ATTR_DBR *ar);
+char *my_ingres_copy_escape(char *dest, char *src, size_t len);
+
+extern const char* my_ingres_batch_lock_path_query;
+extern const char* my_ingres_batch_lock_filename_query;
+extern const char* my_ingres_batch_unlock_tables_query;
+extern const char* my_ingres_batch_fill_filename_query;
+extern const char* my_ingres_batch_fill_path_query;
+
+/* "Generic" names for easier conversion */
+#define sql_store_result(x)   ((x)->result)
+#define sql_free_result(x)    my_ingres_free_result(x)
+#define sql_fetch_row(x)      my_ingres_fetch_row(x)
+#define sql_query(x, y)       my_ingres_query((x), (y))
+#define sql_close(x)          my_ingres_close(x)
+#define sql_strerror(x)       INGerrorMessage((x)->db)
+#define sql_num_rows(x)       ((unsigned) INGntuples((x)->result))
+#define sql_data_seek(x, i)   my_ingres_data_seek((x), (i))
+#define sql_affected_rows(x)  ((x)->num_rows)
+#define sql_insert_id(x,y)    my_ingres_currval((x), (y))
+#define sql_field_seek(x, y)  my_ingres_field_seek((x), (y))
+#define sql_fetch_field(x)    my_ingres_fetch_field(x)
+#define sql_num_fields(x)     ((x)->num_fields)
+
+#define sql_batch_start(x,y)    my_ingres_batch_start(x,y)
+#define sql_batch_end(x,y,z)    my_ingres_batch_end(x,y,z)
+#define sql_batch_insert(x,y,z) my_ingres_batch_insert(x,y,z)
+#define sql_batch_lock_path_query       my_ingres_batch_lock_path_query
+#define sql_batch_lock_filename_query   my_ingres_batch_lock_filename_query
+#define sql_batch_unlock_tables_query   my_ingres_batch_unlock_tables_query
+#define sql_batch_fill_filename_query   my_ingres_batch_fill_filename_query
+#define sql_batch_fill_path_query       my_ingres_batch_fill_path_query
+
+#define SQL_ROW               INGRES_ROW
+#define SQL_FIELD             INGRES_FIELD
+#define SQL_MATCH             "~"
+
+#else
+
 #ifdef HAVE_DBI
 
-#define BDB_VERSION 11
+#define BDB_VERSION 12
 
 #include <dbi/dbi.h>
 
@@ -556,7 +666,7 @@ typedef struct dbi_field {
 } DBI_FIELD;
 
 typedef struct dbi_field_get {
-   BQUEUE bq;
+   dlink link;
    char *value;
 } DBI_FIELD_GET;
 
@@ -568,7 +678,7 @@ typedef struct dbi_field_get {
  *                     D B I
  */
 struct B_DB {
-   BQUEUE bq;                         /* queue control */
+   dlink link;                        /* queue control */
    brwlock_t lock;                    /* transaction lock */
    dbi_conn *db;
    dbi_result *result;
@@ -633,12 +743,12 @@ typedef int (*custom_function_insert_t)(void*, const char*, int);
 typedef char* (*custom_function_error_t)(void*);
 typedef int (*custom_function_end_t)(void*, const char*);
 
-extern const char* my_dbi_batch_lock_path_query[4];
-extern const char* my_dbi_batch_lock_filename_query[4];
-extern const char* my_dbi_batch_unlock_tables_query[4];
-extern const char* my_dbi_batch_fill_filename_query[4];
-extern const char* my_dbi_batch_fill_path_query[4];
-extern const char* my_dbi_match[4];
+extern const char* my_dbi_batch_lock_path_query[5];
+extern const char* my_dbi_batch_lock_filename_query[5];
+extern const char* my_dbi_batch_unlock_tables_query[5];
+extern const char* my_dbi_batch_fill_filename_query[5];
+extern const char* my_dbi_batch_fill_path_query[5];
+extern const char* my_dbi_match[5];
 
 /* "Generic" names for easier conversion */
 #define sql_store_result(x)   (x)->result
@@ -668,56 +778,11 @@ extern const char* my_dbi_match[4];
 #define SQL_ROW               DBI_ROW
 #define SQL_FIELD             DBI_FIELD
 
-
-#else  /* USE BACULA DB routines */
-
-#define HAVE_BACULA_DB 1
-
-/* Change this each time there is some incompatible
- * file format change!!!!
- */
-#define BDB_VERSION 13                /* file version number */
-
-struct s_control {
-   int bdb_version;                   /* Version number */
-   uint32_t JobId;                    /* next Job Id */
-   uint32_t PoolId;                   /* next Pool Id */
-   uint32_t MediaId;                  /* next Media Id */
-   uint32_t JobMediaId;               /* next JobMedia Id */
-   uint32_t ClientId;                 /* next Client Id */
-   uint32_t FileSetId;                /* nest FileSet Id */
-   time_t time;                       /* time file written */
-};
-
-
-/* This is the REAL definition for using the
- *  Bacula internal DB
- */
-struct B_DB {
-   BQUEUE bq;                         /* queue control */
-/* pthread_mutex_t mutex;  */         /* single thread lock */
-   brwlock_t lock;                    /* transaction lock */
-   int ref_count;                     /* number of times opened */
-   struct s_control control;          /* control file structure */
-   int cfd;                           /* control file device */
-   FILE *jobfd;                       /* Jobs records file descriptor */
-   FILE *poolfd;                      /* Pool records fd */
-   FILE *mediafd;                     /* Media records fd */
-   FILE *jobmediafd;                  /* JobMedia records fd */
-   FILE *clientfd;                    /* Client records fd */
-   FILE *filesetfd;                   /* FileSet records fd */
-   char *db_name;                     /* name of database */
-   POOLMEM *errmsg;                   /* nicely edited error message */
-   POOLMEM *cmd;                      /* Command string */
-   POOLMEM *cached_path;
-   int cached_path_len;               /* length of cached path */
-   uint32_t cached_path_id;
-};
-
 #endif /* HAVE_SQLITE3 */
 #endif /* HAVE_MYSQL */
 #endif /* HAVE_SQLITE */
 #endif /* HAVE_POSTGRESQL */
+#endif /* HAVE_INGRES */
 #endif /* HAVE_DBI */
 #endif
 
@@ -835,7 +900,7 @@ struct JOBMEDIA_DBR {
    uint32_t EndFile;                  /* End file on Volume */
    uint32_t StartBlock;               /* start block on tape */
    uint32_t EndBlock;                 /* last block */
-   uint32_t Copy;                     /* identical copy */
+// uint32_t Copy;                     /* identical copy */
 };
 
 
@@ -866,6 +931,7 @@ struct ATTR_DBR {
    char *attr;                        /* attributes statp */
    uint32_t FileIndex;
    uint32_t Stream;
+   uint32_t FileType;
    JobId_t  JobId;
    DBId_t ClientId;
    DBId_t PathId;
@@ -901,6 +967,7 @@ struct POOL_DBR {
    int32_t AcceptAnyVolume;           /* set to accept any volume sequence */
    int32_t AutoPrune;                 /* set to prune automatically */
    int32_t Recycle;                   /* default Vol recycle flag */
+   uint32_t ActionOnPurge;            /* action on purge, e.g. truncate the disk volume */
    utime_t  VolRetention;             /* retention period in seconds */
    utime_t  VolUseDuration;           /* time in secs volume can be used */
    uint32_t MaxVolJobs;               /* Max Jobs on Volume */
@@ -976,6 +1043,7 @@ struct MEDIA_DBR {
    uint64_t VolWriteTime;             /* time spent writing volume */
    utime_t  VolRetention;             /* Volume retention in seconds */
    utime_t  VolUseDuration;           /* time in secs volume can be used */
+   uint32_t ActionOnPurge;            /* action on purge, e.g. truncate the disk volume */
    uint32_t MaxVolJobs;               /* Max Jobs on Volume */
    uint32_t MaxVolFiles;              /* Max files on Volume */
    int32_t  Recycle;                  /* recycle yes/no */
@@ -1044,7 +1112,9 @@ struct db_int64_ctx {
    int count;                         /* number of values seen */
 };
 
-/* Call back context for getting a list of comma separated strings from the database */
+/* Call back context for getting a list of comma separated strings from the
+ * database 
+ */
 class db_list_ctx {
 public:
    POOLMEM *list;                     /* list */
@@ -1052,6 +1122,10 @@ public:
 
    db_list_ctx() { list = get_pool_memory(PM_FNAME); *list = 0; count = 0; }
    ~db_list_ctx() { free_pool_memory(list); list = NULL; }
+
+private:
+   db_list_ctx(const db_list_ctx&);            /* prohibit pass by value */
+   db_list_ctx &operator=(const db_list_ctx&); /* prohibit class assignment */
 };
 
 
@@ -1062,7 +1136,7 @@ public:
 /*
  * Exported globals from sql.c
  */
-extern int DLL_IMP_EXP db_type;        /* SQL engine type index */
+extern int CATS_IMP_EXP db_type;        /* SQL engine type index */
 
 /*
  * Some functions exported by sql.c for use within the
@@ -1072,6 +1146,7 @@ void list_result(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *send, void *ctx, e_list_t
 void list_dashes(B_DB *mdb, DB_LIST_HANDLER *send, void *ctx);
 int get_sql_record_max(JCR *jcr, B_DB *mdb);
 bool check_tables_version(JCR *jcr, B_DB *mdb);
+bool db_check_max_connections(JCR *jcr, B_DB *mdb, uint32_t nb);
 void _db_unlock(const char *file, int line, B_DB *mdb);
 void _db_lock(const char *file, int line, B_DB *mdb);
 const char *db_get_type(void);