* C-API: Added clicon_handle parameter to all xml_bind_* calls
This commit is contained in:
parent
da9bfcbb53
commit
51ebbdf12f
21 changed files with 102 additions and 62 deletions
|
|
@ -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 <rpc>
|
||||
*
|
||||
* 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 <rpc-reply>
|
||||
*
|
||||
* 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){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue