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