]> git.ipfire.org Git - people/ms/network.git/blob - src/networkd/config.h
ports: Refactor enumerating ports
[people/ms/network.git] / src / networkd / config.h
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
24 #include <stdio.h>
25
26 #define NETWORK_CONFIG_KEY_MAX_LENGTH 128
27 #define NETWORK_CONFIG_VALUE_MAX_LENGTH 2048
28
29 typedef struct nw_config nw_config;
30
31 int nw_config_create(nw_config** config, FILE* f);
32 int nw_config_open(nw_config** config, const char* path);
33
34 nw_config* nw_config_ref(nw_config* config);
35 nw_config* nw_config_unref(nw_config* config);
36
37 int nw_config_copy(nw_config* config, nw_config** copy);
38
39 int nw_config_flush(nw_config* config);
40
41 int nw_config_read(nw_config* config, FILE* f);
42 int nw_config_write(nw_config* config, FILE* f);
43
44 int nw_config_del(nw_config* config, const char* key);
45
46 const char* nw_config_get(nw_config* config, const char* key);
47 int nw_config_set(nw_config* config, const char* key, const char* value);
48
49 int nw_config_get_int(nw_config* config, const char* key, const int __default);
50 int nw_config_set_int(nw_config* config, const char* key, const int value);
51
52 int nw_config_get_bool(nw_config* config, const char* key);
53 int nw_config_set_bool(nw_config* config, const char* key, const int value);
54
55 /*
56 Options
57 */
58
59 int nw_config_options_read(nw_config* config);
60 int nw_config_options_write(nw_config* config);
61
62 typedef int (*nw_config_option_read_callback_t)
63 (nw_config* config, const char* key, void* value, void* data);
64 typedef int (*nw_config_option_write_callback_t)
65 (nw_config* config, const char* key, const void* value, void* data);
66
67 int nw_config_option_add(nw_config* config, const char* key, void* value,
68 nw_config_option_read_callback_t read_callback,
69 nw_config_option_write_callback_t write_callback, void* data);
70
71 #define NW_CONFIG_OPTION(config, key, value, read_callback, write_callback, data) \
72 nw_config_option_add(config, key, value, read_callback, write_callback, data)
73
74 // String
75
76 #define NW_CONFIG_OPTION_STRING(config, key, value) \
77 nw_config_option_add(config, key, value, nw_config_read_string, nw_config_write_string, NULL)
78
79 int nw_config_read_string(nw_config* config, const char* key, void* value, void* data);
80 int nw_config_write_string(nw_config* config, const char* key, const void* value, void* data);
81
82 // String Table
83
84 #define NW_CONFIG_OPTION_STRING_TABLE(config, key, value, table) \
85 nw_config_option_add(config, key, value, nw_config_read_string_table, nw_config_write_string_table, (void*)table)
86
87 int nw_config_read_string_table(nw_config* config, const char* key, void* value, void* data);
88 int nw_config_write_string_table(nw_config* config, const char* key, const void* value, void* data);
89
90 // Integer
91
92 #define NW_CONFIG_OPTION_INT(config, key, value) \
93 nw_config_option_add(config, key, value, nw_config_read_int, nw_config_write_int, NULL)
94
95 int nw_config_read_int(nw_config* config, const char* key, void* value, void* data);
96 int nw_config_write_int(nw_config* config, const char* key, const void* value, void* data);
97
98 // Address
99
100 #define NW_CONFIG_OPTION_ADDRESS(config, key, value) \
101 nw_config_option_add(config, key, value, nw_config_read_address, nw_config_write_address, NULL)
102
103 int nw_config_read_address(nw_config* config, const char* key, void* value, void* data);
104 int nw_config_write_address(nw_config* config, const char* key, const void* value, void* data);
105
106 #endif /* NETWORKD_CONFIG_H */