فهرست منبع

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)
Juha Heinanen 15 سال پیش
والد
کامیت
a0fe789aa7
2فایلهای تغییر یافته به همراه18 افزوده شده و 13 حذف شده
  1. 11 11
      modules/dialplan/dialplan.c
  2. 7 2
      modules/dialplan/dp_db.c

+ 11 - 11
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);

+ 7 - 2
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;
 	}