Browse code

registrar - match changes

add param match_flags bit mask
1 callid
2 received
3 contact

add param match_return_flags - bit mask
1 add contact xavp
in registered adds or sets into the transaction
in reg_fetch_contacts adds to plc structure

changes to registered
check the match_flags bit mask value
and tries to find correspondent field in xavp_cfg
matches with the fields found

also looks for match_flags, match_return_flags in xavp_cfg to override the params

preserves existing behaviour
removes reg_callid_avp

Luis Azedo authored on 19/02/2015 13:05:27
Showing 4 changed files
... ...
@@ -630,9 +630,13 @@ int registered(struct sip_msg* _m, udomain_t* _d, str* _uri)
630 630
 	urecord_t* r;
631 631
 	ucontact_t* ptr;
632 632
 	int res;
633
-	int_str match_callid=(int_str)0;
634
-	int_str match_received=(int_str)0;
635
-	int_str match_contact=(int_str)0;
633
+	str match_callid = {0,0};
634
+	str match_received = {0,0};
635
+	str match_contact = {0,0};
636
+	sr_xavp_t *vavp=NULL;
637
+	int match_return_flags = reg_match_return_flags_param;
638
+	int match_flags = reg_match_flags_param;
639
+
636 640
 
637 641
 	if(_uri!=NULL)
638 642
 	{
... ...
@@ -657,59 +661,67 @@ int registered(struct sip_msg* _m, udomain_t* _d, str* _uri)
657 661
 	}
658 662
 
659 663
 	if (res == 0) {
660
-		
661
-		if (reg_callid_avp_name.n) {
662
-			struct usr_avp *avp =
663
-				search_first_avp( reg_callid_avp_type, reg_callid_avp_name, &match_callid, 0);
664
-			if (!(avp && is_avp_str_val(avp)))
665
-				match_callid.n = 0;
666
-				match_callid.s.s = NULL;
667
-		} else {
668
-			match_callid.n = 0;
669
-			match_callid.s.s = NULL;
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;
664
+		LM_DBG("searching with initial match flags (%d,%d)\n", match_flags, match_return_flags);
665
+		if(reg_xavp_cfg.s!=NULL) {
666
+
667
+			if( (vavp = xavp_get_child_with_ival(&reg_xavp_cfg, &match_flags_name)) != NULL
668
+					&& vavp->val.v.s.len > 0) {
669
+				match_flags = vavp->val.v.i;
670
+				LM_DBG("match flags set to %d\n", match_flags);
671
+			}
672
+
673
+			if( (vavp = xavp_get_child_with_ival(&reg_xavp_cfg, &match_return_flags_name)) != NULL
674
+					&& vavp->val.v.s.len > 0) {
675
+				match_return_flags = vavp->val.v.i;
676
+				LM_DBG("match return flags set to %d\n", match_return_flags);
677
+			}
678
+
679
+			if((match_flags & 1)
680
+					&& (vavp = xavp_get_child_with_sval(&reg_xavp_cfg, &match_callid_name)) != NULL
681
+					&& vavp->val.v.s.len > 0) {
682
+				match_callid = vavp->val.v.s;
683
+				LM_DBG("matching with callid %.*s\n", match_callid.len, match_callid.s);
684
+			}
685
+
686
+			if((match_flags & 2)
687
+					&& (vavp = xavp_get_child_with_sval(&reg_xavp_cfg, &match_received_name)) != NULL
688
+					&& vavp->val.v.s.len > 0) {
689
+				match_received = vavp->val.v.s;
690
+				LM_DBG("matching with received %.*s\n", match_received.len, match_received.s);
691
+			}
692
+
693
+			if((match_flags & 4)
694
+					&& (vavp = xavp_get_child_with_sval(&reg_xavp_cfg, &match_contact_name)) != NULL
695
+					&& vavp->val.v.s.len > 0) {
696
+				match_contact = vavp->val.v.s;
697
+				LM_DBG("matching with contact %.*s\n", match_contact.len, match_contact.s);
698
+			}
690 699
 		}
691 700
 
692 701
 		for (ptr = r->contacts; ptr; ptr = ptr->next) {
693 702
 			if(!VALID_CONTACT(ptr, act_time)) continue;
694
-			if (match_callid.s.s && /* optionally enforce tighter matching w/ Call-ID */
695
-				memcmp(match_callid.s.s,ptr->callid.s,match_callid.s.len))
703
+			if (match_callid.s && /* optionally enforce tighter matching w/ Call-ID */
704
+				memcmp(match_callid.s,ptr->callid.s,match_callid.len))
696 705
 				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))
706
+			if (match_received.s && /* optionally enforce tighter matching w/ ip:port */
707
+				memcmp(match_received.s,ptr->received.s,match_received.len))
699 708
 				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))
