From ad7232d1ada9602b6c5302082e1698f6aa3de227 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Fri, 26 Aug 2022 13:29:06 +0200 Subject: [PATCH] Added top-level namespaces when pruning XML tree for client rpc calls and restconf GET Added new xmlns_set_all() --- apps/backend/backend_get.c | 1 - apps/restconf/restconf_methods_get.c | 19 +++++++-------- lib/clixon/clixon_xml.h | 2 -- lib/clixon/clixon_xml_nsctx.h | 2 ++ lib/src/clixon_proto_client.c | 29 +++++++++++++++++++++- lib/src/clixon_text_syntax_parse.y | 1 + lib/src/clixon_xml_nsctx.c | 36 ++++++++++++++++++++++++++++ test/test_debug.sh | 2 +- test/test_perf_restconf.sh | 4 ++-- test/test_perf_restconf_ssl.sh | 4 ++-- test/test_restconf_op.sh | 2 +- test/test_restconf_plain_patch.sh | 2 +- test/test_yang_with_defaults.sh | 2 +- 13 files changed, 83 insertions(+), 23 deletions(-) diff --git a/apps/backend/backend_get.c b/apps/backend/backend_get.c index d87b382c..6babc9ae 100644 --- a/apps/backend/backend_get.c +++ b/apps/backend/backend_get.c @@ -525,7 +525,6 @@ with_defaults(cxobj *xe, cxobj *xret) { } } } - ok: retval = 0; done: return retval; diff --git a/apps/restconf/restconf_methods_get.c b/apps/restconf/restconf_methods_get.c index cbb13f41..de28c60e 100644 --- a/apps/restconf/restconf_methods_get.c +++ b/apps/restconf/restconf_methods_get.c @@ -116,7 +116,6 @@ api_data_get2(clicon_handle h, int i; cxobj *x; int ret; - char *namespace = NULL; cvec *nsc = NULL; char *attr; /* attribute value string */ netconf_content content = CONTENT_ALL; @@ -124,7 +123,8 @@ api_data_get2(clicon_handle h, cxobj *xtop = NULL; cxobj *xbot = NULL; yang_stmt *y = NULL; - char *defaults = NULL; + char *defaults = NULL; + cvec *nscd = NULL; clicon_debug(1, "%s", __FUNCTION__); if ((yspec = clicon_dbspec_yang(h)) == NULL){ @@ -266,16 +266,11 @@ api_data_get2(clicon_handle h, switch (media_out){ case YANG_DATA_XML: for (i=0; i="" */ + ns = xml_find_type_value(x, "xmlns", pf, CX_ATTR); + else{ /* xmlns="" */ + ns = xml_find_type_value(x, NULL, "xmlns", CX_ATTR); + } + if (ns) + continue; + ns = cv_string_get(cv); + if (ns && xmlns_set(x, pf, ns) < 0) + goto done; + } + retval = 0; + done: + return retval; +} + /*! Get prefix of given namespace recursively * @param[in] xn XML node * @param[in] namespace Namespace diff --git a/test/test_debug.sh b/test/test_debug.sh index 07ac0987..d1fe80ad 100755 --- a/test/test_debug.sh +++ b/test/test_debug.sh @@ -89,7 +89,7 @@ expectpart "$($clixon_cli -1 -f $cfg -l o debug backend 1)" 0 "^$" # Exercise debug code new "get and put config using restconf" -expectpart "$(curl $CURLOPTS -H "Accept: application/yang-data+xml" -X GET $RCPROTO://localhost/restconf/data?content=config --next $CURLOPTS -H "Content-Type: application/yang-data+json" -X POST $RCPROTO://localhost/restconf/data -d '{"example:table":{"parameter":{"name":"local0","value":"foo"}}}')" 0 "HTTP/$HVER 200" '' "HTTP/$HVER 201" +expectpart "$(curl $CURLOPTS -H "Accept: application/yang-data+xml" -X GET $RCPROTO://localhost/restconf/data?content=config --next $CURLOPTS -H "Content-Type: application/yang-data+json" -X POST $RCPROTO://localhost/restconf/data -d '{"example:table":{"parameter":{"name":"local0","value":"foo"}}}')" 0 "HTTP/$HVER 200" "" "HTTP/$HVER 201" # In freebsd, backend dies in stop_restconf below unless sleep sleep $DEMSLEEP diff --git a/test/test_perf_restconf.sh b/test/test_perf_restconf.sh index 294f4d75..68bc6245 100755 --- a/test/test_perf_restconf.sh +++ b/test/test_perf_restconf.sh @@ -146,11 +146,11 @@ fi # XXX ftest har \n # Only compare relevant data line -echo -n "">> $ftest +echo -n "">> $ftest cat $fdataxml >> $ftest echo -n "" >> $ftest # -i (ignore case) dont always work properly -sed '//!d' $foutput > $foutput2 +sed "//!d" $foutput > $foutput2 # Strip potential newlines, curl seems to leave trailing newlines on some platforms/versions tr -d "\n\r" < $foutput2 > $foutput diff --git a/test/test_perf_restconf_ssl.sh b/test/test_perf_restconf_ssl.sh index 91ce054e..0e230fd9 100755 --- a/test/test_perf_restconf_ssl.sh +++ b/test/test_perf_restconf_ssl.sh @@ -161,11 +161,11 @@ if [ $r -ne 0 ]; then fi # Only compare relevant data line -echo -n "">> $ftest +echo -n "">> $ftest cat $fdataxml >> $ftest #echo " " >> $ftest echo -n "" >> $ftest -sed '//!d' $foutput > $foutput2 +sed "//!d" $foutput > $foutput2 mv $foutput2 $foutput ret=$(diff -i $ftest $foutput) diff --git a/test/test_restconf_op.sh b/test/test_restconf_op.sh index 10988de4..2256cb26 100755 --- a/test/test_restconf_op.sh +++ b/test/test_restconf_op.sh @@ -206,7 +206,7 @@ expectpart "$(curl $CURLOPTS -X DELETE $RCPROTO://localhost/restconf/data)" 0 "H #--------------- Multiple request in single TCP tests new "Multiple requests: GET + POST using --next" -expectpart "$(curl $CURLOPTS -H "Accept: application/yang-data+xml" -X GET $RCPROTO://localhost/restconf/data?content=config --next $CURLOPTS -H "Content-Type: application/yang-data+json" -X POST $RCPROTO://localhost/restconf/data -d '{"example:cont1":{"interface":{"name":"local0","type":"regular"}}}')" 0 "HTTP/$HVER 200" '' "HTTP/$HVER 201" +expectpart "$(curl $CURLOPTS -H "Accept: application/yang-data+xml" -X GET $RCPROTO://localhost/restconf/data?content=config --next $CURLOPTS -H "Content-Type: application/yang-data+json" -X POST $RCPROTO://localhost/restconf/data -d '{"example:cont1":{"interface":{"name":"local0","type":"regular"}}}')" 0 "HTTP/$HVER 200" "" "HTTP/$HVER 201" new "Multiple requests: POST + POST" # XXX Do for HTTP/1 ALSO expectpart "$(curl $CURLOPTS -H "Content-Type: application/yang-data+json" -X POST $RCPROTO://localhost/restconf/data/example:cont1 -d '{"example:interface":{"name":"local1","type":"regular"}}' --next $CURLOPTS -H "Content-Type: application/yang-data+json" -X POST $RCPROTO://localhost/restconf/data/example:cont1 -d '{"example:interface":{"name":"local2","type":"regular"}}')" 0 "HTTP/$HVER 201" "localhost/restconf/data/example:cont1/interface=local1" "localhost/restconf/data/example:cont1/interface=local2" diff --git a/test/test_restconf_plain_patch.sh b/test/test_restconf_plain_patch.sh index bf2348ff..5d628022 100755 --- a/test/test_restconf_plain_patch.sh +++ b/test/test_restconf_plain_patch.sh @@ -252,7 +252,7 @@ new "PATCH on root resource extra c" # merge extra/c expectpart "$(curl -u andy:bar $CURLOPTS -X PATCH -H "Content-Type: application/yang-data+json" $RCPROTO://localhost/restconf/data -d '{"ietf-restconf:data":{"example-jukebox:extra":"c"}}')" 0 "HTTP/$HVER 204" new "GET check" # XXX: "data" should probably be namespaced? -expectpart "$(curl -u andy:bar $CURLOPTS -X GET $RCPROTO://localhost/restconf/data?content=config -H 'Accept: application/yang-data+xml')" 0 "HTTP/$HVER 200" 'c' '' +expectpart "$(curl -u andy:bar $CURLOPTS -X GET $RCPROTO://localhost/restconf/data?content=config -H 'Accept: application/yang-data+xml')" 0 "HTTP/$HVER 200" 'c' "" new "Add empty leaf" expectpart "$(curl -u andy:bar $CURLOPTS -X POST $RCPROTO://localhost/restconf/data -H 'Content-Type: application/yang-data+json' -d '{"example-system:system":{"extraleaf":""}}')" 0 "HTTP/$HVER 201" diff --git a/test/test_yang_with_defaults.sh b/test/test_yang_with_defaults.sh index 18215be4..455fa9db 100755 --- a/test/test_yang_with_defaults.sh +++ b/test/test_yang_with_defaults.sh @@ -479,7 +479,7 @@ expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+xml' $RCPR "HTTP/$HVER 200" \ "Content-Type: application/yang-data+xml" \ "Cache-Control: no-cache" \ -'eth11500ok' +'eth11500ok' if [ $RC -ne 0 ]; then