]>
Commit | Line | Data |
---|---|---|
6b666d62 MT |
1 | /*############################################################################# |
2 | # # | |
3 | # IPFire.org - A linux based firewall # | |
4 | # Copyright (C) 2023 IPFire Network Development Team # | |
5 | # # | |
6 | # This program is free software: you can redistribute it and/or modify # | |
7 | # it under the terms of the GNU General Public License as published by # | |
8 | # the Free Software Foundation, either version 3 of the License, or # | |
9 | # (at your option) any later version. # | |
10 | # # | |
11 | # This program is distributed in the hope that it will be useful, # | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
14 | # GNU General Public License for more details. # | |
15 | # # | |
16 | # You should have received a copy of the GNU General Public License # | |
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
18 | # # | |
19 | #############################################################################*/ | |
20 | ||
21 | #ifndef NETWORKD_CONFIG_H | |
22 | #define NETWORKD_CONFIG_H | |
23 | ||
e4eebc6e MT |
24 | #include <stdio.h> |
25 | ||
4237caa2 MT |
26 | #define NETWORK_CONFIG_KEY_MAX_LENGTH 128 |
27 | #define NETWORK_CONFIG_VALUE_MAX_LENGTH 2048 | |
28 | ||
2361667e | 29 | typedef struct nw_config nw_config; |
6b666d62 | 30 | |
2361667e | 31 | int nw_config_create(nw_config** config, const char* path); |
6b666d62 | 32 | |
2361667e MT |
33 | nw_config* nw_config_ref(nw_config* config); |
34 | nw_config* nw_config_unref(nw_config* config); | |
6b666d62 | 35 | |
c403eb4c | 36 | int nw_config_destroy(nw_config* config); |
082d81a3 | 37 | int nw_config_copy(nw_config* config, nw_config** copy); |
c403eb4c | 38 | |
2361667e | 39 | const char* nw_config_path(nw_config* config); |
91915f80 | 40 | |
2361667e | 41 | int nw_config_flush(nw_config* config); |
c81a6335 | 42 | |
2361667e MT |
43 | int nw_config_read(nw_config* config); |
44 | int nw_config_write(nw_config* config); | |
d3dfdb77 | 45 | |
2361667e | 46 | int nw_config_del(nw_config* config, const char* key); |
4237caa2 | 47 | |
2361667e MT |
48 | const char* nw_config_get(nw_config* config, const char* key); |
49 | int nw_config_set(nw_config* config, const char* key, const char* value); | |
4237caa2 | 50 | |
2361667e MT |
51 | int nw_config_get_int(nw_config* config, const char* key, const int __default); |
52 | int nw_config_set_int(nw_config* config, const char* key, const int value); | |
d39683a6 | 53 | |
8b0b5c6d MT |
54 | int nw_config_get_bool(nw_config* config, const char* key); |
55 | int nw_config_set_bool(nw_config* config, const char* key, const int value); | |
56 | ||
082d81a3 MT |
57 | /* |
58 | Options | |
59 | */ | |
60 | ||
61 | int nw_config_options_read(nw_config* config); | |
62 | int nw_config_options_write(nw_config* config); | |
63 | ||
64 | typedef int (*nw_config_option_read_callback_t) | |
3eeb38b7 | 65 | (nw_config* config, const char* key, void* value, void* data); |
082d81a3 | 66 | typedef int (*nw_config_option_write_callback_t) |
3eeb38b7 | 67 | (nw_config* config, const char* key, const void* value, void* data); |
082d81a3 MT |
68 | |
69 | int nw_config_option_add(nw_config* config, const char* key, void* value, | |
70 | nw_config_option_read_callback_t read_callback, | |
3eeb38b7 | 71 | nw_config_option_write_callback_t write_callback, void* data); |
082d81a3 | 72 | |
3eeb38b7 MT |
73 | #define NW_CONFIG_OPTION(config, key, value, read_callback, write_callback, data) \ |
74 | nw_config_option_add(config, key, value, read_callback, write_callback, data) | |
082d81a3 | 75 | |
7442668a MT |
76 | // String |
77 | ||
cc54472e | 78 | #define NW_CONFIG_OPTION_STRING(config, key, value) \ |
3eeb38b7 | 79 | nw_config_option_add(config, key, value, nw_config_read_string, nw_config_write_string, NULL) |
082d81a3 | 80 | |
3eeb38b7 MT |
81 | int nw_config_read_string(nw_config* config, const char* key, void* value, void* data); |
82 | int nw_config_write_string(nw_config* config, const char* key, const void* value, void* data); | |
082d81a3 | 83 | |
7442668a MT |
84 | // String Table |
85 | ||
86 | #define NW_CONFIG_OPTION_STRING_TABLE(config, key, value, table) \ | |
87 | nw_config_option_add(config, key, value, nw_config_read_string_table, nw_config_write_string_table, (void*)table) | |
88 | ||
89 | int nw_config_read_string_table(nw_config* config, const char* key, void* value, void* data); | |
90 | int nw_config_write_string_table(nw_config* config, const char* key, const void* value, void* data); | |
91 | ||
92 | // Integer | |
93 | ||
cc54472e | 94 | #define NW_CONFIG_OPTION_INT(config, key, value) \ |
3eeb38b7 | 95 | nw_config_option_add(config, key, value, nw_config_read_int, nw_config_write_int, NULL) |
082d81a3 | 96 | |
3eeb38b7 MT |
97 | int nw_config_read_int(nw_config* config, const char* key, void* value, void* data); |
98 | int nw_config_write_int(nw_config* config, const char* key, const void* value, void* data); | |
082d81a3 | 99 | |
7442668a MT |
100 | // Address |
101 | ||
cc54472e | 102 | #define NW_CONFIG_OPTION_ADDRESS(config, key, value) \ |
3eeb38b7 | 103 | nw_config_option_add(config, key, value, nw_config_read_address, nw_config_write_address, NULL) |
082d81a3 | 104 | |
3eeb38b7 MT |
105 | int nw_config_read_address(nw_config* config, const char* key, void* value, void* data); |
106 | int nw_config_write_address(nw_config* config, const char* key, const void* value, void* data); | |
082d81a3 | 107 | |
6b666d62 | 108 | #endif /* NETWORKD_CONFIG_H */ |