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