STAILQ_ENTRY(nw_config_option) nodes;
const char* key;
- void* data;
+ void* value;
// Callbacks
nw_config_option_read_callback_t read_callback;
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;
}
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;
}
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
// Set key
option->key = key;
- // Set data
- option->data = data;
+ // Set value
+ option->value = value;
// Set callbacks
option->read_callback = read_callback;
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;
r = 0;
ERROR:
- if (value)
- free(value);
+ if (p)
+ free(p);
return r;
}