Set domain as yang-spec name

This commit is contained in:
Olof hagsand 2024-09-25 18:30:17 +02:00
parent e890ff0f13
commit c06945ec37
12 changed files with 111 additions and 45 deletions

View file

@ -1020,7 +1020,7 @@ text_modify(clixon_handle h,
}
if (clicon_option_bool(h, "CLICON_YANG_SCHEMA_MOUNT")){
/* Check if xc is unresolved mountpoint, ie no yang mount binding yet */
if ((ismount = xml_yang_mount_get(h, x1c, NULL, &mount_yspec)) < 0)
if ((ismount = xml_yang_mount_get(h, x1c, NULL, NULL, &mount_yspec)) < 0)
goto done;
if (ismount && mount_yspec == NULL &&
!xml_flag(x1c, XML_FLAG_ANYDATA)){

View file

@ -81,7 +81,7 @@
* @param[out] nvec Number of entries in returned vector
* @retval vec Vector of strings. NULL terminated. Free after use
* @retval NULL Error *
* @see clicon_strsplit
* @see clixon_strsplit
*/
char **
clicon_strsep(char *string,

View file

@ -1027,7 +1027,7 @@ xml_yang_validate_add(clixon_handle h,
validate_level vl = VL_NONE;
if (clicon_option_bool(h, "CLICON_YANG_SCHEMA_MOUNT")){
if ((ret = xml_yang_mount_get(h, xt, &vl, NULL)) < 0)
if ((ret = xml_yang_mount_get(h, xt, &vl, NULL, NULL)) < 0)
goto done;
/* Check if validate beyond mountpoints */
if (ret == 1 && vl == VL_NONE)
@ -1253,7 +1253,7 @@ xml_yang_validate_all(clixon_handle h,
int inext;
if (clicon_option_bool(h, "CLICON_YANG_SCHEMA_MOUNT")){
if ((ret = xml_yang_mount_get(h, xt, &vl, NULL)) < 0)
if ((ret = xml_yang_mount_get(h, xt, &vl, NULL, NULL)) < 0)
goto done;
/* Check if validate beyond mountpoints */
if (ret == 1 && vl == VL_NONE)

View file

@ -464,7 +464,7 @@ xml_bind_yang0_opt(clixon_handle h,
ybc = YB_PARENT;
if (h && clicon_option_bool(h, "CLICON_YANG_SCHEMA_MOUNT")){
yspec1 = NULL;
if ((ret = xml_yang_mount_get(h, xt, NULL, &yspec1)) < 0)
if ((ret = xml_yang_mount_get(h, xt, NULL, NULL, &yspec1)) < 0) // XXX read här
goto done;
if (ret == 0)
yspec1 = yspec;
@ -474,14 +474,14 @@ xml_bind_yang0_opt(clixon_handle h,
else if (h == NULL)
goto ok; /* treat as anydata */
else{
if ((ret = yang_schema_yanglib_parse_mount(h, xt)) < 0)
if ((ret = yang_schema_yanglib_parse_mount(h, xt)) < 0) // XXX malloc + freed här
goto done;
if (ret == 0){ /* Special flag if mount-point but no yanglib */
xml_flag_set(xt, XML_FLAG_ANYDATA);
goto ok;
}
/* Try again */
if ((ret = xml_yang_mount_get(h, xt, NULL, &yspec1)) < 0)
if ((ret = xml_yang_mount_get(h, xt, NULL, NULL, &yspec1)) < 0)
goto done;
if (yspec1)
ybc = YB_MODULE;

View file

@ -395,6 +395,31 @@ yang_cvec_add(yang_stmt *ys,
return cv;
}
/*! Remove old value to yang cvec
*
* @param[in] ys Yang statement
* @param[in] name Name of variable
* @retval 0 OK
* @retval -1 Error
*/
int
yang_cvec_rm(yang_stmt *ys,
char *name)
{
cvec *cvv;
cg_var *cv;
if ((cvv = yang_cvec_get(ys)) != NULL &&
(cv = cvec_find(cvv, name)) != NULL){
if (cvec_len(cvv) <= 1){
yang_cvec_set(ys, NULL);
}
else
cvec_del(cvv, cv);
}
return 0;
}
/*! Get yang stmt flags, used for internal algorithms
*
* @param[in] ys Yang statement
@ -839,6 +864,7 @@ yspec_new(clixon_handle h,
yang_stmt *
yspec_new_shared(clixon_handle h,
char *name,
char *domain,
yang_stmt *yspec0)
{
yang_stmt *yspec1 = NULL;
@ -848,7 +874,7 @@ yspec_new_shared(clixon_handle h,
yspec1 = yspec0;
}
else {
if ((yspec1 = yspec_new(h, name)) == NULL)
if ((yspec1 = yspec_new(h, domain)) == NULL)
goto done;
yang_flag_set(yspec1, YANG_FLAG_SPEC_MOUNT);
clixon_debug(CLIXON_DBG_YANG, "new yang-spec: %p", yspec1);

View file

@ -94,7 +94,6 @@ struct yang_stmt {
Y_REVISION (uint32)
Y_REVISION_DATE (uint32)
Y_UNKNOWN (optional argument)
Y_SPEC: mount-point xpath
Y_ENUM: value
*/
cvec *ys_cvec; /* List of stmt-specific variables

View file

@ -261,21 +261,9 @@ yang_mount_set(yang_stmt *y,
yang_stmt *yspec)
{
int retval = -1;
cg_var *cv2;
if ((cv2 = cv_new(CGV_STRING)) == NULL){
clixon_err(OE_YANG, errno, "cv_new");
goto done;
}
if (cv_string_set(cv2, xpath) == NULL){
clixon_err(OE_UNIX, errno, "cv_string_set");
goto done;
}
/* tag yspec with key/xpath */
yang_cv_set(yspec, cv2);
yang_flag_set(y, YANG_FLAG_MOUNTPOINT); /* Cache value */
retval = 0;
done:
return retval;
}
@ -344,6 +332,7 @@ yang_mount_xmnt2ymnt_xpath(clixon_handle h,
* @param[in] h Clixon handle
* @param[in] xmnt XML mount-point
* @param[out] vallevel Do or dont do full RFC 7950 validation if given
* @param[out] xpathp malloced xpath in canonical form (if ret is 1)
* @param[out] yspec YANG stmt spec of mount-point (if ret is 1)
* @retval 1 x is a mount-point: yspec may be set
* @retval 0 x is not a mount-point
@ -353,6 +342,7 @@ int
xml_yang_mount_get(clixon_handle h,
cxobj *xmnt,
validate_level *vl,
char **xpathp,
yang_stmt **yspec)
{
int retval = -1;
@ -369,6 +359,10 @@ xml_yang_mount_get(clixon_handle h,
goto done;
if (yspec && yang_mount_get(ymnt, xpath, yspec) < 0)
goto done;
if (xpathp){
*xpathp = xpath;
xpath = NULL;
}
retval = 1;
done:
if (xpath)
@ -737,12 +731,10 @@ yang_schema_mount_statistics(clixon_handle h,
while ((cv = cvec_each(cvv, cv)) != NULL) {
if ((xmnt = cv_void_get(cv)) == NULL)
continue;
if ((ret = xml_yang_mount_get(h, xmnt, NULL, &yspec)) < 0)
if ((ret = xml_yang_mount_get(h, xmnt, NULL, &xpath, &yspec)) < 0)
goto done;
if (ret == 0)
continue;
if (xml2xpath(xmnt, NULL, 1, 0, &xpath) < 0)
goto done;
cprintf(cb, "<module-set><name>mountpoint: ");
xml_chardata_cbuf_append(cb, 0, xpath);
cprintf(cb, "</name>");
@ -753,7 +745,7 @@ yang_schema_mount_statistics(clixon_handle h,
while ((cv1 = cvec_each(cvv, cv1)) != NULL) {
if (cv == cv1)
continue;
if ((ret = xml_yang_mount_get(h, cv_void_get(cv1), NULL, &yspec1)) < 0)
if ((ret = xml_yang_mount_get(h, cv_void_get(cv1), NULL, NULL, &yspec1)) < 0)
goto done;
if (yspec1 && yspec == yspec1)
break;
@ -844,7 +836,7 @@ yang_schema_find_share(clixon_handle h,
continue;
/* Find and return yspec */
*yspecp = NULL;
if ((ret = xml_yang_mount_get(h, xmnt, NULL, yspecp)) < 0)
if ((ret = xml_yang_mount_get(h, xmnt, NULL, NULL, yspecp)) < 0)
goto done;
if (ret == 1 && *yspecp != NULL)
break;
@ -903,14 +895,16 @@ yang_schema_yanglib_parse_mount(clixon_handle h,
if (yang_schema_find_share(h, xt, xyanglib, &yspec0) < 0)
goto done;
}
if ((yspec1 = yspec_new_shared(h, xpath, yspec0)) < 0)
if ((yspec1 = yspec_new_shared(h, xpath, domain, yspec0)) < 0)
goto done;
/* Either yspec0 = NULL and yspec1 is new, or yspec0 == yspec1 != NULL (shared) */
if (yspec0 == NULL && yspec1 != NULL){
if ((ret = yang_lib2yspec(h, xyanglib, xpath, domain, yspec1)) < 0)
goto done;
if (ret == 0)
if (ret == 0){
ys_prune_self(yspec1); /* remove from tree, free in done code */
goto anydata;
}
}
if (xml_yang_mount_set(h, xt, yspec1) < 0)
goto done;
@ -953,7 +947,7 @@ yang_schema_get_child(clixon_handle h,
int ret;
x1cname = xml_name(x1c);
if ((ret = xml_yang_mount_get(h, x1, NULL, &yspec1)) < 0)
if ((ret = xml_yang_mount_get(h, x1, NULL, NULL, &yspec1)) < 0)
goto done;
if (ret == 1 && yspec1 != NULL){
if (ys_module_by_xml(yspec1, x1c, &ymod1) <0)
@ -971,3 +965,31 @@ yang_schema_get_child(clixon_handle h,
retval = 0;
goto done;
}
/*! Remove xpath from yspec cvec list, remove yspec if empty
*
* @param[in] h Clixon handle
* @param[in] xmnt XML mount-point
*/
int
yang_schema_yspec_rm(clixon_handle h,
cxobj *xmnt)
{
/* Remove mountpoint from yspec cvec */
int retval = -1;
yang_stmt *yspec = NULL;
char *xpath = NULL;
int ret;
if ((ret = xml_yang_mount_get(h, xmnt, NULL, &xpath, &yspec)) < 0)
goto done;
if (ret == 1 && xpath != NULL && yspec != NULL){
if (yang_cvec_rm(yspec, xpath) < 0)
goto done;
}
retval = 0;
done:
if (xpath)
free(xpath);
return retval;
}