]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/networkd/config.c
config: Implement option that looks up string tables
[people/ms/network.git] / src / networkd / config.c
index 39e98818dcf740db9b14ad0a23773931297ba60e..ee5e8b832a748db7d0cf3e012139991aa23bf8c3 100644 (file)
@@ -570,6 +570,43 @@ int nw_config_write_string(nw_config* config,
        return nw_config_set(config, key, *(const char**)value);
 }
 
+// String Table
+
+int nw_config_read_string_table(nw_config* config, const char* key, void* value, void* data) {
+       const char* s = NULL;
+       int* v = (int*)value;
+
+       const nw_string_table_t* table = (nw_string_table_t*)data;
+
+       // Fetch the string
+       s = nw_config_get(config, key);
+       if (!s)
+               return -errno;
+
+       // Lookup the string in the table
+       *v = nw_string_table_lookup_id(table, s);
+
+       // If the result is negative, nothing was found
+       if (*v < 0)
+               return -EINVAL;
+
+       return 0;
+}
+
+int nw_config_write_string_table(nw_config* config,
+               const char* key, const void* value, void* data) {
+       int* v = (int*)value;
+
+       const nw_string_table_t* table = (nw_string_table_t*)data;
+
+       // Lookup the string
+       const char* s = nw_string_table_lookup_string(table, *v);
+       if (!s)
+               return -errno;
+
+       return nw_config_set(config, key, s);
+}
+
 // Address
 
 int nw_config_read_address(nw_config* config, const char* key, void* value, void* data) {