modules: don't assume module content is a dictionary

This is done by having each module implement a top-level verifier
function.
This commit is contained in:
Daniel Eklöf 2019-01-13 11:54:03 +01:00
parent e471c2357d
commit 9944a8f972
13 changed files with 146 additions and 56 deletions

View file

@ -341,8 +341,10 @@ verify_module(keychain_t *chain, const struct yml_node *node)
return false;
}
assert(info->verify_conf != NULL);
chain_push(chain, mod_name);
if (!conf_verify_dict(chain, values, info->attrs))
if (!info->verify_conf(chain, values))
return false;
chain_pop(chain);

View file

@ -12,9 +12,9 @@ struct bar;
struct module;
struct module_info {
bool (*verify_conf)(keychain_t *chain, const struct yml_node *node);
struct module *(*from_conf)(const struct yml_node *node,
const struct font *parent_font);
const struct attr_info attrs[];
};
struct module_run_context {

View file

@ -280,13 +280,21 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
conf_to_particle(content, parent_font));
}
const struct module_info plugin_info = {
.from_conf = &from_conf,
.attrs = {
static bool
verify_conf(keychain_t *chain, const struct yml_node *node)
{
static const struct attr_info attrs[] = {
{"card", true, &conf_verify_string},
{"mixer", true, &conf_verify_string},
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
{NULL, false, NULL}
},
};
return conf_verify_dict(chain, node, attrs);
}
const struct module_info plugin_info = {
.verify_conf = &verify_conf,
.from_conf = &from_conf,
};

View file

@ -224,12 +224,20 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
yml_value_as_string(name), conf_to_particle(c, parent_font));
}
const struct module_info plugin_info = {
.from_conf = &from_conf,
.attrs = {
static bool
verify_conf(keychain_t *chain, const struct yml_node *node)
{
static const struct attr_info attrs[] = {
{"name", true, &conf_verify_string},
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
{NULL, false, NULL},
},
{NULL, false, NULL}
};
return conf_verify_dict(chain, node, attrs);
}
const struct module_info plugin_info = {
.verify_conf = &verify_conf,
.from_conf = &from_conf,
};

View file

@ -356,13 +356,21 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
poll_interval != NULL ? yml_value_as_int(poll_interval) : 60);
}
const struct module_info plugin_info = {
.from_conf = &from_conf,
.attrs = {
static bool
verify_conf(keychain_t *chain, const struct yml_node *node)
{
static const struct attr_info attrs[] = {
{"name", true, &conf_verify_string},
{"poll-interval", false, &conf_verify_int},
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
{NULL, false, NULL},
},
{NULL, false, NULL}
};
return conf_verify_dict(chain, node, attrs);
}
const struct module_info plugin_info = {
.verify_conf = &verify_conf,
.from_conf = &from_conf,
};

View file

@ -107,13 +107,21 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
time_format != NULL ? yml_value_as_string(time_format) : "%H:%M");
}
const struct module_info plugin_info = {
.from_conf = &from_conf,
.attrs = {
static bool
verify_conf(keychain_t *chain, const struct yml_node *node)
{
static const struct attr_info attrs[] = {
{"date-format", false, &conf_verify_string},
{"time-format", false, &conf_verify_string},
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
{NULL, false, NULL},
},
{NULL, false, NULL}
};
return conf_verify_dict(chain, node, attrs);
}
const struct module_info plugin_info = {
.verify_conf = &verify_conf,
.from_conf = &from_conf,
};

View file

@ -701,14 +701,22 @@ verify_content(keychain_t *chain, const struct yml_node *node)
return true;
}
const struct module_info plugin_info = {
.from_conf = &from_conf,
.attrs = {
static bool
verify_conf(keychain_t *chain, const struct yml_node *node)
{
static const struct attr_info attrs[] = {
{"spacing", false, &conf_verify_int},
{"left-spacing", false, &conf_verify_int},
{"right-spacing", false, &conf_verify_int},
{"content", true, &verify_content},
{"anchors", false, NULL},
{NULL, false, NULL},
},
{NULL, false, NULL}
};
return conf_verify_dict(chain, node, attrs);
}
const struct module_info plugin_info = {
.verify_conf = &verify_conf,
.from_conf = &from_conf,
};

View file

@ -53,11 +53,19 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
return label_new(conf_to_particle(c, parent_font));
}
const struct module_info plugin_info = {
.from_conf = &from_conf,
.attrs = {
static bool
verify_conf(keychain_t *chain, const struct yml_node *node)
{
static const struct attr_info attrs[] = {
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
{NULL, false, NULL},
},
{NULL, false, NULL}
};
return conf_verify_dict(chain, node, attrs);
}
const struct module_info plugin_info = {
.verify_conf = &verify_conf,
.from_conf = &from_conf,
};

View file

@ -491,13 +491,21 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
conf_to_particle(c, parent_font));
}
const struct module_info plugin_info = {
.from_conf = &from_conf,
.attrs = {
static bool
verify_conf(keychain_t *chain, const struct yml_node *node)
{
static const struct attr_info attrs[] = {
{"host", true, &conf_verify_string},
{"port", false, &conf_verify_int},
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
{NULL, false, NULL},
},
{NULL, false, NULL}
};
return conf_verify_dict(chain, node, attrs);
}
const struct module_info plugin_info = {
.verify_conf = &verify_conf,
.from_conf = &from_conf,
};

View file

@ -543,12 +543,20 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
yml_value_as_string(name), conf_to_particle(content, parent_font));
}
const struct module_info plugin_info = {
.from_conf = &from_conf,
.attrs = {
static bool
verify_conf(keychain_t *chain, const struct yml_node *node)
{
static const struct attr_info attrs[] = {
{"name", true, &conf_verify_string},
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
{NULL, false, NULL},
},
{NULL, false, NULL}
};
return conf_verify_dict(chain, node, attrs);
}
const struct module_info plugin_info = {
.verify_conf = &verify_conf,
.from_conf = &from_conf,
};

View file

@ -577,14 +577,22 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
conf_to_particle(content, parent_font), left, right);
}
const struct module_info plugin_info = {
.from_conf = &from_conf,
.attrs = {
static bool
verify_conf(keychain_t *chain, const struct yml_node *node)
{
static const struct attr_info attrs[] = {
{"spacing", false, &conf_verify_int},
{"left-spacing", false, &conf_verify_int},
{"right-spacing", false, &conf_verify_int},
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
{NULL, false, NULL},
},
{NULL, false, NULL}
};
return conf_verify_dict(chain, node, attrs);
}
const struct module_info plugin_info = {
.verify_conf = &verify_conf,
.from_conf = &from_conf,
};

View file

@ -459,11 +459,19 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
return xkb_new(conf_to_particle(c, parent_font));
}
const struct module_info plugin_info = {
.from_conf = &from_conf,
.attrs = {
static bool
verify_conf(keychain_t *chain, const struct yml_node *node)
{
static const struct attr_info attrs[] = {
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
{NULL, false, NULL},
},
{NULL, false, NULL}
};
return conf_verify_dict(chain, node, attrs);
}
const struct module_info plugin_info = {
.verify_conf = &verify_conf,
.from_conf = &from_conf,
};

View file

@ -321,11 +321,19 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
return xwindow_new(conf_to_particle(c, parent_font));
}
const struct module_info plugin_info = {
.from_conf = &from_conf,
.attrs = {
static bool
verify_conf(keychain_t *chain, const struct yml_node *node)
{
static const struct attr_info attrs[] = {
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
{NULL, false, NULL},
},
{NULL, false, NULL}
};
return conf_verify_dict(chain, node, attrs);
}
const struct module_info plugin_info = {
.verify_conf = &verify_conf,
.from_conf = &from_conf,
};