Browse code

dispatcher: fix mi/rpc reload command

Ovidiu Sas authored on 17/09/2013 13:24:51
Showing 3 changed files
... ...
@@ -92,7 +92,7 @@ static ds_ht_t *_dsht_load = NULL;
92 92
 extern int ds_force_dst;
93 93
 
94 94
 static db_func_t ds_dbf;
95
-static db1_con_t* ds_db_handle=0;
95
+static db1_con_t* ds_db_handle=NULL;
96 96
 
97 97
 ds_set_t **ds_lists=NULL;
98 98
 
... ...
@@ -655,8 +655,8 @@ int init_ds_db(void)
655 655
 		return -1;
656 656
 	}
657 657
 
658
-	if(ds_connect_db()!=0){
659
-
658
+	if(ds_connect_db()!=0)
659
+	{
660 660
 		LM_ERR("unable to connect to the database\n");
661 661
 		return -1;
662 662
 	}
... ...
@@ -689,6 +689,26 @@ int init_ds_db(void)
689 689
 	return ret;
690 690
 }
691 691
 
692
+/*! \brief reload groups of destinations from DB*/
693
+int ds_reload_db(void)
694
+{
695
+	int ret;
696
+
697
+	if(ds_connect_db()!=0)
698
+	{
699
+		LM_ERR("unable to connect to the database\n");
700
+		return -1;
701
+	}
702
+	ret = ds_load_db();
703
+	if (ret == -2)
704
+	{
705
+		LM_WARN("failure while loading one or more dispatcher entries\n");
706
+	}
707
+	ds_disconnect_db();
708
+
709
+	return ret;
710
+}
711
+
692 712
 /*! \brief load groups of destinations from DB*/
693 713
 int ds_load_db(void)
694 714
 {
... ...
@@ -105,6 +105,7 @@ int ds_load_list(char *lfile);
105 105
 int ds_connect_db(void);
106 106
 void ds_disconnect_db(void);
107 107
 int ds_load_db(void);
108
+int ds_reload_db(void);
108 109
 int ds_destroy_list(void);
109 110
 int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode);
110 111
 int ds_next_dst(struct sip_msg *msg, int mode);
... ...
@@ -792,7 +792,7 @@ static struct mi_root* ds_mi_reload(struct mi_root* cmd_tree, void* param)
792 792
 		if (ds_load_list(dslistfile)!=0)
793 793
 			return init_mi_tree(500, MI_ERR_RELOAD, MI_ERR_RELOAD_LEN);
794 794
 	} else {
795
-		if(ds_load_db()<0)
795
+		if(ds_reload_db()<0)
796 796
 			return init_mi_tree(500, MI_ERR_RELOAD, MI_ERR_RELOAD_LEN);
797 797
 	}
798 798
 	return init_mi_tree(200, MI_OK_S, MI_OK_LEN);
... ...
@@ -956,7 +956,7 @@ static void dispatcher_rpc_reload(rpc_t* rpc, void* ctx)
956 956
 			return;
957 957
 		}
958 958
 	} else {
959
-		if(ds_load_db()<0) {
959
+		if(ds_reload_db()<0) {
960 960
 			rpc->fault(ctx, 500, "Reload Failed");
961 961
 			return;
962 962
 		}