Add a config_writer API based on libxml2
[lttng-tools.git] / src / common / config / config.h
1 /*
2 * Copyright (C) 2013 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #ifndef _CONFIG_H
19 #define _CONFIG_H
20
21 #include <common/config/ini.h>
22 #include <common/macros.h>
23 #include <stdint.h>
24
25 struct config_entry {
26 /* section is NULL if the entry is not in a section */
27 const char *section;
28 const char *name;
29 const char *value;
30 };
31
32 /* Instance of a configuration writer. */
33 struct config_writer;
34
35 /*
36 * A config_entry_handler_cb receives config_entry structures belonging to the
37 * sections the handler has been registered to.
38 *
39 * The config_entry and its members are only valid for the duration of the call
40 * and must not be freed.
41 *
42 * config_entry_handler_cb may return negative value to indicate an error in
43 * the configuration file.
44 */
45 typedef int (*config_entry_handler_cb)(const struct config_entry *, void *);
46
47 /*
48 * Read a section's entries in an INI configuration file.
49 *
50 * path may be NULL, in which case the following paths will be tried:
51 * 1) $HOME/.lttng/lttng.conf
52 * 2) /etc/lttng/lttng.conf
53 *
54 * handler will only be called with entries belonging to the provided section.
55 * If section is NULL, all entries will be relayed to handler. If section is
56 * "", only the global entries are relayed.
57 *
58 * Returns 0 on success. Negative values are error codes. If the return value
59 * is positive, it represents the line number on which a parsing error occured.
60 */
61 LTTNG_HIDDEN
62 int config_get_section_entries(const char *path, const char *section,
63 config_entry_handler_cb handler, void *user_data);
64
65 /*
66 * Parse a configuration value.
67 *
68 * This function expects either an unsigned integer or a boolean text option.
69 * The following strings are recognized: true, yes, on, false, no and off.
70 *
71 * Returns either the value of the parsed integer, or 0/1 if a boolean text
72 * string was recognized. Negative values indicate an error.
73 */
74 LTTNG_HIDDEN
75 int config_parse_value(const char *value);
76
77 /*
78 * Create an instance of a configuration writer.
79 *
80 * fd_output File to which the XML content must be written. The file will be
81 * closed once the config_writer has been destroyed.
82 *
83 * Returns an instance of a configuration writer on success, NULL on
84 * error.
85 */
86 LTTNG_HIDDEN
87 struct config_writer *config_writer_create(int fd_output);
88
89 /*
90 * Destroy an instance of a configuration writer.
91 *
92 * writer An instance of a configuration writer.
93 *
94 * Returns zero if the XML document could be closed cleanly. Negative values
95 * indicate an error.
96 */
97 LTTNG_HIDDEN
98 int config_writer_destroy(struct config_writer *writer);
99
100 /*
101 * Open an element tag.
102 *
103 * writer An instance of a configuration writer.
104 *
105 * element_name Element tag name.
106 *
107 * Returns zero if the XML document could be closed cleanly.
108 * Negative values indicate an error.
109 */
110 LTTNG_HIDDEN
111 int config_writer_open_element(struct config_writer *writer,
112 const char *element_name);
113
114 /*
115 * Close the current element tag.
116 *
117 * writer An instance of a configuration writer.
118 *
119 * Returns zero if the XML document could be closed cleanly.
120 * Negative values indicate an error.
121 */
122 LTTNG_HIDDEN
123 int config_writer_close_element(struct config_writer *writer);
124
125 /*
126 * Write an element of type unsigned int.
127 *
128 * writer An instance of a configuration writer.
129 *
130 * element_name Element name.
131 *
132 * value Unsigned int value of the element
133 *
134 * Returns zero if the element's value could be written.
135 * Negative values indicate an error.
136 */
137 LTTNG_HIDDEN
138 int config_writer_write_element_unsigned_int(struct config_writer *writer,
139 const char *element_name, uint64_t value);
140
141 /*
142 * Write an element of type signed int.
143 *
144 * writer An instance of a configuration writer.
145 *
146 * element_name Element name.
147 *
148 * value Signed int value of the element
149 *
150 * Returns zero if the element's value could be written.
151 * Negative values indicate an error.
152 */LTTNG_HIDDEN
153 int config_writer_write_element_signed_int(struct config_writer *writer,
154 const char *element_name, int64_t value);
155
156 /*
157 * Write an element of type boolean.
158 *
159 * writer An instance of a configuration writer.
160 *
161 * element_name Element name.
162 *
163 * value Boolean value of the element
164 *
165 * Returns zero if the element's value could be written.
166 * Negative values indicate an error.
167 */
168 LTTNG_HIDDEN
169 int config_writer_write_element_bool(struct config_writer *writer,
170 const char *element_name, int value);
171
172 /*
173 * Write an element of type string.
174 *
175 * writer An instance of a configuration writer.
176 *
177 * element_name Element name.
178 *
179 * value String value of the element
180 *
181 * Returns zero if the element's value could be written.
182 * Negative values indicate an error.
183 */
184 LTTNG_HIDDEN
185 int config_writer_write_element_string(struct config_writer *writer,
186 const char *element_name, const char *value);
187
188 #endif /* _CONFIG_H */
This page took 0.033606 seconds and 5 git commands to generate.