mirror of
https://github.com/haproxy/haproxy.git
synced 2026-02-03 20:39:41 -05:00
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.
65 lines
2.4 KiB
C
65 lines
2.4 KiB
C
/*
|
|
* include/types/cli.h
|
|
* This file provides structures and types for CLI.
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation, version 2.1
|
|
* exclusively.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
#ifndef _TYPES_CLI_H
|
|
#define _TYPES_CLI_H
|
|
|
|
#include <common/mini-clist.h>
|
|
#include <types/applet.h>
|
|
|
|
struct cli_kw {
|
|
const char *str_kw[5]; /* keywords ended by NULL, limited to 5
|
|
separated keywords combination */
|
|
const char *usage; /* usage message */
|
|
int (*parse)(char **args, char *payload, struct appctx *appctx, void *private);
|
|
int (*io_handler)(struct appctx *appctx);
|
|
void (*io_release)(struct appctx *appctx);
|
|
void *private;
|
|
int level; /* this is the level needed to show the keyword usage and to use it */
|
|
};
|
|
|
|
struct cli_kw_list {
|
|
struct list list;
|
|
struct cli_kw kw[VAR_ARRAY];
|
|
};
|
|
|
|
/* CLI states */
|
|
enum {
|
|
CLI_ST_INIT = 0, /* initial state, must leave to zero ! */
|
|
CLI_ST_END, /* final state, let's close */
|
|
CLI_ST_GETREQ, /* wait for a request */
|
|
CLI_ST_OUTPUT, /* all states after this one are responses */
|
|
CLI_ST_PROMPT, /* display the prompt (first output, same code) */
|
|
CLI_ST_PRINT, /* display const message in cli->msg */
|
|
CLI_ST_PRINT_ERR, /* display const error in cli->msg */
|
|
CLI_ST_PRINT_DYN, /* display dynamic message in cli->err. After the display, free the pointer */
|
|
CLI_ST_PRINT_FREE, /* display dynamic error in cli->err. After the display, free the pointer */
|
|
CLI_ST_CALLBACK, /* custom callback pointer */
|
|
};
|
|
|
|
/* CLI severity output formats */
|
|
enum {
|
|
CLI_SEVERITY_UNDEFINED = 0, /* undefined severity format */
|
|
CLI_SEVERITY_NONE, /* no severity information prepended */
|
|
CLI_SEVERITY_NUMBER, /* prepend informational cli messages with a severity as number */
|
|
CLI_SEVERITY_STRING, /* prepend informational cli messages with a severity as string */
|
|
};
|
|
|
|
|
|
#endif /* _TYPES_CLI_H */
|