mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 15:47:01 +02:00
MINOR: proxy: add a new function proxy_find_by_id()
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.
This commit is contained in:
parent
98d0485a90
commit
3c56a7d94f
@ -48,6 +48,7 @@ int stream_set_backend(struct stream *s, struct proxy *be);
|
|||||||
const char *proxy_cap_str(int cap);
|
const char *proxy_cap_str(int cap);
|
||||||
const char *proxy_mode_str(int mode);
|
const char *proxy_mode_str(int mode);
|
||||||
void proxy_store_name(struct proxy *px);
|
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 proxy *proxy_find_by_name(const char *name, int cap, int table);
|
||||||
struct server *findserver(const struct proxy *px, const char *name);
|
struct server *findserver(const struct proxy *px, const char *name);
|
||||||
int proxy_cfg_ensure_no_http(struct proxy *curproxy);
|
int proxy_cfg_ensure_no_http(struct proxy *curproxy);
|
||||||
|
45
src/proxy.c
45
src/proxy.c
@ -346,6 +346,31 @@ void proxy_store_name(struct proxy *px)
|
|||||||
ebis_insert(&proxy_by_name, &px->conf.by_name);
|
ebis_insert(&proxy_by_name, &px->conf.by_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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_id(int id, int cap, int table)
|
||||||
|
{
|
||||||
|
struct eb32_node *n;
|
||||||
|
|
||||||
|
for (n = eb32_lookup(&used_proxy_id, id); n; n = eb32_next(n)) {
|
||||||
|
struct proxy *px = container_of(n, struct proxy, conf.id);
|
||||||
|
|
||||||
|
if (px->uuid != id)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if ((px->cap & cap) != cap)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (table && !px->table.size)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
return px;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Returns a pointer to the first proxy matching either name <name>, or id
|
/* 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.
|
* <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.
|
* If <table> is non-zero, it only considers proxies having a table.
|
||||||
@ -353,27 +378,11 @@ void proxy_store_name(struct proxy *px)
|
|||||||
struct proxy *proxy_find_by_name(const char *name, int cap, int table)
|
struct proxy *proxy_find_by_name(const char *name, int cap, int table)
|
||||||
{
|
{
|
||||||
struct proxy *curproxy;
|
struct proxy *curproxy;
|
||||||
int pid = -1;
|
|
||||||
|
|
||||||
if (*name == '#') {
|
if (*name == '#') {
|
||||||
struct eb32_node *node;
|
curproxy = proxy_find_by_id(atoi(name + 1), cap, table);
|
||||||
|
if (curproxy)
|
||||||
pid = atoi(name + 1);
|
|
||||||
|
|
||||||
for (node = eb32_lookup(&used_proxy_id, pid); node; node = eb32_next(node)) {
|
|
||||||
curproxy = container_of(node, struct proxy, conf.id);
|
|
||||||
|
|
||||||
if (curproxy->uuid != pid)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if ((curproxy->cap & cap) != cap)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (table && !curproxy->table.size)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
return curproxy;
|
return curproxy;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
struct ebpt_node *node;
|
struct ebpt_node *node;
|
||||||
|
Loading…
Reference in New Issue
Block a user