From ae3e2a92491fc650b3620bd28a92622506c39532 Mon Sep 17 00:00:00 2001 From: Stefan Mititelu Date: Tue, 13 Sep 2022 11:24:47 +0300 Subject: [PATCH 1/3] ratelimit: export functions to kemi --- src/modules/ratelimit/ratelimit.c | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/modules/ratelimit/ratelimit.c b/src/modules/ratelimit/ratelimit.c index efecfaa779c..4973694321c 100644 --- a/src/modules/ratelimit/ratelimit.c +++ b/src/modules/ratelimit/ratelimit.c @@ -42,6 +42,7 @@ #include "../../core/data_lump_rpl.h" #include "../../core/counters.h" #include "../../core/rpc_lookup.h" +#include "../../core/kemi.h" #include "rl_statistics.h" @@ -199,6 +200,8 @@ static int w_rl_check_forced(struct sip_msg*, char *, char *); static int w_rl_check_forced_pipe(struct sip_msg*, char *, char *); static int add_queue_params(modparam_t, void *); static int add_pipe_params(modparam_t, void *); +static int ki_rl_check(struct sip_msg *msg); +static int ki_rl_check_pipe(struct sip_msg *msg, int pipe); /* RESERVED for future use static int set_load_source(modparam_t, void *); */ @@ -1323,3 +1326,33 @@ static rpc_export_t rpc_methods[] = { {0, 0, 0, 0} }; +static sr_kemi_t sr_kemi_ratelimit_exports[] = { + { str_init("ratelimit"), str_init("rl_check"), + SR_KEMIP_INT, ki_rl_check, + { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + { str_init("ratelimit"), str_init("rl_check_pipe"), + SR_KEMIP_INT, ki_rl_check_pipe, + { SR_KEMIP_INT, 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 } } + +}; + +static int ki_rl_check(struct sip_msg *msg) { + return rl_check(msg, -1); +} + +static int ki_rl_check_pipe(struct sip_msg *msg, int pipe) { + + LM_DBG("trying kemi pipe %d\n", pipe); + return rl_check(msg, pipe); +} + +int mod_register(char *path, int *dlflags, void *p1, void *p2) +{ + sr_kemi_modules_add(sr_kemi_ratelimit_exports); + return 0; +} From d6bfdfa123cee7259d65848933ff30c4b7818030 Mon Sep 17 00:00:00 2001 From: Stefan Mititelu Date: Tue, 13 Sep 2022 11:41:04 +0300 Subject: [PATCH 2/3] siputils: export is_gruu() to kemi --- src/modules/siputils/siputils.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/modules/siputils/siputils.c b/src/modules/siputils/siputils.c index e7c5e3dcfca..88ed33050b6 100644 --- a/src/modules/siputils/siputils.c +++ b/src/modules/siputils/siputils.c @@ -118,6 +118,7 @@ static int fixup_get_uri_param(void** param, int param_no); static int free_fixup_get_uri_param(void** param, int param_no); static int fixup_option(void** param, int param_no); +static int ki_is_gruu(sip_msg_t *msg); char *contact_flds_separator = DEFAULT_SEPARATOR; @@ -726,11 +727,20 @@ static sr_kemi_t sr_kemi_siputils_exports[] = { { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } }, + { str_init("siputils"), str_init("is_gruu"), + SR_KEMIP_INT, ki_is_gruu, + { SR_KEMIP_NONE, 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 } } }; /* clang-format on */ +static int ki_is_gruu(sip_msg_t *msg) { + return w_is_gruu(msg, NULL, NULL); +} + /** * */ From 245d91986aff9c0ade4b2f0b51189c7c577f56d7 Mon Sep 17 00:00:00 2001 From: Stefan Mititelu Date: Wed, 14 Sep 2022 13:19:05 +0300 Subject: [PATCH 3/3] dialplan: export dp_translate to kemi --- src/modules/dialplan/dialplan.c | 90 +++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/src/modules/dialplan/dialplan.c b/src/modules/dialplan/dialplan.c index 7770679a453..0df83bbee68 100644 --- a/src/modules/dialplan/dialplan.c +++ b/src/modules/dialplan/dialplan.c @@ -75,6 +75,10 @@ static int dp_reload_f(struct sip_msg* msg); static int w_dp_replace(sip_msg_t* msg, char* pid, char* psrc, char* pdst); static int w_dp_match(sip_msg_t* msg, char* pid, char* psrc); +static int ki_dp_translate(sip_msg_t* msg, int id, str *input, str *output); +static int ki_dp_translate_1_args(sip_msg_t* msg, int id); +static int ki_dp_translate_3_args(sip_msg_t* msg, int id, str *input, str *output); + int dp_replace_fixup(void** param, int param_no); int dp_replace_fixup_free(void** param, int param_no); @@ -846,11 +850,97 @@ static sr_kemi_t sr_kemi_dialplan_exports[] = { { SR_KEMIP_INT, SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } }, + { str_init("dialplan"), str_init("dp_transalte"), + SR_KEMIP_INT, ki_dp_translate_1_args, + { SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + { str_init("dialplan"), str_init("dp_transalte"), + SR_KEMIP_INT, ki_dp_translate_3_args, + { SR_KEMIP_INT, SR_KEMIP_STR, SR_KEMIP_STR, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } } }; /* clang-format on */ +static int ki_dp_translate(sip_msg_t* msg, int id, str *input_spv, str *output_spv) { + str input, output; + dpl_id_p idp; + str attrs, *outattrs; + pv_spec_t *pvs_i = NULL, *pvs_o = NULL; + + if (!msg) + return -1; + + if (input_spv == NULL || input_spv->s == NULL || input_spv->len <= 0 || + output_spv == NULL || output_spv->s == NULL || output_spv->len <= 0) { + LM_ERR("invalid destination var name for input or output\n"); + return -1; + } + + if (input_spv == NULL && output_spv == NULL) { + pvs_i = pv_cache_get(&default_param_s); + pvs_o = pv_cache_get(&default_param_s); + } else { + pvs_i = pv_cache_get(input_spv); + pvs_o = pv_cache_get(output_spv); + } + + if (pvs_i == NULL || pvs_o == NULL) { + LM_ERR("cannot get pv spec for input or output\n"); + return -1; + } + + if ((pvs_i->type!=PVT_AVP && pvs_i->type!=PVT_XAVP && pvs_i->type!=PVT_SCRIPTVAR && + pvs_i->type!=PVT_RURI && pvs_i->type!=PVT_RURI_USERNAME) || + (pvs_o->type!=PVT_AVP && pvs_o->type!=PVT_XAVP && pvs_o->type!=PVT_SCRIPTVAR && + pvs_o->type!=PVT_RURI && pvs_o->type!=PVT_RURI_USERNAME)) { + LM_ERR("type of pv error\n"); + return -1; + } + + if ((idp = select_dpid(id)) ==0 ){ + LM_DBG("no information available for dpid %i\n", id); + return -2; + } + + /* get the input */ + if (dp_get_svalue(msg, pvs_i, &input)!=0){ + LM_ERR("invalid param 2\n"); + return -1; + } + + LM_DBG("input is %.*s\n", input.len, input.s); + + outattrs = (!attr_pvar)?NULL:&attrs; + if (dp_translate_helper(msg, &input, &output, idp, outattrs)!=0) { + LM_DBG("could not translate %.*s " + "with dpid %i\n", input.len, input.s, idp->dp_id); + return -1; + } + LM_DBG("input %.*s with dpid %i => output %.*s\n", + input.len, input.s, idp->dp_id, output.len, output.s); + + /* set the output */ + if (dp_update(msg, pvs_o, &output, outattrs) !=0){ + LM_ERR("cannot set the output\n"); + return -1; + } + + return 1; + +} + +static int ki_dp_translate_1_args(sip_msg_t* msg, int id) { + return ki_dp_translate(msg, id, NULL, NULL); +} + +static int ki_dp_translate_3_args(sip_msg_t* msg, int id, str *input, str *output) { + return ki_dp_translate(msg, id, input, output); +} + /** * */