]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] proxy: provide function to retrieve backend/server pointers
authorWilly Tarreau <w@1wt.eu>
Sat, 10 Oct 2009 16:35:51 +0000 (18:35 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 10 Oct 2009 16:36:25 +0000 (18:36 +0200)
int get_backend_server(const char *bk_name, const char *sv_name,
                       struct proxy **bk, struct server **sv);

This function scans the list of backends and servers to retrieve the first
backend and the first server with the given names, and sets them in both
parameters. It returns zero if either is not found, or non-zero and sets
the ones it did not found to NULL. If a NULL pointer is passed for the
backend, only the pointer to the server will be updated.

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

index bab3da7e44decd2c88698e4e31e5f5ca7614c834..d4d4c854c425f7e07975b1aea096d1422353f31f 100644 (file)
@@ -42,6 +42,8 @@ const char *proxy_mode_str(int mode);
 struct proxy *findproxy(const char *name, int mode, int cap);
 struct server *findserver(const struct proxy *px, const char *name);
 int proxy_cfg_ensure_no_http(struct proxy *curproxy);
+int get_backend_server(const char *bk_name, const char *sv_name,
+                      struct proxy **bk, struct server **sv);
 
 /*
  * This function returns a string containing the type of the proxy in a format
index fa6a1973dc37aa8c47efb130d6e7c873e869c437..e44d3d90540710b620a87ba2d4e729fe9ee40d5b 100644 (file)
@@ -76,6 +76,38 @@ const char *proxy_mode_str(int mode) {
                return "unknown";
 }
 
+/*
+ * This function scans the list of backends and servers to retrieve the first
+ * backend and the first server with the given names, and sets them in both
+ * parameters. It returns zero if either is not found, or non-zero and sets
+ * the ones it did not found to NULL. If a NULL pointer is passed for the
+ * backend, only the pointer to the server will be updated.
+ */
+int get_backend_server(const char *bk_name, const char *sv_name,
+                      struct proxy **bk, struct server **sv)
+{
+       struct proxy *p;
+       struct server *s;
+
+       *sv = NULL;
+
+       for (p = proxy; p; p = p->next)
+               if ((p->cap & PR_CAP_BE) && (strcmp(p->id, bk_name) == 0))
+                       break;
+       if (bk)
+               *bk = p;
+       if (!p)
+               return 0;
+
+       for (s = p->srv; s; s = s->next)
+               if (strcmp(s->id, sv_name) == 0)
+                       break;
+       *sv = s;
+       if (!s)
+               return 0;
+       return 1;
+}
+
 /* This function parses a "timeout" statement in a proxy section. It returns
  * -1 if there is any error, 1 for a warning, otherwise zero. If it does not
  * return zero, it may write an error message into the <err> buffer, for at