Browse code

pv: support Record/-Route headers for $hflc(...)

Daniel-Constantin Mierla authored on 09/06/2021 11:33:06
Showing 1 changed files
... ...
@@ -2428,6 +2428,7 @@ int pv_get_hflc(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
2428 2428
 {
2429 2429
 	pv_value_t tv = {0};
2430 2430
 	via_body_t *vb = NULL;
2431
+	rr_t *rrb = NULL;
2431 2432
 	hdr_field_t *hf = NULL;
2432 2433
 	int n = 0;
2433 2434
 
... ...
@@ -2471,6 +2472,33 @@ int pv_get_hflc(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
2471 2472
 		return pv_get_sintval(msg, param, res, n);
2472 2473
 	}
2473 2474
 
2475
+	if((tv.flags == 0) && (tv.ri==HDR_RECORDROUTE_T || tv.ri==HDR_ROUTE_T)) {
2476
+		if(tv.ri==HDR_RECORDROUTE_T) {
2477
+			hf=msg->record_route;
2478
+		} else {
2479
+			hf=msg->route;
2480
+		}
2481
+		if(hf==NULL) {
2482
+			LM_DBG("no %s header\n", (tv.ri==HDR_ROUTE_T)?"route":"record-route");
2483
+			return pv_get_sintval(msg, param, res, 0);
2484
+		}
2485
+
2486
+		/* count Record-Route/Route header bodies */
2487
+		for(; hf!=NULL; hf=hf->next) {
2488
+			if(hf->type==tv.ri) {
2489
+				if(parse_rr(hf) == -1) {
2490
+					LM_ERR("failed parsing %s header\n",
2491
+							(tv.ri==HDR_ROUTE_T)?"route":"record-route");
2492
+					return pv_get_sintval(msg, param, res, 0);
2493
+				}
2494
+				for(rrb=(rr_t*)hf->parsed; rrb!=NULL; rrb=rrb->next) {
2495
+					n++;
2496
+				}
2497
+			}
2498
+		}
2499
+		return pv_get_sintval(msg, param, res, n);
2500
+	}
2501
+
2474 2502
 	for (hf=msg->headers; hf; hf=hf->next) {
2475 2503
 		if(tv.flags == 0) {
2476 2504
 			if (tv.ri==hf->type) {