diff --git a/lib/src/clixon_string.c b/lib/src/clixon_string.c index d9892e90..1f0db0cc 100644 --- a/lib/src/clixon_string.c +++ b/lib/src/clixon_string.c @@ -54,7 +54,6 @@ #include "clixon_string.h" #include "clixon_err.h" - /*! Split string into a vector based on character delimiters. Using malloc * * 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 * by the caller * + * @code + * char **vec = NULL; + * int nvec; + * if ((vec = clicon_strsep("/home/user/src/clixon", "/", &nvec)) == NULL) + * err; + * for (i=0; iys_keyword != Y_ENUM && yi->ys_keyword != Y_BIT) - continue; - if (strcmp(yi->ys_argument, str) == 0){ - found++; + if (restype){ + if (strcmp(restype, "enumeration") == 0){ + found = 0; + while ((yi = yn_each((yang_node*)yrestype, yi)) != NULL){ + if (yi->ys_keyword != Y_ENUM) + continue; + if (strcmp(yi->ys_argument, str) == 0){ + found++; + break; + } + } + if (!found){ + if (reason) + *reason = cligen_reason("'%s' does not match enumeration", str); + retval = 0; break; } } - if (!found){ - if (reason) - *reason = cligen_reason("'%s' does not match enumeration", str); - retval = 0; - 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; iys_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){ @@ -571,9 +604,11 @@ cv_validate1(cg_var *cv, case CGV_EMPTY: /* XXX */ break; } - if (reason && *reason) assert(retval == 0); /* validation failed with error reason */ + done: + if (vec) + free(vec); return retval; } @@ -728,7 +763,7 @@ ys_cv_validate(cg_var *cv, } else if ((retval = cv_validate1(cv, cvtype, options, range_min, range_max, pattern, - yrestype, restype, reason)) < 0) + yrestype, restype, reason)) < 0) goto done; done: if (cvt)