]>
Commit | Line | Data |
---|---|---|
7d3aab1c MM |
1 | /* |
2 | * BIRD Internet Routing Daemon -- Command-Line Interface | |
3 | * | |
4b87e256 | 4 | * (c) 1999--2000 Martin Mares <mj@ucw.cz> |
7d3aab1c MM |
5 | * |
6 | * Can be freely distributed and used under the terms of the GNU GPL. | |
7 | */ | |
8 | ||
9 | #ifndef _BIRD_CLI_H_ | |
10 | #define _BIRD_CLI_H_ | |
11 | ||
12 | #include "lib/resource.h" | |
13 | #include "lib/event.h" | |
82d57fb7 | 14 | #include "lib/timer.h" |
a95fff37 MM |
15 | #include "lib/tlists.h" |
16 | #include "conf/conf.h" | |
7d3aab1c MM |
17 | |
18 | #define CLI_RX_BUF_SIZE 4096 | |
19 | #define CLI_TX_BUF_SIZE 4096 | |
34350a52 | 20 | #define CLI_MAX_ASYNC_QUEUE 4096 |
7d3aab1c | 21 | |
fdf16eb6 OZ |
22 | #define CLI_MSG_SIZE 500 |
23 | #define CLI_LINE_SIZE 512 | |
24 | ||
7d3aab1c MM |
25 | struct cli_out { |
26 | struct cli_out *next; | |
27 | byte *wpos, *outpos, *end; | |
28 | byte buf[0]; | |
29 | }; | |
30 | ||
31 | typedef struct cli { | |
34350a52 | 32 | node n; /* Node in list of all log hooks */ |
7d3aab1c MM |
33 | pool *pool; |
34 | void *priv; /* Private to sysdep layer */ | |
4c19a8a9 | 35 | byte *rx_buf, *rx_pos; /* sysdep */ |
7d3aab1c MM |
36 | struct cli_out *tx_buf, *tx_pos, *tx_write; |
37 | event *event; | |
b9672a84 | 38 | void (*cont)(struct cli *c); |
ffb59d24 | 39 | void (*cleanup)(struct cli *c); |
b9672a84 MM |
40 | void *rover; /* Private to continuation routine */ |
41 | int last_reply; | |
e0a45fb4 | 42 | int restricted; /* CLI is restricted to read-only commands */ |
82d57fb7 | 43 | struct timeformat *tf; /* Time format override */ |
bc2fb680 | 44 | struct linpool *parser_pool; /* Pool used during parsing */ |
f8d44b01 | 45 | struct linpool *show_pool; /* Pool used during route show */ |
34350a52 MM |
46 | byte *ring_buf; /* Ring buffer for asynchronous messages */ |
47 | byte *ring_end, *ring_read, *ring_write; /* Pointers to the ring buffer */ | |
ae80a2de PT |
48 | uint ring_overflow; /* Counter of ring overflows */ |
49 | uint log_mask; /* Mask of allowed message levels */ | |
50 | uint log_threshold; /* When free < log_threshold, store only important messages */ | |
51 | uint async_msg_size; /* Total size of async messages queued in tx_buf */ | |
7d3aab1c MM |
52 | } cli; |
53 | ||
a95fff37 MM |
54 | struct cli_config { |
55 | #define TLIST_PREFIX cli_config | |
56 | #define TLIST_TYPE struct cli_config | |
57 | #define TLIST_ITEM n | |
58 | #define TLIST_DEFINED_BEFORE | |
59 | #define TLIST_WANT_ADD_TAIL | |
f3b6661d | 60 | #define TLIST_WANT_WALK |
a95fff37 MM |
61 | TLIST_DEFAULT_NODE; |
62 | const char *name; | |
f3b6661d | 63 | struct config *config; |
a95fff37 | 64 | uint uid, gid, mode; |
08ff0af8 | 65 | _Bool restricted; |
a95fff37 MM |
66 | }; |
67 | #include "lib/tlists.h" | |
68 | ||
f3b6661d MM |
69 | void cli_config_listen(struct cli_config *, const char *); |
70 | ||
7d3aab1c | 71 | extern pool *cli_pool; |
bc2fb680 | 72 | extern struct cli *this_cli; /* Used during parsing */ |
7d3aab1c | 73 | |
a92cf57d OZ |
74 | #define CLI_ASYNC_CODE 10000 |
75 | ||
b9672a84 MM |
76 | /* Functions to be called by command handlers */ |
77 | ||
145830bd MM |
78 | void cli_vprintf(cli *, int, const char *, va_list); |
79 | static inline void cli_printf(cli *cli, int code, const char *fmt, ...) | |
80 | { | |
81 | va_list args; | |
82 | va_start(args, fmt); | |
83 | cli_vprintf(cli, code, fmt, args); | |
84 | va_end(args); | |
85 | } | |
86 | ||
35793769 | 87 | #define cli_msg(x...) cli_printf(this_cli, x) |
ae80a2de | 88 | void cli_set_log_echo(cli *, uint mask, uint size); |
82d57fb7 | 89 | void cli_set_timeformat(cli *c, const struct timeformat tf); |
b9672a84 | 90 | |
c26c6bc2 OZ |
91 | static inline void cli_separator(cli *c) |
92 | { if (c->last_reply) cli_printf(c, -c->last_reply, ""); }; | |
93 | ||
b9672a84 MM |
94 | /* Functions provided to sysdep layer */ |
95 | ||
08ff0af8 | 96 | cli *cli_new(void *, struct cli_config *); |
7d3aab1c MM |
97 | void cli_init(void); |
98 | void cli_free(cli *); | |
99 | void cli_kick(cli *); | |
100 | void cli_written(cli *); | |
ae80a2de | 101 | void cli_echo(uint class, byte *msg); |
7d3aab1c | 102 | |
e0a45fb4 OZ |
103 | static inline int cli_access_restricted(void) |
104 | { | |
105 | if (this_cli && this_cli->restricted) | |
106 | return (cli_printf(this_cli, 8007, "Access denied"), 1); | |
107 | else | |
108 | return 0; | |
109 | } | |
110 | ||
b9672a84 | 111 | /* Functions provided by sysdep layer */ |
7d3aab1c | 112 | |
6baef17e | 113 | void cli_write_trigger(cli *); |
7d3aab1c MM |
114 | int cli_get_command(cli *); |
115 | ||
116 | #endif |