diff --git a/src/examples/media-session/match-rules.c b/src/examples/media-session/match-rules.c index 9dd79f691..af0033c26 100644 --- a/src/examples/media-session/match-rules.c +++ b/src/examples/media-session/match-rules.c @@ -39,18 +39,18 @@ static bool find_match(struct spa_json *arr, struct pw_properties *props) { - struct spa_json it[1]; + struct spa_json match_obj; - while (spa_json_enter_object(arr, &it[0]) > 0) { + while (spa_json_enter_object(arr, &match_obj) > 0) { char key[256], val[1024]; const char *str, *value; int match = 0, fail = 0; int len; - while (spa_json_get_string(&it[0], key, sizeof(key)-1) > 0) { + while (spa_json_get_string(&match_obj, key, sizeof(key)-1) > 0) { bool success = false; - if ((len = spa_json_next(&it[0], &value)) <= 0) + if ((len = spa_json_next(&match_obj, &value)) <= 0) break; str = pw_properties_get(props, key); @@ -91,28 +91,32 @@ static bool find_match(struct spa_json *arr, struct pw_properties *props) int sm_media_session_match_rules(const char *rules, size_t size, struct pw_properties *props) { const char *val; - struct spa_json it[4], actions; + struct spa_json actions; + struct spa_json it_rules; /* the rules = [] array */ + struct spa_json it_rules_obj; /* one object within that array */ + struct spa_json it_element; /* key/value element within that object */ - spa_json_init(&it[0], rules, size); - if (spa_json_enter_array(&it[0], &it[1]) < 0) + spa_json_init(&it_rules, rules, size); + if (spa_json_enter_array(&it_rules, &it_rules_obj) < 0) return 0; - while (spa_json_enter_object(&it[1], &it[2]) > 0) { + while (spa_json_enter_object(&it_rules_obj, &it_element) > 0) { char key[64]; bool have_match = false, have_actions = false; - while (spa_json_get_string(&it[2], key, sizeof(key)-1) > 0) { + while (spa_json_get_string(&it_element, key, sizeof(key)-1) > 0) { if (spa_streq(key, "matches")) { - if (spa_json_enter_array(&it[2], &it[3]) < 0) + struct spa_json it_matches_array; + if (spa_json_enter_array(&it_element, &it_matches_array) < 0) break; - have_match = find_match(&it[3], props); + have_match = find_match(&it_matches_array, props); } else if (spa_streq(key, "actions")) { - if (spa_json_enter_object(&it[2], &actions) > 0) + if (spa_json_enter_object(&it_element, &actions) > 0) have_actions = true; } - else if (spa_json_next(&it[2], &val) <= 0) + else if (spa_json_next(&it_element, &val) <= 0) break; } if (!have_match || !have_actions)