cli.h 2.23 KB
Newer Older
1 2 3
/*
 *	BIRD Internet Routing Daemon -- Command-Line Interface
 *
4
 *	(c) 1999--2000 Martin Mares <mj@ucw.cz>
5 6 7 8 9 10 11 12 13 14 15 16
 *
 *	Can be freely distributed and used under the terms of the GNU GPL.
 */

#ifndef _BIRD_CLI_H_
#define _BIRD_CLI_H_

#include "lib/resource.h"
#include "lib/event.h"

#define CLI_RX_BUF_SIZE 4096
#define CLI_TX_BUF_SIZE 4096
17
#define CLI_MAX_ASYNC_QUEUE 4096
18

19 20 21
#define CLI_MSG_SIZE 500
#define CLI_LINE_SIZE 512

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

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

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

53 54
#define CLI_ASYNC_CODE 10000

55 56 57
/* Functions to be called by command handlers */

void cli_printf(cli *, int, char *, ...);
58
#define cli_msg(x...) cli_printf(this_cli, x)
Pavel Tvrdík's avatar
Pavel Tvrdík committed
59
void cli_set_log_echo(cli *, uint mask, uint size);
60 61 62

/* Functions provided to sysdep layer */

63 64 65 66 67
cli *cli_new(void *);
void cli_init(void);
void cli_free(cli *);
void cli_kick(cli *);
void cli_written(cli *);
Pavel Tvrdík's avatar
Pavel Tvrdík committed
68
void cli_echo(uint class, byte *msg);
69

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

78
/* Functions provided by sysdep layer */
79

80
void cli_write_trigger(cli *);
81 82 83
int cli_get_command(cli *);

#endif