mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-26 14:42:21 +00:00
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.
This commit is contained in:
parent
d50c7feaa1
commit
edb91ad647
@ -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 <msg> at <severity> 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 <err> 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 <msg> at <severity> 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 <err> 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 */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user