bdb_lib.h

Go to the documentation of this file.
00001 /*
00002  * $Id: bdb_lib.h 4518 2008-07-28 15:39:28Z henningw $
00003  *
00004  * db_berkeley module, portions of this code were templated using
00005  * the dbtext and postgres modules.
00006 
00007  * Copyright (C) 2007 Cisco Systems
00008  *
00009  * This file is part of Kamailio, a free SIP server.
00010  *
00011  * Kamailio is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version
00015  *
00016  * Kamailio is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License 
00022  * along with this program; if not, write to the Free Software 
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  * 
00025  * History:
00026  * --------
00027  * 2007-09-19  genesis (wiquan)
00028  */
00029 
00030 
00031 #ifndef _BDB_LIB_H_
00032 #define _BDB_LIB_H_
00033 
00034 #include <stdlib.h>
00035 #include <syslog.h>
00036 #include <sys/stat.h>
00037 #include <db.h>
00038 
00039 #include "../../str.h"
00040 #include "../../db/db.h"
00041 #include "../../db/db_val.h"
00042 #include "../../locking.h"
00043 
00044 /*max number of columns in a table*/
00045 #define MAX_NUM_COLS 32
00046 
00047 /*max char width of a table row*/
00048 #define MAX_ROW_SIZE 2048
00049 
00050 /*max char width of a table name*/
00051 #define MAX_TABLENAME_SIZE 64
00052 
00053 #define METADATA_COLUMNS "METADATA_COLUMNS"
00054 #define METADATA_KEY "METADATA_KEY"
00055 #define METADATA_READONLY "METADATA_READONLY"
00056 #define METADATA_LOGFLAGS "METADATA_LOGFLAGS"
00057 #define METADATA_DEFAULTS "METADATA_DEFAULTS"
00058 
00059 /*journal logging flag masks */
00060 #define JLOG_NONE   0
00061 #define JLOG_INSERT 1
00062 #define JLOG_DELETE 2
00063 #define JLOG_UPDATE 4
00064 #define JLOG_FILE   8
00065 #define JLOG_STDOUT 16
00066 #define JLOG_SYSLOG 32
00067 
00068 #define DELIM "|"
00069 #define DELIM_LEN (sizeof(DELIM)-1)
00070 
00071 typedef db_val_t bdb_val_t, *bdb_val_p;
00072 
00073 typedef struct _row
00074 {
00075    bdb_val_p fields;
00076    struct _row *prev;
00077    struct _row *next;
00078 } row_t, *row_p;
00079 
00080 typedef struct _column
00081 {
00082    str name;
00083    str dv;     /* default value */
00084    int type;
00085    int flag;
00086 } column_t, *column_p;
00087 
00088 typedef struct _table
00089 {
00090    str name;
00091    DB *db;
00092    gen_lock_t sem;
00093    column_p colp [MAX_NUM_COLS];
00094    int ncols;
00095    int nkeys;
00096    int ro;       /*db readonly flag*/
00097    int logflags; /*flags indication what-where to journal log */
00098    FILE* fp;     /*jlog file pointer */
00099    time_t t;     /*jlog creation time */
00100    ino_t ino;
00101 } table_t, *table_p;
00102 
00103 typedef struct _tbl_cache
00104 {
00105    gen_lock_t sem;
00106    table_p dtp;
00107    struct _tbl_cache *prev;
00108    struct _tbl_cache *next;
00109 } tbl_cache_t, *tbl_cache_p;
00110 
00111 typedef struct _database
00112 {
00113    str name;
00114    DB_ENV *dbenv;
00115    tbl_cache_p tables;
00116 } database_t, *database_p;
00117 
00118 typedef struct _db_parms
00119 {
00120    u_int32_t cache_size;
00121    int auto_reload;
00122    int log_enable;
00123    int journal_roll_interval;
00124 } db_parms_t, *db_parms_p;
00125 
00126 
00127 int bdblib_init(db_parms_p _parms);
00128 int bdblib_destroy(void);
00129 int bdblib_close(char* _n);
00130 int bdblib_reopen(char* _n);
00131 int bdblib_recover(table_p _tp, int error_code);
00132 void bdblib_log(int op, table_p _tp, char* _msg, int len);
00133 int bdblib_create_dbenv(DB_ENV **dbenv, char* home);
00134 int bdblib_create_journal(table_p _tp);
00135 database_p     bdblib_get_db(str *_s);
00136 tbl_cache_p    bdblib_get_table(database_p _db, str *_s);
00137 table_p  bdblib_create_table(database_p _db, str *_s);
00138 
00139 int db_free(database_p _dbp);
00140 int tbl_cache_free(tbl_cache_p _tbc);
00141 int tbl_free(table_p _tp);
00142 
00143 int load_metadata_columns(table_p _tp);
00144 int load_metadata_keys(table_p _tp);
00145 int load_metadata_readonly(table_p _tp);
00146 int load_metadata_logflags(table_p _tp);
00147 int load_metadata_defaults(table_p _tp);
00148 
00149 int bdblib_valtochar(table_p _tp, int* _lres, char* _k, int* _klen, db_val_t* _v, int _n, int _ko);
00150 
00151 #endif

Generated on Thu May 17 12:00:25 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6