MINOR: cli: add two new states to print messages on the CLI

Right now we used to have extremely inconsistent states to report output,
one is CLI_ST_PRINT which prints constant message cli->msg with the
assigned severity, and CLI_ST_PRINT_FREE which prints dynamically
allocated cli->err with severity LOG_ERR, and nothing in between,
eventhough it's useful to be able to report dynamically allocated
messages as well as constant error messages.

This patch adds two extra states, which are not particularly well named
given the constraints imposed by existing ones. One is CLI_ST_PRINT_ERR
which prints a constant error message. The other one is CLI_ST_PRINT_DYN
which prints a dynamically allocated message. By doing so we maintain
the compatibility with current code.

It is important to keep in mind that we cannot pre-initialize pointers
and automatically detect what message type it is based on the assigned
fields, because the CLI's context is in a union shared with all other
users, thus unused fields contain anything upon return. This is why we
have no choice but using 4 states. Keeping the two fields <msg> and
<err> remains useful because one is const and not the other one, and
this catches may copy-paste mistakes. It's just that <err> is pretty
confusing here, it should be renamed.
diff --git a/src/cli.c b/src/cli.c
index 16f6243..1f6a845 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -767,30 +767,47 @@
 			req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */
 		}
 		else {	/* output functions */
+			const char *msg;
+			int sev;
+
 			switch (appctx->st0) {
 			case CLI_ST_PROMPT:
 				break;
-			case CLI_ST_PRINT:
-				if (cli_output_msg(res, appctx->ctx.cli.msg, appctx->ctx.cli.severity,
-							cli_get_severity_output(appctx)) != -1)
-					appctx->st0 = CLI_ST_PROMPT;
-				else
-					si_rx_room_blk(si);
-				break;
-			case CLI_ST_PRINT_FREE: {
-				const char *msg = appctx->ctx.cli.err;
-
-				if (!msg)
-					msg = "Out of memory.\n";
+			case CLI_ST_PRINT:       /* print const message in msg */
+			case CLI_ST_PRINT_ERR:   /* print const error in msg */
+			case CLI_ST_PRINT_DYN:   /* print dyn message in msg, free */
+			case CLI_ST_PRINT_FREE:  /* print dyn error in err, free */
+				if (appctx->st0 == CLI_ST_PRINT || appctx->st0 == CLI_ST_PRINT_ERR) {
+					sev = appctx->st0 == CLI_ST_PRINT_ERR ?
+						LOG_ERR : appctx->ctx.cli.severity;
+					msg = appctx->ctx.cli.msg;
+				}
+				else if (appctx->st0 == CLI_ST_PRINT_DYN || appctx->st0 == CLI_ST_PRINT_FREE) {
+					sev = appctx->st0 == CLI_ST_PRINT_FREE ?
+						LOG_ERR : appctx->ctx.cli.severity;
+					msg = appctx->ctx.cli.err;
+					if (!msg) {
+						sev = LOG_ERR;
+						msg = "Out of memory.\n";
+					}
+				}
+				else {
+					sev = LOG_ERR;
+					msg = "Internal error.\n";
+				}
 
-				if (cli_output_msg(res, msg, LOG_ERR, cli_get_severity_output(appctx)) != -1) {
-					free(appctx->ctx.cli.err);
+				if (cli_output_msg(res, msg, sev, cli_get_severity_output(appctx)) != -1) {
+					if (appctx->st0 == CLI_ST_PRINT_FREE ||
+					    appctx->st0 == CLI_ST_PRINT_DYN) {
+						free(appctx->ctx.cli.err);
+						appctx->ctx.cli.err = NULL;
+					}
 					appctx->st0 = CLI_ST_PROMPT;
 				}
 				else
 					si_rx_room_blk(si);
 				break;
-			}
+
 			case CLI_ST_CALLBACK: /* use custom pointer */
 				if (appctx->io_handler)
 					if (appctx->io_handler(appctx)) {
@@ -891,7 +908,7 @@
 		appctx->io_release(appctx);
 		appctx->io_release = NULL;
 	}
-	else if (appctx->st0 == CLI_ST_PRINT_FREE) {
+	else if (appctx->st0 == CLI_ST_PRINT_FREE || appctx->st0 == CLI_ST_PRINT_DYN) {
 		free(appctx->ctx.cli.err);
 		appctx->ctx.cli.err = NULL;
 	}