]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/starter/parser/conf_parser.h
Update copyright headers after acquisition by secunet
[thirdparty/strongswan.git] / src / starter / parser / conf_parser.h
1 /*
2 * Copyright (C) 2013-2014 Tobias Brunner
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15 /**
16 * @defgroup starter starter
17 *
18 * @defgroup conf_parser conf_parser
19 * @{ @ingroup starter
20 */
21
22 #ifndef CONF_PARSER_H_
23 #define CONF_PARSER_H_
24
25 #include <library.h>
26 #include <collections/dictionary.h>
27
28 typedef enum conf_parser_section_t conf_parser_section_t;
29 typedef struct conf_parser_t conf_parser_t;
30
31 /**
32 * Type of section
33 */
34 enum conf_parser_section_t {
35 /**
36 * config setup
37 */
38 CONF_PARSER_CONFIG_SETUP,
39
40 /**
41 * conn _name_
42 */
43 CONF_PARSER_CONN,
44
45 /**
46 * ca _name_
47 */
48 CONF_PARSER_CA,
49 };
50
51 /**
52 * Parser for ipsec.conf
53 */
54 struct conf_parser_t {
55
56 /**
57 * Parse the config file.
58 *
59 * @return TRUE if config file was parsed successfully
60 */
61 bool (*parse)(conf_parser_t *this);
62
63 /**
64 * Get the names of all sections of the given type.
65 *
66 * @note Returns an empty enumerator for the config setup section.
67 *
68 * @return enumerator over char*
69 */
70 enumerator_t *(*get_sections)(conf_parser_t *this,
71 conf_parser_section_t type);
72
73 /**
74 * Get the section with the given type and name.
75 *
76 * @note The name is ignored for the config setup section.
77 *
78 * @return dictionary with settings
79 */
80 dictionary_t *(*get_section)(conf_parser_t *this,
81 conf_parser_section_t type, char *name);
82
83 /**
84 * Add a section while parsing.
85 *
86 * @note This method can only be called while parsing the config file.
87 *
88 * @param type type of section to add
89 * @param name name of the section, if applicable (gets adopted)
90 * @return TRUE if the section already existed (settings get added)
91 */
92 bool (*add_section)(conf_parser_t *this, conf_parser_section_t type,
93 char *name);
94
95 /**
96 * Add a key/value pair to the latest section.
97 *
98 * @note This method can only be called while parsing the config file.
99 *
100 * @param name key string (gets adopted)
101 * @param value optional value string (gets adopted), if no value is
102 * specified the key is set empty
103 */
104 void (*add_setting)(conf_parser_t *this, char *key, char *value);
105
106
107 /**
108 * Destroy a conf_parser_t instance.
109 */
110 void (*destroy)(conf_parser_t *this);
111 };
112
113 /**
114 * Create a conf_parser_t instance.
115 *
116 * @param file ipsec.conf file to parse (gets copied)
117 * @return conf_parser_t instance
118 */
119 conf_parser_t *conf_parser_create(const char *file);
120
121 #endif /** CONF_PARSER_H_ @}*/