Statistics
| Branch: | Revision:

iof-bird-daemon / nest / cli.h @ ae80a2de

History | View | Annotate | Download (2.17 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
#define CLI_MSG_SIZE 500
20
#define CLI_LINE_SIZE 512
21

    
22
struct cli_out {
23
  struct cli_out *next;
24
  byte *wpos, *outpos, *end;
25
  byte buf[0];
26
};
27

    
28
typedef struct cli {
29
  node n;                                /* Node in list of all log hooks */
30
  pool *pool;
31
  void *priv;                                /* Private to sysdep layer */
32
  byte *rx_buf, *rx_pos, *rx_aux;        /* sysdep */
33
  struct cli_out *tx_buf, *tx_pos, *tx_write;
34
  event *event;
35
  void (*cont)(struct cli *c);
36
  void (*cleanup)(struct cli *c);
37
  void *rover;                                /* Private to continuation routine */
38
  int last_reply;
39
  int restricted;                        /* CLI is restricted to read-only commands */
40
  struct linpool *parser_pool;                /* Pool used during parsing */
41
  byte *ring_buf;                        /* Ring buffer for asynchronous messages */
42
  byte *ring_end, *ring_read, *ring_write;        /* Pointers to the ring buffer */
43
  uint ring_overflow;                        /* Counter of ring overflows */
44
  uint log_mask;                        /* Mask of allowed message levels */
45
  uint log_threshold;                        /* When free < log_threshold, store only important messages */
46
  uint async_msg_size;                        /* Total size of async messages queued in tx_buf */
47
} cli;
48

    
49
extern pool *cli_pool;
50
extern struct cli *this_cli;                /* Used during parsing */
51

    
52
#define CLI_ASYNC_CODE 10000
53

    
54
/* Functions to be called by command handlers */
55

    
56
void cli_printf(cli *, int, char *, ...);
57
#define cli_msg(x...) cli_printf(this_cli, x)
58
void cli_set_log_echo(cli *, uint mask, uint size);
59

    
60
/* Functions provided to sysdep layer */
61

    
62
cli *cli_new(void *);
63
void cli_init(void);
64
void cli_free(cli *);
65
void cli_kick(cli *);
66
void cli_written(cli *);
67
void cli_echo(uint class, byte *msg);
68

    
69
static inline int cli_access_restricted(void)
70
{
71
  if (this_cli && this_cli->restricted)
72
    return (cli_printf(this_cli, 8007, "Access denied"), 1);
73
  else
74
    return 0;
75
}
76

    
77
/* Functions provided by sysdep layer */
78

    
79
void cli_write_trigger(cli *);
80
int cli_get_command(cli *);
81

    
82
#endif