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 /* Instance of a configuration writer. */
37 * A config_entry_handler_cb receives config_entry structures belonging to the
38 * sections the handler has been registered to.
40 * The config_entry and its members are only valid for the duration of the call
41 * and must not be freed.
43 * config_entry_handler_cb may return negative value to indicate an error in
44 * the configuration file.
46 typedef int (*config_entry_handler_cb
)(const struct config_entry
*, void *);
49 * Read a section's entries in an INI configuration file.
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
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.
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.
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.
76 int config_parse_value(const char *value
);
79 * Create an instance of a configuration writer.
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.
84 * indent If other than 0 the XML will be pretty printed
85 * with indentation and newline.
87 * Returns an instance of a configuration writer on success, NULL on
91 struct config_writer
*config_writer_create(int fd_output
, int indent
);
94 * Destroy an instance of a configuration writer.
96 * writer An instance of a configuration writer.
98 * Returns zero if the XML document could be closed cleanly. Negative values
102 int config_writer_destroy(struct config_writer
*writer
);
105 * Open an element tag.
107 * writer An instance of a configuration writer.
109 * element_name Element tag name.
111 * Returns zero if the XML document could be closed cleanly.
112 * Negative values indicate an error.
115 int config_writer_open_element(struct config_writer
*writer
,
116 const char *element_name
);
119 * Close the current element tag.
121 * writer An instance of a configuration writer.
123 * Returns zero if the XML document could be closed cleanly.
124 * Negative values indicate an error.
127 int config_writer_close_element(struct config_writer
*writer
);
130 * Write an element of type unsigned int.
132 * writer An instance of a configuration writer.
134 * element_name Element name.
136 * value Unsigned int value of the element
138 * Returns zero if the element's value could be written.
139 * Negative values indicate an error.
142 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
143 const char *element_name
, uint64_t value
);
146 * Write an element of type signed int.
148 * writer An instance of a configuration writer.
150 * element_name Element name.
152 * value Signed int value of the element
154 * Returns zero if the element's value could be written.
155 * Negative values indicate an error.
157 int config_writer_write_element_signed_int(struct config_writer
*writer
,
158 const char *element_name
, int64_t value
);
161 * Write an element of type boolean.
163 * writer An instance of a configuration writer.
165 * element_name Element name.
167 * value Boolean value of the element
169 * Returns zero if the element's value could be written.
170 * Negative values indicate an error.
173 int config_writer_write_element_bool(struct config_writer
*writer
,
174 const char *element_name
, int value
);
177 * Write an element of type string.
179 * writer An instance of a configuration writer.
181 * element_name Element name.
183 * value String value of the element
185 * Returns zero if the element's value could be written.
186 * Negative values indicate an error.
189 int config_writer_write_element_string(struct config_writer
*writer
,
190 const char *element_name
, const char *value
);
193 * Load session configurations from a file.
195 * path Path to an LTTng session configuration file. All *.lttng files
196 * will be loaded if path is a directory. If path is NULL, the default
197 * paths will be searched in the following order:
198 * 1) $HOME/.lttng/sessions
199 * 2) /etc/lttng/sessions
201 * session_name Name of the session to load. Will load all
202 * sessions from path if NULL.
204 * override Override current session configuration if it exists.
205 * autoload Tell to load the auto session(s).
207 * Returns zero if the session could be loaded successfully. Returns
208 * a negative LTTNG_ERR code on error.
211 int config_load_session(const char *path
, const char *session_name
,
212 int override
, unsigned int autoload
);
214 #endif /* _CONFIG_H */