mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
pulse-server: add an option to check module arguments
Add a list of valid keys to the module info. When set, check if the module arguments only contain the allowed keys and give an error otherwise.
This commit is contained in:
parent
b094057b0b
commit
3c812f672b
4 changed files with 61 additions and 9 deletions
|
|
@ -164,6 +164,28 @@ void module_args_add_props(struct pw_properties *props, const char *str)
|
|||
}
|
||||
}
|
||||
|
||||
static bool find_key(const char * const keys[], const char *key)
|
||||
{
|
||||
for (int i = 0; keys[i] != NULL; i++)
|
||||
if (spa_streq(keys[i], key))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int module_args_check(struct pw_properties *props, const char * const valid_args[])
|
||||
{
|
||||
if (valid_args != NULL) {
|
||||
const struct spa_dict_item *it;
|
||||
spa_dict_for_each(it, &props->dict) {
|
||||
if (!find_key(valid_args, it->key)) {
|
||||
pw_log_warn("'%s' is not a valid module argument key", it->key);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int module_args_to_audioinfo_keys(struct impl *impl, struct pw_properties *props,
|
||||
const char *key_format, const char *key_rate,
|
||||
const char *key_channels, const char *key_channel_map,
|
||||
|
|
@ -299,6 +321,7 @@ struct module *module_create(struct impl *impl, const char *name, const char *ar
|
|||
{
|
||||
const struct module_info *info;
|
||||
struct module *module;
|
||||
int res;
|
||||
|
||||
info = find_module_info(name);
|
||||
if (info == NULL) {
|
||||
|
|
@ -321,19 +344,19 @@ struct module *module_create(struct impl *impl, const char *name, const char *ar
|
|||
return NULL;
|
||||
|
||||
module->props = pw_properties_new(NULL, NULL);
|
||||
if (module->props == NULL) {
|
||||
module_free(module);
|
||||
return NULL;
|
||||
}
|
||||
if (module->props == NULL)
|
||||
goto error_free;
|
||||
|
||||
if (args)
|
||||
module_args_add_props(module->props, args);
|
||||
|
||||
int res = module->info->prepare(module);
|
||||
if (res < 0) {
|
||||
module_free(module);
|
||||
if ((res = module_args_check(module->props, info->valid_args)) < 0) {
|
||||
errno = -res;
|
||||
return NULL;
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
if ((res = module->info->prepare(module)) < 0) {
|
||||
errno = -res;
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
module->index = pw_map_insert_new(&impl->modules, module);
|
||||
|
|
@ -346,4 +369,9 @@ struct module *module_create(struct impl *impl, const char *name, const char *ar
|
|||
module->index |= MODULE_FLAG;
|
||||
|
||||
return module;
|
||||
|
||||
error_free:
|
||||
module_free(module);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ struct module_info {
|
|||
int (*load) (struct module *module);
|
||||
int (*unload) (struct module *module);
|
||||
|
||||
const char* const *valid_args;
|
||||
const struct spa_dict *properties;
|
||||
size_t data_size;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -89,6 +89,15 @@ static int module_roc_sink_unload(struct module *module)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static const char* const valid_args[] = {
|
||||
"sink_name",
|
||||
"sink_properties",
|
||||
"fec_code",
|
||||
"remote_ip",
|
||||
"remote_source_port",
|
||||
"remote_repair_port",
|
||||
NULL
|
||||
};
|
||||
static const struct spa_dict_item module_roc_sink_info[] = {
|
||||
{ PW_KEY_MODULE_AUTHOR, "Sanchayan Maity <sanchayan@asymptotic.io>" },
|
||||
{ PW_KEY_MODULE_DESCRIPTION, "roc sink" },
|
||||
|
|
@ -169,6 +178,7 @@ out:
|
|||
|
||||
DEFINE_MODULE_INFO(module_roc_sink) = {
|
||||
.name = "module-roc-sink",
|
||||
.valid_args = valid_args,
|
||||
.prepare = module_roc_sink_prepare,
|
||||
.load = module_roc_sink_load,
|
||||
.unload = module_roc_sink_unload,
|
||||
|
|
|
|||
|
|
@ -89,6 +89,18 @@ static int module_roc_source_unload(struct module *module)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static const char* const valid_args[] = {
|
||||
"source_name",
|
||||
"source_properties",
|
||||
"resampler_profile",
|
||||
"fec_code",
|
||||
"sess_latency_msec",
|
||||
"local_ip",
|
||||
"local_source_port",
|
||||
"local_repair_port",
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct spa_dict_item module_roc_source_info[] = {
|
||||
{ PW_KEY_MODULE_AUTHOR, "Sanchayan Maity <sanchayan@asymptotic.io>" },
|
||||
{ PW_KEY_MODULE_DESCRIPTION, "roc source" },
|
||||
|
|
@ -178,6 +190,7 @@ out:
|
|||
|
||||
DEFINE_MODULE_INFO(module_roc_source) = {
|
||||
.name = "module-roc-source",
|
||||
.valid_args = valid_args,
|
||||
.prepare = module_roc_source_prepare,
|
||||
.load = module_roc_source_load,
|
||||
.unload = module_roc_source_unload,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue