From 81fd6d5275716e010458252daf2d3b82abacf18b Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 16 Jun 2023 17:36:25 +0200 Subject: [PATCH] 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 --- src/pipewire/properties.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/pipewire/properties.c b/src/pipewire/properties.c index cce9c6f1b..2840d993b 100644 --- a/src/pipewire/properties.c +++ b/src/pipewire/properties.c @@ -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++; }