mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-06-30 13:14:16 -04:00
pulse-server: improve module argument checking
Make the module valid_args a structure that includes the argument key, description and some flags. Use this to enforce mandatory properties in a more central place. We should be able to generate the module usage from this as wel later to have things a bit more structured.
This commit is contained in:
parent
a5a3eaf2cb
commit
e5ff44910e
9 changed files with 122 additions and 68 deletions
|
|
@ -170,15 +170,15 @@ void module_args_add_props(struct pw_properties *props, const char *str)
|
|||
}
|
||||
}
|
||||
|
||||
static bool find_key(const char * const keys[], const char *key)
|
||||
static bool find_key(const struct module_args args[], const char *key)
|
||||
{
|
||||
for (int i = 0; keys[i] != NULL; i++)
|
||||
if (spa_streq(keys[i], key))
|
||||
for (int i = 0; args[i].key != NULL; i++)
|
||||
if (spa_streq(args[i].key, key))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int module_args_check(struct pw_properties *props, const char * const valid_args[])
|
||||
static int module_args_check(struct pw_properties *props, const struct module_args valid_args[])
|
||||
{
|
||||
if (valid_args != NULL) {
|
||||
const struct spa_dict_item *it;
|
||||
|
|
@ -188,6 +188,13 @@ static int module_args_check(struct pw_properties *props, const char * const val
|
|||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; valid_args[i].key != NULL; i++)
|
||||
if (SPA_FLAG_IS_SET(valid_args[i].flags, MODULE_ARG_MANDATORY) &&
|
||||
pw_properties_get(props, valid_args[i].key) == NULL) {
|
||||
pw_log_warn("missing mandatory module argument '%s'", valid_args[i].key);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue