]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/networkd/config.c
config: Rename "data" to "value" as it holds a reference to it
[people/ms/network.git] / src / networkd / config.c
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;
 }