4 * db_berkeley module, portions of this code were templated using
5 * the dbtext and postgres modules.
7 * Copyright (C) 2007 Cisco Systems
9 * This file is part of SIP-router, a free SIP server.
11 * SIP-router is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version
16 * SIP-router is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 * 2007-09-19 genesis (wiquan)
38 #ifndef _KM_BDB_LIB_H_
39 #define _KM_BDB_LIB_H_
46 #include "../../str.h"
47 #include "../../lib/srdb1/db.h"
48 #include "../../lib/srdb1/db_val.h"
49 #include "../../locking.h"
51 /*max number of columns in a table*/
52 #define MAX_NUM_COLS 32
54 /*max char width of a table row*/
55 #define MAX_ROW_SIZE 2048
57 /*max char width of a table name*/
58 #define MAX_TABLENAME_SIZE 64
60 #define METADATA_COLUMNS "METADATA_COLUMNS"
61 #define METADATA_KEY "METADATA_KEY"
62 #define METADATA_READONLY "METADATA_READONLY"
63 #define METADATA_LOGFLAGS "METADATA_LOGFLAGS"
64 #define METADATA_DEFAULTS "METADATA_DEFAULTS"
66 /*journal logging flag masks */
72 #define JLOG_STDOUT 16
73 #define JLOG_SYSLOG 32
76 #define DELIM_LEN (sizeof(DELIM)-1)
78 typedef db_val_t bdb_val_t, *bdb_val_p;
87 typedef struct _column
90 str dv; /* default value */
93 } column_t, *column_p;
100 column_p colp [MAX_NUM_COLS];
103 int ro; /*db readonly flag*/
104 int logflags; /*flags indication what-where to journal log */
105 FILE* fp; /*jlog file pointer */
106 time_t t; /*jlog creation time */
110 typedef struct _tbl_cache
114 struct _tbl_cache *prev;
115 struct _tbl_cache *next;
116 } tbl_cache_t, *tbl_cache_p;
118 typedef struct _database
123 } database_t, *database_p;
125 typedef struct _db_parms
127 u_int32_t cache_size;
130 int journal_roll_interval;
131 } db_parms_t, *db_parms_p;
134 int km_bdblib_init(db_parms_p _parms);
135 int km_bdblib_destroy(void);
136 int km_bdblib_close(char* _n);
137 int km_bdblib_reopen(char* _n);
138 int km_bdblib_recover(table_p _tp, int error_code);
139 void km_bdblib_log(int op, table_p _tp, char* _msg, int len);
140 int km_bdblib_create_dbenv(DB_ENV **dbenv, char* home);
141 int km_bdblib_create_journal(table_p _tp);
142 database_p km_bdblib_get_db(str *_s);
143 tbl_cache_p km_bdblib_get_table(database_p _db, str *_s);
144 table_p km_bdblib_create_table(database_p _db, str *_s);
146 int db_free(database_p _dbp);
147 int tbl_cache_free(tbl_cache_p _tbc);
148 int tbl_free(table_p _tp);
150 int km_load_metadata_columns(table_p _tp);
151 int km_load_metadata_keys(table_p _tp);
152 int km_load_metadata_readonly(table_p _tp);
153 int km_load_metadata_logflags(table_p _tp);
154 int km_load_metadata_defaults(table_p _tp);
156 int km_bdblib_valtochar(table_p _tp, int* _lres, char* _k, int* _klen, db_val_t* _v, int _n, int _ko);