[sr-dev] git:master:a10da3a8: pv: parse header name given with variable to $hdr() and $hdrc()

Daniel-Constantin Mierla miconda at gmail.com
Tue Aug 23 09:58:32 CEST 2022


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2022-08-23T09:58:02+02:00

pv: parse header name given with variable to $hdr() and $hdrc()

---

Modified: src/modules/pv/pv_core.c

---

Diff:  https://github.com/kamailio/kamailio/commit/a10da3a8802fd02bab9e8c655aa845d121370fd4.diff
Patch: https://github.com/kamailio/kamailio/commit/a10da3a8802fd02bab9e8c655aa845d121370fd4.patch

---

diff --git a/src/modules/pv/pv_core.c b/src/modules/pv/pv_core.c
index 5d310ecea7..1410d80b43 100644
--- a/src/modules/pv/pv_core.c
+++ b/src/modules/pv/pv_core.c
@@ -2128,6 +2128,7 @@ int pv_get_hdr(sip_msg_t *msg,  pv_param_t *param, pv_value_t *res)
 	int idx;
 	int idxf;
 	pv_value_t tv = {0};
+	hdr_field_t thdr = {0};
 
 	if(msg==NULL || res==NULL || param==NULL)
 		return -1;
@@ -2138,6 +2139,15 @@ int pv_get_hdr(sip_msg_t *msg,  pv_param_t *param, pv_value_t *res)
 			LM_ERR("invalid name\n");
 			return -1;
 		}
+		parse_hname2_short(tv.rs.s, tv.rs.s + tv.rs.len, &thdr);
+		if(thdr.type==HDR_ERROR_T) {
+			LM_ERR("error parsing header name [%.*s]\n", tv.rs.len, tv.rs.s);
+			return pv_get_null(msg, param, res);
+		}
+		if(thdr.type!=HDR_OTHER_T) {
+			tv.flags = 0;
+			tv.ri = thdr.type;
+		}
 	} else {
 		if(param->pvn.u.isname.type == AVP_NAME_STR) {
 			tv.flags = PV_VAL_STR;
@@ -2162,6 +2172,7 @@ int pv_get_hdrc(struct sip_msg *msg,  pv_param_t *param, pv_value_t *res)
 {
 	pv_value_t tv;
 	struct hdr_field *hf;
+	hdr_field_t thdr = {0};
 	int hcount;
 
 	if(msg==NULL || res==NULL || param==NULL)
@@ -2177,6 +2188,15 @@ int pv_get_hdrc(struct sip_msg *msg,  pv_param_t *param, pv_value_t *res)
 			LM_ERR("invalid name\n");
 			return pv_get_sintval(msg, param, res, hcount);
 		}
+		parse_hname2_short(tv.rs.s, tv.rs.s + tv.rs.len, &thdr);
+		if(thdr.type==HDR_ERROR_T) {
+			LM_ERR("error parsing header name [%.*s]\n", tv.rs.len, tv.rs.s);
+			return pv_get_sintval(msg, param, res, 0);
+		}
+		if(thdr.type!=HDR_OTHER_T) {
+			tv.flags = 0;
+			tv.ri = thdr.type;
+		}
 	} else {
 		if(param->pvn.u.isname.type == AVP_NAME_STR)
 		{




More information about the sr-dev mailing list