Discussion:
[sr-dev] git:master:e8fa2b3e: pv: support Contact header in $hfl(...)
Daniel-Constantin Mierla
2021-06-03 09:12:24 UTC
Permalink
Content preview: Module: kamailio Branch: master Commit: e8fa2b3e8e5a789ac6d6d35f75ec61d09f487d6c
URL: https://github.com/kamailio/kamailio/commit/e8fa2b3e8e5a789ac6d6d35f75ec61d09f487d6c
Author: Daniel-Constantin Mierla <***@gmail.com> Committer: Daniel-Constantin
Mierla <***@gmail.com> Date: 2021-06-03T11:11:50+02:00

Content analysis details: (-2.4 points, 5.5 required)

pts rule name description
---- ---------------------- --------------------------------------------------
-1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP
-1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1%
[score: 0.0000]
1.0 FORGED_GMAIL_RCVD 'From' gmail.com does not match 'Received'
headers
0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level
mail domains are different
0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail
provider (miconda[at]gmail.com)
0.0 DKIM_ADSP_CUSTOM_MED No valid author signature, adsp_override is
CUSTOM_MED
0.2 FREEMAIL_FORGED_FROMDOMAIN 2nd level domains in From and
EnvelopeFrom freemail headers are
different
-1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list
manager

Module: kamailio
Branch: master
Commit: e8fa2b3e8e5a789ac6d6d35f75ec61d09f487d6c
URL: https://github.com/kamailio/kamailio/commit/e8fa2b3e8e5a789ac6d6d35f75ec61d09f487d6c

Author: Daniel-Constantin Mierla <***@gmail.com>
Committer: Daniel-Constantin Mierla <***@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);
}

Loading...