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> | |
22 | #include <common/macros.h> | |
23 | ||
24 | struct config_entry { | |
25 | /* section is NULL if the entry is not in a section */ | |
26 | const char *section; | |
27 | const char *name; | |
28 | const char *value; | |
29 | }; | |
30 | ||
31 | /* | |
32 | * A config_entry_handler_cb receives config_entry structures belonging to the | |
33 | * sections the handler has been registered to. | |
34 | * | |
35 | * The config_entry and its members are only valid for the duration of the call | |
36 | * and must not be freed. | |
37 | * | |
38 | * config_entry_handler_cb may return negative value to indicate an error in | |
39 | * the configuration file. | |
40 | */ | |
41 | typedef int (*config_entry_handler_cb)(const struct config_entry *, void *); | |
42 | ||
43 | /* | |
44 | * Read a section's entries in an INI configuration file. | |
45 | * | |
46 | * path may be NULL, in which case the following paths will be tried: | |
47 | * 1) $HOME/.lttng/lttng.conf | |
48 | * 2) /etc/lttng/lttng.conf | |
49 | * | |
50 | * handler will only be called with entries belonging to the provided section. | |
51 | * If section is NULL, all entries will be relayed to handler. If section is | |
52 | * "", only the global entries are relayed. | |
53 | * | |
54 | * Returns 0 on success. Negative values are error codes. If the return value | |
55 | * is positive, it represents the line number on which a parsing error occured. | |
56 | */ | |
57 | LTTNG_HIDDEN | |
58 | int config_get_section_entries(const char *path, const char *section, | |
59 | config_entry_handler_cb handler, void *user_data); | |
60 | ||
61 | /* | |
62 | * Parse a configuration value. | |
63 | * | |
64 | * This function expects either an unsigned integer or a boolean text option. | |
65 | * The following strings are recognized: true, yes, on, false, no and off. | |
66 | * | |
67 | * Returns either the value of the parsed integer, or 0/1 if a boolean text | |
68 | * string was recognized. Negative values indicate an error. | |
69 | */ | |
70 | LTTNG_HIDDEN | |
71 | int config_parse_value(const char *value); | |
72 | ||
73 | #endif /* _CONFIG_H */ |