diff --git a/pipewire-alsa/alsa-plugins/ctl_pipewire.c b/pipewire-alsa/alsa-plugins/ctl_pipewire.c index 76eed8461..0958308e8 100644 --- a/pipewire-alsa/alsa-plugins/ctl_pipewire.c +++ b/pipewire-alsa/alsa-plugins/ctl_pipewire.c @@ -1021,15 +1021,14 @@ static const struct global_info node_info = { /** metadata */ static int json_object_find(const char *obj, const char *key, char *value, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; const char *v; char k[128]; - spa_json_init(&it[0], obj, strlen(obj)); - if (spa_json_enter_object(&it[0], &it[1]) <= 0) + if (spa_json_begin_object(&it[0], obj, strlen(obj)) <= 0) return -EINVAL; - while (spa_json_get_string(&it[1], k, sizeof(k)) > 0) { + 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; diff --git a/pipewire-jack/src/pipewire-jack.c b/pipewire-jack/src/pipewire-jack.c index 881b0116b..28481e32e 100644 --- a/pipewire-jack/src/pipewire-jack.c +++ b/pipewire-jack/src/pipewire-jack.c @@ -3458,21 +3458,20 @@ static jack_uuid_t client_make_uuid(uint32_t id, bool monitor) static int json_object_find(const char *obj, const char *key, char *value, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; const char *v; char k[128]; - spa_json_init(&it[0], obj, strlen(obj)); - if (spa_json_enter_object(&it[0], &it[1]) <= 0) + if (spa_json_begin_object(&it[0], obj, strlen(obj)) <= 0) return -EINVAL; - while (spa_json_get_string(&it[1], k, sizeof(k)) > 0) { + 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) + if (spa_json_get_string(&it[0], value, len) <= 0) continue; return 0; } else { - if (spa_json_next(&it[1], &v) <= 0) + if (spa_json_next(&it[0], &v) <= 0) break; } } diff --git a/spa/include/spa/utils/json.h b/spa/include/spa/utils/json.h index 86b42806a..b2299f2e7 100644 --- a/spa/include/spa/utils/json.h +++ b/spa/include/spa/utils/json.h @@ -362,23 +362,37 @@ static inline int spa_json_begin(struct spa_json * iter, const char *data, size_ return spa_json_next(iter, val); } +static inline int spa_json_is_container(const char *val, int len) +{ + return len > 0 && (*val == '{' || *val == '['); +} + static inline int spa_json_enter_container(struct spa_json *iter, struct spa_json *sub, char type) { const char *value; int len; if ((len = spa_json_next(iter, &value)) <= 0) return len; + if (!spa_json_is_container(value, len)) + return -EPROTO; if (*value != type) - return -1; + return -EINVAL; spa_json_enter(iter, sub); return 1; } -static inline int spa_json_is_container(const char *val, int len) +static inline int spa_json_begin_container(struct spa_json * iter, + const char *data, size_t size, char type, bool relax) { - return len > 0 && (*val == '{' || *val == '['); + int res; + spa_json_init(iter, data, size); + res = spa_json_enter_container(iter, iter, type); + if (res == -EPROTO && relax) + spa_json_init(iter, data, size); + else if (res <= 0) + return res; + return 1; } - /** * Return length of container at current position, starting at \a value. * @@ -405,6 +419,14 @@ static inline int spa_json_enter_object(struct spa_json *iter, struct spa_json * { return spa_json_enter_container(iter, sub, '{'); } +static inline int spa_json_begin_object_relax(struct spa_json * iter, const char *data, size_t size) +{ + return spa_json_begin_container(iter, data, size, '{', true); +} +static inline int spa_json_begin_object(struct spa_json * iter, const char *data, size_t size) +{ + return spa_json_begin_container(iter, data, size, '{', false); +} /* array */ static inline bool spa_json_is_array(const char *val, int len) @@ -415,6 +437,14 @@ static inline int spa_json_enter_array(struct spa_json *iter, struct spa_json *s { return spa_json_enter_container(iter, sub, '['); } +static inline int spa_json_begin_array_relax(struct spa_json * iter, const char *data, size_t size) +{ + return spa_json_begin_container(iter, data, size, '[', true); +} +static inline int spa_json_begin_array(struct spa_json * iter, const char *data, size_t size) +{ + return spa_json_begin_container(iter, data, size, '[', false); +} /* null */ static inline bool spa_json_is_null(const char *val, int len) diff --git a/spa/plugins/aec/aec-webrtc.cpp b/spa/plugins/aec/aec-webrtc.cpp index 354ad940c..50a281353 100644 --- a/spa/plugins/aec/aec-webrtc.cpp +++ b/spa/plugins/aec/aec-webrtc.cpp @@ -70,10 +70,9 @@ static int parse_mic_geometry(struct impl_data *impl, const char *mic_geometry, { int res; size_t i; - struct spa_json it[2]; + struct spa_json it[1]; - spa_json_init(&it[0], mic_geometry, strlen(mic_geometry)); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) { + if (spa_json_begin_array(&it[0], mic_geometry, strlen(mic_geometry)) <= 0) { spa_log_error(impl->log, "Error: webrtc.mic-geometry expects an array"); return -EINVAL; } @@ -81,7 +80,7 @@ static int parse_mic_geometry(struct impl_data *impl, const char *mic_geometry, for (i = 0; i < geometry.size(); i++) { float f[3]; - if ((res = parse_point(&it[1], f)) < 0) { + if ((res = parse_point(&it[0], f)) < 0) { spa_log_error(impl->log, "Error: can't parse webrtc.mic-geometry points: %d", res); return res; } diff --git a/spa/plugins/alsa/acp/acp.c b/spa/plugins/alsa/acp/acp.c index 353896a22..dc504d2a9 100644 --- a/spa/plugins/alsa/acp/acp.c +++ b/spa/plugins/alsa/acp/acp.c @@ -452,17 +452,16 @@ static int add_pro_profile(pa_card *impl, uint32_t index) static bool contains_string(const char *arr, const char *str) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; if (arr == NULL || str == NULL) return false; - spa_json_init(&it[0], arr, strlen(arr)); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], arr, strlen(arr)); + if (spa_json_begin_array_relax(&it[0], arr, strlen(arr)) <= 0) + return false; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0) { + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0) { if (spa_streq(v, str)) return true; } diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index dba3900a4..6f65d3299 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -968,16 +968,15 @@ int spa_alsa_init(struct state *state, const struct spa_dict *info) } else if (spa_streq(k, "clock.quantum-limit")) { spa_atou32(s, &state->quantum_limit, 0); } else if (spa_streq(k, SPA_KEY_API_ALSA_BIND_CTLS)) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; unsigned int i = 0; /* Read a list of ALSA control names to bind as params */ - spa_json_init(&it[0], s, strlen(s)); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], s, strlen(s)); + if (spa_json_begin_array_relax(&it[0], s, strlen(s)) <= 0) + continue; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && i < SPA_N_ELEMENTS(state->bound_ctls)) { snprintf(state->bound_ctls[i].name, sizeof(state->bound_ctls[i].name), "%s", v); diff --git a/spa/plugins/alsa/alsa-pcm.h b/spa/plugins/alsa/alsa-pcm.h index 61ca8f642..b72cbb6fc 100644 --- a/spa/plugins/alsa/alsa-pcm.h +++ b/spa/plugins/alsa/alsa-pcm.h @@ -325,15 +325,14 @@ static inline uint32_t spa_alsa_channel_from_name(const char *name) static inline void spa_alsa_parse_position(struct channel_map *map, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; map->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && map->channels < SPA_AUDIO_MAX_CHANNELS) { map->pos[map->channels++] = spa_alsa_channel_from_name(v); } @@ -341,16 +340,15 @@ static inline void spa_alsa_parse_position(struct channel_map *map, const char * static inline uint32_t spa_alsa_parse_rates(uint32_t *rates, uint32_t max, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; uint32_t count; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return 0; count = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && count < max) + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && count < max) rates[count++] = atoi(v); return count; } @@ -367,15 +365,14 @@ static inline uint32_t spa_alsa_iec958_codec_from_name(const char *name) static inline void spa_alsa_parse_iec958_codecs(uint64_t *codecs, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; *codecs = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0) + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0) *codecs |= 1ULL << spa_alsa_iec958_codec_from_name(v); } diff --git a/spa/plugins/audioconvert/audioadapter.c b/spa/plugins/audioconvert/audioadapter.c index 14434b6bd..f05ac21b6 100644 --- a/spa/plugins/audioconvert/audioadapter.c +++ b/spa/plugins/audioconvert/audioadapter.c @@ -1830,15 +1830,14 @@ static int do_auto_port_config(struct impl *this, const char *str) 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[2]; + struct spa_json it[1]; char key[1024], val[256]; - spa_json_init(&it[0], str, strlen(str)); - if (spa_json_enter_object(&it[0], &it[1]) <= 0) + if (spa_json_begin_object(&it[0], str, strlen(str)) <= 0) return -EINVAL; - while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { - if (spa_json_get_string(&it[1], val, sizeof(val)) <= 0) + while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) { + if (spa_json_get_string(&it[0], val, sizeof(val)) <= 0) break; if (spa_streq(key, "mode")) { diff --git a/spa/plugins/audioconvert/audioconvert.c b/spa/plugins/audioconvert/audioconvert.c index 47c709c69..a12fa40bb 100644 --- a/spa/plugins/audioconvert/audioconvert.c +++ b/spa/plugins/audioconvert/audioconvert.c @@ -3425,15 +3425,14 @@ static uint32_t channel_from_name(const char *name) static inline uint32_t parse_position(uint32_t *pos, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; uint32_t i = 0; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && i < SPA_AUDIO_MAX_CHANNELS) { pos[i++] = channel_from_name(v); } diff --git a/spa/plugins/avb/avb-pcm.h b/spa/plugins/avb/avb-pcm.h index fb2591ffc..7e8fd7362 100644 --- a/spa/plugins/avb/avb-pcm.h +++ b/spa/plugins/avb/avb-pcm.h @@ -286,15 +286,14 @@ static inline uint32_t spa_avb_channel_from_name(const char *name) static inline void spa_avb_parse_position(struct channel_map *map, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; map->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && map->channels < SPA_AUDIO_MAX_CHANNELS) { map->pos[map->channels++] = spa_avb_channel_from_name(v); } @@ -302,16 +301,15 @@ static inline void spa_avb_parse_position(struct channel_map *map, const char *v static inline uint32_t spa_avb_parse_rates(uint32_t *rates, uint32_t max, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; uint32_t count; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return 0; count = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && count < max) + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && count < max) rates[count++] = atoi(v); return count; } diff --git a/spa/plugins/bluez5/bluez5-dbus.c b/spa/plugins/bluez5/bluez5-dbus.c index 27d21bb9c..0a29f3808 100644 --- a/spa/plugins/bluez5/bluez5-dbus.c +++ b/spa/plugins/bluez5/bluez5-dbus.c @@ -6075,13 +6075,11 @@ impl_get_size(const struct spa_handle_factory *factory, int spa_bt_profiles_from_json_array(const char *str) { - struct spa_json it, it_array; + struct spa_json it_array; char role_name[256]; enum spa_bt_profile profiles = SPA_BT_PROFILE_NULL; - spa_json_init(&it, str, strlen(str)); - - if (spa_json_enter_array(&it, &it_array) <= 0) + if (spa_json_begin_array(&it_array, str, strlen(str)) <= 0) return -EINVAL; while (spa_json_get_string(&it_array, role_name, sizeof(role_name)) > 0) { @@ -6144,7 +6142,7 @@ static void parse_broadcast_source_config(struct spa_bt_monitor *monitor, const char bcode[BROADCAST_CODE_LEN + 3]; int cursor; int big_id = 0; - struct spa_json it[4], it_array[4]; + struct spa_json it[3], it_array[4]; struct spa_list big_list = SPA_LIST_INIT(&big_list); struct spa_error_location loc; struct spa_bt_big *big; @@ -6153,14 +6151,12 @@ static void parse_broadcast_source_config(struct spa_bt_monitor *monitor, const if (!(info && (str = spa_dict_lookup(info, "bluez5.bcast_source.config")))) return; - spa_json_init(&it[0], str, strlen(str)); - /* Verify is an array of BIGS */ - if (spa_json_enter_array(&it[0], &it_array[0]) <= 0) + if (spa_json_begin_array(&it_array[0], str, strlen(str)) <= 0) goto parse_failed; /* Iterate on all BIG objects */ - while (spa_json_enter_object(&it_array[0], &it[1]) > 0) { + while (spa_json_enter_object(&it_array[0], &it[0]) > 0) { struct spa_bt_big *big_entry = calloc(1, sizeof(struct spa_bt_big)); if (!big_entry) @@ -6171,22 +6167,22 @@ static void parse_broadcast_source_config(struct spa_bt_monitor *monitor, const spa_list_append(&big_list, &big_entry->link); /* Iterate on all BIG values */ - while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { + while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) { if (spa_streq(key, "broadcast_code")) { - if (spa_json_get_string(&it[1], bcode, sizeof(bcode)) <= 0) + if (spa_json_get_string(&it[0], bcode, sizeof(bcode)) <= 0) goto parse_failed; if (strlen(bcode) > BROADCAST_CODE_LEN) goto parse_failed; memcpy(big_entry->broadcast_code, bcode, strlen(bcode)); spa_log_debug(monitor->log, "big_entry->broadcast_code %s", big_entry->broadcast_code); } else if (spa_streq(key, "encryption")) { - if (spa_json_get_bool(&it[1], &big_entry->encryption) <= 0) + if (spa_json_get_bool(&it[0], &big_entry->encryption) <= 0) goto parse_failed; spa_log_debug(monitor->log, "big_entry->encryption %d", big_entry->encryption); } else if (spa_streq(key, "bis")) { - if (spa_json_enter_array(&it[1], &it_array[1]) <= 0) + if (spa_json_enter_array(&it[0], &it_array[1]) <= 0) goto parse_failed; - while (spa_json_enter_object(&it_array[1], &it[2]) > 0) { + while (spa_json_enter_object(&it_array[1], &it[1]) > 0) { /* Iterate on all BIS values */ struct spa_bt_bis *bis_entry = calloc(1, sizeof(struct spa_bt_bis)); @@ -6196,19 +6192,19 @@ static void parse_broadcast_source_config(struct spa_bt_monitor *monitor, const spa_list_init(&bis_entry->metadata_list); spa_list_append(&big_entry->bis_list, &bis_entry->link); - while (spa_json_get_string(&it[2], bis_key, sizeof(bis_key)) > 0) { + while (spa_json_get_string(&it[1], bis_key, sizeof(bis_key)) > 0) { if (spa_streq(bis_key, "qos_preset")) { - if (spa_json_get_string(&it[2], bis_entry->qos_preset, sizeof(bis_entry->qos_preset)) <= 0) + if (spa_json_get_string(&it[1], bis_entry->qos_preset, sizeof(bis_entry->qos_preset)) <= 0) goto parse_failed; spa_log_debug(monitor->log, "bis_entry->qos_preset %s", bis_entry->qos_preset); } else if (spa_streq(bis_key, "audio_channel_allocation")) { - if (spa_json_get_int(&it[2], &bis_entry->channel_allocation) <= 0) + if (spa_json_get_int(&it[1], &bis_entry->channel_allocation) <= 0) goto parse_failed; spa_log_debug(monitor->log, "bis_entry->channel_allocation %d", bis_entry->channel_allocation); } else if (spa_streq(bis_key, "metadata")) { - if (spa_json_enter_array(&it[2], &it_array[2]) <= 0) + if (spa_json_enter_array(&it[1], &it_array[2]) <= 0) goto parse_failed; - while (spa_json_enter_object(&it_array[2], &it[3]) > 0) { + while (spa_json_enter_object(&it_array[2], &it[2]) > 0) { struct spa_bt_metadata *metadata_entry = calloc(1, sizeof(struct spa_bt_metadata)); if (!metadata_entry) @@ -6216,13 +6212,13 @@ static void parse_broadcast_source_config(struct spa_bt_monitor *monitor, const spa_list_append(&bis_entry->metadata_list, &metadata_entry->link); - while (spa_json_get_string(&it[3], qos_key, sizeof(qos_key)) > 0) { + while (spa_json_get_string(&it[2], qos_key, sizeof(qos_key)) > 0) { if (spa_streq(qos_key, "type")) { - if (spa_json_get_int(&it[3], &metadata_entry->type) <= 0) + if (spa_json_get_int(&it[2], &metadata_entry->type) <= 0) goto parse_failed; spa_log_debug(monitor->log, "metadata_entry->type %d", metadata_entry->type); } else if (spa_streq(qos_key, "value")) { - if (spa_json_enter_array(&it[3], &it_array[3]) <= 0) + if (spa_json_enter_array(&it[2], &it_array[3]) <= 0) goto parse_failed; for (cursor = 0; cursor < METADATA_MAX_LEN - 1; cursor++) { int temp_val = 0; @@ -6254,7 +6250,7 @@ errno_failed: parse_failed: str = spa_dict_lookup(info, "bluez5.bcast_source.config"); - if (spa_json_get_error(&it[0], str, &loc)) { + if (spa_json_get_error(&it_array[0], str, &loc)) { spa_debug_log_error_location(monitor->log, SPA_LOG_LEVEL_WARN, &loc, "malformed bluez5.bcast_source.config: %s", loc.reason); } else { @@ -6272,7 +6268,7 @@ static int parse_codec_array(struct spa_bt_monitor *this, const struct spa_dict const struct media_codec * const * const media_codecs = this->media_codecs; const char *str; struct spa_dict_item *codecs; - struct spa_json it, it_array; + struct spa_json it_array; char codec_name[256]; size_t num_codecs; int i; @@ -6290,9 +6286,7 @@ static int parse_codec_array(struct spa_bt_monitor *this, const struct spa_dict if (info == NULL || (str = spa_dict_lookup(info, "bluez5.codecs")) == NULL) goto fallback; - spa_json_init(&it, str, strlen(str)); - - if (spa_json_enter_array(&it, &it_array) <= 0) { + if (spa_json_begin_array(&it_array, str, strlen(str)) <= 0) { spa_log_error(this->log, "property bluez5.codecs '%s' is not an array", str); goto fallback; } diff --git a/spa/plugins/support/null-audio-sink.c b/spa/plugins/support/null-audio-sink.c index 91d28db54..a601d3b40 100644 --- a/spa/plugins/support/null-audio-sink.c +++ b/spa/plugins/support/null-audio-sink.c @@ -881,15 +881,14 @@ static uint32_t channel_from_name(const char *name) static inline void parse_position(struct impl *this, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; this->props.channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && this->props.channels < SPA_AUDIO_MAX_CHANNELS) { this->props.pos[this->props.channels++] = channel_from_name(v); } diff --git a/src/modules/module-access.c b/src/modules/module-access.c index 9e06e567f..82e94722e 100644 --- a/src/modules/module-access.c +++ b/src/modules/module-access.c @@ -274,20 +274,18 @@ get_server_name(const struct spa_dict *props) static int parse_socket_args(struct impl *impl, const char *str) { - struct spa_json it[2]; + struct spa_json it[1]; char socket[PATH_MAX]; - spa_json_init(&it[0], str, strlen(str)); - - if (spa_json_enter_object(&it[0], &it[1]) <= 0) + if (spa_json_begin_object(&it[0], str, strlen(str)) <= 0) return -EINVAL; - while (spa_json_get_string(&it[1], socket, sizeof(socket)) > 0) { + while (spa_json_get_string(&it[0], socket, sizeof(socket)) > 0) { char value[256]; const char *val; int len; - if ((len = spa_json_next(&it[1], &val)) <= 0) + if ((len = spa_json_next(&it[0], &val)) <= 0) return -EINVAL; if (spa_json_parse_stringn(val, len, value, sizeof(value)) <= 0) diff --git a/src/modules/module-avb/adp.c b/src/modules/module-avb/adp.c index 19216bc81..9fa0d29d1 100644 --- a/src/modules/module-avb/adp.c +++ b/src/modules/module-avb/adp.c @@ -283,20 +283,19 @@ static int do_help(struct adp *adp, const char *args, FILE *out) static int do_discover(struct adp *adp, const char *args, FILE *out) { - struct spa_json it[2]; + struct spa_json it[1]; char key[128]; uint64_t entity_id = 0ULL; - spa_json_init(&it[0], args, strlen(args)); - if (spa_json_enter_object(&it[0], &it[1]) <= 0) + if (spa_json_begin_object(&it[0], args, strlen(args)) <= 0) return -EINVAL; - while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { + while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) { int len; const char *value; uint64_t id_val; - if ((len = spa_json_next(&it[1], &value)) <= 0) + if ((len = spa_json_next(&it[0], &value)) <= 0) break; if (spa_json_is_null(value, len)) diff --git a/src/modules/module-avb/maap.c b/src/modules/module-avb/maap.c index 5dbe962ea..a721e3752 100644 --- a/src/modules/module-avb/maap.c +++ b/src/modules/module-avb/maap.c @@ -253,7 +253,7 @@ static int load_state(struct maap *maap) { const char *str; char key[512]; - struct spa_json it[3]; + struct spa_json it[2]; bool have_offset = false; int count = 0, offset = 0; @@ -263,18 +263,17 @@ static int load_state(struct maap *maap) if ((str = pw_properties_get(maap->props, "maap.addresses")) == NULL) return 0; - spa_json_init(&it[0], str, strlen(str)); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) + if (spa_json_begin_array(&it[0], str, strlen(str)) <= 0) return 0; - if (spa_json_enter_object(&it[1], &it[2]) <= 0) + if (spa_json_enter_object(&it[0], &it[1]) <= 0) return 0; - while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) { + while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { const char *val; int len; - if ((len = spa_json_next(&it[2], &val)) <= 0) + if ((len = spa_json_next(&it[1], &val)) <= 0) break; if (spa_streq(key, "start")) { diff --git a/src/modules/module-combine-stream.c b/src/modules/module-combine-stream.c index 0109c8973..7e165465d 100644 --- a/src/modules/module-combine-stream.c +++ b/src/modules/module-combine-stream.c @@ -330,15 +330,14 @@ static uint32_t channel_from_name(const char *name) static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; info->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && info->channels < SPA_AUDIO_MAX_CHANNELS) { info->position[info->channels++] = channel_from_name(v); } diff --git a/src/modules/module-echo-cancel.c b/src/modules/module-echo-cancel.c index 676707a37..92d74ce00 100644 --- a/src/modules/module-echo-cancel.c +++ b/src/modules/module-echo-cancel.c @@ -1201,15 +1201,14 @@ static uint32_t channel_from_name(const char *name) static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; info->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && info->channels < SPA_AUDIO_MAX_CHANNELS) { info->position[info->channels++] = channel_from_name(v); } diff --git a/src/modules/module-example-filter.c b/src/modules/module-example-filter.c index 5b6de4b9c..4ac0891c8 100644 --- a/src/modules/module-example-filter.c +++ b/src/modules/module-example-filter.c @@ -457,15 +457,14 @@ static uint32_t channel_from_name(const char *name) static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; info->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && info->channels < SPA_AUDIO_MAX_CHANNELS) { info->position[info->channels++] = channel_from_name(v); } diff --git a/src/modules/module-example-sink.c b/src/modules/module-example-sink.c index 772a45d6e..7b3d17594 100644 --- a/src/modules/module-example-sink.c +++ b/src/modules/module-example-sink.c @@ -292,15 +292,14 @@ static uint32_t channel_from_name(const char *name) static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; info->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && info->channels < SPA_AUDIO_MAX_CHANNELS) { info->position[info->channels++] = channel_from_name(v); } diff --git a/src/modules/module-example-source.c b/src/modules/module-example-source.c index 0b06a06cb..0ac10a5e5 100644 --- a/src/modules/module-example-source.c +++ b/src/modules/module-example-source.c @@ -298,15 +298,14 @@ static uint32_t channel_from_name(const char *name) static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; info->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && info->channels < SPA_AUDIO_MAX_CHANNELS) { info->position[info->channels++] = channel_from_name(v); } diff --git a/src/modules/module-ffado-driver.c b/src/modules/module-ffado-driver.c index 3c43af18c..333996541 100644 --- a/src/modules/module-ffado-driver.c +++ b/src/modules/module-ffado-driver.c @@ -1416,15 +1416,14 @@ static uint32_t channel_from_name(const char *name) static void parse_devices(struct impl *impl, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[FFADO_MAX_SPECSTRING_LENGTH]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; impl->n_devices = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && impl->n_devices < FFADO_MAX_SPECSTRINGS) { impl->devices[impl->n_devices++] = strdup(v); } @@ -1435,12 +1434,11 @@ static void parse_position(struct spa_audio_info_raw *info, const char *val, siz struct spa_json it[2]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; info->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && info->channels < SPA_AUDIO_MAX_CHANNELS) { info->position[info->channels++] = channel_from_name(v); } diff --git a/src/modules/module-filter-chain.c b/src/modules/module-filter-chain.c index 457294321..a7873d2b7 100644 --- a/src/modules/module-filter-chain.c +++ b/src/modules/module-filter-chain.c @@ -2714,7 +2714,7 @@ error: */ static int load_graph(struct graph *graph, struct pw_properties *props) { - struct spa_json it[3]; + struct spa_json it[2]; struct spa_json inputs, outputs, *pinputs = NULL, *poutputs = NULL; struct spa_json cvolumes, pvolumes, *pcvolumes = NULL, *ppvolumes = NULL; struct spa_json nodes, *pnodes = NULL, links, *plinks = NULL; @@ -2730,57 +2730,56 @@ static int load_graph(struct graph *graph, struct pw_properties *props) return -EINVAL; } - spa_json_init(&it[0], json, strlen(json)); - if (spa_json_enter_object(&it[0], &it[1]) <= 0) { + if (spa_json_begin_object(&it[0], json, strlen(json)) <= 0) { pw_log_error("filter.graph must be an object"); return -EINVAL; } - while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { + while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) { if (spa_streq("nodes", key)) { - if (spa_json_enter_array(&it[1], &nodes) <= 0) { + if (spa_json_enter_array(&it[0], &nodes) <= 0) { pw_log_error("nodes expects an array"); return -EINVAL; } pnodes = &nodes; } else if (spa_streq("links", key)) { - if (spa_json_enter_array(&it[1], &links) <= 0) { + if (spa_json_enter_array(&it[0], &links) <= 0) { pw_log_error("links expects an array"); return -EINVAL; } plinks = &links; } else if (spa_streq("inputs", key)) { - if (spa_json_enter_array(&it[1], &inputs) <= 0) { + if (spa_json_enter_array(&it[0], &inputs) <= 0) { pw_log_error("inputs expects an array"); return -EINVAL; } pinputs = &inputs; } else if (spa_streq("outputs", key)) { - if (spa_json_enter_array(&it[1], &outputs) <= 0) { + if (spa_json_enter_array(&it[0], &outputs) <= 0) { pw_log_error("outputs expects an array"); return -EINVAL; } poutputs = &outputs; } else if (spa_streq("capture.volumes", key)) { - if (spa_json_enter_array(&it[1], &cvolumes) <= 0) { + if (spa_json_enter_array(&it[0], &cvolumes) <= 0) { pw_log_error("capture.volumes expects an array"); return -EINVAL; } pcvolumes = &cvolumes; } else if (spa_streq("playback.volumes", key)) { - if (spa_json_enter_array(&it[1], &pvolumes) <= 0) { + if (spa_json_enter_array(&it[0], &pvolumes) <= 0) { pw_log_error("playback.volumes expects an array"); return -EINVAL; } ppvolumes = &pvolumes; } else { pw_log_warn("unexpected graph key '%s'", key); - if (spa_json_next(&it[1], &val) < 0) + if (spa_json_next(&it[0], &val) < 0) break; } } @@ -2788,25 +2787,25 @@ static int load_graph(struct graph *graph, struct pw_properties *props) pw_log_error("filter.graph is missing a nodes array"); return -EINVAL; } - while (spa_json_enter_object(pnodes, &it[2]) > 0) { - if ((res = load_node(graph, &it[2])) < 0) + while (spa_json_enter_object(pnodes, &it[1]) > 0) { + if ((res = load_node(graph, &it[1])) < 0) return res; } if (plinks != NULL) { - while (spa_json_enter_object(plinks, &it[2]) > 0) { - if ((res = parse_link(graph, &it[2])) < 0) + while (spa_json_enter_object(plinks, &it[1]) > 0) { + if ((res = parse_link(graph, &it[1])) < 0) return res; } } if (pcvolumes != NULL) { - while (spa_json_enter_object(pcvolumes, &it[2]) > 0) { - if ((res = parse_volume(graph, &it[2], true)) < 0) + while (spa_json_enter_object(pcvolumes, &it[1]) > 0) { + if ((res = parse_volume(graph, &it[1], true)) < 0) return res; } } if (ppvolumes != NULL) { - while (spa_json_enter_object(ppvolumes, &it[2]) > 0) { - if ((res = parse_volume(graph, &it[2], false)) < 0) + while (spa_json_enter_object(ppvolumes, &it[1]) > 0) { + if ((res = parse_volume(graph, &it[1], false)) < 0) return res; } } @@ -2913,15 +2912,14 @@ static uint32_t channel_from_name(const char *name) static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; info->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && info->channels < SPA_AUDIO_MAX_CHANNELS) { info->position[info->channels++] = channel_from_name(v); } diff --git a/src/modules/module-filter-chain/builtin_plugin.c b/src/modules/module-filter-chain/builtin_plugin.c index b87393214..132923c71 100644 --- a/src/modules/module-filter-chain/builtin_plugin.c +++ b/src/modules/module-filter-chain/builtin_plugin.c @@ -278,7 +278,7 @@ static void *bq_instantiate(const struct fc_descriptor * Descriptor, unsigned long SampleRate, int index, const char *config) { struct builtin *impl; - struct spa_json it[4]; + struct spa_json it[3]; const char *val; char key[256]; uint32_t best_rate = 0; @@ -298,69 +298,68 @@ static void *bq_instantiate(const struct fc_descriptor * Descriptor, goto error; } - spa_json_init(&it[0], config, strlen(config)); - if (spa_json_enter_object(&it[0], &it[1]) <= 0) { + if (spa_json_begin_object(&it[0], config, strlen(config)) <= 0) { pw_log_error("biquads:config section must be an object"); goto error; } - while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { + while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) { if (spa_streq(key, "coefficients")) { - if (spa_json_enter_array(&it[1], &it[2]) <= 0) { + if (spa_json_enter_array(&it[0], &it[1]) <= 0) { pw_log_error("biquads:coefficients require an array"); goto error; } - while (spa_json_enter_object(&it[2], &it[3]) > 0) { + while (spa_json_enter_object(&it[1], &it[2]) > 0) { int32_t rate = 0; float b0 = 1.0f, b1 = 0.0f, b2 = 0.0f; float a0 = 1.0f, a1 = 0.0f, a2 = 0.0f; - while (spa_json_get_string(&it[3], key, sizeof(key)) > 0) { + while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) { if (spa_streq(key, "rate")) { - if (spa_json_get_int(&it[3], &rate) <= 0) { + if (spa_json_get_int(&it[2], &rate) <= 0) { pw_log_error("biquads:rate requires a number"); goto error; } } else if (spa_streq(key, "b0")) { - if (spa_json_get_float(&it[3], &b0) <= 0) { + if (spa_json_get_float(&it[2], &b0) <= 0) { pw_log_error("biquads:b0 requires a float"); goto error; } } else if (spa_streq(key, "b1")) { - if (spa_json_get_float(&it[3], &b1) <= 0) { + if (spa_json_get_float(&it[2], &b1) <= 0) { pw_log_error("biquads:b1 requires a float"); goto error; } } else if (spa_streq(key, "b2")) { - if (spa_json_get_float(&it[3], &b2) <= 0) { + if (spa_json_get_float(&it[2], &b2) <= 0) { pw_log_error("biquads:b2 requires a float"); goto error; } } else if (spa_streq(key, "a0")) { - if (spa_json_get_float(&it[3], &a0) <= 0) { + if (spa_json_get_float(&it[2], &a0) <= 0) { pw_log_error("biquads:a0 requires a float"); goto error; } } else if (spa_streq(key, "a1")) { - if (spa_json_get_float(&it[3], &a1) <= 0) { + if (spa_json_get_float(&it[2], &a1) <= 0) { pw_log_error("biquads:a1 requires a float"); goto error; } } else if (spa_streq(key, "a2")) { - if (spa_json_get_float(&it[3], &a2) <= 0) { + if (spa_json_get_float(&it[2], &a2) <= 0) { pw_log_error("biquads:a0 requires a float"); goto error; } } else { pw_log_warn("biquads: ignoring coefficients key: '%s'", key); - if (spa_json_next(&it[3], &val) < 0) + if (spa_json_next(&it[2], &val) < 0) break; } } @@ -373,7 +372,7 @@ static void *bq_instantiate(const struct fc_descriptor * Descriptor, } else { pw_log_warn("biquads: ignoring config key: '%s'", key); - if (spa_json_next(&it[1], &val) < 0) + if (spa_json_next(&it[0], &val) < 0) break; } } @@ -865,7 +864,7 @@ static void * convolver_instantiate(const struct fc_descriptor * Descriptor, float *samples; int offset = 0, length = 0, channel = index, n_samples = 0, len; uint32_t i = 0; - struct spa_json it[3]; + struct spa_json it[2]; const char *val; char key[256], v[256]; char *filenames[MAX_RATES] = { 0 }; @@ -881,45 +880,44 @@ static void * convolver_instantiate(const struct fc_descriptor * Descriptor, return NULL; } - spa_json_init(&it[0], config, strlen(config)); - if (spa_json_enter_object(&it[0], &it[1]) <= 0) { + if (spa_json_begin_object(&it[0], config, strlen(config)) <= 0) { pw_log_error("convolver:config must be an object"); return NULL; } - while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { + while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) { if (spa_streq(key, "blocksize")) { - if (spa_json_get_int(&it[1], &blocksize) <= 0) { + if (spa_json_get_int(&it[0], &blocksize) <= 0) { pw_log_error("convolver:blocksize requires a number"); return NULL; } } else if (spa_streq(key, "tailsize")) { - if (spa_json_get_int(&it[1], &tailsize) <= 0) { + if (spa_json_get_int(&it[0], &tailsize) <= 0) { pw_log_error("convolver:tailsize requires a number"); return NULL; } } else if (spa_streq(key, "gain")) { - if (spa_json_get_float(&it[1], &gain) <= 0) { + if (spa_json_get_float(&it[0], &gain) <= 0) { pw_log_error("convolver:gain requires a number"); return NULL; } } else if (spa_streq(key, "delay")) { - if (spa_json_get_int(&it[1], &delay) <= 0) { + if (spa_json_get_int(&it[0], &delay) <= 0) { pw_log_error("convolver:delay requires a number"); return NULL; } } else if (spa_streq(key, "filename")) { - if ((len = spa_json_next(&it[1], &val)) <= 0) { + if ((len = spa_json_next(&it[0], &val)) <= 0) { pw_log_error("convolver:filename requires a string or an array"); return NULL; } if (spa_json_is_array(val, len)) { - spa_json_enter(&it[1], &it[2]); - while (spa_json_get_string(&it[2], v, sizeof(v)) > 0 && + spa_json_enter(&it[0], &it[1]); + while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && i < SPA_N_ELEMENTS(filenames)) { filenames[i] = strdup(v); i++; @@ -933,32 +931,32 @@ static void * convolver_instantiate(const struct fc_descriptor * Descriptor, } } else if (spa_streq(key, "offset")) { - if (spa_json_get_int(&it[1], &offset) <= 0) { + if (spa_json_get_int(&it[0], &offset) <= 0) { pw_log_error("convolver:offset requires a number"); return NULL; } } else if (spa_streq(key, "length")) { - if (spa_json_get_int(&it[1], &length) <= 0) { + if (spa_json_get_int(&it[0], &length) <= 0) { pw_log_error("convolver:length requires a number"); return NULL; } } else if (spa_streq(key, "channel")) { - if (spa_json_get_int(&it[1], &channel) <= 0) { + if (spa_json_get_int(&it[0], &channel) <= 0) { pw_log_error("convolver:channel requires a number"); return NULL; } } else if (spa_streq(key, "resample_quality")) { - if (spa_json_get_int(&it[1], &resample_quality) <= 0) { + if (spa_json_get_int(&it[0], &resample_quality) <= 0) { pw_log_error("convolver:resample_quality requires a number"); return NULL; } } else { pw_log_warn("convolver: ignoring config key: '%s'", key); - if (spa_json_next(&it[1], &val) < 0) + if (spa_json_next(&it[0], &val) < 0) break; } } @@ -1097,7 +1095,7 @@ static void *delay_instantiate(const struct fc_descriptor * Descriptor, unsigned long SampleRate, int index, const char *config) { struct delay_impl *impl; - struct spa_json it[2]; + struct spa_json it[1]; const char *val; char key[256]; float max_delay = 1.0f; @@ -1108,21 +1106,20 @@ static void *delay_instantiate(const struct fc_descriptor * Descriptor, return NULL; } - spa_json_init(&it[0], config, strlen(config)); - if (spa_json_enter_object(&it[0], &it[1]) <= 0) { + if (spa_json_begin_object(&it[0], config, strlen(config)) <= 0) { pw_log_error("delay:config must be an object"); return NULL; } - while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { + while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) { if (spa_streq(key, "max-delay")) { - if (spa_json_get_float(&it[1], &max_delay) <= 0) { + if (spa_json_get_float(&it[0], &max_delay) <= 0) { pw_log_error("delay:max-delay requires a number"); return NULL; } } else { pw_log_warn("delay: ignoring config key: '%s'", key); - if (spa_json_next(&it[1], &val) < 0) + if (spa_json_next(&it[0], &val) < 0) break; } } diff --git a/src/modules/module-filter-chain/sofa_plugin.c b/src/modules/module-filter-chain/sofa_plugin.c index 53a3c90b6..5645bd106 100644 --- a/src/modules/module-filter-chain/sofa_plugin.c +++ b/src/modules/module-filter-chain/sofa_plugin.c @@ -36,7 +36,7 @@ static void * spatializer_instantiate(const struct fc_descriptor * Descriptor, unsigned long SampleRate, int index, const char *config) { struct spatializer_impl *impl; - struct spa_json it[2]; + struct spa_json it[1]; const char *val; char key[256]; char filename[PATH_MAX] = ""; @@ -47,8 +47,7 @@ static void * spatializer_instantiate(const struct fc_descriptor * Descriptor, return NULL; } - spa_json_init(&it[0], config, strlen(config)); - if (spa_json_enter_object(&it[0], &it[1]) <= 0) { + if (spa_json_begin_object(&it[0], config, strlen(config)) <= 0) { pw_log_error("spatializer: expected object in config"); return NULL; } @@ -59,29 +58,29 @@ static void * spatializer_instantiate(const struct fc_descriptor * Descriptor, return NULL; } - while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { + while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) { if (spa_streq(key, "blocksize")) { - if (spa_json_get_int(&it[1], &impl->blocksize) <= 0) { + if (spa_json_get_int(&it[0], &impl->blocksize) <= 0) { pw_log_error("spatializer:blocksize requires a number"); errno = EINVAL; goto error; } } else if (spa_streq(key, "tailsize")) { - if (spa_json_get_int(&it[1], &impl->tailsize) <= 0) { + if (spa_json_get_int(&it[0], &impl->tailsize) <= 0) { pw_log_error("spatializer:tailsize requires a number"); errno = EINVAL; goto error; } } else if (spa_streq(key, "filename")) { - if (spa_json_get_string(&it[1], filename, sizeof(filename)) <= 0) { + if (spa_json_get_string(&it[0], filename, sizeof(filename)) <= 0) { pw_log_error("spatializer:filename requires a string"); errno = EINVAL; goto error; } } - else if (spa_json_next(&it[1], &val) < 0) + else if (spa_json_next(&it[0], &val) < 0) break; } if (!filename[0]) { diff --git a/src/modules/module-jack-tunnel.c b/src/modules/module-jack-tunnel.c index edff0fc63..a6e38d05f 100644 --- a/src/modules/module-jack-tunnel.c +++ b/src/modules/module-jack-tunnel.c @@ -1001,15 +1001,14 @@ static uint32_t channel_from_name(const char *name) static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; info->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && info->channels < SPA_AUDIO_MAX_CHANNELS) { info->position[info->channels++] = channel_from_name(v); } diff --git a/src/modules/module-loopback.c b/src/modules/module-loopback.c index 8d1d69e01..291ecfc53 100644 --- a/src/modules/module-loopback.c +++ b/src/modules/module-loopback.c @@ -773,15 +773,14 @@ static uint32_t channel_from_name(const char *name) static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; info->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && info->channels < SPA_AUDIO_MAX_CHANNELS) { info->position[info->channels++] = channel_from_name(v); } diff --git a/src/modules/module-metadata.c b/src/modules/module-metadata.c index 2d05fb83f..b813327ac 100644 --- a/src/modules/module-metadata.c +++ b/src/modules/module-metadata.c @@ -66,21 +66,20 @@ struct factory_data { */ static int fill_metadata(struct pw_metadata *metadata, const char *str) { - struct spa_json it[3]; + struct spa_json it[2]; - spa_json_init(&it[0], str, strlen(str)); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) + if (spa_json_begin_array(&it[0], str, strlen(str)) <= 0) return -EINVAL; - while (spa_json_enter_object(&it[1], &it[2]) > 0) { + while (spa_json_enter_object(&it[0], &it[1]) > 0) { char key[256], *k = NULL, *v = NULL, *t = NULL; int id = 0; - while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) { + while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { int len; const char *val; - if ((len = spa_json_next(&it[2], &val)) <= 0) + if ((len = spa_json_next(&it[1], &val)) <= 0) return -EINVAL; if (spa_streq(key, "id")) { @@ -94,7 +93,7 @@ static int fill_metadata(struct pw_metadata *metadata, const char *str) spa_json_parse_stringn(val, len, t, len+1); } else if (spa_streq(key, "value")) { if (spa_json_is_container(val, len)) - len = spa_json_container_len(&it[2], val, len); + len = spa_json_container_len(&it[1], val, len); if ((v = malloc(len+1)) != NULL) spa_json_parse_stringn(val, len, v, len+1); } diff --git a/src/modules/module-netjack2-driver.c b/src/modules/module-netjack2-driver.c index dd999ad26..f4630961a 100644 --- a/src/modules/module-netjack2-driver.c +++ b/src/modules/module-netjack2-driver.c @@ -1156,15 +1156,14 @@ static uint32_t channel_from_name(const char *name) static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; info->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && info->channels < SPA_AUDIO_MAX_CHANNELS) { info->position[info->channels++] = channel_from_name(v); } diff --git a/src/modules/module-netjack2-manager.c b/src/modules/module-netjack2-manager.c index 329036d14..4a28f6d10 100644 --- a/src/modules/module-netjack2-manager.c +++ b/src/modules/module-netjack2-manager.c @@ -1182,15 +1182,14 @@ static uint32_t channel_from_name(const char *name) static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; info->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && info->channels < SPA_AUDIO_MAX_CHANNELS) { info->position[info->channels++] = channel_from_name(v); } diff --git a/src/modules/module-pipe-tunnel.c b/src/modules/module-pipe-tunnel.c index ee963357c..2ab768cdc 100644 --- a/src/modules/module-pipe-tunnel.c +++ b/src/modules/module-pipe-tunnel.c @@ -764,15 +764,14 @@ static uint32_t channel_from_name(const char *name) static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; info->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && info->channels < SPA_AUDIO_MAX_CHANNELS) { info->position[info->channels++] = channel_from_name(v); } diff --git a/src/modules/module-protocol-native.c b/src/modules/module-protocol-native.c index c6efc373d..d20b3d854 100644 --- a/src/modules/module-protocol-native.c +++ b/src/modules/module-protocol-native.c @@ -1659,7 +1659,7 @@ static int create_servers(struct pw_protocol *this, struct pw_impl_core *core, const struct pw_properties *props, const struct pw_properties *args) { const char *sockets = args ? pw_properties_get(args, "sockets") : NULL; - struct spa_json it[3]; + struct spa_json it[2]; spa_autoptr(pw_properties) p = pw_properties_copy(props); if (sockets == NULL) { @@ -1681,12 +1681,10 @@ static int create_servers(struct pw_protocol *this, struct pw_impl_core *core, return 0; } - spa_json_init(&it[0], sockets, strlen(sockets)); - - if (spa_json_enter_array(&it[0], &it[1]) <= 0) + if (spa_json_begin_array(&it[0], sockets, strlen(sockets)) <= 0) goto error_invalid; - while (spa_json_enter_object(&it[1], &it[2]) > 0) { + while (spa_json_enter_object(&it[0], &it[1]) > 0) { struct socket_info info = {0}; char key[256]; char name[PATH_MAX]; @@ -1698,11 +1696,11 @@ static int create_servers(struct pw_protocol *this, struct pw_impl_core *core, pw_properties_clear(p); pw_properties_update(p, &props->dict); - while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) { + while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { const char *value; int len; - if ((len = spa_json_next(&it[2], &value)) <= 0) + if ((len = spa_json_next(&it[1], &value)) <= 0) goto error_invalid; if (spa_streq(key, "name")) { @@ -1762,7 +1760,7 @@ static int create_servers(struct pw_protocol *this, struct pw_impl_core *core, info.has_mode = true; } else if (spa_streq(key, "props")) { if (spa_json_is_container(value, len)) - len = spa_json_container_len(&it[2], value, len); + len = spa_json_container_len(&it[1], value, len); pw_properties_update_string(p, value, len); } diff --git a/src/modules/module-protocol-native/local-socket.c b/src/modules/module-protocol-native/local-socket.c index f514881aa..7064a30de 100644 --- a/src/modules/module-protocol-native/local-socket.c +++ b/src/modules/module-protocol-native/local-socket.c @@ -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; diff --git a/src/modules/module-protocol-pulse/cmd.c b/src/modules/module-protocol-pulse/cmd.c index 0fcd83a98..bd7506460 100644 --- a/src/modules/module-protocol-pulse/cmd.c +++ b/src/modules/module-protocol-pulse/cmd.c @@ -68,25 +68,24 @@ static int parse_cmd(void *user_data, const char *location, const char *section, const char *str, size_t len) { struct impl *impl = user_data; - struct spa_json it[3]; + struct spa_json it[2]; char key[512]; int res = 0; spa_autofree char *s = strndup(str, len); - spa_json_init(&it[0], s, len); - if (spa_json_enter_array(&it[0], &it[1]) < 0) { + if (spa_json_begin_array(&it[0], s, len) < 0) { pw_log_error("config file error: pulse.cmd is not an array"); return -EINVAL; } - while (spa_json_enter_object(&it[1], &it[2]) > 0) { + while (spa_json_enter_object(&it[0], &it[1]) > 0) { char *cmd = NULL, *args = NULL, *flags = NULL; - while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) { + while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { const char *val; int len; - if ((len = spa_json_next(&it[2], &val)) <= 0) + if ((len = spa_json_next(&it[1], &val)) <= 0) break; if (spa_streq(key, "cmd")) { @@ -97,7 +96,7 @@ static int parse_cmd(void *user_data, const char *location, spa_json_parse_stringn(val, len, args, len+1); } else if (spa_streq(key, "flags")) { if (spa_json_is_container(val, len)) - len = spa_json_container_len(&it[2], val, len); + len = spa_json_container_len(&it[1], val, len); flags = (char*)val; spa_json_parse_stringn(val, len, flags, len+1); } diff --git a/src/modules/module-protocol-pulse/format.c b/src/modules/module-protocol-pulse/format.c index 4ed12dc46..479f9a42a 100644 --- a/src/modules/module-protocol-pulse/format.c +++ b/src/modules/module-protocol-pulse/format.c @@ -440,15 +440,14 @@ void channel_map_parse(const char *str, struct channel_map *map) void channel_map_parse_position(const char *str, struct channel_map *map) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], str, strlen(str)); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], str, strlen(str)); + if (spa_json_begin_array_relax(&it[0], str, strlen(str)) <= 0) + return; map->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && map->channels < SPA_AUDIO_MAX_CHANNELS) { map->map[map->channels++] = channel_name2id(v); } diff --git a/src/modules/module-protocol-pulse/modules/module-stream-restore.c b/src/modules/module-protocol-pulse/modules/module-stream-restore.c index 79481390b..ab689285d 100644 --- a/src/modules/module-protocol-pulse/modules/module-stream-restore.c +++ b/src/modules/module-protocol-pulse/modules/module-stream-restore.c @@ -177,7 +177,7 @@ static int do_extension_stream_restore_read(struct module *module, struct client reply = reply_new(client, tag); spa_dict_for_each(item, &client->routes->dict) { - struct spa_json it[3]; + struct spa_json it[2]; const char *value; char name[1024], key[128]; char device_name[1024] = "\0"; @@ -191,45 +191,44 @@ static int do_extension_stream_restore_read(struct module *module, struct client pw_log_debug("%s -> %s: %s", item->key, name, item->value); - spa_json_init(&it[0], item->value, strlen(item->value)); - if (spa_json_enter_object(&it[0], &it[1]) <= 0) + if (spa_json_begin_object(&it[0], item->value, strlen(item->value)) <= 0) continue; - while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { + while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) { if (spa_streq(key, "volume")) { - if (spa_json_get_float(&it[1], &volume) <= 0) + if (spa_json_get_float(&it[0], &volume) <= 0) continue; } else if (spa_streq(key, "mute")) { - if (spa_json_get_bool(&it[1], &mute) <= 0) + if (spa_json_get_bool(&it[0], &mute) <= 0) continue; } else if (spa_streq(key, "volumes")) { vol = VOLUME_INIT; - if (spa_json_enter_array(&it[1], &it[2]) <= 0) + if (spa_json_enter_array(&it[0], &it[1]) <= 0) continue; for (vol.channels = 0; vol.channels < CHANNELS_MAX; vol.channels++) { - if (spa_json_get_float(&it[2], &vol.values[vol.channels]) <= 0) + if (spa_json_get_float(&it[1], &vol.values[vol.channels]) <= 0) break; } } else if (spa_streq(key, "channels")) { - if (spa_json_enter_array(&it[1], &it[2]) <= 0) + if (spa_json_enter_array(&it[0], &it[1]) <= 0) continue; for (map.channels = 0; map.channels < CHANNELS_MAX; map.channels++) { char chname[16]; - if (spa_json_get_string(&it[2], chname, sizeof(chname)) <= 0) + if (spa_json_get_string(&it[1], chname, sizeof(chname)) <= 0) break; map.map[map.channels] = channel_name2id(chname); } } else if (spa_streq(key, "target-node")) { - if (spa_json_get_string(&it[1], device_name, sizeof(device_name)) <= 0) + if (spa_json_get_string(&it[0], device_name, sizeof(device_name)) <= 0) continue; } - else if (spa_json_next(&it[1], &value) <= 0) + else if (spa_json_next(&it[0], &value) <= 0) break; } message_put(reply, diff --git a/src/modules/module-protocol-pulse/pulse-server.c b/src/modules/module-protocol-pulse/pulse-server.c index a2b032f86..1297add4d 100644 --- a/src/modules/module-protocol-pulse/pulse-server.c +++ b/src/modules/module-protocol-pulse/pulse-server.c @@ -930,21 +930,20 @@ static void manager_object_data_timeout(void *data, struct pw_manager_object *o, static int json_object_find(const char *obj, const char *key, char *value, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; const char *v; char k[128]; - spa_json_init(&it[0], obj, strlen(obj)); - if (spa_json_enter_object(&it[0], &it[1]) <= 0) + if (spa_json_begin_object(&it[0], obj, strlen(obj)) <= 0) return -EINVAL; - while (spa_json_get_string(&it[1], k, sizeof(k)) > 0) { + 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) + if (spa_json_get_string(&it[0], value, len) <= 0) continue; return 0; } else { - if (spa_json_next(&it[1], &v) <= 0) + if (spa_json_next(&it[0], &v) <= 0) break; } } diff --git a/src/modules/module-protocol-pulse/server.c b/src/modules/module-protocol-pulse/server.c index e35f25c32..51e8b7cfa 100644 --- a/src/modules/module-protocol-pulse/server.c +++ b/src/modules/module-protocol-pulse/server.c @@ -977,29 +977,28 @@ int servers_create_and_start(struct impl *impl, const char *addresses, struct pw { int len, res, count = 0, err = 0; /* store the first error to return when no servers could be created */ const char *v; - struct spa_json it[3]; + struct spa_json it[2]; /* update `err` if it hasn't been set to an errno */ #define UPDATE_ERR(e) do { if (err == 0) err = (e); } while (false) /* collect addresses into an array of `struct sockaddr_storage` */ - spa_json_init(&it[0], addresses, strlen(addresses)); /* [ ... ] */ - if (spa_json_enter_array(&it[0], &it[1]) < 0) + if (spa_json_begin_array(&it[0], addresses, strlen(addresses)) < 0) return -EINVAL; /* a server-spec is either an address or an object */ - while ((len = spa_json_next(&it[1], &v)) > 0) { + while ((len = spa_json_next(&it[0], &v)) > 0) { char addr_str[FORMATTED_SOCKET_ADDR_STRLEN] = { 0 }; char key[128], client_access[64] = { 0 }; struct sockaddr_storage addrs[2]; int i, max_clients = MAX_CLIENTS, listen_backlog = LISTEN_BACKLOG, n_addr; if (spa_json_is_object(v, len)) { - spa_json_enter(&it[1], &it[2]); - while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) { - if ((len = spa_json_next(&it[2], &v)) <= 0) + 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], &v)) <= 0) break; if (spa_streq(key, "address")) { diff --git a/src/modules/module-protocol-simple.c b/src/modules/module-protocol-simple.c index 560a7e8fa..4f6d453eb 100644 --- a/src/modules/module-protocol-simple.c +++ b/src/modules/module-protocol-simple.c @@ -805,15 +805,14 @@ static inline uint32_t channel_from_name(const char *name) static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; info->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && info->channels < SPA_AUDIO_MAX_CHANNELS) { info->position[info->channels++] = channel_from_name(v); } @@ -890,7 +889,7 @@ static void copy_props(struct impl *impl, const char *key) static int parse_params(struct impl *impl) { const char *str; - struct spa_json it[2]; + struct spa_json it[1]; char value[512]; pw_properties_fetch_bool(impl->props, "capture", &impl->capture); @@ -965,9 +964,8 @@ static int parse_params(struct impl *impl) if ((str = pw_properties_get(impl->props, "server.address")) == NULL) str = DEFAULT_SERVER; - spa_json_init(&it[0], str, strlen(str)); - if (spa_json_enter_array(&it[0], &it[1]) > 0) { - while (spa_json_get_string(&it[1], value, sizeof(value)) > 0) { + if (spa_json_begin_array_relax(&it[0], str, strlen(str)) > 0) { + while (spa_json_get_string(&it[0], value, sizeof(value)) > 0) { if (create_server(impl, value) == NULL) { pw_log_warn("%p: can't create server for %s: %m", impl, value); diff --git a/src/modules/module-pulse-tunnel.c b/src/modules/module-pulse-tunnel.c index 3e1592040..e3d7ca4b5 100644 --- a/src/modules/module-pulse-tunnel.c +++ b/src/modules/module-pulse-tunnel.c @@ -1074,15 +1074,14 @@ static uint32_t channel_from_name(const char *name) static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; info->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && info->channels < SPA_AUDIO_MAX_CHANNELS) { info->position[info->channels++] = channel_from_name(v); } diff --git a/src/modules/module-rtp-sap.c b/src/modules/module-rtp-sap.c index defd11094..c4ebc7a4b 100644 --- a/src/modules/module-rtp-sap.c +++ b/src/modules/module-rtp-sap.c @@ -965,19 +965,16 @@ static struct session *session_new_announce(struct impl *impl, struct node *node sess->ts_refclk_ptp = pw_properties_get_bool(props, "rtp.fetch-ts-refclk", false); if ((str = pw_properties_get(props, PW_KEY_NODE_CHANNELNAMES)) != NULL) { struct spa_strbuf buf; + struct spa_json it[1]; + char v[256]; + int count = 0; + spa_strbuf_init(&buf, sdp->channelmap, sizeof(sdp->channelmap)); - struct spa_json it[2]; - char v[256]; - - spa_json_init(&it[0], str, strlen(str)); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], str, strlen(str)); - - if (spa_json_get_string(&it[1], v, sizeof(v)) > 0) - spa_strbuf_append(&buf, "%s", v); - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0) - spa_strbuf_append(&buf, ", %s", v); + if (spa_json_begin_array_relax(&it[0], str, strlen(str)) > 0) { + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0) + spa_strbuf_append(&buf, "%s%s", count++ > 0 ? ", " : "", v); + } } pw_log_info("created new session for node:%u", node->id); @@ -1799,30 +1796,24 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args) struct spa_strbuf buf; if ((str = pw_properties_get(props, "sap.preamble-extra")) != NULL) { spa_strbuf_init(&buf, buffer, sizeof(buffer)); - struct spa_json it[2]; + struct spa_json it[1]; char line[256]; - spa_json_init(&it[0], str, strlen(str)); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], str, strlen(str)); - - while (spa_json_get_string(&it[1], line, sizeof(line)) > 0) - spa_strbuf_append(&buf, "%s\n", line); - + if (spa_json_begin_array_relax(&it[0], str, strlen(str)) > 0) { + while (spa_json_get_string(&it[0], line, sizeof(line)) > 0) + spa_strbuf_append(&buf, "%s\n", line); + } impl->extra_attrs_preamble = strdup(buffer); } if ((str = pw_properties_get(props, "sap.end-extra")) != NULL) { spa_strbuf_init(&buf, buffer, sizeof(buffer)); - struct spa_json it[2]; + struct spa_json it[1]; char line[256]; - spa_json_init(&it[0], str, strlen(str)); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], str, strlen(str)); - - while (spa_json_get_string(&it[1], line, sizeof(line)) > 0) - spa_strbuf_append(&buf, "%s\n", line); - + if (spa_json_begin_array_relax(&it[0], str, strlen(str)) > 0) { + while (spa_json_get_string(&it[0], line, sizeof(line)) > 0) + spa_strbuf_append(&buf, "%s\n", line); + } impl->extra_attrs_end = strdup(buffer); } diff --git a/src/modules/module-rtp/stream.c b/src/modules/module-rtp/stream.c index 27f8af98d..7e8289a2e 100644 --- a/src/modules/module-rtp/stream.c +++ b/src/modules/module-rtp/stream.c @@ -291,15 +291,14 @@ static uint32_t channel_from_name(const char *name) static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; info->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && info->channels < SPA_AUDIO_MAX_CHANNELS) { info->position[info->channels++] = channel_from_name(v); } diff --git a/src/modules/module-snapcast-discover.c b/src/modules/module-snapcast-discover.c index 47a72d1f7..ffa3806ed 100644 --- a/src/modules/module-snapcast-discover.c +++ b/src/modules/module-snapcast-discover.c @@ -486,14 +486,13 @@ static int snapcast_connect(struct tunnel *t) static int add_snapcast_stream(struct impl *impl, struct tunnel *t, struct pw_properties *props, const char *servers) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], servers, strlen(servers)); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], servers, strlen(servers)); + if (spa_json_begin_array_relax(&it[0], servers, strlen(servers)) <= 0) + return -EINVAL; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0) { + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0) { t->server_address = strdup(v); snapcast_connect(t); return 0; @@ -523,15 +522,14 @@ static inline uint32_t channel_from_name(const char *name) static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; info->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && info->channels < SPA_AUDIO_MAX_CHANNELS) { info->position[info->channels++] = channel_from_name(v); } diff --git a/src/modules/module-vban/stream.c b/src/modules/module-vban/stream.c index ed1a2eabe..108dc79a8 100644 --- a/src/modules/module-vban/stream.c +++ b/src/modules/module-vban/stream.c @@ -209,15 +209,14 @@ static uint32_t channel_from_name(const char *name) static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return; info->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && info->channels < SPA_AUDIO_MAX_CHANNELS) { info->position[info->channels++] = channel_from_name(v); } diff --git a/src/pipewire/conf.c b/src/pipewire/conf.c index ee8e24a1e..108af4fc5 100644 --- a/src/pipewire/conf.c +++ b/src/pipewire/conf.c @@ -565,19 +565,18 @@ static int parse_spa_libs(void *user_data, const char *location, { struct data *d = user_data; struct pw_context *context = d->context; - struct spa_json it[2]; + struct spa_json it[1]; char key[512], value[512]; int res; - spa_json_init(&it[0], str, len); - if (spa_json_enter_object(&it[0], &it[1]) < 0) { + if (spa_json_begin_object(&it[0], str, len) < 0) { pw_log_error("config file error: context.spa-libs is not an " "object in '%.*s'", (int)len, str); return -EINVAL; } - while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { - if (spa_json_get_string(&it[1], value, sizeof(value)) > 0) { + while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) { + if (spa_json_get_string(&it[0], value, sizeof(value)) > 0) { if ((res = pw_context_add_spa_lib(context, key, value)) < 0) { pw_log_error("error adding spa-libs for '%s' in '%.*s': %s", key, (int)len, str, spa_strerror(res)); @@ -752,27 +751,26 @@ static int parse_modules(void *user_data, const char *location, { struct data *d = user_data; struct pw_context *context = d->context; - struct spa_json it[4]; + struct spa_json it[3]; char key[512]; int res = 0, r; spa_autofree char *s = strndup(str, len); - spa_json_init(&it[0], s, len); - if (spa_json_enter_array(&it[0], &it[1]) < 0) { + if (spa_json_begin_array(&it[0], s, len) < 0) { pw_log_error("context.modules is not an array in '%.*s'", (int)len, str); return -EINVAL; } - while ((r = spa_json_enter_object(&it[1], &it[2])) > 0) { + while ((r = spa_json_enter_object(&it[0], &it[1])) > 0) { char *name = NULL, *args = NULL, *flags = NULL; bool have_match = true; - while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) { + while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { const char *val; int l; - if ((l = spa_json_next(&it[2], &val)) <= 0) { + if ((l = spa_json_next(&it[1], &val)) <= 0) { pw_log_warn("malformed module: key '%s' has no " "value in '%.*s'", key, (int)len, str); break; @@ -783,13 +781,13 @@ static int parse_modules(void *user_data, const char *location, spa_json_parse_stringn(val, l, name, l+1); } else if (spa_streq(key, "args")) { if (spa_json_is_container(val, l)) - l = spa_json_container_len(&it[2], val, l); + l = spa_json_container_len(&it[1], val, l); args = (char*)val; spa_json_parse_stringn(val, l, args, l+1); } else if (spa_streq(key, "flags")) { if (spa_json_is_container(val, l)) - l = spa_json_container_len(&it[2], val, l); + l = spa_json_container_len(&it[1], val, l); flags = (char*)val; spa_json_parse_stringn(val, l, flags, l+1); } else if (spa_streq(key, "condition")) { @@ -798,8 +796,8 @@ static int parse_modules(void *user_data, const char *location, (int)len, str); break; } - spa_json_enter(&it[2], &it[3]); - have_match = find_match(&it[3], &context->properties->dict, true); + spa_json_enter(&it[1], &it[2]); + have_match = find_match(&it[2], &context->properties->dict, true); } else { pw_log_warn("unknown module key '%s' in '%.*s'", key, (int)len, str); @@ -862,26 +860,25 @@ static int parse_objects(void *user_data, const char *location, { struct data *d = user_data; struct pw_context *context = d->context; - struct spa_json it[4]; + struct spa_json it[3]; char key[512]; int res = 0, r; spa_autofree char *s = strndup(str, len); - spa_json_init(&it[0], s, len); - if (spa_json_enter_array(&it[0], &it[1]) < 0) { + if (spa_json_begin_array(&it[0], s, len) < 0) { pw_log_error("config file error: context.objects is not an array"); return -EINVAL; } - while ((r = spa_json_enter_object(&it[1], &it[2])) > 0) { + while ((r = spa_json_enter_object(&it[0], &it[1])) > 0) { char *factory = NULL, *args = NULL, *flags = NULL; bool have_match = true; - while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) { + while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { const char *val; int l; - if ((l = spa_json_next(&it[2], &val)) <= 0) { + if ((l = spa_json_next(&it[1], &val)) <= 0) { pw_log_warn("malformed object: key '%s' has no " "value in '%.*s'", key, (int)len, str); break; @@ -892,13 +889,13 @@ static int parse_objects(void *user_data, const char *location, spa_json_parse_stringn(val, l, factory, l+1); } else if (spa_streq(key, "args")) { if (spa_json_is_container(val, l)) - l = spa_json_container_len(&it[2], val, l); + l = spa_json_container_len(&it[1], val, l); args = (char*)val; spa_json_parse_stringn(val, l, args, l+1); } else if (spa_streq(key, "flags")) { if (spa_json_is_container(val, l)) - l = spa_json_container_len(&it[2], val, l); + l = spa_json_container_len(&it[1], val, l); flags = (char*)val; spa_json_parse_stringn(val, l, flags, l+1); @@ -908,8 +905,8 @@ static int parse_objects(void *user_data, const char *location, (int)len, str); break; } - spa_json_enter(&it[2], &it[3]); - have_match = find_match(&it[3], &context->properties->dict, true); + spa_json_enter(&it[1], &it[2]); + have_match = find_match(&it[2], &context->properties->dict, true); } else { pw_log_warn("unknown object key '%s' in '%.*s'", key, (int)len, str); @@ -1046,29 +1043,28 @@ static int parse_exec(void *user_data, const char *location, { struct data *d = user_data; struct pw_context *context = d->context; - struct spa_json it[4]; + struct spa_json it[3]; char key[512]; int r, res = 0; spa_autofree char *s = strndup(str, len); - spa_json_init(&it[0], s, len); - if (spa_json_enter_array(&it[0], &it[1]) < 0) { + if (spa_json_begin_array(&it[0], s, len) < 0) { pw_log_error("config file error: context.exec is not an array in '%.*s'", (int)len, str); return -EINVAL; } - while ((r = spa_json_enter_object(&it[1], &it[2])) > 0) { + while ((r = spa_json_enter_object(&it[0], &it[1])) > 0) { char *path = NULL; const char *args_val = "[]"; int args_len = 2; bool have_match = true; - while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) { + while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { const char *val; int l; - if ((l = spa_json_next(&it[2], &val)) <= 0) { + if ((l = spa_json_next(&it[1], &val)) <= 0) { pw_log_warn("malformed exec: key '%s' has no " "value in '%.*s'", key, (int)len, str); break; @@ -1079,7 +1075,7 @@ static int parse_exec(void *user_data, const char *location, spa_json_parse_stringn(val, l, path, l+1); } else if (spa_streq(key, "args")) { if (spa_json_is_container(val, l)) - l = spa_json_container_len(&it[2], val, l); + l = spa_json_container_len(&it[1], val, l); args_val = val; args_len = l; } else if (spa_streq(key, "condition")) { @@ -1088,8 +1084,8 @@ static int parse_exec(void *user_data, const char *location, (int)len, str); goto next; } - spa_json_enter(&it[2], &it[3]); - have_match = find_match(&it[3], &context->properties->dict, true); + spa_json_enter(&it[1], &it[2]); + have_match = find_match(&it[2], &context->properties->dict, true); } else { pw_log_warn("unknown exec key '%s' in '%.*s'", key, (int)len, str); @@ -1307,31 +1303,30 @@ int pw_conf_match_rules(const char *str, size_t len, const char *location, void *data) { const char *val; - struct spa_json it[4], actions; + struct spa_json it[3], actions; int r; - spa_json_init(&it[0], str, len); - if (spa_json_enter_array(&it[0], &it[1]) < 0) { + if (spa_json_begin_array(&it[0], str, len) < 0) { pw_log_warn("expect array of match rules in: '%.*s'", (int)len, str); return 0; } - while ((r = spa_json_enter_object(&it[1], &it[2])) > 0) { + while ((r = spa_json_enter_object(&it[0], &it[1])) > 0) { char key[64]; bool have_match = false, have_actions = false; - while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) { + while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { if (spa_streq(key, "matches")) { - if (spa_json_enter_array(&it[2], &it[3]) < 0) { + if (spa_json_enter_array(&it[1], &it[2]) < 0) { pw_log_warn("expected array as matches in '%.*s'", (int)len, str); break; } - have_match = find_match(&it[3], props, false); + have_match = find_match(&it[2], props, false); } else if (spa_streq(key, "actions")) { - if (spa_json_enter_object(&it[2], &actions) > 0) + if (spa_json_enter_object(&it[1], &actions) > 0) have_actions = true; else pw_log_warn("expected object as match actions in '%.*s'", @@ -1339,7 +1334,7 @@ int pw_conf_match_rules(const char *str, size_t len, const char *location, } else { pw_log_warn("unknown match key '%s'", key); - if (spa_json_next(&it[2], &val) <= 0) { + if (spa_json_next(&it[1], &val) <= 0) { pw_log_warn("malformed match rule: key '%s' has " "no value in '%.*s'", key, (int)len, str); break; diff --git a/src/pipewire/context.c b/src/pipewire/context.c index f3e1b4d76..28ba56d4e 100644 --- a/src/pipewire/context.c +++ b/src/pipewire/context.c @@ -204,19 +204,18 @@ static int setup_data_loops(struct impl *impl) lib_name = pw_properties_get(this->properties, "context.data-loop." PW_KEY_LIBRARY_NAME_SYSTEM); if ((str = pw_properties_get(this->properties, "context.data-loops")) != NULL) { - struct spa_json it[4]; + struct spa_json it[2]; char key[512]; int r, len = strlen(str); spa_autofree char *s = strndup(str, len); i = 0; - spa_json_init(&it[0], s, len); - if (spa_json_enter_array(&it[0], &it[1]) < 0) { + if (spa_json_begin_array(&it[0], s, len) < 0) { pw_log_error("context.data-loops is not an array in '%s'", str); res = -EINVAL; goto exit; } - while ((r = spa_json_enter_object(&it[1], &it[2])) > 0) { + while ((r = spa_json_enter_object(&it[0], &it[1])) > 0) { char *props = NULL; if (i >= MAX_LOOPS) { @@ -229,17 +228,17 @@ static int setup_data_loops(struct impl *impl) pw_properties_update(pr, &this->properties->dict); pw_properties_set(pr, PW_KEY_LIBRARY_NAME_SYSTEM, lib_name); - while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) { + while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { const char *val; int l; - if ((l = spa_json_next(&it[2], &val)) <= 0) { + if ((l = spa_json_next(&it[1], &val)) <= 0) { pw_log_warn("malformed data-loop: key '%s' has no " "value in '%.*s'", key, (int)len, str); break; } if (spa_json_is_container(val, l)) - l = spa_json_container_len(&it[2], val, l); + l = spa_json_container_len(&it[1], val, l); props = (char*)val; spa_json_parse_stringn(val, l, props, l+1); diff --git a/src/pipewire/impl-port.c b/src/pipewire/impl-port.c index bbfa9ede6..daa30f1b4 100644 --- a/src/pipewire/impl-port.c +++ b/src/pipewire/impl-port.c @@ -1282,20 +1282,18 @@ int pw_impl_port_add(struct pw_impl_port *port, struct pw_impl_node *node) channel_names = pw_properties_get(nprops, PW_KEY_NODE_CHANNELNAMES); if (channel_names != NULL) { - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; uint32_t i; - spa_json_init(&it[0], channel_names, strlen(channel_names)); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], channel_names, strlen(channel_names)); + if (spa_json_begin_array_relax(&it[0], channel_names, strlen(channel_names)) > 0) { + for (i = 0; i < port->port_id + 1; i++) + if (spa_json_get_string(&it[0], v, sizeof(v)) <= 0) + break; - for (i = 0; i < port->port_id + 1; i++) - if (spa_json_get_string(&it[1], v, sizeof(v)) <= 0) - break; - - if (i == port->port_id + 1 && strlen(v) > 0) - snprintf(position, sizeof(position), "%s", v); + if (i == port->port_id + 1 && strlen(v) > 0) + snprintf(position, sizeof(position), "%s", v); + } } if (pw_properties_get(port->properties, PW_KEY_PORT_NAME) == NULL) { diff --git a/src/pipewire/properties.c b/src/pipewire/properties.c index c7fa6b78b..4f24203c6 100644 --- a/src/pipewire/properties.c +++ b/src/pipewire/properties.c @@ -210,7 +210,7 @@ exit_noupdate: static int update_string(struct pw_properties *props, const char *str, size_t size, int *count, struct spa_error_location *loc) { - struct spa_json it[2]; + struct spa_json it[1]; char key[1024]; struct spa_error_location el; bool err; @@ -220,29 +220,28 @@ static int update_string(struct pw_properties *props, const char *str, size_t si if (props) properties_init(&changes, 16); - spa_json_init(&it[0], str, size); - if (spa_json_enter_object(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], str, size); + if ((res = spa_json_begin_object_relax(&it[0], str, size)) <= 0) + return res; - while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { + while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) { int len; const char *value; char *val = NULL; - if ((len = spa_json_next(&it[1], &value)) <= 0) + if ((len = spa_json_next(&it[0], &value)) <= 0) break; if (spa_json_is_null(value, len)) val = NULL; else { if (spa_json_is_container(value, len)) - len = spa_json_container_len(&it[1], value, len); + len = spa_json_container_len(&it[0], value, len); if (len <= 0) break; if (props) { if ((val = malloc(len+1)) == NULL) { - it[1].state = SPA_JSON_ERROR_FLAG; + it[0].state = SPA_JSON_ERROR_FLAG; break; } spa_json_parse_stringn(value, len, val, len+1); @@ -257,12 +256,12 @@ static int update_string(struct pw_properties *props, const char *str, size_t si } /* item changed or added, apply changes later */ if ((errno = -add_item(&changes, key, false, val, true) < 0)) { - it[1].state = SPA_JSON_ERROR_FLAG; + it[0].state = SPA_JSON_ERROR_FLAG; break; } } } - if ((err = spa_json_get_error(&it[1], str, &el))) { + if ((err = spa_json_get_error(&it[0], str, &el))) { if (loc == NULL) spa_debug_log_error_location(pw_log_get(), SPA_LOG_LEVEL_WARN, &el, "error parsing more than %d properties: %s", diff --git a/src/pipewire/settings.c b/src/pipewire/settings.c index 350efc690..597e686a9 100644 --- a/src/pipewire/settings.c +++ b/src/pipewire/settings.c @@ -90,14 +90,13 @@ static bool uint32_array_contains(uint32_t *vals, uint32_t n_vals, uint32_t val) static uint32_t parse_uint32_array(const char *str, uint32_t *vals, uint32_t max, uint32_t def) { uint32_t count = 0, r; - struct spa_json it[2]; + struct spa_json it[1]; char v[256]; - spa_json_init(&it[0], str, strlen(str)); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], str, strlen(str)); + if (spa_json_begin_array_relax(&it[0], str, strlen(str)) <= 0) + return 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && count < max) { if (spa_atou32(v, &r, 0)) vals[count++] = r; diff --git a/src/pipewire/thread.c b/src/pipewire/thread.c index 4fda54286..c67c4632a 100644 --- a/src/pipewire/thread.c +++ b/src/pipewire/thread.c @@ -27,15 +27,14 @@ do { \ static int parse_affinity(const char *affinity, cpu_set_t *set) { - struct spa_json it[2]; + struct spa_json it[1]; int v; CPU_ZERO(set); - spa_json_init(&it[0], affinity, strlen(affinity)); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], affinity, strlen(affinity)); + if (spa_json_begin_array_relax(&it[0], affinity, strlen(affinity)) <= 0) + return 0; - while (spa_json_get_int(&it[1], &v) > 0) { + while (spa_json_get_int(&it[0], &v) > 0) { if (v >= 0 && v < CPU_SETSIZE) CPU_SET(v, set); } diff --git a/src/pipewire/utils.c b/src/pipewire/utils.c index 4db73a049..103058a6c 100644 --- a/src/pipewire/utils.c +++ b/src/pipewire/utils.c @@ -130,7 +130,7 @@ SPA_EXPORT char **pw_strv_parse(const char *val, size_t len, int max_tokens, int *n_tokens) { struct pw_array arr; - struct spa_json it[2]; + struct spa_json it[1]; int n = 0, l, res; const char *value; struct spa_error_location el; @@ -140,11 +140,10 @@ char **pw_strv_parse(const char *val, size_t len, int max_tokens, int *n_tokens) pw_array_init(&arr, sizeof(char*) * 16); - spa_json_init(&it[0], val, len); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], val, len); + if (spa_json_begin_array_relax(&it[0], val, len) <= 0) + return NULL; - while ((l = spa_json_next(&it[1], &value)) > 0 && n + 1 < max_tokens) { + while ((l = spa_json_next(&it[0], &value)) > 0 && n + 1 < max_tokens) { char *s; if ((s = malloc(l+1)) == NULL) @@ -161,7 +160,7 @@ char **pw_strv_parse(const char *val, size_t len, int max_tokens, int *n_tokens) if ((res = pw_array_add_ptr(&arr, NULL)) < 0) goto error; done: - if ((res = spa_json_get_error(&it[1], val, &el))) { + if ((res = spa_json_get_error(&it[0], val, &el))) { spa_debug_log_error_location(pw_log_get(), SPA_LOG_LEVEL_WARN, &el, "error parsing strv: %s", el.reason); @@ -179,7 +178,7 @@ done: error_errno: res = -errno; error: - it[1].state = SPA_JSON_ERROR_FLAG; + it[0].state = SPA_JSON_ERROR_FLAG; errno = -res; goto done; } diff --git a/src/tools/pw-dot.c b/src/tools/pw-dot.c index b02cb55c4..3398ce229 100644 --- a/src/tools/pw-dot.c +++ b/src/tools/pw-dot.c @@ -1276,7 +1276,7 @@ static int get_data_from_json(struct data *data, const char *json_path) int fd, len; void *json; struct stat sbuf; - struct spa_json it[2]; + struct spa_json it[1]; const char *value; struct spa_error_location loc; @@ -1296,18 +1296,16 @@ static int get_data_from_json(struct data *data, const char *json_path) } close(fd); - spa_json_init(&it[0], json, sbuf.st_size); - - if (spa_json_enter_array(&it[0], &it[1]) <= 0) { + if (spa_json_begin_array(&it[0], json, sbuf.st_size) <= 0) { fprintf(stderr, "expected top-level array in JSON file '%s'\n", json_path); munmap(json, sbuf.st_size); return -1; } - while ((len = spa_json_next(&it[1], &value)) > 0 && spa_json_is_object(value, len)) { + while ((len = spa_json_next(&it[0], &value)) > 0 && spa_json_is_object(value, len)) { struct pw_properties *obj; obj = pw_properties_new(NULL, NULL); - len = spa_json_container_len(&it[1], value, len); + len = spa_json_container_len(&it[0], value, len); pw_properties_update_string(obj, value, len); handle_json_obj(data, obj); pw_properties_free(obj);