9000 Command too long
9001 Parse error
9002 Invalid symbol type
+9003 Pipelining not supported
c->cont(c);
else
{
- err = cli_get_command(c);
- if (!err)
- return;
- if (err < 0)
- cli_printf(c, 9000, "Command too long");
- else
- cli_command(c);
+ switch (cli_get_command(c))
+ {
+ case CGC_OK:
+ cli_command(c);
+ break;
+ case CGC_INCOMPLETE:
+ return;
+ case CGC_TOO_LONG:
+ cli_printf(c, 9000, "Command too long");
+ break;
+ case CGC_TRAILING:
+ cli_printf(c, 9003, "Pipelining not supported");
+ break;
+ }
}
cli_write_trigger(c);
node n; /* Node in list of all log hooks */
pool *pool;
void *priv; /* Private to sysdep layer */
- byte *rx_buf, *rx_pos, *rx_aux; /* sysdep */
+ byte *rx_buf, *rx_pos; /* sysdep */
struct cli_out *tx_buf, *tx_pos, *tx_write;
event *event;
void (*cont)(struct cli *c);
/* Functions provided by sysdep layer */
void cli_write_trigger(cli *);
-int cli_get_command(cli *);
+enum cli_get_command_result {
+ CGC_OK,
+ CGC_INCOMPLETE,
+ CGC_TOO_LONG,
+ CGC_TRAILING,
+};
+
+enum cli_get_command_result cli_get_command(cli *);
#endif
cli_write(s->data);
}
-int
+enum cli_get_command_result
cli_get_command(cli *c)
{
sock *s = c->priv;
- byte *t = c->rx_aux ? : s->rbuf;
+ byte *t = s->rbuf;
byte *tend = s->rpos;
byte *d = c->rx_pos;
byte *dend = c->rx_buf + CLI_RX_BUF_SIZE - 2;
t++;
else if (*t == '\n')
{
- t++;
+ if (++t < tend)
+ return CGC_TRAILING;
+
+ s->rpos = s->rbuf;
c->rx_pos = c->rx_buf;
- c->rx_aux = t;
*d = 0;
- return (d < dend) ? 1 : -1;
+ return (d < dend) ? CGC_OK : CGC_TOO_LONG;
}
else if (d < dend)
*d++ = *t++;
}
- c->rx_aux = s->rpos = s->rbuf;
+
+ s->rpos = s->rbuf;
c->rx_pos = d;
- return 0;
+ return CGC_INCOMPLETE;
}
static int
s->pool = c->pool; /* We need to have all the socket buffers allocated in the cli pool */
s->fast_rx = 1;
c->rx_pos = c->rx_buf;
- c->rx_aux = NULL;
rmove(s, c->pool);
return 1;
}
void sysdep_shutdown_done(void) {}
#include "nest/cli.h"
-int cli_get_command(cli *c UNUSED) { return 0; }
+enum cli_get_command_result cli_get_command(cli *c UNUSED) { return CGC_OK; }
void cli_write_trigger(cli *c UNUSED) {}
cli *cmd_reconfig_stored_cli;