Browse code

mtree: Add RPC response on successful reload, re-organise function rpc_mtree_reload

Olle E. Johansson authored on 03/01/2022 13:53:05
Showing 1 changed files
... ...
@@ -929,61 +929,59 @@ void rpc_mtree_reload(rpc_t* rpc, void* c)
929 929
 {
930 930
 	str tname = {0, 0};
931 931
 	m_tree_t *pt = NULL;
932
-	int treloaded = 0;
932
+	int treeloaded = 0;
933 933
 
934 934
 	if(db_table.len>0)
935 935
 	{
936 936
 		/* re-loading all information from database */
937 937
 		if(mt_load_db_trees()!=0)
938 938
 		{
939
-			LM_ERR("cannot re-load mtrees from database\n");
940
-			goto error;
941
-		}
942
-	} else {
943
-		if(!mt_defined_trees())
944
-		{
945
-			LM_ERR("empty mtree list\n");
946
-			goto error;
939
+			rpc->fault(c, 500, "Can not reload Mtrees from database.");
940
+			return;
947 941
 		}
942
+		rpc->rpl_printf(c, "Ok. Mtrees reloaded.");
943
+		return;
944
+	} 
945
+	if(!mt_defined_trees())
946
+	{
947
+		rpc->fault(c, 500, "No Mtrees defined.");
948
+		return;
949
+	}
948 950
 
949
-		/* read tree name */
950
-		if (rpc->scan(c, "S", &tname) != 1) {
951
+	/* read tree name */
952
+	if (rpc->scan(c, "S", &tname) != 1) {
953
+		tname.s = 0;
954
+		tname.len = 0;
955
+	} else {
956
+		if(*tname.s=='.') {
951 957
 			tname.s = 0;
952 958
 			tname.len = 0;
953
-		} else {
954
-			if(*tname.s=='.') {
955
-				tname.s = 0;
956
-				tname.len = 0;
957
-			}
958 959
 		}
960
+	}
959 961
 
960
-		pt = mt_get_first_tree();
962
+	pt = mt_get_first_tree();
961 963
 
962
-		while(pt!=NULL)
964
+	while(pt!=NULL)
965
+	{
966
+		if(tname.s==NULL
967
+				|| (tname.s!=NULL && pt->tname.len>=tname.len
968
+					&& strncmp(pt->tname.s, tname.s, tname.len)==0))
963 969
 		{
964
-			if(tname.s==NULL
965
-					|| (tname.s!=NULL && pt->tname.len>=tname.len
966
-						&& strncmp(pt->tname.s, tname.s, tname.len)==0))
970
+			/* re-loading table from database */
971
+			if(mt_load_db(pt)!=0)
967 972
 			{
968
-				/* re-loading table from database */
969
-				if(mt_load_db(pt)!=0)
970
-				{
971
-					LM_ERR("cannot re-load mtree from database\n");
972
-					goto error;
973
-				}
974
-				treloaded = 1;
973
+				rpc->fault(c, 500, "Mtree Reload Failed");
974
+				return;
975 975
 			}
976
-			pt = pt->next;
977
-		}
978
-		if(treloaded == 0) {
979
-			rpc->fault(c, 500, "No Mtree Name Matching");
976
+			treeloaded = 1;
980 977
 		}
978
+		pt = pt->next;
981 979
 	}
982
-
980
+	if(treeloaded == 0) {
981
+		rpc->fault(c, 500, "Can not find specified Mtree");
982
+	}
983
+	rpc->rpl_printf(c, "Ok. Mtree reloaded.");
983 984
 	return;
984
-
985
-error:
986
-	rpc->fault(c, 500, "Mtree Reload Failed");
987 985
 }
988 986
 
989 987
 static const char* rpc_mtree_reload_doc[2] = {