]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy: create new function cli_find_frontend() to find a frontend
authorWilly Tarreau <w@1wt.eu>
Thu, 24 Nov 2016 11:02:29 +0000 (12:02 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Nov 2016 15:59:27 +0000 (16:59 +0100)
Several CLI commands require a frontend, so let's have a function to
look this one up and prepare the appropriate error message and the
appctx's state in case of failure.

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

index 2b649665e9ac09a8235ad744f8019b6945eda783..a0fa454d48dc1bc3b07a8dc8460d80a709e858f3 100644 (file)
@@ -25,6 +25,7 @@
 #include <common/config.h>
 #include <common/ticks.h>
 #include <common/time.h>
+#include <types/applet.h>
 #include <types/global.h>
 #include <types/proxy.h>
 #include <types/listener.h>
@@ -56,6 +57,7 @@ int proxy_cfg_ensure_no_http(struct proxy *curproxy);
 void init_new_proxy(struct proxy *p);
 int get_backend_server(const char *bk_name, const char *sv_name,
                       struct proxy **bk, struct server **sv);
+struct proxy *cli_find_frontend(struct appctx *appctx, const char *arg);
 
 /*
  * This function returns a string containing the type of the proxy in a format
index dc6d3e1c6f955daf141084aa6c84b03cd1ab6e74..86b8384a5bda1dccb60dae7b1e1facdd01762f16 100644 (file)
@@ -29,6 +29,7 @@
 #include <ebistree.h>
 
 #include <types/capture.h>
+#include <types/cli.h>
 #include <types/global.h>
 #include <types/obj_type.h>
 #include <types/peers.h>
@@ -1216,6 +1217,29 @@ static struct cfg_kw_list cfg_kws = {ILH, {
        { 0, NULL, NULL },
 }};
 
+/* Expects to find a frontend named <arg> and returns it, otherwise displays various
+ * adequate error messages and returns NULL. This function is designed to be used by
+ * functions requiring a frontend on the CLI.
+ */
+struct proxy *cli_find_frontend(struct appctx *appctx, const char *arg)
+{
+       struct proxy *px;
+
+       if (!*arg) {
+               appctx->ctx.cli.msg = "A frontend name is expected.\n";
+               appctx->st0 = STAT_CLI_PRINT;
+               return NULL;
+       }
+
+       px = proxy_fe_by_name(arg);
+       if (!px) {
+               appctx->ctx.cli.msg = "No such frontend.\n";
+               appctx->st0 = STAT_CLI_PRINT;
+               return NULL;
+       }
+       return px;
+}
+
 __attribute__((constructor))
 static void __proxy_module_init(void)
 {