├── yangc ├── yangc.1x ├── Makefile.am └── yangc.c ├── INSTALL ├── test ├── fake │ ├── base-02.yang │ ├── goo.yang │ ├── test-05.yang │ ├── test-01.yang │ ├── test-02.yang │ ├── test-03.yang │ └── test-04.yang └── core │ ├── rtsdm.yang │ ├── librtsdb-trace-inc.yang │ ├── mchassis-inc.yang │ ├── syslog-inc.yang │ ├── trace-inc.yang │ └── common-inc.yang ├── packaging ├── yangc.pc.in └── yangc.spec.in ├── .gitignore ├── bin ├── Zaliases └── setup.sh ├── m4 ├── ltversion.m4 ├── ltsugar.m4 ├── lt~obsolete.m4 └── ltoptions.m4 ├── libyang ├── yanginternals.h ├── yang.h ├── yangversion.h.in ├── Makefile.am ├── yangloader.h ├── yangwriter.c ├── yangstmt.h ├── yangconfig.h.in ├── yangstmt.c └── yangloader.c ├── warnings.mk ├── Copyright ├── README.md ├── yangc-config.in ├── doc └── yangc.txt ├── Makefile.am └── configure.ac /yangc/yangc.1x: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | # 2 | # $Id$ 3 | # 4 | 5 | * Instructions for building yangc 6 | 7 | ** Dependencies 8 | 9 | TBD..... 10 | -------------------------------------------------------------------------------- /test/fake/base-02.yang: -------------------------------------------------------------------------------- 1 | submodule base { 2 | param $BIG-NUMBER = 1000000; 3 | 4 | typedef big-number { 5 | type int { 6 | range 0 .. $BIG-NUMBER; 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/fake/goo.yang: -------------------------------------------------------------------------------- 1 | module goo { 2 | namespace "http://example.com/goo"; 3 | prefix "goo"; 4 | 5 | grouping contents { 6 | leaf goo-leaf { 7 | type int; 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packaging/yangc.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | 7 | Name: @PACKAGE_NAME@ 8 | Version: @VERSION@ 9 | Description: YANG Compiler and Tools 10 | Requires: libxml-2.0 libxslt libslax 11 | Libs: @YANGC_LIBDIR@ @YANGC_LIBS@ 12 | Cflags: @YANGC_INCLUDEDIR@ 13 | -------------------------------------------------------------------------------- /test/fake/test-05.yang: -------------------------------------------------------------------------------- 1 | module foo { 2 | prefix "foo"; 3 | namespace "http://example.com/foo"; 4 | 5 | import goo; 6 | 7 | extension mumble { 8 | argument this"; 9 | parents "grouping typedef"; 10 | } 11 | 12 | grouping foo { 13 | leaf foo-leaf { 14 | type int; 15 | } 16 | } 17 | 18 | container foo { 19 | uses foo:contents; 20 | uses goo:contents; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.app 26 | *.i*86 27 | *.x86_64 28 | *.hex 29 | 30 | *~ 31 | 32 | aclocal.m4 33 | ar-lib 34 | autom4te.cache 35 | build 36 | compile 37 | config.guess 38 | config.h.in 39 | config.sub 40 | depcomp 41 | install-sh 42 | ltmain.sh 43 | missing 44 | 45 | Makefile.in 46 | configure 47 | .DS_Store 48 | -------------------------------------------------------------------------------- /test/fake/test-01.yang: -------------------------------------------------------------------------------- 1 | module foo { 2 | param $test-default = 15; 3 | param $test-mini = 1; 4 | param $test-max = 100; 5 | 6 | namespace "http://foo.example.net" { 7 | prefix foo; 8 | } 9 | contact "Phil Shafer"; 10 | 11 | augment protocols { 12 | container my-stuff { 13 | leaf test { 14 | description "test help"; 15 | type int { 16 | range $test-min .. $test-max; 17 | } 18 | default $test-default; 19 | must some-function("test"); 20 | } 21 | 22 | leaf-list funky { 23 | description "Funky stuff"; 24 | type string; 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /test/fake/test-02.yang: -------------------------------------------------------------------------------- 1 | module foo { 2 | namespace "http://foo.example.net" { 3 | prefix foo; 4 | } 5 | contact "Phil Shafer"; 6 | 7 | param $MAX = 100; 8 | param $test-default = 42; 9 | 10 | include base-02; 11 | 12 | augment protocols { 13 | container one { 14 | must not(../two); 15 | help "This is" + " a help string"; 16 | config true; 17 | } 18 | 19 | leaf test { 20 | help "test" + "ing"; 21 | must test + ing; 22 | must "test + ing"; 23 | must "test" + "ing"; 24 | type int { 25 | range "1" .. "100"; 26 | } 27 | default $test-default; 28 | must . < $MAX; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /bin/Zaliases: -------------------------------------------------------------------------------- 1 | set top_src=`pwd` 2 | setenv YANGDIR $top_src 3 | alias Zautoreconf "(cd $top_src ; autoreconf --install)" 4 | 5 | set opts=' \ 6 | --enable-clira \ 7 | --enable-debug \ 8 | --enable-warnings \ 9 | --enable-readline \ 10 | --enable-printflike \ 11 | --prefix /Users/phil/work/root \ 12 | --with-libxml-prefix=/Users/phil/work/root \ 13 | --with-libxslt-prefix=/Users/phil/work/root \ 14 | --with-libslax-prefix=/Users/phil/work/root \ 15 | ' 16 | set opts=`echo $opts` 17 | 18 | setenv CONFIGURE_OPTS "$opts" 19 | 20 | alias Zconfigure "(cd $top_src/build; ../configure $opts ); ." 21 | 22 | alias Zbuild "(cd $top_src/build; make \!* ); ." 23 | alias mi "(cd $top_src/build; make && make install); ." 24 | 25 | mkdir -p build 26 | cd build 27 | -------------------------------------------------------------------------------- /m4/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # @configure_input@ 11 | 12 | # serial 3337 ltversion.m4 13 | # This file is part of GNU Libtool 14 | 15 | m4_define([LT_PACKAGE_VERSION], [2.4.2]) 16 | m4_define([LT_PACKAGE_REVISION], [1.3337]) 17 | 18 | AC_DEFUN([LTVERSION_VERSION], 19 | [macro_version='2.4.2' 20 | macro_revision='1.3337' 21 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 22 | _LT_DECL(, macro_revision, 0) 23 | ]) 24 | -------------------------------------------------------------------------------- /libyang/yanginternals.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Juniper Networks, Inc. 3 | * All rights reserved. 4 | * See ../Copyright for the status of this software 5 | */ 6 | 7 | #ifndef YANG_INTERNALS_H 8 | #define YANG_INTERNALS_H 9 | 10 | #include "slaxinternals.h" 11 | 12 | /* In case these are already seen (from slaxconfig.h) */ 13 | #undef PACKAGE 14 | #undef PACKAGE_NAME 15 | #undef PACKAGE_STRING 16 | #undef PACKAGE_TARNAME 17 | #undef PACKAGE_VERSION 18 | #undef VERSION 19 | 20 | #include "yangconfig.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | extern int yangYyDebug; /* yydebug from yangparser.c */ 34 | 35 | #endif /* YANG_INTERNALS_H */ 36 | -------------------------------------------------------------------------------- /libyang/yang.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Juniper Networks, Inc. 3 | * All rights reserved. 4 | * See ../Copyright for the status of this software 5 | */ 6 | 7 | #ifndef LIBYANG_YANG_H 8 | #define LIBYANG_YANG_H 9 | 10 | #define YIN_URI "urn:ietf:params:xml:ns:yang:yin:1" 11 | #define YIN_PREFIX "yin" 12 | 13 | #define YANGC_URI "http://juise.org/yangc/1.0" 14 | #define YANGC_PREFIX "yangc" 15 | 16 | struct _xmlDoc; 17 | struct _xmlDict; 18 | struct _xmlNode; 19 | 20 | struct _xmlDoc * 21 | yangLoadFile (const char *template, const char *filename, 22 | FILE *file, struct _xmlDict *dict, int partial); 23 | 24 | int 25 | yangWriteDocNode (slaxWriterFunc_t func, void *data, 26 | struct _xmlNode *nodep, unsigned flags); 27 | 28 | int 29 | yangWriteDoc (slaxWriterFunc_t func, void *data, 30 | struct _xmlDoc *docp, unsigned flags); 31 | 32 | #endif /* LIBYANG_YANG_H */ 33 | -------------------------------------------------------------------------------- /bin/setup.sh: -------------------------------------------------------------------------------- 1 | # 2 | # $Id$ 3 | # 4 | # Copyright 2011-2014, Juniper Networks, Inc. 5 | # All rights reserved. 6 | # This SOFTWARE is licensed under the LICENSE provided in the 7 | # ../Copyright file. By downloading, installing, copying, or otherwise 8 | # using the SOFTWARE, you agree to be bound by the terms of that 9 | # LICENSE. 10 | 11 | if [ ! -f configure ]; then 12 | vers=`autoreconf --version | head -1` 13 | echo "Using" $vers 14 | 15 | autoreconf --install 16 | 17 | if [ ! -f configure ]; then 18 | echo "Failed to create configure script" 19 | exit 1 20 | fi 21 | fi 22 | 23 | if [ ! -d build ]; then 24 | echo "Creating build directory ..." 25 | mkdir build 26 | fi 27 | 28 | echo "Setup is complete. To build yangc:" 29 | 30 | echo " 1) Type 'cd build ; ../configure' to configure yangc" 31 | echo " 2) Type 'make' to build yangc" 32 | echo " 3) Type 'make install' to install yangc" 33 | 34 | exit 0 35 | -------------------------------------------------------------------------------- /warnings.mk: -------------------------------------------------------------------------------- 1 | # 2 | # $Id$ 3 | # 4 | # Commonly used sets of warnings 5 | # 6 | 7 | MIN_WARNINGS?= -W -Wall 8 | 9 | LOW_WARNINGS?= ${MIN_WARNINGS} \ 10 | -Wstrict-prototypes \ 11 | -Wmissing-prototypes \ 12 | -Wpointer-arith 13 | 14 | MEDIUM_WARNINGS?= ${LOW_WARNINGS} -Werror 15 | 16 | HIGH_WARNINGS?= ${MEDIUM_WARNINGS} \ 17 | -Waggregate-return \ 18 | -Wcast-align \ 19 | -Wcast-qual \ 20 | -Wchar-subscripts \ 21 | -Wcomment \ 22 | -Wformat \ 23 | -Wimplicit \ 24 | -Wmissing-declarations \ 25 | -Wnested-externs \ 26 | -Wparentheses \ 27 | -Wreturn-type \ 28 | -Wshadow \ 29 | -Wswitch \ 30 | -Wtrigraphs \ 31 | -Wuninitialized \ 32 | -Wunused \ 33 | -Wwrite-strings 34 | 35 | HIGHER_WARNINGS?= ${HIGH_WARNINGS} \ 36 | -Winline \ 37 | -Wbad-function-cast \ 38 | -Wpacked \ 39 | -Wpadded \ 40 | -Wstrict-aliasing 41 | 42 | WARNINGS += $(if ${YANGC_WARNINGS}, ${HIGH_WARNINGS}, ${LOW_WARNINGS}) 43 | 44 | WARNINGS += -fno-inline-functions-called-once 45 | -------------------------------------------------------------------------------- /libyang/yangversion.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | * 4 | * Copyright (c) 2014, Juniper Networks, Inc. 5 | * All rights reserved. 6 | * This SOFTWARE is licensed under the LICENSE provided in the 7 | * ../Copyright file. By downloading, installing, copying, or otherwise 8 | * using the SOFTWARE, you agree to be bound by the terms of that 9 | * LICENSE. 10 | * 11 | * yangconfig.h -- compile time constants for libyang 12 | * NOTE: This file is generated from yangconfig.h.in. 13 | */ 14 | 15 | #ifndef LIBYANG_YANGCONFIG_H 16 | #define LIBYANG_YANGCONFIG_H 17 | 18 | /** 19 | * The version string 20 | */ 21 | #define YANGC_VERSION "@PACKAGE_VERSION@" 22 | 23 | /** 24 | * The version number 25 | */ 26 | #define YANGC_VERSION_NUMBER @YANGC_VERSION_NUMBER@ 27 | 28 | /** 29 | * The version number as a string 30 | */ 31 | #define YANGC_VERSION_STRING "@YANGC_VERSION_NUMBER@" 32 | 33 | /** 34 | * The version number extra info as a string 35 | */ 36 | #define YANGC_VERSION_EXTRA "@YANGC_VERSION_EXTRA@" 37 | 38 | #endif /* LIBYANG_YANGCONFIG_H */ 39 | -------------------------------------------------------------------------------- /packaging/yangc.spec.in: -------------------------------------------------------------------------------- 1 | Name: @PACKAGE_NAME@ 2 | Version: @PACKAGE_VERSION@ 3 | Release: 1%{?dist} 4 | Summary: YANG Compiler 5 | 6 | Prefix: /usr 7 | 8 | Vendor: Juniper Networks, Inc. 9 | Packager: Phil Shafer 10 | License: BSD 11 | 12 | Group: Development/Libraries 13 | URL: https://github.com/Juniper/libslax 14 | Source0: https://github.com/Juniper/@PACKAGE_NAME@/releases/@PACKAGE_VERSION@/@PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz 15 | 16 | BuildRequires: libxml2-devel 17 | BuildRequires: libxslt-devel 18 | BuildRequires: libedit-devel 19 | BuildRequires: libslax 20 | BuildRequires: bison-devel 21 | BuildRequires: bison 22 | 23 | %description 24 | Welcome to yangc, the YANG compiler. 25 | 26 | %prep 27 | %setup -q 28 | 29 | %build 30 | %configure 31 | make %{?_smp_mflags} 32 | 33 | %install 34 | rm -rf $RPM_BUILD_ROOT 35 | %make_install 36 | 37 | %clean 38 | rm -rf $RPM_BUILD_ROOT 39 | 40 | %post -p /sbin/ldconfig 41 | 42 | %files 43 | %{_bindir}/* 44 | %{_libdir}/* 45 | %{_libdir}/pkgconfig/yangc.pc 46 | %{_libdir}/lib* 47 | %{_datadir}/doc/yangc/* 48 | %{_libexecdir}/yangc/* 49 | %{_datadir}/yangc/import/* 50 | %{_mandir}/*/* 51 | %docdir %{_mandir}/*/* 52 | -------------------------------------------------------------------------------- /yangc/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # $Id$ 3 | # 4 | # Copyright 2011, Juniper Networks, Inc. 5 | # All rights reserved. 6 | # This SOFTWARE is licensed under the LICENSE provided in the 7 | # ../Copyright file. By downloading, installing, copying, or otherwise 8 | # using the SOFTWARE, you agree to be bound by the terms of that 9 | # LICENSE. 10 | 11 | if YANGC_WARNINGS_HIGH 12 | YANGC_WARNINGS = HIGH 13 | endif 14 | include ${top_srcdir}/warnings.mk 15 | 16 | AM_CFLAGS = \ 17 | -DLIBSLAX_XMLSOFT_NEED_PRIVATE \ 18 | -I${top_srcdir} \ 19 | -I${top_srcdir}/libyang \ 20 | -I${top_builddir} \ 21 | ${LIBSLAX_CFLAGS} \ 22 | ${LIBXSLT_CFLAGS} \ 23 | ${LIBXML_CFLAGS} \ 24 | ${WARNINGS} 25 | 26 | LIBS = \ 27 | ${LIBSLAX_LIBS} \ 28 | ${LIBXSLT_LIBS} \ 29 | -lexslt \ 30 | ${LIBXML_LIBS} 31 | 32 | #noinst_HEADERS = \ 33 | # yangc.h 34 | 35 | if YANGC_DEBUG 36 | AM_CFLAGS += -g -DYANGC_DEBUG 37 | endif 38 | 39 | AM_CFLAGS += \ 40 | -DYANGC_DIR=\"${YANGC_DIR}\" 41 | 42 | if HAVE_READLINE 43 | LIBS += -L/opt/local/lib -lreadline 44 | endif 45 | 46 | if HAVE_LIBEDIT 47 | LIBS += -ledit 48 | endif 49 | 50 | if HAVE_LIBM 51 | LIBS += -lm 52 | endif 53 | 54 | bin_PROGRAMS = yangc 55 | 56 | yangc_SOURCES = yangc.c 57 | yangc_LDADD = ../libyang/libyang.la 58 | yangc_LDFLAGS = -static 59 | 60 | man_MANS = yangc.1x 61 | 62 | EXTRA_DIST = yangc.1x 63 | -------------------------------------------------------------------------------- /Copyright: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Juniper Networks Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the Juniper Networks nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | -------------------------------------------------------------------------------- /test/fake/test-03.yang: -------------------------------------------------------------------------------- 1 | module foo { 2 | // This is a comment 3 | /* This is a comment also */ 4 | namespace "http://foo.example.net" { 5 | prefix foo; 6 | } 7 | contact "Phil Shafer"; 8 | 9 | param $MIN = 12; 10 | param $MAX = 100; 11 | param $test-default = 42; 12 | param $test = "not(foo)"; 13 | param $this = "one"; 14 | param $that = "two"; 15 | 16 | include base-02; 17 | 18 | template foo ($a, $b, $c) { 19 | leaf foo-is-working { 20 | if ($c > 1) { 21 | help $b; 22 | } 23 | } 24 | } 25 | 26 | augment protocols { 27 | call foo($a = "foo-data", $b = "Foo Data", $c = 2); 28 | 29 | container one { 30 | must not(../two == $MAX); 31 | must $test; 32 | must $this==$that; 33 | help "This is" + " a help string"; 34 | config true; 35 | } 36 | 37 | leaf test { 38 | help "test" + "ing"; 39 | must "test" + "ing"; 40 | type int { 41 | range $MIN .. $MAX; 42 | } 43 | default $test-default; 44 | must . < $MAX; 45 | } 46 | } 47 | 48 | container examples-from-spec { 49 | leaf host-name { 50 | type string; 51 | description "Hostname for this system"; 52 | } 53 | 54 | 55 | container system { 56 | container login { 57 | leaf message { 58 | type string; 59 | description 60 | "Message given at start of login session"; 61 | } 62 | 63 | list user { 64 | key "name"; 65 | leaf name { 66 | type string; 67 | } 68 | leaf full-name { 69 | type string; 70 | } 71 | leaf class { 72 | type string; 73 | } 74 | } 75 | } 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 11 | 12 | # JUISE: The JUNOS User Interface Scripting Environment 13 | 14 | The JUISE project (the JUNOS User Interface Scripting Environment) 15 | allows scripts to be written, debugged, and executed outside the 16 | normal JUNOS environment. Users can develop scripts in their desktop 17 | environment, performing the code/test/debug cycle in a more natural 18 | way. Tools for developers are available, including a debugger, a 19 | profiler, a call-flow tracing mechanism, and trace files. 20 | The JUNOS-specific extension functions are available for scripts, 21 | allowing access to JUNOS XML data using the normal jcs:invoke and 22 | jcs:execute functions. Commit scripts can be tested against a JUNOS 23 | device's configuration and the results of those script tested on that 24 | device. 25 | 26 | Check our 27 | [github release page](https://github.com/Juniper/libslax/releases) 28 | to find the latest release. 29 | 30 | Please visit the 31 | [juise wiki](https://github.com/Juniper/juise/wiki) 32 | for more information, documentation, examples, and notes on 33 | JUISE and CLIRA. 34 | 35 | 48 | -------------------------------------------------------------------------------- /yangc-config.in: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | includedir=@includedir@ 6 | libdir=@libdir@ 7 | 8 | usage() 9 | { 10 | cat < yangparser.c 66 | @${RM} yangparser.c.old 67 | 68 | CLEANFILES = yangparser.h yangparser.c yangparser.output 69 | 70 | # 71 | # See the comment at the top of slaxparser-xp.y for details 72 | # 73 | YANGPIECES = \ 74 | ${srcdir}/yangparser.y \ 75 | ${LIBSLAX_INTERNALDIR}/slaxparser-xp.y \ 76 | slaxparser-xpl.y \ 77 | ${LIBSLAX_INTERNALDIR}/slaxparser-tail.y 78 | 79 | 80 | if HAVE_BISON30 81 | BISON_HEADER = "%param {slax_data_t *slax_data}" 82 | else 83 | BISON_HEADER = 84 | endif 85 | 86 | yangparser-out.y: ${YANGPIECES} 87 | ${ECHO_BUILD_${V}}(echo ${BISON_HEADER} ; cat ${YANGPIECES} ) > $@ 88 | 89 | yangparser.h: yangparser.c 90 | ${libyang_la_SOURCES:.c=.o}: ${YANGHEADERS} 91 | ${libyang_la_SOURCES:.c=.lo}: ${YANGHEADERS} 92 | 93 | EXTRA_DIST = \ 94 | yangparser.y 95 | 96 | CLEANFILES += yangparser-out.y slaxparser-xpl.y 97 | 98 | slaxparser-xpl.y: ${LIBSLAX_INTERNALDIR}slaxparser-xp.y 99 | ${ECHO_BUILD_${V}}sed 's/xp_/xpl_/g' \ 100 | < ${LIBSLAX_INTERNALDIR}/slaxparser-xp.y > slaxparser-xpl.y 101 | 102 | clean-yangparser: 103 | ${RM} -f slaxparser-xpl.y yangparser-out.y 104 | 105 | svnignore: 106 | svn propset svn:ignore -F ${srcdir}/.svnignore ${srcdir} 107 | 108 | CLEANFILES += yangconfig.h yangparser.d 109 | -------------------------------------------------------------------------------- /libyang/yangloader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Juniper Networks, Inc. 3 | * All rights reserved. 4 | * This SOFTWARE is licensed under the LICENSE provided in the 5 | * ../Copyright file. By downloading, installing, copying, or otherwise 6 | * using the SOFTWARE, you agree to be bound by the terms of that 7 | * LICENSE. 8 | */ 9 | 10 | typedef struct yang_file_s { 11 | TAILQ_ENTRY(yang_file_s) yf_link; /* Next file */ 12 | char *yf_name; /* Name of this module or submodule */ 13 | unsigned yf_flags; /* Flags (YFF_*) */ 14 | xmlDocPtr yf_docp; /* Parse document */ 15 | xmlNodePtr yf_root; /* Root node of doc: xsl:stylesheet */ 16 | xmlNodePtr yf_main; /* Main template doc: yin:{,sub}module */ 17 | char *yf_namespace; /* XML namespace for this content */ 18 | char *yf_prefix; /* XML prefix for this content */ 19 | char *yf_path; /* Full path to the file */ 20 | char *yf_revision; /* Revision date (or null) */ 21 | xmlXPathContextPtr yf_context; /* Context for functions/select */ 22 | } yang_file_t; 23 | 24 | typedef TAILQ_HEAD(yang_file_list_s, yang_file_s) yang_file_list_t; 25 | 26 | /* Flags for yf_flags: */ 27 | #define YFF_IMPORT (1<<0) /* Imported (not included) */ 28 | #define YFF_MODULE (1<<1) /* File is a module */ 29 | 30 | #define YANG_MAX_STATEMENT_MAP 256 31 | #ifndef NBBY 32 | #define NBBY 8 33 | #endif /* NBBY */ 34 | 35 | typedef unsigned char yang_seen_elt_t; 36 | typedef struct yang_seen_s { 37 | yang_seen_elt_t yss_map[YANG_MAX_STATEMENT_MAP / NBBY]; 38 | } yang_seen_t; 39 | 40 | typedef struct yang_parse_stack_s { 41 | struct yang_stmt_s *yps_stmt; /* Our statement */ 42 | unsigned yps_flags; /* Flags (YPSF_*) */ 43 | yang_seen_t yps_seen; /* Substatements we have seen */ 44 | } yang_parse_stack_t; 45 | 46 | /* Flags for yps_flags: */ 47 | #define YPSF_DISCARD (1<<0) /* Discard when closed (an error) */ 48 | 49 | #define YANG_STACK_MAX_DEPTH 256 /* Max number of nested statements */ 50 | 51 | typedef struct yang_data_s { 52 | yang_parse_stack_t yd_stack[YANG_STACK_MAX_DEPTH]; /* Open stmts */ 53 | yang_parse_stack_t *yd_stackp; /* Pointer into yd_stack */ 54 | xmlNsPtr yd_nsp; /* Point to the 'yin' namespace */ 55 | yang_file_t *yd_filep; /* Current file */ 56 | yang_file_list_t *yd_file_list; /* List of current files */ 57 | } yang_data_t; 58 | 59 | /* 60 | * Find parent parse stack frame 61 | */ 62 | static inline yang_parse_stack_t * 63 | yangStackParent (yang_data_t *ydp, yang_parse_stack_t *ypsp) 64 | { 65 | if (ypsp == NULL || ypsp == ydp->yd_stack) 66 | return NULL; 67 | return ypsp - 1; 68 | } 69 | 70 | /* 71 | * Retrieve the yang data pointer from a slax data block 72 | */ 73 | static inline yang_data_t * 74 | yangData (slax_data_t *sdp) 75 | { 76 | return sdp->sd_opaque; 77 | } 78 | 79 | /* 80 | * The bison-based parser's main function 81 | */ 82 | int 83 | yangParse (slax_data_t *); 84 | 85 | yang_file_t * 86 | yangFileLoader (const char *template, const char *name, 87 | const char *filename, xmlDictPtr dict, int partial); 88 | 89 | void 90 | yangError (slax_data_t *sdp, const char *fmt, ...); 91 | 92 | void 93 | yangFeatureAdd (const char *feature_name); 94 | 95 | xmlDocPtr 96 | yangFeaturesBuildInputDoc (void); 97 | 98 | xmlDocPtr 99 | yangLoadParams (const char *filename, FILE *file, xmlDictPtr dict); 100 | -------------------------------------------------------------------------------- /doc/yangc.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2014, Juniper Networks, Inc. 3 | # All rights reserved. 4 | # See ../Copyright for the status of this software 5 | # 6 | 7 | 8 | * YANGC - The JUNOS YANG Compiler 9 | 10 | ** Overview 11 | 12 | The YANG standard builds on the experiences of the JUNOS DDL, allowing 13 | us to correct many mistakes of the past. But YANG is not a proper 14 | super set of DDL. There are many missing features: 15 | 16 | - DDL using CPP for constant substitution 17 | - DDL using CPP macros with arguments 18 | - DDL "feature" has no YANG equivalent 19 | 20 | In addition there are places in DDL where simple logic statements 21 | would help make meanings more obvious, and more content reusable. 22 | 23 | ** YIN 24 | 25 | Many YANG features use/require XPath support, and the easiest means to 26 | get this is the use of libxml2, which means putting YANG statements 27 | into YIN format. YIN is the XML version of YANG, with a consistent, 28 | round-trip-capable mapping. 29 | 30 | ** Enter SLAX 31 | 32 | Given that YANGC builds XML, it make sense to use the XML-building 33 | functions in libslax. And given that, it make sense to use the logic 34 | elements from SLAX. SLAX statements can be freely intermixed with 35 | YANG statements, playing to the declarative strengths of SLAX. 36 | 37 | leaf foo { 38 | name "Foo knob"; 39 | if ($FOO_IS_MANDATORY) { 40 | mandatory true; 41 | } 42 | } 43 | 44 | SLAX templates can be used in place of CPP macros, with features like 45 | pass-by-name and default values for parameters. 46 | 47 | call gen-foo($help = "Test foo", $hidden = "internal"); 48 | 49 | template gen-foo ($help, $mandatory, $hidden) { 50 | leaf foo { 51 | help $help; 52 | if ($mandatory) { 53 | mandatory $mandatory; 54 | } 55 | if ($hidden) { 56 | hidden $hidden; 57 | } 58 | } 59 | } 60 | 61 | For this all to work, the output of the YANG compiler is an XSLT 62 | script, which can be run to generate the real YANG module, in YIN 63 | format. 64 | 65 | ** Parameters 66 | 67 | Parameters can be declared, with default values, using the SLAX 68 | syntax: 69 | 70 | param $FOO_IS_MANDATORY; 71 | param $MAX_SLOT = 8; 72 | 73 | These can be referred to in YANG statements: 74 | 75 | leaf foo { 76 | type int { 77 | range 0 .. $MAX_SLOT; 78 | } 79 | } 80 | 81 | Internally, this turns into a concat() operation of the strings: 82 | 83 | 84 | 85 | Parameter files on the target device can turn supply local values for 86 | parameters, using a scheme similar to the way multiple junos-defaults 87 | files are loaded. See the gory details in the function 88 | lib/loadogram.c:gram_load_config_defaults(). 89 | 90 | This allows multiple custom local values to be loaded. Rah! 91 | 92 | ** Mechanics 93 | 94 | YANGC parses YANG files and checks contents, expands imports and 95 | includes, replaces groupings, and builds the XSLT script. But it 96 | cannot invoke templates or expand constants, since these will depend 97 | on parameters of the target system. 98 | 99 | This XSLT script will need to be packed into a proprietary format for 100 | JUNOS files, since we can't expose precious internals to our customer 101 | base. 102 | 103 | For customer-provided files, this hidden bit is less important. 104 | 105 | The open-source YANGC project will provide a simple encode/decode, but 106 | provide hooks for a proprietary one for JUNOS modules. 107 | 108 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # $Id$ 3 | # 4 | # Copyright 2011-2014, Juniper Networks, Inc. 5 | # All rights reserved. 6 | # This SOFTWARE is licensed under the LICENSE provided in the 7 | # ../Copyright file. By downloading, installing, copying, or otherwise 8 | # using the SOFTWARE, you agree to be bound by the terms of that 9 | # LICENSE. 10 | 11 | ACLOCAL_AMFLAGS = -I m4 12 | 13 | SUBDIRS = libyang yangc 14 | 15 | bin_SCRIPTS=yangc-config 16 | dist_doc_DATA = Copyright 17 | 18 | EXTRA_DIST = \ 19 | yangc-config.in \ 20 | warnings.mk \ 21 | README.md \ 22 | INSTALL \ 23 | bin/setup.sh \ 24 | packaging/yangc.spec 25 | 26 | .PHONY: test tests 27 | 28 | test tests: 29 | @(cd tests ; ${MAKE} test) 30 | 31 | errors: 32 | @(cd tests/errors ; ${MAKE} test) 33 | 34 | docs: 35 | @(cd doc ; ${MAKE} docs) 36 | 37 | DIST_FILES_DIR = ~/Dropbox/dist-files/ 38 | GH_PAGES_DIR = gh-pages/ 39 | PACKAGE_FILE = ${PACKAGE_TARNAME}-${PACKAGE_VERSION}.tar.gz 40 | 41 | upload: dist upload-docs 42 | @echo "Remember to run:" 43 | @echo " gt tag ${PACKAGE_VERSION}" 44 | 45 | upload-docs: docs 46 | @-[ -d ${GH_PAGES_DIR} ] \ 47 | && echo "Updating manual on gh-pages ..." \ 48 | && cp doc/yangc-manual.html ${GH_PAGES_DIR} \ 49 | && (cd ${GH_PAGES_DIR} \ 50 | && git commit -m 'new docs' \ 51 | yangc-manual.html \ 52 | && git push origin gh-pages ) ; true 53 | 54 | pkgconfigdir=$(libdir)/pkgconfig 55 | pkgconfig_DATA = packaging/${PACKAGE_NAME}.pc 56 | 57 | get-wiki: 58 | git clone https://github.com/Juniper/${PACKAGE_NAME}.wiki.git wiki 59 | 60 | get-gh-pages: 61 | git clone https://github.com/Juniper/${PACKAGE_NAME}.git \ 62 | gh-pages -b gh-pages 63 | 64 | 65 | UPDATE_PACKAGE_FILE = \ 66 | -e "s;__SHA1__;$$SHA1;" \ 67 | -e "s;__SHA256__;SHA256 (textproc/${PACKAGE_FILE}) = $$SHA256;" \ 68 | -e "s;__SIZE__;SIZE (textproc/${PACKAGE_FILE}) = $$SIZE;" 69 | 70 | GH_PACKAGING_DIR = packaging/${PACKAGE_VERSION} 71 | GH_PAGES_PACKAGE_DIR = ${GH_PAGES_DIR}/${GH_PACKAGING_DIR} 72 | 73 | packages: 74 | @-[ -d ${GH_PAGES_DIR} ] \ 75 | && echo "Updating packages on gh-pages ..." \ 76 | && SHA1=`openssl sha1 ${PACKAGE_FILE} | awk '{print $$2}'` \ 77 | && SHA256="`openssl sha256 ${PACKAGE_FILE} | awk '{print $$2}'`" \ 78 | && SIZE="`ls -l ${PACKAGE_FILE} | awk '{print $$5}'`" \ 79 | && mkdir -p ${GH_PAGES_PACKAGE_DIR}/freebsd \ 80 | && echo "... ${GH_PAGES_PACKAGE_DIR}/${PACKAGE_NAME}.rb ..." \ 81 | && sed ${UPDATE_PACKAGE_FILE} \ 82 | packaging/${PACKAGE_NAME}.rb.base \ 83 | > ${GH_PAGES_PACKAGE_DIR}/${PACKAGE_NAME}.rb \ 84 | && cp packaging/${PACKAGE_NAME}.spec \ 85 | ${GH_PAGES_PACKAGE_DIR}/${PACKAGE_NAME}.spec \ 86 | && cp packaging/${PACKAGE_NAME}.spec \ 87 | ${GH_PAGES_PACKAGE_DIR}/${PACKAGE_NAME}.spec \ 88 | && echo "... ${GH_PAGES_PACKAGE_DIR}/freebsd ..." \ 89 | && sed ${UPDATE_PACKAGE_FILE} \ 90 | ${srcdir}/packaging/freebsd/distinfo.base \ 91 | > ${GH_PAGES_PACKAGE_DIR}/freebsd/distinfo \ 92 | && cp ${srcdir}/packaging/freebsd/pkg-descr \ 93 | ${GH_PAGES_PACKAGE_DIR}/freebsd/pkg-descr \ 94 | && cp ${srcdir}/packaging/freebsd/pkg-plist \ 95 | ${GH_PAGES_PACKAGE_DIR}/freebsd/pkg-plist \ 96 | && cp ${srcdir}/packaging/freebsd/pkg-plist \ 97 | ${GH_PAGES_PACKAGE_DIR}/freebsd/pkg-plist \ 98 | && cp packaging/freebsd/port-Makefile \ 99 | ${GH_PAGES_PACKAGE_DIR}/freebsd/Makefile \ 100 | && (cd ${GH_PAGES_DIR} \ 101 | && git add ${GH_PACKAGING_DIR} \ 102 | && git commit -m 'new packaging data' \ 103 | ${GH_PACKAGING_DIR} \ 104 | && git push origin gh-pages ) ; true 105 | -------------------------------------------------------------------------------- /libyang/yangwriter.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Juniper Networks, Inc. 3 | * All rights reserved. 4 | * This SOFTWARE is licensed under the LICENSE provided in the 5 | * ../Copyright file. By downloading, installing, copying, or otherwise 6 | * using the SOFTWARE, you agree to be bound by the terms of that 7 | * LICENSE. 8 | * 9 | * jsonwriter.c -- turn json-oriented XML into json text 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include "slaxinternals.h" 26 | 27 | #include "yang.h" 28 | #include "yangstmt.h" 29 | 30 | /* Forward declarations */ 31 | static int 32 | yangWriteChildren (slax_writer_t *swp, xmlNodePtr parent, 33 | const char *except, unsigned flags); 34 | 35 | static int 36 | yangWriteHasChildNodes (slax_writer_t *swp UNUSED, xmlNodePtr nodep) 37 | { 38 | if (nodep == NULL) 39 | return FALSE; 40 | 41 | for (nodep = nodep->children; nodep; nodep = nodep->next) 42 | if (nodep->type != XML_TEXT_NODE) 43 | return TRUE; 44 | 45 | return FALSE; 46 | } 47 | 48 | static const char * 49 | yangWriteNeedsQuotes (slax_writer_t *swp UNUSED, const char *data) 50 | { 51 | if (data == NULL) 52 | return ""; 53 | 54 | if (strchr(data, (int) '\'') != NULL) 55 | return "\""; 56 | 57 | if (strchr(data, (int) '\"') != NULL) 58 | return "\'"; 59 | 60 | size_t len = strlen(data); 61 | if (strcspn(data, "\"' \t\n\r") != len) 62 | return "\""; 63 | 64 | if (strstr(data, "//") || strstr(data, "/*")) 65 | return "\""; 66 | 67 | return ""; 68 | } 69 | 70 | static int 71 | yangWriteNode (slax_writer_t *swp, xmlNodePtr nodep, unsigned flags) 72 | { 73 | const char *name = (const char *) nodep->name; 74 | const char *namespace = nodep->ns ? (const char *) nodep->ns->href : NULL; 75 | yang_stmt_t *ysp; 76 | const char *argument; 77 | int as_element; 78 | const char *data = NULL; 79 | int ignore_children = FALSE; 80 | 81 | ysp = yangStmtFind(namespace, name); 82 | if (ysp == NULL) { 83 | as_element = FALSE; 84 | argument = "argument"; 85 | } else { 86 | as_element = (ysp->ys_flags & YSF_YINELEMENT) ? TRUE: FALSE; 87 | argument = ysp->ys_argument ?: "argument"; 88 | } 89 | 90 | if (as_element) { 91 | ignore_children = TRUE; 92 | if (nodep) { 93 | xmlNodePtr childp; 94 | for (childp = nodep->children; childp; childp = childp->next) { 95 | if (childp->type != XML_ELEMENT_NODE 96 | || childp->children == NULL) 97 | continue; 98 | if (!streq(argument, (const char *) childp->name)) { 99 | ignore_children = FALSE; 100 | continue; 101 | } 102 | if (childp->children->type == XML_TEXT_NODE) 103 | data = (const char *) childp->children->content; 104 | break; 105 | } 106 | if (childp && childp->next) 107 | ignore_children = FALSE; 108 | } 109 | } else { 110 | data = slaxGetAttrib(nodep, argument); 111 | } 112 | 113 | const char *quote = yangWriteNeedsQuotes(swp, data); 114 | 115 | /* XXX need to escape this data */ 116 | slaxWrite(swp, "%s%s%s%s%s", name, data ? " " : "", 117 | quote, data ?: "", quote); 118 | 119 | if (!ignore_children && yangWriteHasChildNodes(swp, nodep)) { 120 | slaxWrite(swp, " {"); 121 | slaxWriteNewline(swp, NEWL_INDENT); 122 | 123 | yangWriteChildren(swp, nodep, argument, flags); 124 | 125 | slaxWrite(swp, "}"); 126 | slaxWriteNewline(swp, NEWL_OUTDENT); 127 | } else { 128 | slaxWrite(swp, ";"); 129 | slaxWriteNewline(swp, 0); 130 | } 131 | 132 | return 0; 133 | } 134 | 135 | static int 136 | yangWriteChildren (slax_writer_t *swp, xmlNodePtr parent, 137 | const char *except, unsigned flags) 138 | { 139 | xmlNodePtr nodep; 140 | int rc = 0; 141 | 142 | for (nodep = parent->children; nodep; nodep = nodep->next) { 143 | if (nodep->type == XML_ELEMENT_NODE) { 144 | if (except && streq(except, (const char *) nodep->name)) 145 | continue; 146 | yangWriteNode(swp, nodep, flags); 147 | } 148 | } 149 | 150 | return rc; 151 | } 152 | 153 | int 154 | yangWriteDocNode (slaxWriterFunc_t func, void *data, xmlNodePtr nodep, 155 | unsigned flags) 156 | { 157 | slax_writer_t *swp = slaxGetWriter(func, data); 158 | int rc = yangWriteNode(swp, nodep, flags); 159 | 160 | slaxWriteNewline(swp, 0); 161 | 162 | slaxFreeWriter(swp); 163 | return rc; 164 | } 165 | 166 | int 167 | yangWriteDoc (slaxWriterFunc_t func, void *data, xmlDocPtr docp, 168 | unsigned flags) 169 | { 170 | xmlNodePtr nodep = xmlDocGetRootElement(docp); 171 | return yangWriteDocNode(func, data, nodep, flags); 172 | } 173 | -------------------------------------------------------------------------------- /m4/ltsugar.m4: -------------------------------------------------------------------------------- 1 | # ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- 2 | # 3 | # Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. 4 | # Written by Gary V. Vaughan, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # serial 6 ltsugar.m4 11 | 12 | # This is to help aclocal find these macros, as it can't see m4_define. 13 | AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])]) 14 | 15 | 16 | # lt_join(SEP, ARG1, [ARG2...]) 17 | # ----------------------------- 18 | # Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their 19 | # associated separator. 20 | # Needed until we can rely on m4_join from Autoconf 2.62, since all earlier 21 | # versions in m4sugar had bugs. 22 | m4_define([lt_join], 23 | [m4_if([$#], [1], [], 24 | [$#], [2], [[$2]], 25 | [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])]) 26 | m4_define([_lt_join], 27 | [m4_if([$#$2], [2], [], 28 | [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])]) 29 | 30 | 31 | # lt_car(LIST) 32 | # lt_cdr(LIST) 33 | # ------------ 34 | # Manipulate m4 lists. 35 | # These macros are necessary as long as will still need to support 36 | # Autoconf-2.59 which quotes differently. 37 | m4_define([lt_car], [[$1]]) 38 | m4_define([lt_cdr], 39 | [m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])], 40 | [$#], 1, [], 41 | [m4_dquote(m4_shift($@))])]) 42 | m4_define([lt_unquote], $1) 43 | 44 | 45 | # lt_append(MACRO-NAME, STRING, [SEPARATOR]) 46 | # ------------------------------------------ 47 | # Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'. 48 | # Note that neither SEPARATOR nor STRING are expanded; they are appended 49 | # to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked). 50 | # No SEPARATOR is output if MACRO-NAME was previously undefined (different 51 | # than defined and empty). 52 | # 53 | # This macro is needed until we can rely on Autoconf 2.62, since earlier 54 | # versions of m4sugar mistakenly expanded SEPARATOR but not STRING. 55 | m4_define([lt_append], 56 | [m4_define([$1], 57 | m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])]) 58 | 59 | 60 | 61 | # lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...]) 62 | # ---------------------------------------------------------- 63 | # Produce a SEP delimited list of all paired combinations of elements of 64 | # PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list 65 | # has the form PREFIXmINFIXSUFFIXn. 66 | # Needed until we can rely on m4_combine added in Autoconf 2.62. 67 | m4_define([lt_combine], 68 | [m4_if(m4_eval([$# > 3]), [1], 69 | [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl 70 | [[m4_foreach([_Lt_prefix], [$2], 71 | [m4_foreach([_Lt_suffix], 72 | ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[, 73 | [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])]) 74 | 75 | 76 | # lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ]) 77 | # ----------------------------------------------------------------------- 78 | # Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited 79 | # by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ. 80 | m4_define([lt_if_append_uniq], 81 | [m4_ifdef([$1], 82 | [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1], 83 | [lt_append([$1], [$2], [$3])$4], 84 | [$5])], 85 | [lt_append([$1], [$2], [$3])$4])]) 86 | 87 | 88 | # lt_dict_add(DICT, KEY, VALUE) 89 | # ----------------------------- 90 | m4_define([lt_dict_add], 91 | [m4_define([$1($2)], [$3])]) 92 | 93 | 94 | # lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE) 95 | # -------------------------------------------- 96 | m4_define([lt_dict_add_subkey], 97 | [m4_define([$1($2:$3)], [$4])]) 98 | 99 | 100 | # lt_dict_fetch(DICT, KEY, [SUBKEY]) 101 | # ---------------------------------- 102 | m4_define([lt_dict_fetch], 103 | [m4_ifval([$3], 104 | m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]), 105 | m4_ifdef([$1($2)], [m4_defn([$1($2)])]))]) 106 | 107 | 108 | # lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE]) 109 | # ----------------------------------------------------------------- 110 | m4_define([lt_if_dict_fetch], 111 | [m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4], 112 | [$5], 113 | [$6])]) 114 | 115 | 116 | # lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...]) 117 | # -------------------------------------------------------------- 118 | m4_define([lt_dict_filter], 119 | [m4_if([$5], [], [], 120 | [lt_join(m4_quote(m4_default([$4], [[, ]])), 121 | lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]), 122 | [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl 123 | ]) 124 | -------------------------------------------------------------------------------- /test/core/rtsdm.yang: -------------------------------------------------------------------------------- 1 | submodule rtsdm { 2 | /* 3 | * Copyright (c) 2010, 2014, Juniper Networks, Inc. 4 | * All rights reserved. 5 | */ 6 | 7 | augment /system { 8 | container shm-rtsdbd { 9 | hidden support; 10 | notify shm-rtsdbd; 11 | 12 | container traceoptions { 13 | help "SHM rtsock database server trace options"; 14 | require trace; 15 | flag remove-empty; 16 | define DDLAID_SHM_RTSDBD_TRACEOPTIONS; 17 | 18 | uses traceoptions-file; 19 | uses traceoptions-level-leaf; 20 | 21 | list "flag" { 22 | help "Tracing parameters"; 23 | alias traceflag; 24 | flag oneliner; 25 | 26 | key flag-name; 27 | leaf flag-name { 28 | type enumeration { 29 | enum routing-socket { 30 | help "Trace routing-socket events"; 31 | define SHM_RTSDBD_TRACEFLAG_RTSOCK; 32 | } 33 | enum process { 34 | help "Trace process internals"; 35 | define SHM_RTSDBD_TRACEFLAG_PROCESS; 36 | } 37 | enum startup { 38 | help "Trace startup events/flow"; 39 | define SHM_RTSDBD_TRACEFLAG_STARTUP; 40 | } 41 | enum general { 42 | help "Trace general flow"; 43 | define SHM_RTSDBD_TRACEFLAG_GENERAL; 44 | } 45 | enum restart { 46 | help "Trace process restart flow"; 47 | define SHM_RTSDBD_TRACEFLAG_RESTART; 48 | } 49 | enum if-rtsdb { 50 | help "Trace interface hierarchy rtsdb"; 51 | define SHM_RTSDBD_TRACEFLAG_IF_RTSDB; 52 | } 53 | enum "all" { 54 | help "Trace everything"; 55 | define SHM_RTSDBD_TRACEFLAG_ALL; 56 | } 57 | } 58 | } 59 | leaf disable { 60 | help "Disable this trace flag"; 61 | type empty; 62 | } 63 | } 64 | } 65 | 66 | container rtsdb-server-traceoptions { 67 | help "SHM rtsock database server library trace options"; 68 | container if-rtsdb { 69 | help "Trace interface hierarchy rtsdb"; 70 | list "flag" { 71 | alias traceflag; 72 | flag oneliner; 73 | help "Tracing parameters"; 74 | 75 | key flag_name; 76 | leaf flag_name { 77 | type enumeration { 78 | enum "init" { 79 | help "Trace initialization"; 80 | } 81 | choice "routing-socket" { 82 | help "Trace routing socket messages"; 83 | } 84 | enum "state-entry" { 85 | help "Trace routing socket messages state"; 86 | } 87 | enum "map" { 88 | help "Trace shared memory mapping"; 89 | } 90 | enum "update-group" { 91 | help "Trace update group events"; 92 | } 93 | enum "user" { 94 | help "Trace user events"; 95 | } 96 | enum "all" { 97 | help "Trace all"; 98 | } 99 | } 100 | } 101 | leaf disable { 102 | help "Disable this trace flag"; 103 | type toggle; 104 | } 105 | } 106 | } 107 | } 108 | } 109 | } 110 | 111 | template rtsdb-client-trace-options (dbname, helpstr) { 112 | container rtsdb-client-traceoptions { 113 | help "SHM rtsock database client library trace options"; 114 | container $dbname { 115 | help $helpstr; 116 | list "flag" { 117 | alias traceflag; 118 | flag oneliner; 119 | help "Tracing parameters"; 120 | 121 | key flag_name; 122 | leaf flag_name { 123 | type enumeration { 124 | enum "init" { 125 | help "Trace initialization"; 126 | } 127 | enum "routing-socket" { 128 | help "Trace routing socket messages"; 129 | } 130 | enum "map" { 131 | help "Trace shared memory mapping"; 132 | } 133 | enum "all" { 134 | help "Trace all"; 135 | } 136 | } 137 | } 138 | leaf disable { 139 | help "Disable this trace flag"; 140 | type toggle; 141 | } 142 | } 143 | } 144 | } 145 | } 146 | } 147 | 148 | -------------------------------------------------------------------------------- /test/core/librtsdb-trace-inc.yang: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | * 4 | * Copyright (c) 2010, Juniper Networks, Inc. 5 | * All rights reserved. 6 | * 7 | */ 8 | 9 | /** 10 | * @file librtsdb_trace_include.dd 11 | * @brief Tracing knobs for librtsdb 12 | * 13 | * 14 | */ 15 | 16 | #include "common_include.dd" 17 | #include "trace_include.dd" 18 | 19 | #define RTSDB_SERVER_TRACE_OPTIONS(dbname, helpstr) \ 20 | object rtsdb-server-traceoptions { \ 21 | help "SHM rtsock database server library trace options"; \ 22 | object dbname { \ 23 | help helpstr; \ 24 | object "flag" { \ 25 | alias traceflag; \ 26 | flag setof list oneliner; \ 27 | help "Tracing parameters"; \ 28 | \ 29 | attribute flag_name { \ 30 | flag identifier nokeyword; \ 31 | type enum string { \ 32 | choice "init" { \ 33 | help "Trace initialization"; \ 34 | } \ 35 | choice "routing-socket" { \ 36 | help "Trace routing socket messages"; \ 37 | } \ 38 | choice "state-entry" { \ 39 | help "Trace routing socket messages state"; \ 40 | } \ 41 | choice "map" { \ 42 | help "Trace shared memory mapping"; \ 43 | } \ 44 | choice "update-group" { \ 45 | help "Trace update group events"; \ 46 | } \ 47 | choice "user" { \ 48 | help "Trace user events"; \ 49 | } \ 50 | choice "all" { \ 51 | help "Trace all"; \ 52 | } \ 53 | } \ 54 | } \ 55 | attribute disable { \ 56 | help "Disable this trace flag"; \ 57 | type toggle; \ 58 | } \ 59 | } \ 60 | } \ 61 | } 62 | 63 | #define RTSDB_CLIENT_TRACE_OPTIONS(dbname, helpstr) \ 64 | object rtsdb-client-traceoptions { \ 65 | help "SHM rtsock database client library trace options"; \ 66 | object dbname { \ 67 | help helpstr; \ 68 | object "flag" { \ 69 | alias traceflag; \ 70 | flag setof list oneliner; \ 71 | help "Tracing parameters"; \ 72 | \ 73 | attribute flag_name { \ 74 | flag identifier nokeyword; \ 75 | type enum uint { \ 76 | choice "init" { \ 77 | help "Trace initialization"; \ 78 | } \ 79 | choice "routing-socket" { \ 80 | help "Trace routing socket messages"; \ 81 | } \ 82 | choice "map" { \ 83 | help "Trace shared memory mapping"; \ 84 | } \ 85 | choice "all" { \ 86 | help "Trace all"; \ 87 | } \ 88 | } \ 89 | } \ 90 | attribute disable { \ 91 | help "Disable this trace flag"; \ 92 | type toggle; \ 93 | } \ 94 | } \ 95 | } \ 96 | } 97 | -------------------------------------------------------------------------------- /libyang/yangstmt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Juniper Networks, Inc. 3 | * All rights reserved. 4 | * See ../Copyright for the status of this software 5 | */ 6 | 7 | struct yang_stmt_s; 8 | struct yang_data_s; 9 | 10 | #define YANG_STMT_OPEN_ARGS \ 11 | slax_data_t *sdp UNUSED, struct yang_data_s *ydp UNUSED, \ 12 | struct yang_stmt_s *ysp UNUSED 13 | #define YANG_STMT_CLOSE_ARGS \ 14 | slax_data_t *sdp UNUSED, struct yang_data_s *ydp UNUSED, \ 15 | struct yang_stmt_s *ysp UNUSED 16 | #define YANG_STMT_SETARG_ARGS \ 17 | slax_data_t *sdp UNUSED, struct yang_data_s *ydp UNUSED, \ 18 | struct yang_stmt_s *ysp UNUSED 19 | 20 | typedef struct yang_relative_s { 21 | const char *yr_name; /* Name of our relative */ 22 | const char *yr_namespace; /* Namespace (NULL means our's) */ 23 | unsigned yr_flags; /* Flags for this relative */ 24 | } yang_relative_t; 25 | 26 | /* Flags for yr_flags */ 27 | #define YRF_MULTIPLE (1<<0) /* Allow multiple occurances (0..n)*/ 28 | #define YRF_MANDATORY (1<<1) /* Mandatory (1..n or 1) */ 29 | 30 | typedef struct yang_stmt_s { 31 | TAILQ_ENTRY(yang_stmt_s) ys_link; /* Next statement */ 32 | unsigned ys_id; /* Identifier for this statement */ 33 | const char *ys_name; /* The name of this statement */ 34 | const char *ys_namespace; /* XML namespace */ 35 | const char *ys_argument; /* YIN attribute name for argument */ 36 | unsigned ys_flags; /* Flags for this statement (YSF_*) */ 37 | unsigned ys_type; /* Type of argument (Y_*) */ 38 | yang_relative_t *ys_parents; /* Array of acceptable parent statements */ 39 | yang_relative_t *ys_children; /* Array of acceptable children statements */ 40 | int (*ys_open)(YANG_STMT_OPEN_ARGS); /* Statement is opened */ 41 | int (*ys_close)(YANG_STMT_CLOSE_ARGS); /* Statement is closed */ 42 | int (*ys_setarg)(YANG_STMT_SETARG_ARGS); /* Argument is set */ 43 | } yang_stmt_t; 44 | 45 | /* Flags for yang_stmt_t: */ 46 | #define YSF_YINELEMENT (1<<0) /* Encode as an element in YIN */ 47 | #define YSF_STANDARD (1<<1) /* Statement is YANG state */ 48 | #define YSF_CHILDREN_ALLOCED (1<<2) /* ys_children was malloced, needs freed */ 49 | 50 | #define YS_MULTIPLE "*" /* Allow multiple instances */ 51 | #define YS_MULTIPLE_CHAR '*' /* Ditto (as character) */ 52 | 53 | typedef TAILQ_HEAD(yang_stmt_list_s, yang_stmt_s) yang_stmt_list_t; 54 | 55 | void 56 | yangStmtInit (void); 57 | 58 | void 59 | yangStmtAdd (yang_stmt_t *ysp, const char *namespace, int count); 60 | 61 | yang_stmt_t * 62 | yangStmtFind (const char *namespace, const char *name); 63 | 64 | void 65 | yangStmtOpen (slax_data_t *sdp, const char *name); 66 | 67 | void 68 | yangStmtClose (slax_data_t *sdp, const char *name); 69 | 70 | void 71 | yangStmtSetArgument (slax_data_t *sdp, slax_string_t *value, int is_xpath); 72 | 73 | slax_string_t * 74 | yangConcatValues (slax_data_t *sdp, slax_string_t *one, 75 | slax_string_t *two, int with_space); 76 | 77 | #define YS_ANYXML "anyxml" 78 | #define YS_ARGUMENT "argument" 79 | #define YS_AUGMENT "augment" 80 | #define YS_BASE "base" 81 | #define YS_BELONGS_TO "belongs-to" 82 | #define YS_BIT "bit" 83 | #define YS_CASE "case" 84 | #define YS_CHOICE "choice" 85 | #define YS_CONDITION "condition" 86 | #define YS_CONFIG "config" 87 | #define YS_CONTACT "contact" 88 | #define YS_CONTAINER "container" 89 | #define YS_DATE "date" 90 | #define YS_DEFAULT "default" 91 | #define YS_DESCRIPTION "description" 92 | #define YS_DEVIATE "deviate" 93 | #define YS_DEVIATION "deviation" 94 | #define YS_ENUM "enum" 95 | #define YS_ERROR_APP_TAG "error-app-tag" 96 | #define YS_ERROR_MESSAGE "error-message" 97 | #define YS_EXTENSION "extension" 98 | #define YS_FEATURE "feature" 99 | #define YS_FRACTION_DIGITS "fraction-digits" 100 | #define YS_GROUPING "grouping" 101 | #define YS_HELP "help" 102 | #define YS_IDENTITY "identity" 103 | #define YS_IF_FEATURE "if-feature" 104 | #define YS_IMPORT "import" 105 | #define YS_INCLUDE "include" 106 | #define YS_INPUT "input" 107 | #define YS_KEY "key" 108 | #define YS_LEAF "leaf" 109 | #define YS_LEAF_LIST "leaf-list" 110 | #define YS_LENGTH "length" 111 | #define YS_LIST "list" 112 | #define YS_MANDATORY "mandatory" 113 | #define YS_MAX_ELEMENTS "max-elements" 114 | #define YS_MIN_ELEMENTS "min-elements" 115 | #define YS_MODULE "module" 116 | #define YS_MUST "must" 117 | #define YS_NAME "name" 118 | #define YS_NAMESPACE "namespace" 119 | #define YS_NOTIFICATION "notification" 120 | #define YS_ORDERED_BY "ordered-by" 121 | #define YS_ORGANIZATION "organization" 122 | #define YS_OUTPUT "output" 123 | #define YS_PATH "path" 124 | #define YS_PATTERN "pattern" 125 | #define YS_POSITION "position" 126 | #define YS_PREFIX "prefix" 127 | #define YS_PRESENCE "presence" 128 | #define YS_RANGE "range" 129 | #define YS_REFERENCE "reference" 130 | #define YS_REFINE "refine" 131 | #define YS_REQUIRE_INSTANCE "require-instance" 132 | #define YS_REVISION "revision" 133 | #define YS_REVISION_DATE "revision-date" 134 | #define YS_RPC "rpc" 135 | #define YS_STATUS "status" 136 | #define YS_SUBMODULE "submodule" 137 | #define YS_TAG "tag" 138 | #define YS_TARGET_NODE "target-node" 139 | #define YS_TEXT "text" 140 | #define YS_TYPE "type" 141 | #define YS_TYPEDEF "typedef" 142 | #define YS_UNIQUE "unique" 143 | #define YS_UNITS "units" 144 | #define YS_URI "uri" 145 | #define YS_USES "uses" 146 | #define YS_VALUE "value" 147 | #define YS_WHEN "when" 148 | #define YS_YANG_VERSION "yang-version" 149 | #define YS_YIN_ELEMENT "yin-element" 150 | 151 | /* Names for YANGC extensions */ 152 | #define YS_CHILDREN "children" 153 | #define YS_NAMES "names" 154 | #define YS_PARENTS "parents" 155 | 156 | void yangStmtInitBuiltin (void); 157 | 158 | char * 159 | yangStmtGetValueName (slax_data_t *sdp, xmlNodePtr nodep, 160 | const char *namespace, const char *name, 161 | const char *argument, unsigned flags); 162 | char * 163 | yangStmtGetValue (slax_data_t *sdp, xmlNodePtr nodep, yang_stmt_t *ysp); 164 | 165 | void 166 | yangStmtCheckArgument (slax_data_t *sdp, slax_string_t *sp); 167 | -------------------------------------------------------------------------------- /m4/lt~obsolete.m4: -------------------------------------------------------------------------------- 1 | # lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- 2 | # 3 | # Copyright (C) 2004, 2005, 2007, 2009 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004. 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # serial 5 lt~obsolete.m4 11 | 12 | # These exist entirely to fool aclocal when bootstrapping libtool. 13 | # 14 | # In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN) 15 | # which have later been changed to m4_define as they aren't part of the 16 | # exported API, or moved to Autoconf or Automake where they belong. 17 | # 18 | # The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN 19 | # in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us 20 | # using a macro with the same name in our local m4/libtool.m4 it'll 21 | # pull the old libtool.m4 in (it doesn't see our shiny new m4_define 22 | # and doesn't know about Autoconf macros at all.) 23 | # 24 | # So we provide this file, which has a silly filename so it's always 25 | # included after everything else. This provides aclocal with the 26 | # AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything 27 | # because those macros already exist, or will be overwritten later. 28 | # We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. 29 | # 30 | # Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here. 31 | # Yes, that means every name once taken will need to remain here until 32 | # we give up compatibility with versions before 1.7, at which point 33 | # we need to keep only those names which we still refer to. 34 | 35 | # This is to help aclocal find these macros, as it can't see m4_define. 36 | AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])]) 37 | 38 | m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])]) 39 | m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])]) 40 | m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])]) 41 | m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])]) 42 | m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])]) 43 | m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])]) 44 | m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])]) 45 | m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])]) 46 | m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])]) 47 | m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])]) 48 | m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])]) 49 | m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])]) 50 | m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])]) 51 | m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])]) 52 | m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])]) 53 | m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])]) 54 | m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])]) 55 | m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])]) 56 | m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])]) 57 | m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])]) 58 | m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])]) 59 | m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])]) 60 | m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])]) 61 | m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])]) 62 | m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])]) 63 | m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])]) 64 | m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])]) 65 | m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])]) 66 | m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])]) 67 | m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])]) 68 | m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])]) 69 | m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])]) 70 | m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])]) 71 | m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])]) 72 | m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])]) 73 | m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])]) 74 | m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])]) 75 | m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])]) 76 | m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])]) 77 | m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])]) 78 | m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])]) 79 | m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])]) 80 | m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])]) 81 | m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])]) 82 | m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])]) 83 | m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])]) 84 | m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])]) 85 | m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])]) 86 | m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])]) 87 | m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])]) 88 | m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])]) 89 | m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])]) 90 | m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])]) 91 | m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])]) 92 | m4_ifndef([_LT_REQUIRED_DARWIN_CHECKS], [AC_DEFUN([_LT_REQUIRED_DARWIN_CHECKS])]) 93 | m4_ifndef([_LT_AC_PROG_CXXCPP], [AC_DEFUN([_LT_AC_PROG_CXXCPP])]) 94 | m4_ifndef([_LT_PREPARE_SED_QUOTE_VARS], [AC_DEFUN([_LT_PREPARE_SED_QUOTE_VARS])]) 95 | m4_ifndef([_LT_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_PROG_ECHO_BACKSLASH])]) 96 | m4_ifndef([_LT_PROG_F77], [AC_DEFUN([_LT_PROG_F77])]) 97 | m4_ifndef([_LT_PROG_FC], [AC_DEFUN([_LT_PROG_FC])]) 98 | m4_ifndef([_LT_PROG_CXX], [AC_DEFUN([_LT_PROG_CXX])]) 99 | -------------------------------------------------------------------------------- /test/core/mchassis-inc.yang: -------------------------------------------------------------------------------- 1 | submodule mchassic-inc.yang { 2 | /* 3 | * Copyright (c) 1998-2008,2014, Juniper Networks, Inc. 4 | * All rights reserved. 5 | * 6 | * Common definitions for typical multi-chassis YANG. 7 | * (Not exposed to External/SDK users) 8 | */ 9 | 10 | /* 11 | * Protected system domain (formerly Hardware logical router) 12 | * related limits 13 | */ 14 | param $MCHASSIS_UI_MIN_PSD_ID = 1; 15 | param $MCHASSIS_UI_MAX_PSD_ID = 31; 16 | param $MCHASSIS_UI_MAX_PSD_JCS_CHASSIS_ID = 4; 17 | param $MCHASSIS_UI_MAX_PSD_ROOT_DOMAIN_ID = 3; 18 | param $MCHASSIS_UI_MIN_PSD_JCS_SLOT_NUM = 1; 19 | param $MCHASSIS_UI_MAX_PSD_JCS_SLOT_NUM = 12; 20 | 21 | template mchassis-mandatory-arg-help-base ($help_str, $arg) { 22 | choice cid { 23 | flag mandatory; 24 | product $TX_SERIES; 25 | copy-of $arg; 26 | argument lcc { 27 | help $help_str; 28 | type uint { 29 | range 0 .. $MCHASSIS_UI_MAX_LCC_SLOT; 30 | } 31 | action acceptable { 32 | daemon mgd; 33 | function mgd_is_switch_chassis; 34 | } 35 | } 36 | 37 | argument scc-dont-forward { 38 | type empty; 39 | hidden internal; 40 | action acceptable { 41 | daemon mgd; 42 | function mgd_is_switch_chassis; 43 | } 44 | } 45 | } 46 | } 47 | 48 | template mchassis-all-mandatory-arg-help-base ($help_str, $arg) { 49 | call mchassis-mandatory-arg-help-base($help_str, $arg); 50 | augment cid { 51 | argument "all-chassis" { 52 | help "Broadcast to all chassis"; 53 | type empty; 54 | action acceptable { 55 | daemon mgd; 56 | function mgd_is_switch_chassis; 57 | } 58 | } 59 | } 60 | } 61 | 62 | template mchassis-master-mandatory-arg-help-base ($help_str, $arg) { 63 | choice cid { 64 | flag mandatory; 65 | action acceptable { 66 | daemon mgd; 67 | function mgd_is_switch_chassis; 68 | } 69 | copy-of $arg; 70 | argument lcc { 71 | help $help_str; 72 | type uint { 73 | range 0 .. MCHASSIS_UI_MAX_LCC_SLOT; 74 | } 75 | action acceptable { 76 | daemon mgd; 77 | function mgd_is_switch_chassis; 78 | } 79 | } 80 | 81 | argument scc-dont-forward { 82 | type emtpy; 83 | hidden internal; 84 | action acceptable { 85 | daemon mgd; 86 | function mgd_is_switch_chassis; 87 | } 88 | } 89 | } 90 | } 91 | 92 | template mchassis-arg-help-base ($help_str, $arg) { 93 | choice cid { 94 | copy-of $arg; 95 | argument lcc { 96 | help $help_str; 97 | type uint { 98 | range 0 .. MCHASSIS_UI_MAX_LCC_SLOT; 99 | } 100 | action acceptable { 101 | daemon mgd; 102 | function mgd_is_switch_chassis; 103 | } 104 | } 105 | argument scc-dont-forward { 106 | type empty; 107 | hidden internal; 108 | action acceptable { 109 | daemon mgd; 110 | function mgd_is_switch_chassis; 111 | } 112 | } 113 | } 114 | } 115 | 116 | template mchassis-dynamic-arg-help-base ($help_str, $param, $arg) { 117 | choice cid { 118 | product $TX_SERIES; 119 | action mandatory { 120 | daemon mgd; 121 | code "return (mgd_sibling_present(daap, \"" _ $param _ "\") " 122 | "&& mgd_sibling_absent(daap, \"scc-dont-forward\"))"; 123 | } 124 | copy-of $arg; 125 | argument lcc { 126 | help $help_str; 127 | type uint { 128 | range 0 .. MCHASSIS_UI_MAX_LCC_SLOT; 129 | } 130 | action acceptable { 131 | daemon mgd; 132 | function mgd_is_switch_chassis; 133 | } 134 | } 135 | argument scc-dont-forward { 136 | type empty; 137 | hidden internal; 138 | action acceptable { 139 | daemon mgd; 140 | function mgd_is_switch_chassis; 141 | } 142 | } 143 | } 144 | } 145 | 146 | template mchassis-master-arg-help-base ($help_str, $arg) { 147 | choice cid { 148 | action acceptable { 149 | daemon mgd; 150 | function mgd_is_switch_chassis; 151 | } 152 | copy-of $arg; 153 | argument lcc { 154 | help $help_str; 155 | type uint { 156 | range 0 .. MCHASSIS_UI_MAX_LCC_SLOT; 157 | } 158 | action acceptable { 159 | daemon mgd; 160 | function mgd_is_switch_chassis; 161 | } 162 | } 163 | argument scc-dont-forward { 164 | type empty; 165 | hidden internal; 166 | action acceptable { 167 | daemon mgd; 168 | function mgd_is_switch_chassis; 169 | } 170 | } 171 | } 172 | } 173 | 174 | template is-valid-chassis-daemon ($daemon_name) { 175 | action acceptable { 176 | daemon mgd; 177 | code "return mgd_is_valid_chassis_daemon(" _ $daemon_name _ ")"; 178 | } 179 | } 180 | } 181 | 182 | /* 183 | 184 | / * 185 | * The next two provide scc and lcc args to a command. 186 | * / 187 | #define MCHASSIS_ARG_HELP(help) 188 | MCHASSIS_ARG_HELP_BASE(help, MCHASSIS_ARG_SCC(help)); 189 | 190 | #define MCHASSIS_DYNAMIC_ARG_HELP(help, param) 191 | MCHASSIS_DYNAMIC_ARG_HELP_BASE(help, param, MCHASSIS_ARG_SCC(help)); 192 | 193 | #define MCHASSIS_ARG_LCC_SCC_HELP(lcc_help, scc_help) 194 | MCHASSIS_ARG_HELP_BASE(lcc_help, MCHASSIS_ARG_SCC(scc_help)); 195 | 196 | #define MCHASSIS_MASTER_ARG_HELP(help) 197 | MCHASSIS_MASTER_ARG_HELP_BASE(help, MCHASSIS_ARG_SCC(help)); 198 | 199 | #define MCHASSIS_ARG_SHOW 200 | MCHASSIS_ARG_HELP("Display chassis-specific information"); 201 | 202 | #define MCHASSIS_DYNAMIC_ARG_SHOW(param) 203 | MCHASSIS_DYNAMIC_ARG_HELP("Display chassis-specific information", param); 204 | 205 | #define MCHASSIS_MASTER_ARG_SHOW 206 | MCHASSIS_MASTER_ARG_HELP("Display chassis-specific information"); 207 | 208 | #define MCHASSIS_MANDATORY_ARG_HELP(help) 209 | MCHASSIS_MANDATORY_ARG_HELP_BASE(help, MCHASSIS_ARG_SCC(help)); 210 | 211 | #define MCHASSIS_ALL_MANDATORY_ARG_HELP(help) 212 | MCHASSIS_ALL_MANDATORY_ARG_HELP_BASE(help, MCHASSIS_ARG_SCC(help)); 213 | 214 | #define MCHASSIS_MASTER_MANDATORY_ARG_HELP(help) 215 | MCHASSIS_MASTER_MANDATORY_ARG_HELP_BASE(help, MCHASSIS_ARG_SCC(help)); 216 | 217 | #define MCHASSIS_MANDATORY_ARG_SHOW 218 | MCHASSIS_MANDATORY_ARG_HELP("Display chassis-specific information"); 219 | 220 | #define MCHASSIS_MASTER_MANDATORY_ARG_SHOW 221 | MCHASSIS_MASTER_MANDATORY_ARG_HELP("Display chassis-specific information"); 222 | 223 | / * 224 | * This next macros provides lcc only args, no scc. 225 | * / 226 | #define MCHASSIS_LCC_ARG_HELP(help_str) 227 | MCHASSIS_ARG_HELP_BASE(help_str, ); 228 | 229 | #define MCHASSIS_LCC_SHOW(help) 230 | MCHASSIS_ARG_HELP_BASE(help, ); 231 | 232 | #define MCHASSIS_DYNAMIC_LCC_SHOW(param, help) 233 | MCHASSIS_DYNAMIC_ARG_HELP_BASE(help, param, ); 234 | 235 | #define MCHASSIS_MANDATORY_LCC_ARG_HELP(help_str) 236 | MCHASSIS_MANDATORY_ARG_HELP_BASE(help_str, ); 237 | 238 | #define MCHASSIS_MANDATORY_LCC_SHOW 239 | MCHASSIS_MANDATORY_ARG_HELP_BASE("Display chassis-specific information", ); 240 | 241 | */ 242 | -------------------------------------------------------------------------------- /test/fake/test-04.yang: -------------------------------------------------------------------------------- 1 | // Contents of "acme-system.yang" 2 | module acme-system { 3 | namespace "http://acme.example.com/system"; 4 | prefix "acme"; 5 | 6 | organization "ACME Inc."; 7 | contact "joe@acme.example.com"; 8 | description 9 | "The module for entities implementing the ACME system."; 10 | 11 | revision 2007-06-09 { 12 | description "Initial revision."; 13 | } 14 | 15 | container system { 16 | leaf host-name { 17 | type string; 18 | description "Hostname for this system"; 19 | } 20 | 21 | leaf-list domain-search { 22 | type string; 23 | description "List of domain names to search"; 24 | } 25 | 26 | container login { 27 | leaf message { 28 | type string; 29 | description 30 | "Message given at start of login session"; 31 | } 32 | 33 | list user { 34 | key "name"; 35 | leaf name { 36 | type string; 37 | } 38 | leaf full-name { 39 | type string; 40 | } 41 | leaf class { 42 | type string; 43 | } 44 | } 45 | } 46 | } 47 | 48 | list interface { 49 | key "name"; 50 | 51 | leaf name { 52 | type string; 53 | } 54 | leaf speed { 55 | type enumeration { 56 | enum 10m; 57 | enum 100m; 58 | enum auto; 59 | } 60 | } 61 | leaf observed-speed { 62 | type uint32; 63 | config false; 64 | } 65 | } 66 | 67 | typedef percent { 68 | type uint8 { 69 | range "0 .. 100"; 70 | } 71 | description "Percentage"; 72 | } 73 | 74 | leaf completed { 75 | type percent; 76 | } 77 | 78 | grouping target { 79 | leaf address { 80 | type inet:ip-address; 81 | description "Target IP address"; 82 | } 83 | leaf port { 84 | type inet:port-number; 85 | description "Target port number"; 86 | } 87 | } 88 | 89 | container peer { 90 | container destination { 91 | uses target; 92 | } 93 | } 94 | 95 | container connection { 96 | container source { 97 | uses target { 98 | refine "address" { 99 | description "Source IP address"; 100 | } 101 | refine "port" { 102 | description "Source port number"; 103 | } 104 | } 105 | } 106 | container destination { 107 | uses target { 108 | refine "address" { 109 | description "Destination IP address"; 110 | } 111 | refine "port" { 112 | description "Destination port number"; 113 | } 114 | } 115 | } 116 | } 117 | 118 | container food { 119 | choice snack { 120 | case sports-arena { 121 | leaf pretzel { 122 | type empty; 123 | } 124 | leaf beer { 125 | type empty; 126 | } 127 | } 128 | case late-night { 129 | leaf chocolate { 130 | type enumeration { 131 | enum dark; 132 | enum milk; 133 | enum first-available; 134 | } 135 | } 136 | } 137 | } 138 | } 139 | 140 | augment /system/login/user { 141 | when "class != 'wheel'"; 142 | leaf uid { 143 | type uint16 { 144 | range "1000 .. 30000"; 145 | } 146 | } 147 | } 148 | 149 | rpc activate-software-image { 150 | input { 151 | leaf image-name { 152 | type string; 153 | } 154 | } 155 | output { 156 | leaf status { 157 | type string; 158 | } 159 | } 160 | } 161 | 162 | notification link-failure { 163 | description "A link failure has been detected"; 164 | leaf if-name { 165 | type leafref { 166 | path "/interface/name"; 167 | } 168 | } 169 | leaf if-admin-status { 170 | type admin-status; 171 | } 172 | leaf if-oper-status { 173 | type oper-status; 174 | } 175 | } 176 | 177 | list server { 178 | key "name"; 179 | unique "ip port"; 180 | leaf name { 181 | type string; 182 | } 183 | leaf ip { 184 | type inet:ip-address; 185 | } 186 | leaf port { 187 | type inet:port-number; 188 | } 189 | } 190 | 191 | container transfer { 192 | choice how { 193 | default interval; 194 | case interval { 195 | leaf interval { 196 | type uint16; 197 | default 30; 198 | units minutes; 199 | } 200 | } 201 | case daily { 202 | leaf daily { 203 | type empty; 204 | } 205 | leaf time-of-day { 206 | type string; 207 | units 24-hour-clock; 208 | default 1am; 209 | } 210 | } 211 | case manual { 212 | leaf manual { 213 | type empty; 214 | } 215 | } 216 | } 217 | } 218 | 219 | container protocol { 220 | choice name { 221 | case a { 222 | leaf udp { 223 | type empty; 224 | } 225 | } 226 | case b { 227 | leaf tcp { 228 | type empty; 229 | } 230 | } 231 | } 232 | } 233 | 234 | feature local-storage { 235 | description 236 | "This feature means the device supports local 237 | storage (memory, flash or disk) that can be used to 238 | store syslog messages."; 239 | } 240 | 241 | container syslog { 242 | leaf local-storage-limit { 243 | if-feature local-storage; 244 | type uint64; 245 | units "kilobyte"; 246 | config false; 247 | description 248 | "The amount of local storage that can be 249 | used to hold syslog messages."; 250 | } 251 | } 252 | 253 | typedef my-decimal { 254 | type decimal64 { 255 | fraction-digits 2; 256 | range "1 .. 3.14 | 10 | 20..max"; 257 | } 258 | } 259 | 260 | leaf string-node { 261 | type string { 262 | length "0..4"; 263 | pattern "[0-9a-fA-F]*"; 264 | } 265 | } 266 | 267 | leaf myenum { 268 | type enumeration { 269 | enum zero; 270 | enum one; 271 | enum seven { 272 | value 7; 273 | } 274 | } 275 | } 276 | 277 | leaf mybits { 278 | type bits { 279 | bit disable-nagle { 280 | position 0; 281 | } 282 | bit auto-sense-speed { 283 | position 1; 284 | } 285 | bit 10-Mb-only { 286 | position 2; 287 | } 288 | } 289 | default "auto-sense-speed"; 290 | } 291 | 292 | list interface { 293 | key "name"; 294 | leaf name { 295 | type string; 296 | } 297 | leaf admin-status { 298 | type admin-status; 299 | } 300 | list address { 301 | key "ip"; 302 | leaf ip { 303 | type yang:ip-address; 304 | } 305 | } 306 | } 307 | 308 | container default-address { 309 | leaf ifname { 310 | type leafref { 311 | path "../../interface/name"; 312 | } 313 | } 314 | leaf address { 315 | type leafref { 316 | path ../../interface[name = current()/../ifname] 317 | /address/ip; 318 | } 319 | } 320 | } 321 | 322 | notification link-failure { 323 | leaf if-name { 324 | type leafref { 325 | path "/interface/name"; 326 | } 327 | } 328 | leaf admin-status { 329 | type leafref { 330 | path /interface[name = current()/../if-name]/admin-status; 331 | } 332 | } 333 | } 334 | 335 | leaf union-node { 336 | type union { 337 | type int32; 338 | type enumeration { 339 | enum "unbounded"; 340 | } 341 | } 342 | } 343 | } 344 | 345 | 346 | -------------------------------------------------------------------------------- /test/core/syslog-inc.yang: -------------------------------------------------------------------------------- 1 | submodule syslog-inc { 2 | /* 3 | * Copyright (c) 2003-2006, 2008, 2014 Juniper Networks, Inc. 4 | * All rights reserved. 5 | */ 6 | 7 | grouping facilties-choices-except-any { 8 | enum authorization { 9 | help "Authorization system"; 10 | option auth; 11 | } 12 | enum privileged { 13 | help "Privileged authorization events"; 14 | hidden guru; 15 | option authpriv; 16 | } 17 | enum cron { 18 | help "Cron daemon"; 19 | hidden internal; 20 | } 21 | enum daemon { 22 | help "Various system processes"; 23 | } 24 | enum ftp { 25 | help "FTP process"; 26 | } 27 | enum ntp { 28 | help "NTP process"; 29 | } 30 | enum security { 31 | help "Security related"; 32 | } 33 | enum kernel { 34 | help "Kernel"; 35 | option kern; 36 | } 37 | enum lpr { 38 | help "Line printer spooling system"; 39 | hidden guru; 40 | } 41 | enum mail { 42 | help "Mail system"; 43 | hidden guru; 44 | } 45 | enum news { 46 | help "Network news system"; 47 | hidden guru; 48 | } 49 | enum syslog { 50 | help "Internal use only"; 51 | hidden guru; 52 | } 53 | enum user { 54 | help "User processes"; 55 | } 56 | enum uucp { 57 | help "UUCP system"; 58 | hidden guru; 59 | } 60 | enum local0 { 61 | help "Local logging option number 0"; 62 | hidden guru; 63 | } 64 | enum dfc { 65 | help "Dynamic flow capture"; 66 | alias local1; 67 | option local1; 68 | } 69 | enum external { 70 | help "Local external applications"; 71 | alias local2; 72 | option "external"; 73 | } 74 | enum firewall { 75 | help "Firewall filtering system"; 76 | alias local3; 77 | option local3; 78 | } 79 | enum pfe { 80 | help "Packet Forwarding Engine"; 81 | alias local4; 82 | option local4; 83 | } 84 | enum conflict-log { 85 | help "Configuration conflict log"; 86 | alias local5; 87 | option local5; 88 | } 89 | enum change-log { 90 | help "Configuration change log"; 91 | alias local6; 92 | option local6; 93 | } 94 | enum interactive-commands { 95 | help "Commands executed by the UI"; 96 | option local7; 97 | } 98 | } 99 | 100 | grouping system-facility-attribute { 101 | key facility; 102 | leaf facility { 103 | help "Facility type"; 104 | type enumeration { 105 | enum "any" { 106 | help "All facilities"; 107 | option "*"; 108 | } 109 | use facilties-choices-except-any; 110 | } 111 | } 112 | } 113 | 114 | 115 | grouping services-facility-attribute { 116 | key facility; 117 | leaf facility { 118 | help "Facility type"; 119 | type enumeration { 120 | enum services { 121 | help "Adaptive Services PIC"; 122 | } 123 | } 124 | } 125 | } 126 | 127 | grouping level-attribute { 128 | key leve; 129 | leaf level { 130 | help "Level name"; 131 | type enumeration { 132 | enum "any" { 133 | help "All levels"; 134 | option "*"; 135 | } 136 | enum emergency { 137 | help "Panic conditions"; 138 | option "emerg"; 139 | } 140 | enum alert { 141 | help "Conditions that should be corrected immediately"; 142 | } 143 | enum critical { 144 | help "Critical conditions"; 145 | option "crit"; 146 | } 147 | enum error { 148 | help "Error conditions"; 149 | option "err"; 150 | } 151 | enum warning { 152 | help "Warning messages"; 153 | } 154 | enum notice { 155 | help "Conditions that should be handled specially"; 156 | } 157 | enum info { 158 | help "Informational messages"; 159 | } 160 | enum none { 161 | help "No messages"; 162 | } 163 | enum verbose { 164 | hidden guru; 165 | alias debug; 166 | help "Verbose messages"; 167 | option debug; 168 | } 169 | } 170 | } 171 | } 172 | 173 | grouping level-choices-except-any-none { 174 | enum emergency { 175 | help "Panic conditions"; 176 | option "emerg"; 177 | } 178 | enum alert { 179 | help "Conditions that should be corrected immediately"; 180 | } 181 | enum critical { 182 | help "Critical conditions"; 183 | option "crit"; 184 | } 185 | enum error { 186 | help "Error conditions"; 187 | option "err"; 188 | } 189 | enum warning { 190 | help "Warning messages"; 191 | } 192 | enum notice { 193 | help "Conditions that should be handled specially"; 194 | } 195 | enum info { 196 | help "Informational messages"; 197 | } 198 | enum verbose { 199 | hidden guru; 200 | alias debug; 201 | help "Verbose messages"; 202 | option debug; 203 | } 204 | } 205 | 206 | grouping facility-override-attribute { 207 | leaf facility-override { 208 | help "Alternate facility for logging to remote host"; 209 | type enumeration { 210 | enum authorization { 211 | help "Authorization system"; 212 | option auth; 213 | } 214 | enum privileged { 215 | help "Privileged authorization events"; 216 | hidden guru; 217 | option authpriv; 218 | } 219 | enum cron { 220 | help "Cron daemon"; 221 | hidden internal; 222 | } 223 | enum daemon { 224 | help "Various system processes"; 225 | } 226 | enum ftp { 227 | help "FTP process"; 228 | } 229 | enum kernel { 230 | help "Kernel"; 231 | option kern; 232 | } 233 | enum lpr { 234 | help "Line printer spooling system"; 235 | hidden guru; 236 | } 237 | enum mail { 238 | hidden guru; 239 | help "Mail system"; 240 | } 241 | enum news { 242 | help "Network news system"; 243 | hidden guru; 244 | } 245 | enum syslog { 246 | help "Internal use only"; 247 | hidden guru; 248 | } 249 | enum user { 250 | help "User processes"; 251 | } 252 | enum uucp { 253 | help "Uucp system"; 254 | hidden guru; 255 | } 256 | enum local0 { 257 | help "Local logging option number 0"; 258 | } 259 | enum local1 { 260 | help "Local logging option number 1"; 261 | } 262 | enum local2 { 263 | help "Local logging option number 2"; 264 | } 265 | enum local3 { 266 | help "Local logging option number 3"; 267 | } 268 | enum local4 { 269 | help "Local logging option number 4"; 270 | } 271 | enum local5 { 272 | help "Local logging option number 5"; 273 | } 274 | enum local6 { 275 | help "Local logging option number 6"; 276 | } 277 | enum local7 { 278 | help "Local logging option number 7"; 279 | } 280 | } 281 | } 282 | } 283 | 284 | grouping structured-format { 285 | container structured-data { 286 | help "Log system message in structured format"; 287 | flag allow-struct; 288 | 289 | leaf format { 290 | flag nokeyword; 291 | cname sd_format; 292 | 293 | type enumeration { 294 | enum brief { 295 | help "Omit English-language text from end of " 296 | "logged message"; 297 | value 1; 298 | } 299 | 300 | enum detail { 301 | help "Include English-language text at end of " 302 | "logged message"; 303 | value 2; 304 | hidden default; 305 | } 306 | } 307 | default detail; 308 | } 309 | } 310 | } 311 | } 312 | -------------------------------------------------------------------------------- /libyang/yangconfig.h.in: -------------------------------------------------------------------------------- 1 | /* libyang/yangconfig.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP 4 | systems. This function is required for `alloca.c' support on those systems. 5 | */ 6 | #undef CRAY_STACKSEG_END 7 | 8 | /* Define to 1 if using `alloca.c'. */ 9 | #undef C_ALLOCA 10 | 11 | /* Define to 1 if you have `alloca', as a function or macro. */ 12 | #undef HAVE_ALLOCA 13 | 14 | /* Define to 1 if you have and it should be used (not on Ultrix). 15 | */ 16 | #undef HAVE_ALLOCA_H 17 | 18 | /* Bison version >= 3.0 */ 19 | #undef HAVE_BISON30 20 | 21 | /* Define to 1 if you have the `bzero' function. */ 22 | #undef HAVE_BZERO 23 | 24 | /* Define to 1 if you have the `ctime' function. */ 25 | #undef HAVE_CTIME 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #undef HAVE_CTYPE_H 29 | 30 | /* Define to 1 if you have the header file. */ 31 | #undef HAVE_DLFCN_H 32 | 33 | /* Define to 1 if you have the header file. */ 34 | #undef HAVE_ERRNO_H 35 | 36 | /* Define to 1 if you have the `fdopen' function. */ 37 | #undef HAVE_FDOPEN 38 | 39 | /* Define to 1 if you have the `flock' function. */ 40 | #undef HAVE_FLOCK 41 | 42 | /* Define to 1 if you have the `getpass' function. */ 43 | #undef HAVE_GETPASS 44 | 45 | /* Define to 1 if you have the `getrusage' function. */ 46 | #undef HAVE_GETRUSAGE 47 | 48 | /* Define to 1 if you have the `gettimeofday' function. */ 49 | #undef HAVE_GETTIMEOFDAY 50 | 51 | /* Define to 1 if you have the header file. */ 52 | #undef HAVE_INTTYPES_H 53 | 54 | /* Define to 1 if you have the `crypto' library (-lcrypto). */ 55 | #undef HAVE_LIBCRYPTO 56 | 57 | /* Support libedit */ 58 | #undef HAVE_LIBEDIT 59 | 60 | /* Define to 1 if you have the `m' library (-lm). */ 61 | #undef HAVE_LIBM 62 | 63 | /* Define to 1 if you have the `readline' library (-lreadline). */ 64 | #undef HAVE_LIBREADLINE 65 | 66 | /* Define to 1 if you have the `xml2' library (-lxml2). */ 67 | #undef HAVE_LIBXML2 68 | 69 | /* Define to 1 if you have the `xslt' library (-lxslt). */ 70 | #undef HAVE_LIBXSLT 71 | 72 | /* Define to 1 if your system has a GNU libc compatible `malloc' function, and 73 | to 0 otherwise. */ 74 | #undef HAVE_MALLOC 75 | 76 | /* Define to 1 if you have the `memmove' function. */ 77 | #undef HAVE_MEMMOVE 78 | 79 | /* Define to 1 if you have the header file. */ 80 | #undef HAVE_MEMORY_H 81 | 82 | /* Define to 1 if you have the `st_mtimespec' field. */ 83 | #undef HAVE_MTIMESPEC 84 | 85 | /* Enable use of GCC __printflike */ 86 | #undef HAVE_PRINTFLIKE 87 | 88 | /* Have struct pwd.pw_class */ 89 | #undef HAVE_PWD_CLASS 90 | 91 | /* Enable support for GNU readline */ 92 | #undef HAVE_READLINE 93 | 94 | /* Define to 1 if your system has a GNU libc compatible `realloc' function, 95 | and to 0 otherwise. */ 96 | #undef HAVE_REALLOC 97 | 98 | /* Define to 1 if the system has the type `socklen_t'. */ 99 | #undef HAVE_SOCKLEN_T 100 | 101 | /* Define to 1 if you have the `srand' function. */ 102 | #undef HAVE_SRAND 103 | 104 | /* Define to 1 if you have the `sranddev' function. */ 105 | #undef HAVE_SRANDDEV 106 | 107 | /* Define to 1 if you have the `statfs' function. */ 108 | #undef HAVE_STATFS 109 | 110 | /* Define to 1 if you have the header file. */ 111 | #undef HAVE_STDINT_H 112 | 113 | /* Define to 1 if you have the header file. */ 114 | #undef HAVE_STDIO_H 115 | 116 | /* Define to 1 if you have the header file. */ 117 | #undef HAVE_STDLIB_H 118 | 119 | /* Define to 1 if you have the `strchr' function. */ 120 | #undef HAVE_STRCHR 121 | 122 | /* Define to 1 if you have the `strcspn' function. */ 123 | #undef HAVE_STRCSPN 124 | 125 | /* Define to 1 if you have the `strerror' function. */ 126 | #undef HAVE_STRERROR 127 | 128 | /* Define to 1 if you have the header file. */ 129 | #undef HAVE_STRINGS_H 130 | 131 | /* Define to 1 if you have the header file. */ 132 | #undef HAVE_STRING_H 133 | 134 | /* Define to 1 if you have the `strlcpy' function. */ 135 | #undef HAVE_STRLCPY 136 | 137 | /* Define to 1 if you have the `strndup' function. */ 138 | #undef HAVE_STRNDUP 139 | 140 | /* Define to 1 if you have the `strnstr' function. */ 141 | #undef HAVE_STRNSTR 142 | 143 | /* Define to 1 if you have the `strspn' function. */ 144 | #undef HAVE_STRSPN 145 | 146 | /* Have struct sockaddr_un.sun_len */ 147 | #undef HAVE_SUN_LEN 148 | 149 | /* Define to 1 if you have the `sysctlbyname' function. */ 150 | #undef HAVE_SYSCTLBYNAME 151 | 152 | /* Define to 1 if you have the header file. */ 153 | #undef HAVE_SYS_PARAM_H 154 | 155 | /* Define to 1 if you have the header file. */ 156 | #undef HAVE_SYS_STATFS_H 157 | 158 | /* Define to 1 if you have the header file. */ 159 | #undef HAVE_SYS_STAT_H 160 | 161 | /* Define to 1 if you have the header file. */ 162 | #undef HAVE_SYS_SYSCTL_H 163 | 164 | /* Define to 1 if you have the header file. */ 165 | #undef HAVE_SYS_TIME_H 166 | 167 | /* Define to 1 if you have the header file. */ 168 | #undef HAVE_SYS_TYPES_H 169 | 170 | /* Define to 1 if you have the header file. */ 171 | #undef HAVE_UNISTD_H 172 | 173 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 174 | */ 175 | #undef LT_OBJDIR 176 | 177 | /* Name of package */ 178 | #undef PACKAGE 179 | 180 | /* Define to the address where bug reports for this package should be sent. */ 181 | #undef PACKAGE_BUGREPORT 182 | 183 | /* Define to the full name of this package. */ 184 | #undef PACKAGE_NAME 185 | 186 | /* Define to the full name and version of this package. */ 187 | #undef PACKAGE_STRING 188 | 189 | /* Define to the one symbol short name of this package. */ 190 | #undef PACKAGE_TARNAME 191 | 192 | /* Define to the home page for this package. */ 193 | #undef PACKAGE_URL 194 | 195 | /* Define to the version of this package. */ 196 | #undef PACKAGE_VERSION 197 | 198 | /* Path to yangc binary */ 199 | #undef PATH_YANGC 200 | 201 | /* If using the C implementation of alloca, define if you know the 202 | direction of stack growth for your system; otherwise it will be 203 | automatically deduced at runtime. 204 | STACK_DIRECTION > 0 => grows toward higher addresses 205 | STACK_DIRECTION < 0 => grows toward lower addresses 206 | STACK_DIRECTION = 0 => direction of growth unknown */ 207 | #undef STACK_DIRECTION 208 | 209 | /* Define to 1 if you have the ANSI C header files. */ 210 | #undef STDC_HEADERS 211 | 212 | /* Version number of package */ 213 | #undef VERSION 214 | 215 | /* Enable debugging */ 216 | #undef YANGC_DEBUG 217 | 218 | /* Directory for YANGC shared files */ 219 | #undef YANGC_DIR 220 | 221 | /* Version number as dotted value */ 222 | #undef YANGC_VERSION 223 | 224 | /* Version number extra information */ 225 | #undef YANGC_VERSION_EXTRA 226 | 227 | /* Version number as a number */ 228 | #undef YANGC_VERSION_NUMBER 229 | 230 | /* Version number as string */ 231 | #undef YANGC_VERSION_STRING 232 | 233 | /* Define to `__inline__' or `__inline' if that's what the C compiler 234 | calls it, or to nothing if 'inline' is not supported under any name. */ 235 | #ifndef __cplusplus 236 | #undef inline 237 | #endif 238 | 239 | /* Define to rpl_malloc if the replacement function should be used. */ 240 | #undef malloc 241 | 242 | /* Define to rpl_realloc if the replacement function should be used. */ 243 | #undef realloc 244 | 245 | /* Define to `unsigned int' if does not define. */ 246 | #undef size_t 247 | -------------------------------------------------------------------------------- /test/core/trace-inc.yang: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1998-2008,2014, Juniper Networks, Inc. 3 | * All rights reserved. 4 | */ 5 | 6 | submodule trace-inc { 7 | template common-traceflags { 8 | enum route { 9 | help "Trace routing information"; 10 | } 11 | enum normal { 12 | help "Trace normal events"; 13 | } 14 | enum general { 15 | help "Trace general events"; 16 | } 17 | enum state { 18 | help "Trace state transitions"; 19 | } 20 | enum policy { 21 | help "Trace policy processing"; 22 | } 23 | enum task { 24 | help "Trace routing protocol task processing"; 25 | } 26 | enum timer { 27 | help "Trace routing protocol timer processing"; 28 | } 29 | enum "all" { 30 | help "Trace everything"; 31 | } 32 | } 33 | 34 | grouping sendrcv-trace-flags { 35 | leaf send { 36 | help "Trace transmitted packets"; 37 | type empty; 38 | } 39 | leaf send-detail { 40 | help "Trace transmitted packets in detail"; 41 | type empty; 42 | } 43 | leaf receive { 44 | help "Trace received packets"; 45 | type empty; 46 | } 47 | leaf receive-detail { 48 | help "Trace received packets in detail"; 49 | type empty; 50 | } 51 | } 52 | 53 | grouping traceattr-file { 54 | leaf "file" { 55 | help "Trace file options"; 56 | alias tracefile; 57 | flag remove-empty; 58 | type trace_file_type; 59 | } 60 | } 61 | 62 | grouping traceattr-esp-file { 63 | container "file" { 64 | help "Trace file options"; 65 | alias tracefile; 66 | flag remove-empty; 67 | uses esp_trace_file_type; 68 | } 69 | } 70 | 71 | grouping tracefile-leaf { 72 | flag remove-empty; 73 | use traceattr-file; 74 | } 75 | 76 | grouping tracefile-leaf-esp { 77 | flag remove-empty; 78 | use traceattr-esp-file; 79 | } 80 | 81 | template traceflag-options-mode ($hide) { 82 | leaf send { 83 | if ($hide) { 84 | hidden $hide; 85 | } 86 | help "Trace transmitted packets"; 87 | type empty; 88 | } 89 | leaf receive { 90 | if ($hide) { 91 | hidden $hide; 92 | } 93 | help "Trace received packets"; 94 | type empty; 95 | } 96 | leaf detail { 97 | if ($hide) { 98 | hidden $hide; 99 | } 100 | help "Trace detailed information"; 101 | type empty; 102 | } 103 | leaf disable { 104 | if ($hide) { 105 | hidden $hide; 106 | } 107 | help "Disable this trace flag"; 108 | type empty; 109 | } 110 | } 111 | 112 | grouping traceflag-options { 113 | call traceflag-options-mode(); 114 | } 115 | grouping traceflag-options-depr { 116 | call traceflag-options-mode($hide = "deprecated"); 117 | } 118 | 119 | grouping tracefilter-name-leaf { 120 | key name; 121 | leaf name { 122 | help "Filter name"; 123 | type string; 124 | match "^.{1,32}$"; 125 | match-message "Must be a string of 32 characters or less"; 126 | } 127 | } 128 | 129 | grouping tracefilter-policy-leaf { 130 | leaf-list policy { 131 | help "Filter policy"; 132 | mandatory true; 133 | type policy-algebra; 134 | } 135 | } 136 | 137 | template common-match-on-types { 138 | enum prefix { 139 | help "Filter based on prefix"; 140 | } 141 | enum route-leaf { 142 | help "Filter based on route leafs"; 143 | } 144 | enum update-source { 145 | help "Filter based on source of incoming updates"; 146 | } 147 | } 148 | 149 | grouping tracefilter-header { 150 | flag oneliner; 151 | help "Filter to apply to tracing"; 152 | } 153 | 154 | grouping tracefilter-matchon-attr { 155 | leaf "match-on" { 156 | help "Argument on which to match"; 157 | mandatory true; 158 | type enum uint { 159 | /* augmented later */ 160 | } 161 | } 162 | } 163 | 164 | /* 165 | * Common traceoptions objects 166 | */ 167 | template traceoptions-file-common { 168 | call traceoptions-file-common-with-args(10k, 1g, 128k, 2, 1000, 3); 169 | } 170 | 171 | grouping traceoptions-file-without-match { 172 | use remote-trace-options; 173 | container "file" { 174 | uses traceoptions-file-common; 175 | } 176 | } 177 | 178 | /* 179 | * Common traceoptions objects 180 | */ 181 | grouping traceoptions-file { 182 | use remote-trace-options; 183 | container "file" { 184 | uses traceoptions-file-common; 185 | leaf "match" { 186 | help "Regular expression for lines to be logged"; 187 | type regular-expression; 188 | } 189 | } 190 | } 191 | 192 | grouping traceoptions-file-without-remote-trace { 193 | container "file" { 194 | uses traceoptions-file-common; 195 | leaf "match" { 196 | help "Regular expression for lines to be logged"; 197 | type regular-expression; 198 | } 199 | } 200 | } 201 | 202 | grouping syslog-leaf { 203 | leaf syslog { 204 | help "Trace messages also go to syslog at 'info' level"; 205 | hidden support; 206 | type empty; 207 | } 208 | } 209 | 210 | template traceoptions-level-leaf-base ($hide) { 211 | leaf level { 212 | alias tracelevel; 213 | help "Level of debugging output"; 214 | if ($hide) { 215 | hidden $hide; 216 | } 217 | 218 | type enum uint { 219 | enum error { 220 | help "Match error conditions"; 221 | define TRACE_LEVEL_ERR; 222 | } 223 | enum warning { 224 | help "Match warning messages"; 225 | define TRACE_LEVEL_WARN; 226 | } 227 | enum notice { 228 | help "Match conditions that should be handled specially"; 229 | define TRACE_LEVEL_NOTICE; 230 | } 231 | enum info { 232 | help "Match informational messages"; 233 | define TRACE_LEVEL_INFO; 234 | } 235 | enum verbose { 236 | help "Match verbose messages"; 237 | define TRACE_LEVEL_VERBOSE; 238 | } 239 | enum "all" { 240 | help "Match all levels"; 241 | define TRACE_LEVEL_ALL; 242 | } 243 | } 244 | } 245 | } 246 | 247 | template traceoptions-level-leaf-with-default ($hide, $default) { 248 | call traceoptions-level-leaf-base($hide); 249 | leaf level { 250 | if ($default) { 251 | default $default; 252 | } 253 | } 254 | } 255 | 256 | /* 257 | * Many existing TRACEOPTIONS_LEVEL_LEAF references are at error level. 258 | * Keep it to reduce code changes. 259 | */ 260 | template traceoptions-level-leaf ($hide) { 261 | call traceoptions-level-leaf-with-default($hide, $default = "error"); 262 | } 263 | 264 | template traceoptions-control-flag ($hide) { 265 | list "control-flag" { 266 | help "Tracing control flags"; 267 | flag oneliner; 268 | 269 | if ($hide) { 270 | hidden $hide; 271 | } 272 | 273 | key control_flag_name; 274 | leaf control_flag_name { 275 | type enum uint { 276 | enum backtrace { 277 | help "Allow stack backtrace"; 278 | } 279 | enum code-flow { 280 | help "Allow code-flow tracing"; 281 | } 282 | } 283 | } 284 | } 285 | } 286 | 287 | /* 288 | * Common traceoptions objects with args. 289 | * Daemon which want to use their own value for files_min, files_max 290 | * size_min, size_max and their corresponding default value 291 | * should use this macro 292 | */ 293 | template traceoptions-file-with-args ($size-min, $size-max, $size-def, 294 | $files-min, $files-max, $files-def) { 295 | use remote-trace-options; 296 | container "file" { 297 | call traceoptions-file-common-with-args($size-min, $size-max, 298 | $size-def, $files-min, $files-max, $files-def); 299 | leaf "match" { 300 | help "Regular expression for lines to be logged"; 301 | type regular-expression; 302 | } 303 | } 304 | } 305 | 306 | /* 307 | * Common traceoptions objects with arguments 308 | */ 309 | template traceoptions-file-common-with-args ($size-min, $size-max, 310 | $size-def, $files-min, $files-max, $files-def) { 311 | help "Trace file information"; 312 | flag oneliner remove-empty; 313 | 314 | leaf filename { 315 | help "Name of file in which to write trace information"; 316 | flag nokeyword; 317 | type string { 318 | range 1 .. DDL_MAXPATHLEN; 319 | } 320 | uses filename-check; 321 | } 322 | leaf size { 323 | help "Maximum trace file size"; 324 | flag kilo; 325 | type uint { 326 | range size_min .. size_max; 327 | } 328 | default size_def; 329 | } 330 | leaf files { 331 | help "Maximum number of trace files"; 332 | alias "count"; 333 | type uint { 334 | range files_min .. files_max; 335 | } 336 | default files_def; 337 | } 338 | leaf world-readable { 339 | help "Allow any user to read the log file"; 340 | type empty; 341 | flag allow-no; 342 | } 343 | } 344 | 345 | /* 346 | * Include this macro under "object traceoptions" along with 347 | * TRACEOPTIONS_FILE_* macro, to get the leaf under 348 | * [edit ... traceoptions file]. 349 | */ 350 | template traceoptions-file-microseconds ($hide) { 351 | use remote-trace-options; 352 | container "file" { 353 | leaf microsecond-stamp { 354 | help "Timestamp with microsecond granularity"; 355 | type empty; 356 | if ($hide) { 357 | hidden $hide; 358 | } 359 | } 360 | } 361 | } 362 | 363 | grouping remote-trace-options { 364 | leaf no-remote-trace { 365 | help "Disable remote tracing"; 366 | jmust "system tracing" { 367 | message "'no-remote-trace' is valid only " 368 | "when [system tracing] is configured"; 369 | } 370 | type empty; 371 | } 372 | } 373 | } 374 | -------------------------------------------------------------------------------- /yangc/yangc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Juniper Networks, Inc. 3 | * All rights reserved. 4 | * This SOFTWARE is licensed under the LICENSE provided in the 5 | * ../Copyright file. By downloading, installing, copying, or otherwise 6 | * using the SOFTWARE, you agree to be bound by the terms of that 7 | * LICENSE. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include "yanginternals.h" 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | static slax_data_list_t plist; 46 | static int nbparams; 47 | static slax_data_list_t param_files; 48 | 49 | static int options = XSLT_PARSE_OPTIONS; 50 | 51 | static char *encoding; /* Desired document encoding */ 52 | 53 | static int opt_indent = TRUE; /* Indent the output (pretty print) */ 54 | static int opt_partial; /* Parse partial contents */ 55 | static int opt_debugger; /* Invoke the debugger */ 56 | 57 | /* 58 | * Shamelessly lifted from slaxproc.c 59 | */ 60 | static const char * 61 | get_filename (const char *filename, char ***pargv, int outp) 62 | { 63 | if (filename == NULL) { 64 | filename = **pargv; 65 | if (filename) 66 | *pargv += 1; 67 | else filename = "-"; 68 | } 69 | 70 | if (outp >= 0 && slaxFilenameIsStd(filename)) 71 | filename = outp ? "/dev/stdout" : "/dev/stdin"; 72 | return filename; 73 | } 74 | 75 | static void 76 | mergeParamFile (xmlDocPtr docp UNUSED, xmlDocPtr sourcedoc UNUSED) 77 | { 78 | slaxLog("handleParams: %p %p", docp, sourcedoc); 79 | 80 | xmlNodePtr insp = sourcedoc->children->children; 81 | xmlNodePtr nodep, newp; 82 | 83 | for (nodep = docp->children->children; nodep; nodep = nodep->next) { 84 | newp = xmlDocCopyNode(nodep, sourcedoc, 1); 85 | xmlAddPrevSibling(insp, newp); 86 | } 87 | } 88 | 89 | static int 90 | do_eval (xmlDocPtr sourcedoc, const char *sourcename, const char *input) 91 | { 92 | xmlDocPtr indoc; 93 | xmlDocPtr res = NULL; 94 | xsltStylesheetPtr source; 95 | const char **params = alloca(nbparams * 2 * sizeof(*params) + 1); 96 | slax_data_node_t *dnp; 97 | int i = 0; 98 | 99 | SLAXDATALIST_FOREACH(dnp, &plist) { 100 | params[i++] = dnp->dn_data; 101 | } 102 | 103 | params[i] = NULL; 104 | 105 | source = xsltParseStylesheetDoc(sourcedoc); 106 | if (source == NULL || source->errors != 0) 107 | errx(1, "%d errors parsing source: '%s'", 108 | source ? source->errors : 1, sourcename); 109 | 110 | SLAXDATALIST_FOREACH(dnp, ¶m_files) { 111 | const char *name = dnp->dn_data; 112 | FILE *fp = fopen(name, "r"); 113 | if (fp == NULL) 114 | err(1, "cannot open parameter file '%s'", name); 115 | 116 | xmlDocPtr docp = yangLoadParams(name, fp, NULL); 117 | if (docp) { 118 | mergeParamFile(docp, sourcedoc); 119 | xmlFreeDoc(docp); 120 | } 121 | 122 | fclose(fp); 123 | } 124 | 125 | if (input) 126 | indoc = xmlReadFile(input, encoding, options); 127 | else 128 | indoc = yangFeaturesBuildInputDoc(); 129 | 130 | if (indoc == NULL) 131 | errx(1, "unable to parse: '%s'", input); 132 | 133 | if (opt_indent) 134 | source->indent = 1; 135 | 136 | if (opt_debugger) { 137 | slaxDebugInit(); 138 | slaxDebugSetStylesheet(source); 139 | res = slaxDebugApplyStylesheet(sourcename, source, 140 | slaxFilenameIsStd(input) ? NULL : input, 141 | indoc, params); 142 | } else { 143 | res = xsltApplyStylesheet(source, indoc, params); 144 | } 145 | 146 | if (res) { 147 | FILE *outfile = stdout; 148 | 149 | xsltSaveResultToFile(outfile, res, source); 150 | yangWriteDoc((slaxWriterFunc_t) fprintf, outfile, res, 0); 151 | 152 | xmlFreeDoc(res); 153 | } 154 | 155 | xmlFreeDoc(indoc); 156 | xsltFreeStylesheet(source); 157 | 158 | return 0; 159 | } 160 | 161 | static int 162 | do_post (const char *name, const char *output UNUSED, 163 | const char *input, char **argv) 164 | { 165 | name = get_filename(name, &argv, -1); 166 | 167 | xmlDocPtr docp = xmlReadFile(name, NULL, XSLT_PARSE_OPTIONS); 168 | if (docp == NULL) { 169 | errx(1, "cannot parse file: '%s'", name); 170 | return -1; 171 | } 172 | 173 | return do_eval(docp, name, input); 174 | } 175 | 176 | static int 177 | do_work (const char *name, const char *output, const char *input, 178 | char **argv, int full_eval) 179 | { 180 | xmlDocPtr sourcedoc; 181 | const char *sourcename; 182 | FILE *sourcefile, *outfile; 183 | char buf[BUFSIZ]; 184 | 185 | sourcename = get_filename(name, &argv, -1); 186 | output = get_filename(output, &argv, -1); 187 | 188 | if (slaxFilenameIsStd(sourcename)) 189 | errx(1, "source file cannot be stdin"); 190 | 191 | sourcefile = slaxFindIncludeFile(sourcename, buf, sizeof(buf)); 192 | if (sourcefile == NULL) 193 | err(1, "file open failed for '%s'", sourcename); 194 | 195 | sourcedoc = yangLoadFile(NULL, sourcename, sourcefile, NULL, 0); 196 | if (sourcedoc == NULL) 197 | errx(1, "cannot parse: '%s'", sourcename); 198 | if (sourcefile != stdin) 199 | fclose(sourcefile); 200 | 201 | if (output == NULL || slaxFilenameIsStd(output)) 202 | outfile = stdout; 203 | else { 204 | outfile = fopen(output, "w"); 205 | if (outfile == NULL) 206 | err(1, "could not open output file: '%s'", output); 207 | } 208 | 209 | if (full_eval) { 210 | return do_eval(sourcedoc, sourcename, input); 211 | } else { 212 | slaxDumpToFd(fileno(outfile), sourcedoc, FALSE); 213 | } 214 | 215 | return 0; 216 | } 217 | 218 | static int 219 | do_compile (const char *name, const char *output, 220 | const char *input, char **argv) 221 | { 222 | return do_work(name, output, input, argv, FALSE); 223 | } 224 | 225 | static int 226 | do_evaluate (const char *name, const char *output, 227 | const char *input, char **argv) 228 | { 229 | return do_work(name, output, input, argv, TRUE); 230 | } 231 | 232 | static void 233 | print_version (void) 234 | { 235 | printf("libyang version %s%s\n", YANGC_VERSION, YANGC_VERSION_EXTRA); 236 | printf("libslax version %s%s\n", LIBSLAX_VERSION, LIBSLAX_VERSION_EXTRA); 237 | printf("Using libxml %s, libxslt %s and libexslt %s\n", 238 | xmlParserVersion, xsltEngineVersion, exsltLibraryVersion); 239 | printf("yangc was compiled against libxml %d%s, " 240 | "libxslt %d%s and libexslt %d\n", 241 | LIBXML_VERSION, LIBXML_VERSION_EXTRA, 242 | LIBXSLT_VERSION, LIBXSLT_VERSION_EXTRA, LIBEXSLT_VERSION); 243 | printf("libxslt %d was compiled against libxml %d\n", 244 | xsltLibxsltVersion, xsltLibxmlVersion); 245 | printf("libexslt %d was compiled against libxml %d\n", 246 | exsltLibexsltVersion, exsltLibxmlVersion); 247 | } 248 | 249 | static void 250 | print_help (void) 251 | { 252 | fprintf(stderr, "Usage: yangc [options] [files]\n\n"); 253 | } 254 | 255 | int 256 | main (int argc UNUSED, char **argv) 257 | { 258 | char *cp; 259 | const char *input = NULL, *output = NULL, *name = NULL, *trace_file = NULL; 260 | int (*func)(const char *, const char *, const char *, char **) = NULL; 261 | FILE *trace_fp = NULL; 262 | int randomize = 1; 263 | int logger = FALSE; 264 | int use_exslt = TRUE; 265 | char *opt_log_file = NULL; 266 | 267 | setenv("MallocScribble", "true", 1); 268 | 269 | slaxDataListInit(&plist); 270 | slaxDataListInit(¶m_files); 271 | 272 | for (argv++; *argv; argv++) { 273 | cp = *argv; 274 | 275 | if (*cp != '-') 276 | break; 277 | 278 | if (streq(cp, "--compile") || streq(cp, "-c")) { 279 | if (func) 280 | errx(1, "open one action allowed"); 281 | func = do_compile; 282 | 283 | } else if (streq(cp, "--debug") || streq(cp, "-d")) { 284 | opt_debugger = TRUE; 285 | 286 | } else if (streq(cp, "--evaluate") || streq(cp, "-e")) { 287 | func = do_evaluate; 288 | 289 | } else if (streq(cp, "--feature") || streq(cp, "-f")) { 290 | yangFeatureAdd(*++argv); 291 | 292 | } else if (streq(cp, "--help") || streq(cp, "-h")) { 293 | print_help(); 294 | return -1; 295 | 296 | } else if (streq(cp, "--include") || streq(cp, "-I")) { 297 | slaxIncludeAdd(*++argv); 298 | 299 | } else if (streq(cp, "--input") || streq(cp, "-i")) { 300 | input = *++argv; 301 | 302 | } else if (streq(cp, "--log") || streq(cp, "-l")) { 303 | opt_log_file = *++argv; 304 | 305 | } else if (streq(cp, "--name") || streq(cp, "-n")) { 306 | name = *++argv; 307 | 308 | } else if (streq(cp, "--no-randomize")) { 309 | randomize = 0; 310 | 311 | } else if (streq(cp, "--output") || streq(cp, "-o")) { 312 | output = *++argv; 313 | 314 | } else if (streq(cp, "--param") || streq(cp, "-a")) { 315 | char *pname = *++argv; 316 | char *pvalue = *++argv; 317 | char *tvalue; 318 | char quote; 319 | int plen; 320 | 321 | if (pname == NULL || pvalue == NULL) 322 | errx(1, "missing parameter value"); 323 | 324 | plen = strlen(pvalue); 325 | tvalue = xmlMalloc(plen + 3); 326 | if (tvalue == NULL) 327 | errx(1, "out of memory"); 328 | 329 | quote = strrchr(pvalue, '\"') ? '\'' : '\"'; 330 | tvalue[0] = quote; 331 | memcpy(tvalue + 1, pvalue, plen); 332 | tvalue[plen + 1] = quote; 333 | tvalue[plen + 2] = '\0'; 334 | 335 | nbparams += 1; 336 | slaxDataListAddNul(&plist, pname); 337 | slaxDataListAddNul(&plist, tvalue); 338 | 339 | } else if (streq(cp, "--partial")) { 340 | opt_partial = TRUE; 341 | 342 | } else if (streq(cp, "--param-file") || streq(cp, "-P")) { 343 | slaxDataListAddNul(¶m_files, *++argv); 344 | 345 | } else if (streq(cp, "--post") || streq(cp, "-p")) { 346 | func = do_post; 347 | 348 | } else if (streq(cp, "--trace") || streq(cp, "-t")) { 349 | trace_file = *++argv; 350 | 351 | } else if (streq(cp, "--verbose") || streq(cp, "-v")) { 352 | logger = TRUE; 353 | 354 | } else if (streq(cp, "--version") || streq(cp, "-V")) { 355 | print_version(); 356 | exit(0); 357 | 358 | } else if (streq(cp, "--yydebug") || streq(cp, "-y")) { 359 | yangYyDebug = TRUE; 360 | 361 | } else { 362 | fprintf(stderr, "invalid option: %s\n", cp); 363 | print_help(); 364 | return -1; 365 | } 366 | } 367 | 368 | cp = getenv("SLAXPATH"); 369 | if (cp) 370 | slaxIncludeAddPath(cp); 371 | 372 | /* 373 | * Seed the random number generator. This is optional to allow 374 | * test jigs to take advantage of the default stream of generated 375 | * numbers. 376 | */ 377 | if (randomize) 378 | slaxInitRandomizer(); 379 | 380 | /* 381 | * Start the XML API 382 | */ 383 | xmlInitParser(); 384 | xsltInit(); 385 | slaxEnable(SLAX_ENABLE); 386 | slaxIoUseStdio(0); 387 | yangStmtInit(); 388 | 389 | if (opt_log_file) { 390 | FILE *fp = fopen(opt_log_file, "w"); 391 | if (fp == NULL) 392 | err(1, "could not open log file: '%s'", opt_log_file); 393 | 394 | slaxLogEnable(TRUE); 395 | slaxLogToFile(fp); 396 | 397 | } else if (logger) { 398 | slaxLogEnable(TRUE); 399 | } 400 | 401 | if (use_exslt) 402 | exsltRegisterAll(); 403 | 404 | if (trace_file) { 405 | if (slaxFilenameIsStd(trace_file)) 406 | trace_fp = stderr; 407 | else { 408 | trace_fp = fopen(trace_file, "w"); 409 | if (trace_fp == NULL) 410 | err(1, "could not open trace file: '%s'", trace_file); 411 | } 412 | slaxTraceToFile(trace_fp); 413 | } 414 | 415 | if (func == NULL) 416 | func = do_compile; 417 | 418 | func(name, output, input, argv); 419 | 420 | if (trace_fp && trace_fp != stderr) 421 | fclose(trace_fp); 422 | 423 | slaxDynClean(); 424 | xsltCleanupGlobals(); 425 | xmlCleanupParser(); 426 | 427 | exit(slaxGetExitCode()); 428 | } 429 | -------------------------------------------------------------------------------- /libyang/yangstmt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Juniper Networks, Inc. 3 | * All rights reserved. 4 | * See ../Copyright for the status of this software 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include "yanginternals.h" 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | static yang_stmt_list_t yangStmtList; 26 | 27 | 28 | static void 29 | yangStmtRebuildParents (yang_stmt_t *ysp, yang_relative_t *yrp) 30 | { 31 | yang_stmt_t *parent = yangStmtFind(yrp->yr_namespace, yrp->yr_name); 32 | yang_relative_t *tmp; 33 | int count = 0; 34 | 35 | if (parent == NULL) { 36 | slaxLog("could not add statement: not found '%s:%s'", 37 | yrp->yr_namespace ?: "", yrp->yr_name); 38 | return; 39 | } 40 | 41 | for (tmp = parent->ys_children; tmp && tmp->yr_name; tmp++) 42 | count += 1; 43 | 44 | yang_relative_t *newp = xmlMalloc((count + 2) * sizeof(*newp)); 45 | if (newp == NULL) { 46 | slaxLog("out of memory for '%s'", ysp->ys_name); 47 | return; 48 | } 49 | 50 | memcpy(newp, parent->ys_children, count * sizeof(*newp)); 51 | tmp = newp + count; 52 | tmp->yr_name = ysp->ys_name; 53 | tmp->yr_namespace = ysp->ys_namespace; 54 | tmp->yr_flags = yrp->yr_flags; 55 | bzero(tmp + 1, sizeof(*newp)); 56 | 57 | if (parent->ys_flags & YSF_CHILDREN_ALLOCED) 58 | xmlFreeAndEasy(parent->ys_children); 59 | parent->ys_children = newp; 60 | parent->ys_flags |= YSF_CHILDREN_ALLOCED; 61 | } 62 | 63 | /** 64 | * Add a new statement to the list of supported statements 65 | */ 66 | void 67 | yangStmtAdd (yang_stmt_t *ysp, const char *namespace, int count) 68 | { 69 | static unsigned ys_id; 70 | 71 | if (count <= 0) 72 | count = INT_MAX; 73 | 74 | for ( ; count > 0 && ysp->ys_name; count--, ysp++) { 75 | ysp->ys_id = ys_id++; 76 | ysp->ys_namespace = namespace; 77 | 78 | if (ysp->ys_parents) { 79 | yang_relative_t *yrp; 80 | 81 | for (yrp = ysp->ys_parents; yrp && yrp->yr_name; yrp++) { 82 | yangStmtRebuildParents(ysp, yrp); 83 | } 84 | } 85 | 86 | TAILQ_INSERT_TAIL(&yangStmtList, ysp, ys_link); 87 | } 88 | } 89 | 90 | yang_stmt_t * 91 | yangStmtFind (const char *namespace, const char *name) 92 | { 93 | yang_stmt_t *ysp; 94 | int is_yin = namespace ? streq(namespace, YIN_URI) : FALSE; 95 | 96 | TAILQ_FOREACH(ysp, &yangStmtList, ys_link) { 97 | if (namespace) { 98 | if (ysp->ys_namespace) { 99 | if (!streq(namespace, ysp->ys_namespace)) 100 | continue; 101 | } else if (!is_yin) 102 | continue; 103 | } 104 | 105 | if (streq(ysp->ys_name, name)) 106 | return ysp; 107 | } 108 | 109 | return NULL; 110 | } 111 | 112 | static xmlNsPtr 113 | yangStmtFindNs (yang_data_t *ydp, yang_stmt_t *ysp) 114 | { 115 | if (ysp->ys_namespace == NULL) 116 | return ydp->yd_nsp; 117 | 118 | return NULL; 119 | } 120 | 121 | char * 122 | yangStmtGetValueName (slax_data_t *sdp, xmlNodePtr nodep, 123 | const char *namespace, const char *name, 124 | const char *argument, unsigned flags) 125 | { 126 | if (nodep == NULL) { 127 | nodep = sdp->sd_ctxt->node; 128 | if (nodep == NULL) 129 | return NULL; 130 | } 131 | 132 | for (nodep = nodep->children; nodep; nodep = nodep->next) { 133 | if (nodep->type != XML_ELEMENT_NODE) 134 | continue; 135 | 136 | if (namespace) { 137 | if (nodep->ns == NULL 138 | || !streq(namespace, (const char *) nodep->ns->href)) 139 | continue; 140 | } 141 | 142 | if (!streq(name, (const char *) nodep->name)) 143 | continue; 144 | 145 | if (flags & YSF_YINELEMENT) { 146 | xmlNodePtr childp; 147 | for (childp = nodep->children; childp; childp = childp->next) { 148 | if (childp->type != XML_ELEMENT_NODE 149 | || childp->children == NULL) 150 | continue; 151 | if (!streq(argument, (const char *) childp->name)) 152 | continue; 153 | if (childp->children->type == XML_TEXT_NODE) 154 | return (char *) xmlStrdup(childp->children->content); 155 | break; 156 | } 157 | 158 | } else { 159 | return slaxGetAttrib(nodep, argument); 160 | } 161 | } 162 | 163 | return NULL; 164 | } 165 | 166 | char * 167 | yangStmtGetValue (slax_data_t *sdp, xmlNodePtr nodep, yang_stmt_t *ysp) 168 | { 169 | if (ysp == NULL) 170 | return NULL; 171 | 172 | return yangStmtGetValueName(sdp, nodep, ysp->ys_namespace, 173 | ysp->ys_name, ysp->ys_argument, 174 | ysp->ys_flags); 175 | } 176 | 177 | static yang_relative_t * 178 | yangFindRelative (yang_relative_t *listp, yang_stmt_t *ysp) 179 | { 180 | for ( ; listp->yr_name; listp++) 181 | if (streq(listp->yr_name, ysp->ys_name)) 182 | return listp; 183 | 184 | return NULL; 185 | } 186 | 187 | static int 188 | yangSeenTestAndSet (yang_parse_stack_t *ypsp, yang_stmt_t *ysp) 189 | { 190 | unsigned x = ysp->ys_id / NBBY; 191 | unsigned y = ysp->ys_id % NBBY; 192 | unsigned z = 1 << y; 193 | yang_seen_elt_t *map = ypsp->yps_seen.yss_map; 194 | 195 | slaxLog("yangSeenTestAndSet: %d -> %d/%d/%d (%p)", 196 | ysp->ys_id, x, y, z, map); 197 | 198 | int res = (map[x] & z) ? 1 : 0; 199 | 200 | map[x] |= z; 201 | return res; 202 | } 203 | 204 | static unsigned 205 | yangCheckChildren (slax_data_t *sdp, yang_stmt_t *ysp, const char *name) 206 | { 207 | yang_data_t *ydp = yangData(sdp); 208 | yang_parse_stack_t *ypsp = ydp->yd_stackp; 209 | yang_stmt_t *parent = ypsp ? ypsp->yps_stmt : NULL; 210 | 211 | slaxLog("check child: %s", name); 212 | if (ysp && parent && parent->ys_children) { 213 | yang_relative_t *yrp = yangFindRelative(parent->ys_children, ysp); 214 | if (yrp == NULL) { 215 | yangError(sdp, "statement '%s' cannot contain statement '%s'", 216 | parent->ys_name, name); 217 | return YPSF_DISCARD; 218 | } else if (!(yrp->yr_flags & YRF_MULTIPLE) 219 | && yangSeenTestAndSet(ypsp, ysp)) { 220 | yangError(sdp, "statement '%s' can only contain " 221 | "one statement '%s'", 222 | parent->ys_name, name); 223 | return YPSF_DISCARD; 224 | } 225 | } 226 | 227 | return 0; 228 | } 229 | 230 | void 231 | yangStmtOpen (slax_data_t *sdp, const char *raw_name) 232 | { 233 | yang_data_t *ydp = yangData(sdp); 234 | unsigned flags = 0; 235 | char *local_name, *ns = NULL; 236 | const char *name = raw_name; 237 | 238 | local_name = strchr(name, ':'); 239 | if (local_name) { 240 | size_t len = local_name - name; 241 | if (len) { 242 | ns = alloca(len + 1); 243 | memcpy(ns, name, len); 244 | ns[len] = '\0'; 245 | } 246 | name = local_name + 1; 247 | } 248 | 249 | slaxLog("yang: open: %s (%s:%s)", raw_name, ns ?: "--", name); 250 | 251 | slaxElementOpen(sdp, name); 252 | 253 | yang_stmt_t *ysp = yangStmtFind(ns, name); 254 | if (ysp) { 255 | sdp->sd_ctxt->node->ns = yangStmtFindNs(ydp, ysp); 256 | 257 | flags |= yangCheckChildren(sdp, ysp, name); 258 | 259 | if (ysp->ys_open) { 260 | slaxLog("yang: calling open for %s", name); 261 | ysp->ys_open(sdp, ydp, ysp); 262 | } 263 | 264 | if (ysp->ys_type) 265 | sdp->sd_ytype = sdp->sd_ttype = ysp->ys_type; 266 | } else { 267 | slaxError("%s:%d: unknown statement: %s", 268 | sdp->sd_filename, sdp->sd_line, raw_name); 269 | sdp->sd_errors += 1; 270 | } 271 | 272 | if (sdp->sd_ttype == 0) 273 | sdp->sd_ytype = sdp->sd_ttype = Y_STRING; 274 | 275 | /* Tell the lexer we are looking for a string */ 276 | if (sdp->sd_ytype == Y_STRING || sdp->sd_ytype == Y_IDENT 277 | || sdp->sd_ytype == Y_REGEX) 278 | sdp->sd_flags |= SDF_STRING; 279 | 280 | /* Allocate a frame on the parse stack */ 281 | ydp->yd_stackp = ydp->yd_stackp ? ydp->yd_stackp + 1 : ydp->yd_stack; 282 | 283 | /* Fill in the parse stack frame with the info we know */ 284 | bzero(ydp->yd_stackp, sizeof(*ydp->yd_stackp)); 285 | ydp->yd_stackp->yps_stmt = ysp; 286 | ydp->yd_stackp->yps_flags = flags; 287 | } 288 | 289 | void 290 | yangStmtClose (slax_data_t *sdp, const char *name) 291 | { 292 | yang_data_t *ydp = yangData(sdp); 293 | 294 | slaxLog("yang: close: %s", name); 295 | 296 | yang_stmt_t *ysp = ydp->yd_stackp ? ydp->yd_stackp->yps_stmt : NULL; 297 | if (ysp && ysp->ys_close) { 298 | slaxLog("yang: calling close for %s", name); 299 | ysp->ys_close(sdp, ydp, ysp); 300 | } 301 | 302 | unsigned flags = 0; 303 | 304 | if (ydp->yd_stackp) { 305 | flags = ydp->yd_stackp->yps_flags; 306 | ydp->yd_stackp->yps_stmt = NULL; 307 | 308 | if (ydp->yd_stackp == ydp->yd_stack) 309 | ydp->yd_stackp = NULL; 310 | else 311 | ydp->yd_stackp -= 1; 312 | } 313 | 314 | xmlNodePtr nodep = sdp->sd_ctxt->node; 315 | slaxElementClose(sdp); 316 | 317 | if (nodep && (flags & YPSF_DISCARD)) { 318 | slaxLog("yang: close: discarding '%s'", (const char *) nodep->name); 319 | xmlUnlinkNode(nodep); 320 | } 321 | } 322 | 323 | void 324 | yangStmtSetArgument (slax_data_t *sdp, slax_string_t *value, 325 | int is_xpath UNUSED) 326 | { 327 | yang_data_t *ydp = yangData(sdp); 328 | xmlNodePtr nodep = sdp->sd_ctxt->node; 329 | const char *name = (const char *) nodep->name; 330 | yang_stmt_t *ysp; 331 | const char *argument; 332 | int as_element; 333 | 334 | slaxLog("yangStmtSetArgument: %x %x %d -> %x:%s", 335 | sdp, value, is_xpath, nodep, name); 336 | 337 | ysp = ydp->yd_stackp ? ydp->yd_stackp->yps_stmt : NULL; 338 | if (ysp == NULL) { 339 | as_element = FALSE; 340 | argument = "argument"; 341 | } else { 342 | as_element = (ysp->ys_flags & YSF_YINELEMENT) ? TRUE: FALSE; 343 | argument = ysp->ys_argument; 344 | 345 | if (argument == NULL) { 346 | xmlParserError(sdp->sd_ctxt, 347 | "%s:%d: statement '%s' does not accept " 348 | "an argument ('%s')", 349 | sdp->sd_filename, sdp->sd_line, 350 | name, value->ss_token); 351 | return; 352 | } 353 | } 354 | 355 | if (as_element) { 356 | slaxElementOpen(sdp, argument); 357 | 358 | /* XXX need to convert token chain to string */ 359 | xmlNodePtr textp = xmlNewText((const xmlChar *) value->ss_token); 360 | if (textp == NULL) 361 | fprintf(stderr, "could not make node: text\n"); 362 | else 363 | slaxAddChild(sdp, NULL, textp); 364 | 365 | slaxElementClose(sdp); 366 | 367 | } else { 368 | slaxAttribAddXpath(sdp, argument, value); 369 | } 370 | 371 | if (ysp && ysp->ys_setarg) 372 | ysp->ys_setarg(sdp, ydp, ysp); 373 | } 374 | 375 | void 376 | yangStmtCheckArgument (slax_data_t *sdp, slax_string_t *sp) 377 | { 378 | yang_data_t *ydp = yangData(sdp); 379 | yang_stmt_t *ysp = ydp->yd_stackp ? ydp->yd_stackp->yps_stmt : NULL; 380 | 381 | if (ysp && ysp->ys_argument && sp == NULL) { 382 | slaxError("%s:%d: missing argument for %s", 383 | sdp->sd_filename, sdp->sd_line, ysp->ys_name); 384 | sdp->sd_errors += 1; 385 | } 386 | } 387 | 388 | static int 389 | yangIsSimple (slax_string_t *ssp) 390 | { 391 | return (ssp->ss_ttype == T_BARE || ssp->ss_ttype == T_QUOTED 392 | || ssp->ss_ttype == T_NUMBER 393 | || (ssp->ss_ttype > V_LAST && ssp->ss_ttype < L_LAST)); 394 | } 395 | 396 | static slax_string_t * 397 | yangPadString (slax_string_t *val, int after) 398 | { 399 | int len1 = strlen(val->ss_token); 400 | int len = len1 + 1; 401 | int start = after ? 0 : 1; 402 | slax_string_t *ssp = xmlMalloc(sizeof(*ssp) + len + 1); 403 | 404 | if (ssp == NULL) 405 | return NULL; 406 | 407 | if (!after) 408 | ssp->ss_token[0] = ' '; 409 | memcpy(ssp->ss_token + start, val->ss_token, len1); 410 | if (after) 411 | ssp->ss_token[len1] = ' '; 412 | ssp->ss_token[len] = '\0'; 413 | ssp->ss_next = ssp->ss_concat = NULL; 414 | ssp->ss_ttype = T_QUOTED; 415 | ssp->ss_flags = val->ss_flags; 416 | 417 | return ssp; 418 | } 419 | 420 | slax_string_t * 421 | yangConcatValues (slax_data_t *sdp, slax_string_t *one, 422 | slax_string_t *two, int with_space) 423 | { 424 | slax_string_t *ssp; 425 | 426 | /* 427 | * First we need to decide if these strings need simple concatenation 428 | */ 429 | if (yangIsSimple(one) && yangIsSimple(two)) { 430 | int len1 = strlen(one->ss_token); 431 | int len2 = strlen(two->ss_token); 432 | int len = len1 + len2; 433 | 434 | if (with_space) 435 | len += 1; 436 | 437 | ssp = xmlMalloc(sizeof(*ssp) + len + 1); 438 | if (ssp == NULL) 439 | return NULL; 440 | 441 | memcpy(ssp->ss_token, one->ss_token, len1); 442 | if (with_space) 443 | ssp->ss_token[len1++] = ' '; 444 | memcpy(ssp->ss_token + len1, two->ss_token, len2); 445 | ssp->ss_token[len] = '\0'; 446 | ssp->ss_next = ssp->ss_concat = NULL; 447 | ssp->ss_ttype = T_QUOTED; 448 | ssp->ss_flags = one->ss_flags; 449 | slaxLog("yangConcatValues: built %p %d:'%s'", 450 | ssp, ssp->ss_ttype,ssp->ss_token); 451 | 452 | slaxStringFree(one); 453 | slaxStringFree(two); 454 | 455 | return ssp; 456 | } 457 | 458 | if (with_space) { 459 | if (yangIsSimple(one)) { 460 | ssp = yangPadString(one, TRUE); 461 | if (ssp) { 462 | slaxStringFree(one); 463 | one = ssp; 464 | } 465 | 466 | } else if (yangIsSimple(two)) { 467 | ssp = yangPadString(two, FALSE); 468 | if (ssp) { 469 | slaxStringFree(two); 470 | two = ssp; 471 | } 472 | } else { 473 | slax_string_t *spacep = slaxStringLiteral(" ", T_QUOTED); 474 | ssp = slaxStringLiteral("_", L_UNDERSCORE); 475 | one = slaxConcatRewrite(sdp, one, ssp, spacep); 476 | } 477 | } 478 | 479 | ssp = slaxStringLiteral("_", L_UNDERSCORE); 480 | ssp = slaxConcatRewrite(sdp, one, ssp, two); 481 | return ssp; 482 | } 483 | 484 | void 485 | yangStmtInit (void) 486 | { 487 | TAILQ_INIT(&yangStmtList); 488 | yangStmtInitBuiltin(); 489 | } 490 | -------------------------------------------------------------------------------- /m4/ltoptions.m4: -------------------------------------------------------------------------------- 1 | # Helper functions for option handling. -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004, 2005, 2007, 2008, 2009 Free Software Foundation, 4 | # Inc. 5 | # Written by Gary V. Vaughan, 2004 6 | # 7 | # This file is free software; the Free Software Foundation gives 8 | # unlimited permission to copy and/or distribute it, with or without 9 | # modifications, as long as this notice is preserved. 10 | 11 | # serial 7 ltoptions.m4 12 | 13 | # This is to help aclocal find these macros, as it can't see m4_define. 14 | AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])]) 15 | 16 | 17 | # _LT_MANGLE_OPTION(MACRO-NAME, OPTION-NAME) 18 | # ------------------------------------------ 19 | m4_define([_LT_MANGLE_OPTION], 20 | [[_LT_OPTION_]m4_bpatsubst($1__$2, [[^a-zA-Z0-9_]], [_])]) 21 | 22 | 23 | # _LT_SET_OPTION(MACRO-NAME, OPTION-NAME) 24 | # --------------------------------------- 25 | # Set option OPTION-NAME for macro MACRO-NAME, and if there is a 26 | # matching handler defined, dispatch to it. Other OPTION-NAMEs are 27 | # saved as a flag. 28 | m4_define([_LT_SET_OPTION], 29 | [m4_define(_LT_MANGLE_OPTION([$1], [$2]))dnl 30 | m4_ifdef(_LT_MANGLE_DEFUN([$1], [$2]), 31 | _LT_MANGLE_DEFUN([$1], [$2]), 32 | [m4_warning([Unknown $1 option `$2'])])[]dnl 33 | ]) 34 | 35 | 36 | # _LT_IF_OPTION(MACRO-NAME, OPTION-NAME, IF-SET, [IF-NOT-SET]) 37 | # ------------------------------------------------------------ 38 | # Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. 39 | m4_define([_LT_IF_OPTION], 40 | [m4_ifdef(_LT_MANGLE_OPTION([$1], [$2]), [$3], [$4])]) 41 | 42 | 43 | # _LT_UNLESS_OPTIONS(MACRO-NAME, OPTION-LIST, IF-NOT-SET) 44 | # ------------------------------------------------------- 45 | # Execute IF-NOT-SET unless all options in OPTION-LIST for MACRO-NAME 46 | # are set. 47 | m4_define([_LT_UNLESS_OPTIONS], 48 | [m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), 49 | [m4_ifdef(_LT_MANGLE_OPTION([$1], _LT_Option), 50 | [m4_define([$0_found])])])[]dnl 51 | m4_ifdef([$0_found], [m4_undefine([$0_found])], [$3 52 | ])[]dnl 53 | ]) 54 | 55 | 56 | # _LT_SET_OPTIONS(MACRO-NAME, OPTION-LIST) 57 | # ---------------------------------------- 58 | # OPTION-LIST is a space-separated list of Libtool options associated 59 | # with MACRO-NAME. If any OPTION has a matching handler declared with 60 | # LT_OPTION_DEFINE, dispatch to that macro; otherwise complain about 61 | # the unknown option and exit. 62 | m4_defun([_LT_SET_OPTIONS], 63 | [# Set options 64 | m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), 65 | [_LT_SET_OPTION([$1], _LT_Option)]) 66 | 67 | m4_if([$1],[LT_INIT],[ 68 | dnl 69 | dnl Simply set some default values (i.e off) if boolean options were not 70 | dnl specified: 71 | _LT_UNLESS_OPTIONS([LT_INIT], [dlopen], [enable_dlopen=no 72 | ]) 73 | _LT_UNLESS_OPTIONS([LT_INIT], [win32-dll], [enable_win32_dll=no 74 | ]) 75 | dnl 76 | dnl If no reference was made to various pairs of opposing options, then 77 | dnl we run the default mode handler for the pair. For example, if neither 78 | dnl `shared' nor `disable-shared' was passed, we enable building of shared 79 | dnl archives by default: 80 | _LT_UNLESS_OPTIONS([LT_INIT], [shared disable-shared], [_LT_ENABLE_SHARED]) 81 | _LT_UNLESS_OPTIONS([LT_INIT], [static disable-static], [_LT_ENABLE_STATIC]) 82 | _LT_UNLESS_OPTIONS([LT_INIT], [pic-only no-pic], [_LT_WITH_PIC]) 83 | _LT_UNLESS_OPTIONS([LT_INIT], [fast-install disable-fast-install], 84 | [_LT_ENABLE_FAST_INSTALL]) 85 | ]) 86 | ])# _LT_SET_OPTIONS 87 | 88 | 89 | ## --------------------------------- ## 90 | ## Macros to handle LT_INIT options. ## 91 | ## --------------------------------- ## 92 | 93 | # _LT_MANGLE_DEFUN(MACRO-NAME, OPTION-NAME) 94 | # ----------------------------------------- 95 | m4_define([_LT_MANGLE_DEFUN], 96 | [[_LT_OPTION_DEFUN_]m4_bpatsubst(m4_toupper([$1__$2]), [[^A-Z0-9_]], [_])]) 97 | 98 | 99 | # LT_OPTION_DEFINE(MACRO-NAME, OPTION-NAME, CODE) 100 | # ----------------------------------------------- 101 | m4_define([LT_OPTION_DEFINE], 102 | [m4_define(_LT_MANGLE_DEFUN([$1], [$2]), [$3])[]dnl 103 | ])# LT_OPTION_DEFINE 104 | 105 | 106 | # dlopen 107 | # ------ 108 | LT_OPTION_DEFINE([LT_INIT], [dlopen], [enable_dlopen=yes 109 | ]) 110 | 111 | AU_DEFUN([AC_LIBTOOL_DLOPEN], 112 | [_LT_SET_OPTION([LT_INIT], [dlopen]) 113 | AC_DIAGNOSE([obsolete], 114 | [$0: Remove this warning and the call to _LT_SET_OPTION when you 115 | put the `dlopen' option into LT_INIT's first parameter.]) 116 | ]) 117 | 118 | dnl aclocal-1.4 backwards compatibility: 119 | dnl AC_DEFUN([AC_LIBTOOL_DLOPEN], []) 120 | 121 | 122 | # win32-dll 123 | # --------- 124 | # Declare package support for building win32 dll's. 125 | LT_OPTION_DEFINE([LT_INIT], [win32-dll], 126 | [enable_win32_dll=yes 127 | 128 | case $host in 129 | *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-cegcc*) 130 | AC_CHECK_TOOL(AS, as, false) 131 | AC_CHECK_TOOL(DLLTOOL, dlltool, false) 132 | AC_CHECK_TOOL(OBJDUMP, objdump, false) 133 | ;; 134 | esac 135 | 136 | test -z "$AS" && AS=as 137 | _LT_DECL([], [AS], [1], [Assembler program])dnl 138 | 139 | test -z "$DLLTOOL" && DLLTOOL=dlltool 140 | _LT_DECL([], [DLLTOOL], [1], [DLL creation program])dnl 141 | 142 | test -z "$OBJDUMP" && OBJDUMP=objdump 143 | _LT_DECL([], [OBJDUMP], [1], [Object dumper program])dnl 144 | ])# win32-dll 145 | 146 | AU_DEFUN([AC_LIBTOOL_WIN32_DLL], 147 | [AC_REQUIRE([AC_CANONICAL_HOST])dnl 148 | _LT_SET_OPTION([LT_INIT], [win32-dll]) 149 | AC_DIAGNOSE([obsolete], 150 | [$0: Remove this warning and the call to _LT_SET_OPTION when you 151 | put the `win32-dll' option into LT_INIT's first parameter.]) 152 | ]) 153 | 154 | dnl aclocal-1.4 backwards compatibility: 155 | dnl AC_DEFUN([AC_LIBTOOL_WIN32_DLL], []) 156 | 157 | 158 | # _LT_ENABLE_SHARED([DEFAULT]) 159 | # ---------------------------- 160 | # implement the --enable-shared flag, and supports the `shared' and 161 | # `disable-shared' LT_INIT options. 162 | # DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. 163 | m4_define([_LT_ENABLE_SHARED], 164 | [m4_define([_LT_ENABLE_SHARED_DEFAULT], [m4_if($1, no, no, yes)])dnl 165 | AC_ARG_ENABLE([shared], 166 | [AS_HELP_STRING([--enable-shared@<:@=PKGS@:>@], 167 | [build shared libraries @<:@default=]_LT_ENABLE_SHARED_DEFAULT[@:>@])], 168 | [p=${PACKAGE-default} 169 | case $enableval in 170 | yes) enable_shared=yes ;; 171 | no) enable_shared=no ;; 172 | *) 173 | enable_shared=no 174 | # Look at the argument we got. We use all the common list separators. 175 | lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," 176 | for pkg in $enableval; do 177 | IFS="$lt_save_ifs" 178 | if test "X$pkg" = "X$p"; then 179 | enable_shared=yes 180 | fi 181 | done 182 | IFS="$lt_save_ifs" 183 | ;; 184 | esac], 185 | [enable_shared=]_LT_ENABLE_SHARED_DEFAULT) 186 | 187 | _LT_DECL([build_libtool_libs], [enable_shared], [0], 188 | [Whether or not to build shared libraries]) 189 | ])# _LT_ENABLE_SHARED 190 | 191 | LT_OPTION_DEFINE([LT_INIT], [shared], [_LT_ENABLE_SHARED([yes])]) 192 | LT_OPTION_DEFINE([LT_INIT], [disable-shared], [_LT_ENABLE_SHARED([no])]) 193 | 194 | # Old names: 195 | AC_DEFUN([AC_ENABLE_SHARED], 196 | [_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[shared]) 197 | ]) 198 | 199 | AC_DEFUN([AC_DISABLE_SHARED], 200 | [_LT_SET_OPTION([LT_INIT], [disable-shared]) 201 | ]) 202 | 203 | AU_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)]) 204 | AU_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)]) 205 | 206 | dnl aclocal-1.4 backwards compatibility: 207 | dnl AC_DEFUN([AM_ENABLE_SHARED], []) 208 | dnl AC_DEFUN([AM_DISABLE_SHARED], []) 209 | 210 | 211 | 212 | # _LT_ENABLE_STATIC([DEFAULT]) 213 | # ---------------------------- 214 | # implement the --enable-static flag, and support the `static' and 215 | # `disable-static' LT_INIT options. 216 | # DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. 217 | m4_define([_LT_ENABLE_STATIC], 218 | [m4_define([_LT_ENABLE_STATIC_DEFAULT], [m4_if($1, no, no, yes)])dnl 219 | AC_ARG_ENABLE([static], 220 | [AS_HELP_STRING([--enable-static@<:@=PKGS@:>@], 221 | [build static libraries @<:@default=]_LT_ENABLE_STATIC_DEFAULT[@:>@])], 222 | [p=${PACKAGE-default} 223 | case $enableval in 224 | yes) enable_static=yes ;; 225 | no) enable_static=no ;; 226 | *) 227 | enable_static=no 228 | # Look at the argument we got. We use all the common list separators. 229 | lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," 230 | for pkg in $enableval; do 231 | IFS="$lt_save_ifs" 232 | if test "X$pkg" = "X$p"; then 233 | enable_static=yes 234 | fi 235 | done 236 | IFS="$lt_save_ifs" 237 | ;; 238 | esac], 239 | [enable_static=]_LT_ENABLE_STATIC_DEFAULT) 240 | 241 | _LT_DECL([build_old_libs], [enable_static], [0], 242 | [Whether or not to build static libraries]) 243 | ])# _LT_ENABLE_STATIC 244 | 245 | LT_OPTION_DEFINE([LT_INIT], [static], [_LT_ENABLE_STATIC([yes])]) 246 | LT_OPTION_DEFINE([LT_INIT], [disable-static], [_LT_ENABLE_STATIC([no])]) 247 | 248 | # Old names: 249 | AC_DEFUN([AC_ENABLE_STATIC], 250 | [_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[static]) 251 | ]) 252 | 253 | AC_DEFUN([AC_DISABLE_STATIC], 254 | [_LT_SET_OPTION([LT_INIT], [disable-static]) 255 | ]) 256 | 257 | AU_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)]) 258 | AU_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)]) 259 | 260 | dnl aclocal-1.4 backwards compatibility: 261 | dnl AC_DEFUN([AM_ENABLE_STATIC], []) 262 | dnl AC_DEFUN([AM_DISABLE_STATIC], []) 263 | 264 | 265 | 266 | # _LT_ENABLE_FAST_INSTALL([DEFAULT]) 267 | # ---------------------------------- 268 | # implement the --enable-fast-install flag, and support the `fast-install' 269 | # and `disable-fast-install' LT_INIT options. 270 | # DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. 271 | m4_define([_LT_ENABLE_FAST_INSTALL], 272 | [m4_define([_LT_ENABLE_FAST_INSTALL_DEFAULT], [m4_if($1, no, no, yes)])dnl 273 | AC_ARG_ENABLE([fast-install], 274 | [AS_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@], 275 | [optimize for fast installation @<:@default=]_LT_ENABLE_FAST_INSTALL_DEFAULT[@:>@])], 276 | [p=${PACKAGE-default} 277 | case $enableval in 278 | yes) enable_fast_install=yes ;; 279 | no) enable_fast_install=no ;; 280 | *) 281 | enable_fast_install=no 282 | # Look at the argument we got. We use all the common list separators. 283 | lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," 284 | for pkg in $enableval; do 285 | IFS="$lt_save_ifs" 286 | if test "X$pkg" = "X$p"; then 287 | enable_fast_install=yes 288 | fi 289 | done 290 | IFS="$lt_save_ifs" 291 | ;; 292 | esac], 293 | [enable_fast_install=]_LT_ENABLE_FAST_INSTALL_DEFAULT) 294 | 295 | _LT_DECL([fast_install], [enable_fast_install], [0], 296 | [Whether or not to optimize for fast installation])dnl 297 | ])# _LT_ENABLE_FAST_INSTALL 298 | 299 | LT_OPTION_DEFINE([LT_INIT], [fast-install], [_LT_ENABLE_FAST_INSTALL([yes])]) 300 | LT_OPTION_DEFINE([LT_INIT], [disable-fast-install], [_LT_ENABLE_FAST_INSTALL([no])]) 301 | 302 | # Old names: 303 | AU_DEFUN([AC_ENABLE_FAST_INSTALL], 304 | [_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install]) 305 | AC_DIAGNOSE([obsolete], 306 | [$0: Remove this warning and the call to _LT_SET_OPTION when you put 307 | the `fast-install' option into LT_INIT's first parameter.]) 308 | ]) 309 | 310 | AU_DEFUN([AC_DISABLE_FAST_INSTALL], 311 | [_LT_SET_OPTION([LT_INIT], [disable-fast-install]) 312 | AC_DIAGNOSE([obsolete], 313 | [$0: Remove this warning and the call to _LT_SET_OPTION when you put 314 | the `disable-fast-install' option into LT_INIT's first parameter.]) 315 | ]) 316 | 317 | dnl aclocal-1.4 backwards compatibility: 318 | dnl AC_DEFUN([AC_ENABLE_FAST_INSTALL], []) 319 | dnl AC_DEFUN([AM_DISABLE_FAST_INSTALL], []) 320 | 321 | 322 | # _LT_WITH_PIC([MODE]) 323 | # -------------------- 324 | # implement the --with-pic flag, and support the `pic-only' and `no-pic' 325 | # LT_INIT options. 326 | # MODE is either `yes' or `no'. If omitted, it defaults to `both'. 327 | m4_define([_LT_WITH_PIC], 328 | [AC_ARG_WITH([pic], 329 | [AS_HELP_STRING([--with-pic@<:@=PKGS@:>@], 330 | [try to use only PIC/non-PIC objects @<:@default=use both@:>@])], 331 | [lt_p=${PACKAGE-default} 332 | case $withval in 333 | yes|no) pic_mode=$withval ;; 334 | *) 335 | pic_mode=default 336 | # Look at the argument we got. We use all the common list separators. 337 | lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," 338 | for lt_pkg in $withval; do 339 | IFS="$lt_save_ifs" 340 | if test "X$lt_pkg" = "X$lt_p"; then 341 | pic_mode=yes 342 | fi 343 | done 344 | IFS="$lt_save_ifs" 345 | ;; 346 | esac], 347 | [pic_mode=default]) 348 | 349 | test -z "$pic_mode" && pic_mode=m4_default([$1], [default]) 350 | 351 | _LT_DECL([], [pic_mode], [0], [What type of objects to build])dnl 352 | ])# _LT_WITH_PIC 353 | 354 | LT_OPTION_DEFINE([LT_INIT], [pic-only], [_LT_WITH_PIC([yes])]) 355 | LT_OPTION_DEFINE([LT_INIT], [no-pic], [_LT_WITH_PIC([no])]) 356 | 357 | # Old name: 358 | AU_DEFUN([AC_LIBTOOL_PICMODE], 359 | [_LT_SET_OPTION([LT_INIT], [pic-only]) 360 | AC_DIAGNOSE([obsolete], 361 | [$0: Remove this warning and the call to _LT_SET_OPTION when you 362 | put the `pic-only' option into LT_INIT's first parameter.]) 363 | ]) 364 | 365 | dnl aclocal-1.4 backwards compatibility: 366 | dnl AC_DEFUN([AC_LIBTOOL_PICMODE], []) 367 | 368 | ## ----------------- ## 369 | ## LTDL_INIT Options ## 370 | ## ----------------- ## 371 | 372 | m4_define([_LTDL_MODE], []) 373 | LT_OPTION_DEFINE([LTDL_INIT], [nonrecursive], 374 | [m4_define([_LTDL_MODE], [nonrecursive])]) 375 | LT_OPTION_DEFINE([LTDL_INIT], [recursive], 376 | [m4_define([_LTDL_MODE], [recursive])]) 377 | LT_OPTION_DEFINE([LTDL_INIT], [subproject], 378 | [m4_define([_LTDL_MODE], [subproject])]) 379 | 380 | m4_define([_LTDL_TYPE], []) 381 | LT_OPTION_DEFINE([LTDL_INIT], [installable], 382 | [m4_define([_LTDL_TYPE], [installable])]) 383 | LT_OPTION_DEFINE([LTDL_INIT], [convenience], 384 | [m4_define([_LTDL_TYPE], [convenience])]) 385 | -------------------------------------------------------------------------------- /libyang/yangloader.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Juniper Networks, Inc. 3 | * All rights reserved. 4 | * See ../Copyright for the status of this software 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "yanginternals.h" 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | static slax_data_list_t yang_features; 25 | static int yang_features_initted; 26 | 27 | void 28 | yangFeatureAdd (const char *feature_name) 29 | { 30 | if (!yang_features_initted) { 31 | yang_features_initted += 1; 32 | TAILQ_INIT(&yang_features); 33 | } 34 | 35 | slaxDataListAdd(&yang_features, feature_name); 36 | } 37 | 38 | xmlDocPtr 39 | yangFeaturesBuildInputDoc (void) 40 | { 41 | xmlDocPtr docp; 42 | xmlNodePtr top, nodep; 43 | slax_data_node_t *dnp; 44 | 45 | docp = xmlNewDoc((const xmlChar *) XML_DEFAULT_VERSION); 46 | if (docp == NULL) 47 | return NULL; 48 | 49 | docp->standalone = 1; 50 | docp->dict = xmlDictCreate(); 51 | 52 | top = xmlNewDocNode(docp, NULL, (const xmlChar *) "features", NULL); 53 | if (top == NULL) { 54 | xmlFreeDoc(docp); 55 | return NULL; 56 | } 57 | 58 | xmlDocSetRootElement(docp, top); 59 | 60 | if (yang_features_initted) { 61 | SLAXDATALIST_FOREACH(dnp, &yang_features) { 62 | char *name = dnp->dn_data; 63 | 64 | /* 65 | * The feature is either a simple name or a "name=value" 66 | * format. If there's an equal sign, break it into the 67 | * two pieces and put the value as the content of the node. 68 | */ 69 | const char *cp = strchr(name, '='); 70 | if (cp) { 71 | size_t len = cp - name; 72 | char *newp = alloca(len + 1); 73 | memcpy(newp, name, len); 74 | newp[len] = '\0'; 75 | 76 | name = newp; 77 | cp += 1; 78 | } 79 | 80 | nodep = xmlNewDocNode(docp, NULL, (const xmlChar *) name, 81 | (const xmlChar *) cp); 82 | if (nodep == NULL) 83 | break; 84 | 85 | xmlAddChild(top, nodep); 86 | } 87 | } 88 | 89 | return docp; 90 | } 91 | 92 | #if 0 93 | static xmlNodePtr 94 | yangFindMain (yang_file_t *yfp) 95 | { 96 | static const char *sel = "xsl:template[@match = '/features']" 97 | "/node()[local-name() == 'module' || local-name() == 'submodule']"; 98 | xmlNodePtr nodep = NULL; 99 | 100 | xmlNodeSetPtr res = slaxXpathSelect(yfp->yf_docp, yfp->yf_root, sel); 101 | if (res && res->nodeNr == 1) { 102 | nodep = res->nodeTab[0]; 103 | xmlXPathFreeNodeSet(res); 104 | } 105 | 106 | return nodep; 107 | } 108 | #endif 109 | 110 | static yang_file_t * 111 | yangFileLoadContents (yang_file_list_t *listp, 112 | const char *template, const char *name UNUSED, 113 | const char *filename, FILE *file, 114 | xmlDictPtr dict, int partial UNUSED) 115 | { 116 | slax_data_t sd; 117 | yang_data_t yd; 118 | int rc; 119 | xmlParserCtxtPtr ctxt = xmlNewParserCtxt(); 120 | yang_file_t *yfp; 121 | 122 | if (ctxt == NULL) 123 | return NULL; 124 | 125 | yfp = xmlMalloc(sizeof(*yfp)); 126 | if (yfp == NULL) 127 | return NULL; 128 | 129 | bzero(yfp, sizeof(*yfp)); 130 | yfp->yf_name = strdup(name); 131 | yfp->yf_path = strdup(filename); 132 | TAILQ_INSERT_TAIL(listp, yfp, yf_link); 133 | 134 | /* 135 | * Turn on line number recording in each node 136 | */ 137 | ctxt->linenumbers = 1; 138 | 139 | if (dict) { 140 | if (ctxt->dict) 141 | xmlDictFree(ctxt->dict); 142 | 143 | ctxt->dict = dict; 144 | xmlDictReference(ctxt->dict); 145 | } 146 | 147 | bzero(&sd, sizeof(sd)); 148 | 149 | /* We want to parse SLAX, either full or partial */ 150 | sd.sd_parse = sd.sd_ttype = M_YANG; 151 | sd.sd_flags |= SDF_SLSH_COMMENTS; 152 | 153 | strncpy(sd.sd_filename, filename, sizeof(sd.sd_filename)); 154 | sd.sd_file = file; 155 | 156 | sd.sd_ctxt = ctxt; 157 | 158 | ctxt->version = xmlCharStrdup(XML_DEFAULT_VERSION); 159 | ctxt->userData = &sd; 160 | 161 | /* 162 | * Fake up an inputStream so the error mechanisms will work 163 | */ 164 | if (filename) 165 | xmlSetupParserForBuffer(ctxt, (const xmlChar *) "", filename); 166 | 167 | sd.sd_docp = slaxBuildDoc(&sd, ctxt); 168 | if (sd.sd_docp == NULL) { 169 | slaxDataCleanup(&sd); 170 | return NULL; 171 | } 172 | 173 | yfp->yf_docp = sd.sd_docp; 174 | yfp->yf_root = xmlDocGetRootElement(sd.sd_docp); 175 | #if 0 176 | yfp->yf_context = xmlXPathNewContext(sd.sd_docp); 177 | #endif 178 | 179 | if (filename != NULL) 180 | sd.sd_docp->URL = (xmlChar *) xmlStrdup((const xmlChar *) filename); 181 | 182 | /* Add the YIN namespace to the root node */ 183 | xmlNsPtr nsp = xmlNewNs(sd.sd_ctxt->node, (const xmlChar *) YIN_URI, 184 | (const xmlChar *) YIN_PREFIX); 185 | 186 | if (slaxElementPush(&sd, ELT_TEMPLATE, NULL, NULL)) { 187 | if (template) { 188 | const char *cp = strrchr(template, '/'); 189 | slaxAttribAddLiteral(&sd, ATT_NAME, cp ? cp + 1 : template); 190 | } else { 191 | slaxAttribAddLiteral(&sd, ATT_MATCH, "/features"); 192 | } 193 | } 194 | 195 | bzero(&yd, sizeof(yd)); 196 | sd.sd_opaque = &yd; /* Hang our data off the slax parser */ 197 | yd.yd_nsp = nsp; 198 | yd.yd_filep = yfp; 199 | yd.yd_file_list = listp; 200 | 201 | rc = yangParse(&sd); 202 | 203 | if (yfp->yf_main == NULL) { 204 | slaxError("%s: no module or submodule found", sd.sd_filename); 205 | sd.sd_errors += 1; 206 | } 207 | 208 | if (sd.sd_errors) { 209 | slaxError("%s: %d error%s detected during parsing (%d)", 210 | sd.sd_filename, sd.sd_errors, (sd.sd_errors == 1) ? "" : "s", rc); 211 | 212 | slaxDataCleanup(&sd); 213 | return NULL; 214 | } 215 | 216 | /* Save docp before slaxDataCleanup nukes it */ 217 | sd.sd_docp = NULL; 218 | slaxDataCleanup(&sd); 219 | 220 | return yfp; 221 | } 222 | 223 | void 224 | yangError (slax_data_t *sdp, const char *fmt, ...) 225 | { 226 | va_list vap; 227 | char *cp; 228 | 229 | va_start(vap, fmt); 230 | vasprintf(&cp, fmt, vap); 231 | slaxError("%s:%d: %s", sdp->sd_filename, sdp->sd_line, cp); 232 | sdp->sd_errors += 1; 233 | 234 | free(cp); 235 | va_end(vap); 236 | } 237 | 238 | static yang_file_t * 239 | yangFileFind (yang_file_list_t *listp, const char *name) 240 | { 241 | yang_file_t *yfp; 242 | 243 | TAILQ_FOREACH(yfp, listp, yf_link) { 244 | if (streq(name, yfp->yf_name)) 245 | return yfp; 246 | } 247 | 248 | return NULL; 249 | } 250 | 251 | static FILE * 252 | yangFindIncludeFile (const char *name, char *buf, int bufsiz) 253 | { 254 | static char yang_ext[] = ".yang"; 255 | int len = strlen(name); 256 | char filename[len + sizeof(yang_ext)]; 257 | 258 | memcpy(filename, name, len); 259 | memcpy(filename + len, yang_ext, sizeof(yang_ext)); 260 | 261 | return slaxFindIncludeFile(filename, buf, bufsiz); 262 | } 263 | 264 | static void 265 | yangFileFree (yang_file_t *yfp, int free_doc) 266 | { 267 | xmlFreeAndEasy(yfp->yf_name); 268 | xmlFreeAndEasy(yfp->yf_path); 269 | 270 | if (free_doc && yfp->yf_docp) 271 | xmlFreeDoc(yfp->yf_docp); 272 | 273 | if (yfp->yf_context) 274 | xmlXPathFreeContext(yfp->yf_context); 275 | 276 | xmlFree(yfp); 277 | } 278 | 279 | static yang_file_t * 280 | yangFileParse (yang_file_list_t *listp, const char *template, 281 | const char *name, const char *filename, FILE *sourcefile, 282 | xmlDictPtr dict, int partial) 283 | { 284 | yang_file_t *yfp; 285 | 286 | yfp = yangFileFind(listp, name); 287 | if (yfp) 288 | return yfp; 289 | 290 | yfp = yangFileLoadContents(listp, template, name, filename, 291 | sourcefile, dict, partial); 292 | 293 | fclose(sourcefile); 294 | 295 | #if 0 296 | yfp->yf_main = yangFindMain(yfp); 297 | if (yfp->yf_main == NULL) { 298 | slaxError("%s: could not file main template", filename); 299 | yangFileFree(yfp, TRUE); 300 | return NULL; 301 | } 302 | 303 | uri = yfp->yf_namespace = slaxGetAttrib(yfp->yf_main, YS_NAMESPACE); 304 | pref = yfp->yf_prefix = slaxGetAttrib(yfp->yf_main, YS_PREFIX); 305 | 306 | if (uri && pref) 307 | xmlNewNs(yfp->yf_root, (const xmlChar *) uri, (const xmlChar *) pref); 308 | #endif 309 | 310 | return yfp; 311 | } 312 | 313 | yang_file_t * 314 | yangFileLoader (const char *template, const char *name, 315 | const char *filename, xmlDictPtr dict, int partial) 316 | { 317 | char path[MAXPATHLEN]; 318 | FILE *sourcefile; 319 | yang_file_list_t list; 320 | 321 | TAILQ_INIT(&list); 322 | sourcefile = yangFindIncludeFile(name, path, sizeof(path)); 323 | if (sourcefile == NULL) 324 | return NULL; 325 | 326 | return yangFileParse(&list, template, name, filename, sourcefile, 327 | dict, partial); 328 | } 329 | 330 | static void 331 | yangImportFile (yang_file_list_t *listp UNUSED, xmlNodePtr insp UNUSED, 332 | const char *fname, const char *pref, 333 | const char *rev, int is_import) 334 | { 335 | slaxLog("yang: import: '%s' '%s' '%s' %s", 336 | fname ?: "", pref ?: "", rev ?: "", is_import ? " is-import" : ""); 337 | } 338 | 339 | static const char * 340 | yangGetValue (xmlNodePtr nodep, const char *elt_name, const char *attr_name) 341 | { 342 | if (nodep == NULL) 343 | return NULL; 344 | 345 | for (nodep = nodep->children; nodep; nodep = nodep->next) { 346 | if (nodep->type != XML_ELEMENT_NODE) 347 | continue; 348 | 349 | if (streq((const char *) nodep->name, elt_name)) 350 | return slaxGetAttrib(nodep, attr_name); 351 | } 352 | 353 | return NULL; 354 | } 355 | 356 | /* 357 | * Find and load all imported modules, from which we extract all 358 | * groupings, typedefs, extensions, features, and identities. We 359 | * also handle includes.n 360 | */ 361 | static void 362 | yangHandleImports (yang_file_list_t *listp UNUSED, yang_file_t *filep UNUSED) 363 | { 364 | xmlNodePtr insp, mainp, nodep, nextp; 365 | int is_import; 366 | 367 | mainp = filep->yf_main; /* Look at the current module */ 368 | insp = mainp->parent->parent->children; /* Insertion point */ 369 | 370 | for (nodep = mainp->children; nodep; nodep = nextp) { 371 | nextp = nodep->next; 372 | 373 | if (nodep->type != XML_ELEMENT_NODE) 374 | continue; 375 | 376 | if (streq((const char *) nodep->name, YS_IMPORT)) 377 | is_import = TRUE; 378 | 379 | else if (streq((const char *) nodep->name, YS_INCLUDE)) 380 | is_import = FALSE; 381 | 382 | else 383 | continue; 384 | 385 | const char *fname = slaxGetAttrib(nodep, YS_MODULE); 386 | const char *pref 387 | = is_import ? yangGetValue(nodep, YS_PREFIX, YS_VALUE): NULL; 388 | const char *rev = yangGetValue(nodep, YS_REVISION_DATE, YS_DATE); 389 | 390 | yangImportFile(listp, insp, fname, pref, rev, is_import); 391 | } 392 | } 393 | 394 | /* 395 | * Find all {,sub}module parameters and move them to be globals. 396 | * XXX Duplicates should be ignored. 397 | */ 398 | static void 399 | yangHandleGlobals (yang_file_list_t *listp UNUSED, yang_file_t *filep) 400 | { 401 | xmlNodePtr insp, mainp, nodep, nextp; 402 | 403 | mainp = filep->yf_main; /* Look at the current module */ 404 | insp = mainp->parent->parent->children; /* Insertion point */ 405 | 406 | for (nodep = mainp->children; nodep; nodep = nextp) { 407 | nextp = nodep->next; 408 | 409 | if (nodep->type != XML_ELEMENT_NODE) 410 | continue; 411 | 412 | if (streq((const char *) nodep->name, ELT_PARAM) 413 | || streq((const char *) nodep->name, ELT_TEMPLATE)) { 414 | slaxLog("moving global '%s' (%p)", 415 | (const char *) nodep->name, nodep); 416 | } else { 417 | continue; 418 | } 419 | 420 | xmlUnlinkNode(nodep); 421 | xmlAddPrevSibling(insp, nodep); 422 | } 423 | } 424 | 425 | xmlDocPtr 426 | yangLoadFile (const char *template, const char *filename, FILE *file, 427 | xmlDictPtr dict, int partial UNUSED) 428 | { 429 | int len = strlen(filename) + 1; 430 | char name[len], *cp, *sp; 431 | yang_file_list_t list; 432 | yang_file_t *yfp; 433 | 434 | TAILQ_INIT(&list); 435 | 436 | memcpy(name, filename, len); 437 | sp = strrchr(name, '/'); 438 | cp = strrchr(name, '.'); 439 | if (cp && (sp == NULL || cp > sp)) 440 | *cp = '\0'; 441 | 442 | yfp = yangFileParse(&list, template, name, filename, file, dict, partial); 443 | if (yfp == NULL) 444 | return NULL; 445 | 446 | xmlDocPtr docp = yfp->yf_docp; 447 | if (docp) { 448 | yangHandleImports(&list, yfp); 449 | yangHandleGlobals(&list, yfp); 450 | 451 | slaxDynLoad(yfp->yf_docp); /* Check dynamic extensions */ 452 | } 453 | 454 | yang_file_t *xp; 455 | for (;;) { 456 | xp = TAILQ_FIRST(&list); 457 | if (xp == NULL) 458 | break; 459 | TAILQ_REMOVE(&list, xp, yf_link); 460 | yangFileFree(xp, (xp != yfp)); 461 | } 462 | 463 | return docp; 464 | } 465 | 466 | xmlDocPtr 467 | yangLoadParams (const char *filename, FILE *file, 468 | xmlDictPtr dict) 469 | { 470 | slax_data_t sd; 471 | yang_data_t yd; 472 | int rc; 473 | xmlParserCtxtPtr ctxt = xmlNewParserCtxt(); 474 | 475 | if (ctxt == NULL) 476 | return NULL; 477 | 478 | /* 479 | * Turn on line number recording in each node 480 | */ 481 | ctxt->linenumbers = 1; 482 | 483 | if (dict) { 484 | if (ctxt->dict) 485 | xmlDictFree(ctxt->dict); 486 | 487 | ctxt->dict = dict; 488 | xmlDictReference(ctxt->dict); 489 | } 490 | 491 | bzero(&sd, sizeof(sd)); 492 | 493 | /* We want to parse SLAX, either full or partial */ 494 | sd.sd_parse = sd.sd_ttype = M_YANG; 495 | sd.sd_flags |= SDF_SLSH_COMMENTS; 496 | 497 | strncpy(sd.sd_filename, filename, sizeof(sd.sd_filename)); 498 | sd.sd_file = file; 499 | 500 | sd.sd_ctxt = ctxt; 501 | 502 | ctxt->version = xmlCharStrdup(XML_DEFAULT_VERSION); 503 | ctxt->userData = &sd; 504 | 505 | /* 506 | * Fake up an inputStream so the error mechanisms will work 507 | */ 508 | if (filename) 509 | xmlSetupParserForBuffer(ctxt, (const xmlChar *) "", filename); 510 | 511 | sd.sd_docp = slaxBuildDoc(&sd, ctxt); 512 | if (sd.sd_docp == NULL) { 513 | slaxDataCleanup(&sd); 514 | return NULL; 515 | } 516 | 517 | if (filename != NULL) 518 | sd.sd_docp->URL = (xmlChar *) xmlStrdup((const xmlChar *) filename); 519 | 520 | /* Add the YIN namespace to the root node */ 521 | xmlNewNs(sd.sd_ctxt->node, (const xmlChar *) YIN_URI, 522 | (const xmlChar *) YIN_PREFIX); 523 | 524 | bzero(&yd, sizeof(yd)); 525 | sd.sd_opaque = &yd; /* Hang our data off the slax parser */ 526 | 527 | rc = yangParse(&sd); 528 | 529 | if (sd.sd_errors) { 530 | slaxError("%s: %d error%s detected during parsing (%d)", 531 | sd.sd_filename, sd.sd_errors, (sd.sd_errors == 1) ? "" : "s", rc); 532 | 533 | slaxDataCleanup(&sd); 534 | return NULL; 535 | } 536 | 537 | /* Save docp before slaxDataCleanup nukes it */ 538 | xmlDocPtr docp = sd.sd_docp; 539 | sd.sd_docp = NULL; 540 | slaxDataCleanup(&sd); 541 | 542 | return docp; 543 | } 544 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # 2 | # $Id$ 3 | # 4 | # Copyright 2011-2012, Juniper Networks, Inc. 5 | # All rights reserved. 6 | # This SOFTWARE is licensed under the LICENSE provided in the 7 | # ../Copyright file. By downloading, installing, copying, or otherwise 8 | # using the SOFTWARE, you agree to be bound by the terms of that 9 | # LICENSE. 10 | 11 | AC_PREREQ(2.2) 12 | AC_INIT([yangc], [0.0.1], [phil@juniper.net]) 13 | AM_INIT_AUTOMAKE([-Wall -Werror foreign -Wno-portability]) 14 | 15 | case $prefix in 16 | NONE) 17 | prefix=/usr/local 18 | ;; 19 | esac 20 | 21 | case $exec_prefix in 22 | NONE) 23 | exec_prefix=$prefix 24 | ;; 25 | esac 26 | 27 | # Support silent build rules. Requires at least automake-1.11. 28 | # Disable with "configure --disable-silent-rules" or "make V=1" 29 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 30 | 31 | # 32 | # libxslt 1.1.26 has a fix for AVT terminating with close braces 33 | # 34 | LIBXML_REQUIRED_VERSION=2.7.7 35 | LIBXSLT_REQUIRED_VERSION=1.1.26 36 | LIBSLAX_REQUIRED_VERSION=0.12.3 37 | 38 | AC_PROG_CC 39 | AM_PROG_AR 40 | AC_PROG_INSTALL 41 | AC_CONFIG_MACRO_DIR([m4]) 42 | 43 | # Must be after AM_PROG_AR 44 | LT_INIT([dlopen]) 45 | 46 | AC_PATH_PROG(BASENAME, basename, /usr/bin/basename) 47 | AC_PATH_PROG(BISON, bison, /usr/bin/bison) 48 | AC_PATH_PROG(CAT, cat, /bin/cat) 49 | AC_PATH_PROG(CHMOD, chmod, /bin/chmod) 50 | AC_PATH_PROG(CP, cp, /bin/cp) 51 | AC_PATH_PROG(DIFF, diff, /usr/bin/diff) 52 | AC_PATH_PROG(MKDIR, mkdir, /bin/mkdir) 53 | AC_PATH_PROG(MV, mv, /bin/mv) 54 | AC_PATH_PROG(RM, rm, /bin/rm) 55 | AC_PATH_PROG(SED, sed, /bin/sed) 56 | 57 | AC_PROG_LN_S 58 | 59 | AC_STDC_HEADERS 60 | 61 | # Checks for typedefs, structures, and compiler characteristics. 62 | AC_C_INLINE 63 | AC_TYPE_SIZE_T 64 | 65 | # Checks for library functions. 66 | AC_FUNC_ALLOCA 67 | AC_FUNC_MALLOC 68 | AC_FUNC_REALLOC 69 | AC_CHECK_FUNCS([bzero memmove strchr strcspn strerror strspn]) 70 | AC_CHECK_FUNCS([sranddev srand strlcpy]) 71 | AC_CHECK_FUNCS([fdopen getrusage]) 72 | AC_CHECK_FUNCS([gettimeofday ctime]) 73 | AC_CHECK_FUNCS([getpass]) 74 | AC_CHECK_FUNCS([sysctlbyname]) 75 | AC_CHECK_FUNCS([flock]) 76 | AC_CHECK_FUNCS([statfs]) 77 | AC_CHECK_FUNCS([strnstr]) 78 | AC_CHECK_FUNCS([strndup]) 79 | 80 | AC_CHECK_HEADERS([sys/time.h]) 81 | AC_CHECK_HEADERS([ctype.h errno.h stdio.h stdlib.h]) 82 | AC_CHECK_HEADERS([string.h sys/param.h unistd.h]) 83 | AC_CHECK_HEADERS([sys/sysctl.h]) 84 | AC_CHECK_HEADERS([stdint.h sys/statfs.h]) 85 | 86 | 87 | AC_CHECK_LIB([crypto], [MD5_Init]) 88 | AM_CONDITIONAL([HAVE_LIBCRYPTO], [test "$HAVE_LIBCRYPTO" != "no"]) 89 | 90 | AC_CHECK_LIB([m], [lrint]) 91 | AM_CONDITIONAL([HAVE_LIBM], [test "$HAVE_LIBM" != "no"]) 92 | 93 | AC_CHECK_LIB([xml2], [xmlNewParserCtxt]) 94 | AC_CHECK_LIB([xslt], [xsltInit]) 95 | AC_CHECK_LIB([readline], [readline]) 96 | 97 | AC_CHECK_MEMBER([struct passwd.pw_class], 98 | [HAVE_PWD_CLASS=yes ; 99 | AC_DEFINE([HAVE_PWD_CLASS], [1], [Have struct pwd.pw_class])], 100 | [HAS_PWD_CLASS=no], [[#include ]]) 101 | 102 | AC_CHECK_MEMBER([struct sockaddr_un.sun_len], 103 | [HAVE_SUN_LEN=yes ; 104 | AC_DEFINE([HAVE_SUN_LEN], [1], [Have struct sockaddr_un.sun_len])], 105 | [HAS_SUN_LEN=no], [[#include ]]) 106 | 107 | dnl 108 | dnl Some packages need to be checked against version numbers so we 109 | dnl define a function here for later use 110 | dnl 111 | AC_DEFUN([VERSION_TO_NUMBER], 112 | [`$1 | sed -e 's/lib.* //' | awk 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 1000 + [$]2) * 1000 + [$]3;}'`]) 113 | 114 | AC_MSG_CHECKING([whether to build with warnings]) 115 | AC_ARG_ENABLE([warnings], 116 | [ --enable-warnings Turn on compiler warnings], 117 | [YANGC_WARNINGS=$enableval], 118 | [YANGC_WARNINGS=no]) 119 | AC_MSG_RESULT([$YANGC_WARNINGS]) 120 | AM_CONDITIONAL([YANGC_WARNINGS_HIGH], [test "$YANGC_WARNINGS" != "no"]) 121 | 122 | AC_MSG_CHECKING([whether to build CLIRA web interface]) 123 | AC_ARG_ENABLE([clira], 124 | [ --enable-clira Build the CLIRA web interface], 125 | [NEED_CLIRA=$enableval], 126 | [NEED_CLIRA=no]) 127 | AC_MSG_RESULT([$NEED_CLIRA]) 128 | AM_CONDITIONAL([NEED_CLIRA], [test "$NEED_CLIRA" != "no"]) 129 | AC_SUBST(NEED_CLIRA) 130 | 131 | AC_MSG_CHECKING([whether to build mixer]) 132 | AC_ARG_ENABLE([mixer], 133 | [ --enable-mixer Build the mixer binary], 134 | [NEED_MIXER=$enableval], 135 | [NEED_MIXER=$NEED_CLIRA]) 136 | AC_MSG_RESULT([$NEED_MIXER]) 137 | AM_CONDITIONAL([NEED_MIXER], [test "$NEED_MIXER" != "no"]) 138 | AC_SUBST(NEED_MIXER) 139 | 140 | AC_MSG_CHECKING([whether to build with debugging]) 141 | AC_ARG_ENABLE([debug], 142 | [ --enable-debug Turn on debugging], 143 | [YANGC_DEBUG=$enable_debug], 144 | [YANGC_DEBUG=no]) 145 | AC_MSG_RESULT([$YANGC_DEBUG]) 146 | AM_CONDITIONAL([YANGC_DEBUG], [test "$YANGC_DEBUG" = "yes"]) 147 | if test "YANGC_DEBUG" = "yes" ; then 148 | AC_DEFINE([YANGC_DEBUG], [1], [Enable debugging]) 149 | fi 150 | AC_SUBST(YANGC_DEBUG) 151 | 152 | PATH_YANGC=`eval echo $bindir/yangc` 153 | AC_DEFINE_UNQUOTED(PATH_YANGC, ["$PATH_YANGC"], [Path to yangc binary]) 154 | 155 | AC_MSG_CHECKING([whether to build with readline]) 156 | AC_ARG_ENABLE([readline], 157 | [ --enable-readline Enable support for GNU readline], 158 | [HAVE_READLINE=$enable_readline], 159 | [HAVE_READLINE=$ac_cv_lib_readline_readline]) 160 | AC_MSG_RESULT([$HAVE_READLINE]) 161 | AM_CONDITIONAL([HAVE_READLINE], [test "$HAVE_READLINE" = "yes"]) 162 | if test "$HAVE_READLINE" = "yes" ; then 163 | AC_DEFINE([HAVE_READLINE], [1], [Enable support for GNU readline]) 164 | fi 165 | 166 | AC_MSG_CHECKING([whether to build with libedit]) 167 | AC_ARG_ENABLE([libedit], 168 | [ --enable-libedit Enable support for libedit (BSD readline)], 169 | [HAVE_LIBEDIT=yes; AC_DEFINE([HAVE_LIBEDIT], [1], [Support libedit])], 170 | [HAVE_LIBEDIT=no]) 171 | AC_MSG_RESULT([$HAVE_LIBEDIT]) 172 | AM_CONDITIONAL([HAVE_LIBEDIT], [test "$HAVE_LIBEDIT" != "no"]) 173 | 174 | AC_MSG_CHECKING([whether to build with __printflike]) 175 | AC_ARG_ENABLE([printflike], 176 | [ --enable-printflike Enable use of GCC __printflike attribute], 177 | [HAVE_PRINTFLIKE=$enable_printflike], 178 | [HAVE_PRINTFLIKE=no]) 179 | AC_MSG_RESULT([$HAVE_PRINTFLIKE]) 180 | AM_CONDITIONAL([HAVE_PRINTFLIKE], [test "$HAVE_PRINTFLIKE" = "yes"]) 181 | if test "$HAVE_PRINTFLIKE" = "yes" ; then 182 | AC_DEFINE([HAVE_PRINTFLIKE], [1], [Enable use of GCC __printflike]) 183 | fi 184 | 185 | # 186 | # ---- start of noise 187 | # 188 | 189 | # 190 | # ---- handle libxml2 191 | # 192 | 193 | LIBXML_CONFIG_PREFIX="" 194 | LIBXML_SRC="" 195 | 196 | AC_ARG_WITH(libxml-prefix, 197 | [ --with-libxml-prefix=[PFX] Specify location of libxml config], 198 | LIBXML_CONFIG_PREFIX=$withval 199 | ) 200 | 201 | AC_ARG_WITH(libxml-include-prefix, 202 | [ --with-libxml-include-prefix=[PFX] Specify location of libxml headers], 203 | LIBXML_CFLAGS="-I$withval" 204 | ) 205 | 206 | AC_ARG_WITH(libxml-libs-prefix, 207 | [ --with-libxml-libs-prefix=[PFX] Specify location of libxml libs], 208 | LIBXML_LIBS="-L$withval" 209 | ) 210 | 211 | AC_ARG_WITH(libxml-src, 212 | [ --with-libxml-src=[DIR] For libxml thats not installed yet (sets all three above)], 213 | LIBXML_SRC="$withval" 214 | ) 215 | AC_SUBST(LIBXML_SRC) 216 | 217 | dnl 218 | dnl where is xml2-config 219 | dnl 220 | 221 | AC_SUBST(LIBXML_REQUIRED_VERSION) 222 | AC_MSG_CHECKING(for libxml libraries >= $LIBXML_REQUIRED_VERSION) 223 | if test "x$LIBXML_CONFIG_PREFIX" != "x" 224 | then 225 | XML_CONFIG=${LIBXML_CONFIG_PREFIX}/bin/xml2-config 226 | else 227 | XML_CONFIG=xml2-config 228 | fi 229 | 230 | dnl 231 | dnl make sure xml2-config is executable, 232 | dnl test version and init our variables 233 | dnl 234 | 235 | if ${XML_CONFIG} --libs > /dev/null 2>&1 236 | then 237 | LIBXML_VERSION=`$XML_CONFIG --version` 238 | if test VERSION_TO_NUMBER(echo $LIBXML_VERSION) -ge VERSION_TO_NUMBER(echo $LIBXML_REQUIRED_VERSION) 239 | then 240 | LIBXML_LIBS="$LIBXML_LIBS `$XML_CONFIG --libs`" 241 | LIBXML_CFLAGS="$LIBXML_CFLAGS `$XML_CONFIG --cflags`" 242 | AC_MSG_RESULT($LIBXML_VERSION found) 243 | else 244 | AC_MSG_ERROR(Version $LIBXML_VERSION found. You need at least libxml2 $LIBXML_REQUIRED_VERSION for this version of libxslt) 245 | fi 246 | else 247 | AC_MSG_ERROR([Could not find libxml2 anywhere, check ftp://xmlsoft.org/.]) 248 | fi 249 | 250 | AC_SUBST(XML_CONFIG) 251 | AC_SUBST(LIBXML_LIBS) 252 | AC_SUBST(LIBXML_CFLAGS) 253 | 254 | 255 | 256 | # 257 | # ---- handle libxslt 258 | # 259 | 260 | LIBXSLT_CONFIG_PREFIX="" 261 | LIBXSLT_SRC="" 262 | 263 | AC_ARG_WITH(libxslt-prefix, 264 | [ --with-libxslt-prefix=[PFX] Specify location of libxslt config], 265 | LIBXSLT_CONFIG_PREFIX=$withval 266 | ) 267 | 268 | AC_ARG_WITH(libxslt-include-prefix, 269 | [ --with-libxslt-include-prefix=[PFX] Specify location of libxslt headers], 270 | LIBXSLT_CFLAGS="-I$withval" 271 | ) 272 | 273 | AC_ARG_WITH(libxslt-libs-prefix, 274 | [ --with-libxslt-libs-prefix=[PFX] Specify location of libxslt libs], 275 | LIBXSLT_LIBS="-L$withval" 276 | ) 277 | 278 | AC_ARG_WITH(libxslt-src, 279 | [ --with-libxslt-src=[DIR] For libxslt thats not installed yet (sets all three above)], 280 | LIBXSLT_SRC="$withval" 281 | ) 282 | AC_SUBST(LIBXSLT_SRC) 283 | 284 | dnl 285 | dnl where is xslt-config 286 | dnl 287 | 288 | AC_SUBST(LIBXSLT_REQUIRED_VERSION) 289 | AC_MSG_CHECKING(for libxslt libraries >= $LIBXSLT_REQUIRED_VERSION) 290 | if test "x$LIBXSLT_CONFIG_PREFIX" != "x" 291 | then 292 | XSLT_CONFIG=${LIBXSLT_CONFIG_PREFIX}/bin/xslt-config 293 | else 294 | XSLT_CONFIG=xslt-config 295 | fi 296 | 297 | dnl 298 | dnl make sure xslt-config is executable, 299 | dnl test version and init our variables 300 | dnl 301 | 302 | if ${XSLT_CONFIG} --libs > /dev/null 2>&1 303 | then 304 | LIBXSLT_VERSION=`$XSLT_CONFIG --version` 305 | if test VERSION_TO_NUMBER(echo $LIBXSLT_VERSION) -ge VERSION_TO_NUMBER(echo $LIBXSLT_REQUIRED_VERSION) 306 | then 307 | LIBXSLT_LIBS="$LIBXSLT_LIBS `$XSLT_CONFIG --libs`" 308 | LIBXSLT_CFLAGS="$LIBXSLT_CFLAGS `$XSLT_CONFIG --cflags`" 309 | AC_MSG_RESULT($LIBXSLT_VERSION found) 310 | else 311 | AC_MSG_ERROR(Version $LIBXSLT_VERSION found. You need at least libxslt $LIBXSLT_REQUIRED_VERSION for this version of libxslt) 312 | fi 313 | else 314 | AC_MSG_ERROR([Could not find libxslt anywhere, check ftp://xmlsoft.org/.]) 315 | fi 316 | 317 | AC_SUBST(XSLT_CONFIG) 318 | AC_SUBST(LIBXSLT_LIBS) 319 | AC_SUBST(LIBXSLT_CFLAGS) 320 | 321 | 322 | 323 | # 324 | # ---- handle libslax 325 | # 326 | 327 | LIBSLAX_CONFIG_PREFIX="" 328 | LIBSLAX_SRC="" 329 | 330 | AC_ARG_WITH(libslax-prefix, 331 | [ --with-libslax-prefix=[PFX] Specify location of libslax config], 332 | LIBSLAX_CONFIG_PREFIX=$withval 333 | ) 334 | 335 | AC_ARG_WITH(libslax-include-prefix, 336 | [ --with-libslax-include-prefix=[PFX] Specify location of libslax headers], 337 | LIBSLAX_CFLAGS="-I$withval" 338 | ) 339 | 340 | AC_ARG_WITH(libslax-libs-prefix, 341 | [ --with-libslax-libs-prefix=[PFX] Specify location of libslax libs], 342 | LIBSLAX_LIBS="-L$withval" 343 | ) 344 | 345 | AC_ARG_WITH(libslax-src, 346 | [ --with-libslax-src=[DIR] For libslax thats not installed yet (sets all three above)], 347 | LIBSLAX_SRC="$withval" 348 | ) 349 | AC_SUBST(LIBSLAX_SRC) 350 | 351 | dnl 352 | dnl where is slax-config 353 | dnl 354 | 355 | AC_SUBST(LIBSLAX_REQUIRED_VERSION) 356 | AC_MSG_CHECKING(for libslax libraries >= $LIBSLAX_REQUIRED_VERSION) 357 | if test "x$LIBSLAX_CONFIG_PREFIX" != "x" 358 | then 359 | SLAX_CONFIG=${LIBSLAX_CONFIG_PREFIX}/bin/slax-config 360 | else 361 | SLAX_CONFIG=slax-config 362 | fi 363 | 364 | dnl 365 | dnl make sure slax-config is executable, 366 | dnl test version and init our variables 367 | dnl 368 | 369 | if ${SLAX_CONFIG} --libs > /dev/null 2>&1 370 | then 371 | LIBSLAX_VERSION=`$SLAX_CONFIG --version` 372 | if test VERSION_TO_NUMBER(echo $LIBSLAX_VERSION) -ge VERSION_TO_NUMBER(echo $LIBSLAX_REQUIRED_VERSION) 373 | then 374 | LIBSLAX_LIBS="$LIBSLAX_LIBS `$SLAX_CONFIG --libs`" 375 | LIBSLAX_CFLAGS="$LIBSLAX_CFLAGS `$SLAX_CONFIG --cflags-internal`" 376 | LIBSLAX_INTERNALDIR="`$SLAX_CONFIG --internal`" 377 | SLAX_EXTDIR="`$SLAX_CONFIG --extdir | head -1`" 378 | SLAX_LIBDIR="`$SLAX_CONFIG --libdir | head -1`" 379 | SLAX_BINDIR="`$SLAX_CONFIG --bindir | head -1`" 380 | SLAX_OXTRADOCDIR="`$SLAX_CONFIG --oxtradoc | head -1`" 381 | AC_MSG_RESULT($LIBSLAX_VERSION found) 382 | else 383 | AC_MSG_ERROR(Version $LIBSLAX_VERSION found. You need at least libslax $LIBSLAX_REQUIRED_VERSION for this version of yangc) 384 | fi 385 | else 386 | AC_MSG_ERROR([Could not find libslax anywhere, check https://github.com/Juniper/libslax.]) 387 | fi 388 | 389 | AC_SUBST(SLAX_CONFIG) 390 | AC_SUBST(LIBSLAX_CFLAGS) 391 | AC_SUBST(LIBSLAX_INTERNALDIR) 392 | AC_SUBST(LIBSLAX_LIBS) 393 | AC_SUBST(SLAX_BINDIR) 394 | AC_SUBST(SLAX_EXTDIR) 395 | AC_SUBST(SLAX_LIBDIR) 396 | AC_SUBST(SLAX_OXTRADOCDIR) 397 | 398 | AC_CHECK_TYPES(socklen_t,,,[#include 399 | #include ]) 400 | 401 | 402 | # 403 | # Find the version of BISON 404 | # 405 | AC_MSG_CHECKING([bison version]) 406 | test -z "${BISON}" && BISON=bison 407 | BISON_VERSION=[`${BISON} --version | grep 'GNU Bison' | cut -d ' ' -f 4 \ 408 | | sed -e 's/[-\.]/ /g' | tr -d a-z \ 409 | | sed -e 's/\([0-9]*\) \([0-9]*\).*/\1.\2/'`] 410 | BISON_VERSION_NUMBER=VERSION_TO_NUMBER(echo $BISON_VERSION) 411 | AC_SUBST(BISON_VERSION) 412 | AC_SUBST(BISON_VERSION_NUMBER) 413 | AM_CONDITIONAL([HAVE_BISON30], [test "$BISON_VERSION_NUMBER" -ge 3000000]) 414 | if test "$BISON_VERSION_NUMBER" -ge 3000000 ; then 415 | AC_DEFINE([HAVE_BISON30], [1], [Bison version >= 3.0]) 416 | fi 417 | AC_MSG_RESULT($BISON_VERSION) 418 | 419 | # 420 | # ---- end of noise 421 | # 422 | 423 | # Cygwin lacks the modern st_mtimespec field in struct stat 424 | AC_MSG_CHECKING([for stat.st_mtimespec]) 425 | AC_COMPILE_IFELSE( 426 | [AC_LANG_PROGRAM([[ 427 | #include 428 | #include 429 | ]], 430 | [[struct stat st; st.st_mtimespec.tv_sec = 0;]])], 431 | [ 432 | AC_MSG_RESULT([yes]) 433 | AC_DEFINE_UNQUOTED([HAVE_MTIMESPEC], 1, 434 | [Define to 1 if you have the `st_mtimespec' field.]) 435 | ], 436 | [ 437 | AC_MSG_RESULT([no]) 438 | AC_DEFINE_UNQUOTED([HAVE_MTIMESPEC], 0, 439 | [Define to 1 if you have the `st_mtimespec' field.]) 440 | ] 441 | ) 442 | 443 | case $host_os in 444 | darwin*) 445 | LIBTOOL=glibtool 446 | SLAX_LIBEXT=dylib 447 | ;; 448 | Linux*|linux*) 449 | CFLAGS="-D_GNU_SOURCE $CFLAGS" 450 | LDFLAGS=-ldl 451 | SLAX_LIBEXT=so 452 | ;; 453 | cygwin*|CYGWIN*) 454 | LDFLAGS=-no-undefined 455 | SLAX_LIBEXT=ddl 456 | ;; 457 | esac 458 | 459 | YANGCDIR="" 460 | 461 | AC_ARG_WITH(yangc-dir, 462 | [ --with-yangc-dir=[DIR] Specify location of yangc files], 463 | [YANGC_DIR=$withval], 464 | [YANGC_DIR=$prefix/share/yangc] 465 | ) 466 | AC_SUBST(YANGC_DIR) 467 | 468 | YANGC_LIBS=-lyang 469 | AC_SUBST(YANGC_LIBS) 470 | YANGC_SRCDIR='${srcdir}' 471 | AC_SUBST(YANGC_SRCDIR) 472 | YANGC_LIBDIR='${libdir}' 473 | AC_SUBST(YANGC_LIBDIR) 474 | YANGC_INCLUDEDIR='${includedir}' 475 | AC_SUBST(YANGC_LIBEXECDIR) 476 | YANGC_LIBEXECDIR='${pkglibexecdir}' 477 | AC_SUBST(YANGC_INCLUDEDIR) 478 | 479 | AC_SUBST(SLAX_LIBEXT) 480 | 481 | dnl for the spec file 482 | RELDATE=`date +'%Y-%m-%d%n'` 483 | AC_SUBST(RELDATE) 484 | UNAME=`uname -a` 485 | 486 | AC_MSG_RESULT(Using configure dir $ac_abs_confdir) 487 | 488 | if test -d $ac_abs_confdir/.git ; then 489 | extra=`git branch | awk '/\*/ { print $2 }'` 490 | if test "$extra" != "" -a "$extra" != "master" 491 | then 492 | YANGC_VERSION_EXTRA="-git-$extra" 493 | fi 494 | fi 495 | 496 | YANGC_VERSION=$PACKAGE_VERSION 497 | YANGC_VERSION_NUMBER=VERSION_TO_NUMBER(echo $PACKAGE_VERSION) 498 | AC_SUBST(YANGC_VERSION) 499 | AC_SUBST(YANGC_VERSION_NUMBER) 500 | AC_SUBST(YANGC_VERSION_EXTRA) 501 | 502 | AC_DEFINE_UNQUOTED(YANGC_VERSION, ["$YANGC_VERSION"], 503 | [Version number as dotted value]) 504 | AC_DEFINE_UNQUOTED(YANGC_VERSION_NUMBER, [$YANGC_VERSION_NUMBER], 505 | [Version number as a number]) 506 | AC_DEFINE_UNQUOTED(YANGC_VERSION_STRING, ["$YANGC_VERSION_NUMBER"], 507 | [Version number as string]) 508 | AC_DEFINE_UNQUOTED(YANGC_VERSION_EXTRA, ["$YANGC_VERSION_EXTRA"], 509 | [Version number extra information]) 510 | AC_DEFINE_UNQUOTED(YANGC_DIR, ["$YANGC_DIR"], 511 | [Directory for YANGC shared files]) 512 | 513 | AC_CONFIG_HEADERS([libyang/yangconfig.h]) 514 | AC_CONFIG_FILES([ 515 | Makefile 516 | yangc-config 517 | libyang/Makefile 518 | libyang/yangversion.h 519 | yangc/Makefile 520 | packaging/yangc.pc 521 | ]) 522 | AC_OUTPUT 523 | 524 | 525 | AC_MSG_NOTICE([summary of build options: 526 | 527 | build system: ${UNAME} 528 | 529 | yangc version: ${VERSION} ${YANGC_VERSION_EXTRA} 530 | host type: ${host} 531 | install prefix: ${prefix} 532 | compiler: ${CC} 533 | compiler flags: ${CFLAGS} 534 | library types: Shared=${enable_shared}, Static=${enable_static} 535 | 536 | libxml version: ${LIBXML_VERSION} 537 | libxml cflags: ${LIBXML_CFLAGS} 538 | libxml libs: ${LIBXML_LIBS} 539 | 540 | libxslt version: ${LIBXSLT_VERSION} 541 | libxslt cflags: ${LIBXSLT_CFLAGS} 542 | libxslt libs: ${LIBXSLT_LIBS} 543 | 544 | libslax version: ${LIBSLAX_VERSION} 545 | libslax cflags: ${LIBSLAX_CFLAGS} 546 | libslax headers: ${LIBSLAX_INTERNALDIR} 547 | libslax libs: ${LIBSLAX_LIBS} 548 | libslax libdir: ${SLAX_LIBDIR} 549 | libslax extdir: ${SLAX_EXTDIR} 550 | 551 | warnings: ${YANGC_WARNINGS:-no} 552 | debug: ${YANGC_DEBUG:-no} 553 | readline: ${HAVE_READLINE:-no} 554 | libedit: ${HAVE_LIBEDIT:-no} 555 | printf-like: ${HAVE_PRINTFLIKE:-no} 556 | ]) 557 | -------------------------------------------------------------------------------- /test/core/common-inc.yang: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1998-2008,2014, Juniper Networks, Inc. 3 | * All rights reserved. 4 | */ 5 | 6 | submodbule common-inc { 7 | param $ddl_maxpathlen = 1024; 8 | param $MCHASSIS_UI_MAX_LCC_SLOT = 3; 9 | param $MCHASSIS_UI_MAX_VC_MEMBER_ID = 10; 10 | 11 | param $MAX_UINT = 4294967295; 12 | param $MAX_INT = 2147483647; 13 | 14 | param $PID_MAX = 99999; 15 | 16 | param $GB_MAC_TABLE_LIMIT_MIN = 20; 17 | param $GB_MAC_TABLE_LIMIT_MAX = 1048575; 18 | 19 | param $MAX_SIMPLE_STRING_LENGTH = 254; 20 | 21 | /* 22 | * Minimum IPv6 PMTU discovery timeout in minutes, as 23 | * mandated in RFC 1981 (Path MTU Discovery for IP version 6) 24 | */ 25 | param $MIN_IPV6_PMTU_TIMEOUT = 5; 26 | 27 | /* 28 | * Maximum IPv6 PMTU discovery timeout in minutes. 29 | * This is equivalent to maximum time in minutes that can 30 | * be represented by 4294967295 (MAX_UINT) seconds 31 | * This is around 136 years, good enough to cover expected lifetime 32 | * of a router. 33 | */ 34 | param $MAX_IPV6_PMTU_TIMEOUT = 71582788; 35 | 36 | typedef percent { 37 | type uint { 38 | range 0 .. 100; 39 | } 40 | } 41 | 42 | /* 43 | * VLAN Range string format. 44 | */ 45 | grouping vlan-range-format-check { 46 | match "^(([1-9][0-9]{0,2}|[1-3][0-9]{3}|40[0-8][0-9]|409[0-4])" 47 | "\-([1-9][0-9]{0,2}|[1-3][0-9]{3}|40[0-8][0-9]|409[0-4]))$" { 48 | -message "Must be a string in the format <1-4094>-<1-4094>"; 49 | } 50 | } 51 | 52 | /* 53 | * VLAN Tag format. 54 | */ 55 | grouping vlan-tag-format-check { 56 | match "^(([1-9][0-9]{0,2}|[1-3][0-9]{3}|40[0-8][0-9]|409[0-4]))$" { 57 | message "VLAN ID has to be an integer between 1 and 4094"; 58 | } 59 | } 60 | 61 | /* 62 | * VLAN Name string format. 63 | */ 64 | grouping vlan-name-format-check { 65 | match "^[[:alpha:]][[:alnum:]_.-]+$" { 66 | message "Must be a string of length atleast 2 beginning " 67 | "with a letter and consisting of letters, numbers, " 68 | "periods, dashes, and underscores"; 69 | } 70 | } 71 | 72 | /* 73 | * Regular expression for specifying VLAN Range or VLAN Tag 74 | */ 75 | grouping vlan-range-or-tag-format-check { 76 | match "^(([1-9][0-9]{0,2}|[1-3][0-9]{3}|40[0-8][0-9]|409[0-4]))" 77 | "$|^(([1-9][0-9]{0,2}|[1-3][0-9]{3}|40[0-8][0-9]|409[0-4])" 78 | "\-([1-9][0-9]{0,2}|[1-3][0-9]{3}|40[0-8][0-9]|409[0-4]))$" { 79 | message "Must be a valid VLAN range string or VLAN tag"; 80 | } 81 | } 82 | 83 | /* 84 | * Regular expression for specifying VLAN Name or VLAN Tag 85 | */ 86 | grouging vlan-name-or-tag-format-check { 87 | match "^([[:alpha:]][[:alnum:]_.-]+)|^([1-9][0-9]{0,2}" 88 | "|[1-3][0-9]{3}|40[0-8][0-9]|409[0-4])$" { 89 | message "Must be a valid VLAN name or VLAN tag"; 90 | } 91 | } 92 | 93 | /* 94 | * Regular expression for specifying VLAN Name or VLAN Tag or 95 | * VLAN Range string 96 | */ 97 | grouping vlan-reference-string-format-check { 98 | match "(^([[:alpha:]][[:alnum:]_.-]+)$)" 99 | "|(^([1-9][0-9]{0,2}|[1-3][0-9]{3}|40[0-8][0-9]|409[0-4])$)" 100 | "|(^(([1-9][0-9]{0,2}|[1-3][0-9]{3}|40[0-8][0-9]|409[0-4])" 101 | "\-([1-9][0-9]{0,2}|[1-3][0-9]{3}|40[0-8][0-9]|409[0-4]))$)" { 102 | message "Must be a valid VLAN name, VLAN tag or " 103 | "VLAN range string"; 104 | } 105 | } 106 | 107 | /* 108 | * L2 circuit range for virtual circuit identifier. 109 | */ 110 | param $L2CKT_VC_ID_MIN = 1; 111 | param $L2CKT_VC_ID_MAX = 0xffffffff; 112 | 113 | /* 114 | * L2 circuit range for switchover delay to backup 115 | */ 116 | param $L2CKT_SWITCH_DELAY_MIN = 0; 117 | param $L2CKT_SWITCH_DELAY_MAX = 180000; 118 | 119 | /* 120 | * Min-max range for configured MTU. 121 | */ 122 | param $L2CKT_INTF_MTU_MIN = 512; 123 | param $L2CKT_INTF_MTU_MAX = 65535; 124 | 125 | /* 126 | * L2 circuit revertive timer delay range (in secs) 127 | */ 128 | param $L2CKT_REVERT_TIME_MIN = 0; 129 | param $L2CKT_REVERT_TIME_MAX = 600; 130 | 131 | /* 132 | * Min-max range for incoming static labels 133 | */ 134 | param $L2CKT_STATIC_IN_LABEL_MIN = 1000000; 135 | param $L2CKT_STATIC_IN_LABEL_MAX = 1048575; 136 | 137 | /* 138 | * Min-max range for outgoing static labels 139 | */ 140 | param $L2CKT_STATIC_OUT_LABEL_MIN = 16; 141 | param $L2CKT_STATIC_OUT_LABEL_MAX = 1048575; 142 | 143 | 144 | template enab-disab-leaf ($parameter, $help) { 145 | leaf enab_disab { 146 | help $help; 147 | xml-name enable-disable; 148 | flag nokeyword; 149 | default enable; 150 | type enumeration { 151 | enum enable { 152 | hidden default; 153 | value TRUE; 154 | help "Enable parameter"; 155 | } 156 | enum disable { 157 | value FALSE; 158 | help "Disable parameter"; 159 | } 160 | } 161 | } 162 | } 163 | 164 | template conditional-enab-disab-leaf ($parameter, $condition) { 165 | leaf enab_disab { 166 | xml-name enable-disable; 167 | flag nokeyword; 168 | default enable; 169 | type enumeration { 170 | enum enable { 171 | hidden default; 172 | if ($condition) { 173 | copy-of $condition; 174 | } 175 | value TRUE; 176 | help "Enable parameter"; 177 | } 178 | choice disable { 179 | if ($condition) { 180 | copy-of $condition; 181 | } 182 | value FALSE; 183 | help "Disable parameter"; 184 | } 185 | } 186 | } 187 | } 188 | 189 | template nodefault-enab-disab-leaf ($parameter) { 190 | leaf enab_disab { 191 | xml-name enable-disable; 192 | flag nokeyword; 193 | type enumeration { 194 | enum enable { 195 | hidden unconditional; 196 | value TRUE; 197 | help "Enable " _ $parameter; 198 | } 199 | enum disable { 200 | value FALSE; 201 | help "Disable " _ $parameter; 202 | } 203 | } 204 | } 205 | } 206 | 207 | template mandatory-enab-disab-leaf ($parameter) { 208 | leaf enab_disab { 209 | xml-name enable-disable; 210 | flag nokeyword mandatory; 211 | type enumeration { 212 | enum enable { 213 | value TRUE; 214 | help "Enable " _ $parameter; 215 | } 216 | enum disable { 217 | value FALSE; 218 | help "Disable "_ $parameter; 219 | } 220 | } 221 | } 222 | } 223 | 224 | template hidden-enab-disab-leaf ($parameter) { 225 | leaf enab_disab { 226 | xml-name enable-disable; 227 | flag nokeyword; 228 | default enable; 229 | type enumeration { 230 | enum enable { 231 | hidden default; 232 | value TRUE; 233 | help "Enable " _ $parameter; 234 | } 235 | enum disable { 236 | hidden deprecated; 237 | value FALSE; 238 | help "Disable " _ $parameter; 239 | } 240 | } 241 | } 242 | } 243 | 244 | template process-location ($parameter) { 245 | leaf "command" { 246 | hidden support; 247 | flag mustquote; 248 | help "Path for " _ $parameter; 249 | require wheel; 250 | type string { 251 | range 1 .. DDL_MAXPATHLEN; 252 | } 253 | } 254 | } 255 | 256 | template toggle-option ($keyword, $flagline, $helptext) { 257 | leaf keyword { 258 | flag $flagline; 259 | flag allow-no; 260 | help $helptext; 261 | type toggle; 262 | } 263 | } 264 | 265 | template intf-toggle-option ($keyword, $flagline, $helptext, $interfaces, 266 | $var_line) { 267 | leaf $keyword { 268 | flag $flagline; 269 | flag allow-no; 270 | help $helptext; 271 | type toggle; 272 | interface-acceptable $interfaces; 273 | copy-of $var_line; 274 | } 275 | } 276 | 277 | grouping cos-max-name-len { 278 | match "^.{1,64}$" { 279 | message "Must be string of 64 characters or less"; 280 | } 281 | } 282 | 283 | grouping cos-max-alpha-name-len { 284 | match "^([a-zA-Z].{0,63})$" { 285 | message "Must be string of 64 characters or less " 286 | "beginning with letter"; 287 | } 288 | } 289 | 290 | grouping cos-routing-instance-name-check { 291 | match "!^(([\*]{1,})|(__.*__)|(.{129,}))$" { 292 | message "Must be a non-reserved string of 128 characters or less"; 293 | } 294 | } 295 | 296 | param $COS_6BIT_ALIAS_MATCH = "^(([01]{6})|([a-zA-Z].{0,63}))$"; 297 | param $COS_6BIT_ALIAS_MATCH_MSG = "Not 6-bit pattern or code point alias"; 298 | 299 | param $COS_3BIT_ALIAS_MATCH = "^(([01]{3})|([a-zA-Z].{0,63}))$"; 300 | param $COS_3BIT_ALIAS_MATCH_MSG = "Not 3-bit pattern or code point alias"; 301 | 302 | param $IPSEC_SA_MAX_NAME_LEN = 32; /* Maximum length of ipsec sa name. */ 303 | 304 | template access-nai-check ($attr_name) { 305 | action commit { 306 | daemon mgd; 307 | function "return mgd_validate_rfc2486(daap, \"" 308 | _ $attr_name _ "\");"; 309 | } 310 | } 311 | 312 | template access-nai-check-wildcard ($attr_name) { 313 | action commit { 314 | daemon mgd; 315 | function "return mgd_validate_rfc2486_or_asterisk(daap, \"" 316 | _ $attr_name _ "\");"; 317 | } 318 | } 319 | 320 | grouping access-nai-no-rfc2486-toggle { 321 | leaf no-rfc2486 { 322 | type toggle; 323 | help "RFC2486 compliance is not enforced"; 324 | } 325 | } 326 | 327 | param $ACCESS_MAX_NAME_LEN = 64; 328 | param $DYN_PROF_MAX_NAME_LEN = 80; 329 | 330 | grouping filename-check { 331 | match "![/ %]" { 332 | message "Must not contain '/', % or a space"; 333 | } 334 | } 335 | 336 | /* 337 | * check for routing instance names 338 | */ 339 | 340 | grouping instance-name-check { 341 | match "!^((__.*__)|(all)|(.*[ ].*)|(.{129,}))$" { 342 | message "Must be a non-reserved string of 128 characters " 343 | "or less with no spaces"; 344 | } 345 | } 346 | 347 | /* 348 | * The topology name must be 128 or less characters and not 349 | * contain a colon. 350 | */ 351 | grouping topology-name-check { 352 | match "!^((.*:.*)|(.{129,}))$" { 353 | message "Must be a non-reserved string of 128 characters or less"; 354 | } 355 | } 356 | 357 | grouping bd-name-check { 358 | match "!^((__.*__)|(.{129,})|(.*[+].*))$" { 359 | message "Must be a non-reserved string of 128 characters or less"; 360 | } 361 | } 362 | 363 | grouping instance-existence-check { 364 | path-reference "routing-instances <*>"; 365 | must "routing-instances $$" { 366 | message "referenced routing-instance must be defined"; 367 | } 368 | } 369 | 370 | grouping instance-reference ($hide) { 371 | leaf routing-instance { 372 | help "Use specified routing instance"; 373 | type string; 374 | if ($hide) { 375 | hidden $hide; 376 | } 377 | uses instance-existence-check; 378 | } 379 | } 380 | 381 | grouping instance-type-check { 382 | path-reference "routing-instances <*>"; 383 | must "routing-instances $$ instance-type" { 384 | message "'instance-type' for the referenced routing-instance " 385 | "must be configured"; 386 | } 387 | } 388 | 389 | grouping instance-name-validate { 390 | use instance-name-check; 391 | use instance-existence-check; 392 | } 393 | 394 | /* 395 | * Common match expression for user login names 396 | */ 397 | grouping user-login-name-check { 398 | match "^[[:alnum:]_]{1,}[.]{0,1}[[:alnum:]_-]{0,}$" { 399 | message "Must contain characters (alphanumerics, underscores " 400 | "or hyphens) beginning with an alphanumeric or an " 401 | "underscore character."; 402 | } 403 | } 404 | 405 | /* 406 | * Limit on the name and content of a service-set name 407 | */ 408 | grouping services-name-len-check { 409 | match "^[A-Za-z0-9][_0-9A-Za-z-]{0,62}$" { 410 | message "Must be a string beginning with a number or letter " 411 | "and consisting of no more than 63 total letters, " 412 | "numbers, dashes and underscores."; 413 | } 414 | } 415 | 416 | /* 417 | * Products supporting the GGSN PIC 418 | */ 419 | param $PRODUCTS_SUPPORTING_GGSN = "m5 m10 m20 m120 m320"; 420 | 421 | /* 422 | * declares a type of regex with length restrictions 423 | */ 424 | template length-restricted-regex ($len) { 425 | type regular-expression; 426 | } 427 | 428 | /* 429 | * a port.. 430 | */ 431 | typedef port { 432 | type ushort { 433 | range 1 .. 65535; 434 | } 435 | } 436 | 437 | grouping radius-target-hostname { 438 | key address; 439 | leaf address { 440 | type hostname; 441 | help "RADIUS server address"; 442 | } 443 | } 444 | 445 | grouping radius-target-ipaddr { 446 | key address; 447 | leaf address { 448 | help "RADIUS server address"; 449 | type ipv4addr; 450 | flag unicast-only; 451 | match "!^127\.0\.0\.1" { 452 | message "The loopback address cannot be used"; 453 | } 454 | } 455 | } 456 | 457 | grouping radius-target-ports { 458 | leaf port { 459 | alias authentication-port; 460 | help "RADIUS server authentication port number"; 461 | type ushort { 462 | range 1 .. 65535; 463 | } 464 | default 1812; 465 | } 466 | leaf accounting-port { 467 | help "RADIUS server accounting port number"; 468 | type ushort { 469 | range 1 .. 65535; 470 | } 471 | default 1813; 472 | } 473 | } 474 | 475 | grouping radius-target-leafs { 476 | use radius-target-ipaddr; 477 | use radius-target-ports; 478 | } 479 | 480 | grouping radius-common-leafs { 481 | leaf secret { 482 | help "Shared secret with the RADIUS server"; 483 | type unreadable; 484 | flag secret mandatory; 485 | require secret; 486 | } 487 | leaf timeout { 488 | help "Request timeout period"; 489 | type uint { 490 | range 1 .. 90; 491 | } 492 | default 3; 493 | units seconds; 494 | } 495 | leaf retry { 496 | help "Retry attempts"; 497 | type uint { 498 | range 1 .. 10; 499 | } 500 | default 3; 501 | } 502 | leaf max-outstanding-requests { 503 | help "Maximum requests in flight to server"; 504 | type uint { 505 | range 0 .. 2000; 506 | } 507 | default 1000; 508 | } 509 | } 510 | 511 | /* 512 | * For SNMP Object ID's 513 | * (note, '\.' doesn't work in the match reg expressions) 514 | */ 515 | typedef oid-name-type { 516 | type string; 517 | match "^([.]?1|[a-zA-Z][a-zA-Z0-9]*)([.]([a-zA-Z]|[0-9]+))*$" { 518 | message "Must be an OID of the form 1.x.y.z... " 519 | "or objname[.x.y.z] where x, y, & z are either numbers " 520 | "or a single letter"; 521 | } 522 | } 523 | 524 | /* 525 | * For use when multiple objects can be entered 526 | */ 527 | typedef oid-name-type-mult { 528 | type string; 529 | match "^(([.]?1|[a-zA-Z][a-zA-Z0-9]*)([.]([a-zA-Z]|[0-9]+))*" 530 | "([ ]|$))+$" { 531 | message "Must be an OID of the form 1.x.y.z... " 532 | "or objname[.x.y.z] where x, y, & z are either numbers " 533 | "or a single letter"; 534 | } 535 | } 536 | 537 | /* 538 | * Restriction for named entities in the services configuration 539 | */ 540 | grouping services-reserved-name-check { 541 | match "^[[:alnum:]][[:alnum:]_-]*$" { 542 | message "Must be a string beginning with a number " 543 | "or letter and consisting of letters, numbers, " 544 | "dashes and underscores."; 545 | } 546 | } 547 | 548 | /* 549 | * KMD stuff for the maximum name length 550 | */ 551 | param $KMD_MAX_NAME_LEN = 32; /**< maximum name length that should be 552 | * kept in sync with 553 | * KMD_CHECK_MAX_NAME_LEN check */ 554 | 555 | grouping kmd-check-max-name-len { 556 | match "^.{1,32}$" { 557 | message "Must be string of 32 characters or less"; 558 | } 559 | } 560 | 561 | param $KMD_MAX_ENROLLMENT_RETRIES = 1080; 562 | param $KMD_MAX_ENROLLMENT_RETRY_INTERVAL = 3600; 563 | param $KMD_MAX_CRL_REFRESH_TIME = 8784; /* One year */ 564 | param $KMD_MAX_CRL_URL_STRING_LEN = 500; 565 | 566 | grouping default-tcp-auth-alg { 567 | leaf authentication-algorithm { 568 | default hmac-sha-1-96; 569 | } 570 | } 571 | 572 | template chap-secret-leaf ($attr_name, $help_msg) { 573 | leaf $attr_name { 574 | help $help_msg; 575 | type unreadable; 576 | flag secret; 577 | require secret; 578 | } 579 | } 580 | 581 | grouping vlan-id-range-check { 582 | match "^(0[Xx][0-9A-Fa-f]{4}\." 583 | "([0-9]{1,3}|1[0-9]{3}|2[0-9]{3}|3[0-9]{3}|40[0-8][0-9]" 584 | "|409[0-4]))$|^([0-9]{1,3}|1[0-9]{3}|2[0-9]{3}|3[0-9]{3}" 585 | "|40[0-8][0-9]|409[0-4])$" { 586 | message "vlan-id in vlan-tag (0xNNNN.vlan-id) must be 0 to 4094"; 587 | } 588 | } 589 | 590 | grouping regulation-count-valid-values { 591 | match "^(once|100|[0-9]{1,2})$" { 592 | message "Regulation can be 0-100 percentage or 'once'"; 593 | } 594 | } 595 | 596 | /* 597 | * Route Target and Route Origin definition syntax. Defined at a common, 598 | * place to avoid duplication and hence to maintain consistency. 599 | * 600 | * Format is target|origin:[L] or IP Address: 601 | * Use L to specify 4 byte AS. 602 | */ 603 | param $ROUTE_TARGET_FORMAT = "^[a-z]+:[0-9\.]+L?:[0-9]+$"; 604 | param $ROUTE_TARGET_FORMAT_MSG = 605 | "Use format 'target:x:y' where 'x' is an AS number followed by " 606 | "an optional 'L' (To indicate 4 byte AS), or an IP address and " 607 | "'y' is a number. e.g. target:123456L:100"; 608 | 609 | param $ROUTE_TARGET_FILTER_FORMAT = 610 | "^[0-9\.]{1,15}L?:[0-9]{1,10}/([0-9]|[2-5][0-9]|6[0-4])$"; 611 | param $ROUTE_TARGET_FILTER_FORMAT_MSG = 612 | "Use format 'x:y/len' where 'x' is an AS number followed by " 613 | "an optional 'L' (To indicate 4 byte AS), or an IP address and " 614 | "'y' is a number. e.g. 123456L:100 and len is a prefix length from " 615 | "0 to 64"; 616 | 617 | param $ROUTE_ORIGIN_FORMAT = "^[a-z]+:[0-9\.]+L?:[0-9]+$"; 618 | param $ROUTE_ORIGIN_FORMAT_MSG = 619 | "Use format 'origin:x:y' where 'x' is an AS number followed by " 620 | "an optional 'L' (To indicate 4 byte AS), or an IP address and " 621 | "'y' is a number. e.g. target:1.2.3.4:100"; 622 | 623 | param $RT_CONSTRAIN_FORMAT = 624 | "^[0-9]{1,15}:[0-9\.]{1,15}L?:[0-9]{1,10}/(0|3[2-9]|[4-8][0-9]|9[0-6])$"; 625 | param $RT_CONSTRAIN_FORMAT_MSG = 626 | "Use format 'as:x:y/len' where 'as' is an AS number and " 627 | "'x' is an AS number followed by " 628 | "an optional 'L' (To indicate 4 byte AS), or an IP address and " 629 | "'y' is a number. e.g. 123456L:100 and len is a prefix length from " 630 | "32 to 96 or 0"; 631 | 632 | param $L2VPN_ID_FORMAT = "^(l2vpn-id)+:[0-9\.]+:[0-9]+$"; 633 | param $L2VPN_ID_FORMAT_MSG = 634 | "Use format 'l2vpn-id:x:y' where 'x' is 2 byte AS number, " 635 | "or an IP address and 'y' is a number. e.g. l2vpn-id:1:100, " 636 | "l2vpn-id:1.2.3.4:100"; 637 | 638 | param $PRODUCTS_SUPPORTING_FTAPLITE = "m120 m320 " _ $MX_SERIES; 639 | 640 | /* 641 | * Route distinguisher definition syntax. Defined at a common place, 642 | * to avoid duplication and hence to maintain consistency. 643 | * 644 | * Format is [L] or IP Address: 645 | * Use L to specify 4 byte AS. 646 | */ 647 | param $ROUTE_DISTINGUISHER_FORMAT = "^[0-9\.]+L?:[0-9]+$"; 648 | param ROUTE_DISTINGUISHER_FORMAT_MSG = 649 | "Use format 'x:y' where 'x' is an AS number followed by " 650 | "an optional 'L' (To indicate 4 byte AS), or an IP address and " 651 | "'y' is a number. e.g. 123456L:100"; 652 | 653 | grouping port-mirror-association-check { 654 | path-reference "forwarding-options port-mirroring instance <*>"; 655 | must "forwarding-options port-mirroring instance $$" { 656 | message "Referenced port-mirroring instance does not exist"; 657 | } 658 | } 659 | 660 | grouping port-mirror-exclude-derived-instance-binding { 661 | path-reference "forwarding-options port-mirroring instance <*>"; 662 | jmust "not(forwarding-options port-mirroring instance " 663 | "$$ input-parameters-instance)" { 664 | message "Derived instance cannot be binded"; 665 | } 666 | } 667 | 668 | grouping sampling-association-check { 669 | path-reference "forwarding-options sampling instance <*>"; 670 | must "forwarding-options sampling instance $$" { 671 | message "Referenced sampling instance does not exist"; 672 | } 673 | } 674 | 675 | grouping juniper-def-routing-switch-options { 676 | leaf switch-options { 677 | help "Options for default routing-instance of type virtual-switch"; 678 | exemption top_level_tag-1-sgoudar-3e7baafb3ac67d2959922c88ea37f458; 679 | notify l2ald; 680 | require routing; 681 | flag remove-empty; 682 | ACTION_MX_SERIES_L2_SHOW_ONLY; 683 | feature-id "switch-option"; 684 | type juniper-def-rtb-switch-options; 685 | } 686 | } 687 | 688 | template leaf-shared-with ($args) { 689 | container shared-with { 690 | help "Name of the resource used to import a shared-id"; 691 | flag oneliner; 692 | notify DNAME_VSYNCD; 693 | 694 | leaf shared-name { 695 | help "Name of the shared-with entity"; 696 | flag nokeyword; 697 | mandatory yes; 698 | type string { 699 | range 1..64; 700 | } 701 | use instance-name-check; 702 | must "virtual-node" { 703 | message "To configure shared-with, virtual-node " 704 | "should be set"; 705 | } 706 | copy-of $args; 707 | } 708 | } 709 | } 710 | 711 | grouping member-role-choice { 712 | choice member-role { 713 | flag strict-order; 714 | argument master { 715 | help "Run command on master"; 716 | option "-m master"; 717 | type empty; 718 | } 719 | argument backup { 720 | help "Run command on backup"; 721 | option "-m backup"; 722 | type argument; 723 | } 724 | } 725 | } 726 | } 727 | --------------------------------------------------------------------------------