Commit | Line | Data |
---|---|---|
3299fd31 SM |
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 INI_CONFIG_H | |
9 | #define INI_CONFIG_H | |
10 | ||
11 | struct config_entry { | |
12 | /* section is NULL if the entry is not in a section */ | |
13 | const char *section; | |
14 | const char *name; | |
15 | const char *value; | |
16 | }; | |
17 | ||
18 | /* | |
19 | * A config_entry_handler_cb receives config_entry structures belonging to the | |
20 | * sections the handler has been registered to. | |
21 | * | |
22 | * The config_entry and its members are only valid for the duration of the call | |
23 | * and must not be freed. | |
24 | * | |
25 | * config_entry_handler_cb may return negative value to indicate an error in | |
26 | * the configuration file. | |
27 | */ | |
28 | typedef int (*config_entry_handler_cb)(const struct config_entry *, void *); | |
29 | ||
30 | /* | |
31 | * Read a section's entries in an INI configuration file. | |
32 | * | |
33 | * path may be NULL, in which case the following paths will be tried: | |
34 | * 1) $HOME/.lttng/lttng.conf | |
35 | * 2) /etc/lttng/lttng.conf | |
36 | * | |
37 | * handler will only be called with entries belonging to the provided section. | |
38 | * If section is NULL, all entries will be relayed to handler. If section is | |
39 | * "", only the global entries are relayed. | |
40 | * | |
41 | * Returns 0 on success. Negative values are error codes. If the return value | |
42 | * is positive, it represents the line number on which a parsing error occurred. | |
43 | */ | |
44 | int config_get_section_entries(const char *path, const char *section, | |
45 | config_entry_handler_cb handler, void *user_data); | |
46 | ||
47 | /* | |
48 | * Parse a configuration value. | |
49 | * | |
50 | * This function expects either an unsigned integer or a boolean text option. | |
51 | * The following strings are recognized: true, yes, on, false, no and off. | |
52 | * | |
53 | * Returns either the value of the parsed integer, or 0/1 if a boolean text | |
54 | * string was recognized. Negative values indicate an error. | |
55 | */ | |
56 | int config_parse_value(const char *value); | |
57 | ||
58 | #endif /* INI_CONFIG_H */ |