Browse code

select core extension: ....uri.params.XXXX tries to find required parameter

allowed to combine NESTED | CONSUME_NEXT_STR (_INT) - resolve checks for correct parameter type (and value if STR)


GCC warning avoided in select_authorize & auth_diameter

Michal Matyska authored on 27/06/2006 19:07:44
Showing 3 changed files
... ...
@@ -182,7 +182,7 @@ int resolve_select(select_t* s)
182 182
 			if (!t->table) continue;
183 183
 			while (t->table[table_idx].curr_f || t->table[table_idx].new_f) {
184 184
 				if (t->table[table_idx].curr_f == f) {
185
-					if (t->table[table_idx].flags & NESTED) {
185
+					if ((t->table[table_idx].flags & (NESTED | CONSUME_NEXT_INT | CONSUME_NEXT_STR)) == NESTED) {
186 186
 						accept = 1;
187 187
 					} else if (t->table[table_idx].type == s->params[param_idx].type) {
188 188
 						switch (t->table[table_idx].type) {
... ...
@@ -649,10 +649,33 @@ int select_uri_hostport(str* res, select_t* s, struct sip_msg* msg)
649 649
 
650 650
 int select_uri_params(str* res, select_t* s, struct sip_msg* msg)
651 651
 {
652
+	param_hooks_t h;
653
+	param_t *p, *list=NULL;
654
+	str* wanted;
655
+	
652 656
 	if (parse_uri(res->s, res->len, &uri)<0)
653 657
 		return -1;
654
-		
655
-	RETURN0_res(uri.params);
658
+	
659
+	if (s->param_offset[s->lvl+1]-s->param_offset[s->lvl]==1)
660
+		RETURN0_res(uri.params);
661
+
662
+	if (s->params[s->param_offset[s->lvl]+1].type!=SEL_PARAM_STR) return -1;
663
+	wanted=&s->params[s->param_offset[s->lvl]+1].v.s;
664
+	
665
+	if (parse_params(&uri.params, CLASS_ANY, &h, &list)<0) return -1;
666
+	
667
+	for (p = list; p->next; p=p->next) {
668
+		if ((p->name.len==wanted->len) && 
669
+			 !strncmp(p->name.s, wanted->s,wanted->len)) {
670
+			*res=p->body;
671
+			free_params(list);
672
+			return (res->len ? 0 : 1);
673
+		}
674
+	}
675
+	free_params(list);
676
+
677
+	DBG("SELECT ...uri.params.%s NOT FOUND !", wanted->s);
678
+	return -1;
656 679
 }
657 680
 
658 681
 int select_event(str* res, select_t* s, struct sip_msg* msg)
... ...
@@ -856,7 +879,7 @@ int select_auth_param(str* res, select_t* s, struct sip_msg* msg)
856 879
 	struct hdr_field* hdr;
857 880
 	dig_cred_t* cred;
858 881
 
859
-	if (s->n != 3 && s->n != 4 || s->params[s->n - 1].type != SEL_PARAM_DIV) return -1;
882
+	if ((s->n != 3 && s->n != 4) || (s->params[s->n - 1].type != SEL_PARAM_DIV)) return -1;
860 883
 
861 884
 	hdr = get_credentials(msg, s);
862 885
 	if (!hdr) return 1;
... ...
@@ -168,8 +168,9 @@ static select_row_t select_core[] = {
168 168
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("pwd"), select_uri_pwd, 0},
169 169
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("host"), select_uri_host, 0},
170 170
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("port"), select_uri_port, 0},
171
-	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("params"), select_uri_params, 0},
171
+	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("params"), select_uri_params, CONSUME_NEXT_STR | OPTIONAL},
172 172
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("hostport"), select_uri_hostport, 0},
173
+
173 174
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("event"), select_event, 0},
174 175
 
175 176
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("record_route"), select_rr, 0},