a6955b0b95b4e9435114187c6ebeb1adfd8093fd
[lttng-tools.git] / src / common / config / session-config.h
1 /*
2 * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8 #ifndef _CONFIG_H
9 #define _CONFIG_H
10
11 #include <common/config/ini.h>
12 #include <common/config/config-session-abi.h>
13 #include <common/macros.h>
14 #include <stdint.h>
15
16 struct config_entry {
17 /* section is NULL if the entry is not in a section */
18 const char *section;
19 const char *name;
20 const char *value;
21 };
22
23 struct config_load_session_override_attr {
24 char *path_url;
25 char *ctrl_url;
26 char *data_url;
27 char *session_name;
28 };
29
30 /* Instance of a configuration writer. */
31 struct config_writer;
32
33 /*
34 * A config_entry_handler_cb receives config_entry structures belonging to the
35 * sections the handler has been registered to.
36 *
37 * The config_entry and its members are only valid for the duration of the call
38 * and must not be freed.
39 *
40 * config_entry_handler_cb may return negative value to indicate an error in
41 * the configuration file.
42 */
43 typedef int (*config_entry_handler_cb)(const struct config_entry *, void *);
44
45 /*
46 * Read a section's entries in an INI configuration file.
47 *
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
51 *
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.
55 *
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.
58 */
59 int config_get_section_entries(const char *path, const char *section,
60 config_entry_handler_cb handler, void *user_data);
61
62 /*
63 * Parse a configuration value.
64 *
65 * This function expects either an unsigned integer or a boolean text option.
66 * The following strings are recognized: true, yes, on, false, no and off.
67 *
68 * Returns either the value of the parsed integer, or 0/1 if a boolean text
69 * string was recognized. Negative values indicate an error.
70 */
71 int config_parse_value(const char *value);
72
73 /*
74 * Create an instance of a configuration writer.
75 *
76 * fd_output File to which the XML content must be written. fd_output is
77 * owned by the caller.
78 *
79 * indent If other than 0 the XML will be pretty printed
80 * with indentation and newline.
81 *
82 * Returns an instance of a configuration writer on success, NULL on
83 * error.
84 */
85 struct config_writer *config_writer_create(int fd_output, int indent);
86
87 /*
88 * Destroy an instance of a configuration writer.
89 *
90 * writer An instance of a configuration writer.
91 *
92 * Returns zero if the XML document could be closed cleanly. Negative values
93 * indicate an error.
94 */
95 int config_writer_destroy(struct config_writer *writer);
96
97 /*
98 * Open an element tag.
99 *
100 * writer An instance of a configuration writer.
101 *
102 * element_name Element tag name.
103 *
104 * Returns zero if the XML element could be opened.
105 * Negative values indicate an error.
106 */
107 int config_writer_open_element(struct config_writer *writer,
108 const char *element_name);
109
110 /*
111 * Write an element tag attribute.
112 *
113 * writer An instance of a configuration writer.
114 *
115 * name Attribute name.
116 *
117 * Returns zero if the XML element's attribute could be written.
118 * Negative values indicate an error.
119 */
120 int config_writer_write_attribute(struct config_writer *writer,
121 const char *name, const char *value);
122
123 /*
124 * Close the current element tag.
125 *
126 * writer An instance of a configuration writer.
127 *
128 * Returns zero if the XML document could be closed cleanly.
129 * Negative values indicate an error.
130 */
131 int config_writer_close_element(struct config_writer *writer);
132
133 /*
134 * Write an element of type unsigned int.
135 *
136 * writer An instance of a configuration writer.
137 *
138 * element_name Element name.
139 *
140 * value Unsigned int value of the element
141 *
142 * Returns zero if the element's value could be written.
143 * Negative values indicate an error.
144 */
145 int config_writer_write_element_unsigned_int(struct config_writer *writer,
146 const char *element_name, uint64_t value);
147
148 /*
149 * Write an element of type signed int.
150 *
151 * writer An instance of a configuration writer.
152 *
153 * element_name Element name.
154 *
155 * value Signed int value of the element
156 *
157 * Returns zero if the element's value could be written.
158 * Negative values indicate an error.
159 */
160 int config_writer_write_element_signed_int(struct config_writer *writer,
161 const char *element_name, int64_t value);
162
163 /*
164 * Write an element of type boolean.
165 *
166 * writer An instance of a configuration writer.
167 *
168 * element_name Element name.
169 *
170 * value Boolean value of the element
171 *
172 * Returns zero if the element's value could be written.
173 * Negative values indicate an error.
174 */
175 int config_writer_write_element_bool(struct config_writer *writer,
176 const char *element_name, int value);
177
178 /*
179 * Write an element of type string.
180 *
181 * writer An instance of a configuration writer.
182 *
183 * element_name Element name.
184 *
185 * value String value of the element
186 *
187 * Returns zero if the element's value could be written.
188 * Negative values indicate an error.
189 */
190 int config_writer_write_element_string(struct config_writer *writer,
191 const char *element_name, const char *value);
192
193 /*
194 * Write an element of type double.
195 *
196 * writer An instance of a configuration writer.
197 *
198 * element_name Element name.
199 *
200 * value Double value of the element
201 *
202 * Returns zero if the element's value could be written.
203 * Negative values indicate an error.
204 */
205 int config_writer_write_element_double(struct config_writer *writer,
206 const char *element_name,
207 double value);
208
209 /*
210 * Load session configurations from a file.
211 *
212 * path Path to an LTTng session configuration file. All *.lttng files
213 * will be loaded if path is a directory. If path is NULL, the default
214 * paths will be searched in the following order:
215 * 1) $HOME/.lttng/sessions
216 * 2) /etc/lttng/sessions
217 *
218 * session_name Name of the session to load. Will load all
219 * sessions from path if NULL.
220 *
221 * overwrite Overwrite current session configuration if it exists.
222 * autoload Tell to load the auto session(s).
223 * overrides The override attribute structure specifying override parameters.
224 *
225 * Returns zero if the session could be loaded successfully. Returns
226 * a negative LTTNG_ERR code on error.
227 */
228 int config_load_session(const char *path, const char *session_name,
229 int overwrite, unsigned int autoload,
230 const struct config_load_session_override_attr *overrides);
231
232 #endif /* _CONFIG_H */
This page took 0.03398 seconds and 3 git commands to generate.