summaryrefslogtreecommitdiffstats
path: root/include/haproxy/cli.h
blob: 32c6599446025e593977171dc799c24e7e8eba2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
 * include/haproxy/cli.h
 * This file contains definitions of some primitives to dedicated to
 * statistics output.
 *
 * Copyright (C) 2000-2011 Willy Tarreau - w@1wt.eu
 *
 * 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 _HAPROXY_CLI_H
#define _HAPROXY_CLI_H

#include <haproxy/applet.h>
#include <haproxy/channel-t.h>
#include <haproxy/cli-t.h>
#include <haproxy/global.h>
#include <haproxy/mworker-t.h>
#include <haproxy/stream-t.h>


void cli_register_kw(struct cli_kw_list *kw_list);
struct cli_kw* cli_find_kw_exact(char **args);
void cli_list_keywords(void);

int cli_has_level(struct appctx *appctx, int level);

int cli_parse_default(char **args, char *payload, struct appctx *appctx, void *private);

/* mworker proxy functions */

int mworker_cli_proxy_create(void);
struct bind_conf *mworker_cli_proxy_new_listener(char *line);
int mworker_cli_sockpair_new(struct mworker_proc *mworker_proc, int proc);
void mworker_cli_proxy_stop(void);

extern struct bind_conf *mcli_reload_bind_conf;

/* proxy mode cli functions */

/* analyzers */
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)
{
	struct cli_print_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx));

	ctx->severity = severity;
	ctx->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)
{
	struct cli_print_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx));

	ctx->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)
{
	struct cli_print_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx));

	ctx->severity = severity;
	ctx->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)
{
	struct cli_print_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx));

	ctx->err = err;
	appctx->st0 = CLI_ST_PRINT_DYNERR;
	return 1;
}

/* updates the CLI's context to log messages stored in thread-local
 * usermsgs_ctx at <severity> level. usermsgs_ctx will be reset when done.
 * This is for use in CLI parsers to deal with quick response messages.
 *
 * Always returns 1.
 */
static inline int cli_umsg(struct appctx *appctx, int severity)
{
	struct cli_print_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx));

	ctx->severity = severity;
	appctx->st0 = CLI_ST_PRINT_UMSG;
	return 1;
}

/* updates the CLI's context to log messages stored in thread-local
 * usermsgs_ctx using error level. usermsgs_ctx will be reset when done.
 * This is for use in CLI parsers to deal with quick response messages.
 *
 * Always returns 1.
 */
static inline int cli_umsgerr(struct appctx *appctx)
{
	appctx->st0 = CLI_ST_PRINT_UMSGERR;
	return 1;
}

#endif /* _HAPROXY_CLI_H */