mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
properties: just use the parser in all cases
We can just use the json parser to parse the old key=val syntax as well now.
This commit is contained in:
parent
f29bc42b4d
commit
2fd35488c7
2 changed files with 21 additions and 42 deletions
|
|
@ -150,57 +150,36 @@ int pw_properties_update_string(struct pw_properties *props, const char *str, si
|
||||||
{
|
{
|
||||||
struct properties *impl = SPA_CONTAINER_OF(props, struct properties, this);
|
struct properties *impl = SPA_CONTAINER_OF(props, struct properties, this);
|
||||||
struct spa_json it[2];
|
struct spa_json it[2];
|
||||||
|
char key[1024], *val;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
spa_json_init(&it[0], str, size);
|
spa_json_init(&it[0], str, size);
|
||||||
if (spa_json_enter_object(&it[0], &it[1]) > 0) {
|
if (spa_json_enter_object(&it[0], &it[1]) <= 0)
|
||||||
char key[1024], *val;
|
spa_json_init(&it[1], str, size);
|
||||||
|
|
||||||
while (spa_json_get_string(&it[1], key, sizeof(key)-1)) {
|
while (spa_json_get_string(&it[1], key, sizeof(key)-1)) {
|
||||||
int len;
|
int len;
|
||||||
const char *value;
|
const char *value;
|
||||||
|
|
||||||
if ((len = spa_json_next(&it[1], &value)) <= 0)
|
if ((len = spa_json_next(&it[1], &value)) <= 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (key[0] == '#')
|
if (key[0] == '#')
|
||||||
continue;
|
continue;
|
||||||
if (spa_json_is_null(value, len))
|
if (spa_json_is_null(value, len))
|
||||||
val = NULL;
|
val = NULL;
|
||||||
else {
|
else {
|
||||||
if (spa_json_is_container(value, len))
|
if (spa_json_is_container(value, len))
|
||||||
len = spa_json_container_len(&it[1], value, len);
|
len = spa_json_container_len(&it[1], value, len);
|
||||||
|
|
||||||
if ((val = strndup(value, len)) == NULL)
|
if ((val = strndup(value, len)) == NULL)
|
||||||
return -errno;
|
|
||||||
|
|
||||||
if (spa_json_is_string(value, len))
|
|
||||||
spa_json_parse_string(value, len, val);
|
|
||||||
}
|
|
||||||
count += pw_properties_set(&impl->this, key, val);
|
|
||||||
free(val);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const char *state = NULL, *s = NULL;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
s = pw_split_walk(str, " \t\n\r", &len, &state);
|
|
||||||
while (s) {
|
|
||||||
char *val, *eq;
|
|
||||||
|
|
||||||
if (s[0] == '#')
|
|
||||||
continue;
|
|
||||||
if ((val = strndup(s, len)) == NULL)
|
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
eq = strchr(val, '=');
|
if (spa_json_is_string(value, len))
|
||||||
if (eq && eq != val) {
|
spa_json_parse_string(value, len, val);
|
||||||
*eq = '\0';
|
|
||||||
count += pw_properties_set(&impl->this, val, eq+1);
|
|
||||||
}
|
|
||||||
free(val);
|
|
||||||
s = pw_split_walk(str, " \t\n\r", &len, &state);
|
|
||||||
}
|
}
|
||||||
|
count += pw_properties_set(&impl->this, key, val);
|
||||||
|
free(val);
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -211,7 +211,7 @@ static void test_new_string(void)
|
||||||
{
|
{
|
||||||
struct pw_properties *props;
|
struct pw_properties *props;
|
||||||
|
|
||||||
props = pw_properties_new_string("foo=bar bar=baz ignore him=too empty= =gg");
|
props = pw_properties_new_string("foo=bar bar=baz \"#ignore\"=ignore him=too empty=\"\" =gg");
|
||||||
spa_assert(props != NULL);
|
spa_assert(props != NULL);
|
||||||
spa_assert(props->flags == 0);
|
spa_assert(props->flags == 0);
|
||||||
spa_assert(props->dict.n_items == 4);
|
spa_assert(props->dict.n_items == 4);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue