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>
21 /* section is NULL if the entry is not in a section */
27 struct config_load_session_override_attr
{
34 /* Instance of a configuration writer. */
38 * A config_entry_handler_cb receives config_entry structures belonging to the
39 * sections the handler has been registered to.
41 * The config_entry and its members are only valid for the duration of the call
42 * and must not be freed.
44 * config_entry_handler_cb may return negative value to indicate an error in
45 * the configuration file.
47 typedef int (*config_entry_handler_cb
)(const struct config_entry
*, void *);
50 * Read a section's entries in an INI configuration file.
52 * path may be NULL, in which case the following paths will be tried:
53 * 1) $HOME/.lttng/lttng.conf
54 * 2) /etc/lttng/lttng.conf
56 * handler will only be called with entries belonging to the provided section.
57 * If section is NULL, all entries will be relayed to handler. If section is
58 * "", only the global entries are relayed.
60 * Returns 0 on success. Negative values are error codes. If the return value
61 * is positive, it represents the line number on which a parsing error occurred.
63 int config_get_section_entries(const char *path
, const char *section
,
64 config_entry_handler_cb handler
, void *user_data
);
67 * Parse a configuration value.
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.
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.
75 int config_parse_value(const char *value
);
78 * Create an instance of a configuration writer.
80 * fd_output File to which the XML content must be written. fd_output is
81 * owned by the caller.
83 * indent If other than 0 the XML will be pretty printed
84 * with indentation and newline.
86 * Returns an instance of a configuration writer on success, NULL on
89 struct config_writer
*config_writer_create(int fd_output
, int indent
);
92 * Destroy an instance of a configuration writer.
94 * writer An instance of a configuration writer.
96 * 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.
111 int config_writer_open_element(struct config_writer
*writer
,
112 const char *element_name
);
115 * Write an element tag attribute.
117 * writer An instance of a configuration writer.
119 * name Attribute name.
121 * Returns zero if the XML element's attribute could be written.
122 * Negative values indicate an error.
124 int config_writer_write_attribute(struct config_writer
*writer
,
125 const char *name
, const char *value
);
128 * Close the current element tag.
130 * writer An instance of a configuration writer.
132 * Returns zero if the XML document could be closed cleanly.
133 * Negative values indicate an error.
135 int config_writer_close_element(struct config_writer
*writer
);
138 * Write an element of type unsigned int.
140 * writer An instance of a configuration writer.
142 * element_name Element name.
144 * value Unsigned int value of the element
146 * Returns zero if the element's value could be written.
147 * Negative values indicate an error.
149 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
150 const char *element_name
, uint64_t value
);
153 * Write an element of type signed int.
155 * writer An instance of a configuration writer.
157 * element_name Element name.
159 * value Signed int value of the element
161 * Returns zero if the element's value could be written.
162 * Negative values indicate an error.
164 int config_writer_write_element_signed_int(struct config_writer
*writer
,
165 const char *element_name
, int64_t value
);
168 * Write an element of type boolean.
170 * writer An instance of a configuration writer.
172 * element_name Element name.
174 * value Boolean value of the element
176 * Returns zero if the element's value could be written.
177 * Negative values indicate an error.
179 int config_writer_write_element_bool(struct config_writer
*writer
,
180 const char *element_name
, int value
);
183 * Write an element of type string.
185 * writer An instance of a configuration writer.
187 * element_name Element name.
189 * value String value of the element
191 * Returns zero if the element's value could be written.
192 * Negative values indicate an error.
194 int config_writer_write_element_string(struct config_writer
*writer
,
195 const char *element_name
, const char *value
);
198 * Write an element of type double.
200 * writer An instance of a configuration writer.
202 * element_name Element name.
204 * value Double value of the element
206 * Returns zero if the element's value could be written.
207 * Negative values indicate an error.
209 int config_writer_write_element_double(struct config_writer
*writer
,
210 const char *element_name
,
214 * Load session configurations from a file.
216 * path Path to an LTTng session configuration file. All *.lttng files
217 * will be loaded if path is a directory. If path is NULL, the default
218 * paths will be searched in the following order:
219 * 1) $HOME/.lttng/sessions
220 * 2) /etc/lttng/sessions
222 * session_name Name of the session to load. Will load all
223 * sessions from path if NULL.
225 * overwrite Overwrite current session configuration if it exists.
226 * autoload Tell to load the auto session(s).
227 * overrides The override attribute structure specifying override parameters.
229 * Returns zero if the session could be loaded successfully. Returns
230 * a negative LTTNG_ERR code on error.
232 int config_load_session(const char *path
, const char *session_name
,
233 int overwrite
, unsigned int autoload
,
234 const struct config_load_session_override_attr
*overrides
);
240 #endif /* _CONFIG_H */