mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-07 13:30:09 -05:00
media-session: use more descriptive names for parsing match rules
Easier to understand this way what is being passed around and where we're at with the parsing.
This commit is contained in:
parent
7d13c7750d
commit
6f9586bf54
1 changed files with 17 additions and 13 deletions
|
|
@ -39,18 +39,18 @@
|
||||||
|
|
||||||
static bool find_match(struct spa_json *arr, struct pw_properties *props)
|
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];
|
char key[256], val[1024];
|
||||||
const char *str, *value;
|
const char *str, *value;
|
||||||
int match = 0, fail = 0;
|
int match = 0, fail = 0;
|
||||||
int len;
|
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;
|
bool success = false;
|
||||||
|
|
||||||
if ((len = spa_json_next(&it[0], &value)) <= 0)
|
if ((len = spa_json_next(&match_obj, &value)) <= 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
str = pw_properties_get(props, key);
|
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)
|
int sm_media_session_match_rules(const char *rules, size_t size, struct pw_properties *props)
|
||||||
{
|
{
|
||||||
const char *val;
|
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);
|
spa_json_init(&it_rules, rules, size);
|
||||||
if (spa_json_enter_array(&it[0], &it[1]) < 0)
|
if (spa_json_enter_array(&it_rules, &it_rules_obj) < 0)
|
||||||
return 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];
|
char key[64];
|
||||||
bool have_match = false, have_actions = false;
|
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_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;
|
break;
|
||||||
|
|
||||||
have_match = find_match(&it[3], props);
|
have_match = find_match(&it_matches_array, props);
|
||||||
}
|
}
|
||||||
else if (spa_streq(key, "actions")) {
|
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;
|
have_actions = true;
|
||||||
}
|
}
|
||||||
else if (spa_json_next(&it[2], &val) <= 0)
|
else if (spa_json_next(&it_element, &val) <= 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!have_match || !have_actions)
|
if (!have_match || !have_actions)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue