]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli: automatically enable a CLI I/O handler when there's no parser
authorWilly Tarreau <w@1wt.eu>
Fri, 16 Dec 2016 16:59:25 +0000 (17:59 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 16 Dec 2016 18:40:13 +0000 (19:40 +0100)
Sometimes a registered keyword will not need any specific parsing nor
initialization, so it's annoying to have to write an empty parsing
function returning zero just for this.

This patch makes it possible to automatically call a keyword's I/O
handler of when the parsing function is not defined, while still allowing
a parser to set the I/O handler itself.

src/cli.c

index a875d384485c906f3de8f0af4e8eb7b43d7b3a66..12556bc1160c680876467826f3d82b76e176fc7c 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -398,6 +398,8 @@ int cli_has_level(struct appctx *appctx, int level)
  * it. It will possilbly leave st0 to CLI_ST_CALLBACK if the keyword needs to
  * have its own I/O handler called again. Most of the time, parsers will only
  * set st0 to CLI_ST_PRINT and put their message to be displayed into cli.msg.
+ * If a keyword parser is NULL and an I/O handler is declared, the I/O handler
+ * will automatically be used.
  */
 static int cli_parse_request(struct appctx *appctx, char *line)
 {
@@ -458,11 +460,11 @@ static int cli_parse_request(struct appctx *appctx, char *line)
        appctx->st2 = 0;
 
        kw = cli_find_kw(args);
-       if (!kw || !kw->parse)
+       if (!kw)
                return 0;
 
        appctx->io_handler = kw->io_handler;
-       if (kw->parse(args, appctx, kw->private) == 0 && appctx->io_handler) {
+       if ((!kw->parse || kw->parse(args, appctx, kw->private) == 0) && appctx->io_handler) {
                appctx->st0 = CLI_ST_CALLBACK;
                appctx->io_release = kw->io_release;
        }