Browse code

Level of the select call is moved to a global variable form the structure in order to make the select calls shared memory-safe. Fixes SER-318

Miklos Tirpak authored on 03/10/2007 14:56:32
Showing 3 changed files
... ...
@@ -55,6 +55,11 @@
55 55
  */
56 56
 static select_table_t *select_list = &select_core_table;
57 57
 
58
+/* the level of the select call that is beeing evaluated
59
+ * by the child process
60
+ */
61
+int select_level = 0;
62
+
58 63
 /*
59 64
  * Parse select string into select structure s
60 65
  * moves pointer p to the first unused char
... ...
@@ -274,7 +279,7 @@ int resolve_select(select_t* s)
274 274
 		}
275 275
 
276 276
 		if (t->table[table_idx].flags & FIXUP_CALL) {
277
-			s->lvl = nested;
277
+			select_level = nested;
278 278
 			s->param_offset[nested+1] = param_idx;
279 279
 			if (t->table[table_idx].new_f(NULL, s, NULL)<0) goto not_found;
280 280
 		}
... ...
@@ -305,7 +310,7 @@ not_found:
305 305
 
306 306
 int run_select(str* res, select_t* s, struct sip_msg* msg)
307 307
 {
308
-	int ret;
308
+	int ret, orig_level;
309 309
 
310 310
 	if (res == NULL) {
311 311
 		BUG("Select unprepared result space\n");
... ...
@@ -321,10 +326,17 @@ int run_select(str* res, select_t* s, struct sip_msg* msg)
321 321
 	}
322 322
 	DBG("Calling SELECT %p \n", s->f);
323 323
 
324
+	/* save and resore the original select_level
325
+	 * because of the nested selets */
326
+	orig_level = select_level;
324 327
 	ret = 0;
325
-	for (s->lvl=0; (ret == 0) && (s->f[s->lvl] !=0 ) && (s->lvl<MAX_NESTED_CALLS); (s->lvl)++)	{
326
-		ret = s->f[s->lvl](res, s, msg);
328
+	for (	select_level=0;
329
+		(ret == 0) && (s->f[select_level] !=0 ) && (select_level<MAX_NESTED_CALLS);
330
+		select_level++
331
+	) {
332
+		ret = s->f[select_level](res, s, msg);
327 333
 	}
334
+	select_level = orig_level;
328 335
 	return ret;
329 336
 }
330 337
 
... ...
@@ -122,7 +122,6 @@ typedef struct select {
122 122
 	int param_offset[MAX_NESTED_CALLS+1];
123 123
 	select_param_t params[MAX_SELECT_PARAMS];
124 124
 	int n;
125
-	int lvl;
126 125
 } select_t;
127 126
 
128 127
 typedef struct {
... ...
@@ -138,6 +137,11 @@ typedef struct select_table {
138 138
   struct select_table *next;
139 139
 } select_table_t;
140 140
 
141
+/* the level of the select call that is beeing evaluated
142
+ * by the child process
143
+ */
144
+extern int select_level;
145
+
141 146
 /*
142 147
  * Lookup corresponding select function based on
143 148
  * the select parameters
... ...
@@ -547,7 +547,7 @@ int select_anyheader(str* res, select_t* s, struct sip_msg* msg)
547 547
 	hf0 = NULL;
548 548
 
549 549
 	/* extract header index if present */
550
-	if (s->param_offset[s->lvl+1] == 4) {
550
+	if (s->param_offset[select_level+1] == 4) {
551 551
 		if (s->params[3].type == SEL_PARAM_INT) {
552 552
 			hi = s->params[3].v.i;
553 553
 		} else {
... ...
@@ -698,7 +698,7 @@ int select_uri_params(str* res, select_t* s, struct sip_msg* msg)
698 698
 	if (parse_uri(res->s, res->len, &uri)<0)
699 699
 		return -1;
700 700
 	
701
-	if (s->param_offset[s->lvl+1]-s->param_offset[s->lvl]==1)
701
+	if (s->param_offset[select_level+1]-s->param_offset[select_level]==1)
702 702
 		RETURN0_res(uri.params);
703 703
 
704 704
 	*res=uri.params;
... ...
@@ -713,17 +713,17 @@ int select_any_params(str* res, select_t* s, struct sip_msg* msg)
713 713
 	int i;
714 714
 
715 715
 	if (!msg || !res) {
716
-		if (s->param_offset[s->lvl+1]-s->param_offset[s->lvl]==1) return 0;
717
-		if (s->params[s->param_offset[s->lvl]+1].type!=SEL_PARAM_STR) return -1;
718
-		wanted=&s->params[s->param_offset[s->lvl]+1].v.s;
716
+		if (s->param_offset[select_level+1]-s->param_offset[select_level]==1) return 0;
717
+		if (s->params[s->param_offset[select_level]+1].type!=SEL_PARAM_STR) return -1;
718
+		wanted=&s->params[s->param_offset[select_level]+1].v.s;
719 719
 		for (i=0; i<wanted->len; i++) 
720 720
 			if (wanted->s[i]=='_') 
721 721
 				wanted->s[i]='-';
722 722
 		return 0;
723 723
 	}
724 724
 	
725
-	if (s->params[s->param_offset[s->lvl]+1].type!=SEL_PARAM_STR) return -1;
726
-	wanted=&s->params[s->param_offset[s->lvl]+1].v.s;
725
+	if (s->params[s->param_offset[select_level]+1].type!=SEL_PARAM_STR) return -1;
726
+	wanted=&s->params[s->param_offset[select_level]+1].v.s;
727 727
 	
728 728
 	if (!res->len) return -1;
729 729
 	if (parse_params(res, CLASS_ANY, &h, &list)<0) return -1;
... ...
@@ -1071,7 +1071,7 @@ int select_nameaddr_params(str* res, select_t* s, struct sip_msg* msg)
1071 1071
 	res->len=res->len - (p-res->s) -1;
1072 1072
 	res->s=p +1;
1073 1073
 	
1074
-	if (s->param_offset[s->lvl+1]-s->param_offset[s->lvl]==1)
1074
+	if (s->param_offset[select_level+1]-s->param_offset[select_level]==1)
1075 1075
 		return (res->len ? 0 : 1);
1076 1076
 
1077 1077
 	return select_any_params(res, s, msg);