Browse code

pv_headers: fix $x_hdr index on get

* previously we where not supporting pseudo-variables as index

Victor Seva authored on 04/09/2020 09:19:33 • Victor Seva committed on 04/09/2020 14:11:03
Showing 1 changed files
... ...
@@ -539,38 +539,33 @@ int pvh_get_header(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
539 539
 	sr_xavp_t *xavi = NULL;
540 540
 	sr_xval_t *xval = NULL;
541 541
 	pv_value_t tv;
542
-	str hname = STR_NULL;
543
-	int idx = 0;
542
+	str *hname = NULL;
543
+	int idx, idxf;
544 544
 	int cnt = 0;
545 545
 
546
-	idx = param->pvi.u.ival;
546
+	if(pv_get_spec_name(msg, param, &tv) != 0 || (!(tv.flags & PV_VAL_STR))) {
547
+		LM_ERR("invalid header name, must be a string\n");
548
+		return -1;
549
+	}
550
+	hname = &tv.rs;
547 551
 
548
-	if(param->pvn.type == PV_NAME_PVAR) {
549
-		if(pv_get_spec_value(msg, (pv_spec_p)(param->pvn.u.dname), &tv) != 0) {
550
-			LM_ERR("cannot get avp value\n");
551
-			return -1;
552
-		}
553
-		if(!(tv.flags & PV_VAL_STR)) {
554
-			return pv_get_null(msg, param, res);
555
-		}
556
-		hname = tv.rs;
557
-	} else if(param->pvn.u.isname.type == AVP_NAME_STR) {
558
-		hname = param->pvn.u.isname.name.s;
559
-	} else {
560
-		return pv_get_null(msg, param, res);
552
+	/* get the index */
553
+	if(pv_get_spec_index(msg, param, &idx, &idxf) != 0) {
554
+		LM_ERR("invalid index\n");
555
+		return -1;
561 556
 	}
562 557
 
563 558
 	if(idx < 0) {
564
-		if((xavi = pvh_xavi_get_child(msg, &xavi_name, &hname)) == NULL)
559
+		if((xavi = pvh_xavi_get_child(msg, &xavi_name, hname)) == NULL)
565 560
 			cnt = 0;
566 561
 		else
567
-			cnt = xavi_count(&hname, &xavi);
562
+			cnt = xavi_count(hname, &xavi);
568 563
 		idx = idx + cnt;
569 564
 		if(idx < 0)
570
-			pv_get_null(msg, param, res);
565
+			return pv_get_null(msg, param, res);
571 566
 	}
572 567
 
573
-	xval = pvh_xavi_get_value(msg, &xavi_name, &hname, idx);
568
+	xval = pvh_xavi_get_value(msg, &xavi_name, hname, idx);
574 569
 
575 570
 	if(xval == NULL || !xval->v.s.s)
576 571
 		return pv_get_null(msg, param, res);