[sr-dev] git:master:559b52b1: mtree: Add RPC response on successful reload, re-organise function rpc_mtree_reload

Olle E. Johansson oej at edvina.net
Mon Jan 3 15:41:25 CET 2022


Module: kamailio
Branch: master
Commit: 559b52b194f813c0c8584b3becbac9b2ab8e0343
URL: https://github.com/kamailio/kamailio/commit/559b52b194f813c0c8584b3becbac9b2ab8e0343

Author: Olle E. Johansson <oej at edvina.net>
Committer: Olle E. Johansson <oej at edvina.net>
Date: 2022-01-03T15:41:10+01:00

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

---

Modified: src/modules/mtree/mtree_mod.c

---

Diff:  https://github.com/kamailio/kamailio/commit/559b52b194f813c0c8584b3becbac9b2ab8e0343.diff
Patch: https://github.com/kamailio/kamailio/commit/559b52b194f813c0c8584b3becbac9b2ab8e0343.patch

---

diff --git a/src/modules/mtree/mtree_mod.c b/src/modules/mtree/mtree_mod.c
index 63180bbfb7..1a2cd9f737 100644
--- a/src/modules/mtree/mtree_mod.c
+++ b/src/modules/mtree/mtree_mod.c
@@ -929,61 +929,59 @@ void rpc_mtree_reload(rpc_t* rpc, void* c)
 {
 	str tname = {0, 0};
 	m_tree_t *pt = NULL;
-	int treloaded = 0;
+	int treeloaded = 0;
 
 	if(db_table.len>0)
 	{
 		/* re-loading all information from database */
 		if(mt_load_db_trees()!=0)
 		{
-			LM_ERR("cannot re-load mtrees from database\n");
-			goto error;
-		}
-	} else {
-		if(!mt_defined_trees())
-		{
-			LM_ERR("empty mtree list\n");
-			goto error;
+			rpc->fault(c, 500, "Can not reload Mtrees from database.");
+			return;
 		}
+		rpc->rpl_printf(c, "Ok. Mtrees reloaded.");
+		return;
+	} 
+	if(!mt_defined_trees())
+	{
+		rpc->fault(c, 500, "No Mtrees defined.");
+		return;
+	}
 
-		/* read tree name */
-		if (rpc->scan(c, "S", &tname) != 1) {
+	/* read tree name */
+	if (rpc->scan(c, "S", &tname) != 1) {
+		tname.s = 0;
+		tname.len = 0;
+	} else {
+		if(*tname.s=='.') {
 			tname.s = 0;
 			tname.len = 0;
-		} else {
-			if(*tname.s=='.') {
-				tname.s = 0;
-				tname.len = 0;
-			}
 		}
+	}
 
-		pt = mt_get_first_tree();
+	pt = mt_get_first_tree();
 
-		while(pt!=NULL)
+	while(pt!=NULL)
+	{
+		if(tname.s==NULL
+				|| (tname.s!=NULL && pt->tname.len>=tname.len
+					&& strncmp(pt->tname.s, tname.s, tname.len)==0))
 		{
-			if(tname.s==NULL
-					|| (tname.s!=NULL && pt->tname.len>=tname.len
-						&& strncmp(pt->tname.s, tname.s, tname.len)==0))
+			/* re-loading table from database */
+			if(mt_load_db(pt)!=0)
 			{
-				/* re-loading table from database */
-				if(mt_load_db(pt)!=0)
-				{
-					LM_ERR("cannot re-load mtree from database\n");
-					goto error;
-				}
-				treloaded = 1;
+				rpc->fault(c, 500, "Mtree Reload Failed");
+				return;
 			}
-			pt = pt->next;
-		}
-		if(treloaded == 0) {
-			rpc->fault(c, 500, "No Mtree Name Matching");
+			treeloaded = 1;
 		}
+		pt = pt->next;
 	}
-
+	if(treeloaded == 0) {
+		rpc->fault(c, 500, "Can not find specified Mtree");
+	}
+	rpc->rpl_printf(c, "Ok. Mtree reloaded.");
 	return;
-
-error:
-	rpc->fault(c, 500, "Mtree Reload Failed");
 }
 
 static const char* rpc_mtree_reload_doc[2] = {




More information about the sr-dev mailing list