From 1f20c83e04cfcf7ec0d9fefa934b1b7e79d03dc2 Mon Sep 17 00:00:00 2001 From: Guillaume Nault Date: Fri, 8 Feb 2013 14:26:54 +0100 Subject: 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 --- accel-pppd/cli/cli.c | 20 +++++++++++++++----- 1 file 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, ®exp_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, ®exp_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; } -- cgit v1.2.3