709
+			if (match_contact.s && /* optionally enforce tighter matching w/ Contact */
710
+				memcmp(match_contact.s,ptr->c.s,match_contact.len))
702 711
 				continue;
712
+
703 713
 			ul.release_urecord(r);
704 714
 			ul.unlock_udomain(_d, &aor);
705
-			if(ptr->xavp!=NULL) {
706
-				xavp = xavp_clone_level_nodata(ptr->xavp);
715
+			LM_DBG("'%.*s' found in usrloc\n", aor.len, ZSW(aor.s));
716
+
717
+			if(ptr->xavp!=NULL && match_return_flags == 1) {
718
+				sr_xavp_t *xavp = xavp_clone_level_nodata(ptr->xavp);
707 719
 				if(xavp_add(xavp, NULL)<0) {
708 720
 					LM_ERR("error adding xavp for %.*s after successful match\n", aor.len, ZSW(aor.s));
709
-					return -1;
721
+					xavp_destroy_list(&xavp);
710 722
 				}
711 723
 			}
712
-			LM_DBG("'%.*s' found in usrloc\n", aor.len, ZSW(aor.s));
724
+
713 725
 			return 1;
714 726
 		}
715 727
 	}
... ...
@@ -126,16 +126,13 @@ int reg_outbound_mode = 0;
126 126
 int reg_regid_mode = 0;
127 127
 int reg_flow_timer = 0;
128 128
 
129
-/* Populate these AVPs if testing for specific registration instance. */
130
-char *reg_callid_avp_param = 0;
131
-unsigned short reg_callid_avp_type = 0;
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;
129
+int reg_match_flags_param = 0;
130
+int reg_match_return_flags_param = 0;
131
+str match_return_flags_name = str_init("match_return_flags");
132
+str match_flags_name = str_init("match_flags");
133
+str match_callid_name = str_init("match_callid");
134
+str match_received_name = str_init("match_received");
135
+str match_contact_name = str_init("match_contact");
139 136
 
140 137
 char* rcv_avp_param = 0;
141 138
 unsigned short rcv_avp_type = 0;
... ...
@@ -231,24 +228,23 @@ static param_export_t params[] = {
231 228
 	{"max_expires",        INT_PARAM, &default_registrar_cfg.max_expires			},
232 229
 	{"received_param",     PARAM_STR, &rcv_param           					},
233 230
 	{"received_avp",       PARAM_STRING, &rcv_avp_param       					},
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					},
237 231
 	{"max_contacts",       INT_PARAM, &default_registrar_cfg.max_contacts			},
238 232
 	{"retry_after",        INT_PARAM, &default_registrar_cfg.retry_after			},
239
-	{"sock_flag",          INT_PARAM, &sock_flag           					},
240
-	{"sock_hdr_name",      PARAM_STR, &sock_hdr_name     					},
241
-	{"method_filtering",   INT_PARAM, &method_filtering    					},
242
-	{"use_path",           INT_PARAM, &path_enabled        					},
243
-	{"path_mode",          INT_PARAM, &path_mode           					},
244
-	{"path_use_received",  INT_PARAM, &path_use_params     					},
245
-        {"path_check_local",   INT_PARAM, &path_check_local                                     },
246
-	{"xavp_cfg",           PARAM_STR, &reg_xavp_cfg     					},
247
-	{"xavp_rcd",           PARAM_STR, &reg_xavp_rcd     					},
248
-	{"gruu_enabled",       INT_PARAM, &reg_gruu_enabled    					},
249
-	{"outbound_mode",      INT_PARAM, &reg_outbound_mode					},
233
+	{"sock_flag",          INT_PARAM, &sock_flag           				},
234
+	{"sock_hdr_name",      PARAM_STR, &sock_hdr_name     				},
235
+	{"method_filtering",   INT_PARAM, &method_filtering    				},
236
+	{"use_path",           INT_PARAM, &path_enabled        				},
237
+	{"path_mode",          INT_PARAM, &path_mode           				},
238
+	{"path_use_received",  INT_PARAM, &path_use_params     				},
239
+	{"path_check_local",   INT_PARAM, &path_check_local					},
240
+	{"xavp_cfg",           PARAM_STR, &reg_xavp_cfg     				},
241
+	{"xavp_rcd",           PARAM_STR, &reg_xavp_rcd     				},
242
+	{"gruu_enabled",       INT_PARAM, &reg_gruu_enabled    				},
243
+	{"outbound_mode",      INT_PARAM, &reg_outbound_mode				},
250 244
 	{"regid_mode",         INT_PARAM, &reg_regid_mode					},
