Browse code

pv: support for Contact header in $hflc()

Daniel-Constantin Mierla authored on 11/06/2021 07:17:36
Showing 1 changed files
... ...
@@ -2429,6 +2429,7 @@ int pv_get_hflc(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
2429 2429
 	pv_value_t tv = {0};
2430 2430
 	via_body_t *vb = NULL;
2431 2431
 	rr_t *rrb = NULL;
2432
+	contact_t *cb = NULL;
2432 2433
 	hdr_field_t *hf = NULL;
2433 2434
 	int n = 0;
2434 2435
 
... ...
@@ -2499,6 +2500,28 @@ int pv_get_hflc(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
2499 2500
 		return pv_get_sintval(msg, param, res, n);
2500 2501
 	}
2501 2502
 
2503
+	if((tv.flags == 0) && (tv.ri==HDR_CONTACT_T)) {
2504
+		if(msg->contact==NULL) {
2505
+			LM_DBG("no Contact header\n");
2506
+			return pv_get_sintval(msg, param, res, 0);
2507
+		}
2508
+		if(parse_contact_headers(msg) < 0) {
2509
+			LM_DBG("failed to parse Contact headers\n");
2510
+			return pv_get_sintval(msg, param, res, 0);
2511
+		}
2512
+
2513
+		/* count Contact header bodies */
2514
+		for(hf=msg->contact; hf!=NULL; hf=hf->next) {
2515
+			if(hf->type==HDR_CONTACT_T) {
2516
+				for(cb=(((contact_body_t*)hf->parsed)->contacts);
2517
+						cb!=NULL; cb=cb->next) {
2518
+					n++;
2519
+				}
2520
+			}
2521
+		}
2522
+		return pv_get_sintval(msg, param, res, n);
2523
+	}
2524
+
2502 2525
 	for (hf=msg->headers; hf; hf=hf->next) {
2503 2526
 		if(tv.flags == 0) {
2504 2527
 			if (tv.ri==hf->type) {