Fix: XML declaration must be at beginning of XSD file
[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/config/config-session-abi.h>
23 #include <common/macros.h>
24 #include <stdint.h>
25
26 struct config_entry {
27 /* section is NULL if the entry is not in a section */
28 const char *section;
29 const char *name;
30 const char *value;
31 };
32
33 /* Instance of a configuration writer. */
34 struct config_writer;
35
36 /*
37 * A config_entry_handler_cb receives config_entry structures belonging to the
38 * sections the handler has been registered to.
39 *
40 * The config_entry and its members are only valid for the duration of the call
41 * and must not be freed.
42 *
43 * config_entry_handler_cb may return negative value to indicate an error in
44 * the configuration file.
45 */
46 typedef int (*config_entry_handler_cb)(const struct config_entry *, void *);
47
48 /*
49 * Read a section's entries in an INI configuration file.
50 *
51 * path may be NULL, in which case the following paths will be tried:
52 * 1) $HOME/.lttng/lttng.conf
53 * 2) /etc/lttng/lttng.conf
54 *
55 * handler will only be called with entries belonging to the provided section.
56 * If section is NULL, all entries will be relayed to handler. If section is
57 * "", only the global entries are relayed.
58 *
59 * Returns 0 on success. Negative values are error codes. If the return value
60 * is positive, it represents the line number on which a parsing error occured.
61 */
62 LTTNG_HIDDEN
63 int config_get_section_entries(const char *path, const char *section,
64 config_entry_handler_cb handler, void *user_data);
65
66 /*
67 * Parse a configuration value.
68 *
69 * This function expects either an unsigned integer or a boolean text option.
70 * The following strings are recognized: true, yes, on, false, no and off.
71 *
72 * Returns either the value of the parsed integer, or 0/1 if a boolean text
73 * string was recognized. Negative values indicate an error.
74 */
75 LTTNG_HIDDEN
76 int config_parse_value(const char *value);
77
78 /*
79 * Create an instance of a configuration writer.
80 *
81 * fd_output File to which the XML content must be written. The file will be
82 * closed once the config_writer has been destroyed.
83 *
84 * Returns an instance of a configuration writer on success, NULL on
85 * error.
86 */
87 LTTNG_HIDDEN
88 struct config_writer *config_writer_create(int fd_output);
89
90 /*
91 * Destroy an instance of a configuration writer.
92 *
93 * writer An instance of a configuration writer.
94 *
95 * Returns zero if the XML document could be closed cleanly. Negative values
96 * indicate an error.
97 */
98 LTTNG_HIDDEN
99 int config_writer_destroy(struct config_writer *writer);
100
101 /*
102 * Open an element tag.
103 *
104 * writer An instance of a configuration writer.
105 *
106 * element_name Element tag name.
107 *
108 * Returns zero if the XML document could be closed cleanly.
109 * Negative values indicate an error.
110 */
111 LTTNG_HIDDEN
112 int config_writer_open_element(struct config_writer *writer,
113 const char *element_name);
114
115 /*
116 * Close the current element tag.
117 *
118 * writer An instance of a configuration writer.
119 *
120 * Returns zero if the XML document could be closed cleanly.
121 * Negative values indicate an error.
122 */
123 LTTNG_HIDDEN
124 int config_writer_close_element(struct config_writer *writer);
125
126 /*
127 * Write an element of type unsigned int.
128 *
129 * writer An instance of a configuration writer.
130 *
131 * element_name Element name.
132 *
133 * value Unsigned int value of the element
134 *
135 * Returns zero if the element's value could be written.
136 * Negative values indicate an error.
137 */
138 LTTNG_HIDDEN
139 int config_writer_write_element_unsigned_int(struct config_writer *writer,
140 const char *element_name, uint64_t value);
141
142 /*
143 * Write an element of type signed int.
144 *
145 * writer An instance of a configuration writer.
146 *
147 * element_name Element name.
148 *
149 * value Signed int value of the element
150 *
151 * Returns zero if the element's value could be written.
152 * Negative values indicate an error.
153 */LTTNG_HIDDEN
154 int config_writer_write_element_signed_int(struct config_writer *writer,
155 const char *element_name, int64_t value);
156
157 /*
158 * Write an element of type boolean.
159 *
160 * writer An instance of a configuration writer.
161 *
162 * element_name Element name.
163 *
164 * value Boolean value of the element
165 *
166 * Returns zero if the element's value could be written.
167 * Negative values indicate an error.
168 */
169 LTTNG_HIDDEN
170 int config_writer_write_element_bool(struct config_writer *writer,
171 const char *element_name, int value);
172
173 /*
174 * Write an element of type string.
175 *
176 * writer An instance of a configuration writer.
177 *
178 * element_name Element name.
179 *
180 * value String value of the element
181 *
182 * Returns zero if the element's value could be written.
183 * Negative values indicate an error.
184 */
185 LTTNG_HIDDEN
186 int config_writer_write_element_string(struct config_writer *writer,
187 const char *element_name, const char *value);
188
189 /*
190 * Load session configurations from a file.
191 *
192 * path Path to an LTTng session configuration file. All *.lttng files
193 * will be loaded if path is a directory. If path is NULL, the default
194 * paths will be searched in the following order:
195 * 1) $HOME/.lttng/sessions
196 * 2) /etc/lttng/sessions
197 *
198 * session_name Name of the session to load. Will load all
199 * sessions from path if NULL.
200 *
201 * override Override current session configuration if it exists.
202 *
203 * Returns zero if the session could be loaded successfully. Returns
204 * a negative LTTNG_ERR code on error.
205 */
206 LTTNG_HIDDEN
207 int config_load_session(const char *path, const char *session_name,
208 int override);
209
210 #endif /* _CONFIG_H */
This page took 0.034649 seconds and 4 git commands to generate.