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