strongswan.org
Wiki/Project Management
Downloads
Gitweb
projects
/
strongswan.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
012f62a
)
pki tool supports single letter short options
author
Martin Willi
<martin@strongswan.org>
Tue, 15 Sep 2009 08:20:22 +0000
(10:20 +0200)
committer
Martin Willi
<martin@strongswan.org>
Tue, 15 Sep 2009 08:20:22 +0000
(10:20 +0200)
src/pki/command.c
patch
|
blob
|
history
src/pki/command.h
patch
|
blob
|
history
src/pki/commands/gen.c
patch
|
blob
|
history
src/pki/commands/issue.c
patch
|
blob
|
history
src/pki/commands/keyid.c
patch
|
blob
|
history
src/pki/commands/pub.c
patch
|
blob
|
history
src/pki/commands/self.c
patch
|
blob
|
history
src/pki/commands/verify.c
patch
|
blob
|
history
diff --git
a/src/pki/command.c
b/src/pki/command.c
index
1055955
..
2cf1365
100644
(file)
--- a/
src/pki/command.c
+++ b/
src/pki/command.c
@@
-46,19
+46,26
@@
static int help_idx;
struct option command_opts[MAX_COMMANDS > MAX_OPTIONS ?: MAX_OPTIONS];
/**
struct option command_opts[MAX_COMMANDS > MAX_OPTIONS ?: MAX_OPTIONS];
/**
- * Build long_opts for a specific command
+ * Global optstring used by all subcommands
+ */
+char command_optstring[(MAX_COMMANDS > MAX_OPTIONS ?: MAX_OPTIONS) * 3];
+
+/**
+ * Build command_opts/command_optstr for the active command
*/
static void build_opts()
{
*/
static void build_opts()
{
- int i;
+ int i
, pos = 0
;
memset(command_opts, 0, sizeof(command_opts));
memset(command_opts, 0, sizeof(command_opts));
+ memset(command_optstring, 0, sizeof(command_optstring));
if (active == help_idx)
{
for (i = 0; cmds[i].cmd; i++)
{
command_opts[i].name = cmds[i].cmd;
command_opts[i].val = cmds[i].op;
if (active == help_idx)
{
for (i = 0; cmds[i].cmd; i++)
{
command_opts[i].name = cmds[i].cmd;
command_opts[i].val = cmds[i].op;
+ command_optstring[i] = cmds[i].op;
}
}
else
}
}
else
@@
-68,6
+75,19
@@
static void build_opts()
command_opts[i].name = cmds[active].options[i].name;
command_opts[i].has_arg = cmds[active].options[i].arg;
command_opts[i].val = cmds[active].options[i].op;
command_opts[i].name = cmds[active].options[i].name;
command_opts[i].has_arg = cmds[active].options[i].arg;
command_opts[i].val = cmds[active].options[i].op;
+ command_optstring[pos++] = cmds[active].options[i].op;
+ switch (cmds[active].options[i].arg)
+ {
+ case optional_argument:
+ command_optstring[pos++] = ':';
+ /* FALL */
+ case required_argument:
+ command_optstring[pos++] = ':';
+ /* FALL */
+ case no_argument:
+ default:
+ break;
+ }
}
}
}
}
}
}
@@
-86,6
+106,7
@@
void command_register(command_t command)
int command_usage(char *error)
{
FILE *out = stdout;
int command_usage(char *error)
{
FILE *out = stdout;
+ char buf[64];
int i;
if (error)
int i;
if (error)
@@
-99,7
+120,8
@@
int command_usage(char *error)
{
for (i = 0; cmds[i].cmd; i++)
{
{
for (i = 0; cmds[i].cmd; i++)
{
- fprintf(out, " pki --%-6s %s\n", cmds[i].cmd, cmds[i].description);
+ snprintf(buf, sizeof(buf), "--%s (-%c)", cmds[i].cmd, cmds[i].op);
+ fprintf(out, " pki %-14s %s\n", buf, cmds[i].description);
}
}
else
}
}
else
@@
-118,8
+140,10
@@
int command_usage(char *error)
}
for (i = 0; cmds[active].options[i].name; i++)
{
}
for (i = 0; cmds[active].options[i].name; i++)
{
- fprintf(out, " --%-8s %s\n",
- cmds[active].options[i].name, cmds[active].options[i].desc);
+ snprintf(buf, sizeof(buf), "--%s (-%c)",
+ cmds[active].options[i].name, cmds[active].options[i].op);
+ fprintf(out, " %-15s %s\n",
+ buf, cmds[active].options[i].desc);
}
}
return error != NULL;
}
}
return error != NULL;
@@
-145,7
+169,7
@@
int command_dispatch(int argc, char *argv[])
command_register((command_t){help, 'h', "help", "show usage information"});
build_opts();
command_register((command_t){help, 'h', "help", "show usage information"});
build_opts();
- op = getopt_long(argc, argv,
""
, command_opts, NULL);
+ op = getopt_long(argc, argv,
command_optstring
, command_opts, NULL);
for (i = 0; cmds[i].cmd; i++)
{
if (cmds[i].op == op)
for (i = 0; cmds[i].cmd; i++)
{
if (cmds[i].op == op)
diff --git
a/src/pki/command.h
b/src/pki/command.h
index
b82d174
..
874bdaa
100644
(file)
--- a/
src/pki/command.h
+++ b/
src/pki/command.h
@@
-75,6
+75,11
@@
struct command_t {
extern struct option command_opts[];
/**
extern struct option command_opts[];
/**
+ * Short option string of the active command.
+ */
+extern char command_optstring[];
+
+/**
* Register a command.
*/
void command_register(command_t command);
* Register a command.
*/
void command_register(command_t command);
diff --git
a/src/pki/commands/gen.c
b/src/pki/commands/gen.c
index
65b5f5c
..
fcdb50a
100644
(file)
--- a/
src/pki/commands/gen.c
+++ b/
src/pki/commands/gen.c
@@
-28,7
+28,7
@@
static int gen(int argc, char *argv[])
while (TRUE)
{
while (TRUE)
{
- switch (getopt_long(argc, argv,
""
, command_opts, NULL))
+ switch (getopt_long(argc, argv,
command_optstring
, command_opts, NULL))
{
case 'h':
return command_usage(NULL);
{
case 'h':
return command_usage(NULL);
diff --git
a/src/pki/commands/issue.c
b/src/pki/commands/issue.c
index
ba0ead4
..
d62de39
100644
(file)
--- a/
src/pki/commands/issue.c
+++ b/
src/pki/commands/issue.c
@@
-53,7
+53,7
@@
static int issue(int argc, char *argv[])
while (TRUE)
{
while (TRUE)
{
- switch (getopt_long(argc, argv,
""
, command_opts, NULL))
+ switch (getopt_long(argc, argv,
command_optstring
, command_opts, NULL))
{
case 'h':
goto usage;
{
case 'h':
goto usage;
@@
-275,7
+275,7
@@
static int issue(int argc, char *argv[])
not_before = time(NULL);
not_after = not_before + lifetime * 24 * 60 * 60;
not_before = time(NULL);
not_after = not_before + lifetime * 24 * 60 * 60;
-
+
cert = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509,
BUILD_SIGNING_KEY, private, BUILD_SIGNING_CERT, ca,
BUILD_PUBLIC_KEY, public, BUILD_SUBJECT, id,
cert = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509,
BUILD_SIGNING_KEY, private, BUILD_SIGNING_CERT, ca,
BUILD_PUBLIC_KEY, public, BUILD_SUBJECT, id,
diff --git
a/src/pki/commands/keyid.c
b/src/pki/commands/keyid.c
index
b302a8f
..
b856a06
100644
(file)
--- a/
src/pki/commands/keyid.c
+++ b/
src/pki/commands/keyid.c
@@
-34,7
+34,7
@@
static int keyid(int argc, char *argv[])
while (TRUE)
{
while (TRUE)
{
- switch (getopt_long(argc, argv,
""
, command_opts, NULL))
+ switch (getopt_long(argc, argv,
command_optstring
, command_opts, NULL))
{
case 'h':
return command_usage(NULL);
{
case 'h':
return command_usage(NULL);
diff --git
a/src/pki/commands/pub.c
b/src/pki/commands/pub.c
index
0543067
..
7294179
100644
(file)
--- a/
src/pki/commands/pub.c
+++ b/
src/pki/commands/pub.c
@@
-35,7
+35,7
@@
static int pub(int argc, char *argv[])
while (TRUE)
{
while (TRUE)
{
- switch (getopt_long(argc, argv,
""
, command_opts, NULL))
+ switch (getopt_long(argc, argv,
command_optstring
, command_opts, NULL))
{
case 'h':
return command_usage(NULL);
{
case 'h':
return command_usage(NULL);
diff --git
a/src/pki/commands/self.c
b/src/pki/commands/self.c
index
54ef239
..
97eb783
100644
(file)
--- a/
src/pki/commands/self.c
+++ b/
src/pki/commands/self.c
@@
-48,7
+48,7
@@
static int self(int argc, char *argv[])
while (TRUE)
{
while (TRUE)
{
- switch (getopt_long(argc, argv,
""
, command_opts, NULL))
+ switch (getopt_long(argc, argv,
command_optstring
, command_opts, NULL))
{
case 'h':
goto usage;
{
case 'h':
goto usage;
diff --git
a/src/pki/commands/verify.c
b/src/pki/commands/verify.c
index
d070ce0
..
26a6dca
100644
(file)
--- a/
src/pki/commands/verify.c
+++ b/
src/pki/commands/verify.c
@@
-29,7
+29,7
@@
static int verify(int argc, char *argv[])
while (TRUE)
{
while (TRUE)
{
- switch (getopt_long(argc, argv,
""
, command_opts, NULL))
+ switch (getopt_long(argc, argv,
command_optstring
, command_opts, NULL))
{
case 'h':
return command_usage(NULL);
{
case 'h':
return command_usage(NULL);