1 /*#############################################################################
3 # IPFire.org - A linux based firewall #
4 # Copyright (C) 2023 IPFire Network Development Team #
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. #
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. #
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/>. #
19 #############################################################################*/
21 #ifndef NETWORKD_CONFIG_H
22 #define NETWORKD_CONFIG_H
27 #define NETWORK_CONFIG_KEY_MAX_LENGTH 128
28 #define NETWORK_CONFIG_VALUE_MAX_LENGTH 2048
30 typedef struct nw_config nw_config
;
32 int nw_config_create(nw_config
** config
, FILE* f
);
33 int nw_config_open(nw_config
** config
, const char* path
);
35 nw_config
* nw_config_ref(nw_config
* config
);
36 nw_config
* nw_config_unref(nw_config
* config
);
38 int nw_config_copy(nw_config
* config
, nw_config
** copy
);
40 int nw_config_flush(nw_config
* config
);
42 int nw_config_read(nw_config
* config
, FILE* f
);
43 int nw_config_write(nw_config
* config
, FILE* f
);
45 int nw_config_del(nw_config
* config
, const char* key
);
47 const char* nw_config_get(nw_config
* config
, const char* key
);
48 int nw_config_set(nw_config
* config
, const char* key
, const char* value
);
50 int nw_config_get_int(nw_config
* config
, const char* key
, const int __default
);
51 int nw_config_set_int(nw_config
* config
, const char* key
, const int value
);
53 int nw_config_get_bool(nw_config
* config
, const char* key
);
54 int nw_config_set_bool(nw_config
* config
, const char* key
, const int value
);
60 typedef struct nw_configd nw_configd
;
62 int nw_configd_create(nw_configd
** dir
, const char* path
);
64 nw_configd
* nw_configd_ref(nw_configd
* dir
);
65 nw_configd
* nw_configd_unref(nw_configd
* dir
);
67 FILE* nw_configd_fopen(nw_configd
* dir
, const char* path
, const char* mode
);
68 int nw_configd_open_config(nw_config
** config
, nw_configd
* dir
, const char* path
);
69 int nw_configd_unlink(nw_configd
* dir
, const char* path
, int flags
);
71 nw_configd
* nw_configd_descend(nw_configd
* dir
, const char* path
);
73 typedef int (*nw_configd_walk_callback
)(struct dirent
* entry
, FILE* f
, void* data
);
75 int nw_configd_walk(nw_configd
* dir
, nw_configd_walk_callback callback
, void* data
);
81 int nw_config_options_read(nw_config
* config
);
82 int nw_config_options_write(nw_config
* config
);
84 typedef int (*nw_config_option_read_callback_t
)
85 (nw_config
* config
, const char* key
, void* value
, const size_t length
, void* data
);
86 typedef int (*nw_config_option_write_callback_t
)
87 (nw_config
* config
, const char* key
, const void* value
, const size_t length
, void* data
);
89 int nw_config_option_add(nw_config
* config
, const char* key
, void* value
, const size_t length
,
90 nw_config_option_read_callback_t read_callback
,
91 nw_config_option_write_callback_t write_callback
, void* data
);
93 #define NW_CONFIG_OPTION(config, key, value, length, read_callback, write_callback, data) \
94 nw_config_option_add(config, key, value, length, read_callback, write_callback, data)
98 #define NW_CONFIG_OPTION_STRING(config, key, value) \
99 nw_config_option_add(config, key, value, nw_config_read_string, nw_config_write_string, NULL)
101 int nw_config_read_string(nw_config
* config
,
102 const char* key
, void* value
, const size_t length
, void* data
);
103 int nw_config_write_string(nw_config
* config
,
104 const char* key
, const void* value
, const size_t length
, void* data
);
106 #define NW_CONFIG_OPTION_STRING_BUFFER(config, key, value) \
107 nw_config_option_add(config, key, value, sizeof(value), \
108 nw_config_read_string_buffer, nw_config_write_string_buffer, NULL)
110 int nw_config_read_string_buffer(nw_config
* config
,
111 const char* key
, void* value
, const size_t length
, void* data
);
112 #define nw_config_write_string_buffer nw_config_write_string
116 #define NW_CONFIG_OPTION_STRING_TABLE(config, key, value, table) \
117 nw_config_option_add(config, key, value, 0, \
118 nw_config_read_string_table, nw_config_write_string_table, (void*)table)
120 int nw_config_read_string_table(nw_config
* config
,
121 const char* key
, void* value
, const size_t length
, void* data
);
122 int nw_config_write_string_table(nw_config
* config
,
123 const char* key
, const void* value
, const size_t length
, void* data
);
127 #define NW_CONFIG_OPTION_INT(config, key, value) \
128 nw_config_option_add(config, key, value, 0, nw_config_read_int, nw_config_write_int, NULL)
130 int nw_config_read_int(nw_config
* config
,
131 const char* key
, void* value
, const size_t length
, void* data
);
132 int nw_config_write_int(nw_config
* config
,
133 const char* key
, const void* value
, const size_t length
, void* data
);
137 #define NW_CONFIG_OPTION_ADDRESS(config, key, value) \
138 nw_config_option_add(config, key, value, 0, nw_config_read_address, nw_config_write_address, NULL)
140 int nw_config_read_address(nw_config
* config
,
141 const char* key
, void* value
, const size_t length
, void* data
);
142 int nw_config_write_address(nw_config
* config
,
143 const char* key
, const void* value
, const size_t length
, void* data
);
145 #endif /* NETWORKD_CONFIG_H */