spa: add spa_json_begin_array/object and relaxed versions

Add spa_json_begin_array/object to replace
spa_json_init+spa_json_begin_array/object

This function is better because it does not waste a useless spa_json
structure as an iterator. The relaxed versions also error out when the
container is mismatched because parsing a mismatched container is not
going to give any results anyway.
This commit is contained in:
Wim Taymans 2024-09-13 13:09:54 +02:00
parent feccb882b6
commit cd81b5f39a
51 changed files with 401 additions and 452 deletions

View file

@ -152,7 +152,7 @@ int pw_protocol_native_connect_local_socket(struct pw_protocol_client *client,
void *data)
{
const char *name;
struct spa_json it[2];
struct spa_json it[1];
char path[PATH_MAX];
int res = -EINVAL;
@ -160,12 +160,10 @@ int pw_protocol_native_connect_local_socket(struct pw_protocol_client *client,
if (name == NULL)
return -EINVAL;
spa_json_init(&it[0], name, strlen(name));
if (spa_json_enter_array(&it[0], &it[1]) < 0)
if (spa_json_begin_array(&it[0], name, strlen(name)) <= 0)
return try_connect_name(client, name, done_callback, data);
while (spa_json_get_string(&it[1], path, sizeof(path)) > 0) {
while (spa_json_get_string(&it[0], path, sizeof(path)) > 0) {
res = try_connect_name(client, path, done_callback, data);
if (res < 0)
continue;