]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] proxy: make findproxy() return proxies from numeric IDs too
authorWilly Tarreau <w@1wt.eu>
Tue, 2 Aug 2011 09:25:54 +0000 (11:25 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 2 Aug 2011 09:25:54 +0000 (11:25 +0200)
Sometimes it's useful to be able to search a proxy by its numeric ID,
so let's add support for names such as #<id>.

src/proxy.c

index 3b56c86ea2d2d13d1aeb05c626de282585855e25..6df460e59066b7b37249091725b6ec5251cdcd3c 100644 (file)
@@ -315,12 +315,22 @@ struct proxy *findproxy_mode(const char *name, int mode, int cap) {
        return target;
 }
 
+/* Returns a pointer to the proxy matching either name <name>, or id <name> if
+ * <name> begins with a '#'. NULL is returned if no match is found, as well as
+ * if multiple matches are found (eg: too large capabilities mask).
+ */
 struct proxy *findproxy(const char *name, int cap) {
 
        struct proxy *curproxy, *target = NULL;
+       int pid = 0;
+
+       if (*name == '#')
+               pid = atoi(name + 1);
 
        for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
-               if ((curproxy->cap & cap)!=cap || strcmp(curproxy->id, name))
+               if ((curproxy->cap & cap) != cap ||
+                   (pid && curproxy->uuid != pid) ||
+                   (!pid && strcmp(curproxy->id, name)))
                        continue;
 
                if (!target) {