28e7fd6f5bfd25e074a31f66d4c47ca0ec0b4ec9
[strongswan.git] / src / libstrongswan / settings / settings_types.h
1 /*
2 * Copyright (C) 2010-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 * Internal data types and functions shared between the parser and t.
18 *
19 * @defgroup settings_types settings_types
20 * @{ @ingroup settings
21 */
22
23 #ifndef SETTINGS_TYPES_H_
24 #define SETTINGS_TYPES_H_
25
26 typedef struct kv_t kv_t;
27 typedef struct section_t section_t;
28
29 #include "collections/array.h"
30
31 /**
32 * Key/value pair.
33 */
34 struct kv_t {
35
36 /**
37 * Key string, relative, not the full name.
38 */
39 char *key;
40
41 /**
42 * Value as string.
43 */
44 char *value;
45 };
46
47 /**
48 * Section containing subsections and key value pairs.
49 */
50 struct section_t {
51
52 /**
53 * Name of the section.
54 */
55 char *name;
56
57 /**
58 * Fallback sections, as section_t.
59 */
60 array_t *fallbacks;
61
62 /**
63 * Subsections, as section_t.
64 */
65 array_t *sections;
66
67 /**
68 * Key value pairs, as kv_t.
69 */
70 array_t *kv;
71 };
72
73 /**
74 * Create a key/value pair.
75 *
76 * @param key key (gets adopted)
77 * @param value value (gets adopted)
78 * @return allocated key/value pair
79 */
80 kv_t *settings_kv_create(char *key, char *value);
81
82 /**
83 * Destroy a key/value pair.
84 *
85 * @param this key/value pair to destroy
86 * @param contents optional array to store the value in
87 */
88 void settings_kv_destroy(kv_t *this, array_t *contents);
89
90 /**
91 * Create a section with the given name.
92 *
93 * @param name name (gets adopted)
94 * @return allocated section
95 */
96 section_t *settings_section_create(char *name);
97
98 /**
99 * Destroy a section.
100 *
101 * @param this section to destroy
102 * @param contents optional array to store values of removed key/value pairs
103 */
104 void settings_section_destroy(section_t *this, array_t *contents);
105
106 /**
107 * Extend the first section with the values and sub-sections of the second
108 * section, from where they are consequently moved/removed (but there might
109 * still remain some leftovers).
110 *
111 * @param base base section to extend
112 * @param extension section whose data is extracted
113 * @param contents optional array to store replaced values in
114 */
115 void settings_section_extend(section_t *base, section_t *extension,
116 array_t *contents);
117
118 /**
119 * Callback to find a section by name
120 */
121 int settings_section_find(const void *a, const void *b);
122
123 /**
124 * Callback to sort sections by name
125 */
126 int settings_section_sort(const void *a, const void *b, void *user);
127
128 /**
129 * Callback to find a key/value pair by key
130 */
131 int settings_kv_find(const void *a, const void *b);
132
133 /**
134 * Callback to sort kv pairs by key
135 */
136 int settings_kv_sort(const void *a, const void *b, void *user);
137
138 #endif /** SETTINGS_TYPES_H_ @}*/