]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli: add cli_msg(), cli_err(), cli_dynmsg(), cli_dynerr()
authorWilly Tarreau <w@1wt.eu>
Thu, 8 Aug 2019 17:09:21 +0000 (19:09 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Aug 2019 08:11:38 +0000 (10:11 +0200)
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

index 9ed2327cfdab15be083498936d437ffa5ae8fd52..0668508ff2adb4780efc56b3a4ccdf2159754cf9 100644 (file)
@@ -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 */