Temporary mesure: disable xsd validation config_document_get
[lttng-tools.git] / src / common / config / session-config.h
CommitLineData
1501a7f3
JG
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>
54a98423 22#include <common/config/config-session-abi.h>
1501a7f3 23#include <common/macros.h>
5aee5c85 24#include <lttng/domain.h>
471713e3 25#include <lttng/event.h>
36f2332b 26#include <stdint.h>
1501a7f3
JG
27
28struct config_entry {
29 /* section is NULL if the entry is not in a section */
30 const char *section;
31 const char *name;
32 const char *value;
33};
34
36f2332b
JG
35/* Instance of a configuration writer. */
36struct config_writer;
37
fa8b52a2
JR
38/* Instance of a configuration document */
39struct config_document;
40
f7962e8f 41/* Instance of a configuration element */
fa8b52a2
JR
42struct config_element;
43
5aee5c85
JR
44/*
45 * Return the config string representation of a kernel type.
46 */
47LTTNG_HIDDEN
48const char *config_get_domain_str(enum lttng_domain_type domain);
49
f71bde2f
JR
50/*
51 * Return the config string representation of a loglevel type.
52 */
53LTTNG_HIDDEN
54const char *config_get_loglevel_type_string(
55 enum lttng_loglevel_type loglevel_type);
56
471713e3
JR
57/*
58 * Return the event_type int value of lttng_event_type enumeration based on the
59 * passed string.
60 */
61LTTNG_HIDDEN
62int config_get_event_type(const char *event_type);
63
1501a7f3
JG
64/*
65 * A config_entry_handler_cb receives config_entry structures belonging to the
66 * sections the handler has been registered to.
67 *
68 * The config_entry and its members are only valid for the duration of the call
69 * and must not be freed.
70 *
71 * config_entry_handler_cb may return negative value to indicate an error in
72 * the configuration file.
73 */
74typedef int (*config_entry_handler_cb)(const struct config_entry *, void *);
75
76/*
77 * Read a section's entries in an INI configuration file.
78 *
79 * path may be NULL, in which case the following paths will be tried:
80 * 1) $HOME/.lttng/lttng.conf
81 * 2) /etc/lttng/lttng.conf
82 *
83 * handler will only be called with entries belonging to the provided section.
84 * If section is NULL, all entries will be relayed to handler. If section is
85 * "", only the global entries are relayed.
86 *
87 * Returns 0 on success. Negative values are error codes. If the return value
83f4233d 88 * is positive, it represents the line number on which a parsing error occurred.
1501a7f3
JG
89 */
90LTTNG_HIDDEN
91int config_get_section_entries(const char *path, const char *section,
92 config_entry_handler_cb handler, void *user_data);
93
94/*
95 * Parse a configuration value.
96 *
97 * This function expects either an unsigned integer or a boolean text option.
98 * The following strings are recognized: true, yes, on, false, no and off.
99 *
100 * Returns either the value of the parsed integer, or 0/1 if a boolean text
101 * string was recognized. Negative values indicate an error.
102 */
103LTTNG_HIDDEN
104int config_parse_value(const char *value);
105
36f2332b
JG
106/*
107 * Create an instance of a configuration writer.
108 *
109 * fd_output File to which the XML content must be written. The file will be
110 * closed once the config_writer has been destroyed.
111 *
705bb62f
JRJ
112 * indent If other than 0 the XML will be pretty printed
113 * with indentation and newline.
114 *
36f2332b
JG
115 * Returns an instance of a configuration writer on success, NULL on
116 * error.
117 */
118LTTNG_HIDDEN
705bb62f 119struct config_writer *config_writer_create(int fd_output, int indent);
36f2332b
JG
120
121/*
122 * Destroy an instance of a configuration writer.
123 *
124 * writer An instance of a configuration writer.
125 *
126 * Returns zero if the XML document could be closed cleanly. Negative values
127 * indicate an error.
128 */
129LTTNG_HIDDEN
130int config_writer_destroy(struct config_writer *writer);
131
132/*
133 * Open an element tag.
134 *
135 * writer An instance of a configuration writer.
136 *
137 * element_name Element tag name.
138 *
e10b6a1c 139 * Returns zero if the XML element could be opened.
36f2332b
JG
140 * Negative values indicate an error.
141 */
142LTTNG_HIDDEN
143int config_writer_open_element(struct config_writer *writer,
144 const char *element_name);
145
e10b6a1c
JG
146/*
147 * Write an element tag attribute.
148 *
149 * writer An instance of a configuration writer.
150 *
151 * name Attribute name.
152 *
153 * Returns zero if the XML element's attribute could be written.
154 * Negative values indicate an error.
155 */
156LTTNG_HIDDEN
157int config_writer_write_attribute(struct config_writer *writer,
158 const char *name, const char *value);
159
36f2332b
JG
160/*
161 * Close the current element tag.
162 *
163 * writer An instance of a configuration writer.
164 *
165 * Returns zero if the XML document could be closed cleanly.
166 * Negative values indicate an error.
167 */
168LTTNG_HIDDEN
169int config_writer_close_element(struct config_writer *writer);
170
171/*
172 * Write an element of type unsigned int.
173 *
174 * writer An instance of a configuration writer.
175 *
176 * element_name Element name.
177 *
178 * value Unsigned int value of the element
179 *
180 * Returns zero if the element's value could be written.
181 * Negative values indicate an error.
182 */
183LTTNG_HIDDEN
184int config_writer_write_element_unsigned_int(struct config_writer *writer,
185 const char *element_name, uint64_t value);
186
187/*
188 * Write an element of type signed int.
189 *
190 * writer An instance of a configuration writer.
191 *
192 * element_name Element name.
193 *
194 * value Signed int value of the element
195 *
196 * Returns zero if the element's value could be written.
197 * Negative values indicate an error.
198 */LTTNG_HIDDEN
199int config_writer_write_element_signed_int(struct config_writer *writer,
200 const char *element_name, int64_t value);
201
202/*
203 * Write an element of type boolean.
204 *
205 * writer An instance of a configuration writer.
206 *
207 * element_name Element name.
208 *
209 * value Boolean value of the element
210 *
211 * Returns zero if the element's value could be written.
212 * Negative values indicate an error.
213 */
214LTTNG_HIDDEN
215int config_writer_write_element_bool(struct config_writer *writer,
216 const char *element_name, int value);
217
218/*
219 * Write an element of type string.
220 *
221 * writer An instance of a configuration writer.
222 *
223 * element_name Element name.
224 *
225 * value String value of the element
226 *
227 * Returns zero if the element's value could be written.
228 * Negative values indicate an error.
229 */
230LTTNG_HIDDEN
231int config_writer_write_element_string(struct config_writer *writer,
232 const char *element_name, const char *value);
233
8e79e1cd
JR
234/*
235 * Write an element of type config_element.
236 *
237 * writer An instance of a configuration writer.
238 *
239 * element The config_element instance.
240 *
241 * Returns zero if the element could be written.
242 * Negative values indicate an error.
243 */
244LTTNG_HIDDEN
245int config_writer_write_config_element(struct config_writer *writer,
246 const struct config_element *element);
dcf266c0
JG
247/*
248 * Load session configurations from a file.
249 *
250 * path Path to an LTTng session configuration file. All *.lttng files
251 * will be loaded if path is a directory. If path is NULL, the default
252 * paths will be searched in the following order:
253 * 1) $HOME/.lttng/sessions
254 * 2) /etc/lttng/sessions
255 *
256 * session_name Name of the session to load. Will load all
257 * sessions from path if NULL.
258 *
259 * override Override current session configuration if it exists.
ab38c13f 260 * autoload Tell to load the auto session(s).
dcf266c0
JG
261 *
262 * Returns zero if the session could be loaded successfully. Returns
263 * a negative LTTNG_ERR code on error.
264 */
265LTTNG_HIDDEN
266int config_load_session(const char *path, const char *session_name,
ab38c13f 267 int override, unsigned int autoload);
dcf266c0 268
fa8b52a2
JR
269/*
270 * Load session configuration from a document
271 *
272 * document The document to be loaded as a configuration
273 * session_name Name of the session to load. Will load all sessions from the
274 * passed document if NULL
275 *
276 * override Override current session configuration if it exists.
277 *
278 * Returns zero if the session could be loaded successfully. Returns
279 * a negative LTTNG_ERR code on error.
280 */
281LTTNG_HIDDEN
282int config_load_configuration_sessions(struct config_document *document,
283 const char *session_name, int override);
284
285/*
286 * Get the document corresponding to the path.
287 *
288 * path Path to a configuration file.
289 * xsd_validation Whether or not to do a xsd validation
290 *
291 * Returns an new allocated config_document when successful.
292 * Returns NULL on error;
293 *
294 * The caller is responsible of freeing the document via config_document_free.
295 */
296LTTNG_HIDDEN
d26b6a90 297struct config_document *config_document_get(const char *path, int xsd_validation);
fa8b52a2
JR
298
299/*
300 * Free an allocated document.
301 *
302 * document The document to free.
303 */
304LTTNG_HIDDEN
305void config_document_free(struct config_document *document);
306
307/*
308 * Replace the value of a document element
309 *
310 * document The document containing the element to be modified.
311 * xpath The xpath string to the element.
312 * value The value to be placed inside the element.
313 *
314 * Returns zero if the session could be loaded successfully. Returns
315 * a negative LTTNG_ERR code on error.
316 * */
317LTTNG_HIDDEN
318int config_document_replace_element_value(struct config_document *document, const char *xpath, const char *value);
319
320/*
321 * Swap a document node by the passed element.
322 *
323 * document The document containing the element to be modified.
324 * xpath The xpath string to the element.
325 * element The replacement element.
326 *
327 * Returns zero if the session could be loaded successfully. Returns
328 * a negative LTTNG_ERR code on error.
329 */
330LTTNG_HIDDEN
331int config_document_replace_element(struct config_document *document, const char *xpath, const struct config_element *element);
332
333/*
334 * Get the value of a document element.
335 *
336 * document The document to be searched.
337 * xpath The xpath string to the element.
338 *
339 * Return null if multiple values exists or there is no
340 * value for the passed path.
341 */
342LTTNG_HIDDEN
343char *config_document_get_element_value(struct config_document *document, const char *xpath);
344
345/*
346 * Check if an element exists inside a document.
347 *
348 * document The document to be searched.
349 * xpath The xpath string to the element.
350 *
351 * Returns 1 on success and 0 on failure.
352 */
353LTTNG_HIDDEN
354int config_document_element_exist(struct config_document *document, const char *xpath);
355
356/*
f7962e8f 357 * Create a configuration element.
fa8b52a2 358 *
f7962e8f
JR
359 * name The name of the element
360 * value The value to be assigned to the element. The value can be NULL.
361 *
362 * Returns a new configuration element.
363 *
364 * The caller is responsible of freeing the allocated element with
365 * config_element_free.
fa8b52a2
JR
366 */
367LTTNG_HIDDEN
f7962e8f 368struct config_element *config_element_create(const char *name, const char *value);
fa8b52a2 369
f7962e8f
JR
370/*
371 * Free a config_element
372 *
373 * element The element to free.
374 */
fa8b52a2 375LTTNG_HIDDEN
f7962e8f 376void config_element_free(struct config_element *element);
fa8b52a2
JR
377
378/*
379 * Add a child element to an element.
380 *
381 * parent The parent element.
382 * child The element to add as a child.
383 *
384 * Returns zero if the session could be loaded successfully. Returns
385 * a negative LTTNG_ERR code on error.
386 */
387LTTNG_HIDDEN
388int config_element_add_child(struct config_element *parent, const struct config_element *child);
389
390/*
391 * Insert element to an existing document.
392 *
393 * document The document to be modified.
394 * xpath The xpath string to the insertion path.
395 * element The element to be inserted.
396 *
397 * Returns zero if the session could be loaded successfully. Returns
398 * a negative LTTNG_ERR code on error.
399 */
400LTTNG_HIDDEN
401int config_document_insert_element(struct config_document *document, const char *xpath, const struct config_element *element);
402
f7962e8f
JR
403/*
404 * Get an array of elements from a document.
405 *
406 * document The source document.
407 * xpath The xpath string matching the elements path.
408 * element_array The resulting array
409 * array_size The resulting array size
410 *
411 * element_array is NULL on error.
412 *
413 * The caller is responsible of freeing the array with
414 * config_element_free_array.
415 */
416LTTNG_HIDDEN
417void config_document_get_element_array(const struct config_document *document, const char *xpath, struct config_element ***element_array, int *array_size);
418
419/*
420 * Get an array of elements from an element.
421 *
422 * element The source element.
423 * xpath The xpath string matching the elements path.
424 * element_array The resulting array
425 * array_size The resulting array size
426 *
427 * element_array is NULL on error.
428 *
429 * The caller is responsible of freeing the array with
430 * config_element_free_array.
431 */
432LTTNG_HIDDEN
433void config_element_get_element_array(const struct config_element *element, const char *xpath, struct config_element ***element_array, int *array_size);
434
435/*
436 * Free an array of element.
437 *
438 * array The array to free
439 * size The size of the array
440 */
441LTTNG_HIDDEN
442void config_element_free_array(struct config_element **array, int size);
443
444/*
445 * Add an element as a child if a equivalent element is present replace it with
446 * the passed element.
447 *
448 * parent The parent element.
449 * child The child to add.
450 *
451 * Returns zero if the session could be loaded successfully. Returns
452 * a negative LTTNG_ERR code on error.
453 */
454LTTNG_HIDDEN
455int config_element_add_or_replace_child(struct config_element *parent, struct config_element *child);
456
457/*
458 * Get the value of an element under an element.
459 *
460 * element The base element.
461 * xpath The xpath string to the element.
462 *
463 * Return null if multiple values exists or there is no
464 * value for the passed path.
465 */
466LTTNG_HIDDEN
467char *config_element_get_element_value(const struct config_element *element, const char *xpath);
468
469/*
470 * Process an element matching an event configuration and try to enable it.
471 *
472 * element The element to process
473 * session_name The session name to use for event enabling.
474 * domain_type The domain type to use for event enabling
475 * channel_name The channel name to use for event enabling
476 * A NULL channel name will default to the default domain
477 * channel.
478 *
479 * Returns zero if the session could be loaded successfully. Returns
480 * a negative LTTNG_ERR code on error.
481 */
482LTTNG_HIDDEN
483int config_process_event_element(const struct config_element *element, const char* session_name, int domain_type, const char *channel_name);
fa8b52a2 484
1501a7f3 485#endif /* _CONFIG_H */
This page took 0.062071 seconds and 5 git commands to generate.