bdb_mod.c

Go to the documentation of this file.
00001 /*
00002  * $Id$
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 SIP-router, a free SIP server.
00010  *
00011  * SIP-router 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  * SIP-router 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 
00037 #include <stdio.h>
00038 #include <unistd.h>
00039 #include <sys/stat.h>
00040 
00041 
00042 #include "../../str.h"
00043 #include "../../ut.h"
00044 #include "../../mem/mem.h"
00045 
00046 #include "../../sr_module.h"
00047 #include "../../lib/srdb2/db_res.h"
00048 #include "../../lib/srdb2/db.h"
00049 
00050 #include "bdb_lib.h"
00051 #include "bdb_con.h"
00052 #include "bdb_uri.h"
00053 #include "bdb_fld.h"
00054 #include "bdb_res.h"
00055 #include "bdb_cmd.h"
00056 #include "km_db_berkeley.h"
00057 
00058 MODULE_VERSION
00059 
00060 int auto_reload = 0;
00061 int log_enable  = 0;
00062 int journal_roll_interval = 0;
00063 
00064 static int  bdb_mod_init(void);
00065 static void bdb_mod_destroy(void);
00066 
00067 /*
00068  * Exported functions
00069  */
00070 static cmd_export_t cmds[] = {
00071         {"db_ctx",    (cmd_function)NULL,          0, 0, 0},
00072         {"db_con",    (cmd_function)bdb_con,       0, 0, 0},
00073         {"db_uri",    (cmd_function)bdb_uri,       0, 0, 0},
00074         {"db_cmd",    (cmd_function)bdb_cmd,       0, 0, 0},
00075         {"db_put",    (cmd_function)bdb_cmd_exec,  0, 0, 0},
00076         {"db_del",    (cmd_function)bdb_cmd_exec,  0, 0, 0},
00077         {"db_get",    (cmd_function)bdb_cmd_exec,  0, 0, 0},
00078         {"db_upd",    (cmd_function)bdb_cmd_exec,  0, 0, 0},
00079         {"db_sql",    (cmd_function)bdb_cmd_exec,  0, 0, 0},
00080         {"db_first",  (cmd_function)bdb_cmd_first, 0, 0, 0},
00081         {"db_next",   (cmd_function)bdb_cmd_next,  0, 0, 0},
00082         {"db_res",    (cmd_function)bdb_res,       0, 0, 0},
00083         {"db_fld",    (cmd_function)bdb_fld,       0, 0, 0},
00084         {"db_bind_api", (cmd_function)bdb_bind_api, 0, 0, 0},
00085         {0, 0, 0, 0, 0}
00086 };
00087 
00088 /*
00089  * Exported parameters
00090  */
00091 static param_export_t params[] = {
00092         {"auto_reload",        INT_PARAM, &auto_reload },
00093         {"log_enable",         INT_PARAM, &log_enable  },
00094         {"journal_roll_interval", INT_PARAM, &journal_roll_interval  },
00095         {0, 0, 0}
00096 };
00097 
00098 struct module_exports exports = {       
00099         "db_berkeley",
00100         cmds,     /* Exported functions */
00101         0,        /* RPC method */
00102         params,   /* Exported parameters */
00103         bdb_mod_init,     /* module initialization function */
00104         0,        /* response function*/
00105         bdb_mod_destroy,  /* destroy function */
00106         0,        /* oncancel function */
00107         0         /* per-child init function */
00108 };
00109 
00110 
00111 int mod_register(char *path, int *dlflags, void *p1, void *p2)
00112 {
00113         if(db_api_init()<0)
00114                 return -1;
00115         return 0;
00116 }
00117 
00118 static int bdb_mod_init(void)
00119 {
00120         bdb_params_t p;
00121         
00122         p.auto_reload = auto_reload;
00123         p.log_enable = log_enable;
00124         p.cache_size  = (4 * 1024 * 1024); //4Mb
00125         p.journal_roll_interval = journal_roll_interval;
00126         
00127         if(bdblib_init(&p))
00128                 return -1;
00129 
00130         return km_mod_init();
00131 }
00132 
00133 static void bdb_mod_destroy(void)
00134 {
00135         km_destroy();
00136         bdblib_destroy();
00137 }
00138