Add validation of yang bits value
This commit is contained in:
parent
dacd2fe3a0
commit
a576951e57
2 changed files with 61 additions and 16 deletions
|
|
@ -54,7 +54,6 @@
|
||||||
#include "clixon_string.h"
|
#include "clixon_string.h"
|
||||||
#include "clixon_err.h"
|
#include "clixon_err.h"
|
||||||
|
|
||||||
|
|
||||||
/*! Split string into a vector based on character delimiters. Using malloc
|
/*! Split string into a vector based on character delimiters. Using malloc
|
||||||
*
|
*
|
||||||
* The given string is split into a vector where the delimiter can be
|
* The given string is split into a vector where the delimiter can be
|
||||||
|
|
@ -63,6 +62,17 @@
|
||||||
* The vector returned is one single memory block that must be freed
|
* The vector returned is one single memory block that must be freed
|
||||||
* by the caller
|
* by the caller
|
||||||
*
|
*
|
||||||
|
* @code
|
||||||
|
* char **vec = NULL;
|
||||||
|
* int nvec;
|
||||||
|
* if ((vec = clicon_strsep("/home/user/src/clixon", "/", &nvec)) == NULL)
|
||||||
|
* err;
|
||||||
|
* for (i=0; i<nvec; i++){
|
||||||
|
* v = vec[i++];
|
||||||
|
* ...
|
||||||
|
* }
|
||||||
|
* free(vec);
|
||||||
|
* @endcode
|
||||||
* @param[in] string String to be split
|
* @param[in] string String to be split
|
||||||
* @param[in] delim String of delimiter characters
|
* @param[in] delim String of delimiter characters
|
||||||
* @param[out] nvec Number of entries in returned vector
|
* @param[out] nvec Number of entries in returned vector
|
||||||
|
|
|
||||||
|
|
@ -402,6 +402,10 @@ cv_validate1(cg_var *cv,
|
||||||
uint64_t u = 0;
|
uint64_t u = 0;
|
||||||
int64_t i = 0;
|
int64_t i = 0;
|
||||||
char *str;
|
char *str;
|
||||||
|
int found;
|
||||||
|
char **vec = NULL;
|
||||||
|
int nvec;
|
||||||
|
char *v;
|
||||||
|
|
||||||
if (reason && *reason){
|
if (reason && *reason){
|
||||||
free(*reason);
|
free(*reason);
|
||||||
|
|
@ -510,11 +514,11 @@ cv_validate1(cg_var *cv,
|
||||||
case CGV_STRING:
|
case CGV_STRING:
|
||||||
case CGV_REST:
|
case CGV_REST:
|
||||||
str = cv_string_get(cv);
|
str = cv_string_get(cv);
|
||||||
if (restype &&
|
if (restype){
|
||||||
(strcmp(restype, "enumeration") == 0 || strcmp(restype, "bits") == 0)){
|
if (strcmp(restype, "enumeration") == 0){
|
||||||
int found = 0;
|
found = 0;
|
||||||
while ((yi = yn_each((yang_node*)yrestype, yi)) != NULL){
|
while ((yi = yn_each((yang_node*)yrestype, yi)) != NULL){
|
||||||
if (yi->ys_keyword != Y_ENUM && yi->ys_keyword != Y_BIT)
|
if (yi->ys_keyword != Y_ENUM)
|
||||||
continue;
|
continue;
|
||||||
if (strcmp(yi->ys_argument, str) == 0){
|
if (strcmp(yi->ys_argument, str) == 0){
|
||||||
found++;
|
found++;
|
||||||
|
|
@ -528,6 +532,35 @@ cv_validate1(cg_var *cv,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (strcmp(restype, "bits") == 0){
|
||||||
|
/* The lexical representation of the bits type is a space-separated list
|
||||||
|
* of the names of the bits that are set. A zero-length string thus
|
||||||
|
* represents a value where no bits are set.
|
||||||
|
*/
|
||||||
|
if ((vec = clicon_strsep(str, " \t", &nvec)) == NULL)
|
||||||
|
goto done;
|
||||||
|
for (i=0; i<nvec; i++){
|
||||||
|
clicon_log(LOG_NOTICE, "%s: vec[i]: %s", __FUNCTION__, vec[i]);
|
||||||
|
if ((v = vec[i]) == NULL || !strlen(v))
|
||||||
|
continue;
|
||||||
|
found = 0;
|
||||||
|
while ((yi = yn_each((yang_node*)yrestype, yi)) != NULL){
|
||||||
|
if (yi->ys_keyword != Y_BIT)
|
||||||
|
continue;
|
||||||
|
if (strcmp(yi->ys_argument, v) == 0){
|
||||||
|
found++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found){
|
||||||
|
if (reason)
|
||||||
|
*reason = cligen_reason("'%s' does not match enumeration", v);
|
||||||
|
retval = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if ((options & YANG_OPTIONS_LENGTH) != 0){
|
if ((options & YANG_OPTIONS_LENGTH) != 0){
|
||||||
u = strlen(str);
|
u = strlen(str);
|
||||||
if (range_check(u, range_min, range_max, uint64)){
|
if (range_check(u, range_min, range_max, uint64)){
|
||||||
|
|
@ -571,9 +604,11 @@ cv_validate1(cg_var *cv,
|
||||||
case CGV_EMPTY: /* XXX */
|
case CGV_EMPTY: /* XXX */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reason && *reason)
|
if (reason && *reason)
|
||||||
assert(retval == 0); /* validation failed with error reason */
|
assert(retval == 0); /* validation failed with error reason */
|
||||||
|
done:
|
||||||
|
if (vec)
|
||||||
|
free(vec);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue