]> git.ipfire.org Git - network.git/commitdiff
config: Rename "data" to "value" as it holds a reference to it
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 8 Jun 2023 15:17:24 +0000 (15:17 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 8 Jun 2023 15:17:24 +0000 (15:17 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/networkd/config.c
src/networkd/config.h

index 6f22da2c706106519c84314600d26062074b2a4d..b142d17d452e1eef405f18415443152351d8068e 100644 (file)
@@ -42,7 +42,7 @@ struct nw_config_option {
        STAILQ_ENTRY(nw_config_option) nodes;
 
        const char* key;
-       void* data;
+       void* value;
 
        // Callbacks
        nw_config_option_read_callback_t read_callback;
@@ -491,7 +491,7 @@ int nw_config_options_read(nw_config* config) {
        int r;
 
        STAILQ_FOREACH(option, &config->options, nodes) {
-               r = option->read_callback(config, option->key, option->data);
+               r = option->read_callback(config, option->key, option->value);
                if (r < 0)
                        return r;
        }
@@ -504,7 +504,7 @@ int nw_config_options_write(nw_config* config) {
        int r;
 
        STAILQ_FOREACH(option, &config->options, nodes) {
-               r = option->write_callback(config, option->key, option->data);
+               r = option->write_callback(config, option->key, option->value);
                if (r < 0)
                        return r;
        }
@@ -512,11 +512,11 @@ int nw_config_options_write(nw_config* config) {
        return 0;
 }
 
-int nw_config_option_add(nw_config* config, const char* key, 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) {
        // Check input
-       if (!key || !data || !read_callback || !write_callback)
+       if (!key || !value || !read_callback || !write_callback)
                return -EINVAL;
 
        // Allocate a new option
@@ -527,8 +527,8 @@ int nw_config_option_add(nw_config* config, const char* key, void* data,
        // Set key
        option->key = key;
 
-       // Set data
-       option->data = data;
+       // Set value
+       option->value = value;
 
        // Set callbacks
        option->read_callback = read_callback;
@@ -540,67 +540,61 @@ int nw_config_option_add(nw_config* config, const char* key, void* data,
        return 0;
 }
 
-int nw_config_read_int(nw_config* config, const char* key, void* data) {
-       int* p = (int*)data;
-
+int nw_config_read_int(nw_config* config, const char* key, void* value) {
        // Fetch the value
-       *p = nw_config_get_int(config, key, -1);
+       *(int*)value = nw_config_get_int(config, key, -1);
 
        return 0;
 }
 
-int nw_config_write_int(nw_config* config, const char* key, const void* data) {
+int nw_config_write_int(nw_config* config, const char* key, const void* value) {
        return 0;
 }
 
 // String
 
-int nw_config_read_string(nw_config* config, const char* key, void* data) {
-       const char** p = (const char**)data;
-
+int nw_config_read_string(nw_config* config, const char* key, void* value) {
        // Fetch the value
-       const char* value = nw_config_get(config, key);
-       if (value)
-               *p = value;
+       const char* p = nw_config_get(config, key);
+       if (p)
+               *(const char**)value = p;
 
        return 0;
 }
 
-int nw_config_write_string(nw_config* config, const char* key, const void* data) {
-       const char** value = (const char**)data;
-
-       return nw_config_set(config, key, *value);
+int nw_config_write_string(nw_config* config, const char* key, const void* value) {
+       return nw_config_set(config, key, *(const char**)value);
 }
 
 // Address
 
-int nw_config_read_address(nw_config* config, const char* key, void* data) {
-       nw_address_t* address = (nw_address_t*)data;
+int nw_config_read_address(nw_config* config, const char* key, void* value) {
+       nw_address_t* address = (nw_address_t*)value;
        int r;
 
        // Fetch the value
-       const char* value = nw_config_get(config, key);
-       if (!value)
+       const char* p = nw_config_get(config, key);
+       if (!p)
                return -EINVAL;
 
-       r = nw_address_from_string(address, value);
+       r = nw_address_from_string(address, p);
        if (r < 0)
-               ERROR("Could not parse address: %s\n", value);
+               ERROR("Could not parse address: %s\n", p);
 
        return r;
 }
 
-int nw_config_write_address(nw_config* config, const char* key, const void* data) {
-       const nw_address_t* address = (nw_address_t*)data;
+int nw_config_write_address(nw_config* config, const char* key, const void* value) {
+       const nw_address_t* address = (nw_address_t*)value;
        int r;
 
        // Format the address to string
-       char* value = nw_address_to_string(address);
-       if (!value)
+       char* p = nw_address_to_string(address);
+       if (!p)
                return -errno;
 
        // Store the value
-       r = nw_config_set(config, key, value);
+       r = nw_config_set(config, key, p);
        if (r < 0)
                goto ERROR;
 
@@ -608,8 +602,8 @@ int nw_config_write_address(nw_config* config, const char* key, const void* data
        r = 0;
 
 ERROR:
-       if (value)
-               free(value);
+       if (p)
+               free(p);
 
        return r;
 }
index b5417e48d6b8c070875d81e94a3b8e71bca432c6..71850387cf17343d90674ad635e2bc0b05cb87aa 100644 (file)
@@ -62,9 +62,9 @@ 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* data);
+       (nw_config* config, const char* key, void* value);
 typedef int (*nw_config_option_write_callback_t)
-       (nw_config* config, const char* key, const void* data);
+       (nw_config* config, const char* key, const void* value);
 
 int nw_config_option_add(nw_config* config, const char* key, void* value,
        nw_config_option_read_callback_t read_callback,
@@ -73,22 +73,22 @@ int nw_config_option_add(nw_config* config, const char* key, void* value,
 #define NW_CONFIG_OPTION(config, key, data, read_callback, write_callback) \
        nw_config_option_add(config, key, data, read_callback, write_callback)
 
-#define NW_CONFIG_OPTION_STRING(config, key, data) \
-       nw_config_option_add(config, key, data, nw_config_read_string, nw_config_write_string)
+#define NW_CONFIG_OPTION_STRING(config, key, value) \
+       nw_config_option_add(config, key, value, nw_config_read_string, nw_config_write_string)
 
-int nw_config_read_string(nw_config* config, const char* key, void* data);
-int nw_config_write_string(nw_config* config, const char* key, const void* data);
+int nw_config_read_string(nw_config* config, const char* key, void* value);
+int nw_config_write_string(nw_config* config, const char* key, const void* value);
 
-#define NW_CONFIG_OPTION_INT(config, key, data) \
-       nw_config_option_add(config, key, data, nw_config_read_int, nw_config_write_int)
+#define NW_CONFIG_OPTION_INT(config, key, value) \
+       nw_config_option_add(config, key, value, nw_config_read_int, nw_config_write_int)
 
-int nw_config_read_int(nw_config* config, const char* key, void* data);
-int nw_config_write_int(nw_config* config, const char* key, const void* data);
+int nw_config_read_int(nw_config* config, const char* key, void* value);
+int nw_config_write_int(nw_config* config, const char* key, const void* value);
 
-#define NW_CONFIG_OPTION_ADDRESS(config, key, data) \
-       nw_config_option_add(config, key, data, nw_config_read_address, nw_config_write_address)
+#define NW_CONFIG_OPTION_ADDRESS(config, key, value) \
+       nw_config_option_add(config, key, value, nw_config_read_address, nw_config_write_address)
 
-int nw_config_read_address(nw_config* config, const char* key, void* data);
-int nw_config_write_address(nw_config* config, const char* key, const void* data);
+int nw_config_read_address(nw_config* config, const char* key, void* value);
+int nw_config_write_address(nw_config* config, const char* key, const void* value);
 
 #endif /* NETWORKD_CONFIG_H */