Browse code

registrar - add optional avp params for usrloc comparison

reg_received_avp - match with received field
reg_contact_avp - match with contact field

Luis Azedo authored on 17/02/2015 18:29:48
Showing 3 changed files
... ...
@@ -631,6 +631,8 @@ int registered(struct sip_msg* _m, udomain_t* _d, str* _uri)
631 631
 	ucontact_t* ptr;
632 632
 	int res;
633 633
 	int_str match_callid=(int_str)0;
634
+	int_str match_received=(int_str)0;
635
+	int_str match_contact=(int_str)0;
634 636
 
635 637
 	if(_uri!=NULL)
636 638
 	{
... ...
@@ -666,12 +668,38 @@ int registered(struct sip_msg* _m, udomain_t* _d, str* _uri)
666 668
 			match_callid.n = 0;
667 669
 			match_callid.s.s = NULL;
668 670
 		}
671
+		if (reg_received_avp_name.n) {
672
+			struct usr_avp *avp =
673
+				search_first_avp( reg_received_avp_type, reg_received_avp_name, &match_received, 0);
674
+			if (!(avp && is_avp_str_val(avp)))
675
+				match_received.n = 0;
676
+				match_received.s.s = NULL;
677
+		} else {
678
+			match_received.n = 0;
679
+			match_received.s.s = NULL;
680
+		}
681
+		if (reg_contact_avp_name.n) {
682
+			struct usr_avp *avp =
683
+				search_first_avp( reg_contact_avp_type, reg_contact_avp_name, &match_contact, 0);
684
+			if (!(avp && is_avp_str_val(avp)))
685
+				match_contact.n = 0;
686
+				match_contact.s.s = NULL;
687
+		} else {
688
+			match_contact.n = 0;
689
+			match_contact.s.s = NULL;
690
+		}
669 691
 
670 692
 		for (ptr = r->contacts; ptr; ptr = ptr->next) {
671 693
 			if(!VALID_CONTACT(ptr, act_time)) continue;
672 694
 			if (match_callid.s.s && /* optionally enforce tighter matching w/ Call-ID */
673 695
 				memcmp(match_callid.s.s,ptr->callid.s,match_callid.s.len))
674 696
 				continue;
697
+			if (match_received.s.s && /* optionally enforce tighter matching w/ Received */
698
+				memcmp(match_received.s.s,ptr->received.s,match_received.s.len))
699
+				continue;
700
+			if (match_contact.s.s && /* optionally enforce tighter matching w/ Contact */
701
+				memcmp(match_contact.s.s,ptr->c.s,match_contact.s.len))
702
+				continue;
675 703
 			ul.release_urecord(r);
676 704
 			ul.unlock_udomain(_d, &aor);
677 705
 			if(ptr->xavp!=NULL) {
... ...
@@ -126,10 +126,16 @@ int reg_outbound_mode = 0;
126 126
 int reg_regid_mode = 0;
127 127
 int reg_flow_timer = 0;
128 128
 
129
-/* Populate this AVP if testing for specific registration instance. */
129
+/* Populate these AVPs if testing for specific registration instance. */
130 130
 char *reg_callid_avp_param = 0;
131 131
 unsigned short reg_callid_avp_type = 0;
132 132
 int_str reg_callid_avp_name;
133
+char *reg_received_avp_param = 0;
134
+unsigned short reg_received_avp_type = 0;
135
+int_str reg_received_avp_name;
136
+char *reg_contact_avp_param = 0;
137
+unsigned short reg_contact_avp_type = 0;
138
+int_str reg_contact_avp_name;
133 139
 
134 140
 char* rcv_avp_param = 0;
135 141
 unsigned short rcv_avp_type = 0;
... ...
@@ -226,6 +232,8 @@ static param_export_t params[] = {
226 232
 	{"received_param",     PARAM_STR, &rcv_param           					},
227 233
 	{"received_avp",       PARAM_STRING, &rcv_avp_param       					},
228 234
 	{"reg_callid_avp",     PARAM_STRING, &reg_callid_avp_param					},
235
+	{"reg_received_avp",     PARAM_STRING, &reg_received_avp_param					},
236
+	{"reg_contact_avp",     PARAM_STRING, &reg_contact_avp_param					},
229 237
 	{"max_contacts",       INT_PARAM, &default_registrar_cfg.max_contacts			},
230 238
 	{"retry_after",        INT_PARAM, &default_registrar_cfg.retry_after			},
231 239
 	{"sock_flag",          INT_PARAM, &sock_flag           					},
... ...
@@ -335,13 +343,13 @@ static int mod_init(void)
335 343
 		s.s = reg_callid_avp_param; s.len = strlen(s.s);
336 344
 		if (pv_parse_spec(&s, &avp_spec)==0
337 345
 			|| avp_spec.type!=PVT_AVP) {
338
-			LM_ERR("malformed or non AVP %s AVP definition\n", reg_callid_avp_param);
346
+			LM_ERR("malformed or non AVP %s AVP definition - reg_callid_avp\n", reg_callid_avp_param);
339 347
 			return -1;
340 348
 		}
341 349
 
342 350
 		if(pv_get_avp_name(0, &avp_spec.pvp, &reg_callid_avp_name, &reg_callid_avp_type)!=0)
343 351
 		{
344
-			LM_ERR("[%s]- invalid AVP definition\n", reg_callid_avp_param);
352
+			LM_ERR("[%s]- invalid AVP definition - reg_callid_avp\n", reg_callid_avp_param);
345 353
 			return -1;
346 354
 		}
347 355
 	} else {
... ...
@@ -349,6 +357,42 @@ static int mod_init(void)
349 357
 		reg_callid_avp_type = 0;
350 358
 	}
351 359
 
360
+	if (reg_received_avp_param && *reg_received_avp_param) {
361
+		s.s = reg_received_avp_param; s.len = strlen(s.s);
362
+		if (pv_parse_spec(&s, &avp_spec)==0
363
+			|| avp_spec.type!=PVT_AVP) {
364
+			LM_ERR("malformed or non AVP %s AVP definition - reg_received_avp\n", reg_received_avp_param);
365
+			return -1;
366
+		}
367
+
368
+		if(pv_get_avp_name(0, &avp_spec.pvp, &reg_received_avp_name, &reg_received_avp_type)!=0)
369
+		{
370
+			LM_ERR("[%s]- invalid AVP definition - reg_received_avp\n", reg_received_avp_param);
371
+			return -1;
372
+		}
373
+	} else {
374
+		reg_received_avp_name.n = 0;
375
+		reg_received_avp_type = 0;
376
+	}
377
+
378
+	if (reg_contact_avp_param && *reg_contact_avp_param) {
379
+		s.s = reg_contact_avp_param; s.len = strlen(s.s);
380
+		if (pv_parse_spec(&s, &avp_spec)==0
381
+			|| avp_spec.type!=PVT_AVP) {
382
+			LM_ERR("malformed or non AVP %s AVP definition - reg_contact_avp\n", reg_contact_avp_param);
383
+			return -1;
384
+		}
385
+
386
+		if(pv_get_avp_name(0, &avp_spec.pvp, &reg_contact_avp_name, &reg_contact_avp_type)!=0)
387
+		{
388
+			LM_ERR("[%s]- invalid AVP definition - reg_contact_avp\n", reg_contact_avp_param);
389
+			return -1;
390
+		}
391
+	} else {
392
+		reg_contact_avp_name.n = 0;
393
+		reg_contact_avp_type = 0;
394
+	}
395
+
352 396
 	bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0);
353 397
 	if (!bind_usrloc) {
354 398
 		LM_ERR("can't bind usrloc\n");
... ...
@@ -88,6 +88,10 @@ extern unsigned short rcv_avp_type;
88 88
 extern int_str rcv_avp_name;
89 89
 extern unsigned short reg_callid_avp_type;
90 90
 extern int_str reg_callid_avp_name;
91
+extern unsigned short reg_received_avp_type;
92
+extern int_str reg_received_avp_name;
93
+extern unsigned short reg_contact_avp_type;
94
+extern int_str reg_contact_avp_name;
91 95
 
92 96
 extern str rcv_param;
93 97
 extern int method_filtering;