From: Daniel-Constantin Mierla Date: Thu, 20 Aug 2020 13:57:57 +0000 (+0200) Subject: cfgutils: exported route check functions to kemi X-Git-Tag: 5.4.1~12 X-Git-Url: http://git.sip-router.org/cgi-bin/gitweb.cgi?p=kamailio;a=commitdiff_plain;h=daab7955e91c4537547c89eacb7ecd0f136bffdb cfgutils: exported route check functions to kemi (cherry picked from commit ecba550f5d35435adfa9c692cec8cee6cae8a77b) --- 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 } } };