2 * Copyright (C) 2013-2014 Tobias Brunner
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>.
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
16 * @defgroup starter starter
18 * @defgroup conf_parser conf_parser
22 #ifndef CONF_PARSER_H_
23 #define CONF_PARSER_H_
26 #include <collections/dictionary.h>
28 typedef enum conf_parser_section_t conf_parser_section_t
;
29 typedef struct conf_parser_t conf_parser_t
;
34 enum conf_parser_section_t
{
38 CONF_PARSER_CONFIG_SETUP
,
52 * Parser for ipsec.conf
54 struct conf_parser_t
{
57 * Parse the config file.
59 * @return TRUE if config file was parsed successfully
61 bool (*parse
)(conf_parser_t
*this);
64 * Get the names of all sections of the given type.
66 * @note Returns an empty enumerator for the config setup section.
68 * @return enumerator over char*
70 enumerator_t
*(*get_sections
)(conf_parser_t
*this,
71 conf_parser_section_t type
);
74 * Get the section with the given type and name.
76 * @note The name is ignored for the config setup section.
78 * @return dictionary with settings
80 dictionary_t
*(*get_section
)(conf_parser_t
*this,
81 conf_parser_section_t type
, char *name
);
84 * Add a section while parsing.
86 * @note This method can only be called while parsing the config file.
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)
92 bool (*add_section
)(conf_parser_t
*this, conf_parser_section_t type
,
96 * Add a key/value pair to the latest section.
98 * @note This method can only be called while parsing the config file.
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
104 void (*add_setting
)(conf_parser_t
*this, char *key
, char *value
);
108 * Destroy a conf_parser_t instance.
110 void (*destroy
)(conf_parser_t
*this);
114 * Create a conf_parser_t instance.
116 * @param file ipsec.conf file to parse (gets copied)
117 * @return conf_parser_t instance
119 conf_parser_t
*conf_parser_create(const char *file
);
121 #endif /** CONF_PARSER_H_ @}*/