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