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