[sr-dev] git:master:ecba550f: cfgutils: exported route check functions to kemi

Daniel-Constantin Mierla miconda at gmail.com
Thu Aug 20 15:59:24 CEST 2020


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2020-08-20T15:59:05+02:00

cfgutils: exported route check functions to kemi

---

Modified: src/modules/cfgutils/cfgutils.c

---

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

---

diff --git a/src/modules/cfgutils/cfgutils.c b/src/modules/cfgutils/cfgutils.c
index 7be7181d82..9a77b40aed 100644
--- a/src/modules/cfgutils/cfgutils.c
+++ b/src/modules/cfgutils/cfgutils.c
@@ -790,28 +790,23 @@ static int w_cfg_trylock(struct sip_msg *msg, char *key, char *s2)
 
 /*! Check if a route block exists - only request routes
  */
-static int w_check_route_exists(struct sip_msg *msg, char *route)
+static int ki_check_route_exists(sip_msg_t *msg, str *route)
 {
-	str s;
-
-	if (fixup_get_svalue(msg, (gparam_p) route, &s) != 0)
-	{
-			LM_ERR("invalid route parameter\n");
-			return -1;
+	if(route == NULL || route->s == NULL) {
+		return -1;
 	}
-	if (route_lookup(&main_rt, s.s)<0) {
+
+	if (route_lookup(&main_rt, route->s)<0) {
 		/* not found */
 		return -1;
 	}
 	return 1;
 }
 
-/*! Run a request route block if it exists
+/*! Check if a route block exists - only request routes
  */
-static int w_route_exists(struct sip_msg *msg, char *route)
+static int w_check_route_exists(struct sip_msg *msg, char *route)
 {
-	struct run_act_ctx ctx;
-	int newroute, ret;
 	str s;
 
 	if (fixup_get_svalue(msg, (gparam_p) route, &s) != 0) {
@@ -819,18 +814,49 @@ static int w_route_exists(struct sip_msg *msg, char *route)
 			return -1;
 	}
 
-	newroute = route_lookup(&main_rt, s.s);
+	return ki_check_route_exists(msg, &s);
+}
+
+/*! Run a request route block if it exists
+ */
+static int ki_route_if_exists(sip_msg_t *msg, str *route)
+{
+	struct run_act_ctx ctx;
+	int newroute, ret;
+
+	if(route == NULL || route->s == NULL) {
+		return -1;
+	}
+
+	newroute = route_lookup(&main_rt, route->s);
 	if (newroute<0) {
 		return -1;
 	}
+
 	init_run_actions_ctx(&ctx);
 	ret=run_actions(&ctx, main_rt.rlist[newroute], msg);
 	if (ctx.run_flags & EXIT_R_F) {
 		return 0;
 	}
+
 	return ret;
 }
 
+
+/*! Run a request route block if it exists
+ */
+static int w_route_exists(struct sip_msg *msg, char *route)
+{
+	str s;
+
+	if (fixup_get_svalue(msg, (gparam_p) route, &s) != 0) {
+			LM_ERR("invalid route parameter\n");
+			return -1;
+	}
+
+	return ki_route_if_exists(msg, &s);
+}
+
 static int mod_init(void)
 {
 	/* Register RPC commands */
@@ -1078,6 +1104,16 @@ static sr_kemi_t sr_kemi_cfgutils_exports[] = {
 		{ SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
 	},
+	{ str_init("cfgutils"), str_init("check_route_exists"),
+		SR_KEMIP_INT, ki_check_route_exists,
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+	{ str_init("cfgutils"), str_init("route_if_exists"),
+		SR_KEMIP_INT, ki_route_if_exists,
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
 
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
 };




More information about the sr-dev mailing list