From edb91ad647988f6ac6b7fb9e749597072c5d5e8d Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 8 Aug 2019 19:09:21 +0200 Subject: [PATCH] MINOR: cli: add cli_msg(), cli_err(), cli_dynmsg(), cli_dynerr() These functions perform all the boring filling of the appctx's cli struct needed by CLI parsers to return a message or an error, and they return 1 so that they can be used as a single-line return statement. They may be used for const messages or dynamic messages. --- include/proto/cli.h | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/include/proto/cli.h b/include/proto/cli.h index 9ed2327cfd..0668508ff2 100644 --- a/include/proto/cli.h +++ b/include/proto/cli.h @@ -49,6 +49,52 @@ void mworker_cli_proxy_stop(); int pcli_wait_for_request(struct stream *s, struct channel *req, int an_bit); int pcli_wait_for_response(struct stream *s, struct channel *rep, int an_bit); +/* updates the CLI's context to log at and returns 1. This is + * for use in CLI parsers to deal with quick response messages. + */ +static inline int cli_msg(struct appctx *appctx, int severity, const char *msg) +{ + appctx->ctx.cli.severity = severity; + appctx->ctx.cli.msg = msg; + appctx->st0 = CLI_ST_PRINT; + return 1; +} + +/* updates the CLI's context to log error message and returns 1. The + * message will be logged at level LOG_ERR. This is for use in CLI parsers to + * deal with quick response messages. + */ +static inline int cli_err(struct appctx *appctx, const char *err) +{ + appctx->ctx.cli.msg = err; + appctx->st0 = CLI_ST_PRINT_ERR; + return 1; +} + +/* updates the CLI's context to log at and returns 1. The + * message must have been dynamically allocated and will be freed. This is + * for use in CLI parsers to deal with quick response messages. + */ +static inline int cli_dynmsg(struct appctx *appctx, int severity, char *msg) +{ + appctx->ctx.cli.severity = severity; + appctx->ctx.cli.err = msg; + appctx->st0 = CLI_ST_PRINT_DYN; + return 1; +} + +/* updates the CLI's context to log error message and returns 1. The + * message must have been dynamically allocated and will be freed. The message + * will be logged at level LOG_ERR. This is for use in CLI parsers to deal with + * quick response messages. + */ +static inline int cli_dynerr(struct appctx *appctx, char *err) +{ + appctx->ctx.cli.err = err; + appctx->st0 = CLI_ST_PRINT_FREE; + return 1; +} + #endif /* _PROTO_CLI_H */