From 51ebbdf12f2e2a07f307b10de42222bceffe5cde Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Fri, 27 Jan 2023 10:59:20 +0100 Subject: [PATCH] * C-API: Added `clicon_handle` parameter to all `xml_bind_*` calls --- CHANGELOG.md | 1 + apps/backend/backend_client.c | 2 +- apps/backend/backend_commit.c | 4 +- apps/backend/backend_get.c | 2 +- apps/backend/backend_plugin.c | 2 +- apps/backend/backend_startup.c | 2 +- apps/netconf/netconf_main.c | 2 +- apps/netconf/netconf_rpc.c | 2 +- apps/restconf/restconf_methods_post.c | 4 +- lib/clixon/clixon_xml_bind.h | 8 +-- lib/src/clixon_datastore_read.c | 5 +- lib/src/clixon_file.c | 4 +- lib/src/clixon_json.c | 8 +-- lib/src/clixon_proto_client.c | 8 +-- lib/src/clixon_text_syntax.c | 4 +- lib/src/clixon_validate.c | 2 +- lib/src/clixon_xml_bind.c | 90 +++++++++++++++++++-------- lib/src/clixon_xml_default.c | 2 +- lib/src/clixon_xml_io.c | 8 +-- util/clixon_util_path.c | 2 +- util/clixon_util_xpath.c | 2 +- 21 files changed, 102 insertions(+), 62 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b03f41b9..efd55f84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,7 @@ Developers may need to change their code * Added netconf ssh subsystem * Renamed from `clixon` built in `docker/base` * C-API + * Added `clicon_handle` parameter to all `xml_bind_*` calls * All calls to `clicon_log_xml()` changed to new function `clicon_debug_xml()` * Changed type of `veclen` parameter to `size_t` in `xpath_vec_flag()` * Added `with-defaults` parameter (default 0) to `xmldb_get0()` diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index 0c2f1da6..60d49dc9 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -487,7 +487,7 @@ from_client_edit_config(clicon_handle h, xml_spec_set(xc, NULL); /* Populate XML with Yang spec (why not do this in parser?) */ - if ((ret = xml_bind_yang(xc, YB_MODULE, yspec, &xret)) < 0) + if ((ret = xml_bind_yang(h, xc, YB_MODULE, yspec, &xret)) < 0) goto done; if (ret == 0){ if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0) diff --git a/apps/backend/backend_commit.c b/apps/backend/backend_commit.c index 5c1b3fdf..36e14c73 100644 --- a/apps/backend/backend_commit.c +++ b/apps/backend/backend_commit.c @@ -231,7 +231,7 @@ startup_common(clicon_handle h, /* Print upgraded db: -q backend switch for debugging/ showing upgraded config only */ if (clicon_quit_upgrade_get(h) == 1){ /* bind yang */ - if ((ret = xml_bind_yang(xt, YB_MODULE, yspec, &xret)) < 1){ + if ((ret = xml_bind_yang(h, xt, YB_MODULE, yspec, &xret)) < 1){ if (ret == 0){ /* invalid */ clicon_err(OE_XML, EFAULT, "invalid configuration"); @@ -257,7 +257,7 @@ startup_common(clicon_handle h, goto ok; } /* After upgrading, XML tree needs to be sorted and yang spec populated */ - if ((ret = xml_bind_yang(xt, YB_MODULE, yspec, &xret)) < 0) + if ((ret = xml_bind_yang(h, xt, YB_MODULE, yspec, &xret)) < 0) goto done; if (ret == 0){ if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0) diff --git a/apps/backend/backend_get.c b/apps/backend/backend_get.c index 8f209706..413d875f 100644 --- a/apps/backend/backend_get.c +++ b/apps/backend/backend_get.c @@ -761,7 +761,7 @@ get_list_pagination(clicon_handle h, } /* System makes the binding */ - if ((ret = xml_bind_yang(xret, YB_MODULE, yspec, &xerr)) < 0) + if ((ret = xml_bind_yang(h, xret, YB_MODULE, yspec, &xerr)) < 0) goto done; if (ret == 0){ clicon_debug_xml(1, xret, "Yang bind pagination state"); diff --git a/apps/backend/backend_plugin.c b/apps/backend/backend_plugin.c index 1758327b..344557b1 100644 --- a/apps/backend/backend_plugin.c +++ b/apps/backend/backend_plugin.c @@ -370,7 +370,7 @@ clixon_plugin_statedata_all(clicon_handle h, } clicon_debug_xml(CLIXON_DBG_DETAIL, x, "%s %s STATE:", __FUNCTION__, clixon_plugin_name_get(cp)); /* XXX: ret == 0 invalid yang binding should be handled as internal error */ - if ((ret = xml_bind_yang(x, YB_MODULE, yspec, &xerr)) < 0) + if ((ret = xml_bind_yang(h, x, YB_MODULE, yspec, &xerr)) < 0) goto done; if (ret == 0){ if (clixon_netconf_internal_error(xerr, diff --git a/apps/backend/backend_startup.c b/apps/backend/backend_startup.c index 0b083ab7..a5695cde 100644 --- a/apps/backend/backend_startup.c +++ b/apps/backend/backend_startup.c @@ -237,7 +237,7 @@ load_extraxml(clicon_handle h, if (xt) xml_name_set(xt, NETCONF_INPUT_CONFIG); /* Now we can yang bind */ - if ((ret = xml_bind_yang(xt, YB_MODULE, yspec, &xerr)) < 0) + if ((ret = xml_bind_yang(h, xt, YB_MODULE, yspec, &xerr)) < 0) goto done; if (ret == 0){ if (netconf_err2cb(xerr, cbret) < 0) diff --git a/apps/netconf/netconf_main.c b/apps/netconf/netconf_main.c index 56568624..d09297a2 100644 --- a/apps/netconf/netconf_main.c +++ b/apps/netconf/netconf_main.c @@ -229,7 +229,7 @@ netconf_rpc_message(clicon_handle h, *eof = 1; goto ok; } - if ((ret = xml_bind_yang_rpc(xrpc, yspec, &xret)) < 0) + if ((ret = xml_bind_yang_rpc(h, xrpc, yspec, &xret)) < 0) goto done; if (ret > 0 && (ret = xml_yang_validate_rpc(h, xrpc, 0, &xret)) < 0) diff --git a/apps/netconf/netconf_rpc.c b/apps/netconf/netconf_rpc.c index db111b82..f6e0e10e 100644 --- a/apps/netconf/netconf_rpc.c +++ b/apps/netconf/netconf_rpc.c @@ -650,7 +650,7 @@ netconf_application_rpc(clicon_handle h, if ((youtput = yang_find(yrpc, Y_OUTPUT, NULL)) != NULL){ xoutput=xpath_first(*xret, NULL, "/"); xml_spec_set(xoutput, youtput); /* needed for xml_bind_yang */ - if ((ret = xml_bind_yang(xoutput, YB_MODULE, yspec, &xerr)) < 0) + if ((ret = xml_bind_yang(h, xoutput, YB_MODULE, yspec, &xerr)) < 0) goto done; if (ret > 0 && (ret = xml_yang_validate_all_top(h, xoutput, &xerr)) < 0) goto done; diff --git a/apps/restconf/restconf_methods_post.c b/apps/restconf/restconf_methods_post.c index e5746409..4e70fbc2 100644 --- a/apps/restconf/restconf_methods_post.c +++ b/apps/restconf/restconf_methods_post.c @@ -598,7 +598,7 @@ api_operations_post_output(clicon_handle h, if (youtput != NULL){ xml_spec_set(xoutput, youtput); /* needed for xml_bind_yang */ #ifdef notyet - if ((ret = xml_bind_yang(xoutput, YB_MODULE, yspec, &xerr)) < 0) + if ((ret = xml_bind_yang(h, xoutput, YB_MODULE, yspec, &xerr)) < 0) goto done; if (ret > 0 && (ret = xml_yang_validate_all(xoutput, &xerr)) < 0) goto done; @@ -798,7 +798,7 @@ api_operations_post(clicon_handle h, clicon_debug_xml(1, xtop, "%s 5. Translate input args:", __FUNCTION__); #endif /* 6. Validate outgoing RPC and fill in defaults */ - if ((ret = xml_bind_yang_rpc(xtop, yspec, &xerr)) < 0) /* */ + if ((ret = xml_bind_yang_rpc(h, xtop, yspec, &xerr)) < 0) /* */ goto done; if (ret == 0){ if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0) diff --git a/lib/clixon/clixon_xml_bind.h b/lib/clixon/clixon_xml_bind.h index 1b609128..02b4c8cb 100644 --- a/lib/clixon/clixon_xml_bind.h +++ b/lib/clixon/clixon_xml_bind.h @@ -45,10 +45,10 @@ */ int xml_bind_yang_unknown_anydata(int val); int xml_bind_netconf_message_id_optional(int val); -int xml_bind_yang_rpc(cxobj *xrpc, yang_stmt *yspec, cxobj **xerr); -int xml_bind_yang_rpc_reply(cxobj *xrpc, char *name, yang_stmt *yspec, cxobj **xerr); -int xml_bind_yang0(cxobj *xt, yang_bind yb, yang_stmt *yspec, cxobj **xerr); -int xml_bind_yang(cxobj *xt, yang_bind yb, yang_stmt *yspec, cxobj **xerr); +int xml_bind_yang_rpc(clicon_handle h, cxobj *xrpc, yang_stmt *yspec, cxobj **xerr); +int xml_bind_yang_rpc_reply(clicon_handle h, cxobj *xrpc, char *name, yang_stmt *yspec, cxobj **xerr); +int xml_bind_yang0(clicon_handle h, cxobj *xt, yang_bind yb, yang_stmt *yspec, cxobj **xerr); +int xml_bind_yang(clicon_handle h, cxobj *xt, yang_bind yb, yang_stmt *yspec, cxobj **xerr); int xml_bind_special(cxobj *xd, yang_stmt *yspec, char *schema_nodeid); #endif /* _CLIXON_XML_BIND_H_ */ diff --git a/lib/src/clixon_datastore_read.c b/lib/src/clixon_datastore_read.c index bb58d87b..d73ff67b 100644 --- a/lib/src/clixon_datastore_read.c +++ b/lib/src/clixon_datastore_read.c @@ -537,6 +537,7 @@ xmldb_readfile(clicon_handle h, xml_flag_set(x0, XML_FLAG_TOP); if (xml_child_nr(x0) == 0 && de) de->de_empty = 1; + /* Check if we support modstate */ if (clicon_option_bool(h, "CLICON_XMLDB_MODSTATE")) if ((msdiff = modstate_diff_new()) == NULL) @@ -618,7 +619,7 @@ xmldb_readfile(clicon_handle h, } /* if msdiff */ /* xml looks like: ... actually YB_MODULE_NEXT */ - if ((ret = xml_bind_yang(x0, YB_MODULE, yspec1?yspec1:yspec, xerr)) < 0) + if ((ret = xml_bind_yang(h, x0, YB_MODULE, yspec1?yspec1:yspec, xerr)) < 0) goto done; if (ret == 0) goto fail; @@ -883,7 +884,7 @@ xmldb_get_cache(clicon_handle h, x0t = de->de_xml; if (yb == YB_MODULE && !xml_spec(x0t)){ - if ((ret = xml_bind_yang(x0t, YB_MODULE, yspec, xerr)) < 0) + if ((ret = xml_bind_yang(h, x0t, YB_MODULE, yspec, xerr)) < 0) goto done; if (ret == 0) ; /* XXX */ diff --git a/lib/src/clixon_file.c b/lib/src/clixon_file.c index c4adbbae..68f2ea49 100644 --- a/lib/src/clixon_file.c +++ b/lib/src/clixon_file.c @@ -144,7 +144,7 @@ clicon_files_recursive(const char *dir, int res = 0; char errbuf[128]; - clicon_debug(2, "%s dir:%s", __FUNCTION__, dir); + clicon_debug(CLIXON_DBG_DETAIL, "%s dir:%s", __FUNCTION__, dir); if (regexp && (res = regcomp(&re, regexp, REG_EXTENDED)) != 0) { regerror(res, &re, errbuf, sizeof(errbuf)); clicon_err(OE_DB, 0, "regcomp: %s", errbuf); @@ -238,7 +238,7 @@ clicon_file_dirent(const char *dir, clicon_err(OE_UNIX, errno, "realloc"); goto quit; } /* realloc */ - clicon_debug(2, "%s memcpy(%p %p %u", __FUNCTION__, &new[nent], dent, direntStructSize); + clicon_debug(CLIXON_DBG_DETAIL, "%s memcpy(%p %p %u", __FUNCTION__, &new[nent], dent, direntStructSize); /* man (3) readdir: * By implication, the use sizeof(struct dirent) to capture the size of the record including * the size of d_name is also incorrect. */ diff --git a/lib/src/clixon_json.c b/lib/src/clixon_json.c index 707031b6..4e107849 100644 --- a/lib/src/clixon_json.c +++ b/lib/src/clixon_json.c @@ -1462,19 +1462,19 @@ _json_parse(char *str, */ switch (yb){ case YB_PARENT: - if ((ret = xml_bind_yang0(x, yb, yspec, xerr)) < 0) + if ((ret = xml_bind_yang0(NULL, x, yb, yspec, xerr)) < 0) goto done; if (ret == 0) failed++; break; case YB_MODULE_NEXT: - if ((ret = xml_bind_yang(x, YB_MODULE, yspec, xerr)) < 0) + if ((ret = xml_bind_yang(NULL, x, YB_MODULE, yspec, xerr)) < 0) goto done; if (ret == 0) failed++; break; case YB_MODULE: - if ((ret = xml_bind_yang0(x, yb, yspec, xerr)) < 0) + if ((ret = xml_bind_yang0(NULL, x, yb, yspec, xerr)) < 0) goto done; if (ret == 0) failed++; @@ -1482,7 +1482,7 @@ _json_parse(char *str, case YB_NONE: break; case YB_RPC: - if ((ret = xml_bind_yang_rpc(x, yspec, xerr)) < 0) + if ((ret = xml_bind_yang_rpc(NULL, x, yspec, xerr)) < 0) goto done; if (ret == 0) failed++; diff --git a/lib/src/clixon_proto_client.c b/lib/src/clixon_proto_client.c index 441fda99..d6180615 100644 --- a/lib/src/clixon_proto_client.c +++ b/lib/src/clixon_proto_client.c @@ -449,7 +449,7 @@ clicon_rpc_netconf_xml(clicon_handle h, xml_find_type(xreply, NULL, "rpc-error", CX_ELMNT) == NULL){ yspec = clicon_dbspec_yang(h); /* Here use rpc name to bind to yang */ - if ((ret = xml_bind_yang_rpc_reply(xreply, rpcname, yspec, &xerr)) < 0) + if ((ret = xml_bind_yang_rpc_reply(h, xreply, rpcname, yspec, &xerr)) < 0) goto done; if (ret == 0){ /* Replace reply with error */ @@ -573,7 +573,7 @@ clicon_rpc_get_config(clicon_handle h, else{ if (xml_bind_special(xd, yspec, "/nc:get-config/output/data") < 0) goto done; - if ((ret = xml_bind_yang(xd, YB_MODULE, yspec, &xerr)) < 0) + if ((ret = xml_bind_yang(h, xd, YB_MODULE, yspec, &xerr)) < 0) goto done; if (ret == 0){ if (clixon_netconf_internal_error(xerr, @@ -1020,7 +1020,7 @@ clicon_rpc_get(clicon_handle h, else{ if (xml_bind_special(xd, yspec, "/nc:get/output/data") < 0) goto done; - if ((ret = xml_bind_yang(xd, YB_MODULE, yspec, &xerr)) < 0) + if ((ret = xml_bind_yang(h, xd, YB_MODULE, yspec, &xerr)) < 0) goto done; if (ret == 0){ if (clixon_netconf_internal_error(xerr, @@ -1184,7 +1184,7 @@ clicon_rpc_get_pageable_list(clicon_handle h, else{ if (xml_bind_special(xd, yspec, "/nc:get/output/data") < 0) goto done; - if ((ret = xml_bind_yang(xd, YB_MODULE, yspec, &xerr)) < 0) + if ((ret = xml_bind_yang(h, xd, YB_MODULE, yspec, &xerr)) < 0) goto done; if (ret == 0){ if (clixon_netconf_internal_error(xerr, diff --git a/lib/src/clixon_text_syntax.c b/lib/src/clixon_text_syntax.c index b1f9c1b0..98e7195e 100644 --- a/lib/src/clixon_text_syntax.c +++ b/lib/src/clixon_text_syntax.c @@ -419,7 +419,7 @@ _text_syntax_parse(char *str, */ switch (yb){ case YB_MODULE_NEXT: - if ((ret = xml_bind_yang(x, YB_MODULE, yspec, xerr)) < 0) + if ((ret = xml_bind_yang(NULL, x, YB_MODULE, yspec, xerr)) < 0) goto done; if (ret == 0) failed++; @@ -428,7 +428,7 @@ _text_syntax_parse(char *str, /* xt: nospec * x: <-- populate from modules */ - if ((ret = xml_bind_yang0(x, YB_MODULE, yspec, xerr)) < 0) + if ((ret = xml_bind_yang0(NULL, x, YB_MODULE, yspec, xerr)) < 0) goto done; if (ret == 0) failed++; diff --git a/lib/src/clixon_validate.c b/lib/src/clixon_validate.c index 11fe11f0..34fa276f 100644 --- a/lib/src/clixon_validate.c +++ b/lib/src/clixon_validate.c @@ -1416,7 +1416,7 @@ rpc_reply_check(clicon_handle h, } if (xml_rootchild(x, 0, &x) < 0) goto done; - if ((ret = xml_bind_yang_rpc_reply(x, rpcname, yspec, &xret)) < 0) + if ((ret = xml_bind_yang_rpc_reply(h, x, rpcname, yspec, &xret)) < 0) goto done; if (ret == 0){ clicon_debug(1, "%s failure when validating:%s", __FUNCTION__, cbuf_get(cbret)); diff --git a/lib/src/clixon_xml_bind.c b/lib/src/clixon_xml_bind.c index 7c4ad3f5..3ff35f1f 100644 --- a/lib/src/clixon_xml_bind.c +++ b/lib/src/clixon_xml_bind.c @@ -34,7 +34,8 @@ ***** END LICENSE BLOCK ***** * - * Translation / mapping code between formats + * Given an existing XML tree, bind YANG specs to XML nodes according to different + * algorithms */ #ifdef HAVE_CONFIG_H #include "clixon_config.h" /* generated by config & autoconf */ @@ -68,13 +69,13 @@ #include "clixon_options.h" #include "clixon_data.h" #include "clixon_yang_module.h" -#include "clixon_plugin.h" #include "clixon_xml_nsctx.h" #include "clixon_xpath_ctx.h" #include "clixon_xpath.h" #include "clixon_log.h" #include "clixon_err.h" #include "clixon_netconf_lib.h" +#include "clixon_plugin.h" #include "clixon_xml_sort.h" #include "clixon_yang_type.h" #include "clixon_xml_map.h" @@ -136,6 +137,8 @@ strip_body_objects(cxobj *xt) /*! Associate XML node x with x:s parents yang:s matching child * * @param[in] xt XML tree node + * @param[in] xsibling + * @param[in] yspec Top-level YANG spec / mount-point * @param[out] xerr Reason for failure, or NULL * @retval 2 OK Yang assignment not made because yang parent is anyxml or anydata * @retval 1 OK Yang assignment made @@ -145,9 +148,10 @@ strip_body_objects(cxobj *xt) * @see populate_self_top */ static int -populate_self_parent(cxobj *xt, - cxobj *xsibling, - cxobj **xerr) +populate_self_parent(cxobj *xt, + cxobj *xsibling, + yang_stmt *yspec, + cxobj **xerr) { int retval = -1; yang_stmt *y = NULL; /* yang node */ @@ -349,6 +353,7 @@ populate_self_top(cxobj *xt, * * Populate xt:s children as top-level symbols * This may be unnecessary if yspec is set on manual creation: x=xml_new(); xml_spec_set(x,y) + * @param[in] h Clixon handle (sometimes NULL) * @param[in] xt XML tree node * @param[in] yb How to bind yang to XML top-level when parsing * @param[in] yspec Yang spec @@ -358,16 +363,17 @@ populate_self_top(cxobj *xt, * @retval -1 Error * @code * cxobj *xerr = NULL; - * if (xml_bind_yang(x, YB_MODULE, yspec, &xerr) < 0) + * if (xml_bind_yang(h, x, YB_MODULE, yspec, &xerr) < 0) * err; * @endcode - * @note For subs to anyxml nodes will not have spec set * There are several functions in the API family * @see xml_bind_yang_rpc for incoming rpc * @see xml_bind_yang0 If the calling xml object should also be populated + * @note For subs to anyxml nodes will not have spec set */ int -xml_bind_yang(cxobj *xt, +xml_bind_yang(clicon_handle h, + cxobj *xt, yang_bind yb, yang_stmt *yspec, cxobj **xerr) @@ -379,7 +385,7 @@ xml_bind_yang(cxobj *xt, strip_body_objects(xt); xc = NULL; /* Apply on children */ while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL) { - if ((ret = xml_bind_yang0(xc, yb, yspec, xerr)) < 0) + if ((ret = xml_bind_yang0(h, xc, yb, yspec, xerr)) < 0) goto done; if (ret == 0) goto fail; @@ -392,9 +398,23 @@ xml_bind_yang(cxobj *xt, goto done; } +/*! + * + * @param[in] h Clixon handle (sometimes NULL) + * @param[in] xt XML tree node + * @param[in] yb How to bind yang to XML top-level when parsing + * @param[in] yspec Yang spec + * @param[in] xsibling + * @param[out] xerr Reason for failure, or NULL + * @retval 1 OK yang assignment made + * @retval 0 Partial or no yang assigment made (at least one failed) and xerr set + * @retval -1 Error + */ static int -xml_bind_yang0_opt(cxobj *xt, +xml_bind_yang0_opt(clicon_handle h, + cxobj *xt, yang_bind yb, + yang_stmt *yspec, cxobj *xsibling, cxobj **xerr) { @@ -407,11 +427,17 @@ xml_bind_yang0_opt(cxobj *xt, char *name0 = NULL; char *prefix0 = NULL; char *name; + yang_bind ybc; char *prefix; + yang_stmt *yspec1 = NULL; switch (yb){ + case YB_MODULE: + if ((ret = populate_self_top(xt, yspec, xerr)) < 0) + goto done; + break; case YB_PARENT: - if ((ret = populate_self_parent(xt, xsibling, xerr)) < 0) + if ((ret = populate_self_parent(xt, xsibling, yspec, xerr)) < 0) goto done; break; default: @@ -424,6 +450,8 @@ xml_bind_yang0_opt(cxobj *xt, else if (ret == 2) /* ret=2 for anyxml from parent^ */ goto ok; strip_body_objects(xt); + ybc = YB_PARENT; + yspec1 = yspec; xc = NULL; /* Apply on children */ while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL) { /* It is xml2ns in populate_self_parent that needs improvement */ @@ -433,15 +461,15 @@ xml_bind_yang0_opt(cxobj *xt, if (yc0 != NULL && clicon_strcmp(name0, name) == 0 && clicon_strcmp(prefix0, prefix) == 0){ - if ((ret = xml_bind_yang0_opt(xc, YB_PARENT, xc0, xerr)) < 0) + if ((ret = xml_bind_yang0_opt(h, xc, ybc, yspec1, xc0, xerr)) < 0) goto done; } else if (xsibling && (xs = xml_find_type(xsibling, prefix, name, CX_ELMNT)) != NULL){ - if ((ret = xml_bind_yang0_opt(xc, YB_PARENT, xs, xerr)) < 0) + if ((ret = xml_bind_yang0_opt(h, xc, ybc, yspec1, xs, xerr)) < 0) goto done; } - else if ((ret = xml_bind_yang0_opt(xc, YB_PARENT, NULL, xerr)) < 0) + else if ((ret = xml_bind_yang0_opt(h, xc, ybc, yspec1, NULL, xerr)) < 0) goto done; if (ret == 0) goto fail; @@ -461,6 +489,7 @@ xml_bind_yang0_opt(cxobj *xt, /*! Find yang spec association of tree of XML nodes * + * @param[in] h Clixon handle (sometimes NULL) * @param[in] xt XML tree node * @param[in] yb How to bind yang to XML top-level when parsing * @param[in] yspec Yang spec @@ -472,7 +501,8 @@ xml_bind_yang0_opt(cxobj *xt, * @see xml_bind_yang If only children of xt should be populated, not xt itself */ int -xml_bind_yang0(cxobj *xt, +xml_bind_yang0(clicon_handle h, + cxobj *xt, yang_bind yb, yang_stmt *yspec, cxobj **xerr) @@ -487,7 +517,7 @@ xml_bind_yang0(cxobj *xt, goto done; break; case YB_PARENT: - if ((ret = populate_self_parent(xt, NULL, xerr)) < 0) + if ((ret = populate_self_parent(xt, NULL, yspec, xerr)) < 0) goto done; break; case YB_NONE: @@ -505,7 +535,7 @@ xml_bind_yang0(cxobj *xt, strip_body_objects(xt); xc = NULL; /* Apply on children */ while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL) { - if ((ret = xml_bind_yang0_opt(xc, YB_PARENT, NULL, xerr)) < 0) + if ((ret = xml_bind_yang0_opt(h, xc, YB_PARENT, yspec, NULL, xerr)) < 0) goto done; if (ret == 0) goto fail; @@ -520,9 +550,11 @@ xml_bind_yang0(cxobj *xt, } /*! RPC-specific + * @param[in] h Clixon handle (sometimes NULL) */ static int -xml_bind_yang_rpc_rpc(cxobj *x, +xml_bind_yang_rpc_rpc(clicon_handle h, + cxobj *x, yang_stmt *yrpc, char *rpcname, cxobj **xerr) @@ -556,7 +588,7 @@ xml_bind_yang_rpc_rpc(cxobj *x, * recursive population to work. Therefore, assign input yang * to rpc level although not 100% intuitive */ xml_spec_set(x, yi); - if ((ret = xml_bind_yang(x, YB_PARENT, NULL, xerr)) < 0) + if ((ret = xml_bind_yang(h, x, YB_PARENT, NULL, xerr)) < 0) goto done; if (ret == 0) goto fail; @@ -576,10 +608,12 @@ xml_bind_yang_rpc_rpc(cxobj *x, * Find the innermost container or list containing an XML element that carries the name of the * defined action. * Only one action can be invoked in one rpc + * @param[in] h Clixon handle (sometimes NULL) * XXX if not more action, consider folding into calling function */ static int -xml_bind_yang_rpc_action(cxobj *xn, +xml_bind_yang_rpc_action(clicon_handle h, + cxobj *xn, yang_stmt *yspec, cxobj **xerr) { @@ -588,7 +622,7 @@ xml_bind_yang_rpc_action(cxobj *xn, cxobj *xi; yang_stmt *yi;; - if ((ret = xml_bind_yang(xn, YB_MODULE, yspec, xerr)) < 0) + if ((ret = xml_bind_yang(h, xn, YB_MODULE, yspec, xerr)) < 0) goto done; if (ret == 0) goto fail; @@ -608,6 +642,7 @@ xml_bind_yang_rpc_action(cxobj *xn, /*! Find yang spec association of XML node for incoming RPC starting with * * Incoming RPC has an "input" structure that is not taken care of by xml_bind_yang + * @param[in] h Clixon handle (sometimes NULL) * @param[in] xrpc XML rpc node * @param[in] yspec Yang spec * @param[out] xerr Reason for failure, or NULL @@ -623,7 +658,8 @@ xml_bind_yang_rpc_action(cxobj *xn, * @see xml_bind_yang_rpc_reply */ int -xml_bind_yang_rpc(cxobj *xrpc, +xml_bind_yang_rpc(clicon_handle h, + cxobj *xrpc, yang_stmt *yspec, cxobj **xerr) { @@ -699,7 +735,7 @@ xml_bind_yang_rpc(cxobj *xrpc, if ((ret = xml_rpc_isaction(x)) < 0) goto done; if (ret == 1){ - if ((ret = xml_bind_yang_rpc_action(x, yspec, xerr)) < 0) + if ((ret = xml_bind_yang_rpc_action(h, x, yspec, xerr)) < 0) goto done; if (ret == 0) goto fail; @@ -719,7 +755,7 @@ xml_bind_yang_rpc(cxobj *xrpc, goto done; goto fail; } - if ((ret = xml_bind_yang_rpc_rpc(x, yrpc, rpcname, xerr)) < 0) + if ((ret = xml_bind_yang_rpc_rpc(h, x, yrpc, rpcname, xerr)) < 0) goto done; if (ret == 0) goto fail; @@ -736,6 +772,7 @@ xml_bind_yang_rpc(cxobj *xrpc, /*! Find yang spec association of XML node for outgoing RPC starting with * * Outgoing RPC has an "output" structure that is not taken care of by xml_bind_yang + * @param[in] h Clixon handle (sometimes NULL) * @param[in] xrpc XML rpc node * @param[in] name Name of RPC (not seen in output/reply) * @param[in] yspec Yang spec @@ -751,7 +788,8 @@ xml_bind_yang_rpc(cxobj *xrpc, * @see xml_bind_yang For other generic cases */ int -xml_bind_yang_rpc_reply(cxobj *xrpc, +xml_bind_yang_rpc_reply(clicon_handle h, + cxobj *xrpc, char *name, yang_stmt *yspec, cxobj **xerr) @@ -804,7 +842,7 @@ xml_bind_yang_rpc_reply(cxobj *xrpc, goto ok; } /* Use a temporary xml error tree since it is stringified in the original error on error */ - if ((ret = xml_bind_yang(xrpc, YB_PARENT, NULL, &xerr1)) < 0) + if ((ret = xml_bind_yang(h, xrpc, YB_PARENT, NULL, &xerr1)) < 0) goto done; if (ret == 0){ if ((cberr = cbuf_new()) == NULL){ diff --git a/lib/src/clixon_xml_default.c b/lib/src/clixon_xml_default.c index ed4c3884..849d8f12 100644 --- a/lib/src/clixon_xml_default.c +++ b/lib/src/clixon_xml_default.c @@ -178,7 +178,7 @@ xml_default_choice(yang_stmt *yc, yang_stmt *yca = NULL; yang_stmt *ydef; - clicon_debug(2, "%s", __FUNCTION__); + clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); /* 1. Is there a default case and no child under this choice? */ x = NULL; diff --git a/lib/src/clixon_xml_io.c b/lib/src/clixon_xml_io.c index 4c3757c9..76cdb59b 100644 --- a/lib/src/clixon_xml_io.c +++ b/lib/src/clixon_xml_io.c @@ -579,14 +579,14 @@ _xml_parse(const char *str, /* xt:n Has spec * x: <-- populate from parent */ - if ((ret = xml_bind_yang0(x, YB_PARENT, NULL, xerr)) < 0) + if ((ret = xml_bind_yang0(NULL, x, YB_PARENT, NULL, xerr)) < 0) goto done; if (ret == 0) failed++; break; case YB_MODULE_NEXT: - if ((ret = xml_bind_yang(x, YB_MODULE, yspec, xerr)) < 0) + if ((ret = xml_bind_yang(NULL, x, YB_MODULE, yspec, xerr)) < 0) goto done; if (ret == 0) failed++; @@ -595,13 +595,13 @@ _xml_parse(const char *str, /* xt: nospec * x: <-- populate from modules */ - if ((ret = xml_bind_yang0(x, YB_MODULE, yspec, xerr)) < 0) + if ((ret = xml_bind_yang0(NULL, x, YB_MODULE, yspec, xerr)) < 0) goto done; if (ret == 0) failed++; break; case YB_RPC: - if ((ret = xml_bind_yang_rpc(x, yspec, xerr)) < 0) + if ((ret = xml_bind_yang_rpc(NULL, x, yspec, xerr)) < 0) goto done; if (ret == 0){ /* Add message-id */ if (*xerr && clixon_xml_attr_copy(x, *xerr, "message-id") < 0) diff --git a/util/clixon_util_path.c b/util/clixon_util_path.c index ce5a96b8..298a2451 100644 --- a/util/clixon_util_path.c +++ b/util/clixon_util_path.c @@ -225,7 +225,7 @@ main(int argc, /* Validate XML as well */ if (yang_file_dir){ /* Populate */ - if ((ret = xml_bind_yang(x, YB_MODULE, yspec, &xerr)) < 0) + if ((ret = xml_bind_yang(h, x, YB_MODULE, yspec, &xerr)) < 0) goto done; if (ret == 0){ if ((cb = cbuf_new()) ==NULL){ diff --git a/util/clixon_util_xpath.c b/util/clixon_util_xpath.c index 0be82b2d..8484f3c9 100644 --- a/util/clixon_util_xpath.c +++ b/util/clixon_util_xpath.c @@ -321,7 +321,7 @@ main(int argc, /* Validate XML as well */ if (yang_file_dir){ /* Populate */ - if ((ret = xml_bind_yang(x0, YB_MODULE, yspec, &xerr)) < 0) + if ((ret = xml_bind_yang(h, x0, YB_MODULE, yspec, &xerr)) < 0) goto done; if (ret == 0){ if ((cbret = cbuf_new()) ==NULL){