Annotation of embedaddon/strongswan/src/libstrongswan/settings/settings_types.h, revision 1.1.1.1
1.1 misho 1: /*
2: * Copyright (C) 2010-2018 Tobias Brunner
3: * HSR 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_ref_t section_ref_t;
28: typedef struct section_t section_t;
29:
30: #include "collections/array.h"
31:
32: /**
33: * Key/value pair.
34: */
35: struct kv_t {
36:
37: /**
38: * Key string, relative, not the full name.
39: */
40: char *key;
41:
42: /**
43: * Value as string.
44: */
45: char *value;
46: };
47:
48: /**
49: * Section reference.
50: */
51: struct section_ref_t {
52:
53: /**
54: * Name of the referenced section.
55: */
56: char *name;
57:
58: /**
59: * TRUE for permanent references that were added programmatically via
60: * add_fallback() and are not removed during reloads/purges.
61: */
62: bool permanent;
63: };
64:
65: /**
66: * Section containing subsections and key value pairs.
67: */
68: struct section_t {
69:
70: /**
71: * Name of the section.
72: */
73: char *name;
74:
75: /**
76: * Referenced sections, as section_ref_t.
77: */
78: array_t *references;
79:
80: /**
81: * Subsections, as section_t.
82: */
83: array_t *sections;
84:
85: /**
86: * Subsections in original order, as section_t (pointer to obj in sections).
87: */
88: array_t *sections_order;
89:
90: /**
91: * Key value pairs, as kv_t.
92: */
93: array_t *kv;
94:
95: /**
96: * Key value pairs in original order, as kv_t (pointer to obj in kv).
97: */
98: array_t *kv_order;
99: };
100:
101: /**
102: * Create a key/value pair.
103: *
104: * @param key key (gets adopted)
105: * @param value value (gets adopted)
106: * @return allocated key/value pair
107: */
108: kv_t *settings_kv_create(char *key, char *value);
109:
110: /**
111: * Destroy a key/value pair.
112: *
113: * @param this key/value pair to destroy
114: * @param contents optional array to store the value in
115: */
116: void settings_kv_destroy(kv_t *this, array_t *contents);
117:
118: /**
119: * Set the value of the given key/value pair.
120: *
121: * @param kv key/value pair
122: * @param value new value (gets adopted), may be NULL
123: * @param contents optional array to store replaced values in
124: */
125: void settings_kv_set(kv_t *kv, char *value, array_t *contents);
126:
127: /**
128: * Add the given key/value pair to the given section.
129: *
130: * @param section section to add pair to
131: * @param kv key/value pair to add (gets adopted)
132: * @param contents optional array to store replaced values in
133: */
134: void settings_kv_add(section_t *section, kv_t *kv, array_t *contents);
135:
136: /**
137: * Add a reference to another section.
138: *
139: * @param section section to which to add the reference
140: * @param name name of the referenced section (adopted)
141: * @param permanent whether the reference is not removed during reloads
142: */
143: void settings_reference_add(section_t *section, char *name, bool permanent);
144:
145: /**
146: * Create a section with the given name.
147: *
148: * @param name name (gets adopted)
149: * @return allocated section
150: */
151: section_t *settings_section_create(char *name);
152:
153: /**
154: * Destroy a section.
155: *
156: * @param this section to destroy
157: * @param contents optional array to store values of removed key/value pairs
158: */
159: void settings_section_destroy(section_t *this, array_t *contents);
160:
161: /**
162: * Add the given section to the given parent section.
163: *
164: * @param parent section to add section to
165: * @param section section to add (gets adopted)
166: * @param contents optional array to store replaced values in
167: */
168: void settings_section_add(section_t *parent, section_t *section,
169: array_t *contents);
170:
171: /**
172: * Extend the first section with the values and sub-sections of the second
173: * section, from where they are consequently removed.
174: *
175: * @param base base section to extend
176: * @param extension section whose data is extracted
177: * @param contents optional array to store replaced values in
178: * @param purge TRUE to remove settings and sections not found in the
179: * extension (unless (sub-)sections have/are fallbacks)
180: */
181: void settings_section_extend(section_t *base, section_t *extension,
182: array_t *contents, bool purge);
183:
184: /**
185: * Callback to find a section by name
186: */
187: int settings_section_find(const void *a, const void *b);
188:
189: /**
190: * Callback to sort sections by name
191: */
192: int settings_section_sort(const void *a, const void *b, void *user);
193:
194: /**
195: * Callback to find a key/value pair by key
196: */
197: int settings_kv_find(const void *a, const void *b);
198:
199: /**
200: * Callback to sort kv pairs by key
201: */
202: int settings_kv_sort(const void *a, const void *b, void *user);
203:
204: #endif /** SETTINGS_TYPES_H_ @}*/
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>