Bläddra i källkod

- added route_lookup (like route_get(), but doesn't create a new route
if not found) -- patch from Miklos Tirpak <[email protected]>

-fixed route_new_list() not init. realloc'ed chunk bug, found by
Bogdan Pintea <[email protected]>

Andrei Pelinescu-Onciul 19 år sedan
förälder
incheckning
bc5be3498c
3 ändrade filer med 26 tillägg och 1 borttagningar
  1. 1 1
      io_wait.h
  2. 24 0
      route.c
  3. 1 0
      route.h

+ 1 - 1
io_wait.h

@@ -823,7 +823,7 @@ again:
 	if (n!=SIGIO){
 #ifdef SIGINFO64_WORKARROUND
 		/* on linux siginfo.si_band is defined as long in userspace
-		 * and as int kernel => on 64 bits things will break!
+		 * and as int kernel (< 2.6.5) => on 64 bits things will break!
 		 * (si_band will include si_fd, and si_fd will contain
 		 *  garbage)
 		 *  see /usr/src/linux/include/asm-generic/siginfo.h and

+ 24 - 0
route.c

@@ -204,6 +204,8 @@ static inline int route_new_list(struct route_list* rt)
 			LOG(L_CRIT, "ERROR: route_new_list: out of memory\n");
 			goto end;
 		}
+		/* init the newly allocated memory chunk */
+		memset(&tmp[rt->entries], 0, rt->entries*sizeof(struct action*));
 		rt->rlist=tmp;
 		rt->entries*=2;
 	}
@@ -248,6 +250,28 @@ error:
 
 
 
+/* 
+ * if the "name" route already exists, return its index, else
+ * return error
+ * return route index in rt->rlist or -1 on error
+ */
+int route_lookup(struct route_list* rt, char* name)
+{
+	int len;
+	struct str_hash_entry* e;
+	
+	len=strlen(name);
+	/* check if exists an non empty*/
+	e=str_hash_get(&rt->names, name, len);
+	if (e){
+		return e->u.n;
+	}else{
+		return -1;
+	}
+}
+
+
+
 static int fix_actions(struct action* a); /*fwd declaration*/
 
 

+ 1 - 0
route.h

@@ -62,6 +62,7 @@ extern struct route_list onsend_rt;
 int init_routes();
 void destroy_routes();
 int route_get(struct route_list* rt, char* name);
+int route_lookup(struct route_list* rt, char* name);
 
 void push(struct action* a, struct action** head);
 int add_actions(struct action* a, struct action** head);