Browse code

pv: added $viaZ(attr) - get the attributes of last via header

Daniel-Constantin Mierla authored on 03/07/2021 08:54:10
Showing 3 changed files
... ...
@@ -548,6 +548,8 @@ static pv_export_t mod_pvs[] = {
548 548
 		pv_parse_ccp_attrs_name, 0, 0, 0},
549 549
 	{{"via0", (sizeof("via0")-1)}, PVT_OTHER, pv_get_via0, 0,
550 550
 		pv_parse_via_name, 0, 0, 0},
551
+	{{"viaZ", (sizeof("viaZ")-1)}, PVT_OTHER, pv_get_viaZ, 0,
552
+		pv_parse_via_name, 0, 0, 0},
551 553
 
552 554
 	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
553 555
 };
... ...
@@ -4537,7 +4537,7 @@ int pv_get_via_attr(sip_msg_t *msg, via_body_t *vb, pv_param_t *param,
4537 4537
 		pv_value_t *res)
4538 4538
 {
4539 4539
 	if(vb==NULL) {
4540
-		LM_DBG("invalid via header\n");
4540
+		LM_DBG("null via header\n");
4541 4541
 		return pv_get_null(msg, param, res);
4542 4542
 	}
4543 4543
 
... ...
@@ -4594,3 +4594,29 @@ int pv_get_via0(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
4594 4594
 
4595 4595
 	return pv_get_via_attr(msg, msg->via1, param, res);
4596 4596
 }
4597
+
4598
+/**
4599
+ *
4600
+ */
4601
+int pv_get_viaZ(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
4602
+{
4603
+	hdr_field_t *hf = NULL;
4604
+	via_body_t *vb = NULL;
4605
+	via_body_t *vbZ = NULL;
4606
+
4607
+	if (parse_headers(msg, HDR_EOH_F, 0)<0) {
4608
+		LM_DBG("failed to parse sip headers\n");
4609
+		return pv_get_null(msg, param, res);
4610
+	}
4611
+
4612
+	vbZ = msg->via1;
4613
+	for(hf=msg->h_via1; hf!=NULL; hf=hf->next) {
4614
+		if(hf->type==HDR_VIA_T) {
4615
+			for(vb=(via_body_t*)hf->parsed; vb!=NULL; vb=vb->next) {
4616
+				vbZ = vb;
4617
+			}
4618
+		}
4619
+	}
4620
+
4621
+	return pv_get_via_attr(msg, vbZ, param, res);
4622
+}
... ...
@@ -413,6 +413,7 @@ int pv_set_ccp_attrs(struct sip_msg* msg, pv_param_t *param,
413 413
 
414 414
 int pv_parse_via_name(pv_spec_p sp, str *in);
415 415
 int pv_get_via0(sip_msg_t *msg, pv_param_t *param, pv_value_t *res);
416
+int pv_get_viaZ(sip_msg_t *msg, pv_param_t *param, pv_value_t *res);
416 417
 
417 418
 #endif
418 419