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:
Wim Taymans 2024-09-13 16:26:36 +02:00
parent cd81b5f39a
commit ce390d5b22
24 changed files with 171 additions and 269 deletions

View file

@ -1825,20 +1825,21 @@ static int do_auto_port_config(struct impl *this, const char *str)
#define POSITION_PRESERVE 0
#define POSITION_AUX 1
#define POSITION_UNKNOWN 2
int res, position = POSITION_PRESERVE;
int l, res, position = POSITION_PRESERVE;
struct spa_pod *param;
bool have_format = false, monitor = false, control = false;
struct spa_audio_info format = { 0, };
enum spa_param_port_config_mode mode = SPA_PARAM_PORT_CONFIG_MODE_none;
struct spa_json it[1];
char key[1024], val[256];
const char *v;
if (spa_json_begin_object(&it[0], str, strlen(str)) <= 0)
return -EINVAL;
while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) {
if (spa_json_get_string(&it[0], val, sizeof(val)) <= 0)
break;
while ((l = spa_json_object_next(&it[0], key, sizeof(key), &v)) > 0) {
if (spa_json_parse_stringn(v, l, val, sizeof(val)) <= 0)
continue;
if (spa_streq(key, "mode")) {
mode = spa_debug_type_find_type_short(spa_type_param_port_config_mode, val);