* Added yang population of data in clicon_rpc_get[_config]
This commit is contained in:
parent
2de8497972
commit
bab3b5ad56
6 changed files with 114 additions and 62 deletions
|
|
@ -343,7 +343,7 @@ clicon_rpc_generate_error(cxobj *xerr,
|
|||
* @endcode
|
||||
* @see clicon_rpc_get
|
||||
* @see clicon_rpc_generate_error
|
||||
* @note the netconf return message us yang populated, but returned data is not
|
||||
* @note the netconf return message is yang populated, as well as the return data
|
||||
*/
|
||||
int
|
||||
clicon_rpc_get_config(clicon_handle h,
|
||||
|
|
@ -357,10 +357,13 @@ clicon_rpc_get_config(clicon_handle h,
|
|||
struct clicon_msg *msg = NULL;
|
||||
cbuf *cb = NULL;
|
||||
cxobj *xret = NULL;
|
||||
cxobj *xerr = NULL;
|
||||
cxobj *xd;
|
||||
cg_var *cv = NULL;
|
||||
char *prefix;
|
||||
uint32_t session_id;
|
||||
int ret;
|
||||
yang_stmt *yspec;
|
||||
|
||||
if (session_id_check(h, &session_id) < 0)
|
||||
goto done;
|
||||
|
|
@ -394,9 +397,21 @@ clicon_rpc_get_config(clicon_handle h,
|
|||
/* Send xml error back: first check error, then ok */
|
||||
if ((xd = xpath_first(xret, NULL, "/rpc-reply/rpc-error")) != NULL)
|
||||
xd = xml_parent(xd); /* point to rpc-reply */
|
||||
else if ((xd = xpath_first(xret, NULL, "/rpc-reply/data")) == NULL)
|
||||
else if ((xd = xpath_first(xret, NULL, "/rpc-reply/data")) == NULL){
|
||||
if ((xd = xml_new("data", NULL, NULL)) == NULL)
|
||||
goto done;
|
||||
}
|
||||
else{
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
if ((ret = xml_spec_populate(xd, yspec, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
if ((xd = xpath_first(xerr, NULL, "rpc-error")) == NULL){
|
||||
clicon_err(OE_XML, ENOENT, "Expected rpc-error tag but none found(internal)");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (xt){
|
||||
if (xml_rm(xd) < 0)
|
||||
goto done;
|
||||
|
|
@ -406,6 +421,8 @@ clicon_rpc_get_config(clicon_handle h,
|
|||
done:
|
||||
if (cb)
|
||||
cbuf_free(cb);
|
||||
if (xerr)
|
||||
xml_free(xerr);
|
||||
if (xret)
|
||||
xml_free(xret);
|
||||
if (msg)
|
||||
|
|
@ -674,7 +691,7 @@ clicon_rpc_unlock(clicon_handle h,
|
|||
* @endcode
|
||||
* @see clicon_rpc_get_config which is almost the same as with content=config, but you can also select dbname
|
||||
* @see clicon_rpc_generate_error
|
||||
* @note the netconf return message us yang populated, but returned data is not
|
||||
* @note the netconf return message is yang populated, as well as the return data
|
||||
*/
|
||||
int
|
||||
clicon_rpc_get(clicon_handle h,
|
||||
|
|
@ -688,11 +705,14 @@ clicon_rpc_get(clicon_handle h,
|
|||
struct clicon_msg *msg = NULL;
|
||||
cbuf *cb = NULL;
|
||||
cxobj *xret = NULL;
|
||||
cxobj *xerr = NULL;
|
||||
cxobj *xd;
|
||||
char *username;
|
||||
cg_var *cv = NULL;
|
||||
char *prefix;
|
||||
uint32_t session_id;
|
||||
int ret;
|
||||
yang_stmt *yspec;
|
||||
|
||||
if (session_id_check(h, &session_id) < 0)
|
||||
goto done;
|
||||
|
|
@ -733,9 +753,21 @@ clicon_rpc_get(clicon_handle h,
|
|||
/* Send xml error back: first check error, then ok */
|
||||
if ((xd = xpath_first(xret, NULL, "/rpc-reply/rpc-error")) != NULL)
|
||||
xd = xml_parent(xd); /* point to rpc-reply */
|
||||
else if ((xd = xpath_first(xret, NULL, "/rpc-reply/data")) == NULL)
|
||||
else if ((xd = xpath_first(xret, NULL, "/rpc-reply/data")) == NULL){
|
||||
if ((xd = xml_new("data", NULL, NULL)) == NULL)
|
||||
goto done;
|
||||
}
|
||||
else{
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
if ((ret = xml_spec_populate(xd, yspec, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
if ((xd = xpath_first(xerr, NULL, "rpc-error")) == NULL){
|
||||
clicon_err(OE_XML, ENOENT, "Expected rpc-error tag but none found(internal)");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (xt){
|
||||
if (xml_rm(xd) < 0)
|
||||
goto done;
|
||||
|
|
@ -745,6 +777,8 @@ clicon_rpc_get(clicon_handle h,
|
|||
done:
|
||||
if (cb)
|
||||
cbuf_free(cb);
|
||||
if (xerr)
|
||||
xml_free(xerr);
|
||||
if (xret)
|
||||
xml_free(xret);
|
||||
if (msg)
|
||||
|
|
|
|||
|
|
@ -1313,7 +1313,11 @@ populate_self_top(cxobj *xt,
|
|||
* err;
|
||||
* @endcode
|
||||
* @note For subs to anyxml nodes will not have spec set
|
||||
* @see xml_spec_populate_rpc for incoming rpc
|
||||
* There are several functions in the API family
|
||||
* @see xml_spec_populate_rpc for incoming rpc
|
||||
* @see xml_spec_populate_parent Not top-level and parent is properly yang populated
|
||||
* @see xml_spec_populate0 If the calling xml object should also be populated
|
||||
* @see xml_spec_populate0_parent
|
||||
*/
|
||||
int
|
||||
xml_spec_populate(cxobj *xt,
|
||||
|
|
@ -1357,9 +1361,15 @@ xml_spec_populate_parent(cxobj *xt,
|
|||
if (ret == 0)
|
||||
failed++;
|
||||
}
|
||||
retval = (failed==0) ? 1 : 0;
|
||||
if (failed)
|
||||
goto fail;
|
||||
retval = 1;
|
||||
done:
|
||||
return retval;
|
||||
fail:
|
||||
retval = 0;
|
||||
goto done;
|
||||
|
||||
}
|
||||
|
||||
/*! Find yang spec association of tree of XML nodes
|
||||
|
|
@ -1378,18 +1388,23 @@ xml_spec_populate0(cxobj *xt,
|
|||
|
||||
if ((ret = populate_self_top(xt, yspec, xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 1){
|
||||
xc = NULL; /* Apply on children */
|
||||
while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL) {
|
||||
if ((ret = xml_spec_populate0_parent(xc, xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
failed++;
|
||||
}
|
||||
if (ret == 0)
|
||||
goto fail;
|
||||
xc = NULL; /* Apply on children */
|
||||
while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL) {
|
||||
if ((ret = xml_spec_populate0_parent(xc, xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
failed++;
|
||||
}
|
||||
retval = (failed==0) ? 1 : 0;
|
||||
if (failed)
|
||||
goto fail;
|
||||
retval = 1;
|
||||
done:
|
||||
return retval;
|
||||
fail:
|
||||
retval = 0;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/*! Find yang spec association of tree of XML nodes
|
||||
|
|
@ -1408,19 +1423,22 @@ xml_spec_populate0_parent(cxobj *xt,
|
|||
if ((ret = populate_self_parent(xt, xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
failed++;
|
||||
else if (ret != 1){ /* 1 means anyxml parent */
|
||||
xc = NULL; /* Apply on children */
|
||||
while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL) {
|
||||
if ((ret = xml_spec_populate0_parent(xc, xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
failed++;
|
||||
}
|
||||
goto fail;
|
||||
xc = NULL; /* Apply on children */
|
||||
while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL) {
|
||||
if ((ret = xml_spec_populate0_parent(xc, xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
failed++;
|
||||
}
|
||||
retval = (failed==0) ? 1 : 0;
|
||||
if (failed)
|
||||
goto fail;
|
||||
retval = 1;
|
||||
done:
|
||||
return retval;
|
||||
fail:
|
||||
retval = 0;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/*! Given an XML node, build an xpath to root, internal function
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue