[sr-dev] git:master:273c6241: pv: added $viaZ(attr) - get the attributes of last via header

Daniel-Constantin Mierla miconda at gmail.com
Sat Jul 3 11:16:40 CEST 2021


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2021-07-03T10:54:10+02:00

pv: added $viaZ(attr) - get the attributes of last 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/273c6241637f663784695b073ac9e342d243b8bd.diff
Patch: https://github.com/kamailio/kamailio/commit/273c6241637f663784695b073ac9e342d243b8bd.patch

---

diff --git a/src/modules/pv/pv.c b/src/modules/pv/pv.c
index 532d5209d9..41c53eaa3f 100644
--- a/src/modules/pv/pv.c
+++ b/src/modules/pv/pv.c
@@ -548,6 +548,8 @@ static pv_export_t mod_pvs[] = {
 		pv_parse_ccp_attrs_name, 0, 0, 0},
 	{{"via0", (sizeof("via0")-1)}, PVT_OTHER, pv_get_via0, 0,
 		pv_parse_via_name, 0, 0, 0},
+	{{"viaZ", (sizeof("viaZ")-1)}, PVT_OTHER, pv_get_viaZ, 0,
+		pv_parse_via_name, 0, 0, 0},
 
 	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
 };
diff --git a/src/modules/pv/pv_core.c b/src/modules/pv/pv_core.c
index d361d23781..34998b9882 100644
--- a/src/modules/pv/pv_core.c
+++ b/src/modules/pv/pv_core.c
@@ -4537,7 +4537,7 @@ int pv_get_via_attr(sip_msg_t *msg, via_body_t *vb, pv_param_t *param,
 		pv_value_t *res)
 {
 	if(vb==NULL) {
-		LM_DBG("invalid via header\n");
+		LM_DBG("null via header\n");
 		return pv_get_null(msg, param, res);
 	}
 
@@ -4594,3 +4594,29 @@ int pv_get_via0(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
 
 	return pv_get_via_attr(msg, msg->via1, param, res);
 }
+
+/**
+ *
+ */
+int pv_get_viaZ(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
+{
+	hdr_field_t *hf = NULL;
+	via_body_t *vb = NULL;
+	via_body_t *vbZ = NULL;
+
+	if (parse_headers(msg, HDR_EOH_F, 0)<0) {
+		LM_DBG("failed to parse sip headers\n");
+		return pv_get_null(msg, param, res);
+	}
+
+	vbZ = msg->via1;
+	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) {
+				vbZ = vb;
+			}
+		}
+	}
+
+	return pv_get_via_attr(msg, vbZ, param, res);
+}
diff --git a/src/modules/pv/pv_core.h b/src/modules/pv/pv_core.h
index 26a278c0e7..19222bc63e 100644
--- a/src/modules/pv/pv_core.h
+++ b/src/modules/pv/pv_core.h
@@ -413,6 +413,7 @@ int pv_set_ccp_attrs(struct sip_msg* msg, pv_param_t *param,
 
 int pv_parse_via_name(pv_spec_p sp, str *in);
 int pv_get_via0(sip_msg_t *msg, pv_param_t *param, pv_value_t *res);
+int pv_get_viaZ(sip_msg_t *msg, pv_param_t *param, pv_value_t *res);
 
 #endif
 




More information about the sr-dev mailing list