* Yang parser is stricter (see cardinality below) which may break parsing of slack yang specs.

* YANG parser cardinality checked (only modules level yet)
  * See https://github.com/clicon/clixon/issues/48
This commit is contained in:
Olof hagsand 2018-11-18 20:55:57 +01:00
parent 9c57902b96
commit a8f0aad411
28 changed files with 159 additions and 47 deletions

View file

@ -76,12 +76,17 @@
#include "clixon_options.h"
#include "clixon_yang_type.h"
#include "clixon_yang_parse.h"
#include "clixon_yang_cardinality.h"
/* Size of json read buffer when reading from file*/
#define BUFLEN 1024
/*
* Local variables
*/
/* Mapping between yang keyword string <--> clicon constants */
static const map_str2int ykmap[] = {
{"anydata", Y_ANYDATA},
{"anyxml", Y_ANYXML},
{"argument", Y_ARGUMENT},
{"augment", Y_AUGMENT},
@ -393,9 +398,11 @@ yn_each(yang_node *yn,
* @param[in] yn Yang node, current context node.
* @param[in] keyword if 0 match any keyword
* @param[in] argument String compare w argument. if NULL, match any.
* @retval ys Yang statement, if any
* This however means that if you actually want to match only a yang-stmt with
* argument==NULL you cannot, but I have not seen any such examples.
* @see yang_find_datanode
* @see yang_match returns number of matches
*/
yang_stmt *
yang_find(yang_node *yn,
@ -420,6 +427,38 @@ yang_find(yang_node *yn,
}
return match ? ys : NULL;
}
/*! Count number of children that matches keyword and argument
*
* @param[in] yn Yang node, current context node.
* @param[in] keyword if 0 match any keyword
* @param[in] argument String compare w argument. if NULL, match any.
* @retval n Number of matches
* This however means that if you actually want to match only a yang-stmt with
* argument==NULL you cannot, but I have not seen any such examples.
* @see yang_find
*/
int
yang_match(yang_node *yn,
int keyword,
char *argument)
{
yang_stmt *ys = NULL;
int i;
int match = 0;
for (i=0; i<yn->yn_len; i++){
ys = yn->yn_stmt[i];
if (keyword == 0 || ys->ys_keyword == keyword){
if (argument == NULL)
match++;
else
if (ys->ys_argument && strcmp(argument, ys->ys_argument) == 0)
match++;
}
}
return match;
}
#ifdef NOTYET
/*! Prototype more generic than yang_find_datanode and yang_find_schemanode
*/
@ -2140,6 +2179,11 @@ yang_parse(clicon_handle h,
if (yang_parse_recurse(ymod, dir, ysp) < 0)
goto done;
/* Check cardinality maybe this should be done after grouping/augment */
for (i=modnr; i<ysp->yp_len; i++) /* XXX */
if (yang_cardinality(h, ysp->yp_stmt[i], ysp->yp_stmt[i]->ys_argument) < 0)
goto done;
/* Step 2: check features: check if enabled and remove disabled features */
for (i=modnr; i<ysp->yp_len; i++) /* XXX */
if (yang_features(h, ysp->yp_stmt[i]) < 0)