const char* key;
void* value;
+ size_t length;
// 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->value, option->data);
+ r = option->read_callback(config,
+ option->key, option->value, option->length, option->data);
if (r < 0)
return r;
}
int r;
STAILQ_FOREACH(option, &config->options, nodes) {
- r = option->write_callback(config, option->key, option->value, option->data);
+ r = option->write_callback(config,
+ option->key, option->value, option->length, option->data);
if (r < 0)
return r;
}
return 0;
}
-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) {
// Check input
// Set value
option->value = value;
+ option->length = length;
// Set callbacks
option->read_callback = read_callback;
return 0;
}
-int nw_config_read_int(nw_config* config, const char* key, void* value, void* data) {
+int nw_config_read_int(nw_config* config,
+ const char* key, void* value, const size_t length, void* data) {
// Fetch the value
*(int*)value = nw_config_get_int(config, key, -1);
}
int nw_config_write_int(nw_config* config,
- const char* key, const void* value, void* data) {
+ const char* key, const void* value, const size_t length, void* data) {
return 0;
}
// String
-int nw_config_read_string(nw_config* config, const char* key, void* value, void* data) {
+int nw_config_read_string(nw_config* config,
+ const char* key, void* value, const size_t length, void* data) {
// Fetch the value
const char* p = nw_config_get(config, key);
if (p)
}
int nw_config_write_string(nw_config* config,
- const char* key, const void* value, void* data) {
+ const char* key, const void* value, const size_t length, void* data) {
return nw_config_set(config, key, *(const char**)value);
}
+// String Buffer
+
+int nw_config_read_string_buffer(nw_config* config,
+ const char* key, void* value, const size_t length, void* data) {
+ char* string = (char*)value;
+
+ // Fetch the value
+ const char* p = nw_config_get(config, key);
+ if (p)
+ return __nw_string_set(string, length, p);
+
+ return 0;
+}
+
// String Table
-int nw_config_read_string_table(nw_config* config, const char* key, void* value, void* data) {
+int nw_config_read_string_table(nw_config* config,
+ const char* key, void* value, const size_t length, void* data) {
const char* s = NULL;
int* v = (int*)value;
}
int nw_config_write_string_table(nw_config* config,
- const char* key, const void* value, void* data) {
+ const char* key, const void* value, const size_t length, void* data) {
int* v = (int*)value;
const nw_string_table_t* table = (nw_string_table_t*)data;
// Address
-int nw_config_read_address(nw_config* config, const char* key, void* value, void* data) {
+int nw_config_read_address(nw_config* config,
+ const char* key, void* value, const size_t length, void* data) {
nw_address_t* address = (nw_address_t*)value;
int r;
}
int nw_config_write_address(nw_config* config,
- const char* key, const void* value, void* data) {
+ const char* key, const void* value, const size_t length, void* data) {
const nw_address_t* address = (nw_address_t*)value;
int r;
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 */