filter-chain: report more parsing errors

This commit is contained in:
Wim Taymans 2024-03-28 09:16:15 +01:00
parent 66b8cd3e32
commit 6d4f255ae9
2 changed files with 30 additions and 14 deletions

View file

@ -23,6 +23,7 @@
#include <spa/param/tag-utils.h> #include <spa/param/tag-utils.h>
#include <spa/pod/dynamic.h> #include <spa/pod/dynamic.h>
#include <spa/debug/types.h> #include <spa/debug/types.h>
#include <spa/debug/log.h>
#include <pipewire/utils.h> #include <pipewire/utils.h>
#include <pipewire/impl.h> #include <pipewire/impl.h>
@ -1872,24 +1873,35 @@ exit:
*/ */
static int parse_config(struct node *node, struct spa_json *config) static int parse_config(struct node *node, struct spa_json *config)
{ {
const char *val; const char *val, *s = config->cur;
int len; int res = 0, len;
struct spa_error_location loc;
if ((len = spa_json_next(config, &val)) <= 0)
return len;
if ((len = spa_json_next(config, &val)) <= 0) {
res = -EINVAL;
goto done;
}
if (spa_json_is_null(val, len)) if (spa_json_is_null(val, len))
return 0; goto done;
if (spa_json_is_container(val, len)) if (spa_json_is_container(val, len)) {
len = spa_json_container_len(config, val, len); len = spa_json_container_len(config, val, len);
if (len == 0) {
if ((node->config = malloc(len+1)) == NULL) res = -EINVAL;
return -errno; goto done;
}
}
if ((node->config = malloc(len+1)) == NULL) {
res = -errno;
goto done;
}
spa_json_parse_stringn(val, len, node->config, len+1); spa_json_parse_stringn(val, len, node->config, len+1);
done:
return 0; if (spa_json_get_error(config, s, &loc))
spa_debug_log_error_location(pw_log_get(), SPA_LOG_LEVEL_WARN,
&loc, "error: %s", loc.reason);
return res;
} }
/** /**

View file

@ -42,12 +42,16 @@ static void * spatializer_instantiate(const struct fc_descriptor * Descriptor,
char filename[PATH_MAX] = ""; char filename[PATH_MAX] = "";
errno = EINVAL; errno = EINVAL;
if (config == NULL) if (config == NULL) {
pw_log_error("spatializer: no config was given");
return NULL; return NULL;
}
spa_json_init(&it[0], config, strlen(config)); spa_json_init(&it[0], config, strlen(config));
if (spa_json_enter_object(&it[0], &it[1]) <= 0) if (spa_json_enter_object(&it[0], &it[1]) <= 0) {
pw_log_error("spatializer: expected object in config");
return NULL; return NULL;
}
impl = calloc(1, sizeof(*impl)); impl = calloc(1, sizeof(*impl));
if (impl == NULL) { if (impl == NULL) {