Browse code

- added route_lookup (like route_get(), but doesn't create a new route if not found) -- patch from Miklos Tirpak <miklos@iptel.org>

-fixed route_new_list() not init. realloc'ed chunk bug, found by
Bogdan Pintea <bogdan.pintea@iptel.org>

Andrei Pelinescu-Onciul authored on 30/05/2006 19:20:51
Showing 3 changed files
... ...
@@ -823,7 +823,7 @@ again:
823 823
 	if (n!=SIGIO){
824 824
 #ifdef SIGINFO64_WORKARROUND
825 825
 		/* on linux siginfo.si_band is defined as long in userspace
826
-		 * and as int kernel => on 64 bits things will break!
826
+		 * and as int kernel (< 2.6.5) => on 64 bits things will break!
827 827
 		 * (si_band will include si_fd, and si_fd will contain
828 828
 		 *  garbage)
829 829
 		 *  see /usr/src/linux/include/asm-generic/siginfo.h and
... ...
@@ -204,6 +204,8 @@ static inline int route_new_list(struct route_list* rt)
204 204
 			LOG(L_CRIT, "ERROR: route_new_list: out of memory\n");
205 205
 			goto end;
206 206
 		}
207
+		/* init the newly allocated memory chunk */
208
+		memset(&tmp[rt->entries], 0, rt->entries*sizeof(struct action*));
207 209
 		rt->rlist=tmp;
208 210
 		rt->entries*=2;
209 211
 	}
... ...
@@ -248,6 +250,28 @@ error:
248 248
 
249 249
 
250 250
 
251
+/* 
252
+ * if the "name" route already exists, return its index, else
253
+ * return error
254
+ * return route index in rt->rlist or -1 on error
255
+ */
256
+int route_lookup(struct route_list* rt, char* name)
257
+{
258
+	int len;
259
+	struct str_hash_entry* e;
260
+	
261
+	len=strlen(name);
262
+	/* check if exists an non empty*/
263
+	e=str_hash_get(&rt->names, name, len);
264
+	if (e){
265
+		return e->u.n;
266
+	}else{
267
+		return -1;
268
+	}
269
+}
270
+
271
+
272
+
251 273
 static int fix_actions(struct action* a); /*fwd declaration*/
252 274
 
253 275
 
... ...
@@ -62,6 +62,7 @@ extern struct route_list onsend_rt;
62 62
 int init_routes();
63 63
 void destroy_routes();
64 64
 int route_get(struct route_list* rt, char* name);
65
+int route_lookup(struct route_list* rt, char* name);
65 66
 
66 67
 void push(struct action* a, struct action** head);
67 68
 int add_actions(struct action* a, struct action** head);