aboutsummaryrefslogtreecommitdiffstats
path: root/src/pki/command.h
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2009-09-10 12:31:40 +0200
committerMartin Willi <martin@strongswan.org>2009-09-10 12:31:40 +0200
commit6be68cc1c72ab076fbdfd05f24662519e62cfca8 (patch)
tree192023cc274e44055696c2280f51c5cb3f75ccd8 /src/pki/command.h
parente5e6c6f43ce143978a97b332b6279cd25f22bd29 (diff)
downloadstrongswan-6be68cc1c72ab076fbdfd05f24662519e62cfca8.tar.bz2
strongswan-6be68cc1c72ab076fbdfd05f24662519e62cfca8.tar.xz
splitted PKI tool to a file per command
Diffstat (limited to 'src/pki/command.h')
-rw-r--r--src/pki/command.h101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/pki/command.h b/src/pki/command.h
new file mode 100644
index 000000000..852a84d2a
--- /dev/null
+++ b/src/pki/command.h
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2009 Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup command command
+ * @{ @ingroup pki
+ */
+
+#ifndef COMMAND_H_
+#define COMMAND_H_
+
+#define _GNU_SOURCE
+#include <getopt.h>
+
+/**
+ * Maximum number of options in a command (+1)
+ */
+#define MAX_OPTIONS 14
+
+/**
+ * Maximum number of usage summary lines (+1)
+ */
+#define MAX_LINES 8
+
+typedef struct command_t command_t;
+typedef enum command_type_t command_type_t;
+
+/**
+ * Command specification.
+ */
+struct command_t {
+ /** Function implementing the command */
+ int (*call)(int, char*[]);
+ /** short option character */
+ char op;
+ /** long option string */
+ char *cmd;
+ /** description of the command */
+ char *description;
+ /** usage summary of the command */
+ char *line[MAX_LINES];
+ /** list of options the command accepts */
+ struct {
+ /** long option string of the option */
+ char *name;
+ /** short option character of the option */
+ char op;
+ /** expected argument to option, no/req/opt_argument */
+ int arg;
+ /** description of the option */
+ char *desc;
+ } options[MAX_OPTIONS];
+};
+
+/**
+ * Type of available commands
+ */
+enum command_type_t {
+ CMD_HELP = 0,
+ CMD_GEN,
+ CMD_PUB,
+ CMD_KEYID,
+ CMD_SELF,
+ CMD_ISSUE,
+ CMD_VERIFY,
+ CMD_MAX
+};
+
+/**
+ * Options of the currently processing command.
+ */
+extern struct option command_opts[];
+
+/**
+ * Register a command.
+ */
+void command_register(command_type_t type, command_t command);
+
+/**
+ * Dispatch commands.
+ */
+int command_dispatch(int argc, char *argv[]);
+
+/**
+ * Show usage information of active command.
+ */
+int command_usage(command_type_t cmd, char *error);
+
+#endif /* COMMAND_H_ @}*/