[sr-dev] git:sr_3.0: modules/dialplan: fixed reloading of db data
Juha Heinanen
jh at tutpro.com
Fri Apr 9 16:17:42 CEST 2010
Module: sip-router
Branch: sr_3.0
Commit: 5d93707e2bd5d517252526991837df1d58c10401
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=5d93707e2bd5d517252526991837df1d58c10401
Author: Juha Heinanen <jh at tutpro.com>
Committer: Juha Heinanen <jh at 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.
(cherry picked from commit 14aaf32dd20252ee92c97dc3d3811c20b615222c)
---
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 c6c1f80..ab3947d 100644
--- a/modules/dialplan/dialplan.c
+++ b/modules/dialplan/dialplan.c
@@ -184,8 +184,6 @@ static int mod_init(void)
static int child_init(int rank)
{
- if(rank>0)
- return dp_connect_db();
return 0;
}
@@ -202,15 +200,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;
}
@@ -316,7 +311,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);
@@ -447,11 +441,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;
@@ -512,8 +514,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 9919daf..262e552 100644
--- a/modules/dialplan/dp_db.c
+++ b/modules/dialplan/dp_db.c
@@ -111,8 +111,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;
}
@@ -199,7 +204,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;
}
More information about the sr-dev
mailing list