forked from external/yambar
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:
parent
e471c2357d
commit
9944a8f972
13 changed files with 146 additions and 56 deletions
|
@ -341,8 +341,10 @@ verify_module(keychain_t *chain, const struct yml_node *node)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(info->verify_conf != NULL);
|
||||||
|
|
||||||
chain_push(chain, mod_name);
|
chain_push(chain, mod_name);
|
||||||
if (!conf_verify_dict(chain, values, info->attrs))
|
if (!info->verify_conf(chain, values))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
chain_pop(chain);
|
chain_pop(chain);
|
||||||
|
|
2
module.h
2
module.h
|
@ -12,9 +12,9 @@ struct bar;
|
||||||
struct module;
|
struct module;
|
||||||
|
|
||||||
struct module_info {
|
struct module_info {
|
||||||
|
bool (*verify_conf)(keychain_t *chain, const struct yml_node *node);
|
||||||
struct module *(*from_conf)(const struct yml_node *node,
|
struct module *(*from_conf)(const struct yml_node *node,
|
||||||
const struct font *parent_font);
|
const struct font *parent_font);
|
||||||
const struct attr_info attrs[];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct module_run_context {
|
struct module_run_context {
|
||||||
|
|
|
@ -280,13 +280,21 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
|
||||||
conf_to_particle(content, parent_font));
|
conf_to_particle(content, parent_font));
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
static bool
|
||||||
.from_conf = &from_conf,
|
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||||
.attrs = {
|
{
|
||||||
|
static const struct attr_info attrs[] = {
|
||||||
{"card", true, &conf_verify_string},
|
{"card", true, &conf_verify_string},
|
||||||
{"mixer", true, &conf_verify_string},
|
{"mixer", true, &conf_verify_string},
|
||||||
{"content", true, &conf_verify_particle},
|
{"content", true, &conf_verify_particle},
|
||||||
{"anchors", false, NULL},
|
{"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,
|
||||||
};
|
};
|
||||||
|
|
|
@ -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));
|
yml_value_as_string(name), conf_to_particle(c, parent_font));
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
static bool
|
||||||
.from_conf = &from_conf,
|
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||||
.attrs = {
|
{
|
||||||
|
static const struct attr_info attrs[] = {
|
||||||
{"name", true, &conf_verify_string},
|
{"name", true, &conf_verify_string},
|
||||||
{"content", true, &conf_verify_particle},
|
{"content", true, &conf_verify_particle},
|
||||||
{"anchors", false, NULL},
|
{"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,
|
||||||
};
|
};
|
||||||
|
|
|
@ -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);
|
poll_interval != NULL ? yml_value_as_int(poll_interval) : 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
static bool
|
||||||
.from_conf = &from_conf,
|
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||||
.attrs = {
|
{
|
||||||
|
static const struct attr_info attrs[] = {
|
||||||
{"name", true, &conf_verify_string},
|
{"name", true, &conf_verify_string},
|
||||||
{"poll-interval", false, &conf_verify_int},
|
{"poll-interval", false, &conf_verify_int},
|
||||||
{"content", true, &conf_verify_particle},
|
{"content", true, &conf_verify_particle},
|
||||||
{"anchors", false, NULL},
|
{"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,
|
||||||
};
|
};
|
||||||
|
|
|
@ -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");
|
time_format != NULL ? yml_value_as_string(time_format) : "%H:%M");
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
static bool
|
||||||
.from_conf = &from_conf,
|
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||||
.attrs = {
|
{
|
||||||
|
static const struct attr_info attrs[] = {
|
||||||
{"date-format", false, &conf_verify_string},
|
{"date-format", false, &conf_verify_string},
|
||||||
{"time-format", false, &conf_verify_string},
|
{"time-format", false, &conf_verify_string},
|
||||||
{"content", true, &conf_verify_particle},
|
{"content", true, &conf_verify_particle},
|
||||||
{"anchors", false, NULL},
|
{"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,
|
||||||
};
|
};
|
||||||
|
|
18
modules/i3.c
18
modules/i3.c
|
@ -701,14 +701,22 @@ verify_content(keychain_t *chain, const struct yml_node *node)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
static bool
|
||||||
.from_conf = &from_conf,
|
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||||
.attrs = {
|
{
|
||||||
|
static const struct attr_info attrs[] = {
|
||||||
{"spacing", false, &conf_verify_int},
|
{"spacing", false, &conf_verify_int},
|
||||||
{"left-spacing", false, &conf_verify_int},
|
{"left-spacing", false, &conf_verify_int},
|
||||||
{"right-spacing", false, &conf_verify_int},
|
{"right-spacing", false, &conf_verify_int},
|
||||||
{"content", true, &verify_content},
|
{"content", true, &verify_content},
|
||||||
{"anchors", false, NULL},
|
{"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,
|
||||||
};
|
};
|
||||||
|
|
|
@ -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));
|
return label_new(conf_to_particle(c, parent_font));
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
static bool
|
||||||
.from_conf = &from_conf,
|
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||||
.attrs = {
|
{
|
||||||
|
static const struct attr_info attrs[] = {
|
||||||
{"content", true, &conf_verify_particle},
|
{"content", true, &conf_verify_particle},
|
||||||
{"anchors", false, NULL},
|
{"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,
|
||||||
};
|
};
|
||||||
|
|
|
@ -491,13 +491,21 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
|
||||||
conf_to_particle(c, parent_font));
|
conf_to_particle(c, parent_font));
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
static bool
|
||||||
.from_conf = &from_conf,
|
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||||
.attrs = {
|
{
|
||||||
|
static const struct attr_info attrs[] = {
|
||||||
{"host", true, &conf_verify_string},
|
{"host", true, &conf_verify_string},
|
||||||
{"port", false, &conf_verify_int},
|
{"port", false, &conf_verify_int},
|
||||||
{"content", true, &conf_verify_particle},
|
{"content", true, &conf_verify_particle},
|
||||||
{"anchors", false, NULL},
|
{"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,
|
||||||
};
|
};
|
||||||
|
|
|
@ -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));
|
yml_value_as_string(name), conf_to_particle(content, parent_font));
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
static bool
|
||||||
.from_conf = &from_conf,
|
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||||
.attrs = {
|
{
|
||||||
|
static const struct attr_info attrs[] = {
|
||||||
{"name", true, &conf_verify_string},
|
{"name", true, &conf_verify_string},
|
||||||
{"content", true, &conf_verify_particle},
|
{"content", true, &conf_verify_particle},
|
||||||
{"anchors", false, NULL},
|
{"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,
|
||||||
};
|
};
|
||||||
|
|
|
@ -577,14 +577,22 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
|
||||||
conf_to_particle(content, parent_font), left, right);
|
conf_to_particle(content, parent_font), left, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
static bool
|
||||||
.from_conf = &from_conf,
|
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||||
.attrs = {
|
{
|
||||||
|
static const struct attr_info attrs[] = {
|
||||||
{"spacing", false, &conf_verify_int},
|
{"spacing", false, &conf_verify_int},
|
||||||
{"left-spacing", false, &conf_verify_int},
|
{"left-spacing", false, &conf_verify_int},
|
||||||
{"right-spacing", false, &conf_verify_int},
|
{"right-spacing", false, &conf_verify_int},
|
||||||
{"content", true, &conf_verify_particle},
|
{"content", true, &conf_verify_particle},
|
||||||
{"anchors", false, NULL},
|
{"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,
|
||||||
};
|
};
|
||||||
|
|
|
@ -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));
|
return xkb_new(conf_to_particle(c, parent_font));
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
static bool
|
||||||
.from_conf = &from_conf,
|
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||||
.attrs = {
|
{
|
||||||
|
static const struct attr_info attrs[] = {
|
||||||
{"content", true, &conf_verify_particle},
|
{"content", true, &conf_verify_particle},
|
||||||
{"anchors", false, NULL},
|
{"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,
|
||||||
};
|
};
|
||||||
|
|
|
@ -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));
|
return xwindow_new(conf_to_particle(c, parent_font));
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
static bool
|
||||||
.from_conf = &from_conf,
|
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||||
.attrs = {
|
{
|
||||||
|
static const struct attr_info attrs[] = {
|
||||||
{"content", true, &conf_verify_particle},
|
{"content", true, &conf_verify_particle},
|
||||||
{"anchors", false, NULL},
|
{"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,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue