network: rename NetworkConfigSection -> ConfigSection

And move it and relevant functions to conf-parser.[ch].
This commit is contained in:
Yu Watanabe
2022-01-19 14:57:59 +09:00
parent e5c4289a9d
commit 307fe3cdf2
36 changed files with 196 additions and 196 deletions
+44
View File
@@ -573,6 +573,50 @@ int config_parse_many(
return config_parse_many_files(conf_files, files, sections, lookup, table, flags, userdata, ret_stats_by_path);
}
static void config_section_hash_func(const ConfigSection *c, struct siphash *state) {
siphash24_compress_string(c->filename, state);
siphash24_compress(&c->line, sizeof(c->line), state);
}
static int config_section_compare_func(const ConfigSection *x, const ConfigSection *y) {
int r;
r = strcmp(x->filename, y->filename);
if (r != 0)
return r;
return CMP(x->line, y->line);
}
DEFINE_HASH_OPS(config_section_hash_ops, ConfigSection, config_section_hash_func, config_section_compare_func);
int config_section_new(const char *filename, unsigned line, ConfigSection **s) {
ConfigSection *cs;
cs = malloc0(offsetof(ConfigSection, filename) + strlen(filename) + 1);
if (!cs)
return -ENOMEM;
strcpy(cs->filename, filename);
cs->line = line;
*s = TAKE_PTR(cs);
return 0;
}
unsigned hashmap_find_free_section_line(Hashmap *hashmap) {
ConfigSection *cs;
unsigned n = 0;
void *entry;
HASHMAP_FOREACH_KEY(entry, cs, hashmap)
if (n < cs->line)
n = cs->line;
return n + 1;
}
#define DEFINE_PARSER(type, vartype, conv_func) \
DEFINE_CONFIG_PARSE_PTR(config_parse_##type, conv_func, vartype, "Failed to parse " #type " value")