]> git.ipfire.org Git - network.git/blame - src/networkd/config.h
config: Add string buffer type
[network.git] / src / networkd / config.h
CommitLineData
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 29typedef struct nw_config nw_config;
6b666d62 30
8edf3da1
MT
31int nw_config_create(nw_config** config, FILE* f);
32int nw_config_open(nw_config** config, const char* path);
6b666d62 33
2361667e
MT
34nw_config* nw_config_ref(nw_config* config);
35nw_config* nw_config_unref(nw_config* config);
6b666d62 36
082d81a3 37int nw_config_copy(nw_config* config, nw_config** copy);
c403eb4c 38
2361667e 39int nw_config_flush(nw_config* config);
c81a6335 40
8edf3da1
MT
41int nw_config_read(nw_config* config, FILE* f);
42int nw_config_write(nw_config* config, FILE* f);
d3dfdb77 43
2361667e 44int nw_config_del(nw_config* config, const char* key);
4237caa2 45
2361667e
MT
46const char* nw_config_get(nw_config* config, const char* key);
47int nw_config_set(nw_config* config, const char* key, const char* value);
4237caa2 48
2361667e
MT
49int nw_config_get_int(nw_config* config, const char* key, const int __default);
50int nw_config_set_int(nw_config* config, const char* key, const int value);
d39683a6 51
8b0b5c6d
MT
52int nw_config_get_bool(nw_config* config, const char* key);
53int nw_config_set_bool(nw_config* config, const char* key, const int value);
54
082d81a3
MT
55/*
56 Options
57*/
58
59int nw_config_options_read(nw_config* config);
60int nw_config_options_write(nw_config* config);
61
62typedef int (*nw_config_option_read_callback_t)
e633147d 63 (nw_config* config, const char* key, void* value, const size_t length, void* data);
082d81a3 64typedef int (*nw_config_option_write_callback_t)
e633147d 65 (nw_config* config, const char* key, const void* value, const size_t length, void* data);
082d81a3 66
e633147d 67int nw_config_option_add(nw_config* config, const char* key, void* value, const size_t length,
082d81a3 68 nw_config_option_read_callback_t read_callback,
3eeb38b7 69 nw_config_option_write_callback_t write_callback, void* data);
082d81a3 70
e633147d
MT
71#define NW_CONFIG_OPTION(config, key, value, length, read_callback, write_callback, data) \
72 nw_config_option_add(config, key, value, length, read_callback, write_callback, data)
082d81a3 73
7442668a
MT
74// String
75
cc54472e 76#define NW_CONFIG_OPTION_STRING(config, key, value) \
3eeb38b7 77 nw_config_option_add(config, key, value, nw_config_read_string, nw_config_write_string, NULL)
082d81a3 78
e633147d
MT
79int nw_config_read_string(nw_config* config,
80 const char* key, void* value, const size_t length, void* data);
81int nw_config_write_string(nw_config* config,
82 const char* key, const void* value, const size_t length, void* data);
83
84#define NW_CONFIG_OPTION_STRING_BUFFER(config, key, value) \
85 nw_config_option_add(config, key, value, sizeof(value), \
86 nw_config_read_string_buffer, nw_config_write_string_buffer, NULL)
87
88int nw_config_read_string_buffer(nw_config* config,
89 const char* key, void* value, const size_t length, void* data);
90#define nw_config_write_string_buffer nw_config_write_string
082d81a3 91
7442668a
MT
92// String Table
93
94#define NW_CONFIG_OPTION_STRING_TABLE(config, key, value, table) \
e633147d
MT
95 nw_config_option_add(config, key, value, 0, \
96 nw_config_read_string_table, nw_config_write_string_table, (void*)table)
7442668a 97
e633147d
MT
98int nw_config_read_string_table(nw_config* config,
99 const char* key, void* value, const size_t length, void* data);
100int nw_config_write_string_table(nw_config* config,
101 const char* key, const void* value, const size_t length, void* data);
7442668a
MT
102
103// Integer
104
cc54472e 105#define NW_CONFIG_OPTION_INT(config, key, value) \
e633147d 106 nw_config_option_add(config, key, value, 0, nw_config_read_int, nw_config_write_int, NULL)
082d81a3 107
e633147d
MT
108int nw_config_read_int(nw_config* config,
109 const char* key, void* value, const size_t length, void* data);
110int nw_config_write_int(nw_config* config,
111 const char* key, const void* value, const size_t length, void* data);
082d81a3 112
7442668a
MT
113// Address
114
cc54472e 115#define NW_CONFIG_OPTION_ADDRESS(config, key, value) \
e633147d 116 nw_config_option_add(config, key, value, 0, nw_config_read_address, nw_config_write_address, NULL)
082d81a3 117
e633147d
MT
118int nw_config_read_address(nw_config* config,
119 const char* key, void* value, const size_t length, void* data);
120int nw_config_write_address(nw_config* config,
121 const char* key, const void* value, const size_t length, void* data);
082d81a3 122
6b666d62 123#endif /* NETWORKD_CONFIG_H */