diff --git a/CHANGELOG.md b/CHANGELOG.md index 30b8e72f..940860b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -86,6 +86,7 @@ If you submit "nopresence" without a leaf, it will automatically be removed: * You need to define state data in a backend callback. See the example and documentation for more details. ### Minor changes: +* Added prefix parsing of xpath, allowing eg /p:x/p:y, but prefix ignored. * Corrected Yang union CLI generation and type validation. Recursive unions did not work. * Corrected Yang pattern type escaping problem, ie '\.' did not work properly. This requires update of cligen as well. * Compliance with RFC: Rename yang xpath to schema_nodeid and syntaxnode to datanode. diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index 84389dd4..39f1cb39 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -885,7 +885,7 @@ from_client_msg(clicon_handle h, cxobj *xt = NULL; cxobj *x; cxobj *xe; - char *name; + char *name = NULL; char *db; cbuf *cbret = NULL; /* return message */ int pid; diff --git a/lib/src/clixon_xml_map.c b/lib/src/clixon_xml_map.c index 01fa5dcc..dccf0fa5 100644 --- a/lib/src/clixon_xml_map.c +++ b/lib/src/clixon_xml_map.c @@ -1979,9 +1979,6 @@ xml_merge(cxobj *x0, cxobj *x1c; /* mod child */ yang_stmt *yc; - /* Assure top-levels are 'config' */ - assert(x0 && strcmp(xml_name(x0),"config")==0); - assert(x1 && strcmp(xml_name(x1),"config")==0); /* Loop through children of the modification tree */ x1c = NULL; while ((x1c = xml_child_each(x1, x1c, CX_ELMNT)) != NULL) { diff --git a/lib/src/clixon_xsl.c b/lib/src/clixon_xsl.c index 5b953c04..0d3146d4 100644 --- a/lib/src/clixon_xsl.c +++ b/lib/src/clixon_xsl.c @@ -150,6 +150,7 @@ struct xpath_predicate{ struct xpath_element{ struct xpath_element *xe_next; enum axis_type xe_type; + char *xe_prefix; /* eg for namespaces */ char *xe_str; /* eg for child */ struct xpath_predicate *xe_predicate; /* eg within [] */ }; @@ -217,6 +218,7 @@ xpath_element_new(enum axis_type atype, struct xpath_element *xe; char *str1 = NULL; char *pred; + char *local; if ((xe = malloc(sizeof(*xe))) == NULL){ clicon_err(OE_UNIX, errno, "malloc"); @@ -232,7 +234,18 @@ xpath_element_new(enum axis_type atype, if (xpath_split(str1, &pred) < 0) /* Can be more predicates */ goto done; if (strlen(str1)){ - if ((xe->xe_str = strdup(str1)) == NULL){ + /* Split into prefix and localname */ + if ((local = index(str1, ':')) != NULL){ + *local = '\0'; + local++; + if ((xe->xe_prefix = strdup(str1)) == NULL){ + clicon_err(OE_XML, errno, "%s: strdup", __FUNCTION__); + goto done; + } + } + else + local = str1; + if ((xe->xe_str = strdup(local)) == NULL){ clicon_err(OE_XML, errno, "%s: strdup", __FUNCTION__); goto done; } @@ -264,6 +277,8 @@ xpath_element_free(struct xpath_element *xe) if (xe->xe_str) free(xe->xe_str); + if (xe->xe_prefix) + free(xe->xe_prefix); while ((xp = xe->xe_predicate) != NULL){ xe->xe_predicate = xp->xp_next; if (xp->xp_expr) diff --git a/test/test_leafref.sh b/test/test_leafref.sh index 6c74f070..e500d5b4 100755 --- a/test/test_leafref.sh +++ b/test/test_leafref.sh @@ -11,40 +11,30 @@ clixon_cli=clixon_cli cat < /tmp/leafref.yang module example{ - typedef admin-status{ - type string; - } - list interface { - key "name"; - leaf name { - type string; - } - leaf admin-status { - type admin-status; - } - list address { - key "ip"; - leaf ip { - type string; + import ietf-ip { + prefix ip; + } + container default-address { + leaf absname { + type leafref { + path "/ip:interfaces/ip:interface/ip:name"; } } - } - container default-address { - leaf ifname { + leaf relname { type leafref { - path "../../interface/name"; + path "../../interfaces/interface/name"; } } leaf address { type leafref { - path "../../interface[name=eth0]" + path "../../interfaces/interface[name=eth0]" + "/address/ip"; } } } } EOF -# path "../../interface[name = current()/../ifname]" +# XXX not eth0 path "../../interface[name = current()/../ifname]" # kill old backend (if any) new "kill old backend" @@ -61,16 +51,17 @@ if [ $? -ne 0 ]; then fi new "leafref base config" -expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" "eth0up
192.0.2.1
192.0.2.2
loup
127.0.0.1
]]>]]>" "^]]>]]>$" +expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" " +eth0 eth
192.0.2.1
192.0.2.2
lolo
127.0.0.1
]]>]]>" "^]]>]]>$" new "leafref get config" -expecteof "$clixon_netconf -qf $clixon_cf" ']]>]]>' '^eth0' +expecteof "$clixon_netconf -qf $clixon_cf" ']]>]]>' '^eth0' new "leafref base commit" expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" "]]>]]>" "^]]>]]>$" new "leafref add wrong ref" -expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" "eth3
10.0.4.6
]]>]]>" "^]]>]]>$" +expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" "eth3
10.0.4.6
]]>]]>" "^]]>]]>$" new "leafref validate" expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" "]]>]]>" "^missing-attribute" @@ -78,18 +69,31 @@ expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" " new "leafref discard-changes" expecteof "$clixon_netconf -qf $clixon_cf" "]]>]]>" "^]]>]]>$" -new "leafref add correct ref" -expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" "eth0
192.0.2.2
]]>]]>" "^]]>]]>$" +new "leafref add correct absref" +expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" "eth0]]>]]>" "^]]>]]>$" + +new "leafref add correct relref" +expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" "eth0]]>]]>" "^]]>]]>$" + +# XXX add address new "leafref validate (ok)" expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" "]]>]]>" "^" new "leafref delete leaf" -expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" "eth0]]>]]>" "^" +expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" "eth0]]>]]>" "^" new "leafref validate (should fail)" expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" "]]>]]>" "^missing-attribute" +new "leafref discard-changes" +expecteof "$clixon_netconf -qf $clixon_cf" "]]>]]>" "^]]>]]>$" + +new "cli leafref lo" +expectfn "$clixon_cli -1f $clixon_cf -y /tmp/leafref.yang -l o set default-address absname lo" "^$" + +new "cli leafref validate" +expectfn "$clixon_cli -1f $clixon_cf -y /tmp/leafref.yang -l o validate" "^$" new "Kill backend" # Check if still alive