251 245
 	{"flow_timer",         INT_PARAM, &reg_flow_timer					},
246
+	{"match_flags",        INT_PARAM, &reg_match_flags_param			},
247
+	{"match_return_flags", INT_PARAM, &reg_match_return_flags_param		},
252 248
 	{0, 0, 0}
253 249
 };
254 250
 
... ...
@@ -318,8 +314,6 @@ static int mod_init(void)
318 314
 		LM_ERR("Fail to declare the configuration\n");
319 315
 	        return -1;
320 316
 	}
321
-	                                                
322
-	                                                
323 317
 
324 318
 	if (rcv_avp_param && *rcv_avp_param) {
325 319
 		s.s = rcv_avp_param; s.len = strlen(s.s);
... ...
@@ -339,60 +333,6 @@ static int mod_init(void)
339 333
 		rcv_avp_type = 0;
340 334
 	}
341 335
 
342
-	if (reg_callid_avp_param && *reg_callid_avp_param) {
343
-		s.s = reg_callid_avp_param; s.len = strlen(s.s);
344
-		if (pv_parse_spec(&s, &avp_spec)==0
345
-			|| avp_spec.type!=PVT_AVP) {
346
-			LM_ERR("malformed or non AVP %s AVP definition - reg_callid_avp\n", reg_callid_avp_param);
347
-			return -1;
348
-		}
349
-
350
-		if(pv_get_avp_name(0, &avp_spec.pvp, &reg_callid_avp_name, &reg_callid_avp_type)!=0)
351
-		{
352
-			LM_ERR("[%s]- invalid AVP definition - reg_callid_avp\n", reg_callid_avp_param);
353
-			return -1;
354
-		}
355
-	} else {
356
-		reg_callid_avp_name.n = 0;
357
-		reg_callid_avp_type = 0;
358
-	}
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
-
396 336
 	bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0);
397 337
 	if (!bind_usrloc) {
398 338
 		LM_ERR("can't bind usrloc\n");
... ...
@@ -86,12 +86,15 @@ extern float def_q;
86 86
 
87 87
 extern unsigned short rcv_avp_type;
88 88
 extern int_str rcv_avp_name;
89
-extern unsigned short reg_callid_avp_type;
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;
89
+
90
+extern int reg_match_flags_param;
91
+extern int reg_match_return_flags_param;
92
+extern str match_flags_name;
93
+extern str match_return_flags_name;
94
+extern str match_callid_name;
95
+extern str match_received_name;
96
+extern str match_contact_name;
97
+
95 98
 
96 99
 extern str rcv_param;
97 100
 extern int method_filtering;
... ...
@@ -726,6 +726,8 @@ int pv_fetch_contacts(struct sip_msg* msg, char* table, char* uri,
726 726
 	int ilen;
727 727
 	int n;
728 728
 	char *p;
729
+	int match_return_flags = reg_match_return_flags_param;
730
+	sr_xavp_t *vavp=NULL;
729 731
 
730 732
 	rpp = regpv_get_profile((str*)profile);
731 733
 	if(rpp==0)
... ...
@@ -771,6 +773,13 @@ int pv_fetch_contacts(struct sip_msg* msg, char* table, char* uri,
771 773
 		return -1;
772 774
 	}
773 775
 
776
+	if(reg_xavp_cfg.s!=NULL) {
777
+		if( (vavp = xavp_get_child_with_ival(&reg_xavp_cfg, &match_return_flags_name)) != NULL) {
778
+			match_return_flags = vavp->val.v.i;
779
+			LM_INFO("match return flags set to %d\n", match_return_flags);
780
+		}
781
+	}
782
+
774 783
 	ptr = r->contacts;
775 784
 	ptr0 = NULL;
776 785
 	n = 0;
... ...
@@ -837,11 +846,11 @@ int pv_fetch_contacts(struct sip_msg* msg, char* table, char* uri,
837 846
 			c0->instance.len = ptr->instance.len;
838 847
 			p += c0->instance.len;
839 848
 		}
840
-		if(ptr->xavp != NULL)
849
+		if(ptr->xavp != NULL && match_return_flags == 1)
841 850
 		{
851
+			LM_DBG("adding contact xavp \n");
842 852
 			c0->xavp = xavp_clone_level_nodata(ptr->xavp);
843
-		}		
844
-
853
+		}
845 854
 		if(ptr0==NULL)
846 855
 		{
847 856
 			rpp->contacts = c0;