Module: sip-router
Branch: master
Commit: 14aaf32dd20252ee92c97dc3d3811c20b615222c
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=14aaf32…
Author: Juha Heinanen <jh(a)tutpro.com>
Committer: Juha Heinanen <jh(a)tutpro.com>
Date: Sat Apr 3 13:20:38 2010 +0300
modules/dialplan: fixed reloading of db data
- Open and close db connection each time rules are (re)loaded from
database.
---
modules/dialplan/dialplan.c | 22 +++++++++++-----------
modules/dialplan/dp_db.c | 9 +++++++--
2 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/modules/dialplan/dialplan.c b/modules/dialplan/dialplan.c
index af090a3..ad740b4 100644
--- a/modules/dialplan/dialplan.c
+++ b/modules/dialplan/dialplan.c
@@ -197,8 +197,6 @@ static int mod_init(void)
static int child_init(int rank)
{
- if(rank>0)
- return dp_connect_db();
return 0;
}
@@ -215,15 +213,12 @@ static void mod_destroy(void)
attr_pvar = NULL;
}
destroy_data();
-
- /*close database connection*/
- dp_disconnect_db();
}
static int mi_child_init(void)
{
- return dp_connect_db();
+ return 0;
}
@@ -328,7 +323,6 @@ static int dp_translate_f(struct sip_msg* msg, char* str1, char*
str2)
LM_ERR("no dpid value\n");
return -1;
}
- LM_DBG("dpid is %i\n", dpid);
if ((idp = select_dpid(dpid)) ==0 ){
LM_DBG("no information available for dpid %i\n", dpid);
@@ -467,11 +461,19 @@ static struct mi_root * mi_reload_rules(struct mi_root *cmd_tree,
void *param)
{
struct mi_root* rpl_tree= NULL;
+ if (dp_connect_db() < 0) {
+ LM_ERR("failed to reload rules fron database (db connect)\n");
+ return 0;
+ }
+
if(dp_load_db() != 0){
- LM_ERR("failed to reload database data\n");
- return 0;
+ LM_ERR("failed to reload rules fron database (db load)\n");
+ dp_disconnect_db();
+ return 0;
}
+ dp_disconnect_db();
+
rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
if (rpl_tree==0)
return 0;
@@ -532,8 +534,6 @@ static struct mi_root * mi_translate(struct mi_root *cmd, void
*param)
return init_mi_tree(404, "Empty input parameter", 21);
}
- LM_DBG("input is %.*s\n", input.len, input.s);
-
if (translate(NULL, input, &output, idp, &attrs)!=0){
LM_DBG("could not translate %.*s with dpid %i\n",
input.len, input.s, idp->dp_id);
diff --git a/modules/dialplan/dp_db.c b/modules/dialplan/dp_db.c
index 0fab800..3f50e78 100644
--- a/modules/dialplan/dp_db.c
+++ b/modules/dialplan/dp_db.c
@@ -119,8 +119,13 @@ error:
int dp_connect_db(void)
{
+ if (dp_dbf.init==0){
+ LM_CRIT("null dp_dbf\n");
+ return -1;
+ }
+
if(dp_db_handle){
- LM_CRIT("BUG: connection to DB already open\n");
+ LM_CRIT("BUG: connection to database already open\n");
return -1;
}
@@ -207,7 +212,7 @@ int dp_load_db(void)
}
if (dp_dbf.use_table(dp_db_handle, &dp_table_name) < 0){
- LM_ERR("error in use_table\n");
+ LM_ERR("error in use_table %.*s\n", dp_table_name.len, dp_table_name.s);
return -1;
}