Added validation for leafref forward and nackward references.
This commit is contained in:
parent
96f341d8fc
commit
1b6c9aacbe
11 changed files with 295 additions and 49 deletions
|
|
@ -89,15 +89,19 @@ generic_validate(yang_spec *yspec,
|
|||
int retval = -1;
|
||||
cxobj *x1;
|
||||
cxobj *x2;
|
||||
int i;
|
||||
yang_stmt *ys;
|
||||
int i;
|
||||
|
||||
/* All entries */
|
||||
if (xml_apply(td->td_target, CX_ELMNT,
|
||||
(xml_applyfn_t*)xml_yang_validate_all, NULL) < 0)
|
||||
goto done;
|
||||
|
||||
/* changed entries */
|
||||
for (i=0; i<td->td_clen; i++){
|
||||
x1 = td->td_scvec[i]; /* source changed */
|
||||
x2 = td->td_tcvec[i]; /* target changed */
|
||||
ys = xml_spec(x1);
|
||||
if (xml_yang_validate(x2, ys) < 0)
|
||||
if (xml_yang_validate_add(x2, NULL) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* deleted entries */
|
||||
|
|
@ -113,11 +117,8 @@ generic_validate(yang_spec *yspec,
|
|||
/* added entries */
|
||||
for (i=0; i<td->td_alen; i++){
|
||||
x2 = td->td_avec[i];
|
||||
ys = xml_spec(x2);
|
||||
if (xml_yang_validate(x2, ys) < 0)
|
||||
goto done;
|
||||
if (xml_apply(x2, CX_ELMNT,
|
||||
(xml_applyfn_t*)xml_yang_validate, NULL) < 0)
|
||||
if (xml_apply0(x2, CX_ELMNT,
|
||||
(xml_applyfn_t*)xml_yang_validate_add, NULL) < 0)
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
|
|||
|
|
@ -275,9 +275,10 @@ yang2cli_var_sub(clicon_handle h,
|
|||
if (helptext)
|
||||
cprintf(cb0, "(\"%s\")", helptext);
|
||||
if (completion){
|
||||
#if 0
|
||||
if (type && (strcmp(type, "leafref") == 0)){
|
||||
yang_stmt *ypath;
|
||||
|
||||
/* XXX only for absolute xpath */
|
||||
if ((ypath = yang_find((yang_node*)ytype, Y_PATH, NULL)) == NULL){
|
||||
clicon_err(OE_XML, 0, "leafref should have path sub");
|
||||
goto done;
|
||||
|
|
@ -290,6 +291,7 @@ yang2cli_var_sub(clicon_handle h,
|
|||
ypath->ys_argument);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (cli_expand_var_generate(h, ys, cvtype, cb0,
|
||||
options, fraction_digits) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -141,12 +141,29 @@ expand_dbvar(void *h,
|
|||
if (api_path_fmt2xpath(api_path, cvv, &xpath) < 0)
|
||||
goto done;
|
||||
/* XXX read whole configuration, why not send xpath? */
|
||||
if (clicon_rpc_get_config(h, dbstr, "/", &xt) < 0)
|
||||
if (clicon_rpc_get_config(h, dbstr, xpath, &xt) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
|
||||
clicon_rpc_generate_error(xerr);
|
||||
goto done;
|
||||
}
|
||||
#if 0
|
||||
/* Get xpath from datastore?
|
||||
* 1. Get whole datastore,
|
||||
* 2. Add tentative my location to xpath,
|
||||
* 3. If leafref, compute relative xpath
|
||||
*/
|
||||
{
|
||||
cxobj *xcur = NULL; /* xpath, NULL if datastore */
|
||||
// yang_node *y = NULL; /* yang spec of xpath */
|
||||
|
||||
if ((xcur = xpath_first(xt, xpath)) == NULL)
|
||||
goto done;
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
/* One round to detect duplicates
|
||||
* XXX The code below would benefit from some cleanup
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -196,6 +196,26 @@ catch:
|
|||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
ys_find_rpc(yang_stmt *ys,
|
||||
void *arg)
|
||||
{
|
||||
cxobj *xn = (cxobj*)arg;
|
||||
char *name = xml_name(xn);
|
||||
|
||||
if (ys->ys_keyword == Y_RPC && strcmp(name, ys->ys_argument) == 0){
|
||||
/*
|
||||
* XXX
|
||||
* 1. Check xn arguments with input statement.
|
||||
* 2. Send to backend as clicon_msg-encode()
|
||||
* 3. In backend to similar but there call actual backend
|
||||
*/
|
||||
return 1; /* handled */
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*! See if there is any callback registered for this tag
|
||||
*
|
||||
* @param[in] h clicon handle
|
||||
|
|
@ -211,21 +231,28 @@ netconf_plugin_callbacks(clicon_handle h,
|
|||
cxobj *xn,
|
||||
cxobj **xret)
|
||||
{
|
||||
int retval = -1;
|
||||
netconf_reg_t *nreg;
|
||||
int retval;
|
||||
yang_spec *yspec;
|
||||
|
||||
if (deps == NULL)
|
||||
return 0;
|
||||
nreg = deps;
|
||||
do {
|
||||
if (strcmp(nreg->nr_tag, xml_name(xn)) == 0){
|
||||
if ((retval = nreg->nr_callback(h, xn, xret, nreg->nr_arg)) < 0)
|
||||
return -1;
|
||||
else
|
||||
return 1; /* handled */
|
||||
}
|
||||
nreg = NEXTQ(netconf_reg_t *, nreg);
|
||||
} while (nreg != deps);
|
||||
return 0;
|
||||
if (deps != NULL){
|
||||
nreg = deps;
|
||||
do {
|
||||
if (strcmp(nreg->nr_tag, xml_name(xn)) == 0){
|
||||
retval = nreg->nr_callback(h, xn, xret, nreg->nr_arg);
|
||||
goto done;
|
||||
}
|
||||
nreg = NEXTQ(netconf_reg_t *, nreg);
|
||||
} while (nreg != deps);
|
||||
}
|
||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "No yang spec");
|
||||
goto done;
|
||||
}
|
||||
if (yang_apply((yang_node*)yspec, ys_find_rpc, xn) < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue