diff --git a/lib/clixon/clixon_proto_client.h b/lib/clixon/clixon_proto_client.h index 82608827..245fa1c1 100644 --- a/lib/clixon/clixon_proto_client.h +++ b/lib/clixon/clixon_proto_client.h @@ -54,6 +54,7 @@ int clicon_rpc_copy_config(clicon_handle h, char *db1, char *db2); int clicon_rpc_delete_config(clicon_handle h, char *db); int clicon_rpc_lock(clicon_handle h, char *db); int clicon_rpc_unlock(clicon_handle h, char *db); +int clicon_rpc_get2(clicon_handle h, char *xpath, cvec *nsc, netconf_content content, int32_t depth, char *defaults, int bind, cxobj **xret); int clicon_rpc_get(clicon_handle h, char *xpath, cvec *nsc, netconf_content content, int32_t depth, char *defaults, cxobj **xret); int clicon_rpc_get_pageable_list(clicon_handle h, char *datastore, char *xpath, cvec *nsc, netconf_content content, int32_t depth, char *defaults, diff --git a/lib/src/clixon_proto_client.c b/lib/src/clixon_proto_client.c index 44306fc4..d8583123 100644 --- a/lib/src/clixon_proto_client.c +++ b/lib/src/clixon_proto_client.c @@ -957,6 +957,55 @@ clicon_rpc_get(clicon_handle h, int32_t depth, char *defaults, cxobj **xt) +{ + return clicon_rpc_get2(h, xpath, nsc, content, depth, defaults, 1, xt); +} + +/*! Get database configuration and state data (please use instead of clicon_rpc_get) + * + * @param[in] h Clicon handle + * @param[in] xpath XPath in a filter stmt (or NULL/"" for no filter) + * @param[in] namespace Namespace associated w xpath + * @param[in] nsc Namespace context for filter + * @param[in] content Clixon extension: all, config, noconfig. -1 means all + * @param[in] depth Nr of XML levels to get, -1 is all, 0 is none + * @param[in] defaults Value of the with-defaults mode, rfc6243, or NULL + * @param[out] xt XML tree. Free with xml_free. + * Either or . + * @retval 0 OK + * @retval -1 Error, fatal or xml + * @note if xpath is set but namespace is NULL, the default, netconf base + * namespace will be used which is most probably wrong. + * @code + * cxobj *xt = NULL; + * cvec *nsc = NULL; + * + * if ((nsc = xml_nsctx_init(NULL, "urn:example:hello")) == NULL) + * err; + * if (clicon_rpc_get(h, "/hello/world", nsc, CONTENT_ALL, -1, &xt) < 0) + * err; + * if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ + * clixon_netconf_error(xerr, "clicon_rpc_get", NULL); + * err; + * } + * if (xt) + * xml_free(xt); + * if (nsc) + * xml_nsctx_free(nsc); + * @endcode + * @see clicon_rpc_get_config which is almost the same as with content=config, but you can also select dbname + * @see clixon_netconf_error + * @note the netconf return message is yang populated, as well as the return data + */ +int +clicon_rpc_get2(clicon_handle h, + char *xpath, + cvec *nsc, /* namespace context for filter */ + netconf_content content, + int32_t depth, + char *defaults, + int bind, + cxobj **xt) { int retval = -1; struct clicon_msg *msg = NULL; @@ -1030,15 +1079,17 @@ 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(h, xd, YB_MODULE, yspec, &xerr)) < 0) - goto done; - if (ret == 0){ - if (clixon_netconf_internal_error(xerr, - ". Internal error, backend returned invalid XML.", - NULL) < 0) + if (bind){ + if ((ret = xml_bind_yang(h, xd, YB_MODULE, yspec, &xerr)) < 0) goto done; - xd = xerr; - xerr = NULL; + if (ret == 0){ + if (clixon_netconf_internal_error(xerr, + ". Internal error, backend returned invalid XML.", + NULL) < 0) + goto done; + xd = xerr; + xerr = NULL; + } } } if (xt && xd){ @@ -1791,6 +1842,8 @@ clicon_hello_req(clicon_handle h, int ret; cbuf *cb = NULL; int clixon_lib = 0; + char *ns = NULL; + char *prefix = NULL; if ((cb = cbuf_new()) == NULL){ clicon_err(OE_XML, errno, "cbuf_new"); @@ -1802,6 +1855,8 @@ clicon_hello_req(clicon_handle h, clixon_lib++; } /* RFC 6022 session parameters transport and source-host */ + clicon_data_get(h, "session-namespace", &ns); + clicon_data_get(h, "session-namespace-prefix", &prefix); if (transport == NULL) clicon_data_get(h, "session-transport", &transport); if (transport){ diff --git a/lib/src/clixon_xpath.c b/lib/src/clixon_xpath.c index dae205c9..bcff49f9 100644 --- a/lib/src/clixon_xpath.c +++ b/lib/src/clixon_xpath.c @@ -1225,8 +1225,17 @@ xml2xpath1(cxobj *x, if ((xp = xml_parent(x)) == NULL) goto ok; - if (spec && xml_spec(x) == NULL) + y = xml_spec(x); + + if (spec && y == NULL) goto ok; + /* Strip top-level netconf anydata, eg from get-config protocol processing */ + if (y != NULL){ + if (yang_keyword_get(y) == Y_ANYXML) + goto ok; + if (yang_keyword_get(y) == Y_ANYDATA) + goto ok; + } if (xml2xpath1(xp, nsc, spec, apostrophe, cb) < 0) goto done; if (nsc){ @@ -1246,7 +1255,7 @@ xml2xpath1(cxobj *x, if (prefix) cprintf(cb, "%s:", prefix); cprintf(cb, "%s", xml_name(x)); - if ((y = xml_spec(x)) != NULL){ + if (y != NULL){ keyword = yang_keyword_get(y); switch (keyword){ case Y_LEAF_LIST: