Added keyword arg to find schemanode functions
This commit is contained in:
parent
d57a6cf53c
commit
3df4a8a190
4 changed files with 27 additions and 13 deletions
|
|
@ -893,7 +893,7 @@ netconf_application_rpc(clicon_handle h,
|
||||||
// else
|
// else
|
||||||
// cprintf(cb, "/%s", xml_name(xn)); /* XXX not accepdted by below */
|
// cprintf(cb, "/%s", xml_name(xn)); /* XXX not accepdted by below */
|
||||||
/* Find yang rpc statement, return yang rpc statement if found */
|
/* Find yang rpc statement, return yang rpc statement if found */
|
||||||
if (yang_abs_schema_nodeid(yspec, cbuf_get(cb), &yrpc) < 0)
|
if (yang_abs_schema_nodeid(yspec, cbuf_get(cb), Y_RPC, &yrpc) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
/* Check if found */
|
/* Check if found */
|
||||||
if (yrpc != NULL){
|
if (yrpc != NULL){
|
||||||
|
|
|
||||||
|
|
@ -1038,7 +1038,7 @@ api_operations_post(clicon_handle h,
|
||||||
clicon_debug(1, "%s oppath: %s", __FUNCTION__, oppath);
|
clicon_debug(1, "%s oppath: %s", __FUNCTION__, oppath);
|
||||||
|
|
||||||
/* Find yang rpc statement, return yang rpc statement if found */
|
/* Find yang rpc statement, return yang rpc statement if found */
|
||||||
if (yang_abs_schema_nodeid(yspec, oppath, &yrpc) < 0)
|
if (yang_abs_schema_nodeid(yspec, oppath, Y_RPC, &yrpc) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (yrpc == NULL){
|
if (yrpc == NULL){
|
||||||
if (netconf_operation_failed_xml(&xerr, "protocol", "yang node not found") < 0)
|
if (netconf_operation_failed_xml(&xerr, "protocol", "yang node not found") < 0)
|
||||||
|
|
|
||||||
|
|
@ -260,9 +260,9 @@ int yang_parse(clicon_handle h, const char *yang_dir,
|
||||||
int yang_apply(yang_node *yn, enum rfc_6020 key, yang_applyfn_t fn,
|
int yang_apply(yang_node *yn, enum rfc_6020 key, yang_applyfn_t fn,
|
||||||
void *arg);
|
void *arg);
|
||||||
int yang_abs_schema_nodeid(yang_spec *yspec, char *schema_nodeid,
|
int yang_abs_schema_nodeid(yang_spec *yspec, char *schema_nodeid,
|
||||||
yang_stmt **yres);
|
enum rfc_6020 keyword, yang_stmt **yres);
|
||||||
int yang_desc_schema_nodeid(yang_node *yn, char *schema_nodeid,
|
int yang_desc_schema_nodeid(yang_node *yn, char *schema_nodeid,
|
||||||
yang_stmt **yres);
|
enum rfc_6020 keyword, yang_stmt **yres);
|
||||||
cg_var *ys_parse(yang_stmt *ys, enum cv_type cvtype);
|
cg_var *ys_parse(yang_stmt *ys, enum cv_type cvtype);
|
||||||
int ys_parse_sub(yang_stmt *ys, char *extra);
|
int ys_parse_sub(yang_stmt *ys, char *extra);
|
||||||
int yang_mandatory(yang_stmt *ys);
|
int yang_mandatory(yang_stmt *ys);
|
||||||
|
|
|
||||||
|
|
@ -1319,7 +1319,7 @@ yang_augment_node(yang_stmt *ys,
|
||||||
clicon_debug(1, "%s %s", __FUNCTION__, schema_nodeid);
|
clicon_debug(1, "%s %s", __FUNCTION__, schema_nodeid);
|
||||||
|
|
||||||
/* Find the target */
|
/* Find the target */
|
||||||
if (yang_abs_schema_nodeid(ysp, schema_nodeid, &yss) < 0)
|
if (yang_abs_schema_nodeid(ysp, schema_nodeid, -1, &yss) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (yss == NULL)
|
if (yss == NULL)
|
||||||
goto ok;
|
goto ok;
|
||||||
|
|
@ -1748,7 +1748,7 @@ ys_schemanode_check(yang_stmt *ys,
|
||||||
/* fallthru */
|
/* fallthru */
|
||||||
case Y_REFINE:
|
case Y_REFINE:
|
||||||
case Y_UNIQUE:
|
case Y_UNIQUE:
|
||||||
if (yang_desc_schema_nodeid(yp, ys->ys_argument, &yres) < 0)
|
if (yang_desc_schema_nodeid(yp, ys->ys_argument, -1, &yres) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (yres == NULL){
|
if (yres == NULL){
|
||||||
clicon_err(OE_YANG, 0, "schemanode sanity check of %d %s",
|
clicon_err(OE_YANG, 0, "schemanode sanity check of %d %s",
|
||||||
|
|
@ -1759,7 +1759,7 @@ ys_schemanode_check(yang_stmt *ys,
|
||||||
break;
|
break;
|
||||||
case Y_DEVIATION:
|
case Y_DEVIATION:
|
||||||
yspec = ys_spec(ys);
|
yspec = ys_spec(ys);
|
||||||
if (yang_abs_schema_nodeid(yspec, ys->ys_argument, &yres) < 0)
|
if (yang_abs_schema_nodeid(yspec, ys->ys_argument, -1, &yres) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (yres == NULL){
|
if (yres == NULL){
|
||||||
clicon_err(OE_YANG, 0, "schemanode sanity check of %s", ys->ys_argument);
|
clicon_err(OE_YANG, 0, "schemanode sanity check of %s", ys->ys_argument);
|
||||||
|
|
@ -1902,6 +1902,7 @@ yang_apply(yang_node *yn,
|
||||||
* @param[in] yn Yang node. Find next yang stmt and return that if match.
|
* @param[in] yn Yang node. Find next yang stmt and return that if match.
|
||||||
* @param[in] vec Vector of nodeid's in a schema node identifier, eg a/b
|
* @param[in] vec Vector of nodeid's in a schema node identifier, eg a/b
|
||||||
* @param[in] nvec Length of vec
|
* @param[in] nvec Length of vec
|
||||||
|
* @param[in] keyword A schemode of this type, or -1 if any
|
||||||
* @param[out] yres Result yang statement node, or NULL if not found
|
* @param[out] yres Result yang statement node, or NULL if not found
|
||||||
* @retval -1 Error, with clicon_err called
|
* @retval -1 Error, with clicon_err called
|
||||||
* @retval 0 OK
|
* @retval 0 OK
|
||||||
|
|
@ -1910,6 +1911,7 @@ static int
|
||||||
schema_nodeid_vec(yang_node *yn,
|
schema_nodeid_vec(yang_node *yn,
|
||||||
char **vec,
|
char **vec,
|
||||||
int nvec,
|
int nvec,
|
||||||
|
enum rfc_6020 keyword,
|
||||||
yang_stmt **yres)
|
yang_stmt **yres)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
|
|
@ -1940,6 +1942,8 @@ schema_nodeid_vec(yang_node *yn,
|
||||||
ys = yn->yn_stmt[i];
|
ys = yn->yn_stmt[i];
|
||||||
if (!yang_schemanode(ys))
|
if (!yang_schemanode(ys))
|
||||||
continue;
|
continue;
|
||||||
|
if (keyword != -1 && keyword != ys->ys_keyword)
|
||||||
|
continue;
|
||||||
/* some keys dont have arguments, match on key */
|
/* some keys dont have arguments, match on key */
|
||||||
if (ys->ys_keyword == Y_INPUT || ys->ys_keyword == Y_OUTPUT){
|
if (ys->ys_keyword == Y_INPUT || ys->ys_keyword == Y_OUTPUT){
|
||||||
if (strcmp(nodeid, yang_key2str(ys->ys_keyword)) == 0){
|
if (strcmp(nodeid, yang_key2str(ys->ys_keyword)) == 0){
|
||||||
|
|
@ -1966,7 +1970,7 @@ schema_nodeid_vec(yang_node *yn,
|
||||||
goto ok;
|
goto ok;
|
||||||
}
|
}
|
||||||
/* recursive call using ynext */
|
/* recursive call using ynext */
|
||||||
if (schema_nodeid_vec(ynext, vec+1, nvec-1, yres) < 0)
|
if (schema_nodeid_vec(ynext, vec+1, nvec-1, keyword, yres) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
ok:
|
ok:
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
@ -1977,16 +1981,22 @@ schema_nodeid_vec(yang_node *yn,
|
||||||
/*! Given an absolute schema-nodeid (eg /a/b/c) find matching yang spec
|
/*! Given an absolute schema-nodeid (eg /a/b/c) find matching yang spec
|
||||||
* @param[in] yspec Yang specification.
|
* @param[in] yspec Yang specification.
|
||||||
* @param[in] schema_nodeid Absolute schema-node-id, ie /a/b
|
* @param[in] schema_nodeid Absolute schema-node-id, ie /a/b
|
||||||
|
* @param[in] keyword A schemode of this type, or -1 if any
|
||||||
* @param[out] yres Result yang statement node, or NULL if not found
|
* @param[out] yres Result yang statement node, or NULL if not found
|
||||||
* @retval -1 Error, with clicon_err called
|
* @retval -1 Error, with clicon_err called
|
||||||
* @retval 0 OK (if yres set then found, if yres=0 then not found)
|
* @retval 0 OK (if yres set then found, if yres=0 then not found)
|
||||||
* Assume schema nodeid:s have prefixes, (actually the first).
|
* Assume schema nodeid:s have prefixes, (actually the first).
|
||||||
* @see yang_desc_schema_nodeid
|
* @see yang_desc_schema_nodeid
|
||||||
|
* @see RFC7950 6.5
|
||||||
|
o schema node: A node in the schema tree. One of action, container,
|
||||||
|
leaf, leaf-list, list, choice, case, rpc, input, output,
|
||||||
|
notification, anydata, and anyxml.
|
||||||
* Used in yang: deviation, top-level augment
|
* Used in yang: deviation, top-level augment
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
yang_abs_schema_nodeid(yang_spec *yspec,
|
yang_abs_schema_nodeid(yang_spec *yspec,
|
||||||
char *schema_nodeid,
|
char *schema_nodeid,
|
||||||
|
enum rfc_6020 keyword,
|
||||||
yang_stmt **yres)
|
yang_stmt **yres)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
|
|
@ -1996,6 +2006,7 @@ yang_abs_schema_nodeid(yang_spec *yspec,
|
||||||
char *id;
|
char *id;
|
||||||
char *prefix = NULL;
|
char *prefix = NULL;
|
||||||
yang_stmt *yprefix;
|
yang_stmt *yprefix;
|
||||||
|
yang_stmt *ys;
|
||||||
|
|
||||||
/* check absolute schema_nodeid */
|
/* check absolute schema_nodeid */
|
||||||
if (schema_nodeid[0] != '/'){
|
if (schema_nodeid[0] != '/'){
|
||||||
|
|
@ -2031,7 +2042,7 @@ yang_abs_schema_nodeid(yang_spec *yspec,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ymod == NULL){ /* Try with topnode */
|
if (ymod == NULL){ /* Try with topnode */
|
||||||
yang_stmt *ys;
|
|
||||||
if ((ys = yang_find_topnode(yspec, id, YC_SCHEMANODE)) == NULL){
|
if ((ys = yang_find_topnode(yspec, id, YC_SCHEMANODE)) == NULL){
|
||||||
clicon_err(OE_YANG, 0, "Module with id:%s:%s not found", prefix,id);
|
clicon_err(OE_YANG, 0, "Module with id:%s:%s not found", prefix,id);
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -2041,7 +2052,7 @@ yang_abs_schema_nodeid(yang_spec *yspec,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (schema_nodeid_vec((yang_node*)ymod, vec+1, nvec-1, yres) < 0)
|
if (schema_nodeid_vec((yang_node*)ymod, vec+1, nvec-1, keyword, yres) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
ok: /* yres may not be set */
|
ok: /* yres may not be set */
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
@ -2056,14 +2067,17 @@ yang_abs_schema_nodeid(yang_spec *yspec,
|
||||||
/*! Given a descendant schema-nodeid (eg a/b/c) find matching yang spec
|
/*! Given a descendant schema-nodeid (eg a/b/c) find matching yang spec
|
||||||
* @param[in] yn Yang node
|
* @param[in] yn Yang node
|
||||||
* @param[in] schema_nodeid Descendant schema-node-id, ie a/b
|
* @param[in] schema_nodeid Descendant schema-node-id, ie a/b
|
||||||
* @retval NULL Error, with clicon_err called
|
* @param[in] keyword A schemode of this type, or -1 if any
|
||||||
* @retval yres First yang node matching schema nodeid
|
* @param[out] yres First yang node matching schema nodeid
|
||||||
|
* @retval 0 OK
|
||||||
|
* @retval -1 Error, with clicon_err called
|
||||||
* @see yang_schema_nodeid
|
* @see yang_schema_nodeid
|
||||||
* Used in yang: unique, refine, uses augment
|
* Used in yang: unique, refine, uses augment
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
yang_desc_schema_nodeid(yang_node *yn,
|
yang_desc_schema_nodeid(yang_node *yn,
|
||||||
char *schema_nodeid,
|
char *schema_nodeid,
|
||||||
|
enum rfc_6020 keyword,
|
||||||
yang_stmt **yres)
|
yang_stmt **yres)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
|
|
@ -2079,7 +2093,7 @@ yang_desc_schema_nodeid(yang_node *yn,
|
||||||
}
|
}
|
||||||
if ((vec = clicon_strsep(schema_nodeid, "/", &nvec)) == NULL)
|
if ((vec = clicon_strsep(schema_nodeid, "/", &nvec)) == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
if (schema_nodeid_vec(yn, vec, nvec, yres) < 0)
|
if (schema_nodeid_vec(yn, vec, nvec, keyword, yres) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue