properties: improve containter serialize

If we are not recursing, take the complete property value without
attempting to parse it as json, only do this when recursing.

If the property value looks like a container is is exactly of the right
length, print is as a container, otherwise print is as string.

This makes properties like "[192.0.0.1]:45000" be printed as a string
instead of the array [192.0.0.1]. but still makes "[FL FR]" be an
array.

Fixes #3290
This commit is contained in:
Wim Taymans 2023-06-16 17:36:25 +02:00
parent 7c7e814b02
commit 81fd6d5275

View file

@ -706,8 +706,11 @@ static int dump(struct dump_config *c, int indent, struct spa_json *it, const ch
if (value == NULL || len == 0) {
fprintf(file, "%snull%s", LITERAL(c), NORMAL(c));
} else if (spa_json_is_container(value, len) && !c->recurse) {
len = spa_json_container_len(it, value, len);
fprintf(file, "%s%.*s%s", CONTAINER(c), len, value, NORMAL(c));
spa_json_enter_container(it, &sub, value[0]);
if (spa_json_container_len(&sub, value, len) == len)
fprintf(file, "%s%.*s%s", CONTAINER(c), len, value, NORMAL(c));
else
encode_string(c, STRING(c), value, len, NORMAL(c));
} else if (spa_json_is_array(value, len)) {
fprintf(file, "[");
spa_json_enter(it, &sub);
@ -782,15 +785,11 @@ int pw_properties_serialize_dict(FILE *f, const struct spa_dict *dict, uint32_t
fprintf(f, "%s%s%s: ", KEY(c), key, NORMAL(c));
}
value = it->value;
len = value ? strlen(value) : 0;
spa_json_init(&sub, value, len);
if ((len = spa_json_next(&sub, &value)) < 0)
if (c->recurse && spa_json_next(&sub, &value) < 0)
break;
if (!spa_json_is_container(value, len))
len = value ? strlen(value) : 0;
dump(c, c->indent, &sub, value, len);
count++;
}