command: fix access to "metadata/list" property

The function tag_property() in command.c passed a key action with empty
path to m_property_read_list. This is normally not valid, because key
actions are supposed to access sub-paths. But it's kind of inconvenient
to check for this case in tag_property(). So make it valid by providing
a m_property_unkey() function, which turns a key access to "" into a
top-level action.
This commit is contained in:
wm4 2014-03-30 13:50:23 +02:00
parent 5cd20c7320
commit 01f3e46290
1 changed files with 14 additions and 0 deletions

View File

@ -246,6 +246,19 @@ bool m_property_split_path(const char *path, bstr *prefix, char **rem)
}
}
// If *action is M_PROPERTY_KEY_ACTION, but the associated path is "", then
// make this into a top-level action.
static void m_property_unkey(int *action, void **arg)
{
if (*action == M_PROPERTY_KEY_ACTION) {
struct m_property_action_arg *ka = *arg;
if (!ka->key[0]) {
*action = ka->action;
*arg = ka->arg;
}
}
}
static int m_property_do_bstr(const m_option_t *prop_list, bstr name,
int action, void *arg, void *ctx)
{
@ -524,6 +537,7 @@ int m_property_read_sub(const struct m_sub_property *props, int action, void *ar
int m_property_read_list(int action, void *arg, int count,
m_get_item_cb get_item, void *ctx)
{
m_property_unkey(&action, &arg);
switch (action) {
case M_PROPERTY_GET_TYPE:
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_NODE};