2 * Copyright (C) 2013-2014 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
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>.
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
17 * @defgroup conf_parser conf_parser
21 #ifndef CONF_PARSER_H_
22 #define CONF_PARSER_H_
25 #include <collections/dictionary.h>
27 typedef enum conf_parser_section_t conf_parser_section_t
;
28 typedef struct conf_parser_t conf_parser_t
;
33 enum conf_parser_section_t
{
37 CONF_PARSER_CONFIG_SETUP
,
51 * Parser for ipsec.conf
53 struct conf_parser_t
{
56 * Parse the config file.
58 * @return TRUE if config file was parsed successfully
60 bool (*parse
)(conf_parser_t
*this);
63 * Get the names of all sections of the given type.
65 * @note Returns an empty enumerator for the config setup section.
67 * @return enumerator over char*
69 enumerator_t
*(*get_sections
)(conf_parser_t
*this,
70 conf_parser_section_t type
);
73 * Get the section with the given type and name.
75 * @note The name is ignored for the config setup section.
77 * @return dictionary with settings
79 dictionary_t
*(*get_section
)(conf_parser_t
*this,
80 conf_parser_section_t type
, char *name
);
83 * Add a section while parsing.
85 * @note This method can only be called while parsing the config file.
87 * @param type type of section to add
88 * @param name name of the section, if applicable (gets adopted)
89 * @return TRUE if the section already existed (settings get added)
91 bool (*add_section
)(conf_parser_t
*this, conf_parser_section_t type
,
95 * Add a key/value pair to the latest section.
97 * @note This method can only be called while parsing the config file.
99 * @param name key string (gets adopted)
100 * @param value optional value string (gets adopted), if no value is
101 * specified the key is set empty
103 void (*add_setting
)(conf_parser_t
*this, char *key
, char *value
);
107 * Destroy a conf_parser_t instance.
109 void (*destroy
)(conf_parser_t
*this);
113 * Create a conf_parser_t instance.
115 * @param file ipsec.conf file to parse (gets copied)
116 * @return conf_parser_t instance
118 conf_parser_t
*conf_parser_create(const char *file
);
120 #endif /** CONF_PARSER_H_ @}*/