splitted PKI tool to a file per command
[strongswan.git] / src / pki / command.h
1 /*
2 * Copyright (C) 2009 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup command command
18 * @{ @ingroup pki
19 */
20
21 #ifndef COMMAND_H_
22 #define COMMAND_H_
23
24 #define _GNU_SOURCE
25 #include <getopt.h>
26
27 /**
28 * Maximum number of options in a command (+1)
29 */
30 #define MAX_OPTIONS 14
31
32 /**
33 * Maximum number of usage summary lines (+1)
34 */
35 #define MAX_LINES 8
36
37 typedef struct command_t command_t;
38 typedef enum command_type_t command_type_t;
39
40 /**
41 * Command specification.
42 */
43 struct command_t {
44 /** Function implementing the command */
45 int (*call)(int, char*[]);
46 /** short option character */
47 char op;
48 /** long option string */
49 char *cmd;
50 /** description of the command */
51 char *description;
52 /** usage summary of the command */
53 char *line[MAX_LINES];
54 /** list of options the command accepts */
55 struct {
56 /** long option string of the option */
57 char *name;
58 /** short option character of the option */
59 char op;
60 /** expected argument to option, no/req/opt_argument */
61 int arg;
62 /** description of the option */
63 char *desc;
64 } options[MAX_OPTIONS];
65 };
66
67 /**
68 * Type of available commands
69 */
70 enum command_type_t {
71 CMD_HELP = 0,
72 CMD_GEN,
73 CMD_PUB,
74 CMD_KEYID,
75 CMD_SELF,
76 CMD_ISSUE,
77 CMD_VERIFY,
78 CMD_MAX
79 };
80
81 /**
82 * Options of the currently processing command.
83 */
84 extern struct option command_opts[];
85
86 /**
87 * Register a command.
88 */
89 void command_register(command_type_t type, command_t command);
90
91 /**
92 * Dispatch commands.
93 */
94 int command_dispatch(int argc, char *argv[]);
95
96 /**
97 * Show usage information of active command.
98 */
99 int command_usage(command_type_t cmd, char *error);
100
101 #endif /* COMMAND_H_ @}*/