]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy: add a new function proxy_find_by_id()
authorWilly Tarreau <w@1wt.eu>
Tue, 26 May 2015 13:25:32 +0000 (15:25 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 27 May 2015 14:49:44 +0000 (16:49 +0200)
It does the same as the other one except that it only focuses on the
numeric ID and the capabilities. It's used by proxy_find_by_name()
for numeric names.

include/proto/proxy.h
src/proxy.c

index 60d2af038fc575cf1fdc3f275d4c85e97874156f..10e8eab2e02eb9f521df7d95f029593054e7c558 100644 (file)
@@ -48,6 +48,7 @@ int  stream_set_backend(struct stream *s, struct proxy *be);
 const char *proxy_cap_str(int cap);
 const char *proxy_mode_str(int mode);
 void proxy_store_name(struct proxy *px);
+struct proxy *proxy_find_by_id(int id, int cap, int table);
 struct proxy *proxy_find_by_name(const char *name, int cap, int table);
 struct server *findserver(const struct proxy *px, const char *name);
 int proxy_cfg_ensure_no_http(struct proxy *curproxy);
index 175e3bb51782fc169a589e02c699368759d55948..0ecd1255f9aebd3b058e447593c52b06b9650167 100644 (file)
@@ -346,34 +346,43 @@ void proxy_store_name(struct proxy *px)
        ebis_insert(&proxy_by_name, &px->conf.by_name);
 }
 
-/* Returns a pointer to the first proxy matching either name <name>, or id
- * <name> if <name> begins with a '#'. NULL is returned if no match is found.
- * If <table> is non-zero, it only considers proxies having a table.
+/* Returns a pointer to the first proxy matching capabilities <cap> and id
+ * <id>. NULL is returned if no match is found. If <table> is non-zero, it
+ * only considers proxies having a table.
  */
-struct proxy *proxy_find_by_name(const char *name, int cap, int table)
+struct proxy *proxy_find_by_id(int id, int cap, int table)
 {
-       struct proxy *curproxy;
-       int pid = -1;
+       struct eb32_node *n;
 
-       if (*name == '#') {
-               struct eb32_node *node;
+       for (n = eb32_lookup(&used_proxy_id, id); n; n = eb32_next(n)) {
+               struct proxy *px = container_of(n, struct proxy, conf.id);
 
-               pid = atoi(name + 1);
+               if (px->uuid != id)
+                       break;
 
-               for (node = eb32_lookup(&used_proxy_id, pid); node; node = eb32_next(node)) {
-                       curproxy = container_of(node, struct proxy, conf.id);
+               if ((px->cap & cap) != cap)
+                       continue;
 
-                       if (curproxy->uuid != pid)
-                               break;
+               if (table && !px->table.size)
+                       continue;
 
-                       if ((curproxy->cap & cap) != cap)
-                               continue;
+               return px;
+       }
+       return NULL;
+}
 
-                       if (table && !curproxy->table.size)
-                               continue;
+/* Returns a pointer to the first proxy matching either name <name>, or id
+ * <name> if <name> begins with a '#'. NULL is returned if no match is found.
+ * If <table> is non-zero, it only considers proxies having a table.
+ */
+struct proxy *proxy_find_by_name(const char *name, int cap, int table)
+{
+       struct proxy *curproxy;
 
+       if (*name == '#') {
+               curproxy = proxy_find_by_id(atoi(name + 1), cap, table);
+               if (curproxy)
                        return curproxy;
-               }
        }
        else {
                struct ebpt_node *node;