mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
spa: add spa_json_object_next
This gets the next key and value from an object. This function is better because it will skip key/value pairs that don't fit in the array to hold the key. The previous code patter would stop parsing the object as soon as a key larger than the available space was found.
This commit is contained in:
parent
cd81b5f39a
commit
ce390d5b22
24 changed files with 171 additions and 269 deletions
|
|
@ -1023,20 +1023,15 @@ static int json_object_find(const char *obj, const char *key, char *value, size_
|
|||
{
|
||||
struct spa_json it[1];
|
||||
const char *v;
|
||||
char k[128];
|
||||
int l, kl = strlen(key) + 3;
|
||||
char k[kl];
|
||||
|
||||
if (spa_json_begin_object(&it[0], obj, strlen(obj)) <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
while (spa_json_get_string(&it[0], k, sizeof(k)) > 0) {
|
||||
if (spa_streq(k, key)) {
|
||||
if (spa_json_get_string(&it[1], value, len) <= 0)
|
||||
continue;
|
||||
return 0;
|
||||
} else {
|
||||
if (spa_json_next(&it[1], &v) <= 0)
|
||||
break;
|
||||
}
|
||||
while ((l = spa_json_object_next(&it[0], k, kl, &v)) > 0) {
|
||||
if (spa_streq(k, key))
|
||||
return spa_json_parse_stringn(v, l, value, len);
|
||||
}
|
||||
return -ENOENT;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1140,9 +1140,7 @@ static int parse_value(const char *str, struct param_info *info)
|
|||
info->type = TYPE_MIN_MAX;
|
||||
info->n_vals = 2;
|
||||
spa_json_enter(&it[0], &it[1]);
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
if ((len = spa_json_next(&it[1], &val)) <= 0)
|
||||
break;
|
||||
while ((len = spa_json_object_next(&it[1], key, sizeof(key), &val)) > 0) {
|
||||
if (info->collect(val, len, &v) < 0)
|
||||
continue;
|
||||
if (spa_streq(key, "min"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue