summaryrefslogtreecommitdiff
path: root/accel-pppd/cli
diff options
context:
space:
mode:
authorGuillaume Nault <g.nault@alphalink.fr>2013-02-08 14:27:40 +0100
committerKozlov Dmitry <xeb@mail.ru>2013-02-12 00:05:40 +0400
commite4048085a8742490e613fa960a4749bd5530fc88 (patch)
treec74aecf815612c1d077c12cf43a0852d05034ef8 /accel-pppd/cli
parent58e46bf8447f7c4ab96dd15251b769bc5647f7db (diff)
downloadaccel-ppp-e4048085a8742490e613fa960a4749bd5530fc88.tar.gz
accel-ppp-e4048085a8742490e613fa960a4749bd5530fc88.zip
cli: Handle arguments to the "help" command
When arguments are supplied to the "help" command, only display help messages corresponding to the command these arguments refer to (e.g. "help pppoe" will only show help messages for commands starting with "pppoe"). Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Diffstat (limited to 'accel-pppd/cli')
-rw-r--r--accel-pppd/cli/cli.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/accel-pppd/cli/cli.c b/accel-pppd/cli/cli.c
index e7e9e92..a9d5a4c 100644
--- a/accel-pppd/cli/cli.c
+++ b/accel-pppd/cli/cli.c
@@ -171,6 +171,7 @@ static int cli_process_help_cmd(struct cli_client_t *cln)
struct cli_simple_cmd_t *sicmd = NULL;
char *cmd = (char *)cln->cmdline;
char *items[MAX_CMD_ITEMS] = { 0 };
+ int cmd_found = 0;
int nb_items;
cmd = skip_space(cmd);
@@ -182,19 +183,40 @@ static int cli_process_help_cmd(struct cli_client_t *cln)
cmd = skip_space(cmd + helpcmd_len);
+ if (cmd[0] == '\0')
+ /* "help" with no argument always succeeds */
+ cmd_found = 1;
+
list_for_each_entry(recmd, &regexp_cmd_list, entry) {
if (cmd[0] == '\0'
|| pcre_exec(recmd->h_re, NULL, cmd, strlen(cmd),
0, 0, NULL, 0) >= 0) {
+ cmd_found = 1;
if (recmd->help)
recmd->help(cmd, cln);
}
}
nb_items = split(cmd, items);
- list_for_each_entry(sicmd, &simple_cmd_list, entry)
- if (sicmd->help)
- sicmd->help(items, nb_items, cln);
+ list_for_each_entry(sicmd, &simple_cmd_list, entry) {
+ int indx = 0;
+ int found = 1;
+ while (indx < sicmd->hdr_len && indx < nb_items) {
+ if (strcmp(sicmd->hdr[indx], items[indx]) != 0) {
+ found = 0;
+ break;
+ }
+ ++indx;
+ }
+ if (found) {
+ cmd_found = 1;
+ if (sicmd->help)
+ sicmd->help(items, nb_items, cln);
+ }
+ }
+
+ if (!cmd_found)
+ cli_send(cln, MSG_INVAL_ERROR);
return 1;
}