Revision bc2fb680 nest/cli.c

View differences:

nest/cli.c
7 7
 */
8 8

  
9 9
#include "nest/bird.h"
10
#include "lib/string.h"
11 10
#include "nest/cli.h"
11
#include "conf/conf.h"
12
#include "lib/string.h"
12 13

  
13 14
pool *cli_pool;
14 15

  
......
88 89
    }
89 90
}
90 91

  
92
static byte *cli_rh_pos;
93
static unsigned int cli_rh_len;
94
static int cli_rh_trick_flag;
95
struct cli *this_cli;
96

  
97
static int
98
cli_cmd_read_hook(byte *buf, unsigned int max)
99
{
100
  if (!cli_rh_trick_flag)
101
    {
102
      cli_rh_trick_flag = 1;
103
      buf[0] = '!';
104
      return 1;
105
    }
106
  if (max > cli_rh_len)
107
    max = cli_rh_len;
108
  memcpy(buf, cli_rh_pos, max);
109
  cli_rh_pos += max;
110
  cli_rh_len -= max;
111
  return max;
112
}
113

  
114
static void
115
cli_command(struct cli *c)
116
{
117
  struct config f;
118
  int res;
119

  
120
  f.pool = NULL;
121
  f.mem = c->parser_pool;
122
  cf_read_hook = cli_cmd_read_hook;
123
  cli_rh_pos = c->rx_buf;
124
  cli_rh_len = strlen(c->rx_buf);
125
  cli_rh_trick_flag = 0;
126
  this_cli = c;
127
  res = cli_parse(&f);
128
  lp_flush(c->parser_pool);
129
  if (!res)
130
    cli_printf(c, 9001, f.err_msg);
131
}
132

  
91 133
static int
92 134
cli_event(void *data)
93 135
{
......
106 148
      if (err < 0)
107 149
	cli_printf(c, 9000, "Command too long");
108 150
      else
109
	{
110
	  cli_printf(c, -9001, "Parse error in:");
111
	  cli_printf(c, 9001, c->rx_buf);
112
	}
151
	cli_command(c);
113 152
    }
114 153
  if (cli_write(c))
115 154
    {
......
133 172
  c->tx_buf = c->tx_pos = c->tx_write = NULL;
134 173
  c->cont = cli_hello;
135 174
  c->last_reply = 0;
175
  c->parser_pool = lp_new(c->pool, 4096);
136 176
  ev_schedule(c->event);
137 177
  return c;
138 178
}

Also available in: Unified diff