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/macros.h>
26 /* section is NULL if the entry is not in a section */
32 /* Instance of a configuration writer. */
36 * A config_entry_handler_cb receives config_entry structures belonging to the
37 * sections the handler has been registered to.
39 * The config_entry and its members are only valid for the duration of the call
40 * and must not be freed.
42 * config_entry_handler_cb may return negative value to indicate an error in
43 * the configuration file.
45 typedef int (*config_entry_handler_cb
)(const struct config_entry
*, void *);
48 * Read a section's entries in an INI configuration file.
50 * path may be NULL, in which case the following paths will be tried:
51 * 1) $HOME/.lttng/lttng.conf
52 * 2) /etc/lttng/lttng.conf
54 * handler will only be called with entries belonging to the provided section.
55 * If section is NULL, all entries will be relayed to handler. If section is
56 * "", only the global entries are relayed.
58 * Returns 0 on success. Negative values are error codes. If the return value
59 * is positive, it represents the line number on which a parsing error occured.
62 int config_get_section_entries(const char *path
, const char *section
,
63 config_entry_handler_cb handler
, void *user_data
);
66 * Parse a configuration value.
68 * This function expects either an unsigned integer or a boolean text option.
69 * The following strings are recognized: true, yes, on, false, no and off.
71 * Returns either the value of the parsed integer, or 0/1 if a boolean text
72 * 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. The file will be
81 * closed once the config_writer has been destroyed.
83 * Returns an instance of a configuration writer on success, NULL on
87 struct config_writer
*config_writer_create(int fd_output
);
90 * Destroy an instance of a configuration writer.
92 * writer An instance of a configuration writer.
94 * Returns zero if the XML document could be closed cleanly. Negative values
98 int config_writer_destroy(struct config_writer
*writer
);
101 * Open an element tag.
103 * writer An instance of a configuration writer.
105 * element_name Element tag name.
107 * Returns zero if the XML document could be closed cleanly.
108 * Negative values indicate an error.
111 int config_writer_open_element(struct config_writer
*writer
,
112 const char *element_name
);
115 * Close the current element tag.
117 * writer An instance of a configuration writer.
119 * Returns zero if the XML document could be closed cleanly.
120 * Negative values indicate an error.
123 int config_writer_close_element(struct config_writer
*writer
);
126 * Write an element of type unsigned int.
128 * writer An instance of a configuration writer.
130 * element_name Element name.
132 * value Unsigned int value of the element
134 * Returns zero if the element's value could be written.
135 * Negative values indicate an error.
138 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
139 const char *element_name
, uint64_t value
);
142 * Write an element of type signed int.
144 * writer An instance of a configuration writer.
146 * element_name Element name.
148 * value Signed int value of the element
150 * Returns zero if the element's value could be written.
151 * Negative values indicate an error.
153 int config_writer_write_element_signed_int(struct config_writer
*writer
,
154 const char *element_name
, int64_t value
);
157 * Write an element of type boolean.
159 * writer An instance of a configuration writer.
161 * element_name Element name.
163 * value Boolean value of the element
165 * Returns zero if the element's value could be written.
166 * Negative values indicate an error.
169 int config_writer_write_element_bool(struct config_writer
*writer
,
170 const char *element_name
, int value
);
173 * Write an element of type string.
175 * writer An instance of a configuration writer.
177 * element_name Element name.
179 * value String value of the element
181 * Returns zero if the element's value could be written.
182 * Negative values indicate an error.
185 int config_writer_write_element_string(struct config_writer
*writer
,
186 const char *element_name
, const char *value
);
189 * Load session configurations from a file.
191 * path Path to an LTTng session configuration file. All *.lttng files
192 * will be loaded if path is a directory. If path is NULL, the default
193 * paths will be searched in the following order:
194 * 1) $HOME/.lttng/sessions
195 * 2) /etc/lttng/sessions
197 * session_name Name of the session to load. Will load all
198 * sessions from path if NULL.
200 * override Override current session configuration if it exists.
202 * Returns zero if the session could be loaded successfully. Returns
203 * a negative LTTNG_ERR code on error.
206 int config_load_session(const char *path
, const char *session_name
,
209 #endif /* _CONFIG_H */