2 * Copyright (C) 2013 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
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.
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
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.
21 #include <common/config/ini.h>
22 #include <common/config/config-session-abi.h>
23 #include <common/macros.h>
27 /* section is NULL if the entry is not in a section */
33 struct config_load_session_override_attr
{
39 /* Instance of a configuration writer. */
43 * A config_entry_handler_cb receives config_entry structures belonging to the
44 * sections the handler has been registered to.
46 * The config_entry and its members are only valid for the duration of the call
47 * and must not be freed.
49 * config_entry_handler_cb may return negative value to indicate an error in
50 * the configuration file.
52 typedef int (*config_entry_handler_cb
)(const struct config_entry
*, void *);
55 * Read a section's entries in an INI configuration file.
57 * path may be NULL, in which case the following paths will be tried:
58 * 1) $HOME/.lttng/lttng.conf
59 * 2) /etc/lttng/lttng.conf
61 * handler will only be called with entries belonging to the provided section.
62 * If section is NULL, all entries will be relayed to handler. If section is
63 * "", only the global entries are relayed.
65 * Returns 0 on success. Negative values are error codes. If the return value
66 * is positive, it represents the line number on which a parsing error occurred.
69 int config_get_section_entries(const char *path
, const char *section
,
70 config_entry_handler_cb handler
, void *user_data
);
73 * Parse a configuration value.
75 * This function expects either an unsigned integer or a boolean text option.
76 * The following strings are recognized: true, yes, on, false, no and off.
78 * Returns either the value of the parsed integer, or 0/1 if a boolean text
79 * string was recognized. Negative values indicate an error.
82 int config_parse_value(const char *value
);
85 * Create an instance of a configuration writer.
87 * fd_output File to which the XML content must be written. The file will be
88 * closed once the config_writer has been destroyed.
90 * indent If other than 0 the XML will be pretty printed
91 * with indentation and newline.
93 * Returns an instance of a configuration writer on success, NULL on
97 struct config_writer
*config_writer_create(int fd_output
, int indent
);
100 * Destroy an instance of a configuration writer.
102 * writer An instance of a configuration writer.
104 * Returns zero if the XML document could be closed cleanly. Negative values
108 int config_writer_destroy(struct config_writer
*writer
);
111 * Open an element tag.
113 * writer An instance of a configuration writer.
115 * element_name Element tag name.
117 * Returns zero if the XML element could be opened.
118 * Negative values indicate an error.
121 int config_writer_open_element(struct config_writer
*writer
,
122 const char *element_name
);
125 * Write an element tag attribute.
127 * writer An instance of a configuration writer.
129 * name Attribute name.
131 * Returns zero if the XML element's attribute could be written.
132 * Negative values indicate an error.
135 int config_writer_write_attribute(struct config_writer
*writer
,
136 const char *name
, const char *value
);
139 * Close the current element tag.
141 * writer An instance of a configuration writer.
143 * Returns zero if the XML document could be closed cleanly.
144 * Negative values indicate an error.
147 int config_writer_close_element(struct config_writer
*writer
);
150 * Write an element of type unsigned int.
152 * writer An instance of a configuration writer.
154 * element_name Element name.
156 * value Unsigned int value of the element
158 * Returns zero if the element's value could be written.
159 * Negative values indicate an error.
162 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
163 const char *element_name
, uint64_t value
);
166 * Write an element of type signed int.
168 * writer An instance of a configuration writer.
170 * element_name Element name.
172 * value Signed int value of the element
174 * Returns zero if the element's value could be written.
175 * Negative values indicate an error.
177 int config_writer_write_element_signed_int(struct config_writer
*writer
,
178 const char *element_name
, int64_t value
);
181 * Write an element of type boolean.
183 * writer An instance of a configuration writer.
185 * element_name Element name.
187 * value Boolean value of the element
189 * Returns zero if the element's value could be written.
190 * Negative values indicate an error.
193 int config_writer_write_element_bool(struct config_writer
*writer
,
194 const char *element_name
, int value
);
197 * Write an element of type string.
199 * writer An instance of a configuration writer.
201 * element_name Element name.
203 * value String value of the element
205 * Returns zero if the element's value could be written.
206 * Negative values indicate an error.
209 int config_writer_write_element_string(struct config_writer
*writer
,
210 const char *element_name
, const char *value
);
213 * Load session configurations from a file.
215 * path Path to an LTTng session configuration file. All *.lttng files
216 * will be loaded if path is a directory. If path is NULL, the default
217 * paths will be searched in the following order:
218 * 1) $HOME/.lttng/sessions
219 * 2) /etc/lttng/sessions
221 * session_name Name of the session to load. Will load all
222 * sessions from path if NULL.
224 * overwrite Overwrite current session configuration if it exists.
225 * autoload Tell to load the auto session(s).
226 * overrides The override attribute structure specifying override parameters.
228 * Returns zero if the session could be loaded successfully. Returns
229 * 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
);
236 #endif /* _CONFIG_H */