Changed singnature of ys_real_module and improved error handling
This commit is contained in:
parent
1a2e074539
commit
576533ed82
7 changed files with 52 additions and 29 deletions
|
|
@ -324,7 +324,10 @@ api_data_post(clicon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
/* ybot is parent of spec(parent(data))) */
|
/* ybot is parent of spec(parent(data))) */
|
||||||
if (ymoddata && (ydata = xml_spec(xdata)) != NULL){
|
if (ymoddata && (ydata = xml_spec(xdata)) != NULL){
|
||||||
if (ys_real_module(ydata) != ymoddata){
|
yang_stmt *ymod = NULL;
|
||||||
|
if (ys_real_module(ydata, &ymod) < 0)
|
||||||
|
goto done;
|
||||||
|
if (ymod != ymoddata){
|
||||||
if (netconf_malformed_message_xml(&xerr, "Data is not prefixed with matching namespace") < 0)
|
if (netconf_malformed_message_xml(&xerr, "Data is not prefixed with matching namespace") < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
|
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
|
||||||
|
|
|
||||||
|
|
@ -215,7 +215,7 @@ yang_stmt *yn_each(yang_stmt *yn, yang_stmt *ys);
|
||||||
char *yang_key2str(int keyword);
|
char *yang_key2str(int keyword);
|
||||||
int ys_module_by_xml(yang_stmt *ysp, struct xml *xt, yang_stmt **ymodp);
|
int ys_module_by_xml(yang_stmt *ysp, struct xml *xt, yang_stmt **ymodp);
|
||||||
yang_stmt *ys_module(yang_stmt *ys);
|
yang_stmt *ys_module(yang_stmt *ys);
|
||||||
yang_stmt *ys_real_module(yang_stmt *ys);
|
int ys_real_module(yang_stmt *ys, yang_stmt **ymod);
|
||||||
yang_stmt *ys_spec(yang_stmt *ys);
|
yang_stmt *ys_spec(yang_stmt *ys);
|
||||||
yang_stmt *yang_find(yang_stmt *yn, int keyword, const char *argument);
|
yang_stmt *yang_find(yang_stmt *yn, int keyword, const char *argument);
|
||||||
int yang_match(yang_stmt *yn, int keyword, char *argument);
|
int yang_match(yang_stmt *yn, int keyword, char *argument);
|
||||||
|
|
|
||||||
|
|
@ -716,12 +716,13 @@ xml2json1_cbuf(cbuf *cb,
|
||||||
enum childtype childt;
|
enum childtype childt;
|
||||||
enum array_element_type xc_arraytype;
|
enum array_element_type xc_arraytype;
|
||||||
yang_stmt *ys;
|
yang_stmt *ys;
|
||||||
yang_stmt *ymod; /* yang module */
|
yang_stmt *ymod = NULL; /* yang module */
|
||||||
int commas;
|
int commas;
|
||||||
char *modname = NULL;
|
char *modname = NULL;
|
||||||
|
|
||||||
if ((ys = xml_spec(x)) != NULL){
|
if ((ys = xml_spec(x)) != NULL){
|
||||||
ymod = ys_real_module(ys);
|
if (ys_real_module(ys, &ymod) < 0)
|
||||||
|
goto done;
|
||||||
modname = yang_argument_get(ymod);
|
modname = yang_argument_get(ymod);
|
||||||
if (modname0 && strcmp(modname, modname0) == 0)
|
if (modname0 && strcmp(modname, modname0) == 0)
|
||||||
modname=NULL;
|
modname=NULL;
|
||||||
|
|
|
||||||
|
|
@ -298,7 +298,8 @@ yang2api_path_fmt_1(yang_stmt *ys,
|
||||||
cbuf *cb)
|
cbuf *cb)
|
||||||
{
|
{
|
||||||
yang_stmt *yp; /* parent */
|
yang_stmt *yp; /* parent */
|
||||||
yang_stmt *ymod;
|
yang_stmt *ymod = NULL;
|
||||||
|
yang_stmt *ypmod = NULL;
|
||||||
int i;
|
int i;
|
||||||
cvec *cvk = NULL; /* vector of index keys */
|
cvec *cvk = NULL; /* vector of index keys */
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
|
|
@ -329,7 +330,11 @@ yang2api_path_fmt_1(yang_stmt *ys,
|
||||||
cprintf(cb, "/");
|
cprintf(cb, "/");
|
||||||
}
|
}
|
||||||
/* If parent namespace/module is different from child -> add child prefix */
|
/* If parent namespace/module is different from child -> add child prefix */
|
||||||
if (ys_real_module(yp) != (ymod = ys_real_module(ys)))
|
if (ys_real_module(yp, &ypmod) < 0)
|
||||||
|
goto done;
|
||||||
|
if (ys_real_module(ys, &ymod) < 0)
|
||||||
|
goto done;
|
||||||
|
if (ypmod != ymod)
|
||||||
cprintf(cb, "%s:", yang_argument_get(ymod));
|
cprintf(cb, "%s:", yang_argument_get(ymod));
|
||||||
}
|
}
|
||||||
else /* top symbol - mark with name prefix */
|
else /* top symbol - mark with name prefix */
|
||||||
|
|
|
||||||
|
|
@ -882,9 +882,10 @@ yang_find_schemanode(yang_stmt *yn,
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Given a yang statement, find the prefix associated to this module
|
/*! Given a yang statement, find the prefix associated to this module
|
||||||
|
*
|
||||||
* @param[in] ys Yang statement in module tree (or module itself)
|
* @param[in] ys Yang statement in module tree (or module itself)
|
||||||
* @retval NULL Not found
|
* @retval NULL No prefix found. This is an error
|
||||||
* @retval prefix Prefix as char* pointer into yang tree
|
* @retval prefix OK: Prefix as char* pointer into yang tree
|
||||||
* @code
|
* @code
|
||||||
* char *myprefix;
|
* char *myprefix;
|
||||||
* myprefix = yang_find_myprefix(ys);
|
* myprefix = yang_find_myprefix(ys);
|
||||||
|
|
@ -893,25 +894,26 @@ yang_find_schemanode(yang_stmt *yn,
|
||||||
char *
|
char *
|
||||||
yang_find_myprefix(yang_stmt *ys)
|
yang_find_myprefix(yang_stmt *ys)
|
||||||
{
|
{
|
||||||
yang_stmt *ymod; /* My module */
|
yang_stmt *ymod = NULL; /* My module */
|
||||||
yang_stmt *yprefix;
|
yang_stmt *yprefix;
|
||||||
char *prefix = NULL;
|
char *prefix = NULL;
|
||||||
|
|
||||||
/* Not good enough with submodule, must be actual module */
|
/* Not good enough with submodule, must be actual module */
|
||||||
if ((ymod = ys_real_module(ys)) == NULL){
|
if (ys_real_module(ys, &ymod) < 0)
|
||||||
clicon_err(OE_YANG, 0, "My yang module not found");
|
goto done;
|
||||||
|
if ((yprefix = yang_find(ymod, Y_PREFIX, NULL)) == NULL){
|
||||||
|
clicon_err(OE_YANG, ENOENT, "No prefix found for module %s", yang_argument_get(ymod));
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if ((yprefix = yang_find(ymod, Y_PREFIX, NULL)) == NULL)
|
|
||||||
goto done;
|
|
||||||
prefix = yang_argument_get(yprefix);
|
prefix = yang_argument_get(yprefix);
|
||||||
done:
|
done:
|
||||||
return prefix;
|
return prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Given a yang statement, find the namespace URI associated to this module
|
/*! Given a yang statement, find the namespace URI associated to this module
|
||||||
|
*
|
||||||
* @param[in] ys Yang statement in module tree (or module itself)
|
* @param[in] ys Yang statement in module tree (or module itself)
|
||||||
* @retval NULL Not found
|
* @retval NULL Error: No namespace found. This is an error
|
||||||
* @retval ns Namspace URI as char* pointer into yang tree
|
* @retval ns Namspace URI as char* pointer into yang tree
|
||||||
* @code
|
* @code
|
||||||
* char *myns = yang_find_mynamespace(ys);
|
* char *myns = yang_find_mynamespace(ys);
|
||||||
|
|
@ -921,16 +923,16 @@ yang_find_myprefix(yang_stmt *ys)
|
||||||
char *
|
char *
|
||||||
yang_find_mynamespace(yang_stmt *ys)
|
yang_find_mynamespace(yang_stmt *ys)
|
||||||
{
|
{
|
||||||
yang_stmt *ymod; /* My module */
|
yang_stmt *ymod = NULL; /* My module */
|
||||||
yang_stmt *ynamespace;
|
yang_stmt *ynamespace;
|
||||||
char *ns = NULL;
|
char *ns = NULL;
|
||||||
|
|
||||||
if ((ymod = ys_real_module(ys)) == NULL){
|
if (ys_real_module(ys, &ymod) < 0)
|
||||||
clicon_err(OE_YANG, ENOENT, "My yang module not found");
|
goto done;
|
||||||
|
if ((ynamespace = yang_find(ymod, Y_NAMESPACE, NULL)) == NULL){
|
||||||
|
clicon_err(OE_YANG, ENOENT, "No namespace found for module %s", yang_argument_get(ymod));
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if ((ynamespace = yang_find(ymod, Y_NAMESPACE, NULL)) == NULL)
|
|
||||||
goto done;
|
|
||||||
ns = yang_argument_get(ynamespace);
|
ns = yang_argument_get(ynamespace);
|
||||||
done:
|
done:
|
||||||
return ns;
|
return ns;
|
||||||
|
|
@ -1255,21 +1257,29 @@ ys_module(yang_stmt *ys)
|
||||||
* With "real" top module means that if sub-module is the top-node,
|
* With "real" top module means that if sub-module is the top-node,
|
||||||
* the module that the sub-module belongs-to is found recursively
|
* the module that the sub-module belongs-to is found recursively
|
||||||
* @param[in] ys Any yang statement in a yang tree
|
* @param[in] ys Any yang statement in a yang tree
|
||||||
* @retval ymod The top module or sub-module
|
* @param[out] ymod The top module or sub-module
|
||||||
|
* @retval 0 OK, returned module in ymod
|
||||||
|
* @retval -1 YANG validation error: all yang statements should have a "real" module
|
||||||
* @see ys_module
|
* @see ys_module
|
||||||
* @note For an augmented node, the original module is returned
|
* @note For an augmented node, the original module is returned
|
||||||
*/
|
*/
|
||||||
yang_stmt *
|
int
|
||||||
ys_real_module(yang_stmt *ys)
|
ys_real_module(yang_stmt *ys,
|
||||||
|
yang_stmt **ymod)
|
||||||
{
|
{
|
||||||
|
int retval = -1;
|
||||||
yang_stmt *ym = NULL;
|
yang_stmt *ym = NULL;
|
||||||
yang_stmt *yb;
|
yang_stmt *yb;
|
||||||
char *name;
|
char *name;
|
||||||
yang_stmt *yspec;
|
yang_stmt *yspec;
|
||||||
|
|
||||||
|
if (ymod == NULL){
|
||||||
|
clicon_err(OE_YANG, EINVAL, "ymod is NULL");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
if ((ym = ys_module(ys)) != NULL){
|
if ((ym = ys_module(ys)) != NULL){
|
||||||
yspec = ys_spec(ym);
|
yspec = ys_spec(ym);
|
||||||
while (yang_keyword_get(ym) == Y_SUBMODULE){
|
while (ym && yang_keyword_get(ym) == Y_SUBMODULE){
|
||||||
if ((yb = yang_find(ym, Y_BELONGS_TO, NULL)) == NULL){
|
if ((yb = yang_find(ym, Y_BELONGS_TO, NULL)) == NULL){
|
||||||
clicon_err(OE_YANG, ENOENT, "No belongs-to statement of submodule %s", yang_argument_get(ym)); /* shouldnt happen */
|
clicon_err(OE_YANG, ENOENT, "No belongs-to statement of submodule %s", yang_argument_get(ym)); /* shouldnt happen */
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -1278,12 +1288,14 @@ ys_real_module(yang_stmt *ys)
|
||||||
clicon_err(OE_YANG, ENOENT, "Belongs-to statement of submodule %s has no argument", yang_argument_get(ym)); /* shouldnt happen */
|
clicon_err(OE_YANG, ENOENT, "Belongs-to statement of submodule %s has no argument", yang_argument_get(ym)); /* shouldnt happen */
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
ym = yang_find_module_by_name(yspec, name);
|
if ((ym = yang_find_module_by_name(yspec, name)) == NULL)
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ym;
|
*ymod = ym;
|
||||||
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
return NULL;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Find top of tree, the yang specification from within the tree
|
/*! Find top of tree, the yang specification from within the tree
|
||||||
|
|
|
||||||
|
|
@ -504,6 +504,7 @@ yang_find_module_by_prefix(yang_stmt *ys,
|
||||||
clicon_err(OE_YANG, 0, "My yang spec not found");
|
clicon_err(OE_YANG, 0, "My yang spec not found");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
/* First try own module */
|
||||||
if ((my_ymod = ys_module(ys)) == NULL){
|
if ((my_ymod = ys_module(ys)) == NULL){
|
||||||
clicon_err(OE_YANG, 0, "My yang module not found");
|
clicon_err(OE_YANG, 0, "My yang module not found");
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -513,6 +514,7 @@ yang_find_module_by_prefix(yang_stmt *ys,
|
||||||
ymod = my_ymod;
|
ymod = my_ymod;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
/* If no match, try imported modules */
|
||||||
yimport = NULL;
|
yimport = NULL;
|
||||||
while ((yimport = yn_each(my_ymod, yimport)) != NULL) {
|
while ((yimport = yn_each(my_ymod, yimport)) != NULL) {
|
||||||
if (yang_keyword_get(yimport) != Y_IMPORT)
|
if (yang_keyword_get(yimport) != Y_IMPORT)
|
||||||
|
|
|
||||||
|
|
@ -353,7 +353,7 @@ yang_expand_grouping(yang_stmt *yn)
|
||||||
do {
|
do {
|
||||||
if (yp == ygrouping){
|
if (yp == ygrouping){
|
||||||
|
|
||||||
clicon_err(OE_YANG, EFAULT, "Yang use of grouping %s in module %s is defined inside the grouping (recursion)",
|
clicon_err(OE_YANG, EFAULT, "Yang use of grouping %s in module %s is defined inside the grouping (recursion), see RFC 7950 Sec 7.12: A grouping MUST NOT reference itself",
|
||||||
yang_argument_get(ys),
|
yang_argument_get(ys),
|
||||||
yang_argument_get(ys_module(yn))
|
yang_argument_get(ys_module(yn))
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue