Browse code

pv: added $rpl(cntrr) - count record-route headers in reply

Daniel-Constantin Mierla authored on 13/05/2021 08:49:19
Showing 1 changed files
... ...
@@ -41,6 +41,7 @@
41 41
 #include "../../core/parser/parse_hname2.h"
42 42
 #include "../../core/parser/parse_content.h"
43 43
 #include "../../core/parser/parse_refer_to.h"
44
+#include "../../core/parser/parse_rr.h"
44 45
 #include "../../core/parser/parse_rpid.h"
45 46
 #include "../../core/parser/parse_diversion.h"
46 47
 #include "../../core/parser/parse_ppi_pai.h"
... ...
@@ -3773,6 +3774,8 @@ int pv_parse_rpl_attrs_name(pv_spec_p sp, str *in)
3773 3774
 				sp->pvp.pvn.u.isname.name.n = 1;
3774 3775
 			else if(strncmp(in->s, "dport", 5)==0)
3775 3776
 				sp->pvp.pvn.u.isname.name.n = 2;
3777
+			else if(strncmp(in->s, "cntrr", 5)==0)
3778
+				sp->pvp.pvn.u.isname.name.n = 21;
3776 3779
 			else goto error;
3777 3780
 		break;
3778 3781
 		case 6:
... ...
@@ -3813,6 +3816,7 @@ int pv_get_rpl_attrs(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
3813 3816
 	str sproto = STR_NULL;
3814 3817
 	unsigned int port = 0;
3815 3818
 	hdr_field_t *hf = NULL;
3819
+	unsigned int hcnt = 0;
3816 3820
 
3817 3821
 	if(param==NULL) {
3818 3822
 		return pv_get_null(msg, param, res);
... ...
@@ -3877,18 +3881,37 @@ int pv_get_rpl_attrs(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
3877 3881
 		case 20: /* count of via */
3878 3882
 			if (parse_headers(msg, HDR_EOH_F, 0)<0) {
3879 3883
 				LM_DBG("failed to parse sip headers\n");
3880
-				return pv_get_uintval(msg, param, res, 0);
3884
+				return pv_get_null(msg, param, res);
3881 3885
 			}
3882
-			port = 0;
3886
+			hcnt = 0;
3883 3887
 			for(hf=msg->h_via1; hf!=NULL; hf=hf->next) {
3884 3888
 				if(hf->type==HDR_VIA_T) {
3885 3889
 					via_body_t *vb;
3886 3890
 					for(vb=(via_body_t*)hf->parsed; vb!=NULL; vb=vb->next) {
3887
-						port++;
3891
+						hcnt++;
3888 3892
 					}
3889 3893
 				}
3890 3894
 			}
3891
-			return pv_get_uintval(msg, param, res, port);
3895
+			return pv_get_uintval(msg, param, res, hcnt);
3896
+		case 21: /* count of record-route */
3897
+			if (parse_headers(msg, HDR_EOH_F, 0)<0) {
3898
+				LM_DBG("failed to parse sip headers\n");
3899
+				return pv_get_null(msg, param, res);
3900
+			}
3901
+			hcnt = 0;
3902
+			for(hf=msg->h_via1; hf!=NULL; hf=hf->next) {
3903
+				if(hf->type == HDR_RECORDROUTE_T) {
3904
+					rr_t *rrb;
3905
+					if(parse_rr(hf) == -1) {
3906
+						LM_ERR("failed parsing rr header\n");
3907
+						return pv_get_null(msg, param, res);
3908
+					}
3909
+					for(rrb=(rr_t*)hf->parsed; rrb!=NULL; rrb=rrb->next) {
3910
+						hcnt++;
3911
+					}
3912
+				}
3913
+			}
3914
+			return pv_get_uintval(msg, param, res, hcnt);
3892 3915
 
3893 3916
 		default:
3894 3917
 			return pv_get_null(msg, param, res);