mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-08 13:30:08 -05: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
|
|
@ -286,18 +286,15 @@ static int do_discover(struct adp *adp, const char *args, FILE *out)
|
|||
struct spa_json it[1];
|
||||
char key[128];
|
||||
uint64_t entity_id = 0ULL;
|
||||
int len;
|
||||
const char *value;
|
||||
|
||||
if (spa_json_begin_object(&it[0], args, strlen(args)) <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) {
|
||||
int len;
|
||||
const char *value;
|
||||
while ((len = spa_json_object_next(&it[0], key, sizeof(key), &value)) > 0) {
|
||||
uint64_t id_val;
|
||||
|
||||
if ((len = spa_json_next(&it[0], &value)) <= 0)
|
||||
break;
|
||||
|
||||
if (spa_json_is_null(value, len))
|
||||
continue;
|
||||
|
||||
|
|
|
|||
|
|
@ -255,7 +255,8 @@ static int load_state(struct maap *maap)
|
|||
char key[512];
|
||||
struct spa_json it[2];
|
||||
bool have_offset = false;
|
||||
int count = 0, offset = 0;
|
||||
int count = 0, offset = 0, len;
|
||||
const char *val;
|
||||
|
||||
snprintf(key, sizeof(key), "maap.%s", maap->server->ifname);
|
||||
pw_conf_load_state("module-avb", key, maap->props);
|
||||
|
|
@ -269,13 +270,7 @@ static int load_state(struct maap *maap)
|
|||
if (spa_json_enter_object(&it[0], &it[1]) <= 0)
|
||||
return 0;
|
||||
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
const char *val;
|
||||
int len;
|
||||
|
||||
if ((len = spa_json_next(&it[1], &val)) <= 0)
|
||||
break;
|
||||
|
||||
while ((len = spa_json_object_next(&it[1], key, sizeof(key), &val)) > 0) {
|
||||
if (spa_streq(key, "start")) {
|
||||
uint8_t addr[6];
|
||||
if (avb_utils_parse_addr(val, len, addr) >= 0 &&
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue