]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/networkd/config.h
config: Add string buffer type
[people/ms/network.git] / src / networkd / config.h
index b25d05e6e1b7480bfff9d81c4c0b4bc9b37d49fe..4b8bc01fb9570688d9977444a8bdc2b39d46d782 100644 (file)
@@ -60,47 +60,64 @@ int nw_config_options_read(nw_config* config);
 int nw_config_options_write(nw_config* config);
 
 typedef int (*nw_config_option_read_callback_t)
-       (nw_config* config, const char* key, void* value, void* data);
+       (nw_config* config, const char* key, void* value, const size_t length, void* data);
 typedef int (*nw_config_option_write_callback_t)
-       (nw_config* config, const char* key, const void* value, void* data);
+       (nw_config* config, const char* key, const void* value, const size_t length, void* data);
 
-int nw_config_option_add(nw_config* config, const char* key, void* value,
+int nw_config_option_add(nw_config* config, const char* key, void* value, const size_t length,
        nw_config_option_read_callback_t read_callback,
        nw_config_option_write_callback_t write_callback, void* data);
 
-#define NW_CONFIG_OPTION(config, key, value, read_callback, write_callback, data) \
-       nw_config_option_add(config, key, value, read_callback, write_callback, data)
+#define NW_CONFIG_OPTION(config, key, value, length, read_callback, write_callback, data) \
+       nw_config_option_add(config, key, value, length, read_callback, write_callback, data)
 
 // String
 
 #define NW_CONFIG_OPTION_STRING(config, key, value) \
        nw_config_option_add(config, key, value, nw_config_read_string, nw_config_write_string, NULL)
 
-int nw_config_read_string(nw_config* config, const char* key, void* value, void* data);
-int nw_config_write_string(nw_config* config, const char* key, const void* value, void* data);
+int nw_config_read_string(nw_config* config,
+       const char* key, void* value, const size_t length, void* data);
+int nw_config_write_string(nw_config* config,
+       const char* key, const void* value, const size_t length, void* data);
+
+#define NW_CONFIG_OPTION_STRING_BUFFER(config, key, value) \
+       nw_config_option_add(config, key, value, sizeof(value), \
+               nw_config_read_string_buffer, nw_config_write_string_buffer, NULL)
+
+int nw_config_read_string_buffer(nw_config* config,
+       const char* key, void* value, const size_t length, void* data);
+#define nw_config_write_string_buffer nw_config_write_string
 
 // String Table
 
 #define NW_CONFIG_OPTION_STRING_TABLE(config, key, value, table) \
-       nw_config_option_add(config, key, value, nw_config_read_string_table, nw_config_write_string_table, (void*)table)
+       nw_config_option_add(config, key, value, 0, \
+               nw_config_read_string_table, nw_config_write_string_table, (void*)table)
 
-int nw_config_read_string_table(nw_config* config, const char* key, void* value, void* data);
-int nw_config_write_string_table(nw_config* config, const char* key, const void* value, void* data);
+int nw_config_read_string_table(nw_config* config,
+       const char* key, void* value, const size_t length, void* data);
+int nw_config_write_string_table(nw_config* config,
+       const char* key, const void* value, const size_t length, void* data);
 
 // Integer
 
 #define NW_CONFIG_OPTION_INT(config, key, value) \
-       nw_config_option_add(config, key, value, nw_config_read_int, nw_config_write_int, NULL)
+       nw_config_option_add(config, key, value, 0, nw_config_read_int, nw_config_write_int, NULL)
 
-int nw_config_read_int(nw_config* config, const char* key, void* value, void* data);
-int nw_config_write_int(nw_config* config, const char* key, const void* value, void* data);
+int nw_config_read_int(nw_config* config,
+       const char* key, void* value, const size_t length, void* data);
+int nw_config_write_int(nw_config* config,
+       const char* key, const void* value, const size_t length, void* data);
 
 // Address
 
 #define NW_CONFIG_OPTION_ADDRESS(config, key, value) \
-       nw_config_option_add(config, key, value, nw_config_read_address, nw_config_write_address, NULL)
+       nw_config_option_add(config, key, value, 0, nw_config_read_address, nw_config_write_address, NULL)
 
-int nw_config_read_address(nw_config* config, const char* key, void* value, void* data);
-int nw_config_write_address(nw_config* config, const char* key, const void* value, void* data);
+int nw_config_read_address(nw_config* config,
+       const char* key, void* value, const size_t length, void* data);
+int nw_config_write_address(nw_config* config,
+       const char* key, const void* value, const size_t length, void* data);
 
 #endif /* NETWORKD_CONFIG_H */