* Added yang access functions
* Change all y->ys_parent to yang_parent_get(y)
* Change all y->ys_keyword to yang_keyword_get(y)
* Change all y->ys_argument to yang_argument_get(y)
* Change all y->ys_cv to yang_cv_get(y)
* Change all y->ys_cvec to yang_cvec_get(y)
This commit is contained in:
parent
0a951899c8
commit
cef0dc5a22
11 changed files with 269 additions and 124 deletions
|
|
@ -625,6 +625,7 @@ xml_child_i_set(cxobj *xt,
|
|||
* ...
|
||||
* }
|
||||
* @endcode
|
||||
* @note makes uses _x_vector_i:can be changed if list changed between calls
|
||||
*/
|
||||
cxobj *
|
||||
xml_child_each(cxobj *xparent,
|
||||
|
|
@ -791,7 +792,7 @@ xml_cv_set(cxobj *x,
|
|||
*
|
||||
* @retval xmlobj if found.
|
||||
* @retval NULL if no such node found.
|
||||
* @see xml_find_type which is a more generic function
|
||||
* @see xml_find_type A more generic function
|
||||
*/
|
||||
cxobj *
|
||||
xml_find(cxobj *x_up,
|
||||
|
|
|
|||
|
|
@ -87,9 +87,9 @@
|
|||
#include "clixon_plugin.h"
|
||||
#include "clixon_data.h"
|
||||
#include "clixon_options.h"
|
||||
#include "clixon_yang_type.h"
|
||||
#include "clixon_yang_parse.h"
|
||||
#include "clixon_yang_cardinality.h"
|
||||
#include "clixon_yang_type.h"
|
||||
|
||||
/* Size of json read buffer when reading from file*/
|
||||
#define BUFLEN 1024
|
||||
|
|
@ -174,6 +174,56 @@ static const map_str2int ykmap[] = {
|
|||
{NULL, -1}
|
||||
};
|
||||
|
||||
/* Access functions
|
||||
*/
|
||||
|
||||
/*! Get yang statement parent
|
||||
* @param[in] ys Yang statement node
|
||||
*/
|
||||
yang_stmt *
|
||||
yang_parent_get(yang_stmt *ys)
|
||||
{
|
||||
return ys->ys_parent;
|
||||
}
|
||||
|
||||
/*! Get yang statement keyword
|
||||
* @param[in] ys Yang statement node
|
||||
*/
|
||||
enum rfc_6020
|
||||
yang_keyword_get(yang_stmt *ys)
|
||||
{
|
||||
return ys->ys_keyword;
|
||||
}
|
||||
|
||||
/*! Get yang statement context-dependent argument
|
||||
* @param[in] ys Yang statement node
|
||||
*/
|
||||
char*
|
||||
yang_argument_get(yang_stmt *ys)
|
||||
{
|
||||
return ys->ys_argument;
|
||||
}
|
||||
|
||||
/*! Get yang statement CLIgen variable
|
||||
* @param[in] ys Yang statement node
|
||||
*/
|
||||
cg_var*
|
||||
yang_cv_get(yang_stmt *ys)
|
||||
{
|
||||
return ys->ys_cv;
|
||||
}
|
||||
|
||||
/*! Get yang statement CLIgen variable vector
|
||||
* @param[in] ys Yang statement node
|
||||
*/
|
||||
cvec*
|
||||
yang_cvec_get(yang_stmt *ys)
|
||||
{
|
||||
return ys->ys_cvec;
|
||||
}
|
||||
|
||||
/* End access functions */
|
||||
|
||||
/*! Create new yang specification
|
||||
* @retval yspec Free with yspec_free()
|
||||
* @retval NULL Error
|
||||
|
|
@ -392,29 +442,38 @@ yn_insert(yang_stmt *ys_parent,
|
|||
|
||||
/*! Iterate through all yang statements from a yang node
|
||||
*
|
||||
* Note that this is not optimized, one could use 'i' as index?
|
||||
* @param[in] yparent yang statement whose children should be iterated
|
||||
* @param[in] yprev previous child, or NULL on init
|
||||
* @code
|
||||
* yang_stmt *ys = NULL;
|
||||
* while ((ys = yn_each(yn, ys)) != NULL) {
|
||||
* ...ys...
|
||||
* yang_stmt *yprev = NULL;
|
||||
* while ((yprev = yn_each(yparent, yprev)) != NULL) {
|
||||
* ...yprev...
|
||||
* }
|
||||
* @endcode
|
||||
* @note makes uses _ys_vector_i:can be changed if list changed between calls
|
||||
*/
|
||||
yang_stmt *
|
||||
yn_each(yang_stmt *yn,
|
||||
yang_stmt *ys)
|
||||
yn_each(yang_stmt *yparent,
|
||||
yang_stmt *yprev)
|
||||
{
|
||||
int i;
|
||||
yang_stmt *yc = NULL;
|
||||
int i;
|
||||
|
||||
for (i=0; i<yn->ys_len; i++){
|
||||
yc = yn->ys_stmt[i];
|
||||
if (ys==NULL)
|
||||
return yc;
|
||||
if (ys==yc)
|
||||
ys = NULL;
|
||||
if (yparent == NULL)
|
||||
return NULL;
|
||||
for (i=yprev?yprev->_ys_vector_i+1:0; i<yparent->ys_len; i++){
|
||||
if ((yc = yparent->ys_stmt[i]) == NULL){
|
||||
assert(yc); /* XXX Check if happens */
|
||||
continue;
|
||||
}
|
||||
/* make room for other conditionals */
|
||||
break; /* this is next object after previous */
|
||||
}
|
||||
return NULL;
|
||||
if (i < yparent->ys_len) /* found */
|
||||
yc->_ys_vector_i = i;
|
||||
else
|
||||
yc = NULL;
|
||||
return yc;
|
||||
}
|
||||
|
||||
/*! Find first child yang_stmt with matching keyword and argument
|
||||
|
|
|
|||
91
lib/src/clixon_yang_internal.h
Normal file
91
lib/src/clixon_yang_internal.h
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
*
|
||||
***** 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 *****
|
||||
|
||||
* Yang functions
|
||||
* @see https://tools.ietf.org/html/rfc6020 YANG 1.0
|
||||
* @see https://tools.ietf.org/html/rfc7950 YANG 1.1
|
||||
*/
|
||||
|
||||
#ifndef _CLIXON_YANG_INTERNAL_H_
|
||||
#define _CLIXON_YANG_INTERNAL_H_
|
||||
|
||||
/*! Yang type cache. Yang type statements can cache all typedef info here
|
||||
* @note unions not cached
|
||||
*/
|
||||
struct yang_type_cache{
|
||||
int yc_options; /* See YANG_OPTIONS_* that determines pattern/
|
||||
fraction fields. */
|
||||
cvec *yc_cvv; /* Range and length restriction. (if YANG_OPTION_
|
||||
LENGTH|RANGE. Can be a vector if multiple
|
||||
ranges*/
|
||||
char *yc_pattern; /* regex (posix) (if YANG_OPTIONS_PATTERN) */
|
||||
uint8_t yc_fraction; /* Fraction digits for decimal64 (if
|
||||
YANG_OPTIONS_FRACTION_DIGITS */
|
||||
yang_stmt *yc_resolved; /* Resolved type object, can be NULL - note direct ptr */
|
||||
};
|
||||
typedef struct yang_type_cache yang_type_cache;
|
||||
|
||||
/*! yang statement
|
||||
*/
|
||||
struct yang_stmt{
|
||||
int ys_len; /* Number of children */
|
||||
struct yang_stmt **ys_stmt; /* Vector of children statement pointers */
|
||||
struct yang_stmt *ys_parent; /* Backpointer to parent: yang-stmt or yang-spec */
|
||||
enum rfc_6020 ys_keyword; /* See clicon_yang_parse.tab.h */
|
||||
|
||||
char *ys_argument; /* String / argument depending on keyword */
|
||||
int ys_flags; /* Flags according to YANG_FLAG_* above */
|
||||
yang_stmt *ys_module; /* Shortcut to "my" module. Augmented
|
||||
nodes can belong to other
|
||||
modules than the ancestor module */
|
||||
|
||||
char *ys_extra; /* For unknown */
|
||||
cg_var *ys_cv; /* cligen variable. See ys_populate()
|
||||
Following stmts have cv:s:
|
||||
leaf: for default value
|
||||
leaf-list,
|
||||
config: boolean true or false
|
||||
mandatory: boolean true or false
|
||||
fraction-digits for fraction-digits
|
||||
unknown-stmt (argument)
|
||||
*/
|
||||
cvec *ys_cvec; /* List of stmt-specific variables
|
||||
Y_RANGE: range_min, range_max
|
||||
Y_LIST: vector of keys
|
||||
Y_TYPE & identity: store all derived types
|
||||
*/
|
||||
yang_type_cache *ys_typecache; /* If ys_keyword==Y_TYPE, cache all typedef data except unions */
|
||||
int _ys_vector_i; /* internal use: yn_each */
|
||||
};
|
||||
|
||||
#endif /* _CLIXON_YANG_INTERNAL_H_ */
|
||||
Loading…
Add table
Add a link
Reference in a new issue