iof-bird-daemon / nest / cli.h @ e0a45fb4
History | View | Annotate | Download (2.14 KB)
1 |
/*
|
---|---|
2 |
* BIRD Internet Routing Daemon -- Command-Line Interface
|
3 |
*
|
4 |
* (c) 1999--2000 Martin Mares <mj@ucw.cz>
|
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" |
14 |
|
15 |
#define CLI_RX_BUF_SIZE 4096 |
16 |
#define CLI_TX_BUF_SIZE 4096 |
17 |
#define CLI_MAX_ASYNC_QUEUE 4096 |
18 |
|
19 |
struct cli_out {
|
20 |
struct cli_out *next;
|
21 |
byte *wpos, *outpos, *end; |
22 |
byte buf[0];
|
23 |
}; |
24 |
|
25 |
typedef struct cli { |
26 |
node n; /* Node in list of all log hooks */
|
27 |
pool *pool; |
28 |
void *priv; /* Private to sysdep layer */ |
29 |
byte *rx_buf, *rx_pos, *rx_aux; /* sysdep */
|
30 |
struct cli_out *tx_buf, *tx_pos, *tx_write;
|
31 |
event *event; |
32 |
void (*cont)(struct cli *c); |
33 |
void (*cleanup)(struct cli *c); |
34 |
void *rover; /* Private to continuation routine */ |
35 |
int last_reply;
|
36 |
int restricted; /* CLI is restricted to read-only commands */ |
37 |
struct linpool *parser_pool; /* Pool used during parsing */ |
38 |
byte *ring_buf; /* Ring buffer for asynchronous messages */
|
39 |
byte *ring_end, *ring_read, *ring_write; /* Pointers to the ring buffer */
|
40 |
unsigned int ring_overflow; /* Counter of ring overflows */ |
41 |
unsigned int log_mask; /* Mask of allowed message levels */ |
42 |
unsigned int log_threshold; /* When free < log_threshold, store only important messages */ |
43 |
unsigned int async_msg_size; /* Total size of async messages queued in tx_buf */ |
44 |
} cli; |
45 |
|
46 |
extern pool *cli_pool;
|
47 |
extern struct cli *this_cli; /* Used during parsing */ |
48 |
|
49 |
/* Functions to be called by command handlers */
|
50 |
|
51 |
void cli_printf(cli *, int, char *, ...); |
52 |
#define cli_msg(x...) cli_printf(this_cli, x)
|
53 |
void cli_set_log_echo(cli *, unsigned int mask, unsigned int size); |
54 |
|
55 |
/* Functions provided to sysdep layer */
|
56 |
|
57 |
cli *cli_new(void *);
|
58 |
void cli_init(void); |
59 |
void cli_free(cli *);
|
60 |
void cli_kick(cli *);
|
61 |
void cli_written(cli *);
|
62 |
void cli_echo(unsigned int class, byte *msg); |
63 |
|
64 |
static inline int cli_access_restricted(void) |
65 |
{ |
66 |
if (this_cli && this_cli->restricted)
|
67 |
return (cli_printf(this_cli, 8007, "Access denied"), 1); |
68 |
else
|
69 |
return 0; |
70 |
} |
71 |
|
72 |
/* Functions provided by sysdep layer */
|
73 |
|
74 |
void cli_write_trigger(cli *);
|
75 |
int cli_get_command(cli *);
|
76 |
|
77 |
#endif
|