Fixed: [yang_enum_int_value() fails if no explicit values are assigned to enums](https://github.com/clicon/clixon/issues/483)
This commit is contained in:
parent
60ded12ea7
commit
a97a06d15a
4 changed files with 62 additions and 8 deletions
|
|
@ -73,6 +73,8 @@ Developers may need to change their code
|
||||||
|
|
||||||
### Corrected Bugs
|
### Corrected Bugs
|
||||||
|
|
||||||
|
* Fixed: [yang_enum_int_value() fails if no explicit values are assigned to enums](https://github.com/clicon/clixon/issues/483)
|
||||||
|
Remaining work: `yang_enum2valstr()`
|
||||||
* Fixed: [show compare/diff problems with sorted-by user](https://github.com/clicon/clixon/issues/482)
|
* Fixed: [show compare/diff problems with sorted-by user](https://github.com/clicon/clixon/issues/482)
|
||||||
* Fixed: [Choice and Leafref](https://github.com/clicon/clixon/issues/469)
|
* Fixed: [Choice and Leafref](https://github.com/clicon/clixon/issues/469)
|
||||||
* Fixed: [Problem deleting non-last list element if ordered-by user](https://github.com/clicon/clixon/issues/475)
|
* Fixed: [Problem deleting non-last list element if ordered-by user](https://github.com/clicon/clixon/issues/475)
|
||||||
|
|
|
||||||
|
|
@ -1519,6 +1519,9 @@ yang_valstr2enum(yang_stmt *ytype,
|
||||||
* @retval 1 OK, result in valstr
|
* @retval 1 OK, result in valstr
|
||||||
* @retval 0 Invalid, not found
|
* @retval 0 Invalid, not found
|
||||||
* @retval -1 Error
|
* @retval -1 Error
|
||||||
|
* @note does not handle implicit values
|
||||||
|
* @see yang_enum2int handles implicit values
|
||||||
|
* @note does not handle implicit values, see yang_enum_int_value which does
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
yang_enum2valstr(yang_stmt *ytype,
|
yang_enum2valstr(yang_stmt *ytype,
|
||||||
|
|
@ -1570,8 +1573,8 @@ yang_enum_int_value(cxobj *node,
|
||||||
yang_stmt *ys;
|
yang_stmt *ys;
|
||||||
yang_stmt *ytype;
|
yang_stmt *ytype;
|
||||||
yang_stmt *yrestype; /* resolved type */
|
yang_stmt *yrestype; /* resolved type */
|
||||||
char *reason = NULL;
|
yang_stmt *yenum;
|
||||||
char *intstr = NULL;
|
cg_var *cv;
|
||||||
|
|
||||||
if (node == NULL)
|
if (node == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -1588,13 +1591,17 @@ yang_enum_int_value(cxobj *node,
|
||||||
clixon_err(OE_YANG, 0, "result-type should not be NULL");
|
clixon_err(OE_YANG, 0, "result-type should not be NULL");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (yrestype==NULL || strcmp(yang_argument_get(yrestype), "enumeration"))
|
if (strcmp(yang_argument_get(yrestype), "enumeration"))
|
||||||
goto done;
|
goto done;
|
||||||
if (yang_enum2valstr(yrestype, xml_body(node), &intstr) < 0)
|
if ((yenum = yang_find(yrestype, Y_ENUM, xml_body(node))) == NULL){
|
||||||
|
clixon_err(OE_YANG, 0, "No such enum: %s", xml_body(node));
|
||||||
goto done;
|
goto done;
|
||||||
/* reason is string containing why int could not be parsed */
|
}
|
||||||
if (parse_int32(intstr, val, &reason) < 0)
|
if ((cv = yang_cv_get(yenum)) == NULL){
|
||||||
|
clixon_err(OE_YANG, 0, "Enum lacks cv");
|
||||||
goto done;
|
goto done;
|
||||||
|
}
|
||||||
|
*val = cv_int32_get(cv);
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
return retval;
|
return retval;
|
||||||
|
|
|
||||||
|
|
@ -2563,6 +2563,47 @@ ys_populate_length(clixon_handle h,
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Assign enum values
|
||||||
|
*
|
||||||
|
* @param[in] h Clixon handle
|
||||||
|
* @param[in] ys The yang statement (type) to populate.
|
||||||
|
* @retval 0 OK
|
||||||
|
* @retval -1 Error
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
ys_populate_type_enum(clixon_handle h,
|
||||||
|
yang_stmt *ys)
|
||||||
|
{
|
||||||
|
int retval = -1;
|
||||||
|
|
||||||
|
yang_stmt *yenum = NULL;
|
||||||
|
yang_stmt *yval;
|
||||||
|
char *valstr;
|
||||||
|
int v;
|
||||||
|
int i = 0;
|
||||||
|
cg_var *cv = NULL;
|
||||||
|
|
||||||
|
yenum = NULL;
|
||||||
|
while ((yenum = yn_each(ys, yenum)) != NULL) {
|
||||||
|
if ((cv = cv_new(CGV_INT32)) == NULL){
|
||||||
|
clixon_err(OE_YANG, errno, "cv_new");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
if ((yval = yang_find(yenum, Y_VALUE, NULL)) != NULL){
|
||||||
|
valstr = yang_argument_get(yval);
|
||||||
|
if (parse_int32(valstr, &v, NULL) < 0)
|
||||||
|
goto done;
|
||||||
|
if (v > i)
|
||||||
|
i = v;
|
||||||
|
}
|
||||||
|
cv_int32_set(cv, i++);
|
||||||
|
yang_cv_set(yenum, cv);
|
||||||
|
}
|
||||||
|
retval = 0;
|
||||||
|
done:
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
/*! Sanity check yang type statement
|
/*! Sanity check yang type statement
|
||||||
*
|
*
|
||||||
* XXX: Replace with generic parent/child type-check
|
* XXX: Replace with generic parent/child type-check
|
||||||
|
|
@ -2585,8 +2626,7 @@ ys_populate_type(clixon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (strcmp(ys->ys_argument, "identityref") == 0){
|
||||||
if (strcmp(ys->ys_argument, "identityref") == 0){
|
|
||||||
if ((ybase = yang_find(ys, Y_BASE, NULL)) == NULL){
|
if ((ybase = yang_find(ys, Y_BASE, NULL)) == NULL){
|
||||||
clixon_err(OE_YANG, 0, "identityref type requires base sub-statement");
|
clixon_err(OE_YANG, 0, "identityref type requires base sub-statement");
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -2597,6 +2637,10 @@ ys_populate_type(clixon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (strcmp(ys->ys_argument, "enumeration") == 0){
|
||||||
|
if (ys_populate_type_enum(h, ys) < 0)
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
return retval;
|
return retval;
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,7 @@ struct yang_stmt{
|
||||||
revision (uint32)
|
revision (uint32)
|
||||||
unknown-stmt (optional argument)
|
unknown-stmt (optional argument)
|
||||||
spec: mount-point xpath
|
spec: mount-point xpath
|
||||||
|
enum: value
|
||||||
*/
|
*/
|
||||||
cvec *ys_cvec; /* List of stmt-specific variables
|
cvec *ys_cvec; /* List of stmt-specific variables
|
||||||
Y_RANGE: range_min, range_max
|
Y_RANGE: range_min, range_max
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue