From a02f99a7b40c51a014ab2cead4bf2371ba000ed5 Mon Sep 17 00:00:00 2001 From: Tony van der Peet Date: Tue, 25 Jun 2024 11:18:42 +1200 Subject: [PATCH] sch_gnode_to_json: fix concatentation of model and name It was possible that name included the model prefix and this is not supposed to show. Construct the model:name correctly by excluding the prefix if it is present. --- schema.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/schema.c b/schema.c index 1a55620..6e13161 100644 --- a/schema.c +++ b/schema.c @@ -3602,6 +3602,25 @@ _sch_gnode_to_json (sch_instance * instance, sch_node * schema, xmlNs *ns, GNode return data; } +static gchar * +_model_name (xmlNs *ns, char *model, char *name) +{ + gchar *ret; + gchar **n_split = g_strsplit (name, ":", 2); + + /* If first part of name is actually the namespace prefix, we don't want to see it */ + if (g_strv_length (n_split) == 2 && g_strcmp0 (n_split[0], (gchar *) ns->prefix) == 0) + { + ret = g_strdup_printf ("%s:%s", model, n_split[1]); + } + else + { + ret = g_strdup_printf ("%s:%s", model, name); + } + g_strfreev (n_split); + return ret; +} + json_t * sch_gnode_to_json (sch_instance * instance, sch_node * schema, GNode * node, int flags) { @@ -3632,7 +3651,7 @@ sch_gnode_to_json (sch_instance * instance, sch_node * schema, GNode * node, int char * model = sch_model (schema, false); if (model) { - name = g_strdup_printf ("%s:%s", model, name); + name = _model_name (ns, model, name); json = json_object (); json_object_set_new (json, name, child); free (name);