]> git.ipfire.org Git - network.git/blobdiff - src/networkd/config.h
config: Implement option that looks up string tables
[network.git] / src / networkd / config.h
index 5b9910bdf2afecb5213858cee360e562090eec85..63e9d180f217e95b4c24f12587ec3ab70696aaae 100644 (file)
 #define NETWORK_CONFIG_KEY_MAX_LENGTH          128
 #define NETWORK_CONFIG_VALUE_MAX_LENGTH                2048
 
-struct nw_config;
+typedef struct nw_config nw_config;
 
-int nw_config_create(struct nw_config** config, const char* path);
+int nw_config_create(nw_config** config, const char* path);
 
-struct nw_config* nw_config_ref(struct nw_config* config);
-struct nw_config* nw_config_unref(struct nw_config* config);
+nw_config* nw_config_ref(nw_config* config);
+nw_config* nw_config_unref(nw_config* config);
 
-const char* nw_config_path(struct nw_config* config);
+int nw_config_destroy(nw_config* config);
+int nw_config_copy(nw_config* config, nw_config** copy);
 
-int nw_config_flush(struct nw_config* config);
+const char* nw_config_path(nw_config* config);
 
-int nw_config_read(struct nw_config* config);
-int nw_config_write(struct nw_config* config);
+int nw_config_flush(nw_config* config);
 
-int nw_config_del(struct nw_config* config, const char* key);
+int nw_config_read(nw_config* config);
+int nw_config_write(nw_config* config);
 
-int nw_config_set(struct nw_config* config, const char* key, const char* value);
+int nw_config_del(nw_config* config, const char* key);
 
-const char* nw_config_get(struct nw_config* config, const char* key);
-unsigned int nw_config_get_unsigned_int(struct nw_config* config, const char* key);
+const char* nw_config_get(nw_config* config, const char* key);
+int nw_config_set(nw_config* config, const char* key, const char* value);
+
+int nw_config_get_int(nw_config* config, const char* key, const int __default);
+int nw_config_set_int(nw_config* config, const char* key, const int value);
+
+int nw_config_get_bool(nw_config* config, const char* key);
+int nw_config_set_bool(nw_config* config, const char* key, const int value);
+
+/*
+       Options
+*/
+
+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);
+typedef int (*nw_config_option_write_callback_t)
+       (nw_config* config, const char* key, const void* value, void* data);
+
+int nw_config_option_add(nw_config* config, const char* key, void* value,
+       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)
+
+// 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);
+
+// 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)
+
+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);
+
+// 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)
+
+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);
+
+// 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)
+
+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);
 
 #endif /* NETWORKD_CONFIG_H */