summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Nault <g.nault@alphalink.fr>2013-02-08 14:26:54 +0100
committerKozlov Dmitry <xeb@mail.ru>2013-02-12 00:05:02 +0400
commit1f20c83e04cfcf7ec0d9fefa934b1b7e79d03dc2 (patch)
tree5c4f3f553e96314054f6a3a8c46118dff723c030
parent2e13e02a408319ba2be3b703fb466d0be4e57d52 (diff)
downloadaccel-ppp-1f20c83e04cfcf7ec0d9fefa934b1b7e79d03dc2.tar.gz
accel-ppp-1f20c83e04cfcf7ec0d9fefa934b1b7e79d03dc2.zip
cli: Fix regexp command handling
* Call pcre_compile2() with all mandatory arguments and improve error message. * Register regexp commands in regexp_cmd_list instead of simple_cmd_list. * Fix "help" function call. * Interpret regexp command return codes (CLI_CMD_*) in the same way as for simple commands. Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
-rw-r--r--accel-pppd/cli/cli.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/accel-pppd/cli/cli.c b/accel-pppd/cli/cli.c
index 90341cd..3240d77 100644
--- a/accel-pppd/cli/cli.c
+++ b/accel-pppd/cli/cli.c
@@ -61,12 +61,19 @@ void __export cli_register_simple_cmd2(
void __export cli_register_regexp_cmd(struct cli_regexp_cmd_t *cmd)
{
int err;
- cmd->re = pcre_compile2(cmd->pattern, cmd->options, &err, NULL, NULL, NULL);
+ int erroffset;
+ const char *errptr;
+
+ cmd->re = pcre_compile2(cmd->pattern, cmd->options, &err,
+ &errptr, &erroffset, NULL);
if (!cmd->re) {
- log_emerg("cli: failed to compile regexp %s: %i\n", cmd->pattern, err);
+ log_emerg("cli: failed to compile regexp \"%s\": %s (error %i)"
+ " at positon %i (unprocessed characters: \"%s\")\n",
+ cmd->pattern, errptr, err, erroffset,
+ cmd->pattern + erroffset);
_exit(EXIT_FAILURE);
}
- list_add_tail(&cmd->entry, &simple_cmd_list);
+ list_add_tail(&cmd->entry, &regexp_cmd_list);
}
int __export cli_send(void *client, const char *data)
@@ -146,7 +153,7 @@ int __export cli_process_cmd(struct cli_client_t *cln)
list_for_each_entry(cmd2, &regexp_cmd_list, entry)
if (cmd2->help)
- cmd1->help(f, n, cln);
+ cmd2->help(f, n, cln);
return 0;
}
@@ -183,10 +190,13 @@ int __export cli_process_cmd(struct cli_client_t *cln)
case CLI_CMD_EXIT:
cln->disconnect(cln);
case CLI_CMD_FAILED:
- return 0;
+ return -1;
case CLI_CMD_SYNTAX:
cli_send(cln, MSG_SYNTAX_ERROR);
return 0;
+ case CLI_CMD_INVAL:
+ cli_send(cln, MSG_INVAL_ERROR);
+ return 0;
case CLI_CMD_OK:
found = 1;
}