starter: Add starter group and fix formatting of conf_parser_section_t enum
[strongswan.git] / src / starter / parser / conf_parser.h
1 /*
2 * Copyright (C) 2013-2014 Tobias Brunner
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 starter starter
18 *
19 * @defgroup conf_parser conf_parser
20 * @{ @ingroup starter
21 */
22
23 #ifndef CONF_PARSER_H_
24 #define CONF_PARSER_H_
25
26 #include <library.h>
27 #include <collections/dictionary.h>
28
29 typedef enum conf_parser_section_t conf_parser_section_t;
30 typedef struct conf_parser_t conf_parser_t;
31
32 /**
33 * Type of section
34 */
35 enum conf_parser_section_t {
36 /**
37 * config setup
38 */
39 CONF_PARSER_CONFIG_SETUP,
40
41 /**
42 * conn _name_
43 */
44 CONF_PARSER_CONN,
45
46 /**
47 * ca _name_
48 */
49 CONF_PARSER_CA,
50 };
51
52 /**
53 * Parser for ipsec.conf
54 */
55 struct conf_parser_t {
56
57 /**
58 * Parse the config file.
59 *
60 * @return TRUE if config file was parsed successfully
61 */
62 bool (*parse)(conf_parser_t *this);
63
64 /**
65 * Get the names of all sections of the given type.
66 *
67 * @note Returns an empty enumerator for the config setup section.
68 *
69 * @return enumerator over char*
70 */
71 enumerator_t *(*get_sections)(conf_parser_t *this,
72 conf_parser_section_t type);
73
74 /**
75 * Get the section with the given type and name.
76 *
77 * @note The name is ignored for the config setup section.
78 *
79 * @return dictionary with settings
80 */
81 dictionary_t *(*get_section)(conf_parser_t *this,
82 conf_parser_section_t type, char *name);
83
84 /**
85 * Add a section while parsing.
86 *
87 * @note This method can only be called while parsing the config file.
88 *
89 * @param type type of section to add
90 * @param name name of the section, if applicable (gets adopted)
91 * @return TRUE if the section already existed (settings get added)
92 */
93 bool (*add_section)(conf_parser_t *this, conf_parser_section_t type,
94 char *name);
95
96 /**
97 * Add a key/value pair to the latest section.
98 *
99 * @note This method can only be called while parsing the config file.
100 *
101 * @param name key string (gets adopted)
102 * @param value optional value string (gets adopted), if no value is
103 * specified the key is set empty
104 */
105 void (*add_setting)(conf_parser_t *this, char *key, char *value);
106
107
108 /**
109 * Destroy a conf_parser_t instance.
110 */
111 void (*destroy)(conf_parser_t *this);
112 };
113
114 /**
115 * Create a conf_parser_t instance.
116 *
117 * @param file ipsec.conf file to parse (gets copied)
118 * @return conf_parser_t instance
119 */
120 conf_parser_t *conf_parser_create(const char *file);
121
122 #endif /** CONF_PARSER_H_ @}*/