2 * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
11 #include <common/config/ini.h>
12 #include <common/config/config-session-abi.h>
13 #include <common/macros.h>
17 /* section is NULL if the entry is not in a section */
23 struct config_load_session_override_attr
{
30 /* Instance of a configuration writer. */
34 * A config_entry_handler_cb receives config_entry structures belonging to the
35 * sections the handler has been registered to.
37 * The config_entry and its members are only valid for the duration of the call
38 * and must not be freed.
40 * config_entry_handler_cb may return negative value to indicate an error in
41 * the configuration file.
43 typedef int (*config_entry_handler_cb
)(const struct config_entry
*, void *);
46 * Read a section's entries in an INI configuration file.
48 * path may be NULL, in which case the following paths will be tried:
49 * 1) $HOME/.lttng/lttng.conf
50 * 2) /etc/lttng/lttng.conf
52 * handler will only be called with entries belonging to the provided section.
53 * If section is NULL, all entries will be relayed to handler. If section is
54 * "", only the global entries are relayed.
56 * Returns 0 on success. Negative values are error codes. If the return value
57 * is positive, it represents the line number on which a parsing error occurred.
60 int config_get_section_entries(const char *path
, const char *section
,
61 config_entry_handler_cb handler
, void *user_data
);
64 * Parse a configuration value.
66 * This function expects either an unsigned integer or a boolean text option.
67 * The following strings are recognized: true, yes, on, false, no and off.
69 * Returns either the value of the parsed integer, or 0/1 if a boolean text
70 * string was recognized. Negative values indicate an error.
73 int config_parse_value(const char *value
);
76 * Create an instance of a configuration writer.
78 * fd_output File to which the XML content must be written. fd_output is
79 * owned by the caller.
81 * indent If other than 0 the XML will be pretty printed
82 * with indentation and newline.
84 * Returns an instance of a configuration writer on success, NULL on
88 struct config_writer
*config_writer_create(int fd_output
, int indent
);
91 * Destroy an instance of a configuration writer.
93 * writer An instance of a configuration writer.
95 * Returns zero if the XML document could be closed cleanly. Negative values
99 int config_writer_destroy(struct config_writer
*writer
);
102 * Open an element tag.
104 * writer An instance of a configuration writer.
106 * element_name Element tag name.
108 * Returns zero if the XML element could be opened.
109 * Negative values indicate an error.
112 int config_writer_open_element(struct config_writer
*writer
,
113 const char *element_name
);
116 * Write an element tag attribute.
118 * writer An instance of a configuration writer.
120 * name Attribute name.
122 * Returns zero if the XML element's attribute could be written.
123 * Negative values indicate an error.
126 int config_writer_write_attribute(struct config_writer
*writer
,
127 const char *name
, const char *value
);
130 * Close the current element tag.
132 * writer An instance of a configuration writer.
134 * Returns zero if the XML document could be closed cleanly.
135 * Negative values indicate an error.
138 int config_writer_close_element(struct config_writer
*writer
);
141 * Write an element of type unsigned int.
143 * writer An instance of a configuration writer.
145 * element_name Element name.
147 * value Unsigned int value of the element
149 * Returns zero if the element's value could be written.
150 * Negative values indicate an error.
153 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
154 const char *element_name
, uint64_t value
);
157 * Write an element of type signed int.
159 * writer An instance of a configuration writer.
161 * element_name Element name.
163 * value Signed int value of the element
165 * Returns zero if the element's value could be written.
166 * Negative values indicate an error.
168 int config_writer_write_element_signed_int(struct config_writer
*writer
,
169 const char *element_name
, int64_t value
);
172 * Write an element of type boolean.
174 * writer An instance of a configuration writer.
176 * element_name Element name.
178 * value Boolean value of the element
180 * Returns zero if the element's value could be written.
181 * Negative values indicate an error.
184 int config_writer_write_element_bool(struct config_writer
*writer
,
185 const char *element_name
, int value
);
188 * Write an element of type string.
190 * writer An instance of a configuration writer.
192 * element_name Element name.
194 * value String value of the element
196 * Returns zero if the element's value could be written.
197 * Negative values indicate an error.
200 int config_writer_write_element_string(struct config_writer
*writer
,
201 const char *element_name
, const char *value
);
204 * Write an element of type double.
206 * writer An instance of a configuration writer.
208 * element_name Element name.
210 * value Double value of the element
212 * Returns zero if the element's value could be written.
213 * Negative values indicate an error.
216 int config_writer_write_element_double(struct config_writer
*writer
,
217 const char *element_name
,
221 * Load session configurations from a file.
223 * path Path to an LTTng session configuration file. All *.lttng files
224 * will be loaded if path is a directory. If path is NULL, the default
225 * paths will be searched in the following order:
226 * 1) $HOME/.lttng/sessions
227 * 2) /etc/lttng/sessions
229 * session_name Name of the session to load. Will load all
230 * sessions from path if NULL.
232 * overwrite Overwrite current session configuration if it exists.
233 * autoload Tell to load the auto session(s).
234 * overrides The override attribute structure specifying override parameters.
236 * Returns zero if the session could be loaded successfully. Returns
237 * a negative LTTNG_ERR code on error.
240 int config_load_session(const char *path
, const char *session_name
,
241 int overwrite
, unsigned int autoload
,
242 const struct config_load_session_override_attr
*overrides
);
244 #endif /* _CONFIG_H */