Browse code

uri.params.XXXX now acceped and returns value of that parameter, or empty string flag if param without value is present. fixed param_offset and lvl values at the time of FIXUP_CALL

Michal Matyska authored on 27/06/2006 21:34:50
Showing 3 changed files
... ...
@@ -86,18 +86,34 @@ int w_parse_select(char**p, select_t* sel)
86 86
 		sel->n++;
87 87
 		if (*(*p)=='[') {
88 88
 			(*p)++; 
89
-			name.s=(*p);
90
-			if (*(*p)=='-') (*p)++;
91
-			while (isdigit(*(*p))) (*p)++;
92
-			name.len=(*p)-name.s;
93
-			if (*(*p)!=']') {
94
-				ERR("parse_select: invalid index, no closing ]\n");
95
-				goto error;
96
-			};
97
-			(*p)++;
98
-			sel->params[sel->n].type=SEL_PARAM_INT;
99
-			sel->params[sel->n].v.i=atoi(name.s);
100
-			DBG("parse_select: part %d: [%d]\n", sel->n, sel->params[sel->n].v.i);
89
+			if (*(*p)=='"') {
90
+				(*p)++;	
91
+				name.s=(*p);
92
+				while (*(*p)!='"') (*p)++;
93
+				name.len=(*p)-name.s;
94
+				(*p)++;
95
+				if (*(*p)!=']') {
96
+					ERR("parse_select: invalid string index, no closing ]\n");
97
+					goto error;
98
+				};
99
+				(*p)++;
100
+				sel->params[sel->n].type=SEL_PARAM_STR;
101
+				sel->params[sel->n].v.s=name;
102
+				DBG("parse_select: part %d: [\"%.*s\"]\n", sel->n, sel->params[sel->n].v.s.len, sel->params[sel->n].v.s.s);
103
+			} else {
104
+				name.s=(*p);
105
+				if (*(*p)=='-') (*p)++;
106
+				while (isdigit(*(*p))) (*p)++;
107
+				name.len=(*p)-name.s;
108
+				if (*(*p)!=']') {
109
+					ERR("parse_select: invalid index, no closing ]\n");
110
+					goto error;
111
+				};
112
+				(*p)++;
113
+				sel->params[sel->n].type=SEL_PARAM_INT;
114
+				sel->params[sel->n].v.i=atoi(name.s);
115
+				DBG("parse_select: part %d: [%d]\n", sel->n, sel->params[sel->n].v.i);
116
+			}
101 117
 			sel->n++;
102 118
 		}
103 119
 		if (*(*p)!='.') break;
... ...
@@ -246,7 +262,6 @@ int resolve_select(select_t* s)
246 246
 
247 247
 		if (t->table[table_idx].flags & NESTED) {
248 248
 			if (nested < MAX_NESTED_CALLS-1) { /* need space for final function */
249
-				s->lvl = nested;
250 249
 				s->f[nested++] = f;
251 250
 				s->param_offset[nested] = param_idx;
252 251
 			} else {
... ...
@@ -258,6 +273,8 @@ int resolve_select(select_t* s)
258 258
 		}
259 259
 
260 260
 		if (t->table[table_idx].flags & FIXUP_CALL) {
261
+			s->lvl = nested;
262
+			s->param_offset[nested+1] = param_idx;
261 263
 			if (t->table[table_idx].new_f(NULL, s, NULL)<0) goto not_found;
262 264
 		}
263 265
 
... ...
@@ -652,6 +652,17 @@ int select_uri_params(str* res, select_t* s, struct sip_msg* msg)
652 652
 	param_hooks_t h;
653 653
 	param_t *p, *list=NULL;
654 654
 	str* wanted;
655
+	int i;
656
+
657
+	if (!msg || !res) {
658
+		if (s->param_offset[s->lvl+1]-s->param_offset[s->lvl]==1) return 0;
659
+		if (s->params[s->param_offset[s->lvl]+1].type!=SEL_PARAM_STR) return -1;
660
+		wanted=&s->params[s->param_offset[s->lvl]+1].v.s;
661
+		for (i=0; i<wanted->len; i++) 
662
+			if (wanted->s[i]=='_') 
663
+				wanted->s[i]='-';
664
+		return 0;
665
+	}
655 666
 	
656 667
 	if (parse_uri(res->s, res->len, &uri)<0)
657 668
 		return -1;
... ...
@@ -662,11 +673,12 @@ int select_uri_params(str* res, select_t* s, struct sip_msg* msg)
662 662
 	if (s->params[s->param_offset[s->lvl]+1].type!=SEL_PARAM_STR) return -1;
663 663
 	wanted=&s->params[s->param_offset[s->lvl]+1].v.s;
664 664
 	
665
+	if (!uri.params.len) return -1;
665 666
 	if (parse_params(&uri.params, CLASS_ANY, &h, &list)<0) return -1;
666 667
 	
667
-	for (p = list; p->next; p=p->next) {
668
+	for (p = list; p; p=p->next) {
668 669
 		if ((p->name.len==wanted->len) && 
669
-			 !strncmp(p->name.s, wanted->s,wanted->len)) {
670
+			 !strncasecmp(p->name.s, wanted->s,wanted->len)) {
670 671
 			*res=p->body;
671 672
 			free_params(list);
672 673
 			return (res->len ? 0 : 1);
... ...
@@ -168,7 +168,7 @@ 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, CONSUME_NEXT_STR | OPTIONAL},
171
+	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("params"), select_uri_params, CONSUME_NEXT_STR | OPTIONAL | FIXUP_CALL },
172 172
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("hostport"), select_uri_hostport, 0},
173 173
 
174 174
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("event"), select_event, 0},