Commit 45edc4df authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Move vlu to the private cli struct and turn ->cmd into a VSB.

parent ea9bb000
......@@ -73,7 +73,7 @@ cli_cb_before(const struct cli *cli)
{
ASSERT_CLI();
VSL(SLT_CLI, 0, "Rd %s", cli->cmd);
VSL(SLT_CLI, 0, "Rd %s", VSB_data(cli->cmd));
VCL_Poll();
VBE_Poll();
Lck_Lock(&cli_mtx);
......
......@@ -340,8 +340,8 @@ mgt_cli_cb_before(const struct cli *cli)
{
if (cli->priv == stderr)
fprintf(stderr, "> %s\n", cli->cmd);
MGT_Complain(C_CLI, "CLI %s Rd %s", cli->ident, cli->cmd);
fprintf(stderr, "> %s\n", VSB_data(cli->cmd));
MGT_Complain(C_CLI, "CLI %s Rd %s", cli->ident, VSB_data(cli->cmd));
}
static void
......@@ -351,7 +351,7 @@ mgt_cli_cb_after(const struct cli *cli)
MGT_Complain(C_CLI, "CLI %s Wr %03u %s",
cli->ident, cli->result, VSB_data(cli->sb));
if (cli->priv == stderr &&
cli->result != CLIS_OK && cli->cmd[0] != '-') {
cli->result != CLIS_OK && *VSB_data(cli->cmd) != '-') {
MGT_Complain(C_ERR, "-I file CLI command failed (%d)\n%s\n",
cli->result, VSB_data(cli->sb));
exit(2);
......
......@@ -34,7 +34,6 @@
#include "vcli.h"
struct cli; /* NB: struct cli is opaque at this level. */
struct vlu;
struct VCLS;
typedef void cli_func_t(struct cli*, const char * const *av, void *priv);
......@@ -68,18 +67,17 @@ struct cli_proto {
/* a CLI session */
struct cli {
unsigned magic;
unsigned magic;
#define CLI_MAGIC 0x4038d570
void *priv;
struct vsb *sb;
enum VCLI_status_e result;
char *cmd;
unsigned auth;
char challenge[34];
char *ident;
struct vlu *vlu;
struct VCLS *cls;
volatile unsigned *limit;
struct vsb *sb;
enum VCLI_status_e result;
struct vsb *cmd;
unsigned auth;
char challenge[34];
char *ident;
struct VCLS *cls;
volatile unsigned *limit;
};
/* The implementation must provide these functions */
......
......@@ -64,6 +64,7 @@ struct VCLS_fd {
struct vsb *last_arg;
int last_idx;
char **argv;
struct vlu *vlu;
};
struct VCLS {
......@@ -342,9 +343,13 @@ cls_vlu(void *priv, const char *p)
continue;
if (*p == '\0')
return (0);
REPLACE(cli->cmd, p);
AN(p); /* for FlexeLint */
cli->cmd = VSB_new(NULL, NULL, strlen(p) + 1, 0);
AN(cli->cmd);
VSB_cat(cli->cmd, p);
AZ(VSB_finish(cli->cmd));
/* We ignore a single leading '-' (for -I cli_file) */
if (p[0] == '-')
av = VAV_Parse(p + 1, NULL, 0);
......@@ -354,8 +359,7 @@ cls_vlu(void *priv, const char *p)
if (av[0] != NULL) {
i = cls_vlu2(priv, av);
VAV_Free(av);
free(cli->cmd);
cli->cmd = NULL;
VSB_destroy(&cli->cmd);
return (i);
}
for (i = 1; av[i] != NULL; i++)
......@@ -363,8 +367,7 @@ cls_vlu(void *priv, const char *p)
if (i < 3 || cli->auth == 0 || strcmp(av[i - 2], "<<")) {
i = cls_vlu2(priv, av);
VAV_Free(av);
free(cli->cmd);
cli->cmd = NULL;
VSB_destroy(&cli->cmd);
return (i);
}
cfd->argv = av;
......@@ -391,8 +394,7 @@ cls_vlu(void *priv, const char *p)
cfd->argv[cfd->last_idx] = NULL;
VAV_Free(cfd->argv);
cfd->argv = NULL;
free(cli->cmd);
cli->cmd = NULL;
VSB_destroy(&cli->cmd);
VSB_destroy(&cfd->last_arg);
cfd->last_idx = 0;
return (i);
......@@ -437,8 +439,8 @@ VCLS_AddFd(struct VCLS *cs, int fdi, int fdo, cls_cb_f *closefunc, void *priv)
cfd->fdo = fdo;
cfd->cli = &cfd->clis;
cfd->cli->magic = CLI_MAGIC;
cfd->cli->vlu = VLU_New(cls_vlu, cfd, *cs->maxlen);
AN(cfd->cli->vlu);
cfd->vlu = VLU_New(cls_vlu, cfd, *cs->maxlen);
AN(cfd->vlu);
cfd->cli->sb = VSB_new_auto();
AN(cfd->cli->sb);
cfd->cli->limit = cs->limit;
......@@ -459,7 +461,7 @@ cls_close_fd(struct VCLS *cs, struct VCLS_fd *cfd)
VTAILQ_REMOVE(&cs->fds, cfd, list);
cs->nfd--;
VLU_Destroy(&cfd->cli->vlu);
VLU_Destroy(&cfd->vlu);
VSB_destroy(&cfd->cli->sb);
if (cfd->closefunc == NULL) {
(void)close(cfd->fdi);
......@@ -538,7 +540,7 @@ VCLS_Poll(struct VCLS *cs, const struct cli *cli, int timeout)
if (pfd[0].revents & POLLHUP)
k = 1;
else
k = VLU_Fd(cfd->cli->vlu, cfd->fdi);
k = VLU_Fd(cfd->vlu, cfd->fdi);
if (k)
cls_close_fd(cs, cfd);
return (k);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment