Module: kamailio Branch: master Commit: c9ec6cad7300d40beef095116bcdd361bc9690c4 URL: https://github.com/kamailio/kamailio/commit/c9ec6cad7300d40beef095116bcdd361bc9690c4
Author: Daniel-Constantin Mierla <mico...@gmail.com> Committer: Daniel-Constantin Mierla <mico...@gmail.com> Date: 2024-11-25T19:58:06+01:00 dispatcher: function to fetch by group id and uri --- Modified: src/modules/dispatcher/dispatcher.c --- Diff: https://github.com/kamailio/kamailio/commit/c9ec6cad7300d40beef095116bcdd361bc9690c4.diff Patch: https://github.com/kamailio/kamailio/commit/c9ec6cad7300d40beef095116bcdd361bc9690c4.patch --- diff --git a/src/modules/dispatcher/dispatcher.c b/src/modules/dispatcher/dispatcher.c index d9626000ddc..852296bbad1 100644 --- a/src/modules/dispatcher/dispatcher.c +++ b/src/modules/dispatcher/dispatcher.c @@ -185,6 +185,7 @@ static int w_ds_reload(struct sip_msg* msg, char*, char*); static int w_ds_is_active(sip_msg_t *msg, char *pset, char *p2); static int w_ds_is_active_uri(sip_msg_t *msg, char *pset, char *puri); static int w_ds_dsg_fetch(sip_msg_t *msg, char *pset, char *p2); +static int w_ds_dsg_fetch_uri(sip_msg_t *msg, char *pset, char *puri); static int w_ds_oc_set_attrs(sip_msg_t*, char*, char*, char*, char*, char*); static int fixup_ds_is_from_list(void** param, int param_no); @@ -199,6 +200,7 @@ static int pv_parse_dsv(pv_spec_p sp, str *in); static int pv_get_dsg(sip_msg_t *msg, pv_param_t *param, pv_value_t *res); static int pv_parse_dsg(pv_spec_p sp, str *in); static void ds_dsg_fetch(int dg); +static void ds_dsg_fetch_uri(int dg, str *uri); static pv_export_t mod_pvs[] = { { {"dsv", (sizeof("dsv")-1)}, PVT_OTHER, pv_get_dsv, 0, @@ -266,6 +268,8 @@ static cmd_export_t cmds[]={ fixup_isiii, fixup_free_isiii, ANY_ROUTE}, {"ds_dsg_fetch", (cmd_function)w_ds_dsg_fetch, 1, fixup_igp_null, fixup_free_igp_null, ANY_ROUTE}, + {"ds_dsg_fetch_uri", (cmd_function)w_ds_dsg_fetch_uri, 2, + fixup_igp_spve, fixup_free_igp_spve, ANY_ROUTE}, {0,0,0,0,0,0} }; @@ -1367,14 +1371,32 @@ static int pv_parse_dsv(pv_spec_p sp, str *in) /** * */ -static int _pv_dsg_fetch = 1; +static int _pv_dsg_fetch_dg = 1; +static str _pv_dsg_fetch_uri = STR_NULL; /** * */ static void ds_dsg_fetch(int dg) { - _pv_dsg_fetch = dg; + _pv_dsg_fetch_dg = dg; + if(_pv_dsg_fetch_uri.s != NULL) { + pkg_free(_pv_dsg_fetch_uri.s); + } + _pv_dsg_fetch_uri.s = NULL; + _pv_dsg_fetch_uri.len = 0; +} + +/** + * + */ +static void ds_dsg_fetch_uri(int dg, str *uri) +{ + _pv_dsg_fetch_dg = dg; + if(_pv_dsg_fetch_uri.s != NULL) { + pkg_free(_pv_dsg_fetch_uri.s); + } + pkg_str_dup(&_pv_dsg_fetch_uri, uri); } /** @@ -1393,6 +1415,28 @@ static int w_ds_dsg_fetch(sip_msg_t *msg, char *pset, char *p2) return 1; } +/** + * + */ +static int w_ds_dsg_fetch_uri(sip_msg_t *msg, char *pset, char *puri) +{ + int set; + str suri = STR_NULL; + + if(fixup_get_ivalue(msg, (gparam_p)pset, &set) != 0) { + LM_ERR("cannot get set id param value\n"); + return -1; + } + if(fixup_get_svalue(msg, (gparam_p)puri, &suri) != 0) { + LM_ERR("cannot get uri param value\n"); + return -1; + } + + ds_dsg_fetch_uri(set, &suri); + + return 1; +} + /** * */ @@ -1439,16 +1483,19 @@ static int pv_get_dsg(sip_msg_t *msg, pv_param_t *param, pv_value_t *res) int active = 0; int inactive = 0; int j = 0; + ds_ocdata_t ocdata; if(param == NULL) { return -1; } - dsg = ds_list_lookup(_pv_dsg_fetch); + dsg = ds_list_lookup(_pv_dsg_fetch_dg); if(dsg == NULL) { return pv_get_null(msg, param, res); } + memset(&ocdata, 0, sizeof(ds_ocdata_t)); + lock_get(&dsg->lock); count = dsg->nr; for(j = 0; j < dsg->nr; j++) { @@ -1457,6 +1504,14 @@ static int pv_get_dsg(sip_msg_t *msg, pv_param_t *param, pv_value_t *res) } else { active++; } + if(_pv_dsg_fetch_uri.s != NULL && _pv_dsg_fetch_uri.len > 0) { + if((_pv_dsg_fetch_uri.len == dsg->dlist[j].uri.len) + && (strncmp(dsg->dlist[j].uri.s, _pv_dsg_fetch_uri.s, + _pv_dsg_fetch_uri.len) + == 0)) { + memcpy(&ocdata, &dsg->dlist[j].ocdata, sizeof(ds_ocdata_t)); + } + } } lock_release(&dsg->lock); _______________________________________________ Kamailio - Development Mailing List -- sr-dev@lists.kamailio.org To unsubscribe send an email to sr-dev-le...@lists.kamailio.org Important: keep the mailing list in the recipients, do not reply only to the sender!