xl2tpd: conditionally build with flags for more verbose log output.
[feed/packages.git] / net / xl2tpd / patches / 210-xl2tpd-control-show-all-available-commands-in-help.patch
1 From 26b77b7cdc70beddc68507f74372a4e2815720f0 Mon Sep 17 00:00:00 2001
2 From: Yousong Zhou <yszhou4tech@gmail.com>
3 Date: Sun, 17 May 2015 10:53:44 +0800
4 Subject: [PATCH 210/210] xl2tpd-control: show all available commands in
5 --help.
6
7 ---
8 xl2tpd-control.c | 63 ++++++++++++++++++++++++++++++++++++++----------------
9 1 file changed, 44 insertions(+), 19 deletions(-)
10
11 diff --git a/xl2tpd-control.c b/xl2tpd-control.c
12 index 6b08850..b98ff24 100644
13 --- a/xl2tpd-control.c
14 +++ b/xl2tpd-control.c
15 @@ -51,6 +51,7 @@ struct command_t
16 char *name;
17 int (*handler) (FILE*, char* tunnel, int optc, char *optv[]);
18 int requires_tunnel;
19 + char *help;
20 };
21
22 int command_add_lac (FILE*, char* tunnel, int optc, char *optv[]);
23 @@ -65,13 +66,29 @@ int command_available (FILE*, char* tunnel, int optc, char *optv[]);
24
25 struct command_t commands[] = {
26 /* Keep this command mapping for backwards compat */
27 - {"add", &command_add_lac, TUNNEL_REQUIRED},
28 - {"connect", &command_connect_lac, TUNNEL_REQUIRED},
29 - {"disconnect", &command_disconnect_lac, TUNNEL_REQUIRED},
30 - {"remove", &command_remove_lac, TUNNEL_REQUIRED},
31 + {"add", &command_add_lac, TUNNEL_REQUIRED,
32 + "\tadd\tadds new or modify existing lac configuration.\n"
33 + "\t\tConfiguration must be specified as command options in\n"
34 + "\t\t<key>=<value> pairs format.\n"
35 + "\t\tSee available options in xl2tpd.conf(5)\n"
36 + },
37 + {"connect", &command_connect_lac, TUNNEL_REQUIRED,
38 + "\tconnect\ttries to activate the tunnel.\n"
39 + "\t\tUsername and secret for the tunnel can be passed as\n"
40 + "\t\tcommand options.\n"
41 + },
42 + {"disconnect", &command_disconnect_lac, TUNNEL_REQUIRED,
43 + "\tdisconnect\tdisconnects the tunnel.\n"
44 + },
45 + {"remove", &command_remove_lac, TUNNEL_REQUIRED,
46 + "\tremove\tremoves lac configuration from xl2tpd.\n"
47 + "\t\txl2tpd disconnects the tunnel before removing.\n"
48 + },
49
50 /* LAC commands */
51 - {"add-lac", &command_add_lac, TUNNEL_REQUIRED},
52 + {"add-lac", &command_add_lac, TUNNEL_REQUIRED,
53 + "\tadd-lns\tadds new or modify existing lns configuration.\n"
54 + },
55 {"connect-lac", &command_connect_lac, TUNNEL_REQUIRED},
56 {"disconnect-lac", &command_disconnect_lac, TUNNEL_REQUIRED},
57 {"remove-lac", &command_remove_lac, TUNNEL_REQUIRED},
58 @@ -89,36 +106,44 @@ struct command_t commands[] = {
59
60 void usage()
61 {
62 + int i;
63 +
64 printf ("\nxl2tpd server version %s\n", SERVER_VERSION);
65 printf ("Usage: xl2tpd-control [-c <PATH>] <command> <tunnel name> [<COMMAND OPTIONS>]\n"
66 "\n"
67 " -c\tspecifies xl2tpd control file\n"
68 " -d\tspecify xl2tpd-control to run in debug mode\n"
69 "--help\tshows extended help\n"
70 - "Available commands: add, connect, disconnect, remove, add-lns\n"
71 );
72 +
73 + printf ("Available commands: ");
74 + for (i = 0; commands[i].name; i++) {
75 + struct command_t *command = &commands[i];
76 + int last = command[1].name == NULL;
77 +
78 + printf ("%s%s", command->name, !last ? ", " : "\n");
79 + }
80 }
81
82 void help()
83 {
84 + int i;
85 +
86 usage();
87 printf (
88 "\n"
89 "Commands help:\n"
90 - "\tadd\tadds new or modify existing lac configuration.\n"
91 - "\t\tConfiguration must be specified as command options in\n"
92 - "\t\t<key>=<value> pairs format.\n"
93 - "\t\tSee available options in xl2tpd.conf(5)\n"
94 - "\tconnect\ttries to activate the tunnel.\n"
95 - "\t\tUsername and secret for the tunnel can be passed as\n"
96 - "\t\tcommand options.\n"
97 - "\tdisconnect\tdisconnects the tunnel.\n"
98 - "\tremove\tremoves lac configuration from xl2tpd.\n"
99 - "\t\txl2tpd disconnects the tunnel before removing.\n"
100 - "\n"
101 - "\tadd-lns\tadds new or modify existing lns configuration.\n"
102 - "See xl2tpd-control man page for more help\n"
103 );
104 +
105 + for (i = 0; commands[i].name; i++) {
106 + struct command_t *command = &commands[i];
107 +
108 + if (!command->help)
109 + continue;
110 + printf ("%s", command->help);
111 + }
112 + /*FIXME Ha! there is currently no manpage for xl2tpd-control */
113 + printf ("See xl2tpd-control man page for more help\n");
114 }
115
116 void cleanup(void)
117 --
118 1.7.10.4
119