* Added clicon_handle as parameter to all validate functions

* Added libxml2 XSD regexp mode as alternative to posix translation
* Added `CLICON_YANG_REGEXP` option with possible values libxml2 and posix
This commit is contained in:
Olof hagsand 2019-05-23 22:48:33 +02:00
parent 69f2eb30f1
commit a804e05375
27 changed files with 501 additions and 289 deletions

View file

@ -67,7 +67,7 @@ CPPFLAGS = @CPPFLAGS@
INCLUDES = -I. @INCLUDES@ -I$(top_srcdir)/lib/clixon -I$(top_srcdir)/include -I$(top_srcdir)
SRC = clixon_sig.c clixon_log.c clixon_err.c clixon_event.c \
clixon_string.c clixon_handle.c \
clixon_string.c clixon_regex.c clixon_handle.c \
clixon_xml.c clixon_xml_sort.c clixon_xml_map.c clixon_file.c \
clixon_json.c clixon_yang.c clixon_yang_type.c clixon_yang_module.c \
clixon_yang_cardinality.c clixon_xml_changelog.c \

View file

@ -198,7 +198,7 @@ parse_configfile(clicon_handle h,
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
if ((ret = xml_yang_validate_add(xc, cbret)) < 0)
if ((ret = xml_yang_validate_add(h, xc, cbret)) < 0)
goto done;
if (ret == 0){
clicon_err(OE_CFG, 0, "Config file validation: %s", cbuf_get(cbret));

272
lib/src/clixon_regex.c Normal file
View file

@ -0,0 +1,272 @@
/*
*
***** BEGIN LICENSE BLOCK *****
Copyright (C) 2009-2019 Olof Hagsand and Benny Holmgren
This file is part of CLIXON.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Alternatively, the contents of this file may be used under the terms of
the GNU General Public License Version 3 or later (the "GPL"),
in which case the provisions of the GPL are applicable instead
of those above. If you wish to allow use of your version of this file only
under the terms of the GPL, and not to allow others to
use your version of this file under the terms of Apache License version 2,
indicate your decision by deleting the provisions above and replace them with
the notice and other provisions required by the GPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the Apache License version 2 or the GPL.
***** END LICENSE BLOCK *****
*
* Clixon regular expression code for Yang type patterns following XML Schema
* regex.
* Two modes: libxml2 and posix-translation
* @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028
*/
#ifdef HAVE_CONFIG_H
#include "clixon_config.h"
#endif
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <errno.h>
#include <regex.h>
#include <ctype.h>
#ifdef HAVE_LIBXML_XMLREGEXP_H
#include <libxml/xmlregexp.h>
#endif
#include <cligen/cligen.h>
/* clicon */
#include "clixon_queue.h"
#include "clixon_hash.h"
#include "clixon_handle.h"
#include "clixon_err.h"
#include "clixon_log.h"
#include "clixon_yang.h"
#include "clixon_options.h"
#include "clixon_regex.h"
/*-------------------------- POSIX translation -------------------------*/
/*! Transform from XSD regex to posix ERE
* The usecase is that Yang (RFC7950) supports XSD regular expressions but
* CLIgen supports POSIX ERE
* POSIX ERE regexps according to man regex(3).
* @param[in] xsd Input regex string according XSD
* @param[out] posix Output (malloced) string according to POSIX ERE
* @see https://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#regexs
* @see https://www.regular-expressions.info/posixbrackets.html#class translation
* @see https://www.regular-expressions.info/xml.html
* Translation is not complete but covers some character sequences:
* \d decimal digit
* \w all characters except the set of "punctuation", "separator" and
* "other" characters: #x0000-#x10FFFF]-[\p{P}\p{Z}\p{C}]
* \i letters + underscore and colon
* \c XML Namechar, see: https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameChar
*
* Not implemented:
* \p{X} category escape. the ones identified in openconfig and yang-models are:
* \p{L} Letters [ultmo]?
* \p{M} Marks [nce]?
* \p{N} Numbers [dlo]?
* \p{P} Punctuation [cdseifo]?
* \p{Z} Separators [slp]?
* \p{S} Symbols [mcko]?
* \p{O} Other [cfon]?
*/
int
regexp_xsd2posix(char *xsd,
char **posix)
{
int retval = -1;
cbuf *cb = NULL;
char x;
int i;
int j; /* lookahead */
int esc;
int minus = 0;
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
esc=0;
for (i=0; i<strlen(xsd); i++){
x = xsd[i];
if (esc){
esc = 0;
switch (x){
case '-': /* \- is translated to -], ie must be last in bracket */
minus++;
break;
case 'c': /* xml namechar */
cprintf(cb, "[0-9a-zA-Z._:-]"); /* also interpunct */
break;
case 'd':
cprintf(cb, "[0-9]");
break;
case 'i': /* initial */
cprintf(cb, "[a-zA-Z_:]");
break;
case 'p': /* category escape: \p{IsCategory} */
j = i+1;
if (j+2 < strlen(xsd) &&
xsd[j] == '{' &&
(xsd[j+2] == '}' || xsd[j+3] == '}')){
switch (xsd[j+1]){
case 'L': /* Letters */
cprintf(cb, "a-zA-Z"); /* assume in [] */
break;
case 'M': /* Marks */
cprintf(cb, "\?!"); /* assume in [] */
break;
case 'N': /* Numbers */
cprintf(cb, "0-9");
break;
case 'P': /* Punctuation */
cprintf(cb, "a-zA-Z"); /* assume in [] */
break;
case 'Z': /* Separators */
cprintf(cb, "\t "); /* assume in [] */
break;
case 'S': /* Symbols */
/* assume in [] */
break;
case 'C': /* Others */
/* assume in [] */
break;
default:
break;
}
if (xsd[j+2] == '}')
i = j+2;
else
i = j+3;
}
/* if syntax error, just leave it */
break;
case 's':
cprintf(cb, "[ \t\r\n]");
break;
case 'S':
cprintf(cb, "[^ \t\r\n]");
break;
case 'w': /* word */
//cprintf(cb, "[0-9a-zA-Z_\\\\-]")
cprintf(cb, "[^[:punct:][:space:][:cntrl:]]");
break;
case 'W': /* inverse of \w */
cprintf(cb, "[[:punct:][:space:][:cntrl:]]");
break;
default:
cprintf(cb, "\\%c", x);
break;
}
}
else if (x == '\\')
esc++;
else if (x == '$')
cprintf(cb, "\\%c", x);
else if (x == ']' && minus){
cprintf(cb, "-]");
minus = 0;
}
else
cprintf(cb, "%c", x);
}
if ((*posix = strdup(cbuf_get(cb))) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
goto done;
}
retval = 0;
done:
if (cb)
cbuf_free(cb);
return retval;
}
/*-------------------------- Generic API functions ------------------------*/
/*! Compilation of regular expression / pattern
* @param[in] h Clicon handle
* @param[in] regexp Regular expression string in XSD regex format
* @param[out] recomp Compiled regular expression (malloc:d, should be freed)
* @retval 1 OK
* @retval 0 Invalid regular expression (syntax error?)
* @retval -1 Error
* @note Clixon supports Yang's XSD regexp only. But CLIgen can support both
* POSIX and XSD(using libxml2). But to use CLIgen's POSIX, Clixon must
* translate from XSD to POSIX.
*/
int
regex_compile(clicon_handle h,
char *regexp,
void **recomp)
{
int retval = -1;
char *mode;
char *posix = NULL; /* Transform to posix regex */
mode = clicon_yang_regexp(h);
if (strcmp(mode, "posix") == 0){
if (regexp_xsd2posix(regexp, &posix) < 0)
goto done;
retval = cligen_regex_posix_compile(posix, recomp);
}
else if (strcmp(mode, "libxml2") == 0)
retval = cligen_regex_libxml2_compile(regexp, recomp);
else{
clicon_err(OE_CFG, 0, "clicon_yang_regexp invalid value: %s", mode);
goto done;
}
/* retval from fns above */
done:
if (posix)
free(posix);
return retval;
}
/*! Execution of (pre-compiled) regular expression / pattern
* @param[in] h Clicon handle
*/
int
regex_exec(clicon_handle h,
void *recomp,
char *string)
{
int retval = -1;
char *mode;
mode = clicon_yang_regexp(h);
if (strcmp(mode, "posix") == 0)
retval = cligen_regex_posix_exec(recomp, string);
else if (strcmp(mode, "libxml2") == 0)
retval = cligen_regex_libxml2_exec(recomp, string);
else{
clicon_err(OE_CFG, 0, "clicon_yang_regexp invalid value: %s", mode);
goto done;
}
/* retval from fns above */
done:
return retval;
}

View file

@ -30,10 +30,7 @@
the terms of any one of the Apache License version 2 or the GPL.
***** END LICENSE BLOCK *****
*/
/* Error handling: dont use clicon_err, treat as unix system calls. That is,
ensure errno is set and return -1/NULL */
#ifdef HAVE_CONFIG_H
#include "clixon_config.h"
@ -44,7 +41,6 @@
#include <stdint.h>
#include <stdlib.h>
#include <errno.h>
#include <regex.h>
#include <ctype.h>
#include <cligen/cligen.h>
@ -694,120 +690,6 @@ clixon_trim(char *str)
return s;
}
/*! Transform from XSD regex to posix ERE
* The usecase is that Yang (RFC7950) supports XSD regular expressions but
* CLIgen supports POSIX ERE
* POSIX ERE regexps according to man regex(3).
* @param[in] xsd Input regex string according XSD
* @param[out] posix Output (malloced) string according to POSIX ERE
* @see https://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#regexs
* @see https://www.regular-expressions.info/posixbrackets.html#class translation
* @see https://www.regular-expressions.info/xml.html
* Translation is not complete but covers some character sequences:
* \d decimal digit
* \w all characters except the set of "punctuation", "separator" and
* "other" characters: #x0000-#x10FFFF]-[\p{P}\p{Z}\p{C}]
* \i letters + underscore and colon
* \c XML Namechar, see: https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameChar
*
* Not implemented:
* \p{X} category escape. the ones identified in openconfig and yang-models are:
* \p{L} Letters [ultmo]?
* \p{N} Numbers [dlo]?
*/
int
regexp_xsd2posix(char *xsd,
char **posix)
{
int retval = -1;
cbuf *cb = NULL;
char x;
int i;
int j; /* lookahead */
int esc;
int minus = 0;
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
esc=0;
for (i=0; i<strlen(xsd); i++){
x = xsd[i];
if (esc){
esc = 0;
switch (x){
case '-': /* \- is translated to -], ie must be last in bracket */
minus++;
break;
case 'c': /* xml namechar */
cprintf(cb, "[0-9a-zA-Z._:-]"); /* also interpunct */
break;
case 'd':
cprintf(cb, "[0-9]");
break;
case 'i': /* initial */
cprintf(cb, "[a-zA-Z_:]");
break;
case 'p': /* category escape: \p{IsCategory} */
j = i+1;
if (j+2 < strlen(xsd) &&
xsd[j] == '{' &&
xsd[j+2] == '}'){
switch (xsd[j+1]){
case 'L': /* Letters */
cprintf(cb, "a-zA-Z"); /* assume in [] */
break;
case 'N': /* Numbers */
cprintf(cb, "0-9");
break;
default:
break;
}
i = j+2;
}
/* if syntax error, just leave it */
break;
case 's':
cprintf(cb, "[ \t\r\n]");
break;
case 'S':
cprintf(cb, "[^ \t\r\n]");
break;
case 'w': /* word */
//cprintf(cb, "[0-9a-zA-Z_\\\\-]")
cprintf(cb, "[^[:punct:][:space:][:cntrl:]]");
break;
case 'W': /* inverse of \w */
cprintf(cb, "[[:punct:][:space:][:cntrl:]]");
break;
default:
cprintf(cb, "\\%c", x);
break;
}
}
else if (x == '\\')
esc++;
else if (x == '$')
cprintf(cb, "\\%c", x);
else if (x == ']' && minus){
cprintf(cb, "-]");
minus = 0;
}
else
cprintf(cb, "%c", x);
}
if ((*posix = strdup(cbuf_get(cb))) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
goto done;
}
retval = 0;
done:
if (cb)
cbuf_free(cb);
return retval;
}
/*! strndup() for systems without it, such as xBSD
*/
#ifndef HAVE_STRNDUP

View file

@ -441,9 +441,9 @@ clixon_xml_changelog_init(clicon_handle h)
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
if ((ret = xml_yang_validate_all(xt, cbret)) < 0)
if ((ret = xml_yang_validate_all(h, xt, cbret)) < 0)
goto done;
if (ret==1 && (ret = xml_yang_validate_add(xt, cbret)) < 0)
if (ret==1 && (ret = xml_yang_validate_add(h, xt, cbret)) < 0)
goto done;
if (ret == 0){ /* validation failed */
clicon_err(OE_YANG, 0, "validation failed: %s", cbuf_get(cbret));

View file

@ -453,7 +453,8 @@ xml_yang_root(cxobj *x,
* @note Should need a variant accepting cxobj **xret
*/
int
xml_yang_validate_rpc(cxobj *xrpc,
xml_yang_validate_rpc(clicon_handle h,
cxobj *xrpc,
cbuf *cbret)
{
int retval = -1;
@ -472,9 +473,9 @@ xml_yang_validate_rpc(cxobj *xrpc,
goto done;
goto fail;
}
if ((retval = xml_yang_validate_all(xn, cbret)) < 1)
if ((retval = xml_yang_validate_all(h, xn, cbret)) < 1)
goto done; /* error or validation fail */
if ((retval = xml_yang_validate_add(xn, cbret)) < 1)
if ((retval = xml_yang_validate_add(h, xn, cbret)) < 1)
goto done; /* error or validation fail */
if (xml_apply0(xn, CX_ELMNT, xml_default, NULL) < 0)
goto done;
@ -1020,7 +1021,7 @@ check_list_unique_minmax(cxobj *xt,
* @code
* cxobj *x;
* cbuf *cbret = cbuf_new();
* if ((ret = xml_yang_validate_add(x, cbret)) < 0)
* if ((ret = xml_yang_validate_add(h, x, cbret)) < 0)
* err;
* if (ret == 0)
* fail;
@ -1030,7 +1031,8 @@ check_list_unique_minmax(cxobj *xt,
* @note Should need a variant accepting cxobj **xret
*/
int
xml_yang_validate_add(cxobj *xt,
xml_yang_validate_add(clicon_handle h,
cxobj *xt,
cbuf *cbret)
{
int retval = -1;
@ -1084,7 +1086,7 @@ xml_yang_validate_add(cxobj *xt,
}
}
if ((ys_cv_validate(cv, yt, &reason)) != 1){
if ((ys_cv_validate(h, cv, yt, &reason)) != 1){
if (netconf_bad_element(cbret, "application", yt->ys_argument, reason) < 0)
goto done;
goto fail;
@ -1096,7 +1098,7 @@ xml_yang_validate_add(cxobj *xt,
}
x = NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
if ((ret = xml_yang_validate_add(x, cbret)) < 0)
if ((ret = xml_yang_validate_add(h, x, cbret)) < 0)
goto done;
if (ret == 0)
goto fail;
@ -1116,7 +1118,8 @@ xml_yang_validate_add(cxobj *xt,
/*! Some checks done only at edit_config, eg keys in lists
*/
int
xml_yang_validate_list_key_only(cxobj *xt,
xml_yang_validate_list_key_only(clicon_handle h,
cxobj *xt,
cbuf *cbret)
{
int retval = -1;
@ -1134,7 +1137,7 @@ xml_yang_validate_list_key_only(cxobj *xt,
}
x = NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
if ((ret = xml_yang_validate_list_key_only(x, cbret)) < 0)
if ((ret = xml_yang_validate_list_key_only(h, x, cbret)) < 0)
goto done;
if (ret == 0)
goto fail;
@ -1168,7 +1171,8 @@ xml_yang_validate_list_key_only(cxobj *xt,
* @note Should need a variant accepting cxobj **xret
*/
int
xml_yang_validate_all(cxobj *xt,
xml_yang_validate_all(clicon_handle h,
cxobj *xt,
cbuf *cbret)
{
int retval = -1;
@ -1247,7 +1251,7 @@ xml_yang_validate_all(cxobj *xt,
}
x = NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
if ((ret = xml_yang_validate_all(x, cbret)) < 0)
if ((ret = xml_yang_validate_all(h, x, cbret)) < 0)
goto done;
if (ret == 0)
goto fail;
@ -1275,7 +1279,8 @@ xml_yang_validate_all(cxobj *xt,
* @retval -1 Error
*/
int
xml_yang_validate_all_top(cxobj *xt,
xml_yang_validate_all_top(clicon_handle h,
cxobj *xt,
cbuf *cbret)
{
int ret;
@ -1283,7 +1288,7 @@ xml_yang_validate_all_top(cxobj *xt,
x = NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
if ((ret = xml_yang_validate_all(x, cbret)) < 1)
if ((ret = xml_yang_validate_all(h, x, cbret)) < 1)
return ret;
}
if ((ret = check_list_unique_minmax(xt, cbret)) < 1)

View file

@ -62,6 +62,7 @@
#include "clixon_queue.h"
#include "clixon_hash.h"
#include "clixon_handle.h"
#include "clixon_regex.h"
#include "clixon_yang.h"
#include "clixon_hash.h"
#include "clixon_xml.h"
@ -128,74 +129,6 @@ static const map_str2int ytmap2[] = {
{NULL, -1}
};
/*! Regular expression compiling
* @retval -1 Error
* @retval 0 regex problem (no match?)
* @retval 1 OK Match
* @see match_regexp the CLIgen original composite function
*/
static int
regex_compile(char *pattern0,
regex_t *re)
{
int retval = -1;
char pattern[1024];
// char errbuf[1024];
int len0;
int status;
len0 = strlen(pattern0);
if (len0 > sizeof(pattern)-5){
clicon_err(OE_XML, EINVAL, "pattern too long");
goto done;
}
strncpy(pattern, "^(", 2);
strncpy(pattern+2, pattern0, sizeof(pattern)-2);
strncat(pattern, ")$", sizeof(pattern)-len0-1);
if ((status = regcomp(re, pattern, REG_NOSUB|REG_EXTENDED)) != 0) {
#if 0 /* ignore error msg for now */
regerror(status, re, errbuf, sizeof(errbuf));
#endif
goto fail;
}
retval = 1;
done:
return retval;
fail:
retval = 0;
goto done;
}
/*! Regular expression execution
* @retval -1 Error
* @retval 0 regex problem (no match?)
* @retval 1 OK Match
* @see match_regexp the CLIgen original composite function
*/
static int
regex_exec(regex_t *re,
char *string)
{
int retval = -1;
int status;
// char errbuf[1024];
status = regexec(re, string, (size_t) 0, NULL, 0);
if (status != 0) {
#if 0 /* ignore error msg for now */
regerror(status, re, errbuf, sizeof(errbuf));
#endif
goto fail;
}
retval = 1;
done:
return retval;
fail:
retval = 0;
goto done;
}
/* return 1 if built-in, 0 if not */
static int
yang_builtin(char *type)
@ -447,7 +380,8 @@ clicon_type2cv(char *origtype,
* @retval 1 Validation OK
*/
static int
cv_validate1(cg_var *cv,
cv_validate1(clicon_handle h,
cg_var *cv,
enum cv_type cvtype,
int options,
cvec *cvv,
@ -459,7 +393,7 @@ cv_validate1(cg_var *cv,
int retval = 1; /* OK */
cg_var *cv1;
cg_var *cv2;
int retval2;
int ret;
yang_stmt *yi = NULL;
char *str = NULL;
int found;
@ -620,51 +554,30 @@ cv_validate1(cg_var *cv,
}
}
}
if ((options & YANG_OPTIONS_PATTERN) != 0){
char *posix = NULL;
regex_t *re = NULL;
if ((re = yang_regex_cache_get(yrestype)) == NULL){
/* Transform to posix regex */
if (regexp_xsd2posix(pattern, &posix) < 0)
goto done;
/* Create regex cache */
if ((re = malloc(sizeof(*re))) == NULL){
clicon_err(OE_UNIX, errno, "malloc");
goto done;
if ((options & YANG_OPTIONS_PATTERN) != 0) {
void *re = NULL;
if ((re = yang_regex_cache_get(yrestype)) == NULL){
if ((ret = regex_compile(h, pattern, &re)) < 0)
goto done;
if (ret == 0){
if (reason)
*reason = cligen_reason("regexp compile fail: \"%s\"",
pattern);
goto fail;
break;
}
yang_regex_cache_set(yrestype, re);
}
memset(re, 0, sizeof(*re));
/* Compute regex pattern for use in patterns */
if ((retval2 = regex_compile(posix, re)) < 0)
if ((ret = regex_exec(h, re, str?str:"")) < 0)
goto done;
if (retval2 == 0){
if (reason)
*reason = cligen_reason("regexp match fail: \"%s\" does not match %s",
str, pattern);
goto fail;
break;
}
yang_regex_cache_set(yrestype, re);
if (posix)
free(posix);
}
if ((retval2 = regex_exec(re, str?str:"")) < 0)
goto done;
if (retval2 == 0){
if (ret == 0){
if (reason)
*reason = cligen_reason("regexp match fail: \"%s\" does not match %s",
str, pattern);
goto fail;
break;
}
if (retval2 == 0){
if (reason)
*reason = cligen_reason("regexp match fail: \"%s\" does not match %s",
str, pattern);
goto fail;
break;
}
}
break;
case CGV_VOID:
break; /* empty type OK */
@ -688,8 +601,8 @@ cv_validate1(cg_var *cv,
}
/* Forward */
static int ys_cv_validate_union(yang_stmt *ys, char **reason, yang_stmt *yrestype,
char *type, char *val);
static int ys_cv_validate_union(clicon_handle h,yang_stmt *ys, char **reason,
yang_stmt *yrestype, char *type, char *val);
/*!
* @retval -1 Error (fatal), with errno set to indicate error
@ -697,7 +610,8 @@ static int ys_cv_validate_union(yang_stmt *ys, char **reason, yang_stmt *yrestyp
* @retval 1 Validation OK
*/
static int
ys_cv_validate_union_one(yang_stmt *ys,
ys_cv_validate_union_one(clicon_handle h,
yang_stmt *ys,
char **reason,
yang_stmt *yt,
char *type, /* orig type */
@ -718,7 +632,7 @@ ys_cv_validate_union_one(yang_stmt *ys,
goto done;
restype = yrt?yrt->ys_argument:NULL;
if (restype && strcmp(restype, "union") == 0){ /* recursive union */
if ((retval = ys_cv_validate_union(ys, reason, yrt, type, val)) < 0)
if ((retval = ys_cv_validate_union(h, ys, reason, yrt, type, val)) < 0)
goto done;
}
else {
@ -735,7 +649,7 @@ ys_cv_validate_union_one(yang_stmt *ys,
}
if (retval == 0)
goto done;
if ((retval = cv_validate1(cvt, cvtype, options, cvv,
if ((retval = cv_validate1(h, cvt, cvtype, options, cvv,
pattern, yrt, restype, reason)) < 0)
goto done;
}
@ -751,7 +665,8 @@ ys_cv_validate_union_one(yang_stmt *ys,
* @retval 1 Validation OK
*/
static int
ys_cv_validate_union(yang_stmt *ys,
ys_cv_validate_union(clicon_handle h,
yang_stmt *ys,
char **reason,
yang_stmt *yrestype,
char *type, /* orig type */
@ -764,7 +679,7 @@ ys_cv_validate_union(yang_stmt *ys,
while ((yt = yn_each(yrestype, yt)) != NULL){
if (yt->ys_keyword != Y_TYPE)
continue;
if ((retval = ys_cv_validate_union_one(ys, reason, yt, type, val)) < 0)
if ((retval = ys_cv_validate_union_one(h, ys, reason, yt, type, val)) < 0)
goto done;
/* If validation failed, save reason, reset error and continue,
* save latest reason if noithing validates.
@ -800,7 +715,8 @@ ys_cv_validate_union(yang_stmt *ys,
* See also cv_validate - the code is similar.
*/
int
ys_cv_validate(cg_var *cv,
ys_cv_validate(clicon_handle h,
cg_var *cv,
yang_stmt *ys,
char **reason)
{
@ -846,12 +762,12 @@ ys_cv_validate(cg_var *cv,
if (restype && strcmp(restype, "union") == 0){
assert(cvtype == CGV_REST);
val = cv_string_get(cv);
if ((retval2 = ys_cv_validate_union(ys, reason, yrestype, type, val)) < 0)
if ((retval2 = ys_cv_validate_union(h, ys, reason, yrestype, type, val)) < 0)
goto done;
retval = retval2; /* invalid (0) with latest reason or valid 1 */
}
else
if ((retval = cv_validate1(cv, cvtype, options, cvv, pattern,
if ((retval = cv_validate1(h, cv, cvtype, options, cvv, pattern,
yrestype, restype, reason)) < 0)
goto done;
done: