Module: kamailio Branch: master Commit: 0f8da1746e79066a423b0808195c061701bb29da URL: https://github.com/kamailio/kamailio/commit/0f8da1746e79066a423b0808195c0617...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2015-04-21T19:03:32+02:00
pv: new config var - $sbranch(key)
- a static branch structure that can be used for config operations - the key can be like for $branch(key) - the static branch is not used for outbound routing, it is just a local container
---
Modified: modules/pv/pv.c Modified: modules/pv/pv_branch.c Modified: modules/pv/pv_branch.h
---
Diff: https://github.com/kamailio/kamailio/commit/0f8da1746e79066a423b0808195c0617... Patch: https://github.com/kamailio/kamailio/commit/0f8da1746e79066a423b0808195c0617...
---
diff --git a/modules/pv/pv.c b/modules/pv/pv.c index d969adc..fb122a0 100644 --- a/modules/pv/pv.c +++ b/modules/pv/pv.c @@ -68,6 +68,9 @@ static pv_export_t mod_pvs[] = { { {"branch", sizeof("branch")-1}, /* branch attributes */ PVT_CONTEXT, pv_get_branchx, pv_set_branchx, pv_parse_branchx_name, pv_parse_index, 0, 0 }, + { {"sbranch", sizeof("sbranch")-1}, /* static branch attributes */ + PVT_CONTEXT, pv_get_sbranch, pv_set_sbranch, + pv_parse_branchx_name, 0, 0, 0 }, { {"mi", (sizeof("mi")-1)}, /* message id */ PVT_OTHER, pv_get_msgid, 0, 0, 0, 0, 0}, diff --git a/modules/pv/pv_branch.c b/modules/pv/pv_branch.c index 24e22a6..521e4b9 100644 --- a/modules/pv/pv_branch.c +++ b/modules/pv/pv_branch.c @@ -27,22 +27,27 @@ #include "pv_core.h" #include "pv_branch.h"
-int pv_get_branchx(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res) +static branch_t _pv_sbranch = {0}; + +int pv_get_branchx_helper(sip_msg_t *msg, pv_param_t *param, + pv_value_t *res, int btype) { int idx = 0; int idxf = 0; branch_t *br;
- /* get the index */ - if(pv_get_spec_index(msg, param, &idx, &idxf)!=0) - { - LM_ERR("invalid index\n"); - return pv_get_null(msg, param, res); + if(btype==1) { + br = &_pv_sbranch; + } else { + /* get the index */ + if(pv_get_spec_index(msg, param, &idx, &idxf)!=0) + { + LM_ERR("invalid index\n"); + return pv_get_null(msg, param, res); + } + br = get_sip_branch(idx); }
- br = get_sip_branch(idx); - /* branch(count) doesn't need a valid branch, everything else does */ if(br->len == 0 && ( param->pvn.u.isname.name.n != 5/* count*/ )) { @@ -88,8 +93,14 @@ int pv_get_branchx(struct sip_msg *msg, pv_param_t *param, return 0; }
-int pv_set_branchx(struct sip_msg* msg, pv_param_t *param, - int op, pv_value_t *val) +int pv_get_branchx(sip_msg_t *msg, pv_param_t *param, + pv_value_t *res) +{ + return pv_get_branchx_helper(msg, param, res, 0); +} + +int pv_set_branchx_helper(sip_msg_t *msg, pv_param_t *param, + int op, pv_value_t *val, int btype) { int idx = 0; int idxf = 0; @@ -105,15 +116,18 @@ int pv_set_branchx(struct sip_msg* msg, pv_param_t *param, return -1; }
- /* get the index */ - if(pv_get_spec_index(msg, param, &idx, &idxf)!=0) - { - LM_ERR("invalid index\n"); - return -1; + if(btype==1) { + br = &_pv_sbranch; + } else { + /* get the index */ + if(pv_get_spec_index(msg, param, &idx, &idxf)!=0) + { + LM_ERR("invalid index\n"); + return -1; + } + br = get_sip_branch(idx); }
- br = get_sip_branch(idx); - if(br==NULL) { LM_DBG("no branch to operate on\n"); @@ -283,6 +297,12 @@ int pv_set_branchx(struct sip_msg* msg, pv_param_t *param, return 0; }
+int pv_set_branchx(sip_msg_t *msg, pv_param_t *param, + int op, pv_value_t *val) +{ + return pv_set_branchx_helper(msg, param, op, val, 0); +} + int pv_parse_branchx_name(pv_spec_p sp, str *in) { if(sp==NULL || in==NULL || in->len<=0) @@ -339,6 +359,18 @@ int pv_parse_branchx_name(pv_spec_p sp, str *in) return -1; }
+int pv_get_sbranch(sip_msg_t *msg, pv_param_t *param, + pv_value_t *res) +{ + return pv_get_branchx_helper(msg, param, res, 1); +} + +int pv_set_sbranch(sip_msg_t *msg, pv_param_t *param, + int op, pv_value_t *val) +{ + return pv_set_branchx_helper(msg, param, op, val, 1); +} + int pv_get_sndfrom(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { diff --git a/modules/pv/pv_branch.h b/modules/pv/pv_branch.h index 8ef5c2c..d9c3fc6 100644 --- a/modules/pv/pv_branch.h +++ b/modules/pv/pv_branch.h @@ -29,6 +29,11 @@ int pv_set_branchx(struct sip_msg* msg, pv_param_t *param, int op, pv_value_t *val); int pv_parse_branchx_name(pv_spec_p sp, str *in);
+int pv_get_sbranch(sip_msg_t *msg, pv_param_t *param, + pv_value_t *res); +int pv_set_sbranch(sip_msg_t *msg, pv_param_t *param, + int op, pv_value_t *val); + int pv_get_sndto(struct sip_msg *msg, pv_param_t *param, pv_value_t *res); int pv_get_sndfrom(struct sip_msg *msg, pv_param_t *param,