[sr-dev] git:master:10bc5b24: pv: new variable $hflc(hname)
Daniel-Constantin Mierla
miconda at gmail.com
Tue Jun 8 13:28:17 CEST 2021
Module: kamailio
Branch: master
Commit: 10bc5b244db34e57beb9e5b4ec546396fb12a76b
URL: https://github.com/kamailio/kamailio/commit/10bc5b244db34e57beb9e5b4ec546396fb12a76b
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2021-06-08T13:25:54+02:00
pv: new variable $hflc(hname)
- return the number of bodies for known headers that can also be as a comma
separated list
- supported now is Via header
---
Modified: src/modules/pv/pv.c
Modified: src/modules/pv/pv_core.c
Modified: src/modules/pv/pv_core.h
---
Diff: https://github.com/kamailio/kamailio/commit/10bc5b244db34e57beb9e5b4ec546396fb12a76b.diff
Patch: https://github.com/kamailio/kamailio/commit/10bc5b244db34e57beb9e5b4ec546396fb12a76b.patch
---
diff --git a/src/modules/pv/pv.c b/src/modules/pv/pv.c
index 2738a8b7a2..3a904e3161 100644
--- a/src/modules/pv/pv.c
+++ b/src/modules/pv/pv.c
@@ -110,6 +110,8 @@ static pv_export_t mod_pvs[] = {
0, 0, 0},
{{"hfl", (sizeof("hfl")-1)}, PVT_HDR, pv_get_hfl, 0, pv_parse_hfl_name,
pv_parse_index, 0, 0},
+ {{"hflc", (sizeof("hflc")-1)}, PVT_HDRC, pv_get_hflc, 0, pv_parse_hfl_name,
+ 0, 0, 0},
{{"var", (sizeof("var")-1)}, PVT_SCRIPTVAR, pv_get_scriptvar,
pv_set_scriptvar, pv_parse_scriptvar_name, 0, 0, 0},
{{"vz", (sizeof("vz")-1)}, PVT_SCRIPTVAR, pv_get_scriptvar,
diff --git a/src/modules/pv/pv_core.c b/src/modules/pv/pv_core.c
index 1b39ef3fb8..a4bfe21985 100644
--- a/src/modules/pv/pv_core.c
+++ b/src/modules/pv/pv_core.c
@@ -2421,6 +2421,70 @@ int pv_get_hfl(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
return pv_get_hdr_helper(msg, param, res, &tv, idx, idxf);
}
+/**
+ *
+ */
+int pv_get_hflc(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
+{
+ pv_value_t tv = {0};
+ via_body_t *vb = NULL;
+ hdr_field_t *hf = NULL;
+ int n = 0;
+
+ if(msg==NULL || res==NULL || param==NULL)
+ return -1;
+
+ /* get the name */
+ if(param->pvn.type == PV_NAME_PVAR) {
+ if(pv_get_spec_name(msg, param, &tv)!=0 || (!(tv.flags&PV_VAL_STR))) {
+ LM_ERR("invalid name\n");
+ return pv_get_sintval(msg, param, res, 0);
+ }
+ } else {
+ if(param->pvn.u.isname.type == AVP_NAME_STR) {
+ tv.flags = PV_VAL_STR;
+ tv.rs = param->pvn.u.isname.name.s;
+ } else {
+ tv.flags = 0;
+ tv.ri = param->pvn.u.isname.name.n;
+ }
+ }
+
+ if (parse_headers(msg, HDR_EOH_F, 0)<0) {
+ LM_DBG("failed to parse sip headers\n");
+ return pv_get_sintval(msg, param, res, 0);
+ }
+
+ if((tv.flags == 0) && (tv.ri==HDR_VIA_T)) {
+ if(msg->h_via1==NULL) {
+ LM_WARN("no Via header\n");
+ return pv_get_sintval(msg, param, res, 0);
+ }
+ /* count Via header bodies */
+ for(hf=msg->h_via1; hf!=NULL; hf=hf->next) {
+ if(hf->type==HDR_VIA_T) {
+ for(vb=(via_body_t*)hf->parsed; vb!=NULL; vb=vb->next) {
+ n++;
+ }
+ }
+ }
+ return pv_get_sintval(msg, param, res, n);
+ }
+
+ for (hf=msg->headers; hf; hf=hf->next) {
+ if(tv.flags == 0) {
+ if (tv.ri==hf->type) {
+ n++;
+ }
+ } else {
+ if (cmp_hdrname_str(&hf->name, &tv.rs)==0) {
+ n++;
+ }
+ }
+ }
+ return pv_get_sintval(msg, param, res, n);
+}
+
/**
*
*/
diff --git a/src/modules/pv/pv_core.h b/src/modules/pv/pv_core.h
index 179df8fd0b..d001104647 100644
--- a/src/modules/pv/pv_core.h
+++ b/src/modules/pv/pv_core.h
@@ -255,6 +255,8 @@ int pv_get_hdrc(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
int pv_get_hfl(sip_msg_t *msg, pv_param_t *param, pv_value_t *res);
+int pv_get_hflc(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
+
int pv_get_scriptvar(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res);
More information about the sr-dev
mailing list