### Install Library Files Source: https://github.com/cesnet/libyang/blob/master/CMakeLists.txt Installs the compiled 'yang' target and header files to their respective installation directories. ```cmake install(TARGETS yang DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(FILES ${headers} ${g_headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libyang) ``` -------------------------------- ### Install Dependencies and Build Package Source: https://github.com/cesnet/libyang/blob/master/distro/README.md Installs git, rpm-build, and python3-pip using dnf, then installs apkg via pip and builds the package. ```bash sudo dnf install -y git rpm-build python3-pip pip3 install apkg apkg build -i ``` -------------------------------- ### Generate and Install pkg-config File Source: https://github.com/cesnet/libyang/blob/master/CMakeLists.txt Configures, generates, and installs the pkg-config file for libyang if PkgConfig is found. It also checks if the installation path is correctly added to pkg-config's search path. ```cmake find_package(PkgConfig) if(PKG_CONFIG_FOUND) # generate and install pkg-config file configure_file("libyang.pc.in" "libyang.pc" @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libyang.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") # check that pkg-config includes the used path execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable pc_path pkg-config RESULT_VARIABLE RETURN OUTPUT_VARIABLE PC_PATH ERROR_QUIET) if(RETURN EQUAL 0) string(STRIP "${PC_PATH}" PC_PATH) set(PC_PATH "${PC_PATH}:$ENV{PKG_CONFIG_PATH}") string(REGEX MATCH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig" SUBSTR "${PC_PATH}") string(LENGTH "${SUBSTR}" SUBSTR_LEN) if(SUBSTR_LEN EQUAL 0) message(WARNING "pkg-config will not detect the new package after installation, adjust PKG_CONFIG_PATH using \"export PKG_CONFIG_PATH=\\\${PKG_CONFIG_PATH}:\\\${CMAKE_INSTALL_PREFIX}/\\\${CMAKE_INSTALL_LIBDIR}/pkgconfig\".") endif() endif() endif() ``` -------------------------------- ### Install YANG Modules Source: https://github.com/cesnet/libyang/blob/master/CMakeLists.txt Installs YANG module files from the source directory to the destination module directory. ```cmake install(DIRECTORY "${PROJECT_SOURCE_DIR}/modules/" DESTINATION ${YANG_MODULE_DIR} FILES_MATCHING PATTERN "*.yang") ``` -------------------------------- ### Get Help for a Specific Yanglint Command Source: https://github.com/cesnet/libyang/blob/master/tools/lint/examples/README.md Use 'help' followed by a command name to get detailed usage information for that specific command. ```bash > help searchpath Usage: searchpath [--clear] [ ...] Set paths of directories where to search for imports and includes of the schema modules. Subdirectories are also searched. The current working directory and the path of the module being added is used implicitly. The 'load' command uses these paths to search even for the schema modules to be loaded. ``` -------------------------------- ### Change Install Path with CMake Source: https://github.com/cesnet/libyang/blob/master/README.md Customize the installation prefix for libyang by setting the CMAKE_INSTALL_PREFIX variable during CMake configuration. ```bash cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .. ``` -------------------------------- ### Run AFL Fuzzing Instances (Master and Slave) Source: https://github.com/cesnet/libyang/blob/master/tests/fuzz/README.md Start AFL fuzzing with input and output directories, specifying master and slave modes for multiple cores. ```bash afl-fuzz -i minimised_testcases/ -o syncdir/ -M fuzzer1 -- libyang/build/tests/fuzz/lyd_parse_mem_fuzz_harness afl-fuzz -i minimised_testcases/ -o syncdir/ -S fuzzer2 -- libyang/build/tests/fuzz/lyd_parse_mem_fuzz_harness ``` -------------------------------- ### Link libyang Library Source: https://github.com/cesnet/libyang/blob/master/README.md Link your program with the libyang library using these linker parameters. Ensure the library is installed and accessible. ```bash -lyang ``` -------------------------------- ### Add a Simple Plugin Source: https://github.com/cesnet/libyang/blob/master/tests/plugins/CMakeLists.txt Example of calling the `ly_add_plugin` function to add a plugin named 'simple' with source file 'simple.c'. ```cmake ly_add_plugin(NAME simple SOURCES simple.c) ``` -------------------------------- ### Enable Code Coverage with CMake Source: https://github.com/cesnet/libyang/blob/master/README.md Enable code coverage reporting. This requires additional setup and tools to generate the report after running tests. ```bash cmake -DENABLE_COVERAGE=ON .. ``` ```bash make ``` ```bash make coverage ``` -------------------------------- ### Get next extension instance Source: https://github.com/cesnet/libyang/blob/master/doc/compat_report_4_5.html Retrieves the next extension instance associated with a schema node. Used for iterating through extensions. ```c lys_getnext_ext(struct lysc_node const* last, struct lysc_node const* parent, struct lysc_ext_instance const* ext, uint32_t options) ``` -------------------------------- ### Function Definition Style Source: https://github.com/cesnet/libyang/blob/master/CONTRIBUTING.md Place the return type, function name, and opening brace on separate lines, all starting at column 0. This applies to standard function definitions. ```c static int foo(int arg) { ... ``` -------------------------------- ### Basic Build Process Source: https://github.com/cesnet/libyang/blob/master/doc/build.dox Standard commands to build libyang with default settings. Navigate to a build directory, configure with CMake, and compile with make. ```bash mkdir build; cd build cmake .. make # make install ``` -------------------------------- ### Display Available Commands in Yanglint Source: https://github.com/cesnet/libyang/blob/master/tools/lint/examples/README.md Use the 'help' command to list all available commands in the yanglint interactive mode. ```bash > help Available commands: help Display commands description add Add a new module from a specific file load Load a new schema from the searchdirs print Print a module data Load, validate and optionally print instance data ext Validate extension data list List all the loaded modules feature Print all features of module(s) with their state searchpath Print/set the search path(s) for schemas clear Clear the context - remove all the loaded modules verb Change verbosity debug Display specific debug message groups quit Quit the program ? Display commands description exit Quit the program ``` -------------------------------- ### Load and List Data Models in Yanglint Source: https://github.com/cesnet/libyang/blob/master/tools/lint/examples/README.md Demonstrates clearing the context, adding a YANG module, and listing the loaded modules. This is a preparation step for detecting duplicate namespaces. ```bash > clear > add module1.yang > list ``` ```text List of the loaded models: i ietf-yang-metadata@2016-08-05 I yang@2016-08-05 i ietf-inet-types@2013-07-15 i ietf-yang-types@2013-07-15 I ietf-yang-schema-mount@2019-01-14 I module1 ``` -------------------------------- ### Prepare Multiple YANG Modules Source: https://github.com/cesnet/libyang/blob/master/tools/lint/examples/README.md Loads multiple YANG modules to support validation of documents with multiple top-level elements. ```bash > clear > add ietf-netconf-acm.yang > add ietf-interfaces.yang > add ietf-ip.yang > add iana-if-type.yang ``` -------------------------------- ### Get YANG library data Source: https://github.com/cesnet/libyang/blob/master/doc/compat_report_4_5.html Retrieves YANG library data from the context. Used for managing YANG module information. ```c ly_ctx_get_yanglib_data(struct ly_ctx const* _ctx_, struct lyd_node** root_p, char const* _content_id_format_, ...) ``` -------------------------------- ### Generate Configuration Data in JSON Format Source: https://github.com/cesnet/libyang/blob/master/tools/lint/examples/README.md Demonstrates generating configuration data in JSON format from a YANG model. This is useful for creating or inspecting configuration files. ```bash > data -f json -t config data-ip.xml ``` -------------------------------- ### Print Tree Output of YANG Model with Schema Mount Source: https://github.com/cesnet/libyang/blob/master/tools/lint/examples/README.md Illustrates printing a YANG model that uses the Schema Mount extension, showing the structure of mounted data. This is useful for debugging and understanding schema mount configurations. ```bash $ yanglint -f tree -p . -Y sm-context-main.xml -x sm-context-extension.xml sm-main.yang ``` -------------------------------- ### Prepare YANG Module Source: https://github.com/cesnet/libyang/blob/master/tools/lint/examples/README.md Clears the context and adds a YANG module to the yanglint environment. This is a common preparation step before validating data. ```bash > clear > add ietf-netconf-acm.yang ``` -------------------------------- ### Add an Invalid Plugin Source: https://github.com/cesnet/libyang/blob/master/tests/plugins/CMakeLists.txt Example of calling the `ly_add_plugin` function to add a plugin named 'invalid' with source file 'invalid.c'. ```cmake ly_add_plugin(NAME invalid SOURCES invalid.c) ``` -------------------------------- ### Get identity module for a type Source: https://github.com/cesnet/libyang/blob/master/doc/compat_report_4_5.html Retrieves the identity module for a given context node and type format. Used in type handling and validation. ```c lyplg_type_identity_module(struct ly_ctx const* ctx, struct lysc_node const* ctx_node, char const* prefix, uint32_t prefix_len, enum LY_VALUE_FORMAT format, void const* prefix_data) ``` -------------------------------- ### Build Static libyang Library Source: https://github.com/cesnet/libyang/blob/master/CMakeLists.txt Configures the build to create a static libyang library. It sets definitions and library search paths for static linking. ```cmake if(NOT BUILD_SHARED_LIBS) add_definitions(-DSTATIC) # allow binaries compilation linking both static and dynamic libraries never linking static glibc #set(CMAKE_EXE_LINKER_FLAGS -static) # prefer static libraries set(CMAKE_FIND_LIBRARY_SUFFIXES .a;.so) set(CMAKE_LINK_SEARCH_START_STATIC TRUE) set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS) # remove -Wl,-Bdynamic set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS) add_library(yang STATIC ${libsrc} ${compatsrc}) else() set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) add_library(yangobj OBJECT ${libsrc} ${compatsrc}) if(NOT WIN32) set_target_properties(yangobj PROPERTIES COMPILE_FLAGS "-fvisibility=hidden") endif() target_compile_definitions(yangobj PRIVATE LIBYANG_BUILD) add_library(yang SHARED $) if(WIN32) find_package(dlfcn-win32 REQUIRED) set(CMAKE_DL_LIBS dlfcn-win32::dl) endif() #link dl target_link_libraries(yang ${CMAKE_DL_LIBS}) endif() ``` -------------------------------- ### Prepare and Validate Extension Data Source: https://github.com/cesnet/libyang/blob/master/tools/lint/examples/README.md This sequence of commands prepares the environment by clearing previous data, adding necessary YANG modules, and then loads and validates extension data from an XML file against operational data. Successful validation produces no output. ```bash > clear > add ietf-restconf@2017-01-26.yang > add example-jukebox.yang > data -t ext --ext-inst ietf-restconf:yang-data:yang-errors -O operational-data.xml ext-data.xml ``` -------------------------------- ### Data Validation: Out-of-Range Value Source: https://github.com/cesnet/libyang/blob/master/tools/lint/examples/README.md This example demonstrates a libyang error when a value '-1' is provided for a 'uint32' type, which is outside the defined minimum and maximum bounds. ```text > data data-out-of-range-value.xml libyang[0]: Value "-1" is out of type uint32 min/max bounds. (path: Schema location "/ietf-netconf-acm:nacm/denied-operations", data location "/ietf-netconf-acm:nacm", line number 24.) YANGLINT[E]: Failed to parse input data file "data-out-of-range-value.xml". ``` -------------------------------- ### Create a new 'any' extension data node Source: https://github.com/cesnet/libyang/blob/master/doc/compat_report_4_5.html Creates a new data node for an extension instance with 'any' type. Requires specifying the value and its type. ```c lyd_new_ext_any(struct lysc_ext_instance const* ext, char const* name, void const* value, enum LYD_ANYDATA_VALUETYPE value_type, uint32_t options, struct lyd_node** node) ``` -------------------------------- ### Enable Internal 'expect' Debugging Source: https://github.com/cesnet/libyang/blob/master/tests/yanglint/README.md Get more detailed information about 'expect' execution for a specific test. This is useful for debugging interactive test flows. Ensure you are in the 'interactive' directory. ```bash tclsh clear.test -match clear_ietf_yang_library -load "exp_internal 1" ``` -------------------------------- ### Print YANG Data Model as pyang-style Tree Source: https://github.com/cesnet/libyang/blob/master/tools/lint/examples/README.md Shows how to print a YANG data model in a tree format similar to pyang. This is helpful for visualizing the structure of a YANG module. ```bash > clear > add ietf-netconf-acm.yang > print ietf-netconf-acm ``` -------------------------------- ### Schema Violation: Unexpected Child Element Source: https://github.com/cesnet/libyang/blob/master/tools/lint/examples/README.md This example shows a libyang error when a child element 'module-name' is found inside a terminal node 'name', violating the schema. ```text libyang[0]: Child element "module-name" inside a terminal node "name" found. (path: Schema location "/ietf-netconf-acm:nacm/rule-list/rule/name", data location "/ietf-netconf-acm:name", line number 7.) YANGLINT[E]: Failed to parse input data file "data-malformed-xml2.xml". ``` -------------------------------- ### Run Tests with Make Source: https://github.com/cesnet/libyang/blob/master/README.md Execute all built tests using the 'test' target provided by the Makefile. ```bash make test ``` -------------------------------- ### Multi-line Function Parameter Style Source: https://github.com/cesnet/libyang/blob/master/CONTRIBUTING.md When function parameters span multiple lines, continue the list on a new line starting after the opening parenthesis of the initial parameter line. ```c static int my_function(struct my_struct *p1, struct another_struct *p2, int size) { ... ``` -------------------------------- ### Data Node and Tree Traversal Source: https://github.com/cesnet/libyang/blob/master/doc/compat_report_1_2.html Functions for retrieving information about data nodes and traversing the data tree. These include getting the owner module, parent node, and target path. ```c lyd_owner_module( struct lyd_node const* node ) lyd_parent( struct lyd_node const* node ) lyd_target( struct ly_path const* path, struct lyd_node const* tree ) ``` -------------------------------- ### Enable Detailed 'expect' and yanglint Dialog Logging Source: https://github.com/cesnet/libyang/blob/master/tests/yanglint/README.md Log the detailed dialog between 'expect' and yanglint for a specific test. This helps in understanding the interaction. Ensure you are in the 'interactive' directory. ```bash tclsh clear.test -match clear_ietf_yang_library -load "log_user 1" ``` -------------------------------- ### Print YANG Model Part Information Source: https://github.com/cesnet/libyang/blob/master/tools/lint/examples/README.md Demonstrates how to print detailed information about a specific part of a YANG data model. This is useful for inspecting leaf nodes, கட்டமைப்புகள், or other elements. ```bash > clear > add ietf-netconf-acm.yang > print -f info -P /ietf-netconf-acm:nacm/ietf-netconf-acm:enable-nacm ietf-netconf-acm ``` -------------------------------- ### List Enabled Features in YANG Module Source: https://github.com/cesnet/libyang/blob/master/tools/lint/examples/README.md Shows how to list the enabled features of a YANG module. This is useful for understanding which optional functionalities are active. ```bash > clear > add ietf-interfaces.yang > add ietf-ip.yang -F ietf-ip:* > add iana-if-type.yang > feature ietf-ip ``` -------------------------------- ### Create a new 'path' extension data node Source: https://github.com/cesnet/libyang/blob/master/doc/compat_report_4_5.html Creates a new data node for an extension instance with a 'path' type. Requires a parent node, path string, and value. ```c lyd_new_ext_path(struct lyd_node* parent, struct lysc_ext_instance const* ext, char const* path, char const* value, uint32_t options, struct lyd_node** node) ``` -------------------------------- ### Registering Plugins in libyang 2.0 Source: https://github.com/cesnet/libyang/blob/master/doc/transition_1_2.dox Use ::lyplg_add() to register any type of plugin, replacing older functions like ly_register_exts() and ly_register_types(). ```c ::lyplg_add() ``` -------------------------------- ### Run All Unit Tests from a .test File (Alternative) Source: https://github.com/cesnet/libyang/blob/master/tests/yanglint/README.md An alternative method to run all unit tests from a .test file using tclsh with the -file option. This provides flexibility in test execution. ```bash tclsh all.tcl -file clear.test ``` -------------------------------- ### Configure Fuzz Targets Source: https://github.com/cesnet/libyang/blob/master/tests/fuzz/CMakeLists.txt Sets up fuzz targets and links them with the 'yang' library. This configuration is used when the FUZZER is not AFL. ```cmake if(ENABLE_FUZZ_TARGETS) set(fuzz_targets lys_parse_mem lyd_parse_mem_xml lyd_parse_mem_json yang_parse_module) if(FUZZER STREQUAL "AFL") foreach(target_name IN LISTS fuzz_targets) add_executable(${target_name}_fuzz_harness ${target_name}.c main.c) target_link_libraries(${target_name}_fuzz_harness yang) endforeach() elseif() foreach(target_name IN LISTS fuzz_targets) add_executable(${target_name}_fuzz_harness ${target_name}.c) set_source_files_properties(${target_name}.c PROPERTIES COMPILE_FLAGS "-fsanitize=fuzzer") target_link_libraries(${target_name}_fuzz_harness yang "-fsanitize=fuzzer") endforeach() endif() endif() ``` -------------------------------- ### Inserting Data Instances in libyang 2.0 Source: https://github.com/cesnet/libyang/blob/master/doc/transition_1_2.dox ::lyd_insert_after() and ::lyd_insert_before() are now limited to user-ordered list and leaf-list instances. Data nodes are implicitly ordered according to schema nodes. ```c ::lyd_insert_after() ``` ```c ::lyd_insert_before() ``` -------------------------------- ### Validate and Print Mounted Data in JSON Source: https://github.com/cesnet/libyang/blob/master/tools/lint/examples/README.md Shows how to validate and print data associated with a YANG model that uses Schema Mount, outputting the result in JSON format. This is useful for verifying mounted data integrity. ```bash $ yanglint -f json -t config -p . -Y sm-context-main.xml -x sm-context-extension.xml sm-data.xml ``` -------------------------------- ### Windows-Specific Compatibility Includes and Libraries Source: https://github.com/cesnet/libyang/blob/master/CMakeLists.txt Handles Windows-specific include directories for dirent.h and links compatibility libraries like PThreads4W, shlwapi, and ws2_32. ```cmake if(WIN32) find_path(DIRENT_INCLUDE_DIR NAMES dirent.h REQUIRED) message(STATUS "Found at ${DIRENT_INCLUDE_DIR}") set(COMPAT_POSIX_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/compat/posix-shims ${DIRENT_INCLUDE_DIR}) if(TARGET yangobj) target_include_directories(yangobj PRIVATE ${COMPAT_POSIX_INCLUDES}) endif() target_include_directories(yang PRIVATE ${COMPAT_POSIX_INCLUDES}) include_directories(${COMPAT_POSIX_INCLUDES}) find_package(pthreads REQUIRED) set(COMPAT_WIN_LIBRARIES PThreads4W::PThreads4W shlwapi.lib ws2_32) target_link_libraries(yang ${COMPAT_WIN_LIBRARIES}) endif() ``` -------------------------------- ### Create a new 'list' extension data node Source: https://github.com/cesnet/libyang/blob/master/doc/compat_report_4_5.html Creates a new data node for an extension instance with a 'list' type. Supports variable arguments for list items. ```c lyd_new_ext_list(struct lysc_ext_instance const* ext, char const* name, uint32_t options, struct lyd_node** node, ...) ``` -------------------------------- ### Link Math Library on Non-Windows Source: https://github.com/cesnet/libyang/blob/master/CMakeLists.txt Links the math library ('m') for the 'yang' target when not on a Windows system. ```cmake if(NOT WIN32) target_link_libraries(yang m) endif() ``` -------------------------------- ### Add Subdirectories for Build Components Source: https://github.com/cesnet/libyang/blob/master/tests/CMakeLists.txt Includes subdirectories for different components of the libyang project, such as plugins, unit tests, style checkers, fuzzing, performance tests, and tools. ```cmake add_subdirectory(plugins) add_subdirectory(utests) if(NOT WIN32) add_subdirectory(style) add_subdirectory(fuzz) add_subdirectory(perf) endif() add_subdirectory(yanglint) add_subdirectory(yangre) ``` -------------------------------- ### Return Statement Formatting Source: https://github.com/cesnet/libyang/blob/master/CONTRIBUTING.md Avoid unnecessary parentheses around return values. Use 'return 0;' instead of 'return(0);'. -------------------------------- ### Configure Regression Tests Source: https://github.com/cesnet/libyang/blob/master/tests/fuzz/CMakeLists.txt Sets up and configures regression tests for fuzzing, copying corpus files and linking targets with the 'yang' library. ```cmake if(ENABLE_TESTS) add_executable(fuzz_regression_test fuzz_regression_test.c) set(fuzz_regression_tests lys_parse_mem lyd_parse_mem_xml lyd_parse_mem_json) foreach(target_name IN LISTS fuzz_regression_tests) file(COPY ${CMAKE_SOURCE_DIR}/tests/fuzz/corpus/${target_name} DESTINATION ${CMAKE_BINARY_DIR}/tests/fuzz/) add_executable(regress_fuzz_${target_name} ${target_name}.c main.c) set_target_properties(regress_fuzz_${target_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests/fuzz/${target_name}") target_link_libraries(regress_fuzz_${target_name} yang) add_test(NAME regress_fuzz_${target_name} COMMAND fuzz_regression_test regress_fuzz_${target_name} . WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/fuzz/${target_name}) endforeach() endif() ``` -------------------------------- ### Set CMake Plugins Directory Source: https://github.com/cesnet/libyang/blob/master/README.md Configure the directory where libyang will load extension plugins. This can also be set via an environment variable at runtime. ```bash cmake -DPLUGINS_DIR:PATH=`pwd`"/src/extensions/" .. ``` ```bash LIBYANG_EXTENSIONS_PLUGINS_DIR=`pwd`/my/relative/path yanglint ``` -------------------------------- ### Find and Link XXHash Library Source: https://github.com/cesnet/libyang/blob/master/CMakeLists.txt Finds the XXHash library, defines a preprocessor macro if found, and links it to the 'yang' target. Falls back to an internal hash algorithm if XXHash is not found. ```cmake find_package(XXHash) if(XXHASH_FOUND) add_definitions(-DLY_XXHASH_SUPPORT) set(PC_XXHASH_LIB libxxhash) include_directories(${XXHASH_INCLUDE_DIR}) target_link_libraries(yang ${XXHASH_LIBRARY}) message(STATUS "Hash algorithm: xxhash") if (HAVE_XXH3_64BITS_WITHSEED) # for 32-bit system compatibility, this may not be available there, so use XXH32 instead add_definitions(-DLY_XXH3_64BITS_WITHSEED) endif() else() message(STATUS "Hash algorithm: internal Jenkin's one-at-a-time") endif() ``` -------------------------------- ### Build Fuzz Targets with Make Source: https://github.com/cesnet/libyang/blob/master/tests/fuzz/README.md Compile the fuzzing programs after configuring with CMake. ```bash $ make ``` -------------------------------- ### Run All yanglint Tests Source: https://github.com/cesnet/libyang/blob/master/tests/yanglint/README.md Execute all yanglint tests using the ctest command. This is a high-level command for test execution. ```bash ctest -R yanglint ``` -------------------------------- ### Include Directories for Tests Source: https://github.com/cesnet/libyang/blob/master/tests/CMakeLists.txt Adds system and project-specific include directories for compiling tests. ```cmake include_directories(SYSTEM ${CMOCKA_INCLUDE_DIR}) include_directories(${PROJECT_BINARY_DIR}/tests/) ``` -------------------------------- ### Run Interactive yanglint Tests Source: https://github.com/cesnet/libyang/blob/master/tests/yanglint/README.md Execute all yanglint tests in interactive mode using tclsh. Ensure you are in the 'interactive' directory. ```bash tclsh all.tcl ``` -------------------------------- ### Make Targets Source: https://github.com/cesnet/libyang/blob/master/doc/build.dox Common make targets for managing the libyang build process, including cleaning and documentation generation. ```text all clean cclean doc ``` -------------------------------- ### Create a new 'term' extension data node Source: https://github.com/cesnet/libyang/blob/master/doc/compat_report_4_5.html Creates a new data node for an extension instance with a 'term' type. Requires value and size information. ```c lyd_new_ext_term(struct lysc_ext_instance const* ext, char const* name, void const* value, uint32_t value_size_bits, uint32_t options, struct lyd_node** node) ``` -------------------------------- ### Run All Unit Tests from a .test File Source: https://github.com/cesnet/libyang/blob/master/tests/yanglint/README.md Execute all unit tests contained within a specific .test file using tclsh. This command runs a batch of tests. ```bash tclsh clear.test ``` -------------------------------- ### Update lyd_new_ext_term function signature Source: https://github.com/cesnet/libyang/blob/master/doc/compat_report_2_3.html An 'options' parameter of type uint32_t has been added to lyd_new_ext_term. Old clients will not initialize this parameter. ```c struct lysc_ext_instance const* ext, char const* name, char const* val_str, struct lyd_node** node) ``` ```c struct lysc_ext_instance const* ext, char const* name, void const* value, size_t value_len, uint32_t options, struct lyd_node** node) ``` -------------------------------- ### Run a Single Unit Test by Name (Alternative) Source: https://github.com/cesnet/libyang/blob/master/tests/yanglint/README.md An alternative method to run a single unit test by name using tclsh with the -file and -match options. This combines file specification with pattern matching. ```bash tclsh all.tcl -file clear.test -match clear_ietf_yang_library ``` -------------------------------- ### Function Prototype Style Source: https://github.com/cesnet/libyang/blob/master/CONTRIBUTING.md In function prototypes, the return type and function name should be on the same line, followed by the parameter list. ```c static const struct int foo(int arg); ``` -------------------------------- ### Set Target Version and SOVERSION Source: https://github.com/cesnet/libyang/blob/master/CMakeLists.txt Sets the version and shared object version for the 'yang' target. ```cmake set_target_properties(yang PROPERTIES VERSION ${LIBYANG_SOVERSION_FULL} SOVERSION ${LIBYANG_SOVERSION}) ``` -------------------------------- ### libyang Context Functions Source: https://github.com/cesnet/libyang/blob/master/doc/compat_report_1_2.html These C functions are part of the libyang library for managing YANG contexts. They include functions for retrieving module information, setting context options, and managing search directories. ```c ly_ctx_get_module_implemented ly_ctx_get_module_implemented_ns ly_ctx_get_module_latest ly_ctx_get_module_latest_ns ly_ctx_get_module_ns ly_ctx_get_yanglib_data ly_ctx_get_yanglib_id ly_ctx_reset_latests ly_ctx_set_options ly_ctx_unset_options ly_ctx_unset_searchdir ly_ctx_unset_searchdir_last ``` -------------------------------- ### Enable Tests Source: https://github.com/cesnet/libyang/blob/master/CMakeLists.txt Enables testing and adds the 'tests' subdirectory if tests are enabled. ```cmake if(ENABLE_TESTS) enable_testing() add_subdirectory(tests) endif() ``` -------------------------------- ### Finding Tclsh and Expect for Interactive Tests Source: https://github.com/cesnet/libyang/blob/master/tests/yanglint/CMakeLists.txt Locates the `tclsh` and `expect` executables, which are required for running interactive yanglint tests. Warnings are issued if they are not found. ```cmake find_program(PATH_TCLSH NAMES tclsh) find_program(PATH_EXPECT NAMES expect) if(NOT PATH_TCLSH) message(WARNING "tclsh not found, yanglint(1) interactive tests will not be available.") elseif(NOT PATH_EXPECT) message(WARNING "expect not found, yanglint(1) interactive tests will not be available.") else() # ... test definitions ... endif() ``` -------------------------------- ### Include libyang Header Source: https://github.com/cesnet/libyang/blob/master/README.md Include the main libyang header file to access all library functions in your C/C++ application. ```c #include ``` -------------------------------- ### Module Context Retrieval Functions Source: https://github.com/cesnet/libyang/blob/master/doc/compat_report_2_3.html These functions retrieve module information from the context. Changes in internal structures like 'struct lysc_ext' may cause recompilation errors. ```c ly_ctx_get_module ( struct ly_ctx const * _ctx_, char const * _name_, char const * _revision_ ) ``` ```c ly_ctx_get_module_implemented ( struct ly_ctx const * _ctx_, char const * _name_ ) ``` ```c ly_ctx_get_module_implemented_ns ( struct ly_ctx const * _ctx_, char const * _ns_ ) ``` ```c ly_ctx_get_module_iter ( struct ly_ctx const * _ctx_, uint32_t * _index_ ) ``` ```c ly_ctx_get_module_latest ( struct ly_ctx const * _ctx_, char const * _name_ ) ``` ```c ly_ctx_get_module_latest_ns ( struct ly_ctx const * _ctx_, char const * _ns_ ) ``` ```c ly_ctx_get_module_ns ( struct ly_ctx const * _ctx_, char const * _ns_, char const * _revision_ ) ``` -------------------------------- ### Add Tools Subdirectory Source: https://github.com/cesnet/libyang/blob/master/CMakeLists.txt Includes the 'tools' subdirectory if tools are enabled in the build configuration. ```cmake if(ENABLE_TOOLS) add_subdirectory(tools) endif() ``` -------------------------------- ### Enable Tests with CMake Source: https://github.com/cesnet/libyang/blob/master/README.md Enable the building of tests, which are by default only built in Debug mode. This requires the cmocka library to be present. ```bash cmake -DENABLE_TESTS=ON .. ``` -------------------------------- ### Initialize Tabs Source: https://github.com/cesnet/libyang/blob/master/doc/compat_report_3_4.html Initializes tab functionality on page load. Attaches event listeners for compatibility with older browsers. ```javascript (var i = 0; i < sets.length; i++) { if (sets[i].className.indexOf('tabset') != -1) { var tabs = []; var links = sets[i].getElementsByTagName('a'); for (var j = 0; j < links.length; j++) { if (links[j].className.indexOf('tab') != -1) { tabs.push(links[j]); links[j].tabs = tabs; var tab = document.getElementById(links[j].href.substr(links[j].href.indexOf('#') + 1)); //reset all tabs on start if (tab) { if (links[j].className.indexOf('active')!=-1) { tab.style.display = 'block'; } else { tab.style.display = 'none'; } } links[j].onclick = function() { var tab = document.getElementById(this.href.substr(this.href.indexOf('#') + 1)); if (tab) { //reset all tabs before change for (var k = 0; k < this.tabs.length; k++) { document.getElementById(this.tabs[k].href.substr(this.tabs[k].href.indexOf('#') + 1)).style.display = 'none'; this.tabs[k].className = this.tabs[k].className.replace('active', 'disabled'); } this.className = 'tab active'; tab.style.display = 'block'; // window.location.hash = this.id.replace('ID', ''); return false; } } } } } } if(url.indexOf('#')!=-1) { location.href=location.href; } } if (window.addEventListener) window.addEventListener('load', initTabs, false); else if (window.attachEvent) window.attachEvent('onload', initTabs); --> ``` -------------------------------- ### Configure Fuzzer Targets Source: https://github.com/cesnet/libyang/blob/master/CMakeLists.txt Sets up build configurations for fuzzing targets. It specifically checks for LibFuzzer compatibility with Clang and sets appropriate compiler flags. ```cmake if(ENABLE_FUZZ_TARGETS) set(FUZZER "AFL" CACHE STRING "fuzzer type") if(FUZZER STREQUAL "LibFuzzer") if (NOT CMAKE_C_COMPILER_ID STREQUAL "Clang") message(FATAL_ERROR "LibFuzzer works only with clang") endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address,undefined -fno-omit-frame-pointer") endif() endif() ``` -------------------------------- ### Validate Unknown Data Source: https://github.com/cesnet/libyang/blob/master/tools/lint/examples/README.md Validates configuration data from a file. By default, yanglint ignores unknown data. Use '-f xml' to see the raw XML output. ```bash > data -t config datastore.xml ``` -------------------------------- ### Create new YLDATA context Source: https://github.com/cesnet/libyang/blob/master/doc/compat_report_4_5.html Creates a new context for YLDATA, specifying search directories and an optional tree. Used for initializing Libyang context. ```c ly_ctx_new_yldata(char const* _search_dir_, struct lyd_node const* tree, int _options_, struct ly_ctx** _ctx_) ```