Browse code

registrar - added extra parameter to registered

3rd parameter to registered function as bitmask

1 - match call-id
2 - match received
3 - match contact

module parameter reg_on_match_flag for configuration of actions on match success
0 - do nothing (default)
1 - copy contact xavp
on registered adds the contact xavp to the transaction as lookup and lookup_set do
on reg_fetch_contacts copies to the record structure created.

Luis Azedo authored on 20/02/2015 01:37:32
Showing 6 changed files
... ...
@@ -105,7 +105,7 @@ int regapi_registered(struct sip_msg *msg, char *table)
105 105
 		LM_ERR("usrloc domain [%s] not found\n", table);
106 106
 		return -1;
107 107
 	}
108
-	return registered(msg, d, NULL);
108
+	return registered(msg, d, NULL, 0);
109 109
 }
110 110
 
111 111
 /**
... ...
@@ -624,7 +624,7 @@ done:
624 624
  * it is similar to lookup but registered neither rewrites
625 625
  * the Request-URI nor appends branches
626 626
  */
627
-int registered(struct sip_msg* _m, udomain_t* _d, str* _uri)
627
+int registered(struct sip_msg* _m, udomain_t* _d, str* _uri, int match_flag)
628 628
 {
629 629
 	str uri, aor;
630 630
 	urecord_t* r;
... ...
@@ -633,10 +633,6 @@ int registered(struct sip_msg* _m, udomain_t* _d, str* _uri)
633 633
 	str match_callid = {0,0};
634 634
 	str match_received = {0,0};
635 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
-
640 636
 
641 637
 	if(_uri!=NULL)
642 638
 	{
... ...
@@ -661,38 +657,24 @@ int registered(struct sip_msg* _m, udomain_t* _d, str* _uri)
661 657
 	}
662 658
 
663 659
 	if (res == 0) {
664
-		LM_DBG("searching with initial match flags (%d,%d)\n", match_flags, match_return_flags);
660
+		LM_DBG("searching with initial match flags (%d,%d)\n", match_flags, reg_match_flag);
665 661
 		if(reg_xavp_cfg.s!=NULL) {
666 662
 
667
-			if(match_search_flags == 1) {
668
-				if( (vavp = xavp_get_child_with_ival(&reg_xavp_cfg, &match_flags_name)) != NULL
669
-						&& vavp->val.v.s.len > 0) {
670
-					match_flags = vavp->val.v.i;
671
-					LM_DBG("match flags set to %d\n", match_flags);
672
-				}
673
-
674
-				if( (vavp = xavp_get_child_with_ival(&reg_xavp_cfg, &match_return_flags_name)) != NULL
675
-						&& vavp->val.v.s.len > 0) {
676
-					match_return_flags = vavp->val.v.i;
677
-					LM_DBG("match return flags set to %d\n", match_return_flags);
678
-				}
679
-			}
680
-
681
-			if((match_flags & 1)
663
+			if((match_flag & 1)
682 664
 					&& (vavp = xavp_get_child_with_sval(&reg_xavp_cfg, &match_callid_name)) != NULL
683 665
 					&& vavp->val.v.s.len > 0) {
684 666
 				match_callid = vavp->val.v.s;
685 667
 				LM_DBG("matching with callid %.*s\n", match_callid.len, match_callid.s);
686 668
 			}
687 669
 
688
-			if((match_flags & 2)
670
+			if((match_flag & 2)
689 671
 					&& (vavp = xavp_get_child_with_sval(&reg_xavp_cfg, &match_received_name)) != NULL
690 672
 					&& vavp->val.v.s.len > 0) {
691 673
 				match_received = vavp->val.v.s;
692 674
 				LM_DBG("matching with received %.*s\n", match_received.len, match_received.s);
693 675
 			}
694 676
 
695
-			if((match_flags & 4)
677
+			if((match_flag & 4)
696 678
 					&& (vavp = xavp_get_child_with_sval(&reg_xavp_cfg, &match_contact_name)) != NULL
697 679
 					&& vavp->val.v.s.len > 0) {
698 680
 				match_contact = vavp->val.v.s;
... ...
@@ -716,7 +698,7 @@ int registered(struct sip_msg* _m, udomain_t* _d, str* _uri)
716 698
 			ul.unlock_udomain(_d, &aor);
717 699
 			LM_DBG("'%.*s' found in usrloc\n", aor.len, ZSW(aor.s));
718 700
 
719
-			if(ptr->xavp!=NULL && match_return_flags == 1) {
701
+			if(ptr->xavp!=NULL && reg_match_flag_param == 1) {
720 702
 				sr_xavp_t *xavp = xavp_clone_level_nodata(ptr->xavp);
721 703
 				if(xavp_add(xavp, NULL)<0) {
722 704
 					LM_ERR("error adding xavp for %.*s after successful match\n", aor.len, ZSW(aor.s));
... ...
@@ -68,7 +68,7 @@ int lookup_branches(sip_msg_t *msg, udomain_t *d);
68 68
  * it is similar to lookup but registered neither rewrites
69 69
  * the Request-URI nor appends branches
70 70
  */
71
-int registered(struct sip_msg* _m, udomain_t* _d, str* _uri);
71
+int registered(struct sip_msg* _m, udomain_t* _d, str* _uri, int match_flag);
72 72
 
73 73
 
74 74
 #endif /* LOOKUP_H */
... ...
@@ -94,6 +94,7 @@ static int w_lookup(struct sip_msg* _m, char* _d, char* _p2);
94 94
 static int w_lookup_to_dset(struct sip_msg* _m, char* _d, char* _p2);
95 95
 static int w_lookup_branches(struct sip_msg* _m, char* _d, char* _p2);
96 96
 static int w_registered(struct sip_msg* _m, char* _d, char* _uri);
97
+static int w_registered2(struct sip_msg* _m, char* _d, char* _uri, char* _flags);
97 98
 static int w_unregister(struct sip_msg* _m, char* _d, char* _uri);
98 99
 static int w_unregister2(struct sip_msg* _m, char* _d, char* _uri, char *_ruid);
99 100
 
... ...
@@ -103,6 +104,7 @@ static int domain_uri_fixup(void** param, int param_no);
103 104
 static int save_fixup(void** param, int param_no);
104 105
 static int unreg_fixup(void** param, int param_no);
105 106
 static int fetchc_fixup(void** param, int param_no);
107
+static int registered_fixup(void** param, int param_no);
106 108
 /*! \brief Functions */
107 109
 static int add_sock_hdr(struct sip_msg* msg, char *str, char *foo);
108 110
 
... ...
@@ -126,11 +128,7 @@ int reg_outbound_mode = 0;
126 128
 int reg_regid_mode = 0;
127 129
 int reg_flow_timer = 0;
128 130
 
129
-int reg_match_flags_param = 0;
130
-int reg_match_return_flags_param = 0;
131
-int reg_match_search_flags_param = 0;
132
-str match_return_flags_name = str_init("match_return_flags");
133
-str match_flags_name = str_init("match_flags");
131
+int reg_match_flag_param = 0;
134 132
 str match_callid_name = str_init("match_callid");
135 133
 str match_received_name = str_init("match_received");
136 134
 str match_contact_name = str_init("match_contact");
... ...
@@ -193,6 +191,8 @@ static cmd_export_t cmds[] = {
193 191
 			REQUEST_ROUTE | FAILURE_ROUTE },
194 192
 	{"registered",   (cmd_function)w_registered,  2,  domain_uri_fixup, 0,
195 193
 			REQUEST_ROUTE | FAILURE_ROUTE },
194
+	{"registered",   (cmd_function)w_registered2, 3,  registered_fixup, 0,
195
+			REQUEST_ROUTE | FAILURE_ROUTE },
196 196
 	{"add_sock_hdr", (cmd_function)add_sock_hdr,  1,  fixup_str_null, 0,
197 197
 			REQUEST_ROUTE },
198 198
 	{"unregister",   (cmd_function)w_unregister,  2,  unreg_fixup, 0,
... ...
@@ -244,9 +244,7 @@ static param_export_t params[] = {
244 244
 	{"outbound_mode",      INT_PARAM, &reg_outbound_mode				},
245 245
 	{"regid_mode",         INT_PARAM, &reg_regid_mode					},
246 246
 	{"flow_timer",         INT_PARAM, &reg_flow_timer					},
247
-	{"match_flags",        INT_PARAM, &reg_match_flags_param			},
248
-	{"match_return_flags", INT_PARAM, &reg_match_return_flags_param		},
249
-	{"match_search_flags", INT_PARAM, &reg_match_search_flags_param		},
247
+	{"reg_on_match_flag",  INT_PARAM, &reg_match_flag_param				},
250 248
 	{0, 0, 0}
251 249
 };
252 250
 
... ...
@@ -496,7 +494,24 @@ static int w_registered(struct sip_msg* _m, char* _d, char* _uri)
496 494
 		LM_ERR("invalid uri parameter\n");
497 495
 		return -1;
498 496
 	}
499
-	return registered(_m, (udomain_t*)_d, (uri.len>0)?&uri:NULL);
497
+	return registered(_m, (udomain_t*)_d, (uri.len>0)?&uri:NULL, 0);
498
+}
499
+
500
+static int w_registered2(struct sip_msg* _m, char* _d, char* _uri, char* _flags)
501
+{
502
+	str uri = {0};
503
+	int flags = 0;
504
+	if(_uri!=NULL && (fixup_get_svalue(_m, (gparam_p)_uri, &uri)!=0 || uri.len<=0))
505
+	{
506
+		LM_ERR("invalid uri parameter\n");
507
+		return -1;
508
+	}
509
+	if(_flags!=NULL && (fixup_get_ivalue(_m, (fparam_t*)_flags, &flags)) < 0)
510
+	{
511
+		LM_ERR("invalid flags parameter\n");
512
+		return -1;
513
+	}
514
+	return registered(_m, (udomain_t*)_d, (uri.len>0)?&uri:NULL, flags);
500 515
 }
501 516
 
502 517
 static int w_unregister(struct sip_msg* _m, char* _d, char* _uri)
... ...
@@ -561,6 +576,18 @@ static int domain_uri_fixup(void** param, int param_no)
561 576
 	return 0;
562 577
 }
563 578
 
579
+static int registered_fixup(void** param, int param_no)
580
+{
581
+	if (param_no == 1) {
582
+		return domain_fixup(param, 1);
583
+	} else if (param_no == 2) {
584
+		return fixup_spve_null(param, 1);
585
+	} else if (param_no == 3) {
586
+		return fixup_igp_null(param, 1);
587
+	}
588
+	return 0;
589
+}
590
+
564 591
 
565 592
 /*! \brief
566 593
  * Convert char* parameter to udomain_t* pointer
... ...
@@ -627,7 +654,6 @@ static int fetchc_fixup(void** param, int param_no)
627 654
 	return 0;
628 655
 }
629 656
 
630
-
631 657
 static void mod_destroy(void)
632 658
 {
633 659
 	free_contact_buf();
... ...
@@ -87,11 +87,7 @@ extern float def_q;
87 87
 extern unsigned short rcv_avp_type;
88 88
 extern int_str rcv_avp_name;
89 89
 
90
-extern int reg_match_flags_param;
91
-extern int reg_match_return_flags_param;
92
-extern int reg_match_search_flags_param;
93
-extern str match_flags_name;
94
-extern str match_return_flags_name;
90
+extern int reg_match_flag_param;
95 91
 extern str match_callid_name;
96 92
 extern str match_received_name;
97 93
 extern str match_contact_name;
... ...
@@ -731,8 +731,6 @@ int pv_fetch_contacts(struct sip_msg* msg, char* table, char* uri,
731 731
 	int ilen;
732 732
 	int n;
733 733
 	char *p;
734
-	int match_return_flags = reg_match_return_flags_param;
735
-	sr_xavp_t *vavp=NULL;
736 734
 
737 735
 	rpp = regpv_get_profile((str*)profile);
738 736
 	if(rpp==0)
... ...
@@ -778,15 +776,6 @@ int pv_fetch_contacts(struct sip_msg* msg, char* table, char* uri,
778 776
 		return -1;
779 777
 	}
780 778
 
781
-	if(match_search_flags == 1) {
782
-		if(reg_xavp_cfg.s!=NULL) {
783
-			if( (vavp = xavp_get_child_with_ival(&reg_xavp_cfg, &match_return_flags_name)) != NULL) {
784
-				match_return_flags = vavp->val.v.i;
785
-				LM_INFO("match return flags set to %d\n", match_return_flags);
786
-			}
787
-		}
788
-	}
789
-
790 779
 	ptr = r->contacts;
791 780
 	ptr0 = NULL;
792 781
 	n = 0;
... ...
@@ -853,9 +842,8 @@ int pv_fetch_contacts(struct sip_msg* msg, char* table, char* uri,
853 842
 			c0->instance.len = ptr->instance.len;
854 843
 			p += c0->instance.len;
855 844
 		}
856
-		if(ptr->xavp != NULL && match_return_flags == 1)
845
+		if(ptr->xavp != NULL && reg_match_flag_param == 1)
857 846
 		{
858
-			LM_DBG("adding contact xavp \n");
859 847
 			c0->xavp = xavp_clone_level_nodata(ptr->xavp);
860 848
 		}
861 849
 		if(ptr0==NULL)
... ...
@@ -998,7 +986,7 @@ void reg_ul_expired_contact(ucontact_t* ptr, int type, void* param)
998 986
 		c0->instance.len = ptr->instance.len;
999 987
 		p += c0->instance.len;
1000 988
 	}
1001
-	if(ptr->xavp != NULL)
989
+	if(ptr->xavp != NULL && reg_match_flag_param == 1)
1002 990
 	{
1003 991
 		c0->xavp = xavp_clone_level_nodata(ptr->xavp);
1004 992
 	}