From 95f45bda93d0dcb97c84f97f1e474426383d3f9e Mon Sep 17 00:00:00 2001 From: Graeme Campbell Date: Thu, 11 Apr 2024 14:14:40 +1200 Subject: [PATCH] Fix the addition or deletion of leaf-lists from Netconf. This change modifies _sch_xml_to_gnode and fixes the addition and deletion of leaf-lists. A number of new tests will be added to the apteryx-netconf repository to test the new functionality. --- schema.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/schema.c b/schema.c index 28452c4..3894aa3 100644 --- a/schema.c +++ b/schema.c @@ -3406,10 +3406,36 @@ _sch_xml_to_gnode (_sch_xml_to_gnode_parms *_parms, sch_node * schema, xmlNs *ns /* LIST */ if (sch_is_leaf_list (schema)) { + char *old_xpath = new_xpath; + char *key_value = NULL; + DEBUG (_parms->in_flags, "%*s%s%s\n", depth * 2, " ", depth ? "" : "/", name); tree = APTERYX_NODE (NULL, g_strdup (name)); - node = APTERYX_NODE (tree, g_strdup ("*")); schema = sch_node_child_first (schema); + + if (xml_node_has_content (xml)) + { + key_value = (char *) xmlNodeGetContent (xml); + if (g_strcmp0 (new_op, "delete") == 0 || g_strcmp0 (new_op, "remove") == 0 || + g_strcmp0 (new_op, "none") == 0) + { + new_xpath = g_strdup_printf ("%s/%s", old_xpath, key_value); + } + else + { + new_xpath = g_strdup_printf ("%s/%s/%s", old_xpath, key_value, key_value); + node = APTERYX_NODE (tree, g_strdup (key_value)); + node = APTERYX_NODE (node, g_strdup (key_value)); + } + g_free (key_value); + g_free (old_xpath); + ret_tree = true; + } + else + { + node = APTERYX_NODE (tree, g_strdup ("*")); + } + if (rschema) *rschema = schema; }