yang load add test to not parse files if not already loaded
This commit is contained in:
parent
411a67f9d6
commit
48a7eac096
4 changed files with 36 additions and 10 deletions
|
|
@ -665,7 +665,7 @@ ys_free1(yang_stmt *ys,
|
||||||
* Freed here once.
|
* Freed here once.
|
||||||
*/
|
*/
|
||||||
if (yang_keyword_get(ys) == Y_UNKNOWN &&
|
if (yang_keyword_get(ys) == Y_UNKNOWN &&
|
||||||
strcmp(yang_argument_get(ys), "yangmnt:mount-point")==0){
|
strcmp(yang_argument_get(ys), "yangmnt:mount-point") == 0){
|
||||||
xml_yang_mount_freeall(ys->ys_cvec);
|
xml_yang_mount_freeall(ys->ys_cvec);
|
||||||
}
|
}
|
||||||
cvec_free(ys->ys_cvec);
|
cvec_free(ys->ys_cvec);
|
||||||
|
|
|
||||||
|
|
@ -818,17 +818,19 @@ yang_metadata_init(clicon_handle h)
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Given yang-lib module-set XML tree, parse all modules into an yspec
|
/*! Given yang-lib module-set XML tree, parse modules into an yspec
|
||||||
*
|
*
|
||||||
|
* Skip module if already loaded
|
||||||
* This function is used where a yang-lib module-set is available to populate
|
* This function is used where a yang-lib module-set is available to populate
|
||||||
* an XML mount-point.
|
* an XML mount-point.
|
||||||
* @param[in] h Clicon handle
|
* @param[in] h Clicon handle
|
||||||
* @param[in] xylib yang-lib XML tree on the form <yang-lib>...
|
* @param[in] yanglib XML tree on the form <yang-lib>...
|
||||||
* @param[in] yspec Will be populated with YANGs, is consumed
|
* @param[in] yspec Will be populated with YANGs, is consumed
|
||||||
* @retval 1 OK
|
* @retval 1 OK
|
||||||
* @retval 0 Parse error
|
* @retval 0 Parse error
|
||||||
* @retval -1 Error
|
* @retval -1 Error
|
||||||
* @see xml_schema_add_mount_points
|
* @see xml_schema_add_mount_points
|
||||||
|
* XXX: Ensure yang-lib is always there otherwise get state dont work for mountpoint
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
yang_lib2yspec(clicon_handle h,
|
yang_lib2yspec(clicon_handle h,
|
||||||
|
|
@ -843,6 +845,9 @@ yang_lib2yspec(clicon_handle h,
|
||||||
cxobj **vec = NULL;
|
cxobj **vec = NULL;
|
||||||
size_t veclen;
|
size_t veclen;
|
||||||
int i;
|
int i;
|
||||||
|
yang_stmt *ymod;
|
||||||
|
yang_stmt *yrev;
|
||||||
|
int modmin = 0;
|
||||||
|
|
||||||
if (xpath_vec(yanglib, nsc, "module-set/module", &vec, &veclen) < 0)
|
if (xpath_vec(yanglib, nsc, "module-set/module", &vec, &veclen) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -852,12 +857,31 @@ yang_lib2yspec(clicon_handle h,
|
||||||
continue;
|
continue;
|
||||||
if ((revision = xml_find_body(xi, "revision")) == NULL)
|
if ((revision = xml_find_body(xi, "revision")) == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
if ((ymod = yang_find(yspec, Y_MODULE, name)) != NULL ||
|
||||||
|
(ymod = yang_find(yspec, Y_SUBMODULE, name)) != NULL){
|
||||||
|
/* Skip if matching or no revision
|
||||||
|
* Note this algorithm does not work for multiple revisions
|
||||||
|
*/
|
||||||
|
if ((yrev = yang_find(ymod, Y_REVISION, NULL)) == NULL){
|
||||||
|
modmin++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (strcmp(yang_argument_get(yrev), revision) == 0){
|
||||||
|
modmin++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (yang_parse_module(h, name, revision, yspec, NULL) == NULL)
|
if (yang_parse_module(h, name, revision, yspec, NULL) == NULL)
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
#ifdef YANG_SCHEMA_MOUNT_YANG_LIB_FORCE
|
#ifdef YANG_SCHEMA_MOUNT_YANG_LIB_FORCE
|
||||||
/* XXX: Ensure yang-lib is always there otherwise get state dont work for mountpoint */
|
/* XXX: Ensure yang-lib is always there otherwise get state dont work for mountpoint */
|
||||||
if (yang_parse_module(h, "ietf-yang-library", "2019-01-04", yspec, NULL) < 0)
|
if ((ymod = yang_find(yspec, Y_MODULE, "ietf-yang-library")) != NULL &&
|
||||||
|
(yrev = yang_find(ymod, Y_REVISION, NULL)) != NULL &&
|
||||||
|
strcmp(yang_argument_get(yrev), "2019-01-04") == 0){
|
||||||
|
modmin++;
|
||||||
|
}
|
||||||
|
else if (yang_parse_module(h, "ietf-yang-library", "2019-01-04", yspec, NULL) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
#endif
|
#endif
|
||||||
if (yang_parse_post(h, yspec, 0) < 0)
|
if (yang_parse_post(h, yspec, 0) < 0)
|
||||||
|
|
|
||||||
|
|
@ -1063,6 +1063,7 @@ yang_parse_filename(clicon_handle h,
|
||||||
* @retval -1 Error
|
* @retval -1 Error
|
||||||
*
|
*
|
||||||
* See top of file for diagram of calling order
|
* See top of file for diagram of calling order
|
||||||
|
* @note does not check wether the module is already loaded
|
||||||
*/
|
*/
|
||||||
yang_stmt *
|
yang_stmt *
|
||||||
yang_parse_module(clicon_handle h,
|
yang_parse_module(clicon_handle h,
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,9 @@ xml_yang_mount_set(cxobj *x,
|
||||||
if ((cvv = yang_cvec_get(yu)) != NULL &&
|
if ((cvv = yang_cvec_get(yu)) != NULL &&
|
||||||
(cv = cvec_find(cvv, xpath)) != NULL &&
|
(cv = cvec_find(cvv, xpath)) != NULL &&
|
||||||
(yspec0 = cv_void_get(cv)) != NULL){
|
(yspec0 = cv_void_get(cv)) != NULL){
|
||||||
|
#if 0 /* Problematic to free yang specs here, upper layers should handle it? */
|
||||||
ys_free(yspec0);
|
ys_free(yspec0);
|
||||||
|
#endif
|
||||||
cv_void_set(cv, NULL);
|
cv_void_set(cv, NULL);
|
||||||
}
|
}
|
||||||
else if ((cv = yang_cvec_add(yu, CGV_VOID, xpath)) == NULL)
|
else if ((cv = yang_cvec_add(yu, CGV_VOID, xpath)) == NULL)
|
||||||
|
|
@ -247,7 +249,6 @@ xml_yang_mount_freeall(cvec *cvv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! Find schema mounts - callback function for xml_apply
|
/*! Find schema mounts - callback function for xml_apply
|
||||||
*
|
*
|
||||||
* @param[in] x XML node
|
* @param[in] x XML node
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue