MINOR: cli: add two general purpose pointers and integers in the CLI struct

Most of the keywords don't need to have their own entry in the appctx
union, they just need to reuse some generic pointers like we've been
used to do in the appctx with st{0,1,2}. This patch adds p0, p1, i0, i1
and initializes them to zero before calling the parser. This way some
of the simplest existing keywords will be able to disappear from the
union.

It's worth noting that this is an extension to what was initially
attempted via the "private" member that I removed a few patches ago by
not understanding how it was supposed to be used. Here the fact that
we share the same union will force us to be stricter: the code either
uses the general purpose variables or it uses its own fields but not
both.
This commit is contained in:
Willy Tarreau 2016-12-16 12:37:03 +01:00
parent d25fc79d72
commit a2d5872297
2 changed files with 3 additions and 0 deletions

View File

@ -93,6 +93,8 @@ struct appctx {
struct {
const char *msg; /* pointer to a persistent message to be returned in CLI_ST_PRINT state */
char *err; /* pointer to a 'must free' message to be returned in CLI_ST_PRINT_FREE state */
void *p0, *p1; /* general purpose pointers and integers for registered commands, initialized */
int i0, i1; /* to 0 by the CLI before first invocation of the keyword parser. */
} cli; /* context used by the CLI */
/* all entries below are used by various CLI commands, please

View File

@ -455,6 +455,7 @@ static int cli_parse_request(struct appctx *appctx, char *line)
}
appctx->st2 = 0;
memset(&appctx->ctx.cli, 0, sizeof(appctx->ctx.cli));
kw = cli_find_kw(args);
if (!kw)