blob: 710e01433c72c8702874f307f7bd7723c85fc7fc [file] [log] [blame]
William Lallemand9ed62032016-11-21 17:49:11 +01001/*
2 * include/types/cli.h
3 * This file provides structures and types for CLI.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation, version 2.1
8 * exclusively.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifndef _TYPES_CLI_H
21#define _TYPES_CLI_H
22
Willy Tarreau3f0f82e2020-06-04 19:42:41 +020023#include <haproxy/applet-t.h>
Willy Tarreau853b2972020-05-27 18:01:47 +020024#include <haproxy/list-t.h>
William Lallemand9ed62032016-11-21 17:49:11 +010025
Willy Tarreau86bfe142019-10-24 13:50:48 +020026/* Access level for a stats socket */
27#define ACCESS_LVL_NONE 0
28#define ACCESS_LVL_USER 1
29#define ACCESS_LVL_OPER 2
30#define ACCESS_LVL_ADMIN 3
31#define ACCESS_LVL_MASK 0x3
32
33#define ACCESS_FD_LISTENERS 0x4 /* expose listeners FDs on stats socket */
34#define ACCESS_MASTER 0x8 /* works with the master (and every other processes) */
35#define ACCESS_MASTER_ONLY 0x10 /* only works with the worker */
36
Willy Tarreauabb9f9b2019-10-24 17:55:53 +020037#define ACCESS_EXPERT 0x20 /* access to dangerous commands reserved to experts */
38
Willy Tarreau3f0f82e2020-06-04 19:42:41 +020039/* flags for appctx->st1 */
40#define APPCTX_CLI_ST1_PROMPT (1 << 0)
41#define APPCTX_CLI_ST1_PAYLOAD (1 << 1)
42#define APPCTX_CLI_ST1_NOLF (1 << 2)
43
William Lallemand9ed62032016-11-21 17:49:11 +010044struct cli_kw {
45 const char *str_kw[5]; /* keywords ended by NULL, limited to 5
46 separated keywords combination */
47 const char *usage; /* usage message */
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +020048 int (*parse)(char **args, char *payload, struct appctx *appctx, void *private);
William Lallemand9ed62032016-11-21 17:49:11 +010049 int (*io_handler)(struct appctx *appctx);
50 void (*io_release)(struct appctx *appctx);
51 void *private;
William Lallemand14721be2018-10-26 14:47:37 +020052 int level; /* this is the level needed to show the keyword usage and to use it */
William Lallemand9ed62032016-11-21 17:49:11 +010053};
54
55struct cli_kw_list {
56 struct list list;
57 struct cli_kw kw[VAR_ARRAY];
58};
59
Willy Tarreau3b6e5472016-11-24 15:53:53 +010060/* CLI states */
William Lallemand9ed62032016-11-21 17:49:11 +010061enum {
Willy Tarreau3b6e5472016-11-24 15:53:53 +010062 CLI_ST_INIT = 0, /* initial state, must leave to zero ! */
63 CLI_ST_END, /* final state, let's close */
64 CLI_ST_GETREQ, /* wait for a request */
65 CLI_ST_OUTPUT, /* all states after this one are responses */
66 CLI_ST_PROMPT, /* display the prompt (first output, same code) */
Willy Tarreaud50c7fe2019-08-09 09:57:36 +020067 CLI_ST_PRINT, /* display const message in cli->msg */
68 CLI_ST_PRINT_ERR, /* display const error in cli->msg */
69 CLI_ST_PRINT_DYN, /* display dynamic message in cli->err. After the display, free the pointer */
70 CLI_ST_PRINT_FREE, /* display dynamic error in cli->err. After the display, free the pointer */
Willy Tarreau3b6e5472016-11-24 15:53:53 +010071 CLI_ST_CALLBACK, /* custom callback pointer */
William Lallemand9ed62032016-11-21 17:49:11 +010072};
73
Andjelko Iharosc4df59e2017-07-20 11:59:48 +020074/* CLI severity output formats */
75enum {
76 CLI_SEVERITY_UNDEFINED = 0, /* undefined severity format */
77 CLI_SEVERITY_NONE, /* no severity information prepended */
78 CLI_SEVERITY_NUMBER, /* prepend informational cli messages with a severity as number */
79 CLI_SEVERITY_STRING, /* prepend informational cli messages with a severity as string */
80};
81
William Lallemand9ed62032016-11-21 17:49:11 +010082
83#endif /* _TYPES_CLI_H */