[sr-dev] git:master:e8fa2b3e: pv: support Contact header in $hfl(...)
Daniel-Constantin Mierla
miconda at gmail.com
Thu Jun 3 11:12:24 CEST 2021
Module: kamailio
Branch: master
Commit: e8fa2b3e8e5a789ac6d6d35f75ec61d09f487d6c
URL: https://github.com/kamailio/kamailio/commit/e8fa2b3e8e5a789ac6d6d35f75ec61d09f487d6c
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2021-06-03T11:11:50+02:00
pv: support Contact header in $hfl(...)
---
Modified: src/modules/pv/pv_core.c
---
Diff: https://github.com/kamailio/kamailio/commit/e8fa2b3e8e5a789ac6d6d35f75ec61d09f487d6c.diff
Patch: https://github.com/kamailio/kamailio/commit/e8fa2b3e8e5a789ac6d6d35f75ec61d09f487d6c.patch
---
diff --git a/src/modules/pv/pv_core.c b/src/modules/pv/pv_core.c
index 073d0dccb8..8f398cdf43 100644
--- a/src/modules/pv/pv_core.c
+++ b/src/modules/pv/pv_core.c
@@ -2191,6 +2191,7 @@ int pv_get_hfl(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
pv_value_t tv = {0};
via_body_t *vb = NULL;
rr_t *rrb = NULL;
+ contact_t *cb = NULL;
hdr_field_t *hf = NULL;
int n = 0;
str sval = STR_NULL;
@@ -2358,6 +2359,62 @@ int pv_get_hfl(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
return pv_get_null(msg, param, res);
}
+ if((tv.flags == 0) && (tv.ri==HDR_CONTACT_T)) {
+ if(msg->contact==NULL) {
+ LM_DBG("no Contact header\n");
+ return pv_get_null(msg, param, res);
+ }
+ if(parse_contact_headers(msg) < 0) {
+ LM_DBG("failed to parse Contact headers\n");
+ return pv_get_null(msg, param, res);
+ }
+ if(idx<0) {
+ n = 1;
+ /* count Contact header bodies */
+ for(hf=msg->contact; hf!=NULL; hf=hf->next) {
+ if(hf->type==HDR_CONTACT_T) {
+ for(cb=(((contact_body_t*)hf->parsed)->contacts);
+ cb!=NULL; cb=cb->next) {
+ n++;
+ }
+ }
+ }
+
+ idx = -idx;
+ if(idx>n) {
+ LM_DBG("index out of range\n");
+ return pv_get_null(msg, param, res);
+ }
+ idx = n - idx;
+ }
+ if(idx==0) {
+ cb = ((contact_body_t*)msg->contact->parsed)->contacts;
+ sval.s = cb->name.s;
+ sval.len = cb->len;
+ trim(&sval);
+ res->rs = sval;
+ return 0;
+ }
+ n=0;
+ for(hf=msg->contact; hf!=NULL; hf=hf->next) {
+ if(hf->type==HDR_CONTACT_T) {
+ for(cb=(((contact_body_t*)hf->parsed)->contacts);
+ cb!=NULL; cb=cb->next) {
+ if(n==idx) {
+ sval.s = cb->name.s;
+ sval.len = cb->len;
+ trim(&sval);
+ res->rs = sval;
+ return 0;
+ }
+ n++;
+ }
+ }
+ }
+ LM_DBG("unexpected contact index out of range\n");
+ return pv_get_null(msg, param, res);
+ }
+
return pv_get_hdr_helper(msg, param, res, &tv, idx, idxf);
}
More information about the sr-dev
mailing list