You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

119 lines
4.2 KiB

From 26b77b7cdc70beddc68507f74372a4e2815720f0 Mon Sep 17 00:00:00 2001
From: Yousong Zhou <yszhou4tech@gmail.com>
Date: Sun, 17 May 2015 10:53:44 +0800
Subject: [PATCH 210/210] xl2tpd-control: show all available commands in
--help.
---
xl2tpd-control.c | 63 ++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 44 insertions(+), 19 deletions(-)
diff --git a/xl2tpd-control.c b/xl2tpd-control.c
index 6b08850..b98ff24 100644
--- a/xl2tpd-control.c
+++ b/xl2tpd-control.c
@@ -51,6 +51,7 @@ struct command_t
char *name;
int (*handler) (FILE*, char* tunnel, int optc, char *optv[]);
int requires_tunnel;
+ char *help;
};
int command_add_lac (FILE*, char* tunnel, int optc, char *optv[]);
@@ -65,13 +66,29 @@ int command_available (FILE*, char* tunnel, int optc, char *optv[]);
struct command_t commands[] = {
/* Keep this command mapping for backwards compat */
- {"add", &command_add_lac, TUNNEL_REQUIRED},
- {"connect", &command_connect_lac, TUNNEL_REQUIRED},
- {"disconnect", &command_disconnect_lac, TUNNEL_REQUIRED},
- {"remove", &command_remove_lac, TUNNEL_REQUIRED},
+ {"add", &command_add_lac, TUNNEL_REQUIRED,
+ "\tadd\tadds new or modify existing lac configuration.\n"
+ "\t\tConfiguration must be specified as command options in\n"
+ "\t\t<key>=<value> pairs format.\n"
+ "\t\tSee available options in xl2tpd.conf(5)\n"
+ },
+ {"connect", &command_connect_lac, TUNNEL_REQUIRED,
+ "\tconnect\ttries to activate the tunnel.\n"
+ "\t\tUsername and secret for the tunnel can be passed as\n"
+ "\t\tcommand options.\n"
+ },
+ {"disconnect", &command_disconnect_lac, TUNNEL_REQUIRED,
+ "\tdisconnect\tdisconnects the tunnel.\n"
+ },
+ {"remove", &command_remove_lac, TUNNEL_REQUIRED,
+ "\tremove\tremoves lac configuration from xl2tpd.\n"
+ "\t\txl2tpd disconnects the tunnel before removing.\n"
+ },
/* LAC commands */
- {"add-lac", &command_add_lac, TUNNEL_REQUIRED},
+ {"add-lac", &command_add_lac, TUNNEL_REQUIRED,
+ "\tadd-lns\tadds new or modify existing lns configuration.\n"
+ },
{"connect-lac", &command_connect_lac, TUNNEL_REQUIRED},
{"disconnect-lac", &command_disconnect_lac, TUNNEL_REQUIRED},
{"remove-lac", &command_remove_lac, TUNNEL_REQUIRED},
@@ -89,36 +106,44 @@ struct command_t commands[] = {
void usage()
{
+ int i;
+
printf ("\nxl2tpd server version %s\n", SERVER_VERSION);
printf ("Usage: xl2tpd-control [-c <PATH>] <command> <tunnel name> [<COMMAND OPTIONS>]\n"
"\n"
" -c\tspecifies xl2tpd control file\n"
" -d\tspecify xl2tpd-control to run in debug mode\n"
"--help\tshows extended help\n"
- "Available commands: add, connect, disconnect, remove, add-lns\n"
);
+
+ printf ("Available commands: ");
+ for (i = 0; commands[i].name; i++) {
+ struct command_t *command = &commands[i];
+ int last = command[1].name == NULL;
+
+ printf ("%s%s", command->name, !last ? ", " : "\n");
+ }
}
void help()
{
+ int i;
+
usage();
printf (
"\n"
"Commands help:\n"
- "\tadd\tadds new or modify existing lac configuration.\n"
- "\t\tConfiguration must be specified as command options in\n"
- "\t\t<key>=<value> pairs format.\n"
- "\t\tSee available options in xl2tpd.conf(5)\n"
- "\tconnect\ttries to activate the tunnel.\n"
- "\t\tUsername and secret for the tunnel can be passed as\n"
- "\t\tcommand options.\n"
- "\tdisconnect\tdisconnects the tunnel.\n"
- "\tremove\tremoves lac configuration from xl2tpd.\n"
- "\t\txl2tpd disconnects the tunnel before removing.\n"
- "\n"
- "\tadd-lns\tadds new or modify existing lns configuration.\n"
- "See xl2tpd-control man page for more help\n"
);
+
+ for (i = 0; commands[i].name; i++) {
+ struct command_t *command = &commands[i];
+
+ if (!command->help)
+ continue;
+ printf ("%s", command->help);
+ }
+ /*FIXME Ha! there is currently no manpage for xl2tpd-control */
+ printf ("See xl2tpd-control man page for more help\n");
}
void cleanup(void)
--
1.7.10.4