From 76b2c91d7e3071aed8ea3aa0179b5c3667f10eef Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 5 Feb 2025 08:08:41 +0100 Subject: [PATCH] Adding upstream version 3.7.8. Signed-off-by: Daniel Baumann --- .github/workflows/codeql.yml | 39 - CMakeLists.txt | 8 +- CMakeModules/UseCompat.cmake | 2 +- SECURITY.md | 30 + doc/compat_report_1_2.html | 7645 ++++++++++++++++++ doc/compat_report_2_3.html | 3221 ++++++++ doc/logo.png | Bin 0 -> 2792 bytes src/diff.c | 14 +- src/hash_table.c | 18 +- src/hash_table.h | 5 +- src/log.c | 57 +- src/ly_common.h | 10 +- src/parser_common.c | 47 +- src/parser_data.h | 52 +- src/parser_internal.h | 23 +- src/parser_json.c | 21 +- src/parser_lyb.c | 24 +- src/parser_xml.c | 21 +- src/path.c | 6 +- src/plugins_exts.c | 2 +- src/plugins_types.c | 30 +- src/plugins_types/node_instanceid.c | 33 +- src/plugins_types/union.c | 3 + src/printer_lyb.c | 17 +- src/schema_compile.c | 2 - src/schema_compile_node.c | 6 +- src/schema_compile_node.h | 2 +- src/tree_data.c | 74 +- src/tree_data.h | 31 + src/tree_data_common.c | 147 +- src/tree_data_internal.h | 77 +- src/tree_data_new.c | 361 +- src/tree_data_sorted.c | 12 +- src/tree_schema_common.c | 4 +- src/validation.c | 380 +- src/validation.h | 68 +- src/xpath.c | 39 +- src/xpath.h | 2 +- tests/tool_i.tcl | 9 +- tests/utests/basic/test_xpath.c | 30 +- tests/utests/data/test_new.c | 8 + tests/utests/data/test_tree_data_sorted.c | 21 +- tests/utests/data/test_validation.c | 47 + tests/yanglint/CMakeLists.txt | 2 +- tests/yanglint/interactive/completion.test | 19 +- tools/lint/CMakeLists.txt | 3 +- tools/lint/completion.c | 115 +- tools/lint/linenoise/linenoise.c | 1150 ++- tools/lint/linenoise/linenoise.h | 57 +- tools/lint/linenoise/utf8.c | 464 ++ tools/lint/linenoise/{linenoise.h => utf8.h} | 55 +- tools/lint/main.c | 3 + 52 files changed, 13518 insertions(+), 998 deletions(-) delete mode 100644 .github/workflows/codeql.yml create mode 100644 SECURITY.md create mode 100644 doc/compat_report_1_2.html create mode 100644 doc/compat_report_2_3.html create mode 100644 doc/logo.png create mode 100644 tools/lint/linenoise/utf8.c copy tools/lint/linenoise/{linenoise.h => utf8.h} (50%) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml deleted file mode 100644 index 89a4f0a..0000000 --- a/.github/workflows/codeql.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: "CodeQL" - -on: - push: - branches: [ "master", "devel" ] - pull_request: - branches: [ "devel" ] - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ cpp ] - - steps: - - name: Checkout - uses: actions/checkout@main - - - name: Initialize CodeQL - uses: github/codeql-action/init@main - with: - languages: ${{ matrix.language }} - queries: +security-and-quality - - - name: Autobuild - uses: github/codeql-action/autobuild@main - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@main - with: - category: "/language:${{ matrix.language }}" diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d0bb28..609bedb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,14 +59,14 @@ set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) # set version of the project set(LIBYANG_MAJOR_VERSION 3) -set(LIBYANG_MINOR_VERSION 4) -set(LIBYANG_MICRO_VERSION 2) +set(LIBYANG_MINOR_VERSION 7) +set(LIBYANG_MICRO_VERSION 8) set(LIBYANG_VERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}.${LIBYANG_MICRO_VERSION}) # set version of the library set(LIBYANG_MAJOR_SOVERSION 3) -set(LIBYANG_MINOR_SOVERSION 4) -set(LIBYANG_MICRO_SOVERSION 2) +set(LIBYANG_MINOR_SOVERSION 6) +set(LIBYANG_MICRO_SOVERSION 10) set(LIBYANG_SOVERSION_FULL ${LIBYANG_MAJOR_SOVERSION}.${LIBYANG_MINOR_SOVERSION}.${LIBYANG_MICRO_SOVERSION}) set(LIBYANG_SOVERSION ${LIBYANG_MAJOR_SOVERSION}) diff --git a/CMakeModules/UseCompat.cmake b/CMakeModules/UseCompat.cmake index 8fe9f2c..2c43486 100644 --- a/CMakeModules/UseCompat.cmake +++ b/CMakeModules/UseCompat.cmake @@ -45,7 +45,7 @@ macro(USE_COMPAT) find_package(Threads) list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) check_function_exists(pthread_mutex_timedlock HAVE_PTHREAD_MUTEX_TIMEDLOCK) - list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) + list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} "") # cmake <= 3.19 needs at least one item test_big_endian(IS_BIG_ENDIAN) diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..61444f4 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,30 @@ +# Security Policy + +If you discover a security-related issue (a crash), please report it based on the instructions below. + +## Reporting a Vulnerability + +Please **DO NOT** file a public issue, instead report the vulnerability on the relevant +[GitHub security](https://github.com/CESNET/libyang/security) page. If you do not receive any reaction within 48 hours, +please also send an email to [mvasko@cesnet.cz]. + +## Review Process + +After receiving the report, an initial triage and technical analysis is performed to confirm the report and determine +its scope. We may request additional information in this stage of the process. + +Once a reviewer has confirmed the relevance of the report, a draft security advisory will be created on GitHub. The +draft advisory will be used to discuss the issue with maintainers, the reporter(s), and where applicable, other affected +parties under embargo. + +If the vulnerability is accepted, a timeline for developing a patch, public disclosure, and patch release will be +determined. If there is an embargo period on public disclosure before the patch release, the reporter(s) are expected to +participate in the discussion of the timeline and abide by agreed upon dates for public disclosure. + +Usually, the reasonably complex issues are fixed within hours of being reported. + +## Supported Versions + +After an issue is fixed, it **WILL NOT** be backported to any released version. Instead, it is kept in the public `devel` +branch, which is periodically merged into the main branch when a new release is due. So, the issue will be fixed in the +next release after it is fixed. diff --git a/doc/compat_report_1_2.html b/doc/compat_report_1_2.html new file mode 100644 index 0000000..5bcf4d9 --- /dev/null +++ b/doc/compat_report_1_2.html @@ -0,0 +1,7645 @@ + + + + + + + + + +libyang.so: 1.9.19 to 2.0.0 compatibility report + + + +

API compatibility report for the libyang.so object between 1.9.19 and 2.0.0 versions on x86_64

+ +
+
+

Test Info


+ + + + + + + +
Module Namelibyang.so
Version #11.9.19
Version #22.0.0
Archx86_64
GCC Version7.5.0
SubjectBinary Compatibility
+

Test Results


+ + + + + + + +
Total Header Files7
Total Source Files11
Total Objects1
Total Symbols / Types174 / 22
Compatibility18.8%
+

Problem Summary


+ + + + + + + + + + +
SeverityCount
Added Symbols-153
Removed SymbolsHigh114
Problems with
Data Types
High17
Medium37
Low90
Problems with
Symbols
High18
Medium57
Low57
Problems with
Constants
Low0
Other Changes
in Data Types
-7
+ +

Added Symbols  153 


+context.h, libyang.so.2.0.0
+ly_ctx_get_module_implemented ( struct ly_ctx const* ctx, char const* name )
+ly_ctx_get_module_implemented_ns ( struct ly_ctx const* ctx, char const* ns )
+ly_ctx_get_module_latest ( struct ly_ctx const* ctx, char const* name )
+ly_ctx_get_module_latest_ns ( struct ly_ctx const* ctx, char const* ns )
+ly_ctx_get_module_ns ( struct ly_ctx const* ctx, char const* ns, char const* revision )
+ly_ctx_get_yanglib_data ( struct ly_ctx const* ctx, struct lyd_node** root_p )
+ly_ctx_get_yanglib_id ( struct ly_ctx const* ctx )
+ly_ctx_reset_latests ( struct ly_ctx* ctx )
+ly_ctx_set_options ( struct ly_ctx* ctx, uint16_t option )
+ly_ctx_unset_options ( struct ly_ctx* ctx, uint16_t option )
+ly_ctx_unset_searchdir ( struct ly_ctx* ctx, char const* value )
+ly_ctx_unset_searchdir_last ( struct ly_ctx* ctx, uint32_t count )
+
+in.h, libyang.so.2.0.0
+ly_in_fd ( struct ly_in* in, int fd )
+ly_in_file ( struct ly_in* in, FILE* f )
+ly_in_filepath ( struct ly_in* in, char const* filepath, size_t len )
+ly_in_free ( struct ly_in* in, ly_bool destroy )
+ly_in_memory ( struct ly_in* in, char const* str )
+ly_in_new_fd ( int fd, struct ly_in** in )
+ly_in_new_file ( FILE* f, struct ly_in** in )
+ly_in_new_filepath ( char const* filepath, size_t len, struct ly_in** in )
+ly_in_new_memory ( char const* str, struct ly_in** in )
+ly_in_parsed ( struct ly_in const* in )
+ly_in_reset ( struct ly_in* in )
+ly_in_type ( struct ly_in const* in )
+
+log.h, libyang.so.2.0.0
+ly_err_last ( struct ly_ctx const* ctx )
+ly_errcode ( struct ly_ctx const* ctx )
+ly_log_dbg_groups ( uint32_t dbg_groups )
+ly_log_level ( enum LY_LOG_LEVEL level )
+
+out.h, libyang.so.2.0.0
+ly_out_clb ( struct ly_out* out, ly_write_clb writeclb )
+ly_out_clb_arg ( struct ly_out* out, void* arg )
+ly_out_fd ( struct ly_out* out, int fd )
+ly_out_file ( struct ly_out* out, FILE* f )
+ly_out_filepath ( struct ly_out* out, char const* filepath )
+ly_out_free ( struct ly_out* out, void(*clb_arg_destructor)(void*), ly_bool destroy )
+ly_out_new_clb ( ly_write_clb writeclb, void* user_data, struct ly_out** out )
+ly_out_new_fd ( int fd, struct ly_out** out )
+ly_out_new_file ( FILE* f, struct ly_out** out )
+ly_out_new_filepath ( char const* filepath, struct ly_out** out )
+ly_out_new_memory ( char** strp, size_t size, struct ly_out** out )
+ly_out_printed ( struct ly_out const* out )
+ly_out_reset ( struct ly_out* out )
+ly_out_type ( struct ly_out const* out )
+ly_print ( struct ly_out* out, char const* format, ... )
+ly_print_flush ( struct ly_out* out )
+ly_write ( struct ly_out* out, char const* buf, size_t len )
+
+parser_data.h, libyang.so.2.0.0
+lyd_parse_data ( struct ly_ctx const* ctx, struct ly_in* in, enum LYD_FORMAT format, uint32_t parse_options, uint32_t validate_options, struct lyd_node** tree )
+lyd_parse_data_fd ( struct ly_ctx const* ctx, int fd, enum LYD_FORMAT format, uint32_t parse_options, uint32_t validate_options, struct lyd_node** tree )
+lyd_parse_data_mem ( struct ly_ctx const* ctx, char const* data, enum LYD_FORMAT format, uint32_t parse_options, uint32_t validate_options, struct lyd_node** tree )
+lyd_parse_data_path ( struct ly_ctx const* ctx, char const* path, enum LYD_FORMAT format, uint32_t parse_options, uint32_t validate_options, struct lyd_node** tree )
+lyd_parse_notif ( struct ly_ctx const* ctx, struct ly_in* in, enum LYD_FORMAT format, struct lyd_node** tree, struct lyd_node** ntf )
+lyd_parse_reply ( struct lyd_node const* request, struct ly_in* in, enum LYD_FORMAT format, struct lyd_node** tree, struct lyd_node** op )
+lyd_parse_rpc ( struct ly_ctx const* ctx, struct ly_in* in, enum LYD_FORMAT format, struct lyd_node** tree, struct lyd_node** op )
+lyd_validate_all ( struct lyd_node** tree, struct ly_ctx const* ctx, uint32_t val_opts, struct lyd_node** diff )
+lyd_validate_module ( struct lyd_node** tree, struct lys_module const* module, uint32_t val_opts, struct lyd_node** diff )
+lyd_validate_op ( struct lyd_node* op_tree, struct lyd_node const* tree, enum LYD_VALIDATE_OP op, struct lyd_node** diff )
+
+parser_schema.h, libyang.so.2.0.0
+lys_parse ( struct ly_ctx* ctx, struct ly_in* in, enum LYS_INFORMAT format, char const** features, struct lys_module const** module )
+
+plugins_types.h, libyang.so.2.0.0
+ly_err_free ( void* ptr )
+ly_err_new ( enum LY_LOG_LEVEL level, enum LY_ERR no, enum LY_VECODE vecode, char* msg, char* path, char* apptag )
+ly_type_identity_isderived ( struct lysc_ident* base, struct lysc_ident* der )
+ly_type_parse_dec64 ( uint8_t fraction_digits, char const* value, size_t value_len, int64_t* ret, struct ly_err_item** err )
+ly_type_parse_int ( char const* datatype, int base, int64_t min, int64_t max, char const* value, size_t value_len, int64_t* ret, struct ly_err_item** err )
+ly_type_parse_uint ( char const* datatype, int base, uint64_t max, char const* value, size_t value_len, uint64_t* ret, struct ly_err_item** err )
+ly_type_print_get_prefix ( struct lys_module const* mod, enum LY_PREFIX_FORMAT format, void* prefix_data )
+ly_type_store_resolve_prefix ( struct ly_ctx const* ctx, char const* prefix, size_t prefix_len, enum LY_PREFIX_FORMAT format, void* prefix_data )
+ly_type_validate_patterns ( struct lysc_pattern** patterns, char const* str, size_t str_len, struct ly_err_item** err )
+ly_type_validate_range ( enum LY_DATA_TYPE basetype, struct lysc_range* range, int64_t value, char const* strval, struct ly_err_item** err )
+lysc_prefixes_compile ( char const* str, size_t str_len, struct lysp_module const* prefix_mod, struct lysc_prefix** prefixes )
+lysc_prefixes_dup ( struct lysc_prefix const* orig, struct lysc_prefix** dup )
+lysc_prefixes_free ( struct lysc_prefix* prefixes )
+
+printer_data.h, libyang.so.2.0.0
+lyd_print_all ( struct ly_out* out, struct lyd_node const* root, enum LYD_FORMAT format, uint32_t options )
+lyd_print_tree ( struct ly_out* out, struct lyd_node const* root, enum LYD_FORMAT format, uint32_t options )
+
+printer_schema.h, libyang.so.2.0.0
+lys_print_module ( struct ly_out* out, struct lys_module const* module, enum LYS_OUTFORMAT format, size_t UNUSED_line_length, uint32_t options )
+lys_print_node ( struct ly_out* out, struct lysc_node const* node, enum LYS_OUTFORMAT format, size_t UNUSED_line_length, uint32_t options )
+lys_print_submodule ( struct ly_out* out, struct lys_module const* module, struct lysp_submodule const* submodule, enum LYS_OUTFORMAT format, size_t UNUSED_line_length, uint32_t options )
+
+set.h, libyang.so.2.0.0
+ly_set_erase ( struct ly_set* set, void(*destructor)(void*) )
+
+tree_data.h, libyang.so.2.0.0
+lyd_any_copy_value ( struct lyd_node* trg, union lyd_any_value const* value, enum LYD_ANYDATA_VALUETYPE value_type )
+lyd_change_meta ( struct lyd_meta* meta, char const* val_str )
+lyd_change_term ( struct lyd_node* term, char const* val_str )
+lyd_child ( struct lyd_node const* node )
+lyd_child_no_keys ( struct lyd_node const* node )
+lyd_compare_meta ( struct lyd_meta const* meta1, struct lyd_meta const* meta2 )
+lyd_compare_siblings ( struct lyd_node const* node1, struct lyd_node const* node2, uint32_t options )
+lyd_compare_single ( struct lyd_node const* node1, struct lyd_node const* node2, uint32_t options )
+lyd_diff_apply_all ( struct lyd_node** data, struct lyd_node const* diff )
+lyd_diff_apply_module ( struct lyd_node** data, struct lyd_node const* diff, struct lys_module const* mod, lyd_diff_cb diff_cb, void* cb_data )
+lyd_diff_merge_all ( struct lyd_node** diff, struct lyd_node const* src_diff )
+lyd_diff_merge_module ( struct lyd_node** diff, struct lyd_node const* src_diff, struct lys_module const* mod, lyd_diff_cb diff_cb, void* cb_data )
+lyd_diff_merge_tree ( struct lyd_node** diff_first, struct lyd_node* diff_parent, struct lyd_node const* src_sibling, lyd_diff_cb diff_cb, void* cb_data )
+lyd_diff_reverse_all ( struct lyd_node const* src_diff, struct lyd_node** diff )
+lyd_diff_siblings ( struct lyd_node const* first, struct lyd_node const* second, uint16_t options, struct lyd_node** diff )
+lyd_diff_tree ( struct lyd_node const* first, struct lyd_node const* second, uint16_t options, struct lyd_node** diff )
+lyd_dup_meta_single ( struct lyd_meta const* meta, struct lyd_node* node, struct lyd_meta** dup )
+lyd_dup_siblings ( struct lyd_node const* node, struct lyd_node_inner* parent, uint32_t options, struct lyd_node** dup )
+lyd_dup_single ( struct lyd_node const* node, struct lyd_node_inner* parent, uint32_t options, struct lyd_node** dup )
+lyd_find_meta ( struct lyd_meta const* first, struct lys_module const* module, char const* name )
+lyd_find_sibling_first ( struct lyd_node const* siblings, struct lyd_node const* target, struct lyd_node** match )
+lyd_find_xpath ( struct lyd_node const* ctx_node, char const* xpath, struct ly_set** set )
+lyd_free_all ( struct lyd_node* node )
+lyd_free_attr_siblings ( struct ly_ctx const* ctx, struct lyd_attr* attr )
+lyd_free_attr_single ( struct ly_ctx const* ctx, struct lyd_attr* attr )
+lyd_free_meta_siblings ( struct lyd_meta* meta )
+lyd_free_meta_single ( struct lyd_meta* meta )
+lyd_free_siblings ( struct lyd_node* node )
+lyd_free_tree ( struct lyd_node* node )
+lyd_insert_child ( struct lyd_node* parent, struct lyd_node* node )
+lyd_is_default ( struct lyd_node const* node )
+lyd_merge_siblings ( struct lyd_node** target, struct lyd_node const* source, uint16_t options )
+lyd_merge_tree ( struct lyd_node** target, struct lyd_node const* source, uint16_t options )
+lyd_new_any ( struct lyd_node* parent, struct lys_module const* module, char const* name, void const* value, enum LYD_ANYDATA_VALUETYPE value_type, ly_bool output, struct lyd_node** node )
+lyd_new_attr ( struct lyd_node* parent, char const* module_name, char const* name, char const* val_str, struct lyd_attr** attr )
+lyd_new_implicit_all ( struct lyd_node** tree, struct ly_ctx const* ctx, uint32_t implicit_options, struct lyd_node** diff )
+lyd_new_implicit_module ( struct lyd_node** tree, struct lys_module const* module, uint32_t implicit_options, struct lyd_node** diff )
+lyd_new_implicit_tree ( struct lyd_node* tree, uint32_t implicit_options, struct lyd_node** diff )
+lyd_new_inner ( struct lyd_node* parent, struct lys_module const* module, char const* name, ly_bool output, struct lyd_node** node )
+lyd_new_list ( struct lyd_node* parent, struct lys_module const* module, char const* name, ly_bool output, struct lyd_node** node, ... )
+lyd_new_list2 ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const* keys, ly_bool output, struct lyd_node** node )
+lyd_new_meta ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const* val_str, struct lyd_meta** meta )
+lyd_new_opaq ( struct lyd_node* parent, struct ly_ctx const* ctx, char const* name, char const* value, char const* module_name, struct lyd_node** node )
+lyd_new_path2 ( struct lyd_node* parent, struct ly_ctx const* ctx, char const* path, void const* value, enum LYD_ANYDATA_VALUETYPE value_type, uint32_t options, struct lyd_node** new_parent, struct lyd_node** new_node )
+lyd_new_term ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const* val_str, ly_bool output, struct lyd_node** node )
+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 )
+lyd_unlink_tree ( struct lyd_node* node )
+lyd_value_compare ( struct lyd_node_term const* node, char const* value, size_t value_len )
+lyd_value_validate ( struct ly_ctx const* ctx, struct lyd_node_term const* node, char const* value, size_t value_len, struct lyd_node const* tree, struct lysc_type const** realtype )
+
+tree_schema.h, libyang.so.2.0.0
+lyext_parent2str ( enum LYEXT_PARENT type )
+lys_feature_value ( struct lys_module const* module, char const* feature )
+lys_find_child ( struct lysc_node const* parent, struct lys_module const* module, char const* name, size_t name_len, uint16_t nodetype, uint32_t options )
+lys_find_expr_atoms ( struct lysc_node const* ctx_node, struct lys_module const* cur_mod, struct lyxp_expr const* expr, struct lysc_prefix const* prefixes, uint32_t options, struct ly_set** set )
+lys_find_lypath_atoms ( struct ly_path const* path, struct ly_set** set )
+lys_find_path_atoms ( struct ly_ctx const* ctx, struct lysc_node const* ctx_node, char const* path, ly_bool output, struct ly_set** set )
+lys_find_xpath ( struct lysc_node const* ctx_node, char const* xpath, uint32_t options, struct ly_set** set )
+lys_find_xpath_atoms ( struct lysc_node const* ctx_node, char const* xpath, uint32_t options, struct ly_set** set )
+lys_nodetype2str ( uint16_t nodetype )
+lys_value_validate ( struct ly_ctx const* ctx, struct lysc_node const* node, char const* value, size_t value_len )
+lysc_iffeature_value ( struct lysc_iffeature const* iff )
+lysc_module_dfs_full ( struct lys_module const* mod, lysc_dfs_clb dfs_clb, void* data )
+lysc_node_actions ( struct lysc_node const* node )
+lysc_node_children ( struct lysc_node const* node, uint16_t flags )
+lysc_node_children_full ( struct lysc_node const* node, uint16_t flags )
+lysc_node_notifs ( struct lysc_node const* node )
+lysc_node_parent_full ( struct lysc_node const* node )
+lysc_path ( struct lysc_node const* node, enum LYSC_PATH_TYPE pathtype, char* buffer, size_t buflen )
+lysc_set_private ( struct lysc_node const* node, void* priv, void** prev_priv_p )
+lysc_tree_dfs_full ( struct lysc_node const* root, lysc_dfs_clb dfs_clb, void* data )
+lysp_feature_next ( struct lysp_feature const* last, struct lysp_module const* pmod, uint32_t* idx )
+lysp_node_actions ( struct lysp_node const* node )
+lysp_node_children ( struct lysp_node const* node )
+lysp_node_groupings ( struct lysp_node const* node )
+lysp_node_notifs ( struct lysp_node const* node )
+lysp_node_typedefs ( struct lysp_node const* node )
+lyxp_get_expr ( struct lyxp_expr const* path )
+
+to the top
+

Removed Symbols  114 


+extensions.h, libyang.so.1.9.19
+lyext_vlog ( struct ly_ctx const* ctx, enum LY_VECODE vecode, char const* plugin, char const* function, enum LYEXT_VLOG_ELEM elem_type, void const* elem, char const* format, ... )
+lys_iffeature_free ( struct ly_ctx* ctx, struct lys_iffeature* iffeature, uint8_t iffeature_size, int shallow, void(*private_destructor)(struct lys_node const*, void*) )
+
+libyang.h, libyang.so.1.9.19
+ly_ctx_clean ( struct ly_ctx* ctx, void(*private_destructor)(struct lys_node const*, void*) )
+ly_ctx_find_path ( struct ly_ctx* ctx, char const* path )
+ly_ctx_get_disabled_module_iter ( struct ly_ctx const* ctx, uint32_t* idx )
+ly_ctx_get_module_by_ns ( struct ly_ctx const* ctx, char const* ns, char const* revision, int implemented )
+ly_ctx_get_module_data_clb ( struct ly_ctx const* ctx, void** user_data )
+ly_ctx_get_module_older ( struct ly_ctx const* ctx, struct lys_module const* module )
+ly_ctx_get_node ( struct ly_ctx const* ctx, struct lys_node const* start, char const* nodeid, int output )
+ly_ctx_get_submodule ( struct ly_ctx const* ctx, char const* module, char const* revision, char const* submodule, char const* sub_revision )
+ly_ctx_get_submodule2 ( struct lys_module const* main_module, char const* submodule )
+ly_ctx_info ( struct ly_ctx* ctx )
+ly_ctx_new_ylmem ( char const* search_dir, char const* data, enum LYD_FORMAT format, int options )
+ly_ctx_new_ylpath ( char const* search_dir, char const* path, enum LYD_FORMAT format, int options )
+ly_ctx_remove_module ( struct lys_module const* module, void(*private_destructor)(struct lys_node const*, void*) )
+ly_ctx_set_allimplemented ( struct ly_ctx* ctx )
+ly_ctx_set_disable_searchdir_cwd ( struct ly_ctx* ctx )
+ly_ctx_set_disable_searchdirs ( struct ly_ctx* ctx )
+ly_ctx_set_module_data_clb ( struct ly_ctx* ctx, ly_module_data_clb clb, void* user_data )
+ly_ctx_set_prefer_searchdirs ( struct ly_ctx* ctx )
+ly_ctx_set_trusted ( struct ly_ctx* ctx )
+ly_ctx_unset_allimplemented ( struct ly_ctx* ctx )
+ly_ctx_unset_disable_searchdir_cwd ( struct ly_ctx* ctx )
+ly_ctx_unset_disable_searchdirs ( struct ly_ctx* ctx )
+ly_ctx_unset_prefer_searchdirs ( struct ly_ctx* ctx )
+ly_ctx_unset_searchdirs ( struct ly_ctx* ctx, int index )
+ly_ctx_unset_trusted ( struct ly_ctx* ctx )
+ly_errno_glob_address ( )
+ly_path_data2schema ( struct ly_ctx* ctx, char const* data_path )
+ly_path_xml2json ( struct ly_ctx* ctx, char const* xml_path, struct lyxml_elem* xml )
+ly_verb ( enum LY_LOG_LEVEL level )
+ly_verb_dbg ( int dbg_groups )
+
+tree_data.h, libyang.so.1.9.19
+lyd_change_leaf ( struct lyd_node_leaf_list* leaf, char const* val_str )
+lyd_dec64_to_double ( struct lyd_node const* node )
+lyd_diff ( struct lyd_node* first, struct lyd_node* second, int options )
+lyd_dup ( struct lyd_node const* node, int options )
+lyd_dup_to_ctx ( struct lyd_node const* node, int options, struct ly_ctx* ctx )
+lyd_dup_withsiblings ( struct lyd_node const* node, int options )
+lyd_find_instance ( struct lyd_node const* data, struct lys_node const* schema )
+lyd_find_path ( struct lyd_node const* ctx_node, char const* path )
+lyd_find_sibling ( struct lyd_node const* siblings, struct lyd_node const* target, struct lyd_node** match )
+lyd_find_sibling_set ( struct lyd_node const* siblings, struct lyd_node const* target, struct ly_set** set )
+lyd_free ( struct lyd_node* node )
+lyd_free_attr ( struct ly_ctx* ctx, struct lyd_node* parent, struct lyd_attr* attr, int recursive )
+lyd_free_diff ( struct lyd_difflist* diff )
+lyd_free_val_diff ( struct lyd_difflist* diff )
+lyd_free_withsiblings ( struct lyd_node* node )
+lyd_insert ( struct lyd_node* parent, struct lyd_node* node )
+lyd_insert_attr ( struct lyd_node* parent, struct lys_module const* mod, char const* name, char const* value )
+lyd_leaf_type ( struct lyd_node_leaf_list const* leaf )
+lyd_merge ( struct lyd_node* target, struct lyd_node const* source, int options )
+lyd_merge_to_ctx ( struct lyd_node** trg, struct lyd_node const* src, int options, struct ly_ctx* ctx )
+lyd_new ( struct lyd_node* parent, struct lys_module const* module, char const* name )
+lyd_new_anydata ( struct lyd_node* parent, struct lys_module const* module, char const* name, void* value, enum LYD_ANYDATA_VALUETYPE value_type )
+lyd_new_leaf ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const* val_str )
+lyd_new_output ( struct lyd_node* parent, struct lys_module const* module, char const* name )
+lyd_new_output_anydata ( struct lyd_node* parent, struct lys_module const* module, char const* name, void* value, enum LYD_ANYDATA_VALUETYPE value_type )
+lyd_new_output_leaf ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const* val_str )
+lyd_new_yangdata ( struct lys_module const* module, char const* name_template, char const* name )
+lyd_node_module ( struct lyd_node const* node )
+lyd_node_should_print ( struct lyd_node const* node, int options )
+lyd_parse_fd ( struct ly_ctx* ctx, int fd, enum LYD_FORMAT format, int options, ... )
+lyd_parse_mem ( struct ly_ctx* ctx, char const* data, enum LYD_FORMAT format, int options, ... )
+lyd_parse_path ( struct ly_ctx* ctx, char const* path, enum LYD_FORMAT format, int options, ... )
+lyd_parse_xml ( struct ly_ctx* ctx, struct lyxml_elem** root, int options, ... )
+lyd_schema_sort ( struct lyd_node* sibling, int recursive )
+lyd_unlink ( struct lyd_node* node )
+lyd_validate ( struct lyd_node** node, int options, void* var_arg, ... )
+lyd_validate_modules ( struct lyd_node** node, struct lys_module const** modules, int mod_count, int options, ... )
+lyd_validate_value ( struct lys_node* node, char const* value )
+lyd_value_type ( struct lys_node* node, char const* value, struct lys_type** type )
+lyd_wd_default ( struct lyd_node_leaf_list* node )
+
+tree_schema.h, libyang.so.1.9.19
+ly_clean_plugins ( )
+ly_get_loaded_plugins ( )
+ly_load_plugins ( )
+ly_register_exts ( struct lyext_plugin_list* plugin, char const* log_name )
+ly_register_types ( struct lytype_plugin_list* plugin, char const* log_name )
+lys_data_path ( struct lys_node const* node )
+lys_data_path_pattern ( struct lys_node const* node, char const* placeholder )
+lys_ext_complex_get_substmt ( enum LY_STMT stmt, struct lys_ext_instance_complex* ext, struct lyext_substmt** info )
+lys_ext_instance_presence ( struct lys_ext* def, struct lys_ext_instance** ext, uint8_t ext_size )
+lys_ext_instance_substmt ( struct lys_ext_instance const* ext )
+lys_features_disable ( struct lys_module const* module, char const* feature )
+lys_features_disable_force ( struct lys_module const* module, char const* feature )
+lys_features_enable ( struct lys_module const* module, char const* feature )
+lys_features_enable_force ( struct lys_module const* module, char const* feature )
+lys_features_list ( struct lys_module const* module, uint8_t** states )
+lys_features_state ( struct lys_module const* module, char const* feature )
+lys_getnext_union_type ( struct lys_type const* last, struct lys_type const* type )
+lys_iffeature_value ( struct lys_iffeature const* iff )
+lys_implemented_module ( struct lys_module const* mod )
+lys_is_disabled ( struct lys_node const* node, int recursive )
+lys_is_key ( struct lys_node_leaf const* node, uint8_t* index )
+lys_main_module ( struct lys_module const* module )
+lys_node_module ( struct lys_node const* node )
+lys_node_xpath_atomize ( struct lys_node const* node, int options )
+lys_parent ( struct lys_node const* node )
+lys_path ( struct lys_node const* node, int options )
+lys_set_disabled ( struct lys_module const* module )
+lys_set_enabled ( struct lys_module const* module )
+lys_set_private ( struct lys_node const* node, void* priv )
+lys_xpath_atomize ( struct lys_node const* ctx_node, enum lyxp_node_type ctx_node_type, char const* expr, int options )
+
+xml.h, libyang.so.1.9.19
+lyxml_dup ( struct ly_ctx* ctx, struct lyxml_elem* root )
+lyxml_free ( struct ly_ctx* ctx, struct lyxml_elem* elem )
+lyxml_free_withsiblings ( struct ly_ctx* ctx, struct lyxml_elem* elem )
+lyxml_get_attr ( struct lyxml_elem const* elem, char const* name, char const* ns )
+lyxml_get_ns ( struct lyxml_elem const* elem, char const* prefix )
+lyxml_parse_mem ( struct ly_ctx* ctx, char const* data, int options )
+lyxml_parse_path ( struct ly_ctx* ctx, char const* filename, int options )
+lyxml_print_clb ( ssize_t(*writeclb)(void*, void const*, size_t), void* arg, struct lyxml_elem const* elem, int options )
+lyxml_print_fd ( int fd, struct lyxml_elem const* elem, int options )
+lyxml_print_file ( FILE* stream, struct lyxml_elem const* elem, int options )
+lyxml_print_mem ( char** strp, struct lyxml_elem const* elem, int options )
+lyxml_unlink ( struct ly_ctx* ctx, struct lyxml_elem* elem )
+
+to the top
+ +

Problems with Data Types, High Severity  17 


+tree_schema.h
+ +[+] struct lys_module  17  +
+ + +
+to the top
+ +

Problems with Symbols, High Severity  18 


+libyang.h, libyang.so.1.9.19
+ +[+] ly_ctx_new ( char const* search_dir, int options )  1  +
+ + +[+] ly_set_add ( struct ly_set* set, void* node, int options )  1  +
+ + +[+] ly_set_log_clb ( void(*clb)(LY_LOG_LEVEL, char const*, char const*), int path )  1  +
+ + +[+] ly_set_merge ( struct ly_set* trg, struct ly_set* src, int options )  1  +
+ +
+tree_data.h, libyang.so.1.9.19
+ +[+] lyd_find_sibling_val ( struct lyd_node const* siblings, struct lys_node const* schema, char const* key_or_value, struct lyd_node** match )  1  +
+ + +[+] lyd_new_path ( struct lyd_node* data_tree, struct ly_ctx const* ctx, char const* path, void* value, enum LYD_ANYDATA_VALUETYPE value_type, int options )  2  +
+ +
+tree_schema.h, libyang.so.1.9.19
+ +[+] lys_find_path ( struct lys_module const* cur_module, struct lys_node const* cur_node, char const* path )  4  +
+ + +[+] lys_print_clb ( ssize_t(*writeclb)(void*, void const*, size_t), void* arg, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_fd ( int fd, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_file ( FILE* f, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_mem ( char** strp, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_path ( char const* path, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_search_localfile ( char const*const* searchpaths, int cwd, char const* name, char const* revision, char** localfile, LYS_INFORMAT* format )  1  +
+ + +[+] lys_set_implemented ( struct lys_module const* module )  1  +
+ +
+to the top
+ +

Problems with Data Types, Medium Severity  37 


+libyang.h
+ +[+] enum LY_ERR  3  +
+ + +
+tree_data.h
+ +[+] struct lyd_node  11  +
+ + +
+tree_schema.h
+ +[+] enum LYS_INFORMAT  1  +
+ + + +[+] enum LYS_OUTFORMAT  2  +
+ + + +[+] struct lys_module  20  +
+ + +
+to the top
+ +

Problems with Symbols, Medium Severity  57 


+dict.h, libyang.so.1.9.19
+ +[+] lydict_insert ( struct ly_ctx* ctx, char const* value, size_t len )  3  +
+ + +[+] lydict_insert_zc ( struct ly_ctx* ctx, char* value )  3  +
+ +
+libyang.h, libyang.so.1.9.19
+ +[+] ly_ctx_get_module ( struct ly_ctx const* ctx, char const* name, char const* revision, int implemented )  1  +
+ + +[+] ly_ctx_get_options ( struct ly_ctx* ctx )  1  +
+ + +[+] ly_ctx_load_module ( struct ly_ctx* ctx, char const* name, char const* revision )  1  +
+ + +[+] ly_ctx_new ( char const* search_dir, int options )  3  +
+ + +[+] ly_set_add ( struct ly_set* set, void* node, int options )  1  +
+ + +[+] ly_set_clean ( struct ly_set* set )  2  +
+ + +[+] ly_set_contains ( struct ly_set const* set, void* node )  2  +
+ + +[+] ly_set_dup ( struct ly_set const* set )  4  +
+ + +[+] ly_set_free ( struct ly_set* set )  1  +
+ + +[+] ly_set_merge ( struct ly_set* trg, struct ly_set* src, int options )  1  +
+ + +[+] ly_set_new ( )  3  +
+ + +[+] ly_set_rm ( struct ly_set* set, void* node )  1  +
+ + +[+] ly_set_rm_index ( struct ly_set* set, unsigned int index )  1  +
+ +
+tree_data.h, libyang.so.1.9.19
+ +[+] lyd_find_sibling_val ( struct lyd_node const* siblings, struct lys_node const* schema, char const* key_or_value, struct lyd_node** match )  1  +
+ + +[+] lyd_insert_sibling ( struct lyd_node** sibling, struct lyd_node* node )  2  +
+ + +[+] lyd_new_path ( struct lyd_node* data_tree, struct ly_ctx const* ctx, char const* path, void* value, enum LYD_ANYDATA_VALUETYPE value_type, int options )  2  +
+ + +[+] lyd_path ( struct lyd_node const* node )  3  +
+ +
+tree_schema.h, libyang.so.1.9.19
+ +[+] lys_find_path ( struct lys_module const* cur_module, struct lys_node const* cur_node, char const* path )  2  +
+ + +[+] lys_getnext ( struct lys_node const* last, struct lys_node const* parent, struct lys_module const* module, int options )  4  +
+ + +[+] lys_parse_fd ( struct ly_ctx* ctx, int fd, enum LYS_INFORMAT format )  3  +
+ + +[+] lys_parse_mem ( struct ly_ctx* ctx, char const* data, enum LYS_INFORMAT format )  3  +
+ + +[+] lys_parse_path ( struct ly_ctx* ctx, char const* path, enum LYS_INFORMAT format )  3  +
+ + +[+] lys_print_clb ( ssize_t(*writeclb)(void*, void const*, size_t), void* arg, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_fd ( int fd, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_file ( FILE* f, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_mem ( char** strp, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_path ( char const* path, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_set_implemented ( struct lys_module const* module )  1  +
+ +
+to the top
+ +

Problems with Data Types, Low Severity  90 


+libyang.h
+ +[+] enum LY_VECODE  77  +
+ + + +[+] struct ly_set  3  +
+ + + +[+] typedef ly_module_imp_clb  1  +
+ + +
+tree_data.h
+ +[+] struct lyd_node  5  +
+ + +
+tree_schema.h
+ +[+] enum LYS_OUTFORMAT  2  +
+ + + +[+] struct lys_module  2  +
+ + +
+to the top
+ +

Problems with Symbols, Low Severity  57 


+dict.h, libyang.so.1.9.19
+ +[+] lydict_insert ( struct ly_ctx* ctx, char const* value, size_t len )  1  +
+ + +[+] lydict_insert_zc ( struct ly_ctx* ctx, char* value )  1  +
+ + +[+] lydict_remove ( struct ly_ctx* ctx, char const* value )  1  +
+ +
+libyang.h, libyang.so.1.9.19
+ +[+] ly_ctx_destroy ( struct ly_ctx* ctx, void(*private_destructor)(struct lys_node const*, void*) )  1  +
+ + +[+] ly_ctx_get_module ( struct ly_ctx const* ctx, char const* name, char const* revision, int implemented )  1  +
+ + +[+] ly_ctx_get_module_iter ( struct ly_ctx const* ctx, uint32_t* idx )  1  +
+ + +[+] ly_ctx_get_options ( struct ly_ctx* ctx )  1  +
+ + +[+] ly_ctx_internal_modules_count ( struct ly_ctx* ctx )  2  +
+ + +[+] ly_ctx_set_searchdir ( struct ly_ctx* ctx, char const* search_dir )  1  +
+ + +[+] ly_get_log_clb ( )  1  +
+ + +[+] ly_log_options ( int opts )  2  +
+ + +[+] ly_set_add ( struct ly_set* set, void* node, int options )  2  +
+ + +[+] ly_set_contains ( struct ly_set const* set, void* node )  1  +
+ + +[+] ly_set_log_clb ( void(*clb)(LY_LOG_LEVEL, char const*, char const*), int path )  1  +
+ + +[+] ly_set_merge ( struct ly_set* trg, struct ly_set* src, int options )  1  +
+ + +[+] ly_set_rm ( struct ly_set* set, void* node )  2  +
+ + +[+] ly_set_rm_index ( struct ly_set* set, unsigned int index )  2  +
+ +
+tree_data.h, libyang.so.1.9.19
+ +[+] lyd_find_sibling_val ( struct lyd_node const* siblings, struct lys_node const* schema, char const* key_or_value, struct lyd_node** match )  1  +
+ + +[+] lyd_first_sibling ( struct lyd_node* node )  1  +
+ + +[+] lyd_insert_after ( struct lyd_node* sibling, struct lyd_node* node )  1  +
+ + +[+] lyd_insert_before ( struct lyd_node* sibling, struct lyd_node* node )  1  +
+ + +[+] lyd_insert_sibling ( struct lyd_node** sibling, struct lyd_node* node )  2  +
+ + +[+] lyd_list_pos ( struct lyd_node const* node )  2  +
+ + +[+] lyd_new_path ( struct lyd_node* data_tree, struct ly_ctx const* ctx, char const* path, void* value, enum LYD_ANYDATA_VALUETYPE value_type, int options )  5  +
+ + +[+] lyd_print_clb ( ssize_t(*writeclb)(void*, void const*, size_t), void* arg, struct lyd_node const* root, enum LYD_FORMAT format, int options )  4  +
+ + +[+] lyd_print_fd ( int fd, struct lyd_node const* root, enum LYD_FORMAT format, int options )  2  +
+ + +[+] lyd_print_file ( FILE* f, struct lyd_node const* root, enum LYD_FORMAT format, int options )  2  +
+ + +[+] lyd_print_mem ( char** strp, struct lyd_node const* root, enum LYD_FORMAT format, int options )  2  +
+ + +[+] lyd_print_path ( char const* path, struct lyd_node const* root, enum LYD_FORMAT format, int options )  2  +
+ +
+tree_schema.h, libyang.so.1.9.19
+ +[+] lys_getnext ( struct lys_node const* last, struct lys_node const* parent, struct lys_module const* module, int options )  1  +
+ + +[+] lys_print_clb ( ssize_t(*writeclb)(void*, void const*, size_t), void* arg, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  3  +
+ + +[+] lys_print_fd ( int fd, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_file ( FILE* f, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_mem ( char** strp, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_path ( char const* path, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_search_localfile ( char const*const* searchpaths, int cwd, char const* name, char const* revision, char** localfile, LYS_INFORMAT* format )  1  +
+ + +[+] lys_set_implemented ( struct lys_module const* module )  1  +
+ +
+to the top
+ +

Other Changes in Data Types  7 


+libyang.h
+ +[+] enum LY_ERR  6  +
+ + +
+tree_schema.h
+ +[+] enum LYS_OUTFORMAT  1  +
+ + +
+to the top
+

Header Files  7 


+
+dict.h
+extensions.h
+libyang.h
+tree_data.h
+tree_schema.h
+user_types.h
+xml.h
+
+
to the top
+

Source Files  11 


+
+common.c
+context.c
+hash_table.c
+log.c
+parser_lyb.c
+parser_xml.c
+plugins.c
+printer.c
+tree_data.c
+tree_schema.c
+xml.c
+
+
to the top
+

Objects  1 


+
+libyang.so.1.9.19
+
+
to the top
+


+

Test Info


+ + + + + + +
Module Namelibyang.so
Version #11.9.19
Version #22.0.0
Archx86_64
SubjectSource Compatibility
+

Test Results


+ + + + + + + +
Total Header Files7
Total Source Files11
Total Objects1
Total Symbols / Types174 / 22
Compatibility14.1%
+

Problem Summary


+ + + + + + + + + + + +
SeverityCount
Added Symbols-154
Removed SymbolsHigh114
Problems with
Data Types
High112
Medium2
Low9
Problems with
Symbols
High13
Medium47
Low52
Problems with
Constants
Low0
Other Changes
in Data Types
-24
Other Changes
in Symbols
-10
+ +

Added Symbols  154 


+context.h
+ly_ctx_get_module_implemented ( struct ly_ctx const* ctx, char const* name )
+ly_ctx_get_module_implemented_ns ( struct ly_ctx const* ctx, char const* ns )
+ly_ctx_get_module_latest ( struct ly_ctx const* ctx, char const* name )
+ly_ctx_get_module_latest_ns ( struct ly_ctx const* ctx, char const* ns )
+ly_ctx_get_module_ns ( struct ly_ctx const* ctx, char const* ns, char const* revision )
+ly_ctx_get_yanglib_data ( struct ly_ctx const* ctx, struct lyd_node** root_p )
+ly_ctx_get_yanglib_id ( struct ly_ctx const* ctx )
+ly_ctx_reset_latests ( struct ly_ctx* ctx )
+ly_ctx_set_options ( struct ly_ctx* ctx, uint16_t option )
+ly_ctx_unset_options ( struct ly_ctx* ctx, uint16_t option )
+ly_ctx_unset_searchdir ( struct ly_ctx* ctx, char const* value )
+ly_ctx_unset_searchdir_last ( struct ly_ctx* ctx, uint32_t count )
+
+in.h
+ly_in_fd ( struct ly_in* in, int fd )
+ly_in_file ( struct ly_in* in, FILE* f )
+ly_in_filepath ( struct ly_in* in, char const* filepath, size_t len )
+ly_in_free ( struct ly_in* in, ly_bool destroy )
+ly_in_memory ( struct ly_in* in, char const* str )
+ly_in_new_fd ( int fd, struct ly_in** in )
+ly_in_new_file ( FILE* f, struct ly_in** in )
+ly_in_new_filepath ( char const* filepath, size_t len, struct ly_in** in )
+ly_in_new_memory ( char const* str, struct ly_in** in )
+ly_in_parsed ( struct ly_in const* in )
+ly_in_reset ( struct ly_in* in )
+ly_in_type ( struct ly_in const* in )
+
+log.h
+ly_err_last ( struct ly_ctx const* ctx )
+ly_errcode ( struct ly_ctx const* ctx )
+ly_log_dbg_groups ( uint32_t dbg_groups )
+ly_log_level ( enum LY_LOG_LEVEL level )
+
+out.h
+ly_out_clb ( struct ly_out* out, ly_write_clb writeclb )
+ly_out_clb_arg ( struct ly_out* out, void* arg )
+ly_out_fd ( struct ly_out* out, int fd )
+ly_out_file ( struct ly_out* out, FILE* f )
+ly_out_filepath ( struct ly_out* out, char const* filepath )
+ly_out_free ( struct ly_out* out, void(*clb_arg_destructor)(void*), ly_bool destroy )
+ly_out_new_clb ( ly_write_clb writeclb, void* user_data, struct ly_out** out )
+ly_out_new_fd ( int fd, struct ly_out** out )
+ly_out_new_file ( FILE* f, struct ly_out** out )
+ly_out_new_filepath ( char const* filepath, struct ly_out** out )
+ly_out_new_memory ( char** strp, size_t size, struct ly_out** out )
+ly_out_printed ( struct ly_out const* out )
+ly_out_reset ( struct ly_out* out )
+ly_out_type ( struct ly_out const* out )
+ly_print ( struct ly_out* out, char const* format, ... )
+ly_print_flush ( struct ly_out* out )
+ly_write ( struct ly_out* out, char const* buf, size_t len )
+
+parser_data.h
+lyd_parse_data ( struct ly_ctx const* ctx, struct ly_in* in, enum LYD_FORMAT format, uint32_t parse_options, uint32_t validate_options, struct lyd_node** tree )
+lyd_parse_data_fd ( struct ly_ctx const* ctx, int fd, enum LYD_FORMAT format, uint32_t parse_options, uint32_t validate_options, struct lyd_node** tree )
+lyd_parse_data_mem ( struct ly_ctx const* ctx, char const* data, enum LYD_FORMAT format, uint32_t parse_options, uint32_t validate_options, struct lyd_node** tree )
+lyd_parse_data_path ( struct ly_ctx const* ctx, char const* path, enum LYD_FORMAT format, uint32_t parse_options, uint32_t validate_options, struct lyd_node** tree )
+lyd_parse_notif ( struct ly_ctx const* ctx, struct ly_in* in, enum LYD_FORMAT format, struct lyd_node** tree, struct lyd_node** ntf )
+lyd_parse_reply ( struct lyd_node const* request, struct ly_in* in, enum LYD_FORMAT format, struct lyd_node** tree, struct lyd_node** op )
+lyd_parse_rpc ( struct ly_ctx const* ctx, struct ly_in* in, enum LYD_FORMAT format, struct lyd_node** tree, struct lyd_node** op )
+lyd_validate_all ( struct lyd_node** tree, struct ly_ctx const* ctx, uint32_t val_opts, struct lyd_node** diff )
+lyd_validate_module ( struct lyd_node** tree, struct lys_module const* module, uint32_t val_opts, struct lyd_node** diff )
+lyd_validate_op ( struct lyd_node* op_tree, struct lyd_node const* tree, enum LYD_VALIDATE_OP op, struct lyd_node** diff )
+
+parser_schema.h
+lys_parse ( struct ly_ctx* ctx, struct ly_in* in, enum LYS_INFORMAT format, char const** features, struct lys_module const** module )
+
+plugins_types.h
+ly_builtin_type_plugins [data]
+ly_err_free ( void* ptr )
+ly_err_new ( enum LY_LOG_LEVEL level, enum LY_ERR no, enum LY_VECODE vecode, char* msg, char* path, char* apptag )
+ly_type_identity_isderived ( struct lysc_ident* base, struct lysc_ident* der )
+ly_type_parse_dec64 ( uint8_t fraction_digits, char const* value, size_t value_len, int64_t* ret, struct ly_err_item** err )
+ly_type_parse_int ( char const* datatype, int base, int64_t min, int64_t max, char const* value, size_t value_len, int64_t* ret, struct ly_err_item** err )
+ly_type_parse_uint ( char const* datatype, int base, uint64_t max, char const* value, size_t value_len, uint64_t* ret, struct ly_err_item** err )
+ly_type_print_get_prefix ( struct lys_module const* mod, enum LY_PREFIX_FORMAT format, void* prefix_data )
+ly_type_store_resolve_prefix ( struct ly_ctx const* ctx, char const* prefix, size_t prefix_len, enum LY_PREFIX_FORMAT format, void* prefix_data )
+ly_type_validate_patterns ( struct lysc_pattern** patterns, char const* str, size_t str_len, struct ly_err_item** err )
+ly_type_validate_range ( enum LY_DATA_TYPE basetype, struct lysc_range* range, int64_t value, char const* strval, struct ly_err_item** err )
+lysc_prefixes_compile ( char const* str, size_t str_len, struct lysp_module const* prefix_mod, struct lysc_prefix** prefixes )
+lysc_prefixes_dup ( struct lysc_prefix const* orig, struct lysc_prefix** dup )
+lysc_prefixes_free ( struct lysc_prefix* prefixes )
+
+printer_data.h
+lyd_print_all ( struct ly_out* out, struct lyd_node const* root, enum LYD_FORMAT format, uint32_t options )
+lyd_print_tree ( struct ly_out* out, struct lyd_node const* root, enum LYD_FORMAT format, uint32_t options )
+
+printer_schema.h
+lys_print_module ( struct ly_out* out, struct lys_module const* module, enum LYS_OUTFORMAT format, size_t UNUSED_line_length, uint32_t options )
+lys_print_node ( struct ly_out* out, struct lysc_node const* node, enum LYS_OUTFORMAT format, size_t UNUSED_line_length, uint32_t options )
+lys_print_submodule ( struct ly_out* out, struct lys_module const* module, struct lysp_submodule const* submodule, enum LYS_OUTFORMAT format, size_t UNUSED_line_length, uint32_t options )
+
+set.h
+ly_set_erase ( struct ly_set* set, void(*destructor)(void*) )
+
+tree_data.h
+lyd_any_copy_value ( struct lyd_node* trg, union lyd_any_value const* value, enum LYD_ANYDATA_VALUETYPE value_type )
+lyd_change_meta ( struct lyd_meta* meta, char const* val_str )
+lyd_change_term ( struct lyd_node* term, char const* val_str )
+lyd_child ( struct lyd_node const* node )
+lyd_child_no_keys ( struct lyd_node const* node )
+lyd_compare_meta ( struct lyd_meta const* meta1, struct lyd_meta const* meta2 )
+lyd_compare_siblings ( struct lyd_node const* node1, struct lyd_node const* node2, uint32_t options )
+lyd_compare_single ( struct lyd_node const* node1, struct lyd_node const* node2, uint32_t options )
+lyd_diff_apply_all ( struct lyd_node** data, struct lyd_node const* diff )
+lyd_diff_apply_module ( struct lyd_node** data, struct lyd_node const* diff, struct lys_module const* mod, lyd_diff_cb diff_cb, void* cb_data )
+lyd_diff_merge_all ( struct lyd_node** diff, struct lyd_node const* src_diff )
+lyd_diff_merge_module ( struct lyd_node** diff, struct lyd_node const* src_diff, struct lys_module const* mod, lyd_diff_cb diff_cb, void* cb_data )
+lyd_diff_merge_tree ( struct lyd_node** diff_first, struct lyd_node* diff_parent, struct lyd_node const* src_sibling, lyd_diff_cb diff_cb, void* cb_data )
+lyd_diff_reverse_all ( struct lyd_node const* src_diff, struct lyd_node** diff )
+lyd_diff_siblings ( struct lyd_node const* first, struct lyd_node const* second, uint16_t options, struct lyd_node** diff )
+lyd_diff_tree ( struct lyd_node const* first, struct lyd_node const* second, uint16_t options, struct lyd_node** diff )
+lyd_dup_meta_single ( struct lyd_meta const* meta, struct lyd_node* node, struct lyd_meta** dup )
+lyd_dup_siblings ( struct lyd_node const* node, struct lyd_node_inner* parent, uint32_t options, struct lyd_node** dup )
+lyd_dup_single ( struct lyd_node const* node, struct lyd_node_inner* parent, uint32_t options, struct lyd_node** dup )
+lyd_find_meta ( struct lyd_meta const* first, struct lys_module const* module, char const* name )
+lyd_find_sibling_first ( struct lyd_node const* siblings, struct lyd_node const* target, struct lyd_node** match )
+lyd_find_xpath ( struct lyd_node const* ctx_node, char const* xpath, struct ly_set** set )
+lyd_free_all ( struct lyd_node* node )
+lyd_free_attr_siblings ( struct ly_ctx const* ctx, struct lyd_attr* attr )
+lyd_free_attr_single ( struct ly_ctx const* ctx, struct lyd_attr* attr )
+lyd_free_meta_siblings ( struct lyd_meta* meta )
+lyd_free_meta_single ( struct lyd_meta* meta )
+lyd_free_siblings ( struct lyd_node* node )
+lyd_free_tree ( struct lyd_node* node )
+lyd_insert_child ( struct lyd_node* parent, struct lyd_node* node )
+lyd_is_default ( struct lyd_node const* node )
+lyd_merge_siblings ( struct lyd_node** target, struct lyd_node const* source, uint16_t options )
+lyd_merge_tree ( struct lyd_node** target, struct lyd_node const* source, uint16_t options )
+lyd_new_any ( struct lyd_node* parent, struct lys_module const* module, char const* name, void const* value, enum LYD_ANYDATA_VALUETYPE value_type, ly_bool output, struct lyd_node** node )
+lyd_new_attr ( struct lyd_node* parent, char const* module_name, char const* name, char const* val_str, struct lyd_attr** attr )
+lyd_new_implicit_all ( struct lyd_node** tree, struct ly_ctx const* ctx, uint32_t implicit_options, struct lyd_node** diff )
+lyd_new_implicit_module ( struct lyd_node** tree, struct lys_module const* module, uint32_t implicit_options, struct lyd_node** diff )
+lyd_new_implicit_tree ( struct lyd_node* tree, uint32_t implicit_options, struct lyd_node** diff )
+lyd_new_inner ( struct lyd_node* parent, struct lys_module const* module, char const* name, ly_bool output, struct lyd_node** node )
+lyd_new_list ( struct lyd_node* parent, struct lys_module const* module, char const* name, ly_bool output, struct lyd_node** node, ... )
+lyd_new_list2 ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const* keys, ly_bool output, struct lyd_node** node )
+lyd_new_meta ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const* val_str, struct lyd_meta** meta )
+lyd_new_opaq ( struct lyd_node* parent, struct ly_ctx const* ctx, char const* name, char const* value, char const* module_name, struct lyd_node** node )
+lyd_new_path2 ( struct lyd_node* parent, struct ly_ctx const* ctx, char const* path, void const* value, enum LYD_ANYDATA_VALUETYPE value_type, uint32_t options, struct lyd_node** new_parent, struct lyd_node** new_node )
+lyd_new_term ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const* val_str, ly_bool output, struct lyd_node** node )
+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 )
+lyd_unlink_tree ( struct lyd_node* node )
+lyd_value_compare ( struct lyd_node_term const* node, char const* value, size_t value_len )
+lyd_value_validate ( struct ly_ctx const* ctx, struct lyd_node_term const* node, char const* value, size_t value_len, struct lyd_node const* tree, struct lysc_type const** realtype )
+
+tree_schema.h
+lyext_parent2str ( enum LYEXT_PARENT type )
+lys_feature_value ( struct lys_module const* module, char const* feature )
+lys_find_child ( struct lysc_node const* parent, struct lys_module const* module, char const* name, size_t name_len, uint16_t nodetype, uint32_t options )
+lys_find_expr_atoms ( struct lysc_node const* ctx_node, struct lys_module const* cur_mod, struct lyxp_expr const* expr, struct lysc_prefix const* prefixes, uint32_t options, struct ly_set** set )
+lys_find_lypath_atoms ( struct ly_path const* path, struct ly_set** set )
+lys_find_path_atoms ( struct ly_ctx const* ctx, struct lysc_node const* ctx_node, char const* path, ly_bool output, struct ly_set** set )
+lys_find_xpath ( struct lysc_node const* ctx_node, char const* xpath, uint32_t options, struct ly_set** set )
+lys_find_xpath_atoms ( struct lysc_node const* ctx_node, char const* xpath, uint32_t options, struct ly_set** set )
+lys_nodetype2str ( uint16_t nodetype )
+lys_value_validate ( struct ly_ctx const* ctx, struct lysc_node const* node, char const* value, size_t value_len )
+lysc_iffeature_value ( struct lysc_iffeature const* iff )
+lysc_module_dfs_full ( struct lys_module const* mod, lysc_dfs_clb dfs_clb, void* data )
+lysc_node_actions ( struct lysc_node const* node )
+lysc_node_children ( struct lysc_node const* node, uint16_t flags )
+lysc_node_children_full ( struct lysc_node const* node, uint16_t flags )
+lysc_node_notifs ( struct lysc_node const* node )
+lysc_node_parent_full ( struct lysc_node const* node )
+lysc_path ( struct lysc_node const* node, enum LYSC_PATH_TYPE pathtype, char* buffer, size_t buflen )
+lysc_set_private ( struct lysc_node const* node, void* priv, void** prev_priv_p )
+lysc_tree_dfs_full ( struct lysc_node const* root, lysc_dfs_clb dfs_clb, void* data )
+lysp_feature_next ( struct lysp_feature const* last, struct lysp_module const* pmod, uint32_t* idx )
+lysp_node_actions ( struct lysp_node const* node )
+lysp_node_children ( struct lysp_node const* node )
+lysp_node_groupings ( struct lysp_node const* node )
+lysp_node_notifs ( struct lysp_node const* node )
+lysp_node_typedefs ( struct lysp_node const* node )
+lyxp_get_expr ( struct lyxp_expr const* path )
+
+to the top
+

Removed Symbols  114 


+extensions.h
+lyext_vlog ( struct ly_ctx const* ctx, enum LY_VECODE vecode, char const* plugin, char const* function, enum LYEXT_VLOG_ELEM elem_type, void const* elem, char const* format, ... )
+lys_iffeature_free ( struct ly_ctx* ctx, struct lys_iffeature* iffeature, uint8_t iffeature_size, int shallow, void(*private_destructor)(struct lys_node const*, void*) )
+
+libyang.h
+ly_ctx_clean ( struct ly_ctx* ctx, void(*private_destructor)(struct lys_node const*, void*) )
+ly_ctx_find_path ( struct ly_ctx* ctx, char const* path )
+ly_ctx_get_disabled_module_iter ( struct ly_ctx const* ctx, uint32_t* idx )
+ly_ctx_get_module_by_ns ( struct ly_ctx const* ctx, char const* ns, char const* revision, int implemented )
+ly_ctx_get_module_data_clb ( struct ly_ctx const* ctx, void** user_data )
+ly_ctx_get_module_older ( struct ly_ctx const* ctx, struct lys_module const* module )
+ly_ctx_get_node ( struct ly_ctx const* ctx, struct lys_node const* start, char const* nodeid, int output )
+ly_ctx_get_submodule ( struct ly_ctx const* ctx, char const* module, char const* revision, char const* submodule, char const* sub_revision )
+ly_ctx_get_submodule2 ( struct lys_module const* main_module, char const* submodule )
+ly_ctx_info ( struct ly_ctx* ctx )
+ly_ctx_new_ylmem ( char const* search_dir, char const* data, enum LYD_FORMAT format, int options )
+ly_ctx_new_ylpath ( char const* search_dir, char const* path, enum LYD_FORMAT format, int options )
+ly_ctx_remove_module ( struct lys_module const* module, void(*private_destructor)(struct lys_node const*, void*) )
+ly_ctx_set_allimplemented ( struct ly_ctx* ctx )
+ly_ctx_set_disable_searchdir_cwd ( struct ly_ctx* ctx )
+ly_ctx_set_disable_searchdirs ( struct ly_ctx* ctx )
+ly_ctx_set_module_data_clb ( struct ly_ctx* ctx, ly_module_data_clb clb, void* user_data )
+ly_ctx_set_prefer_searchdirs ( struct ly_ctx* ctx )
+ly_ctx_set_trusted ( struct ly_ctx* ctx )
+ly_ctx_unset_allimplemented ( struct ly_ctx* ctx )
+ly_ctx_unset_disable_searchdir_cwd ( struct ly_ctx* ctx )
+ly_ctx_unset_disable_searchdirs ( struct ly_ctx* ctx )
+ly_ctx_unset_prefer_searchdirs ( struct ly_ctx* ctx )
+ly_ctx_unset_searchdirs ( struct ly_ctx* ctx, int index )
+ly_ctx_unset_trusted ( struct ly_ctx* ctx )
+ly_errno_glob_address ( )
+ly_path_data2schema ( struct ly_ctx* ctx, char const* data_path )
+ly_path_xml2json ( struct ly_ctx* ctx, char const* xml_path, struct lyxml_elem* xml )
+ly_verb ( enum LY_LOG_LEVEL level )
+ly_verb_dbg ( int dbg_groups )
+
+tree_data.h
+lyd_change_leaf ( struct lyd_node_leaf_list* leaf, char const* val_str )
+lyd_dec64_to_double ( struct lyd_node const* node )
+lyd_diff ( struct lyd_node* first, struct lyd_node* second, int options )
+lyd_dup ( struct lyd_node const* node, int options )
+lyd_dup_to_ctx ( struct lyd_node const* node, int options, struct ly_ctx* ctx )
+lyd_dup_withsiblings ( struct lyd_node const* node, int options )
+lyd_find_instance ( struct lyd_node const* data, struct lys_node const* schema )
+lyd_find_path ( struct lyd_node const* ctx_node, char const* path )
+lyd_find_sibling ( struct lyd_node const* siblings, struct lyd_node const* target, struct lyd_node** match )
+lyd_find_sibling_set ( struct lyd_node const* siblings, struct lyd_node const* target, struct ly_set** set )
+lyd_free ( struct lyd_node* node )
+lyd_free_attr ( struct ly_ctx* ctx, struct lyd_node* parent, struct lyd_attr* attr, int recursive )
+lyd_free_diff ( struct lyd_difflist* diff )
+lyd_free_val_diff ( struct lyd_difflist* diff )
+lyd_free_withsiblings ( struct lyd_node* node )
+lyd_insert ( struct lyd_node* parent, struct lyd_node* node )
+lyd_insert_attr ( struct lyd_node* parent, struct lys_module const* mod, char const* name, char const* value )
+lyd_leaf_type ( struct lyd_node_leaf_list const* leaf )
+lyd_merge ( struct lyd_node* target, struct lyd_node const* source, int options )
+lyd_merge_to_ctx ( struct lyd_node** trg, struct lyd_node const* src, int options, struct ly_ctx* ctx )
+lyd_new ( struct lyd_node* parent, struct lys_module const* module, char const* name )
+lyd_new_anydata ( struct lyd_node* parent, struct lys_module const* module, char const* name, void* value, enum LYD_ANYDATA_VALUETYPE value_type )
+lyd_new_leaf ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const* val_str )
+lyd_new_output ( struct lyd_node* parent, struct lys_module const* module, char const* name )
+lyd_new_output_anydata ( struct lyd_node* parent, struct lys_module const* module, char const* name, void* value, enum LYD_ANYDATA_VALUETYPE value_type )
+lyd_new_output_leaf ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const* val_str )
+lyd_new_yangdata ( struct lys_module const* module, char const* name_template, char const* name )
+lyd_node_module ( struct lyd_node const* node )
+lyd_node_should_print ( struct lyd_node const* node, int options )
+lyd_parse_fd ( struct ly_ctx* ctx, int fd, enum LYD_FORMAT format, int options, ... )
+lyd_parse_mem ( struct ly_ctx* ctx, char const* data, enum LYD_FORMAT format, int options, ... )
+lyd_parse_path ( struct ly_ctx* ctx, char const* path, enum LYD_FORMAT format, int options, ... )
+lyd_parse_xml ( struct ly_ctx* ctx, struct lyxml_elem** root, int options, ... )
+lyd_schema_sort ( struct lyd_node* sibling, int recursive )
+lyd_unlink ( struct lyd_node* node )
+lyd_validate ( struct lyd_node** node, int options, void* var_arg, ... )
+lyd_validate_modules ( struct lyd_node** node, struct lys_module const** modules, int mod_count, int options, ... )
+lyd_validate_value ( struct lys_node* node, char const* value )
+lyd_value_type ( struct lys_node* node, char const* value, struct lys_type** type )
+lyd_wd_default ( struct lyd_node_leaf_list* node )
+
+tree_schema.h
+ly_clean_plugins ( )
+ly_get_loaded_plugins ( )
+ly_load_plugins ( )
+ly_register_exts ( struct lyext_plugin_list* plugin, char const* log_name )
+ly_register_types ( struct lytype_plugin_list* plugin, char const* log_name )
+lys_data_path ( struct lys_node const* node )
+lys_data_path_pattern ( struct lys_node const* node, char const* placeholder )
+lys_ext_complex_get_substmt ( enum LY_STMT stmt, struct lys_ext_instance_complex* ext, struct lyext_substmt** info )
+lys_ext_instance_presence ( struct lys_ext* def, struct lys_ext_instance** ext, uint8_t ext_size )
+lys_ext_instance_substmt ( struct lys_ext_instance const* ext )
+lys_features_disable ( struct lys_module const* module, char const* feature )
+lys_features_disable_force ( struct lys_module const* module, char const* feature )
+lys_features_enable ( struct lys_module const* module, char const* feature )
+lys_features_enable_force ( struct lys_module const* module, char const* feature )
+lys_features_list ( struct lys_module const* module, uint8_t** states )
+lys_features_state ( struct lys_module const* module, char const* feature )
+lys_getnext_union_type ( struct lys_type const* last, struct lys_type const* type )
+lys_iffeature_value ( struct lys_iffeature const* iff )
+lys_implemented_module ( struct lys_module const* mod )
+lys_is_disabled ( struct lys_node const* node, int recursive )
+lys_is_key ( struct lys_node_leaf const* node, uint8_t* index )
+lys_main_module ( struct lys_module const* module )
+lys_node_module ( struct lys_node const* node )
+lys_node_xpath_atomize ( struct lys_node const* node, int options )
+lys_parent ( struct lys_node const* node )
+lys_path ( struct lys_node const* node, int options )
+lys_set_disabled ( struct lys_module const* module )
+lys_set_enabled ( struct lys_module const* module )
+lys_set_private ( struct lys_node const* node, void* priv )
+lys_xpath_atomize ( struct lys_node const* ctx_node, enum lyxp_node_type ctx_node_type, char const* expr, int options )
+
+xml.h
+lyxml_dup ( struct ly_ctx* ctx, struct lyxml_elem* root )
+lyxml_free ( struct ly_ctx* ctx, struct lyxml_elem* elem )
+lyxml_free_withsiblings ( struct ly_ctx* ctx, struct lyxml_elem* elem )
+lyxml_get_attr ( struct lyxml_elem const* elem, char const* name, char const* ns )
+lyxml_get_ns ( struct lyxml_elem const* elem, char const* prefix )
+lyxml_parse_mem ( struct ly_ctx* ctx, char const* data, int options )
+lyxml_parse_path ( struct ly_ctx* ctx, char const* filename, int options )
+lyxml_print_clb ( ssize_t(*writeclb)(void*, void const*, size_t), void* arg, struct lyxml_elem const* elem, int options )
+lyxml_print_fd ( int fd, struct lyxml_elem const* elem, int options )
+lyxml_print_file ( FILE* stream, struct lyxml_elem const* elem, int options )
+lyxml_print_mem ( char** strp, struct lyxml_elem const* elem, int options )
+lyxml_unlink ( struct ly_ctx* ctx, struct lyxml_elem* elem )
+
+to the top
+ +

Problems with Data Types, High Severity  112 


+libyang.h
+ +[+] enum LY_VECODE  77  +
+ + + +[+] struct ly_set  2  +
+ + +
+tree_data.h
+ +[+] struct lyd_node  6  +
+ + +
+tree_schema.h
+ +[+] enum LYS_OUTFORMAT  2  +
+ + + +[+] struct lys_module  25  +
+ + +
+to the top
+ +

Problems with Symbols, High Severity  13 


+libyang.h
+ +[+] ly_set_add ( struct ly_set* set, void* node, int options )  1  +
+ + +[+] ly_set_merge ( struct ly_set* trg, struct ly_set* src, int options )  1  +
+ +
+tree_data.h
+ +[+] lyd_find_sibling_val ( struct lyd_node const* siblings, struct lys_node const* schema, char const* key_or_value, struct lyd_node** match )  1  +
+ +
+tree_schema.h
+ +[+] lys_find_path ( struct lys_module const* cur_module, struct lys_node const* cur_node, char const* path )  4  +
+ + +[+] lys_print_clb ( ssize_t(*writeclb)(void*, void const*, size_t), void* arg, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_fd ( int fd, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_file ( FILE* f, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_mem ( char** strp, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_path ( char const* path, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_set_implemented ( struct lys_module const* module )  1  +
+ +
+to the top
+ +

Problems with Data Types, Medium Severity  2 


+tree_data.h
+ +[+] struct lyd_node  2  +
+ + +
+to the top
+ +

Problems with Symbols, Medium Severity  47 


+dict.h
+ +[+] lydict_insert ( struct ly_ctx* ctx, char const* value, size_t len )  2  +
+ + +[+] lydict_insert_zc ( struct ly_ctx* ctx, char* value )  2  +
+ +
+libyang.h
+ +[+] ly_ctx_get_module ( struct ly_ctx const* ctx, char const* name, char const* revision, int implemented )  1  +
+ + +[+] ly_ctx_load_module ( struct ly_ctx* ctx, char const* name, char const* revision )  1  +
+ + +[+] ly_ctx_new ( char const* search_dir, int options )  2  +
+ + +[+] ly_set_add ( struct ly_set* set, void* node, int options )  1  +
+ + +[+] ly_set_clean ( struct ly_set* set )  2  +
+ + +[+] ly_set_contains ( struct ly_set const* set, void* node )  1  +
+ + +[+] ly_set_dup ( struct ly_set const* set )  3  +
+ + +[+] ly_set_free ( struct ly_set* set )  1  +
+ + +[+] ly_set_merge ( struct ly_set* trg, struct ly_set* src, int options )  1  +
+ + +[+] ly_set_new ( )  2  +
+ + +[+] ly_set_rm ( struct ly_set* set, void* node )  1  +
+ + +[+] ly_set_rm_index ( struct ly_set* set, unsigned int index )  1  +
+ +
+tree_data.h
+ +[+] lyd_find_sibling_val ( struct lyd_node const* siblings, struct lys_node const* schema, char const* key_or_value, struct lyd_node** match )  1  +
+ + +[+] lyd_insert_sibling ( struct lyd_node** sibling, struct lyd_node* node )  2  +
+ + +[+] lyd_new_path ( struct lyd_node* data_tree, struct ly_ctx const* ctx, char const* path, void* value, enum LYD_ANYDATA_VALUETYPE value_type, int options )  2  +
+ + +[+] lyd_path ( struct lyd_node const* node )  3  +
+ +
+tree_schema.h
+ +[+] lys_find_path ( struct lys_module const* cur_module, struct lys_node const* cur_node, char const* path )  2  +
+ + +[+] lys_getnext ( struct lys_node const* last, struct lys_node const* parent, struct lys_module const* module, int options )  4  +
+ + +[+] lys_parse_fd ( struct ly_ctx* ctx, int fd, enum LYS_INFORMAT format )  2  +
+ + +[+] lys_parse_mem ( struct ly_ctx* ctx, char const* data, enum LYS_INFORMAT format )  2  +
+ + +[+] lys_parse_path ( struct ly_ctx* ctx, char const* path, enum LYS_INFORMAT format )  2  +
+ + +[+] lys_print_clb ( ssize_t(*writeclb)(void*, void const*, size_t), void* arg, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_fd ( int fd, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_file ( FILE* f, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_mem ( char** strp, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_path ( char const* path, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_set_implemented ( struct lys_module const* module )  1  +
+ +
+to the top
+ +

Problems with Data Types, Low Severity  9 


+libyang.h
+ +[+] typedef ly_module_imp_clb  1  +
+ + +
+tree_data.h
+ +[+] struct lyd_node  2  +
+ + +
+tree_schema.h
+ +[+] struct lys_module  6  +
+ + +
+to the top
+ +

Problems with Symbols, Low Severity  52 


+dict.h
+ +[+] lydict_insert ( struct ly_ctx* ctx, char const* value, size_t len )  1  +
+ + +[+] lydict_insert_zc ( struct ly_ctx* ctx, char* value )  1  +
+ +
+libyang.h
+ +[+] ly_ctx_destroy ( struct ly_ctx* ctx, void(*private_destructor)(struct lys_node const*, void*) )  1  +
+ + +[+] ly_ctx_get_module ( struct ly_ctx const* ctx, char const* name, char const* revision, int implemented )  1  +
+ + +[+] ly_ctx_get_options ( struct ly_ctx* ctx )  1  +
+ + +[+] ly_ctx_internal_modules_count ( struct ly_ctx* ctx )  1  +
+ + +[+] ly_ctx_new ( char const* search_dir, int options )  2  +
+ + +[+] ly_ctx_set_searchdir ( struct ly_ctx* ctx, char const* search_dir )  1  +
+ + +[+] ly_get_log_clb ( )  1  +
+ + +[+] ly_log_options ( int opts )  2  +
+ + +[+] ly_set_add ( struct ly_set* set, void* node, int options )  1  +
+ + +[+] ly_set_contains ( struct ly_set const* set, void* node )  1  +
+ + +[+] ly_set_dup ( struct ly_set const* set )  1  +
+ + +[+] ly_set_log_clb ( void(*clb)(LY_LOG_LEVEL, char const*, char const*), int path )  1  +
+ + +[+] ly_set_merge ( struct ly_set* trg, struct ly_set* src, int options )  1  +
+ + +[+] ly_set_new ( )  1  +
+ + +[+] ly_set_rm ( struct ly_set* set, void* node )  1  +
+ + +[+] ly_set_rm_index ( struct ly_set* set, unsigned int index )  1  +
+ +
+tree_data.h
+ +[+] lyd_find_sibling_val ( struct lyd_node const* siblings, struct lys_node const* schema, char const* key_or_value, struct lyd_node** match )  1  +
+ + +[+] lyd_insert_after ( struct lyd_node* sibling, struct lyd_node* node )  1  +
+ + +[+] lyd_insert_before ( struct lyd_node* sibling, struct lyd_node* node )  1  +
+ + +[+] lyd_insert_sibling ( struct lyd_node** sibling, struct lyd_node* node )  2  +
+ + +[+] lyd_list_pos ( struct lyd_node const* node )  1  +
+ + +[+] lyd_new_path ( struct lyd_node* data_tree, struct ly_ctx const* ctx, char const* path, void* value, enum LYD_ANYDATA_VALUETYPE value_type, int options )  4  +
+ + +[+] lyd_print_clb ( ssize_t(*writeclb)(void*, void const*, size_t), void* arg, struct lyd_node const* root, enum LYD_FORMAT format, int options )  2  +
+ + +[+] lyd_print_fd ( int fd, struct lyd_node const* root, enum LYD_FORMAT format, int options )  2  +
+ + +[+] lyd_print_file ( FILE* f, struct lyd_node const* root, enum LYD_FORMAT format, int options )  2  +
+ + +[+] lyd_print_mem ( char** strp, struct lyd_node const* root, enum LYD_FORMAT format, int options )  2  +
+ + +[+] lyd_print_path ( char const* path, struct lyd_node const* root, enum LYD_FORMAT format, int options )  2  +
+ +
+tree_schema.h
+ +[+] lys_getnext ( struct lys_node const* last, struct lys_node const* parent, struct lys_module const* module, int options )  1  +
+ + +[+] lys_parse_fd ( struct ly_ctx* ctx, int fd, enum LYS_INFORMAT format )  1  +
+ + +[+] lys_parse_mem ( struct ly_ctx* ctx, char const* data, enum LYS_INFORMAT format )  1  +
+ + +[+] lys_parse_path ( struct ly_ctx* ctx, char const* path, enum LYS_INFORMAT format )  1  +
+ + +[+] lys_print_clb ( ssize_t(*writeclb)(void*, void const*, size_t), void* arg, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_fd ( int fd, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_file ( FILE* f, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_mem ( char** strp, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_print_path ( char const* path, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ + +[+] lys_search_localfile ( char const*const* searchpaths, int cwd, char const* name, char const* revision, char** localfile, LYS_INFORMAT* format )  2  +
+ + +[+] lys_set_implemented ( struct lys_module const* module )  1  +
+ +
+to the top
+ +

Other Changes in Data Types  24 


+libyang.h
+ +[+] enum LY_ERR  9  +
+ + +
+tree_data.h
+ +[+] struct lyd_node  5  +
+ + +
+tree_schema.h
+ +[+] enum LYS_INFORMAT  1  +
+ + + +[+] enum LYS_OUTFORMAT  3  +
+ + + +[+] struct lys_module  6  +
+ + +
+to the top
+ +

Other Changes in Symbols  10 


+libyang.h
+ +[+] ly_ctx_get_module_iter ( struct ly_ctx const* ctx, uint32_t* idx )  1  +
+ + +[+] ly_set_add ( struct ly_set* set, void* node, int options )  1  +
+ + +[+] ly_set_contains ( struct ly_set const* set, void* node )  1  +
+ + +[+] ly_set_rm ( struct ly_set* set, void* node )  1  +
+ +
+tree_data.h
+ +[+] lyd_list_pos ( struct lyd_node const* node )  1  +
+ + +[+] lyd_new_path ( struct lyd_node* data_tree, struct ly_ctx const* ctx, char const* path, void* value, enum LYD_ANYDATA_VALUETYPE value_type, int options )  3  +
+ + +[+] lyd_print_clb ( ssize_t(*writeclb)(void*, void const*, size_t), void* arg, struct lyd_node const* root, enum LYD_FORMAT format, int options )  1  +
+ +
+tree_schema.h
+ +[+] lys_print_clb ( ssize_t(*writeclb)(void*, void const*, size_t), void* arg, struct lys_module const* module, enum LYS_OUTFORMAT format, char const* target_node, int line_length, int options )  1  +
+ +
+to the top
+

Header Files  7 


+
+dict.h
+extensions.h
+libyang.h
+tree_data.h
+tree_schema.h
+user_types.h
+xml.h
+
+
to the top
+

Source Files  11 


+
+common.c
+context.c
+hash_table.c
+log.c
+parser_lyb.c
+parser_xml.c
+plugins.c
+printer.c
+tree_data.c
+tree_schema.c
+xml.c
+
+
to the top
+

Objects  1 


+
+libyang.so.1.9.19
+
+
to the top
+



+ +
+ + diff --git a/doc/compat_report_2_3.html b/doc/compat_report_2_3.html new file mode 100644 index 0000000..90bfe04 --- /dev/null +++ b/doc/compat_report_2_3.html @@ -0,0 +1,3221 @@ + + + + + + + + + +libyang.so: 2.47.2 to 3.0.0 compatibility report + + + +

API compatibility report for the libyang.so object between 2.47.2 and 3.0.0 versions on x86_64

+ +
+
+

Test Info


+ + + + + + + +
Module Namelibyang.so
Version #12.47.2
Version #23.0.0
Archx86_64
GCC Version13.2.1
SubjectBinary Compatibility
+

Test Results


+ + + + + + +
Total Header Files17
Total Objects1
Total Symbols / Types391 / 104
Compatibility65.9%
+

Problem Summary


+ + + + + + + + + +
SeverityCount
Added Symbols-15
Removed SymbolsHigh19
Problems with
Data Types
High0
Medium7
Low7
Problems with
Symbols
High26
Medium4
Low18
Problems with
Constants
Low0
+ +

Added Symbols  15 


+log.h, libyang.so.3.0.0
+ly_last_logmsg ( )
+ly_strerr ( )
+
+plugins_types.h, libyang.so.3.0.0
+lyplg_type_sort_binary ( struct ly_ctx const* UNUSED_ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_bits ( struct ly_ctx const* UNUSED_ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_boolean ( struct ly_ctx const* UNUSED_ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_decimal64 ( struct ly_ctx const* UNUSED_ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_enum ( struct ly_ctx const* UNUSED_ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_identityref ( struct ly_ctx const* UNUSED_ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_instanceid ( struct ly_ctx const* ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_int ( struct ly_ctx const* UNUSED_ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_leafref ( struct ly_ctx const* ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_simple ( struct ly_ctx const* ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_uint ( struct ly_ctx const* UNUSED_ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_union ( struct ly_ctx const* ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+
+printer_data.h, libyang.so.3.0.0
+lyd_metadata_should_print ( struct lyd_meta const* meta )
+
+to the top
+

Removed Symbols  19 


+context.h, libyang.so.2.47.2
+ly_ctx_reset_latests ( struct ly_ctx* ctx )
+
+log.h, libyang.so.2.47.2
+ly_errapptag ( struct ly_ctx const* ctx )
+ly_errcode ( struct ly_ctx const* ctx )
+ly_errmsg ( struct ly_ctx const* ctx )
+ly_errpath ( struct ly_ctx const* ctx )
+ly_last_errmsg ( )
+ly_strerrcode ( )
+ly_vecode ( struct ly_ctx const* ctx )
+
+tree_data.h, libyang.so.2.47.2
+lyd_child ( struct lyd_node const* node )
+lyd_find_xpath4 ( struct lyd_node const* ctx_node, struct lyd_node const* tree, char const* xpath, void* prefix_data, struct lyxp_var const* vars, struct ly_set** set )
+lyd_get_value ( struct lyd_node const* node )
+lyd_new_list3_bin ( struct lyd_node* parent, struct lys_module const* module, char const* name, void const** key_values, uint32_t* value_lengths, ly_bool output, struct lyd_node** node )
+lyd_new_list3_canon ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const** key_values, uint32_t* value_lengths, ly_bool output, struct lyd_node** node )
+lyd_new_list_bin ( struct lyd_node* parent, struct lys_module const* module, char const* name, ly_bool output, struct lyd_node** node, ... )
+lyd_new_list_canon ( struct lyd_node* parent, struct lys_module const* module, char const* name, ly_bool output, struct lyd_node** node, ... )
+lyd_new_term_bin ( struct lyd_node* parent, struct lys_module const* module, char const* name, void const* value, size_t value_len, ly_bool output, struct lyd_node** node )
+lyd_new_term_canon ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const* val_str, ly_bool output, struct lyd_node** node )
+lyd_parent ( struct lyd_node const* node )
+lyd_target ( struct ly_path const* path, struct lyd_node const* tree )
+
+to the top
+ +

Problems with Symbols, High Severity  26 


+plugins_types.h, libyang.so.2.47.2
+ +[+] lyplg_type_compare_binary ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ + +[+] lyplg_type_compare_bits ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ + +[+] lyplg_type_compare_boolean ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ + +[+] lyplg_type_compare_decimal64 ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ + +[+] lyplg_type_compare_identityref ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ + +[+] lyplg_type_compare_instanceid ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ + +[+] lyplg_type_compare_int ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ + +[+] lyplg_type_compare_leafref ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ + +[+] lyplg_type_compare_simple ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ + +[+] lyplg_type_compare_uint ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ + +[+] lyplg_type_compare_union ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ +
+tree_data.h, libyang.so.2.47.2
+ +[+] lyd_find_xpath3 ( struct lyd_node const* ctx_node, struct lyd_node const* tree, char const* xpath, struct lyxp_var const* vars, struct ly_set** set )  2  +
+ + +[+] lyd_new_any ( struct lyd_node* parent, struct lys_module const* module, char const* name, void const* value, ly_bool use_value, ly_bool output, struct lyd_node** node )  3  +
+ + +[+] lyd_new_ext_list ( struct lysc_ext_instance const* ext, char const* name, struct lyd_node** node, ... )  1  +
+ + +[+] lyd_new_ext_term ( struct lysc_ext_instance const* ext, char const* name, char const* val_str, struct lyd_node** node )  3  +
+ + +[+] lyd_new_list ( struct lyd_node* parent, struct lys_module const* module, char const* name, ly_bool output, struct lyd_node** node, ... )  1  +
+ + +[+] lyd_new_list2 ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const* keys, ly_bool output, struct lyd_node** node )  1  +
+ + +[+] lyd_new_list3 ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const** key_values, uint32_t* value_lengths, ly_bool output, struct lyd_node** node )  1  +
+ + +[+] lyd_new_meta ( struct ly_ctx const* ctx, struct lyd_node* parent, struct lys_module const* module, char const* name, char const* val_str, ly_bool clear_dflt, struct lyd_meta** meta )  1  +
+ + +[+] lyd_new_meta2 ( struct ly_ctx const* ctx, struct lyd_node* parent, ly_bool clear_dflt, struct lyd_attr const* attr, struct lyd_meta** meta )  1  +
+ + +[+] lyd_new_term ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const* val_str, ly_bool output, struct lyd_node** node )  1  +
+ +
+to the top
+ +

Problems with Data Types, Medium Severity  7 


+log.h
+ +[+] struct ly_err_item  2  +
+ + +
+tree_schema.h
+ +[+] struct lysc_ext  1  +
+ + + +[+] struct lysc_type  1  +
+ + + +[+] struct lysc_type_bits  1  +
+ + + +[+] struct lysc_type_leafref  2  +
+ + +
+to the top
+ +

Problems with Symbols, Medium Severity  4 


+log.h, libyang.so.2.47.2
+ +[+] ly_err_first ( struct ly_ctx const* ctx )  1  +
+ + +[+] ly_err_last ( struct ly_ctx const* ctx )  1  +
+ + +[+] ly_set_log_clb ( void(*clb)(, char const*, char const*), ly_bool path )  1  +
+ +
+tree_data.h, libyang.so.2.47.2
+ +[+] lyd_new_ext_term ( struct lysc_ext_instance const* ext, char const* name, char const* val_str, struct lyd_node** node )  1  +
+ +
+to the top
+ +

Problems with Data Types, Low Severity  7 


+log.h
+ +[+] struct ly_err_item  3  +
+ + + +[+] typedef ly_log_clb  1  +
+ + +
+plugins_types.h
+ +[+] typedef lyplg_type_sort_clb  1  +
+ + +
+tree_schema.h
+ +[+] struct lysc_type  1  +
+ + + +[+] struct lysc_type_bits  1  +
+ + +
+to the top
+ +

Problems with Symbols, Low Severity  18 


+log.h, libyang.so.2.47.2
+ +[+] ly_err_first ( struct ly_ctx const* ctx )  1  +
+ + +[+] ly_err_last ( struct ly_ctx const* ctx )  1  +
+ + +[+] ly_err_print ( struct ly_ctx const* ctx, struct ly_err_item* eitem )  1  +
+ + +[+] ly_temp_log_options ( uint32_t* opts )  1  +
+ +
+plugins_exts.h, libyang.so.2.47.2
+ +[+] lyplg_ext_compile_log ( struct lysc_ctx const* cctx, struct lysc_ext_instance const* ext, char const* format, ... )  1  +
+ + +[+] lyplg_ext_compile_log_err ( struct ly_err_item const* err, struct lysc_ext_instance const* ext )  1  +
+ + +[+] lyplg_ext_compile_log_path ( char const* path, struct lysc_ext_instance const* ext, char const* format, ... )  1  +
+ + +[+] lyplg_ext_parse_log ( struct lysp_ctx const* pctx, struct lysp_ext_instance const* ext, char const* format, ... )  1  +
+ +
+plugins_types.h, libyang.so.2.47.2
+ +[+] ly_err_new ( struct ly_err_item** err, char* path, char* apptag, char const* err_format, ... )  1  +
+ +
+tree_data.h, libyang.so.2.47.2
+ +[+] lyd_new_ext_any ( struct lysc_ext_instance const* ext, char const* name, void const* value, ly_bool use_value, struct lyd_node** node )  2  +
+ + +[+] lyd_new_list ( struct lyd_node* parent, struct lys_module const* module, char const* name, ly_bool output, struct lyd_node** node, ... )  1  +
+ + +[+] lyd_new_list2 ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const* keys, ly_bool output, struct lyd_node** node )  1  +
+ + +[+] lyd_new_list3 ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const** key_values, uint32_t* value_lengths, ly_bool output, struct lyd_node** node )  1  +
+ + +[+] lyd_new_meta ( struct ly_ctx const* ctx, struct lyd_node* parent, struct lys_module const* module, char const* name, char const* val_str, ly_bool clear_dflt, struct lyd_meta** meta )  1  +
+ + +[+] lyd_new_meta2 ( struct ly_ctx const* ctx, struct lyd_node* parent, ly_bool clear_dflt, struct lyd_attr const* attr, struct lyd_meta** meta )  1  +
+ + +[+] lyd_new_term ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const* val_str, ly_bool output, struct lyd_node** node )  2  +
+ +
+to the top
+

Header Files  17 


+
+context.h
+dict.h
+hash_table.h
+in.h
+log.h
+metadata.h
+out.h
+parser_data.h
+parser_schema.h
+plugins.h
+plugins_exts.h
+plugins_types.h
+printer_data.h
+printer_schema.h
+set.h
+tree_data.h
+tree_schema.h
+
+
to the top
+

Objects  1 


+
+libyang.so.2.47.2
+
+
to the top
+


+

Test Info


+ + + + + + +
Module Namelibyang.so
Version #12.47.2
Version #23.0.0
Archx86_64
SubjectSource Compatibility
+

Test Results


+ + + + + + +
Total Header Files17
Total Objects1
Total Symbols / Types391 / 104
Compatibility42.3%
+

Problem Summary


+ + + + + + + + + + +
SeverityCount
Added Symbols-15
Removed SymbolsHigh19
Problems with
Data Types
High4
Medium0
Low7
Problems with
Symbols
High20
Medium4
Low6
Problems with
Constants
Low0
Other Changes
in Symbols
-15
+ +

Added Symbols  15 


+log.h
+ly_last_logmsg ( )
+ly_strerr ( )
+
+plugins_types.h
+lyplg_type_sort_binary ( struct ly_ctx const* UNUSED_ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_bits ( struct ly_ctx const* UNUSED_ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_boolean ( struct ly_ctx const* UNUSED_ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_decimal64 ( struct ly_ctx const* UNUSED_ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_enum ( struct ly_ctx const* UNUSED_ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_identityref ( struct ly_ctx const* UNUSED_ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_instanceid ( struct ly_ctx const* ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_int ( struct ly_ctx const* UNUSED_ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_leafref ( struct ly_ctx const* ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_simple ( struct ly_ctx const* ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_uint ( struct ly_ctx const* UNUSED_ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+lyplg_type_sort_union ( struct ly_ctx const* ctx, struct lyd_value const* val1, struct lyd_value const* val2 )
+
+printer_data.h
+lyd_metadata_should_print ( struct lyd_meta const* meta )
+
+to the top
+

Removed Symbols  19 


+context.h
+ly_ctx_reset_latests ( struct ly_ctx* ctx )
+
+log.h
+ly_errapptag ( struct ly_ctx const* ctx )
+ly_errcode ( struct ly_ctx const* ctx )
+ly_errmsg ( struct ly_ctx const* ctx )
+ly_errpath ( struct ly_ctx const* ctx )
+ly_last_errmsg ( )
+ly_strerrcode ( )
+ly_vecode ( struct ly_ctx const* ctx )
+
+tree_data.h
+lyd_child ( struct lyd_node const* node )
+lyd_find_xpath4 ( struct lyd_node const* ctx_node, struct lyd_node const* tree, char const* xpath, void* prefix_data, struct lyxp_var const* vars, struct ly_set** set )
+lyd_get_value ( struct lyd_node const* node )
+lyd_new_list3_bin ( struct lyd_node* parent, struct lys_module const* module, char const* name, void const** key_values, uint32_t* value_lengths, ly_bool output, struct lyd_node** node )
+lyd_new_list3_canon ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const** key_values, uint32_t* value_lengths, ly_bool output, struct lyd_node** node )
+lyd_new_list_bin ( struct lyd_node* parent, struct lys_module const* module, char const* name, ly_bool output, struct lyd_node** node, ... )
+lyd_new_list_canon ( struct lyd_node* parent, struct lys_module const* module, char const* name, ly_bool output, struct lyd_node** node, ... )
+lyd_new_term_bin ( struct lyd_node* parent, struct lys_module const* module, char const* name, void const* value, size_t value_len, ly_bool output, struct lyd_node** node )
+lyd_new_term_canon ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const* val_str, ly_bool output, struct lyd_node** node )
+lyd_parent ( struct lyd_node const* node )
+lyd_target ( struct ly_path const* path, struct lyd_node const* tree )
+
+to the top
+ +

Problems with Data Types, High Severity  4 


+log.h
+ +[+] struct ly_err_item  2  +
+ + +
+tree_schema.h
+ +[+] struct lysc_ext  1  +
+ + + +[+] struct lysc_type_leafref  1  +
+ + +
+to the top
+ +

Problems with Symbols, High Severity  20 


+plugins_types.h
+ +[+] lyplg_type_compare_binary ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ + +[+] lyplg_type_compare_bits ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ + +[+] lyplg_type_compare_boolean ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ + +[+] lyplg_type_compare_decimal64 ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ + +[+] lyplg_type_compare_identityref ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ + +[+] lyplg_type_compare_instanceid ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ + +[+] lyplg_type_compare_int ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ + +[+] lyplg_type_compare_leafref ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ + +[+] lyplg_type_compare_simple ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ + +[+] lyplg_type_compare_uint ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ + +[+] lyplg_type_compare_union ( struct lyd_value const* val1, struct lyd_value const* val2 )  1  +
+ +
+tree_data.h
+ +[+] lyd_find_xpath3 ( struct lyd_node const* ctx_node, struct lyd_node const* tree, char const* xpath, struct lyxp_var const* vars, struct ly_set** set )  2  +
+ + +[+] lyd_new_any ( struct lyd_node* parent, struct lys_module const* module, char const* name, void const* value, ly_bool use_value, ly_bool output, struct lyd_node** node )  3  +
+ + +[+] lyd_new_ext_list ( struct lysc_ext_instance const* ext, char const* name, struct lyd_node** node, ... )  1  +
+ + +[+] lyd_new_ext_term ( struct lysc_ext_instance const* ext, char const* name, char const* val_str, struct lyd_node** node )  3  +
+ +
+to the top
+ +

Problems with Symbols, Medium Severity  4 


+log.h
+ +[+] ly_err_first ( struct ly_ctx const* ctx )  1  +
+ + +[+] ly_err_last ( struct ly_ctx const* ctx )  1  +
+ + +[+] ly_set_log_clb ( void(*clb)(, char const*, char const*), ly_bool path )  1  +
+ +
+tree_data.h
+ +[+] lyd_new_ext_term ( struct lysc_ext_instance const* ext, char const* name, char const* val_str, struct lyd_node** node )  1  +
+ +
+to the top
+ +

Problems with Data Types, Low Severity  7 


+log.h
+ +[+] struct ly_err_item  2  +
+ + + +[+] typedef ly_log_clb  1  +
+ + +
+plugins_types.h
+ +[+] typedef lyplg_type_sort_clb  1  +
+ + +
+tree_schema.h
+ +[+] struct lysc_type  1  +
+ + + +[+] struct lysc_type_bits  1  +
+ + + +[+] struct lysc_type_leafref  1  +
+ + +
+to the top
+ +

Problems with Symbols, Low Severity  6 


+tree_data.h
+ +[+] lyd_new_list ( struct lyd_node* parent, struct lys_module const* module, char const* name, ly_bool output, struct lyd_node** node, ... )  1  +
+ + +[+] lyd_new_list2 ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const* keys, ly_bool output, struct lyd_node** node )  1  +
+ + +[+] lyd_new_list3 ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const** key_values, uint32_t* value_lengths, ly_bool output, struct lyd_node** node )  1  +
+ + +[+] lyd_new_meta ( struct ly_ctx const* ctx, struct lyd_node* parent, struct lys_module const* module, char const* name, char const* val_str, ly_bool clear_dflt, struct lyd_meta** meta )  1  +
+ + +[+] lyd_new_meta2 ( struct ly_ctx const* ctx, struct lyd_node* parent, ly_bool clear_dflt, struct lyd_attr const* attr, struct lyd_meta** meta )  1  +
+ + +[+] lyd_new_term ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const* val_str, ly_bool output, struct lyd_node** node )  1  +
+ +
+to the top
+ +

Other Changes in Symbols  15 


+log.h
+ +[+] ly_temp_log_options ( uint32_t* opts )  1  +
+ +
+plugins_exts.h
+ +[+] lyplg_ext_compile_log ( struct lysc_ctx const* cctx, struct lysc_ext_instance const* ext, char const* format, ... )  1  +
+ + +[+] lyplg_ext_compile_log_err ( struct ly_err_item const* err, struct lysc_ext_instance const* ext )  1  +
+ + +[+] lyplg_ext_compile_log_path ( char const* path, struct lysc_ext_instance const* ext, char const* format, ... )  1  +
+ + +[+] lyplg_ext_parse_log ( struct lysp_ctx const* pctx, struct lysp_ext_instance const* ext, char const* format, ... )  1  +
+ +
+plugins_types.h
+ +[+] ly_err_new ( struct ly_err_item** err, char* path, char* apptag, char const* err_format, ... )  1  +
+ +
+tree_data.h
+ +[+] lyd_new_ext_any ( struct lysc_ext_instance const* ext, char const* name, void const* value, ly_bool use_value, struct lyd_node** node )  2  +
+ + +[+] lyd_new_list ( struct lyd_node* parent, struct lys_module const* module, char const* name, ly_bool output, struct lyd_node** node, ... )  1  +
+ + +[+] lyd_new_list2 ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const* keys, ly_bool output, struct lyd_node** node )  1  +
+ + +[+] lyd_new_list3 ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const** key_values, uint32_t* value_lengths, ly_bool output, struct lyd_node** node )  1  +
+ + +[+] lyd_new_meta ( struct ly_ctx const* ctx, struct lyd_node* parent, struct lys_module const* module, char const* name, char const* val_str, ly_bool clear_dflt, struct lyd_meta** meta )  1  +
+ + +[+] lyd_new_meta2 ( struct ly_ctx const* ctx, struct lyd_node* parent, ly_bool clear_dflt, struct lyd_attr const* attr, struct lyd_meta** meta )  1  +
+ + +[+] lyd_new_term ( struct lyd_node* parent, struct lys_module const* module, char const* name, char const* val_str, ly_bool output, struct lyd_node** node )  2  +
+ +
+to the top
+

Header Files  17 


+
+context.h
+dict.h
+hash_table.h
+in.h
+log.h
+metadata.h
+out.h
+parser_data.h
+parser_schema.h
+plugins.h
+plugins_exts.h
+plugins_types.h
+printer_data.h
+printer_schema.h
+set.h
+tree_data.h
+tree_schema.h
+
+
to the top
+

Objects  1 


+
+libyang.so.2.47.2
+
+
to the top
+



+ +
+ + diff --git a/doc/logo.png b/doc/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..13878b7bd5fcfff729749ffc6cceac50a6a54a16 GIT binary patch literal 2792 zcmVP)=e@1>GB$sBKycmO=QnGudDpDEllOKrA#MJOyRL`q5uLPA1BmDk_j4~xYDi^YN$FJ8dqa;^NU4?u(4{!K)#bqi5j zM5MU^$Oljx92`8FmzPJ?)zvgKG(;@b-Q7(^MMVT)t&IYx1(2_`ABad>AOQ9Nc%7Y{ zP4)HlG(9~n-}5|bYipydtSnDp2*7Iqdo=ZlCY1u)0GLx!QpjSlFmbdPEiEn4>C>mz zgF*nz0JgDsR#9MEf2XF;IFl_`N0Ac{Nm6er|-EL>@P!@Xh z=#e)dE7k@ehI|tz<@&TQ$}4~T@(-yAOwmFKso6hh);JxeZ^OG%$8s)2z43JMAm1%>no1VH(L0|$H>#)=Lf zJ}d?Zu^hfw!6->iPImd~Ftt{XA3qig#Kmf&m%ZA{aa^jwVE9jad;8xvZ{94cEGe3p zn82GiZvX%p85xL*ijrNX-EK#8bTpQhmc(S61CT{T|CLp_9GU=P0s{kwwD@Xkv)QPy zu<*N2Yhhs_*=#o1G!TyCwk0Ga{Ce`_Nh$To*3{ILB5BtuI5=2xUblYbIBuKROj3Ht?-dml z0Sp=}N!zz?S0wFPjf{*)&g)hHfZs*u5;ML5*prfyqUkSvv$L~gGMRYCag)hJv$M03 z>#3=!ku!&^wmqca9P&qHWhDXvwA=6)8XAh4ni}48H8nK|4GooC4}%`EqCZ5X7D^64 zes*@Y1ho3{+QFC%gP3M~<-SAp{Xyj07*8a2!`#Utj;vLx&ED08|^ zXklRim6esq%ge*W#Do@2@CtbBzwQi1F*}VOe7YM`OmPN~I zwc_H%i@101-s-RzzAoPb;&eJuQBi?w*RH|gaHw9t!jcC>?ICM&auTJbrD$$$R<&Lg zy%ZT4skO6|ws}5( z^RD*V?RM+J!UA71S(=)fLQzo>CMPEqtw#s)K3qZAZ|cKcU0n>?;#n@23rCM0)#D4C z5*p@9AOuL0*=%Oe7SF1xs=~8p&lD?PXKLb2!8fKs!A%Ym6B9qeys_GNH#rF1x!B7( zyPZ|*P?tZ5(tw+pC?Y7ko4NJ?Pfyos-cUFA3=#b`K0f}hQ>RWz$qqT2?>aj>(c0R|o36FB z6`h@(lIxMFDkAzzQcfup-MvI|0JDmU3R$1P#Kc68?;tB08ylm<#6+!nhc*Gs+)yNi z_%oZ$vLD=NG*V+@<9B5@Ha3#cXw(XZb|L;&K}j_j40B?lSUVgJX7315QBjnen@hR5 zxfB%@r41!S!_j@yc5IJp24A|oR=#m2^lgoTA6C@2U)K|$a+4qv~1 zMO$0jdc`=fd~#_R%jYv1i0Hj44 1) { + if (asprintf(&dyn, "%" PRIu32, pos - 1) == -1) { + LOGMEM(LYD_CTX(node)); + rc = LY_EMEM; + goto cleanup; + } + meta_val = dyn; + } else { + meta_val = ""; } - meta_val = dyn; } else if (node->schema->nodetype == LYS_LIST) { meta_name = "yang:key"; diff --git a/src/hash_table.c b/src/hash_table.c index 4dbfdd1..6da79f2 100644 --- a/src/hash_table.c +++ b/src/hash_table.c @@ -264,7 +264,6 @@ lyht_find_rec(const struct ly_ht *ht, void *val_p, uint32_t hash, ly_bool mod, l if (col) { *col = 0; } - *rec_p = NULL; LYHT_ITER_HLIST_RECS(ht, hlist_idx, rec_idx, rec) { if ((rec->hash == hash) && val_equal(val_p, &rec->val, mod, ht->cb_data)) { @@ -278,6 +277,7 @@ lyht_find_rec(const struct ly_ht *ht, void *val_p, uint32_t hash, ly_bool mod, l } /* not found even in collisions */ + *rec_p = NULL; return LY_ENOTFOUND; } @@ -286,14 +286,10 @@ lyht_find(const struct ly_ht *ht, void *val_p, uint32_t hash, void **match_p) { struct ly_ht_rec *rec; - if (match_p) { - *match_p = NULL; - } - lyht_find_rec(ht, val_p, hash, 0, ht->val_equal, NULL, &rec); - if (rec && match_p) { - *match_p = rec->val; + if (match_p) { + *match_p = rec ? rec->val : NULL; } return rec ? LY_SUCCESS : LY_ENOTFOUND; } @@ -313,14 +309,14 @@ lyht_find_with_val_cb(const struct ly_ht *ht, void *val_p, uint32_t hash, lyht_v LIBYANG_API_DEF LY_ERR lyht_find_next_with_collision_cb(const struct ly_ht *ht, void *val_p, uint32_t hash, - lyht_value_equal_cb collision_val_equal, void **match_p) + lyht_value_equal_cb val_equal, void **match_p) { struct ly_ht_rec *rec; uint32_t rec_idx; uint32_t i; /* find the record of the previously found value */ - if (lyht_find_rec(ht, val_p, hash, 1, ht->val_equal, &i, &rec)) { + if (lyht_find_rec(ht, val_p, hash, 1, val_equal ? val_equal : ht->val_equal, &i, &rec)) { /* not found, cannot happen */ LOGINT_RET(NULL); } @@ -333,8 +329,8 @@ lyht_find_next_with_collision_cb(const struct ly_ht *ht, void *val_p, uint32_t h continue; } - if (collision_val_equal) { - if (collision_val_equal(val_p, &rec->val, 0, ht->cb_data)) { + if (val_equal) { + if (val_equal(val_p, &rec->val, 0, ht->cb_data)) { /* even the value matches */ if (match_p) { *match_p = rec->val; diff --git a/src/hash_table.h b/src/hash_table.h index 5780f1e..a0cd7b6 100644 --- a/src/hash_table.h +++ b/src/hash_table.h @@ -163,13 +163,14 @@ LIBYANG_API_DECL LY_ERR lyht_find_next(const struct ly_ht *ht, void *val_p, uint * @param[in] ht Hash table to search in. * @param[in] val_p Pointer to the previously found value in @p ht. * @param[in] hash Hash of the previously found value. - * @param[in] collision_val_equal Val equal callback to use for checking collisions. + * @param[in] val_equal Callback for checking value equivalence. Called with @p mod 1 when searching for the first value + * and then uses @p mod 0 to check all the following collisions. * @param[out] match_p Pointer to the matching value, optional. * @return LY_SUCCESS if value was found, * @return LY_ENOTFOUND if not found. */ LIBYANG_API_DECL LY_ERR lyht_find_next_with_collision_cb(const struct ly_ht *ht, void *val_p, uint32_t hash, - lyht_value_equal_cb collision_val_equal, void **match_p); + lyht_value_equal_cb val_equal, void **match_p); /** * @brief Insert a value into a hash table. diff --git a/src/log.c b/src/log.c index 9cb60b3..12d5753 100644 --- a/src/log.c +++ b/src/log.c @@ -381,19 +381,19 @@ ly_get_log_clb(void) } void -ly_log_location(const struct lysc_node *scnode, const struct lyd_node *dnode, const char *spath, const struct ly_in *in) +ly_log_location(const struct lysc_node *scnode, const struct lyd_node *dnode, const char *path, const struct ly_in *in) { if (scnode) { ly_set_add(&log_location.scnodes, (void *)scnode, 1, NULL); } - if (dnode || (!scnode && !spath && !in)) { + if (dnode || (!scnode && !path && !in)) { ly_set_add(&log_location.dnodes, (void *)dnode, 1, NULL); } - if (spath) { - char *s = strdup(spath); + if (path) { + char *s = strdup(path); LY_CHECK_ERR_RET(!s, LOGMEM(NULL), ); - ly_set_add(&log_location.spaths, s, 1, NULL); + ly_set_add(&log_location.paths, s, 1, NULL); } if (in) { ly_set_add(&log_location.inputs, (void *)in, 1, NULL); @@ -401,7 +401,7 @@ ly_log_location(const struct lysc_node *scnode, const struct lyd_node *dnode, co } void -ly_log_location_revert(uint32_t scnode_steps, uint32_t dnode_steps, uint32_t spath_steps, uint32_t in_steps) +ly_log_location_revert(uint32_t scnode_steps, uint32_t dnode_steps, uint32_t path_steps, uint32_t in_steps) { for (uint32_t i = scnode_steps; i && log_location.scnodes.count; i--) { log_location.scnodes.count--; @@ -411,8 +411,8 @@ ly_log_location_revert(uint32_t scnode_steps, uint32_t dnode_steps, uint32_t spa log_location.dnodes.count--; } - for (uint32_t i = spath_steps; i && log_location.spaths.count; i--) { - ly_set_rm_index(&log_location.spaths, log_location.spaths.count - 1, free); + for (uint32_t i = path_steps; i && log_location.paths.count; i--) { + ly_set_rm_index(&log_location.paths, log_location.paths.count - 1, free); } for (uint32_t i = in_steps; i && log_location.inputs.count; i--) { @@ -426,8 +426,8 @@ ly_log_location_revert(uint32_t scnode_steps, uint32_t dnode_steps, uint32_t spa if (dnode_steps && !log_location.dnodes.count) { ly_set_erase(&log_location.dnodes, NULL); } - if (spath_steps && !log_location.spaths.count) { - ly_set_erase(&log_location.spaths, free); + if (path_steps && !log_location.paths.count) { + ly_set_erase(&log_location.paths, free); } if (in_steps && !log_location.inputs.count) { ly_set_erase(&log_location.inputs, NULL); @@ -808,21 +808,38 @@ cleanup: static LY_ERR ly_vlog_build_path_line(const struct ly_ctx *ctx, char **data_path, char **schema_path, uint64_t *line) { + int r; + char *path; + *data_path = NULL; *schema_path = NULL; *line = 0; - if (log_location.spaths.count && ((const char *)(log_location.spaths.objs[log_location.spaths.count - 1]))[0]) { - /* simply get what is in the provided path string */ - *schema_path = strdup(log_location.spaths.objs[log_location.spaths.count - 1]); + /* data/schema node */ + if (log_location.dnodes.count) { + LY_CHECK_RET(ly_vlog_build_data_path(ctx, data_path)); + } else if (log_location.scnodes.count) { + *schema_path = lysc_path(log_location.scnodes.objs[log_location.scnodes.count - 1], LYSC_PATH_LOG, NULL, 0); LY_CHECK_ERR_RET(!*schema_path, LOGMEM(ctx), LY_EMEM); - } else { - /* data/schema node */ - if (log_location.dnodes.count) { - LY_CHECK_RET(ly_vlog_build_data_path(ctx, data_path)); - } else if (log_location.scnodes.count) { - *schema_path = lysc_path(log_location.scnodes.objs[log_location.scnodes.count - 1], LYSC_PATH_LOG, NULL, 0); - LY_CHECK_ERR_RET(!*schema_path, LOGMEM(ctx), LY_EMEM); + } + + if (log_location.paths.count && ((const char *)(log_location.paths.objs[log_location.paths.count - 1]))[0]) { + /* append the provided path string to data/schema path, if any */ + if (*data_path) { + r = asprintf(&path, "%s%s", *data_path, (char *)log_location.paths.objs[log_location.paths.count - 1]); + } else if (*schema_path) { + r = asprintf(&path, "%s%s", *schema_path, (char *)log_location.paths.objs[log_location.paths.count - 1]); + } else { + r = asprintf(&path, "%s", (char *)log_location.paths.objs[log_location.paths.count - 1]); + } + LY_CHECK_ERR_RET(r == -1, LOGMEM(ctx), LY_EMEM); + + if (*data_path) { + free(*data_path); + *data_path = path; + } else { + free(*schema_path); + *schema_path = path; } } diff --git a/src/ly_common.h b/src/ly_common.h index ec0d3ea..51aba57 100644 --- a/src/ly_common.h +++ b/src/ly_common.h @@ -75,7 +75,7 @@ struct ly_log_location_s { struct ly_set inputs; /**< Set of const struct ly_in *in pointers providing the input handler with the line information (LIFO) */ struct ly_set scnodes; /**< Set of const struct lysc_node *scnode pointers providing the compiled schema node to generate path (LIFO) */ struct ly_set dnodes; /**< Set of const struct lyd_node *dnode pointers providing the data node to generate path (LIFO) */ - struct ly_set spaths; /**< Set of schema path strings (LIFO) */ + struct ly_set paths; /**< Set of path strings (LIFO) */ }; /** @@ -122,21 +122,21 @@ void ly_err_move(struct ly_ctx *src_ctx, struct ly_ctx *trg_ctx); * * @param[in] scnode Compiled schema node. * @param[in] dnode Data node. - * @param[in] spath Direct schema path string to print. + * @param[in] path Direct path string to append and print. * @param[in] in Input handler (providing line number). */ void ly_log_location(const struct lysc_node *scnode, const struct lyd_node *dnode, - const char *spath, const struct ly_in *in); + const char *path, const struct ly_in *in); /** * @brief Revert the specific logger location data by number of changes made by ::ly_log_location(). * * @param[in] scnode_steps Number of items in ::ly_log_location_s.scnodes to forget. * @param[in] dnode_steps Number of items in ::ly_log_location_s.dnodes to forget. - * @param[in] spath_steps Number of path strings in ::ly_log_location_s.spaths to forget. + * @param[in] path_steps Number of path strings in ::ly_log_location_s.paths to forget. * @param[in] in_steps Number of input handlers ::ly_log_location_s.inputs to forget. */ -void ly_log_location_revert(uint32_t scnode_steps, uint32_t dnode_steps, uint32_t spath_steps, uint32_t in_steps); +void ly_log_location_revert(uint32_t scnode_steps, uint32_t dnode_steps, uint32_t path_steps, uint32_t in_steps); /** * @brief Get the stored data node for logging at the index. diff --git a/src/parser_common.c b/src/parser_common.c index 5dadecf..789f567 100644 --- a/src/parser_common.c +++ b/src/parser_common.c @@ -54,6 +54,7 @@ #include "tree_data_internal.h" #include "tree_schema.h" #include "tree_schema_internal.h" +#include "validation.h" void lyd_ctx_free(struct lyd_ctx *lydctx) @@ -63,6 +64,7 @@ lyd_ctx_free(struct lyd_ctx *lydctx) ly_set_erase(&lydctx->node_when, NULL); ly_set_erase(&lydctx->ext_node, free); ly_set_erase(&lydctx->ext_val, free); + lyd_val_getnext_ht_free(lydctx->val_getnext_ht); } LY_ERR @@ -321,7 +323,7 @@ lyd_parser_create_meta(struct lyd_ctx *lydctx, struct lyd_node *parent, struct l void *prefix_data, uint32_t hints, const struct lysc_node *ctx_node) { LY_ERR rc = LY_SUCCESS; - char *dpath = NULL, *path = NULL; + char *path = NULL; ly_bool incomplete; struct lyd_meta *first = NULL; ly_bool store_only = (lydctx->parse_opts & LYD_PARSE_STORE_ONLY) == LYD_PARSE_STORE_ONLY ? 1 : 0; @@ -332,8 +334,7 @@ lyd_parser_create_meta(struct lyd_ctx *lydctx, struct lyd_node *parent, struct l } /* generate path to the metadata */ - LY_CHECK_RET(ly_vlog_build_data_path(lydctx->data_ctx->ctx, &dpath)); - if (asprintf(&path, "%s/@%s:%.*s", dpath, mod->name, (int)name_len, name) == -1) { + if (asprintf(&path, "/@%s:%.*s", mod->name, (int)name_len, name) == -1) { LOGMEM(lydctx->data_ctx->ctx); rc = LY_EMEM; goto cleanup; @@ -354,13 +355,12 @@ lyd_parser_create_meta(struct lyd_ctx *lydctx, struct lyd_node *parent, struct l cleanup: ly_log_location_revert(0, 0, 1, 0); - free(dpath); free(path); return rc; } LY_ERR -lyd_parse_check_keys(struct lyd_node *node) +lyd_parser_check_keys(struct lyd_node *node) { const struct lysc_node *skey = NULL; const struct lyd_node *key; @@ -381,7 +381,7 @@ lyd_parse_check_keys(struct lyd_node *node) } LY_ERR -lyd_parse_set_data_flags(struct lyd_node *node, struct lyd_meta **meta, struct lyd_ctx *lydctx, +lyd_parser_set_data_flags(struct lyd_node *node, struct lyd_meta **meta, struct lyd_ctx *lydctx, struct lysc_ext_instance *ext) { struct lyd_meta *meta2, *prev_meta = NULL, *next_meta = NULL; @@ -420,7 +420,7 @@ lyd_parse_set_data_flags(struct lyd_node *node, struct lyd_meta **meta, struct l } /* update dflt flag for all parent NP containers */ - lyd_cont_set_dflt(lyd_parent(node)); + lyd_np_cont_dflt_set(lyd_parent(node)); break; } @@ -444,6 +444,37 @@ lyd_parse_set_data_flags(struct lyd_node *node, struct lyd_meta **meta, struct l return LY_SUCCESS; } +LY_ERR +lyd_parser_validate_new_implicit(struct lyd_ctx *lydctx, struct lyd_node *node) +{ + LY_ERR r, rc = LY_SUCCESS; + + if (lyd_owner_module(node) != lydctx->val_getnext_ht_mod) { + /* free any previous getnext HT */ + lyd_val_getnext_ht_free(lydctx->val_getnext_ht); + + /* create the getnext HT for this module */ + r = lyd_val_getnext_ht_new(&lydctx->val_getnext_ht); + LY_CHECK_ERR_GOTO(r, rc = r, cleanup); + + lydctx->val_getnext_ht_mod = lyd_owner_module(node); + } + + /* new node validation, autodelete CANNOT occur (it can if multi-error), all nodes are new */ + r = lyd_validate_new(lyd_node_child_p(node), node->schema, NULL, NULL, lydctx->val_opts, lydctx->int_opts, + lydctx->val_getnext_ht, NULL); + LY_DPARSER_ERR_GOTO(r, rc = r, lydctx, cleanup); + + /* add any missing default children */ + r = lyd_new_implicit_r(node, lyd_node_child_p(node), NULL, NULL, &lydctx->node_when, &lydctx->node_types, + &lydctx->ext_node, (lydctx->val_opts & LYD_VALIDATE_NO_STATE) ? LYD_IMPLICIT_NO_STATE : 0, + lydctx->val_getnext_ht, NULL); + LY_CHECK_ERR_GOTO(r, rc = r, cleanup); + +cleanup: + return rc; +} + void lys_parser_fill_filepath(struct ly_ctx *ctx, struct ly_in *in, const char **filepath) { @@ -3569,7 +3600,7 @@ lysp_stmt_parse(struct lysp_ctx *pctx, const struct lysp_stmt *stmt, void **resu } LY_ERR -lys_parse_ext_instance_stmt(struct lysp_ctx *pctx, struct lysp_ext_substmt *substmt, struct lysp_stmt *stmt) +lys_parser_ext_instance_stmt(struct lysp_ctx *pctx, struct lysp_ext_substmt *substmt, struct lysp_stmt *stmt) { LY_ERR rc = LY_SUCCESS; diff --git a/src/parser_data.h b/src/parser_data.h index 4aa7c75..d7fbe18 100644 --- a/src/parser_data.h +++ b/src/parser_data.h @@ -332,29 +332,29 @@ LIBYANG_API_DECL LY_ERR lyd_parse_ext_data(const struct lysc_ext_instance *ext, * @{ */ enum lyd_type { - LYD_TYPE_DATA_YANG = 0, /* generic YANG instance data */ - LYD_TYPE_RPC_YANG, /* instance of a YANG RPC/action request with only "input" data children, - including all parents and optional top-level "action" element in case of an action */ - LYD_TYPE_NOTIF_YANG, /* instance of a YANG notification, including all parents in case of a nested one */ - LYD_TYPE_REPLY_YANG, /* instance of a YANG RPC/action reply with only "output" data children, - including all parents in case of an action */ + LYD_TYPE_DATA_YANG = 0, /**< generic YANG instance data */ + LYD_TYPE_RPC_YANG, /**< instance of a YANG RPC/action request with only "input" data children, + including all parents and optional top-level "action" element in case of an action */ + LYD_TYPE_NOTIF_YANG, /**< instance of a YANG notification, including all parents in case of a nested one */ + LYD_TYPE_REPLY_YANG, /**< instance of a YANG RPC/action reply with only "output" data children, + including all parents in case of an action */ - LYD_TYPE_RPC_NETCONF, /* complete NETCONF RPC invocation as defined for - [RPC](https://tools.ietf.org/html/rfc7950#section-7.14.4) and - [action](https://tools.ietf.org/html/rfc7950#section-7.15.2) */ - LYD_TYPE_NOTIF_NETCONF, /* complete NETCONF notification message as defined for - [notification](https://tools.ietf.org/html/rfc7950#section-7.16.2) */ - LYD_TYPE_REPLY_NETCONF, /* complete NETCONF RPC reply as defined for - [RPC](https://tools.ietf.org/html/rfc7950#section-7.14.4) and - [action](https://tools.ietf.org/html/rfc7950#section-7.15.2) */ + LYD_TYPE_RPC_NETCONF, /**< complete NETCONF RPC invocation as defined for + [RPC](https://tools.ietf.org/html/rfc7950#section-7.14.4) and + [action](https://tools.ietf.org/html/rfc7950#section-7.15.2) */ + LYD_TYPE_NOTIF_NETCONF, /**< complete NETCONF notification message as defined for + [notification](https://tools.ietf.org/html/rfc7950#section-7.16.2) */ + LYD_TYPE_REPLY_NETCONF, /**< complete NETCONF RPC reply as defined for + [RPC](https://tools.ietf.org/html/rfc7950#section-7.14.4) and + [action](https://tools.ietf.org/html/rfc7950#section-7.15.2) */ - LYD_TYPE_RPC_RESTCONF, /* message-body of a RESTCONF operation input parameters - ([ref](https://www.rfc-editor.org/rfc/rfc8040.html#section-3.6.1)) */ - LYD_TYPE_NOTIF_RESTCONF, /* RESTCONF JSON notification data - ([ref](https://www.rfc-editor.org/rfc/rfc8040.html#section-6.4)), to parse - a notification in XML, use ::LYD_TYPE_NOTIF_NETCONF */ - LYD_TYPE_REPLY_RESTCONF /* message-body of a RESTCONF operation output parameters - ([ref](https://www.rfc-editor.org/rfc/rfc8040.html#section-3.6.2)) */ + LYD_TYPE_RPC_RESTCONF, /**< message-body of a RESTCONF operation input parameters + ([ref](https://www.rfc-editor.org/rfc/rfc8040.html#section-3.6.1)) */ + LYD_TYPE_NOTIF_RESTCONF, /**< RESTCONF JSON notification data + ([ref](https://www.rfc-editor.org/rfc/rfc8040.html#section-6.4)), to parse + a notification in XML, use ::LYD_TYPE_NOTIF_NETCONF */ + LYD_TYPE_REPLY_RESTCONF /**< message-body of a RESTCONF operation output parameters + ([ref](https://www.rfc-editor.org/rfc/rfc8040.html#section-3.6.2)) */ }; /** @} datatype */ @@ -409,13 +409,21 @@ enum lyd_type { * - @p op - must be NULL, @p parent points to the operation; * Note that error reply should be parsed as 'yang-data' extension data. * + * - ::LYD_TYPE_RPC_YANG: + * - ::LYD_TYPE_NOTIF_YANG: + * - ::LYD_TYPE_REPLY_YANG: + * - all the parameters have their default meaning. + * + * - :: LYD_TYPE_DATA_YANG: + * - not accepted by the function. + * * @param[in] ctx libyang context. * @param[in] parent Optional parent to connect the parsed nodes to. * @param[in] in Input handle to read the input from. * @param[in] format Expected format of the data in @p in. * @param[in] data_type Expected operation to parse (@ref datatype). * @param[out] tree Optional full parsed data tree. If @p parent is set, set to NULL. - * @param[out] op Optional pointer to the operation (action/RPC) node. + * @param[out] op Optional pointer to the operation (action/RPC/notification) node. * @return LY_ERR value. * @return LY_ENOT if @p data_type is a NETCONF message and the root XML element is not the expected one. */ diff --git a/src/parser_internal.h b/src/parser_internal.h index 0c026a0..7315675 100644 --- a/src/parser_internal.h +++ b/src/parser_internal.h @@ -84,6 +84,8 @@ struct lyd_ctx { struct ly_set ext_node; /**< set of nodes with extension instances to validate */ struct ly_set ext_val; /**< set of nested subtrees parsed by extensions to validate */ struct lyd_node *op_node; /**< if an RPC/action/notification is being parsed, store the pointer to it */ + const struct lys_module *val_getnext_ht_mod; /**< module of the cached schema nodes in getnext HT */ + struct ly_ht *val_getnext_ht; /**< cached getnext schema nodes in a HT for validation */ /* callbacks */ lyd_ctx_free_clb free; /**< destructor */ @@ -111,6 +113,8 @@ struct lyd_xml_ctx { struct ly_set ext_node; struct ly_set ext_val; struct lyd_node *op_node; + const struct lys_module *val_getnext_ht_mod; + struct ly_ht *val_getnext_ht; /* callbacks */ lyd_ctx_free_clb free; @@ -134,6 +138,8 @@ struct lyd_json_ctx { struct ly_set ext_node; struct ly_set ext_val; struct lyd_node *op_node; + const struct lys_module *val_getnext_ht_mod; + struct ly_ht *val_getnext_ht; /* callbacks */ lyd_ctx_free_clb free; @@ -164,6 +170,8 @@ struct lyd_lyb_ctx { struct ly_set ext_node; struct ly_set ext_val; struct lyd_node *op_node; + const struct lys_module *val_getnext_ht_mod; + struct ly_ht *val_getnext_ht; /* callbacks */ lyd_ctx_free_clb free; @@ -424,7 +432,7 @@ LY_ERR lyd_parser_create_meta(struct lyd_ctx *lydctx, struct lyd_node *parent, s * @return LY_SUCCESS on success. * @return LY_ENOT on a missing key. */ -LY_ERR lyd_parse_check_keys(struct lyd_node *node); +LY_ERR lyd_parser_check_keys(struct lyd_node *node); /** * @brief Set data flags for a newly parsed node. @@ -435,9 +443,18 @@ LY_ERR lyd_parse_check_keys(struct lyd_node *node); * @param[in] ext Extension instance if @p node was parsed for one. * @return LY_ERR value. */ -LY_ERR lyd_parse_set_data_flags(struct lyd_node *node, struct lyd_meta **meta, struct lyd_ctx *lydctx, +LY_ERR lyd_parser_set_data_flags(struct lyd_node *node, struct lyd_meta **meta, struct lyd_ctx *lydctx, struct lysc_ext_instance *ext); +/** + * @brief Validate a new parsed data node and add its implicit children. + * + * @param[in] lydctx Data parser context. + * @param[in] node Parsed node to validate. + * @return LY_ERR value. + */ +LY_ERR lyd_parser_validate_new_implicit(struct lyd_ctx *lydctx, struct lyd_node *node); + /** * @brief Parse an instance extension statement. * @@ -446,6 +463,6 @@ LY_ERR lyd_parse_set_data_flags(struct lyd_node *node, struct lyd_meta **meta, s * @param[in] stmt Parsed generic statement to process. * @return LY_ERR value. */ -LY_ERR lys_parse_ext_instance_stmt(struct lysp_ctx *pctx, struct lysp_ext_substmt *substmt, struct lysp_stmt *stmt); +LY_ERR lys_parser_ext_instance_stmt(struct lysp_ctx *pctx, struct lysp_ext_substmt *substmt, struct lysp_stmt *stmt); #endif /* LY_PARSER_INTERNAL_H_ */ diff --git a/src/parser_json.c b/src/parser_json.c index 4a94d03..5c31712 100644 --- a/src/parser_json.c +++ b/src/parser_json.c @@ -501,6 +501,7 @@ lydjson_data_check_opaq(struct lyd_json_ctx *lydctx, const struct lysc_node *sno LY_ERR ret = LY_SUCCESS; struct lyjson_ctx *jsonctx = lydctx->jsonctx; enum LYJSON_PARSER_STATUS status; + uint32_t *prev_lo, temp_lo = 0; assert(snode); @@ -523,9 +524,12 @@ lydjson_data_check_opaq(struct lyd_json_ctx *lydctx, const struct lysc_node *sno if ((ret = lydjson_value_type_hint(jsonctx, &status, type_hint_p))) { break; } + + prev_lo = ly_temp_log_options(&temp_lo); if (ly_value_validate(NULL, snode, jsonctx->value, jsonctx->value_len, LY_VALUE_JSON, NULL, *type_hint_p)) { ret = LY_ENOT; } + ly_temp_log_options(prev_lo); break; case LYS_LIST: /* lists may not have all its keys */ @@ -671,7 +675,7 @@ lydjson_metadata_finish(struct lyd_json_ctx *lydctx, struct lyd_node **first_p) } /* add/correct flags */ - ret = lyd_parse_set_data_flags(node, &node->meta, (struct lyd_ctx *)lydctx, ext); + ret = lyd_parser_set_data_flags(node, &node->meta, (struct lyd_ctx *)lydctx, ext); LY_CHECK_GOTO(ret, cleanup); break; } @@ -857,7 +861,7 @@ next_entry: LY_CHECK_GOTO(rc, cleanup); /* add/correct flags */ - rc = lyd_parse_set_data_flags(node, &node->meta, (struct lyd_ctx *)lydctx, NULL); + rc = lyd_parser_set_data_flags(node, &node->meta, (struct lyd_ctx *)lydctx, NULL); LY_CHECK_GOTO(rc, cleanup); } else { /* create attribute */ @@ -1434,19 +1438,14 @@ lydjson_parse_instance_inner(struct lyd_json_ctx *lydctx, const struct lysc_node if (snode->nodetype == LYS_LIST) { /* check all keys exist */ - r = lyd_parse_check_keys(*node); + r = lyd_parser_check_keys(*node); LY_DPARSER_ERR_GOTO(r, rc = r, lydctx, cleanup); } if (!(lydctx->parse_opts & LYD_PARSE_ONLY) && !rc) { - /* new node validation, autodelete CANNOT occur (it can if multi-error), all nodes are new */ - r = lyd_validate_new(lyd_node_child_p(*node), snode, NULL, lydctx->val_opts, NULL); + /* new node validation */ + r = lyd_parser_validate_new_implicit((struct lyd_ctx *)lydctx, *node); LY_DPARSER_ERR_GOTO(r, rc = r, lydctx, cleanup); - - /* add any missing default children */ - r = lyd_new_implicit_r(*node, lyd_node_child_p(*node), NULL, NULL, &lydctx->node_when, &lydctx->node_types, - &lydctx->ext_node, (lydctx->val_opts & LYD_VALIDATE_NO_STATE) ? LYD_IMPLICIT_NO_STATE : 0, NULL); - LY_CHECK_ERR_GOTO(r, rc = r, cleanup); } cleanup: @@ -1530,7 +1529,7 @@ lydjson_parse_instance(struct lyd_json_ctx *lydctx, struct lyd_node *parent, str LY_CHECK_GOTO(!*node, cleanup); /* add/correct flags */ - r = lyd_parse_set_data_flags(*node, &(*node)->meta, (struct lyd_ctx *)lydctx, ext); + r = lyd_parser_set_data_flags(*node, &(*node)->meta, (struct lyd_ctx *)lydctx, ext); LY_CHECK_ERR_GOTO(r, rc = r, cleanup); if (!(lydctx->parse_opts & LYD_PARSE_ONLY)) { diff --git a/src/parser_lyb.c b/src/parser_lyb.c index 3ef1c4b..1622b5d 100644 --- a/src/parser_lyb.c +++ b/src/parser_lyb.c @@ -1079,29 +1079,21 @@ lyb_create_term(struct lyd_lyb_ctx *lybctx, const struct lysc_node *snode, struc * @brief Validate inner node, autodelete default values nad create implicit nodes. * * @param[in,out] lybctx LYB context. - * @param[in] snode Schema of the inner node. * @param[in] node Parsed inner node. * @return LY_ERR value. */ static LY_ERR -lyb_validate_node_inner(struct lyd_lyb_ctx *lybctx, const struct lysc_node *snode, struct lyd_node *node) +lyb_validate_node_inner(struct lyd_lyb_ctx *lybctx, struct lyd_node *node) { - LY_ERR ret = LY_SUCCESS; - uint32_t impl_opts; + LY_ERR rc = LY_SUCCESS; if (!(lybctx->parse_opts & LYD_PARSE_ONLY)) { - /* new node validation, autodelete CANNOT occur, all nodes are new */ - ret = lyd_validate_new(lyd_node_child_p(node), snode, NULL, 0, NULL); - LY_CHECK_RET(ret); - - /* add any missing default children */ - impl_opts = (lybctx->val_opts & LYD_VALIDATE_NO_STATE) ? LYD_IMPLICIT_NO_STATE : 0; - ret = lyd_new_implicit_r(node, lyd_node_child_p(node), NULL, NULL, &lybctx->node_when, &lybctx->node_types, - &lybctx->ext_node, impl_opts, NULL); - LY_CHECK_RET(ret); + /* new node validation */ + rc = lyd_parser_validate_new_implicit((struct lyd_ctx *)lybctx, node); + LY_CHECK_RET(rc); } - return ret; + return rc; } /** @@ -1324,7 +1316,7 @@ lyb_parse_node_inner(struct lyd_lyb_ctx *lybctx, struct lyd_node *parent, const LY_CHECK_GOTO(ret, error); /* additional procedure for inner node */ - ret = lyb_validate_node_inner(lybctx, snode, node); + ret = lyb_validate_node_inner(lybctx, node); LY_CHECK_GOTO(ret, error); if (snode->nodetype & (LYS_RPC | LYS_ACTION | LYS_NOTIF)) { @@ -1463,7 +1455,7 @@ lyb_parse_node_list(struct lyd_lyb_ctx *lybctx, struct lyd_node *parent, const s LY_CHECK_GOTO(ret, error); /* additional procedure for inner node */ - ret = lyb_validate_node_inner(lybctx, snode, node); + ret = lyb_validate_node_inner(lybctx, node); LY_CHECK_GOTO(ret, error); if (snode->nodetype & (LYS_RPC | LYS_ACTION | LYS_NOTIF)) { diff --git a/src/parser_xml.c b/src/parser_xml.c index 34d6fdc..6a17c7d 100644 --- a/src/parser_xml.c +++ b/src/parser_xml.c @@ -394,8 +394,9 @@ lydxml_data_skip(struct lyxml_ctx *xmlctx) static LY_ERR lydxml_data_check_opaq(struct lyd_xml_ctx *lydctx, const struct lysc_node **snode) { - LY_ERR ret = LY_SUCCESS; + LY_ERR ret = LY_SUCCESS, r; struct lyxml_ctx *xmlctx = lydctx->xmlctx, pxmlctx; + uint32_t *prev_lo, temp_lo = 0; if (!(lydctx->parse_opts & LYD_PARSE_OPAQ)) { /* only checks specific to opaque nodes */ @@ -420,7 +421,10 @@ lydxml_data_check_opaq(struct lyd_xml_ctx *lydctx, const struct lysc_node **snod if ((*snode)->nodetype & LYD_NODE_TERM) { /* value may not be valid in which case we parse it as an opaque node */ - if (ly_value_validate(NULL, *snode, xmlctx->value, xmlctx->value_len, LY_VALUE_XML, &xmlctx->ns, LYD_HINT_DATA)) { + prev_lo = ly_temp_log_options(&temp_lo); + r = ly_value_validate(NULL, *snode, xmlctx->value, xmlctx->value_len, LY_VALUE_XML, &xmlctx->ns, LYD_HINT_DATA); + ly_temp_log_options(prev_lo); + if (r) { LOGVRB("Parsing opaque term node \"%s\" with invalid value \"%.*s\".", (*snode)->name, (int)xmlctx->value_len, xmlctx->value); *snode = NULL; @@ -863,19 +867,14 @@ lydxml_subtree_inner(struct lyd_xml_ctx *lydctx, const struct lysc_node *snode, if (snode->nodetype == LYS_LIST) { /* check all keys exist */ - r = lyd_parse_check_keys(*node); + r = lyd_parser_check_keys(*node); LY_CHECK_ERR_GOTO(r, rc = r, cleanup); } if (!(lydctx->parse_opts & LYD_PARSE_ONLY) && !rc) { - /* new node validation, autodelete CANNOT occur (it can if multi-error), all nodes are new */ - r = lyd_validate_new(lyd_node_child_p(*node), snode, NULL, lydctx->val_opts, NULL); + /* new node validation */ + r = lyd_parser_validate_new_implicit((struct lyd_ctx *)lydctx, *node); LY_DPARSER_ERR_GOTO(r, rc = r, lydctx, cleanup); - - /* add any missing default children */ - r = lyd_new_implicit_r(*node, lyd_node_child_p(*node), NULL, NULL, &lydctx->node_when, &lydctx->node_types, - &lydctx->ext_node, (lydctx->val_opts & LYD_VALIDATE_NO_STATE) ? LYD_IMPLICIT_NO_STATE : 0, NULL); - LY_CHECK_ERR_GOTO(r, rc = r, cleanup); } if (snode->nodetype & (LYS_RPC | LYS_ACTION | LYS_NOTIF)) { @@ -1107,7 +1106,7 @@ lydxml_subtree_r(struct lyd_xml_ctx *lydctx, struct lyd_node *parent, struct lyd node_parsed: if (node && snode) { /* add/correct flags */ - r = lyd_parse_set_data_flags(node, &meta, (struct lyd_ctx *)lydctx, ext); + r = lyd_parser_set_data_flags(node, &meta, (struct lyd_ctx *)lydctx, ext); LY_CHECK_ERR_GOTO(r, rc = r; lyd_free_tree(node), cleanup); if (!(lydctx->parse_opts & LYD_PARSE_ONLY)) { diff --git a/src/path.c b/src/path.c index 3876762..f173b17 100644 --- a/src/path.c +++ b/src/path.c @@ -736,8 +736,6 @@ ly_path_compile_predicate(const struct ly_ctx *ctx, const struct lysc_node *cur_ /* names (keys) are unique - it was checked when parsing */ LOGVAL(ctx, LYVE_XPATH, "Predicate missing for a key of %s \"%s\" in path.", lys_nodetype2str(ctx_node->nodetype), ctx_node->name); - ly_path_predicates_free(ctx_node->module->ctx, *predicates); - *predicates = NULL; ret = LY_EVALID; goto cleanup; } @@ -813,6 +811,10 @@ ly_path_compile_predicate(const struct ly_ctx *ctx, const struct lysc_node *cur_ cleanup: LOG_LOCBACK(cur_node ? 1 : 0, 0); + if (ret) { + ly_path_predicates_free(ctx_node->module->ctx, *predicates); + *predicates = NULL; + } return ret; } diff --git a/src/plugins_exts.c b/src/plugins_exts.c index 71449ba..af81792 100644 --- a/src/plugins_exts.c +++ b/src/plugins_exts.c @@ -67,7 +67,7 @@ lyplg_ext_parse_extension_instance(struct lysp_ctx *pctx, struct lysp_ext_instan continue; } - if ((rc = lys_parse_ext_instance_stmt(pctx, &ext->substmts[u], stmt))) { + if ((rc = lys_parser_ext_instance_stmt(pctx, &ext->substmts[u], stmt))) { goto cleanup; } } diff --git a/src/plugins_types.c b/src/plugins_types.c index 3373b0b..d773a8a 100644 --- a/src/plugins_types.c +++ b/src/plugins_types.c @@ -4,7 +4,7 @@ * @author Michal Vasko * @brief Built-in types plugins and interface for user types plugins. * - * Copyright (c) 2019 - 2022 CESNET, z.s.p.o. + * Copyright (c) 2019 - 2024 CESNET, z.s.p.o. * * This source code is licensed under BSD 3-Clause License (the "License"). * You may not use this file except in compliance with the License. @@ -526,37 +526,18 @@ decimal: LIBYANG_API_DEF LY_ERR lyplg_type_validate_patterns(struct lysc_pattern **patterns, const char *str, size_t str_len, struct ly_err_item **err) { - int rc, match_opts; + LY_ERR r; LY_ARRAY_COUNT_TYPE u; - pcre2_match_data *match_data = NULL; LY_CHECK_ARG_RET(NULL, str, err, LY_EINVAL); *err = NULL; LY_ARRAY_FOR(patterns, u) { - /* match_data needs to be allocated each time because of possible multi-threaded evaluation */ - match_data = pcre2_match_data_create_from_pattern(patterns[u]->code, NULL); - if (!match_data) { - return ly_err_new(err, LY_EMEM, 0, NULL, NULL, LY_EMEM_MSG); - } + r = ly_pattern_code_match(patterns[u]->code, str, str_len, err); + LY_CHECK_RET(r && (r != LY_ENOT), r); - match_opts = PCRE2_ANCHORED; -#ifdef PCRE2_ENDANCHORED - /* PCRE2_ENDANCHORED was added in PCRE2 version 10.30 */ - match_opts |= PCRE2_ENDANCHORED; -#endif - rc = pcre2_match(patterns[u]->code, (PCRE2_SPTR)str, str_len, 0, match_opts, match_data, NULL); - pcre2_match_data_free(match_data); - - if ((rc != PCRE2_ERROR_NOMATCH) && (rc < 0)) { - PCRE2_UCHAR pcre2_errmsg[LY_PCRE2_MSG_LIMIT] = {0}; - - pcre2_get_error_message(rc, pcre2_errmsg, LY_PCRE2_MSG_LIMIT); - - return ly_err_new(err, LY_ESYS, 0, NULL, NULL, "%s", (const char *)pcre2_errmsg); - } else if (((rc == PCRE2_ERROR_NOMATCH) && !patterns[u]->inverted) || - ((rc != PCRE2_ERROR_NOMATCH) && patterns[u]->inverted)) { + if (((r == LY_ENOT) && !patterns[u]->inverted) || ((r == LY_SUCCESS) && patterns[u]->inverted)) { char *eapptag = patterns[u]->eapptag ? strdup(patterns[u]->eapptag) : NULL; if (patterns[u]->emsg) { @@ -569,6 +550,7 @@ lyplg_type_validate_patterns(struct lysc_pattern **patterns, const char *str, si } } } + return LY_SUCCESS; } diff --git a/src/plugins_types/node_instanceid.c b/src/plugins_types/node_instanceid.c index 7c80e30..ab141d5 100644 --- a/src/plugins_types/node_instanceid.c +++ b/src/plugins_types/node_instanceid.c @@ -190,6 +190,7 @@ lyplg_type_store_node_instanceid(const struct ly_ctx *ctx, const struct lysc_typ if ((((char *)value)[0] == '/') && (value_len == 1)) { /* special path */ + format = LY_VALUE_CANON; goto store; } @@ -296,6 +297,34 @@ lyplg_type_print_node_instanceid(const struct ly_ctx *UNUSED(ctx), const struct return ret; } +/** + * @brief Implementation of ::lyplg_type_dup_clb for the node-instance-identifier ietf-netconf-acm type. + */ +static LY_ERR +lyplg_type_dup_node_instanceid(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup) +{ + LY_ERR ret; + + memset(dup, 0, sizeof *dup); + + /* canonical value */ + ret = lydict_insert(ctx, original->_canonical, 0, &dup->_canonical); + LY_CHECK_GOTO(ret, error); + + if (original->target) { + /* copy path */ + ret = ly_path_dup(ctx, original->target, &dup->target); + LY_CHECK_GOTO(ret, error); + } /* else is the special path "/" that has no target stored */ + + dup->realtype = original->realtype; + return LY_SUCCESS; + +error: + lyplg_type_free_instanceid(ctx, dup); + return ret; +} + /** * @brief Plugin information for instance-identifier type implementation. * @@ -315,7 +344,7 @@ const struct lyplg_type_record plugins_node_instanceid[] = { .plugin.compare = lyplg_type_compare_simple, .plugin.sort = lyplg_type_sort_simple, .plugin.print = lyplg_type_print_node_instanceid, - .plugin.duplicate = lyplg_type_dup_instanceid, + .plugin.duplicate = lyplg_type_dup_node_instanceid, .plugin.free = lyplg_type_free_instanceid, .plugin.lyb_data_len = -1, }, @@ -330,7 +359,7 @@ const struct lyplg_type_record plugins_node_instanceid[] = { .plugin.compare = lyplg_type_compare_simple, .plugin.sort = lyplg_type_sort_simple, .plugin.print = lyplg_type_print_node_instanceid, - .plugin.duplicate = lyplg_type_dup_instanceid, + .plugin.duplicate = lyplg_type_dup_node_instanceid, .plugin.free = lyplg_type_free_instanceid, .plugin.lyb_data_len = -1, }, diff --git a/src/plugins_types/union.c b/src/plugins_types/union.c index 51cca6c..64281c6 100644 --- a/src/plugins_types/union.c +++ b/src/plugins_types/union.c @@ -401,6 +401,9 @@ lyplg_type_store_union(const struct ly_ctx *ctx, const struct lysc_type *type, c ret = lyb_fill_subvalue(ctx, type_u, value, value_len, prefix_data, subvalue, &options, unres, err); LY_CHECK_GOTO((ret != LY_SUCCESS) && (ret != LY_EINCOMPLETE), cleanup); } else { + /* to correctly resolve the union type, we need to always validate the value */ + options &= ~LYPLG_TYPE_STORE_ONLY; + /* store value to subvalue */ ret = union_subvalue_assignment(value, value_len, &subvalue->original, &subvalue->orig_len, &options); LY_CHECK_GOTO(ret, cleanup); diff --git a/src/printer_lyb.c b/src/printer_lyb.c index de6ae97..ae5714d 100644 --- a/src/printer_lyb.c +++ b/src/printer_lyb.c @@ -70,6 +70,18 @@ lyb_ptr_equal_cb(void *val1_p, void *val2_p, ly_bool UNUSED(mod), void *UNUSED(c return 0; } +/** + * @brief Hash table equal callback for checking collisions. + * + * Implementation of ::lyht_value_equal_cb. + */ +static ly_bool +lyb_col_equal_cb(void *val1_p, void *val2_p, ly_bool mod, void *cb_data) +{ + /* for first value check use lyb_ptr_equal_cb, for collisions lyb_hash_equal_cb */ + return mod ? lyb_ptr_equal_cb(val1_p, val2_p, mod, cb_data) : lyb_hash_equal_cb(val1_p, val2_p, mod, cb_data); +} + /** * @brief Check that sibling collision hash is safe to insert into hash table. * @@ -91,7 +103,6 @@ lyb_hash_sequence_check(struct ly_ht *ht, struct lysc_node *sibling, LYB_HASH ht return LY_SUCCESS; } - lyht_set_cb(ht, lyb_ptr_equal_cb); do { int64_t j; @@ -103,15 +114,13 @@ lyb_hash_sequence_check(struct ly_ht *ht, struct lysc_node *sibling, LYB_HASH ht } if (j == -1) { /* all whole hash sequences of nodes inserted with last hash col ID compare_col_id collide */ - lyht_set_cb(ht, lyb_hash_equal_cb); return LY_EEXIST; } /* get next node inserted with last hash col ID ht_col_id */ - } while (!lyht_find_next_with_collision_cb(ht, col_node, lyb_get_hash(*col_node, ht_col_id), lyb_hash_equal_cb, + } while (!lyht_find_next_with_collision_cb(ht, col_node, lyb_get_hash(*col_node, ht_col_id), lyb_col_equal_cb, (void **)&col_node)); - lyht_set_cb(ht, lyb_hash_equal_cb); return LY_SUCCESS; } diff --git a/src/schema_compile.c b/src/schema_compile.c index d21f0dc..5adfc01 100644 --- a/src/schema_compile.c +++ b/src/schema_compile.c @@ -1056,11 +1056,9 @@ lys_compile_unres_llist_dflts(struct lysc_ctx *ctx, struct lysc_node_leaflist *l for (u = orig_count; u < LY_ARRAY_COUNT(llist->dflts); ++u) { for (v = 0; v < u; ++v) { if (!llist->dflts[u]->realtype->plugin->compare(ctx->ctx, llist->dflts[u], llist->dflts[v])) { - lysc_update_path(ctx, llist->parent ? llist->parent->module : NULL, llist->name); LOGVAL(ctx->ctx, LYVE_SEMANTICS, "Configuration leaf-list has multiple defaults of the same value \"%s\".", (char *)llist->dflts[u]->realtype->plugin->print(ctx->ctx, llist->dflts[u], LY_VALUE_CANON, NULL, NULL, NULL)); - lysc_update_path(ctx, NULL, NULL); return LY_EVALID; } } diff --git a/src/schema_compile_node.c b/src/schema_compile_node.c index d57d8a7..8807b0f 100644 --- a/src/schema_compile_node.c +++ b/src/schema_compile_node.c @@ -1244,7 +1244,7 @@ lys_compile_pattern_chblocks_xmlschema2perl(const struct ly_ctx *ctx, const char } LY_ERR -lys_compile_type_pattern_check(struct ly_ctx *ctx, const char *pattern, pcre2_code **code) +lys_compile_type_pattern_check(const struct ly_ctx *ctx, const char *pattern, pcre2_code **code) { size_t idx, size, brack; char *perl_regex; @@ -1357,7 +1357,7 @@ lys_compile_type_pattern_check(struct ly_ctx *ctx, const char *pattern, pcre2_co if (code) { *code = code_local; } else { - free(code_local); + pcre2_code_free(code_local); } return LY_SUCCESS; @@ -3397,7 +3397,7 @@ lys_compile_node_list(struct lysc_ctx *ctx, struct lysp_node *pnode, struct lysc if (list->min) { list->flags |= LYS_MAND_TRUE; } - list->max = list_p->max ? list_p->max : (uint32_t)-1; + list->max = list_p->max ? list_p->max : UINT32_MAX; LY_LIST_FOR(list_p->child, child_p) { LY_CHECK_RET(lys_compile_node(ctx, child_p, node, 0, NULL)); diff --git a/src/schema_compile_node.h b/src/schema_compile_node.h index e463de6..c3b6aab 100644 --- a/src/schema_compile_node.h +++ b/src/schema_compile_node.h @@ -78,7 +78,7 @@ LY_ERR lys_compile_type_range(struct lysc_ctx *ctx, const struct lysp_restr *ran * @param[in,out] code Compiled PCRE2 pattern. If NULL, the compiled information used to validate pattern are freed. * @return LY_ERR value - LY_SUCCESS, LY_EMEM, LY_EVALID. */ -LY_ERR lys_compile_type_pattern_check(struct ly_ctx *ctx, const char *pattern, pcre2_code **code); +LY_ERR lys_compile_type_pattern_check(const struct ly_ctx *ctx, const char *pattern, pcre2_code **code); /** * @brief Compile parsed pattern restriction in conjunction with the patterns from base type. diff --git a/src/tree_data.c b/src/tree_data.c index a8c42bf..71c0b78 100644 --- a/src/tree_data.c +++ b/src/tree_data.c @@ -165,10 +165,17 @@ lyd_parse(const struct ly_ctx *ctx, const struct lysc_ext_instance *ext, struct } if (!(parse_opts & LYD_PARSE_ONLY)) { - /* validate data */ - r = lyd_validate(first_p, NULL, ctx, val_opts, 0, &lydctx->node_when, &lydctx->node_types, &lydctx->meta_types, - &lydctx->ext_node, &lydctx->ext_val, NULL); - LY_CHECK_ERR_GOTO(r, rc = r, cleanup); + if (ext) { + /* special ext instance data validation */ + r = lyd_validate_ext(first_p, ext, val_opts, 0, &lydctx->node_when, &lydctx->node_types, &lydctx->meta_types, + &lydctx->ext_node, &lydctx->ext_val, NULL); + LY_CHECK_ERR_GOTO(r, rc = r, cleanup); + } else { + /* validate data */ + r = lyd_validate(first_p, NULL, ctx, val_opts, 0, &lydctx->node_when, &lydctx->node_types, &lydctx->meta_types, + &lydctx->ext_node, &lydctx->ext_val, NULL); + LY_CHECK_ERR_GOTO(r, rc = r, cleanup); + } } /* set the operation node */ @@ -545,10 +552,9 @@ lyd_insert_get_next_anchor(const struct lyd_node *first_sibling, const struct ly void lyd_insert_after_node(struct lyd_node **first_sibling_p, struct lyd_node *sibling, struct lyd_node *node) { - struct lyd_node_inner *par; struct lyd_node *first_sibling; - assert(!node->next && (node->prev == node)); + assert(!node->next && (node->prev == node) && (sibling != node)); if (sibling->next) { /* sibling had a succeeding node */ @@ -571,20 +577,16 @@ lyd_insert_after_node(struct lyd_node **first_sibling_p, struct lyd_node *siblin sibling->next = node; node->parent = sibling->parent; - for (par = node->parent; par; par = par->parent) { - if ((par->flags & LYD_DEFAULT) && !(node->flags & LYD_DEFAULT)) { - /* remove default flags from NP containers */ - par->flags &= ~LYD_DEFAULT; - } + if (!(node->flags & LYD_DEFAULT)) { + /* remove default flags from NP containers */ + lyd_np_cont_dflt_del(lyd_parent(node)); } } void lyd_insert_before_node(struct lyd_node *sibling, struct lyd_node *node) { - struct lyd_node_inner *par; - - assert(!node->next && (node->prev == node)); + assert(!node->next && (node->prev == node) && (sibling != node)); node->next = sibling; /* covers situation of sibling being first */ @@ -599,11 +601,9 @@ lyd_insert_before_node(struct lyd_node *sibling, struct lyd_node *node) } node->parent = sibling->parent; - for (par = node->parent; par; par = par->parent) { - if ((par->flags & LYD_DEFAULT) && !(node->flags & LYD_DEFAULT)) { - /* remove default flags from NP containers */ - par->flags &= ~LYD_DEFAULT; - } + if (!(node->flags & LYD_DEFAULT)) { + /* remove default flags from NP containers */ + lyd_np_cont_dflt_del(lyd_parent(node)); } } @@ -628,11 +628,9 @@ lyd_insert_only_child(struct lyd_node *parent, struct lyd_node *node) par->child = node; node->parent = par; - for ( ; par; par = par->parent) { - if ((par->flags & LYD_DEFAULT) && !(node->flags & LYD_DEFAULT)) { - /* remove default flags from NP containers */ - par->flags &= ~LYD_DEFAULT; - } + if (!(node->flags & LYD_DEFAULT)) { + /* remove default flags from NP containers */ + lyd_np_cont_dflt_del(parent); } } @@ -1192,7 +1190,7 @@ lyd_unlink_ignore_lyds(struct lyd_node **first_sibling_p, struct lyd_node *node) } /* check for NP container whether its last non-default node is not being unlinked */ - lyd_cont_set_dflt(lyd_parent(node)); + lyd_np_cont_dflt_set(lyd_parent(node)); node->parent = NULL; } @@ -1285,9 +1283,8 @@ lyd_insert_meta(struct lyd_node *parent, struct lyd_meta *meta, ly_bool clear_df } /* remove default flags from NP containers */ - while (clear_dflt && parent && (parent->schema->nodetype == LYS_CONTAINER) && (parent->flags & LYD_DEFAULT)) { - parent->flags &= ~LYD_DEFAULT; - parent = lyd_parent(parent); + if (clear_dflt) { + lyd_np_cont_dflt_del(parent); } } @@ -2496,7 +2493,6 @@ lyd_merge_sibling_r(struct lyd_node **first_trg, struct lyd_node *parent_trg, const struct lyd_node *child_src, *tmp, *sibling_src; struct lyd_node *match_trg, *dup_src, *elem, *leader; struct lyd_node_opaq *opaq_trg, *opaq_src; - struct lysc_type *type; const struct lysc_node *schema; struct ly_ht *child_dup_inst = NULL; LY_ERR r; @@ -2546,19 +2542,15 @@ lyd_merge_sibling_r(struct lyd_node **first_trg, struct lyd_node *parent_trg, &opaq_trg->val_prefix_data); } } else if ((match_trg->schema->nodetype == LYS_LEAF) && - lyd_compare_single(sibling_src, match_trg, LYD_COMPARE_DEFAULTS)) { - /* since they are different, they cannot both be default */ - assert(!(sibling_src->flags & LYD_DEFAULT) || !(match_trg->flags & LYD_DEFAULT)); + ((options & LYD_MERGE_DEFAULTS) || !(sibling_src->flags & LYD_DEFAULT))) { + /* update value */ + r = lyd_change_term_val(match_trg, &((struct lyd_node_term *)sibling_src)->value, 0, + sibling_src->flags & LYD_DEFAULT); + LY_CHECK_RET(r && (r != LY_EEXIST) && (r != LY_ENOT), r); - /* update value (or only LYD_DEFAULT flag) only if flag set or the source node is not default */ - if ((options & LYD_MERGE_DEFAULTS) || !(sibling_src->flags & LYD_DEFAULT)) { - type = ((struct lysc_node_leaf *)match_trg->schema)->type; - type->plugin->free(LYD_CTX(match_trg), &((struct lyd_node_term *)match_trg)->value); - LY_CHECK_RET(type->plugin->duplicate(LYD_CTX(match_trg), &((struct lyd_node_term *)sibling_src)->value, - &((struct lyd_node_term *)match_trg)->value)); - - /* copy flags and add LYD_NEW */ - match_trg->flags = sibling_src->flags | ((options & LYD_MERGE_WITH_FLAGS) ? 0 : LYD_NEW); + if (options & LYD_MERGE_WITH_FLAGS) { + /* keep the exact same flags */ + match_trg->flags = sibling_src->flags; } } else if ((match_trg->schema->nodetype & LYS_ANYDATA) && lyd_compare_single(sibling_src, match_trg, 0)) { /* update value */ diff --git a/src/tree_data.h b/src/tree_data.h index b8a7653..18bc679 100644 --- a/src/tree_data.h +++ b/src/tree_data.h @@ -26,6 +26,10 @@ # include # endif #endif + +#define PCRE2_CODE_UNIT_WIDTH 8 + +#include #include #include #include @@ -2715,6 +2719,33 @@ LIBYANG_API_DECL LY_ERR lyd_leafref_get_links(const struct lyd_node_term *node, */ LIBYANG_API_DECL LY_ERR lyd_leafref_link_node_tree(const struct lyd_node *tree); +/** + * @brief Check a string matches an XML Schema regex used in YANG. + * + * @param[in] ctx Optional context for storing errors. + * @param[in] pattern Regular expression pattern to use. + * @param[in] string String to match. + * @param[in] str_len Length of @p string, may be 0 if string is 0-terminated. + * @param[in,out] pcode Optional pointer to PCRE2 code. If set and NULL, it is returned. If set and non-NULL, it is + * used directly for matching instead of compiling @p pattern. Free it using pcre2_code_free(). + * @return LY_SUCCESS on a match; + * @return LY_ENOT if the string does not match; + * @return LY_ERR on error. + */ +LIBYANG_API_DECL LY_ERR ly_pattern_match(const struct ly_ctx *ctx, const char *pattern, const char *string, + uint32_t str_len, pcre2_code **pcode); + +/** + * @brief Compile an XML Schema regex pattern prior to matching. + * + * @param[in] ctx Optional context for storing errors. + * @param[in] pattern Regular expression pattern to use. + * @param[out] pcode Compiled @p pattern to be used by ::ly_pattern_match(). Free it using pcre2_code_free(). + * @return LY_SUCCESS on success; + * @return LY_ERR on error. + */ +LIBYANG_API_DECL LY_ERR ly_pattern_compile(const struct ly_ctx *ctx, const char *pattern, pcre2_code **pcode); + #ifdef __cplusplus } #endif diff --git a/src/tree_data_common.c b/src/tree_data_common.c index f480a5a..ce9479d 100644 --- a/src/tree_data_common.c +++ b/src/tree_data_common.c @@ -4,7 +4,7 @@ * @author Michal Vasko * @brief Parsing and validation common functions for data trees * - * Copyright (c) 2015 - 2022 CESNET, z.s.p.o. + * Copyright (c) 2015 - 2024 CESNET, z.s.p.o. * * This source code is licensed under BSD 3-Clause License (the "License"). * You may not use this file except in compliance with the License. @@ -33,6 +33,7 @@ #include "parser_data.h" #include "plugins_exts.h" #include "printer_data.h" +#include "schema_compile_node.h" #include "set.h" #include "tree.h" #include "tree_data.h" @@ -1157,35 +1158,6 @@ lyd_meta_is_internal(const struct lyd_meta *meta) return 0; } -void -lyd_cont_set_dflt(struct lyd_node *node) -{ - const struct lyd_node *child; - - while (node) { - if (!node->schema || (node->flags & LYD_DEFAULT) || !lysc_is_np_cont(node->schema)) { - /* not a non-dflt NP container */ - break; - } - - LY_LIST_FOR(lyd_child(node), child) { - if (!(child->flags & LYD_DEFAULT)) { - break; - } - } - if (child) { - /* explicit child, no dflt change */ - break; - } - - /* set the dflt flag */ - node->flags |= LYD_DEFAULT; - - /* check all parent containers */ - node = lyd_parent(node); - } -} - /** * @brief Comparison callback to match schema node with a schema of a data node. * @@ -1301,6 +1273,44 @@ lyd_del_move_root(struct lyd_node **root, const struct lyd_node *to_del, const s } } +void +lyd_np_cont_dflt_set(struct lyd_node *parent) +{ + const struct lyd_node *child; + + while (parent) { + if (!parent->schema || (parent->flags & LYD_DEFAULT) || !lysc_is_np_cont(parent->schema)) { + /* not a non-dflt NP container */ + break; + } + + LY_LIST_FOR(lyd_child(parent), child) { + if (!(child->flags & LYD_DEFAULT)) { + break; + } + } + if (child) { + /* explicit child, no dflt change */ + break; + } + + /* set the dflt flag */ + parent->flags |= LYD_DEFAULT; + + /* check all parent containers */ + parent = lyd_parent(parent); + } +} + +void +lyd_np_cont_dflt_del(struct lyd_node *parent) +{ + while (parent && (parent->flags & LYD_DEFAULT)) { + parent->flags &= ~LYD_DEFAULT; + parent = lyd_parent(parent); + } +} + LY_ERR ly_nested_ext_schema(const struct lyd_node *parent, const struct lysc_node *sparent, const char *prefix, size_t prefix_len, LY_VALUE_FORMAT format, void *prefix_data, const char *name, size_t name_len, @@ -1834,3 +1844,80 @@ ly_time_ts2str(const struct timespec *ts, char **str) return ly_time_time2str(ts->tv_sec, ts->tv_nsec ? frac_buf : NULL, str); } + +LY_ERR +ly_pattern_code_match(pcre2_code *pcode, const char *str, size_t str_len, struct ly_err_item **err) +{ + int r, match_opts; + pcre2_match_data *match_data = NULL; + + /* match_data needs to be allocated each time because of possible multi-threaded evaluation */ + match_data = pcre2_match_data_create_from_pattern(pcode, NULL); + if (!match_data) { + return ly_err_new(err, LY_EMEM, 0, NULL, NULL, LY_EMEM_MSG); + } + + match_opts = PCRE2_ANCHORED; +#ifdef PCRE2_ENDANCHORED + /* PCRE2_ENDANCHORED was added in PCRE2 version 10.30 */ + match_opts |= PCRE2_ENDANCHORED; +#endif + r = pcre2_match(pcode, (PCRE2_SPTR)str, str_len, 0, match_opts, match_data, NULL); + pcre2_match_data_free(match_data); + + if ((r != PCRE2_ERROR_NOMATCH) && (r < 0)) { + PCRE2_UCHAR pcre2_errmsg[LY_PCRE2_MSG_LIMIT] = {0}; + + pcre2_get_error_message(r, pcre2_errmsg, LY_PCRE2_MSG_LIMIT); + return ly_err_new(err, LY_ESYS, 0, NULL, NULL, "%s", (const char *)pcre2_errmsg); + } + + return (r == PCRE2_ERROR_NOMATCH) ? LY_ENOT : LY_SUCCESS; +} + +LIBYANG_API_DEF LY_ERR +ly_pattern_match(const struct ly_ctx *ctx, const char *pattern, const char *string, uint32_t str_len, pcre2_code **pcode) +{ + LY_ERR r; + pcre2_code *code; + struct ly_err_item *err = NULL; + + LY_CHECK_ARG_RET(ctx, pattern || (pcode && *pcode), string, LY_EINVAL); + + if (pcode && *pcode) { + /* use precompiled pattern */ + code = *pcode; + } else { + /* compile the pattern */ + LY_CHECK_RET(lys_compile_type_pattern_check(ctx, pattern, &code)); + } + + /* match */ + if (!str_len) { + str_len = strlen(string); + } + r = ly_pattern_code_match(code, string, str_len, &err); + if (r && (r != LY_ENOT)) { + ly_err_print(ctx, err); + ly_err_free(err); + return r; + } + + if (pcode && !*pcode) { + *pcode = code; + } else if (!pcode || !*pcode) { + pcre2_code_free(code); + } + return r; +} + +LIBYANG_API_DEF LY_ERR +ly_pattern_compile(const struct ly_ctx *ctx, const char *pattern, pcre2_code **pcode) +{ + LY_CHECK_ARG_RET(ctx, pattern, pcode, LY_EINVAL); + + *pcode = NULL; + + /* compile the pattern */ + return lys_compile_type_pattern_check(ctx, pattern, pcode); +} diff --git a/src/tree_data_internal.h b/src/tree_data_internal.h index b3a027c..03f82bc 100644 --- a/src/tree_data_internal.h +++ b/src/tree_data_internal.h @@ -4,7 +4,7 @@ * @author Michal Vasko * @brief internal functions for YANG schema trees. * - * Copyright (c) 2015 - 2023 CESNET, z.s.p.o. + * Copyright (c) 2015 - 2024 CESNET, z.s.p.o. * * This source code is licensed under BSD 3-Clause License (the "License"). * You may not use this file except in compliance with the License. @@ -117,13 +117,6 @@ const struct lys_module *lyd_mod_next_module(struct lyd_node *tree, const struct */ const struct lys_module *lyd_data_next_module(struct lyd_node **next, struct lyd_node **first); -/** - * @brief Set dflt flag for a NP container if applicable, recursively for parents. - * - * @param[in] node Node whose criteria for the dflt flag has changed. - */ -void lyd_cont_set_dflt(struct lyd_node *node); - /** * @brief Search in the given siblings (NOT recursively) for the first schema node data instance. * Uses hashes - should be used whenever possible for best performance. @@ -147,6 +140,20 @@ LY_ERR lyd_find_sibling_schema(const struct lyd_node *siblings, const struct lys */ void lyd_del_move_root(struct lyd_node **root, const struct lyd_node *to_del, const struct lys_module *mod); +/** + * @brief After adding a default child, check the node and all of its parent NP containers and set their dflt flag. + * + * @param[in] parent Changed first parent to check. + */ +void lyd_np_cont_dflt_set(struct lyd_node *parent); + +/** + * @brief After adding a non-default child, remove the dflt flag from parent and other parent NP containers. + * + * @param[in] parent Changed first parent to update. + */ +void lyd_np_cont_dflt_del(struct lyd_node *parent); + /** * @brief Try to get schema node for data with a parent based on an extension instance. * @@ -345,7 +352,24 @@ LY_ERR lyd_create_opaq(const struct ly_ctx *ctx, const char *name, size_t name_l LY_VALUE_FORMAT format, void *val_prefix_data, uint32_t hints, struct lyd_node **node); /** - * @brief Check the existence and create any non-existing implicit siblings, recursively for the created nodes. + * @brief Change the value of a term (leaf or leaf-list) node. + * + * Node changed this way is always considered explicitly set, meaning its default flag + * is always cleared. + * + * @param[in] term Term node to change. + * @param[in] val New value to use. + * @param[in] use_val Whether @p val can be used and spent or should only be duplicated. + * @param[in] is_dflt Whether @p val is a default value or not. + * @return LY_SUCCESS if value was changed, + * @return LY_EEXIST if value was the same and only the default flag was cleared, + * @return LY_ENOT if the values were equal and no change occured, + * @return LY_ERR value on other errors. + */ +LY_ERR lyd_change_term_val(struct lyd_node *term, struct lyd_value *val, ly_bool use_val, ly_bool is_dflt); + +/** + * @brief Check the existence and create any non-existing implicit children. * * @param[in] parent Parent of the potential default values, NULL for top-level siblings. * @param[in,out] first First sibling. @@ -355,12 +379,32 @@ LY_ERR lyd_create_opaq(const struct ly_ctx *ctx, const char *name, size_t name_l * @param[in] node_types Optional set to add nodes with unresolved types into. * @param[in] ext_node Optional set to add nodes with extension instance node callbacks into. * @param[in] impl_opts Implicit options (@ref implicitoptions). + * @param[in,out] getnext_ht Getnext HT to use, new @p sparent is added to it. + * @param[in,out] diff Validation diff. + * @return LY_ERR value. + */ +LY_ERR lyd_new_implicit(struct lyd_node *parent, struct lyd_node **first, const struct lysc_node *sparent, + const struct lys_module *mod, struct ly_set *node_when, struct ly_set *node_types, struct ly_set *ext_node, + uint32_t impl_opts, struct ly_ht *getnext_ht, struct lyd_node **diff); + +/** + * @brief Check the existence and create any non-existing implicit children, recursively for containers. + * + * @param[in] parent Parent of the potential default values, NULL for top-level siblings. + * @param[in,out] first First sibling. + * @param[in] sparent Schema parent of the siblings, NULL if schema of @p parent can be used. + * @param[in] mod Module of the default values, NULL for nested siblings. + * @param[in] node_when Optional set to add nodes with "when" conditions into. + * @param[in] node_types Optional set to add nodes with unresolved types into. + * @param[in] ext_node Optional set to add nodes with extension instance node callbacks into. + * @param[in] impl_opts Implicit options (@ref implicitoptions). + * @param[in,out] getnext_ht Getnext HT to use, new @p sparent is added to it. * @param[in,out] diff Validation diff. * @return LY_ERR value. */ LY_ERR lyd_new_implicit_r(struct lyd_node *parent, struct lyd_node **first, const struct lysc_node *sparent, const struct lys_module *mod, struct ly_set *node_when, struct ly_set *node_types, struct ly_set *ext_node, - uint32_t impl_opts, struct lyd_node **diff); + uint32_t impl_opts, struct ly_ht *getnext_ht, struct lyd_node **diff); /** * @brief Find the next node, before which to insert the new node. @@ -719,4 +763,17 @@ LY_ERR lyd_unlink_leafref_node(const struct lyd_node_term *node, const struct ly */ void lyd_unlink_ignore_lyds(struct lyd_node **first_sibling, struct lyd_node *node); +/** + * @brief Check a string matches a compiled pattern. + * + * @param[in] pcode Compiled pattern. + * @param[in] str String to match. + * @param[in] str_len Length of @p str. + * @param[out] err Error, if generated. + * @return LY_SUCCESS on a match; + * @return LY_ENOT if the string does not match; + * @return LY_ERR on error. + */ +LY_ERR ly_pattern_code_match(pcre2_code *pcode, const char *str, size_t str_len, struct ly_err_item **err); + #endif /* LY_TREE_DATA_INTERNAL_H_ */ diff --git a/src/tree_data_new.c b/src/tree_data_new.c index 7b26508..76f9a62 100644 --- a/src/tree_data_new.c +++ b/src/tree_data_new.c @@ -1243,14 +1243,15 @@ lyd_new_attr2(struct lyd_node *parent, const char *module_ns, const char *name, * * Reinserting ensures that the node is in the correct position and the data instances remain properly ordered. * - * @param[in] term Term node to change. If it is a key, the parental list is inserted again. + * @param[in] term Term node to change. If it is a key, the parent list is reinserted. * @param[in] val New value for @p term. - * @return LY_SUCCESS on success. + * @param[in] use_val Whether @p val can be used and spent or should only be duplicated. + * @return LY_ERR value. */ static LY_ERR -lyd_change_node_value(struct lyd_node_term *term, struct lyd_value *val) +lyd_change_node_value(struct lyd_node_term *term, struct lyd_value *val, ly_bool use_val) { - LY_ERR ret = LY_SUCCESS; + LY_ERR rc = LY_SUCCESS; struct lyd_node *target, *first; if (term->schema->nodetype == LYS_LEAFLIST) { @@ -1260,33 +1261,115 @@ lyd_change_node_value(struct lyd_node_term *term, struct lyd_value *val) } else { /* just change the value */ term->value.realtype->plugin->free(LYD_CTX(term), &term->value); - term->value = *val; + if (use_val) { + term->value = *val; + } else { + rc = ((struct lysc_node_leaf *)term->schema)->type->plugin->duplicate(LYD_CTX(term), val, &term->value); + } + /* leaf that is not a key, its value is not used for its hash so it does not change */ - return LY_SUCCESS; + return rc; } if (!LYD_NODE_IS_ALONE(target) && lyds_is_supported(target)) { /* changing the value may cause a change in the order */ first = lyd_first_sibling(target); first = first == target ? first->next : first; + /* unlink hash and unlink the target node in the lyds tree */ lyd_unlink_tree(target); + /* change value */ term->value.realtype->plugin->free(LYD_CTX(term), &term->value); - term->value = *val; + if (use_val) { + term->value = *val; + } else { + rc = ((struct lysc_node_leaf *)term->schema)->type->plugin->duplicate(LYD_CTX(term), val, &term->value); + } + /* reinserting */ lyd_insert_node(NULL, &first, target, LYD_INSERT_NODE_DEFAULT); } else { /* unlink hash */ lyd_unlink_hash(target); + /* change value */ term->value.realtype->plugin->free(LYD_CTX(term), &term->value); - term->value = *val; + if (use_val) { + term->value = *val; + } else { + rc = ((struct lysc_node_leaf *)term->schema)->type->plugin->duplicate(LYD_CTX(term), val, &term->value); + } } - lyd_hash(target); - ret = lyd_insert_hash(target); - return ret; + lyd_hash(target); + rc = lyd_insert_hash(target); + + return rc; +} + +LY_ERR +lyd_change_term_val(struct lyd_node *term, struct lyd_value *val, ly_bool use_val, ly_bool is_dflt) +{ + LY_ERR rc = LY_SUCCESS; + struct lysc_type *type; + struct lyd_node_term *t; + ly_bool dflt_change, val_change; + + t = (struct lyd_node_term *)term; + type = ((struct lysc_node_leaf *)term->schema)->type; + + /* compare original and new value */ + if (type->plugin->compare(LYD_CTX(term), &t->value, val)) { + /* since they are different, they cannot both be default */ + assert(!(term->flags & LYD_DEFAULT) || !is_dflt); + + /* values differ, switch them */ + LY_CHECK_RET(lyd_change_node_value(t, val, use_val)); + val_change = 1; + } else { + /* same values, free the new stored one */ + if (use_val) { + type->plugin->free(LYD_CTX(term), val); + } + val_change = 0; + } + + /* clear links to leafref nodes */ + if (val_change && (ly_ctx_get_options(LYD_CTX(term)) & LY_CTX_LEAFREF_LINKING)) { + lyd_free_leafref_nodes(t); + } + + /* update flags */ + if (val_change) { + term->flags |= LYD_NEW; + } + if ((term->flags & LYD_DEFAULT) && !is_dflt) { + /* remove dflt flag */ + term->flags &= ~LYD_DEFAULT; + + /* remove parent dflt flag */ + lyd_np_cont_dflt_del(lyd_parent(term)); + + dflt_change = 1; + } else if (!(term->flags & LYD_DEFAULT) && is_dflt) { + /* add dflt flag */ + term->flags |= LYD_DEFAULT; + + /* add parent dflt flag */ + lyd_np_cont_dflt_set(lyd_parent(term)); + + dflt_change = 1; + } else { + dflt_change = 0; + } + + if (!val_change) { + /* only default flag change or no change */ + rc = dflt_change ? LY_EEXIST : LY_ENOT; + } /* else value changed, LY_SUCCESS */ + + return rc; } /** @@ -1307,68 +1390,20 @@ lyd_change_node_value(struct lyd_node_term *term, struct lyd_value *val) static LY_ERR _lyd_change_term(struct lyd_node *term, const void *value, size_t value_len, LY_VALUE_FORMAT format) { - LY_ERR ret = LY_SUCCESS; - struct lysc_type *type; - struct lyd_node_term *t; - struct lyd_node *parent; + LY_ERR r; struct lyd_value val; - ly_bool dflt_change, val_change; assert(term && term->schema && (term->schema->nodetype & LYD_NODE_TERM)); - t = (struct lyd_node_term *)term; - type = ((struct lysc_node_leaf *)term->schema)->type; - /* parse the new value */ LOG_LOCSET(term->schema, term); - ret = lyd_value_store(LYD_CTX(term), &val, type, value, value_len, 0, 0, NULL, format, NULL, LYD_HINT_DATA, - term->schema, NULL); + r = lyd_value_store(LYD_CTX(term), &val, ((struct lysc_node_leaf *)term->schema)->type, value, value_len, 0, 0, + NULL, format, NULL, LYD_HINT_DATA, term->schema, NULL); LOG_LOCBACK(1, 1); - LY_CHECK_GOTO(ret, cleanup); + LY_CHECK_RET(r); - /* compare original and new value */ - if (type->plugin->compare(LYD_CTX(term), &t->value, &val)) { - /* values differ, switch them */ - lyd_change_node_value(t, &val); - /* make the node non-validated */ - term->flags &= LYD_NEW; - val_change = 1; - } else { - /* same values, free the new stored one */ - type->plugin->free(LYD_CTX(term), &val); - val_change = 0; - } - - /* clear links to leafref nodes */ - if (ly_ctx_get_options(LYD_CTX(term)) & LY_CTX_LEAFREF_LINKING) { - lyd_free_leafref_nodes(t); - } - - /* always clear the default flag */ - if (term->flags & LYD_DEFAULT) { - for (parent = term; parent; parent = lyd_parent(parent)) { - parent->flags &= ~LYD_DEFAULT; - } - /* make the node non-validated */ - term->flags &= LYD_NEW; - dflt_change = 1; - } else { - dflt_change = 0; - } - - /* return value */ - if (!val_change) { - if (dflt_change) { - /* only default flag change */ - ret = LY_EEXIST; - } else { - /* no change */ - ret = LY_ENOT; - } - } /* else value changed, LY_SUCCESS */ - -cleanup: - return ret; + /* change it */ + return lyd_change_term_val(term, &val, 1, 0); } LIBYANG_API_DEF LY_ERR @@ -1623,13 +1658,14 @@ lyd_new_path_(struct lyd_node *parent, const struct ly_ctx *ctx, const struct ly LY_ERR ret = LY_SUCCESS, r; struct lyxp_expr *exp = NULL; struct ly_path *p = NULL; - struct lyd_node *nparent = NULL, *nnode = NULL, *node = NULL, *cur_parent; + struct lyd_node *nparent = NULL, *nnode = NULL, *node = NULL, *cur_parent, *iter; const struct lysc_node *schema; const struct lyd_value *val = NULL; ly_bool store_only = (options & LYD_NEW_VAL_STORE_ONLY) ? 1 : 0; + ly_bool any_use_value = (options & LYD_NEW_ANY_USE_VALUE) ? 1 : 0; LY_ARRAY_COUNT_TYPE path_idx = 0, orig_count = 0; LY_VALUE_FORMAT format; - uint32_t hints; + uint32_t hints, count; assert(parent || ctx); assert(path && ((path[0] == '/') || parent)); @@ -1676,7 +1712,7 @@ lyd_new_path_(struct lyd_node *parent, const struct ly_ctx *ctx, const struct ly goto cleanup; } /* else we were not searching for the whole path */ } else if (r == LY_EINCOMPLETE) { - /* some nodes were found, adjust the iterator to the next segment */ + /* some nodes were found, adjust the iterator to the next segment to be created */ ++path_idx; } else if (r == LY_ENOTFOUND) { /* we will create the nodes from top-level, default behavior (absolute path), or from the parent (relative path) */ @@ -1695,6 +1731,29 @@ lyd_new_path_(struct lyd_node *parent, const struct ly_ctx *ctx, const struct ly LY_ARRAY_INCREMENT(p); } + if ((path_idx < LY_ARRAY_COUNT(p)) && lysc_is_dup_inst_list(p[path_idx].node) && p[path_idx].predicates && + (p[path_idx].predicates[0].type == LY_PATH_PREDTYPE_POSITION)) { + /* check the used position of a key-less list or state leaf-list */ + count = 0; + LYD_LIST_FOR_INST(node ? lyd_child(node) : parent, p[path_idx].node, iter) { + ++count; + } + + if (count + 1 < p[path_idx].predicates[0].position) { + if (count) { + LOGVAL(ctx, LYVE_REFERENCE, + "Cannot create \"%s\" on position %" PRIu64 ", only %" PRIu32 " instance%s exist%s.", + p[path_idx].node->name, p[path_idx].predicates[0].position, count, (count > 1) ? "s" : "", + (count > 1) ? "" : "s"); + } else { + LOGVAL(ctx, LYVE_REFERENCE, "Cannot create \"%s\" on position %" PRIu64 ", no instances exist.", + p[path_idx].node->name, p[path_idx].predicates[0].position); + } + ret = LY_EINVAL; + goto cleanup; + } + } + /* create all the non-existing nodes in a loop */ for ( ; path_idx < LY_ARRAY_COUNT(p); ++path_idx) { cur_parent = node; @@ -1789,7 +1848,7 @@ lyd_new_path_(struct lyd_node *parent, const struct ly_ctx *ctx, const struct ly break; case LYS_ANYDATA: case LYS_ANYXML: - LY_CHECK_GOTO(ret = lyd_create_any(schema, value, value_type, 0, &node), cleanup); + LY_CHECK_GOTO(ret = lyd_create_any(schema, value, value_type, any_use_value, &node), cleanup); break; default: LOGINT(ctx); @@ -1875,16 +1934,16 @@ lyd_new_ext_path(struct lyd_node *parent, const struct lysc_ext_instance *ext, c } LY_ERR -lyd_new_implicit_r(struct lyd_node *parent, struct lyd_node **first, const struct lysc_node *sparent, +lyd_new_implicit(struct lyd_node *parent, struct lyd_node **first, const struct lysc_node *sparent, const struct lys_module *mod, struct ly_set *node_when, struct ly_set *node_types, struct ly_set *ext_node, - uint32_t impl_opts, struct lyd_node **diff) + uint32_t impl_opts, struct ly_ht *getnext_ht, struct lyd_node **diff) { LY_ERR ret; - const struct lysc_node *iter = NULL; + const struct lysc_node *snode, **choices, **snodes; struct lyd_node *node = NULL; struct lyd_value **dflts; LY_ARRAY_COUNT_TYPE u; - uint32_t getnext_opts; + uint32_t i; assert(first && (parent || sparent || mod)); @@ -1892,40 +1951,51 @@ lyd_new_implicit_r(struct lyd_node *parent, struct lyd_node **first, const struc sparent = parent->schema; } - getnext_opts = LYS_GETNEXT_WITHCHOICE; - if (impl_opts & LYD_IMPLICIT_OUTPUT) { - getnext_opts |= LYS_GETNEXT_OUTPUT; - } + /* get cached getnext schema nodes */ + LY_CHECK_RET(lyd_val_getnext_get(sparent, mod, NULL, impl_opts & LYD_IMPLICIT_OUTPUT, getnext_ht, &choices, &snodes)); - while ((iter = lys_getnext(iter, sparent, mod ? mod->compiled : NULL, getnext_opts))) { - if ((impl_opts & LYD_IMPLICIT_NO_STATE) && (iter->flags & LYS_CONFIG_R)) { + /* choice nodes */ + for (i = 0; choices && choices[i]; ++i) { + snode = choices[i]; + + if ((impl_opts & LYD_IMPLICIT_NO_STATE) && (snode->flags & LYS_CONFIG_R)) { continue; - } else if ((impl_opts & LYD_IMPLICIT_NO_CONFIG) && (iter->flags & LYS_CONFIG_W)) { + } else if ((impl_opts & LYD_IMPLICIT_NO_CONFIG) && (snode->flags & LYS_CONFIG_W)) { continue; } - switch (iter->nodetype) { - case LYS_CHOICE: - node = lys_getnext_data(NULL, *first, NULL, iter, NULL); - if (!node && ((struct lysc_node_choice *)iter)->dflt) { - /* create default case data */ - LY_CHECK_RET(lyd_new_implicit_r(parent, first, &((struct lysc_node_choice *)iter)->dflt->node, - NULL, node_when, node_types, ext_node, impl_opts, diff)); - } else if (node) { - /* create any default data in the existing case */ - assert(node->schema->parent->nodetype == LYS_CASE); - LY_CHECK_RET(lyd_new_implicit_r(parent, first, node->schema->parent, NULL, node_when, node_types, - ext_node, impl_opts, diff)); - } - break; + node = lys_getnext_data(NULL, *first, NULL, snode, NULL); + if (!node && ((struct lysc_node_choice *)snode)->dflt) { + /* create default case data */ + LY_CHECK_RET(lyd_new_implicit(parent, first, &((struct lysc_node_choice *)snode)->dflt->node, + NULL, node_when, node_types, ext_node, impl_opts, getnext_ht, diff)); + } else if (node) { + /* create any default data in the existing case */ + assert(node->schema->parent->nodetype == LYS_CASE); + LY_CHECK_RET(lyd_new_implicit(parent, first, node->schema->parent, NULL, node_when, node_types, ext_node, + impl_opts, getnext_ht, diff)); + } + } + + /* container, leaf, leaf-list nodes */ + for (i = 0; snodes && snodes[i]; ++i) { + snode = snodes[i]; + + if ((impl_opts & LYD_IMPLICIT_NO_STATE) && (snode->flags & LYS_CONFIG_R)) { + continue; + } else if ((impl_opts & LYD_IMPLICIT_NO_CONFIG) && (snode->flags & LYS_CONFIG_W)) { + continue; + } + + switch (snode->nodetype) { case LYS_CONTAINER: - if (!(iter->flags & LYS_PRESENCE) && lyd_find_sibling_val(*first, iter, NULL, 0, NULL)) { + if (!(snode->flags & LYS_PRESENCE) && lyd_find_sibling_val(*first, snode, NULL, 0, NULL)) { /* create default NP container */ - LY_CHECK_RET(lyd_create_inner(iter, &node)); - node->flags = LYD_DEFAULT | (lysc_has_when(iter) ? LYD_WHEN_TRUE : 0); + LY_CHECK_RET(lyd_create_inner(snode, &node)); + node->flags = LYD_DEFAULT | (lysc_has_when(snode) ? LYD_WHEN_TRUE : 0); lyd_insert_node(parent, first, node, LYD_INSERT_NODE_DEFAULT); - if (lysc_has_when(iter) && node_when) { + if (lysc_has_when(snode) && node_when) { /* remember to resolve when */ LY_CHECK_RET(ly_set_add(node_when, node, 1, NULL)); } @@ -1937,17 +2007,13 @@ lyd_new_implicit_r(struct lyd_node *parent, struct lyd_node **first, const struc /* add into diff */ LY_CHECK_RET(lyd_val_diff_add(node, LYD_DIFF_OP_CREATE, diff)); } - - /* create any default children */ - LY_CHECK_RET(lyd_new_implicit_r(node, lyd_node_child_p(node), NULL, NULL, node_when, node_types, - ext_node, impl_opts, diff)); } break; case LYS_LEAF: - if (!(impl_opts & LYD_IMPLICIT_NO_DEFAULTS) && ((struct lysc_node_leaf *)iter)->dflt && - lyd_find_sibling_val(*first, iter, NULL, 0, NULL)) { + if (!(impl_opts & LYD_IMPLICIT_NO_DEFAULTS) && ((struct lysc_node_leaf *)snode)->dflt && + lyd_find_sibling_val(*first, snode, NULL, 0, NULL)) { /* create default leaf */ - ret = lyd_create_term2(iter, ((struct lysc_node_leaf *)iter)->dflt, &node); + ret = lyd_create_term2(snode, ((struct lysc_node_leaf *)snode)->dflt, &node); if (ret == LY_EINCOMPLETE) { if (node_types) { /* remember to resolve type */ @@ -1956,10 +2022,10 @@ lyd_new_implicit_r(struct lyd_node *parent, struct lyd_node **first, const struc } else if (ret) { return ret; } - node->flags = LYD_DEFAULT | (lysc_has_when(iter) ? LYD_WHEN_TRUE : 0); + node->flags = LYD_DEFAULT | (lysc_has_when(snode) ? LYD_WHEN_TRUE : 0); lyd_insert_node(parent, first, node, LYD_INSERT_NODE_DEFAULT); - if (lysc_has_when(iter) && node_when) { + if (lysc_has_when(snode) && node_when) { /* remember to resolve when */ LY_CHECK_RET(ly_set_add(node_when, node, 1, NULL)); } @@ -1974,12 +2040,12 @@ lyd_new_implicit_r(struct lyd_node *parent, struct lyd_node **first, const struc } break; case LYS_LEAFLIST: - if (!(impl_opts & LYD_IMPLICIT_NO_DEFAULTS) && ((struct lysc_node_leaflist *)iter)->dflts && - lyd_find_sibling_val(*first, iter, NULL, 0, NULL)) { + if (!(impl_opts & LYD_IMPLICIT_NO_DEFAULTS) && ((struct lysc_node_leaflist *)snode)->dflts && + lyd_find_sibling_val(*first, snode, NULL, 0, NULL)) { /* create all default leaf-lists */ - dflts = ((struct lysc_node_leaflist *)iter)->dflts; + dflts = ((struct lysc_node_leaflist *)snode)->dflts; LY_ARRAY_FOR(dflts, u) { - ret = lyd_create_term2(iter, dflts[u], &node); + ret = lyd_create_term2(snode, dflts[u], &node); if (ret == LY_EINCOMPLETE) { if (node_types) { /* remember to resolve type */ @@ -1988,10 +2054,10 @@ lyd_new_implicit_r(struct lyd_node *parent, struct lyd_node **first, const struc } else if (ret) { return ret; } - node->flags = LYD_DEFAULT | (lysc_has_when(iter) ? LYD_WHEN_TRUE : 0); + node->flags = LYD_DEFAULT | (lysc_has_when(snode) ? LYD_WHEN_TRUE : 0); lyd_insert_node(parent, first, node, LYD_INSERT_NODE_DEFAULT); - if (lysc_has_when(iter) && node_when) { + if (lysc_has_when(snode) && node_when) { /* remember to resolve when */ LY_CHECK_RET(ly_set_add(node_when, node, 1, NULL)); } @@ -2015,38 +2081,64 @@ lyd_new_implicit_r(struct lyd_node *parent, struct lyd_node **first, const struc return LY_SUCCESS; } +LY_ERR +lyd_new_implicit_r(struct lyd_node *parent, struct lyd_node **first, const struct lysc_node *sparent, + const struct lys_module *mod, struct ly_set *node_when, struct ly_set *node_types, struct ly_set *ext_node, + uint32_t impl_opts, struct ly_ht *getnext_ht, struct lyd_node **diff) +{ + struct lyd_node *child; + + /* parent children */ + LY_CHECK_RET(lyd_new_implicit(parent, first, sparent, mod, node_when, node_types, ext_node, impl_opts, getnext_ht, diff)); + + LY_LIST_FOR(parent ? lyd_child_no_keys(parent) : *first, child) { + /* recursively for all the containers */ + if ((child->flags & LYD_DEFAULT) && (child->schema->nodetype == LYS_CONTAINER)) { + LY_CHECK_RET(lyd_new_implicit_r(child, lyd_node_child_p(child), NULL, mod, node_when, node_types, ext_node, + impl_opts, getnext_ht, diff)); + } + } + + return LY_SUCCESS; +} + LIBYANG_API_DEF LY_ERR lyd_new_implicit_tree(struct lyd_node *tree, uint32_t implicit_options, struct lyd_node **diff) { - LY_ERR ret = LY_SUCCESS; + LY_ERR rc = LY_SUCCESS; struct lyd_node *node; struct ly_set node_when = {0}; + struct ly_ht *getnext_ht = NULL; LY_CHECK_ARG_RET(NULL, tree, LY_EINVAL); if (diff) { *diff = NULL; } + /* create the getnext hash table */ + LY_CHECK_GOTO(rc = lyd_val_getnext_ht_new(&getnext_ht), cleanup); + LYD_TREE_DFS_BEGIN(tree, node) { if (node->schema && (node->schema->nodetype & LYD_NODE_INNER)) { - LY_CHECK_GOTO(ret = lyd_new_implicit_r(node, lyd_node_child_p(node), NULL, NULL, &node_when, NULL, - NULL, implicit_options, diff), cleanup); + LY_CHECK_GOTO(rc = lyd_new_implicit(node, lyd_node_child_p(node), NULL, NULL, &node_when, NULL, + NULL, implicit_options, getnext_ht, diff), cleanup); } LYD_TREE_DFS_END(tree, node); } /* resolve when and remove any invalid defaults */ - ret = lyd_validate_unres(&tree, NULL, 0, &node_when, LYXP_IGNORE_WHEN, NULL, NULL, NULL, NULL, 0, diff); - LY_CHECK_GOTO(ret, cleanup); + rc = lyd_validate_unres(&tree, NULL, 0, &node_when, LYXP_IGNORE_WHEN, NULL, NULL, NULL, NULL, 0, diff); + LY_CHECK_GOTO(rc, cleanup); cleanup: ly_set_erase(&node_when, NULL); - if (ret && diff) { + lyd_val_getnext_ht_free(getnext_ht); + if (rc && diff) { lyd_free_all(*diff); *diff = NULL; } - return ret; + return rc; } LIBYANG_API_DEF LY_ERR @@ -2055,7 +2147,7 @@ lyd_new_implicit_all(struct lyd_node **tree, const struct ly_ctx *ctx, uint32_t const struct lys_module *mod; struct lyd_node *d = NULL; uint32_t i = 0; - LY_ERR ret = LY_SUCCESS; + LY_ERR rc = LY_SUCCESS; LY_CHECK_ARG_RET(ctx, tree, *tree || ctx, LY_EINVAL); LY_CHECK_CTX_EQUAL_RET(*tree ? LYD_CTX(*tree) : NULL, ctx, LY_EINVAL); @@ -2072,7 +2164,7 @@ lyd_new_implicit_all(struct lyd_node **tree, const struct ly_ctx *ctx, uint32_t continue; } - LY_CHECK_GOTO(ret = lyd_new_implicit_module(tree, mod, implicit_options, diff ? &d : NULL), cleanup); + LY_CHECK_GOTO(rc = lyd_new_implicit_module(tree, mod, implicit_options, diff ? &d : NULL), cleanup); if (d) { /* merge into one diff */ lyd_insert_sibling(*diff, d, diff); @@ -2082,20 +2174,21 @@ lyd_new_implicit_all(struct lyd_node **tree, const struct ly_ctx *ctx, uint32_t } cleanup: - if (ret && diff) { + if (rc && diff) { lyd_free_all(*diff); *diff = NULL; } - return ret; + return rc; } LIBYANG_API_DEF LY_ERR lyd_new_implicit_module(struct lyd_node **tree, const struct lys_module *module, uint32_t implicit_options, struct lyd_node **diff) { - LY_ERR ret = LY_SUCCESS; + LY_ERR rc = LY_SUCCESS; struct lyd_node *root, *d = NULL; struct ly_set node_when = {0}; + struct ly_ht *getnext_ht = NULL; LY_CHECK_ARG_RET(NULL, tree, module, LY_EINVAL); LY_CHECK_CTX_EQUAL_RET(*tree ? LYD_CTX(*tree) : NULL, module ? module->ctx : NULL, LY_EINVAL); @@ -2103,17 +2196,20 @@ lyd_new_implicit_module(struct lyd_node **tree, const struct lys_module *module, *diff = NULL; } + /* create the getnext hash table for this module */ + LY_CHECK_GOTO(rc = lyd_val_getnext_ht_new(&getnext_ht), cleanup); + /* add all top-level defaults for this module */ - LY_CHECK_GOTO(ret = lyd_new_implicit_r(NULL, tree, NULL, module, &node_when, NULL, NULL, implicit_options, diff), - cleanup); + rc = lyd_new_implicit(NULL, tree, NULL, module, &node_when, NULL, NULL, implicit_options, getnext_ht, diff); + LY_CHECK_GOTO(rc, cleanup); /* resolve when and remove any invalid defaults */ - LY_CHECK_GOTO(ret = lyd_validate_unres(tree, module, 0, &node_when, LYXP_IGNORE_WHEN, NULL, NULL, NULL, NULL, + LY_CHECK_GOTO(rc = lyd_validate_unres(tree, module, 0, &node_when, LYXP_IGNORE_WHEN, NULL, NULL, NULL, NULL, 0, diff), cleanup); - /* process nested nodes */ + /* process top-level (and nested) nodes */ LY_LIST_FOR(*tree, root) { - LY_CHECK_GOTO(ret = lyd_new_implicit_tree(root, implicit_options, diff ? &d : NULL), cleanup); + LY_CHECK_GOTO(rc = lyd_new_implicit_tree(root, implicit_options, diff ? &d : NULL), cleanup); if (d) { /* merge into one diff */ @@ -2124,9 +2220,10 @@ lyd_new_implicit_module(struct lyd_node **tree, const struct lys_module *module, cleanup: ly_set_erase(&node_when, NULL); - if (ret && diff) { + lyd_val_getnext_ht_free(getnext_ht); + if (rc && diff) { lyd_free_all(*diff); *diff = NULL; } - return ret; + return rc; } diff --git a/src/tree_data_sorted.c b/src/tree_data_sorted.c index 69a459b..ce0820c 100644 --- a/src/tree_data_sorted.c +++ b/src/tree_data_sorted.c @@ -935,7 +935,7 @@ lyds_pool_clean(struct lyds_pool *pool) pool->rbn = NULL; for (meta = pool->meta; meta; meta = next) { - next = meta->next ? meta->next : NULL; + next = meta->next; RBT_SET(meta, NULL); lyd_free_meta_single(meta); } @@ -1055,9 +1055,10 @@ lyds_additionally_create_rb_nodes(struct lyd_node **first_sibling, struct lyd_no LY_ERR ret; ly_bool max; struct rb_node *rbn; - struct lyd_node *iter; + struct lyd_node *iter, *next; - for (iter = node; iter && (iter->schema == (*leader)->schema); iter = iter->next) { + for (iter = node; iter && (iter->schema == (*leader)->schema); iter = next) { + next = iter->next; ret = lyds_create_node(iter, &rbn); LY_CHECK_RET(ret); rb_insert_node(rbt, rbn, &max); @@ -1118,7 +1119,7 @@ lyds_additionally_reuse_rb_tree(struct lyd_node **first_sibling, struct lyd_node struct rb_node **rbt, struct lyds_pool *pool, struct lyd_node **next) { ly_bool max; - struct lyd_node *iter; + struct lyd_node *iter, *next_node; /* let's begin with the leader */ RBN_RESET(pool->rbn, *leader); @@ -1126,7 +1127,8 @@ lyds_additionally_reuse_rb_tree(struct lyd_node **first_sibling, struct lyd_node pool->rbn = rb_iter_next(&pool->iter_state); /* continue with the rest of the nodes */ - for (iter = (*leader)->next; iter && (iter->schema == (*leader)->schema); iter = iter->next) { + for (iter = (*leader)->next; iter && (iter->schema == (*leader)->schema); iter = next_node) { + next_node = iter->next; if (!pool->rbn) { *next = iter; return; diff --git a/src/tree_schema_common.c b/src/tree_schema_common.c index 0faaa3c..e6af579 100644 --- a/src/tree_schema_common.c +++ b/src/tree_schema_common.c @@ -91,8 +91,8 @@ lysp_check_date(struct lysp_ctx *ctx, const char *date, size_t date_len, const c } memcpy(&tm_, &tm, sizeof tm); - /* DST may move the hour back resulting in a different day */ - tm_.tm_hour = 1; + /* Disabling DST: Set tm_isdst to -1 so that mktime() won't adjust for daylight saving time. */ + tm_.tm_isdst = -1; mktime(&tm_); /* mktime modifies tm_ if it refers invalid date */ if (tm.tm_mday != tm_.tm_mday) { /* e.g 2018-02-29 -> 2018-03-01 */ diff --git a/src/validation.c b/src/validation.c index a950c54..18ec15c 100644 --- a/src/validation.c +++ b/src/validation.c @@ -3,7 +3,7 @@ * @author Michal Vasko * @brief Validation * - * Copyright (c) 2019 - 2023 CESNET, z.s.p.o. + * Copyright (c) 2019 - 2024 CESNET, z.s.p.o. * * This source code is licensed under BSD 3-Clause License (the "License"). * You may not use this file except in compliance with the License. @@ -56,6 +56,109 @@ } \ } +/** + * @brief Callback for freeing getnext HT values. + */ +static void +lyd_val_getnext_ht_free_cb(void *val_p) +{ + struct lyd_val_getnext *val = val_p; + + free(val->snodes); + free(val->choices); +} + +/** + * @brief Callback for checking getnext HT value equality. + */ +static ly_bool +lyd_val_getnext_ht_equal_cb(void *val1_p, void *val2_p, ly_bool UNUSED(mod), void *UNUSED(cb_data)) +{ + struct lyd_val_getnext *val1 = val1_p; + struct lyd_val_getnext *val2 = val2_p; + + if (val1->sparent == val2->sparent) { + return 1; + } + return 0; +} + +LY_ERR +lyd_val_getnext_ht_new(struct ly_ht **getnext_ht_p) +{ + *getnext_ht_p = lyht_new(32, sizeof(struct lyd_val_getnext), lyd_val_getnext_ht_equal_cb, NULL, 1); + + if (!*getnext_ht_p) { + LOGMEM(NULL); + return LY_EMEM; + } + return LY_SUCCESS; +} + +void +lyd_val_getnext_ht_free(struct ly_ht *getnext_ht) +{ + lyht_free(getnext_ht, lyd_val_getnext_ht_free_cb); +} + +LY_ERR +lyd_val_getnext_get(const struct lysc_node *sparent, const struct lys_module *mod, const struct lysc_ext_instance *ext, + ly_bool output, struct ly_ht *getnext_ht, const struct lysc_node ***choices, const struct lysc_node ***snodes) +{ + LY_ERR rc = LY_SUCCESS; + struct lyd_val_getnext val = {0}, *getnext = NULL; + const struct lysc_node *snode = NULL; + uint32_t getnext_opts, snode_count = 0, choice_count = 0; + + /* try to find the entry for this schema parent */ + val.sparent = sparent; + if (!lyht_find(getnext_ht, &val, (uintptr_t)sparent, (void **)&getnext)) { + goto cleanup; + } + + /* traverse all the children using getnext and store them */ + getnext_opts = LYS_GETNEXT_WITHCHOICE | (output ? LYS_GETNEXT_OUTPUT : 0); + while (ext ? (snode = lys_getnext_ext(snode, sparent, ext, getnext_opts)) : + (snode = lys_getnext(snode, sparent, mod ? mod->compiled : NULL, getnext_opts))) { + if (snode->nodetype == LYS_CHOICE) { + /* store a choice node */ + val.choices = ly_realloc(val.choices, (choice_count + 2) * sizeof *val.choices); + LY_CHECK_ERR_GOTO(!val.choices, LOGMEM(NULL); rc = LY_EMEM, cleanup); + val.choices[choice_count] = snode; + ++choice_count; + } else { + /* store other nodes */ + val.snodes = ly_realloc(val.snodes, (snode_count + 2) * sizeof *val.snodes); + LY_CHECK_ERR_GOTO(!val.snodes, LOGMEM(NULL); rc = LY_EMEM, cleanup); + val.snodes[snode_count] = snode; + ++snode_count; + } + } + + /* add terminating NULL items */ + if (choice_count) { + val.choices[choice_count] = NULL; + } + if (snode_count) { + val.snodes[snode_count] = NULL; + } + + /* add into the hash table */ + if ((rc = lyht_insert(getnext_ht, &val, (uintptr_t)sparent, (void **)&getnext))) { + goto cleanup; + } + +cleanup: + if (rc) { + free(val.snodes); + free(val.choices); + } else { + *choices = getnext->choices; + *snodes = getnext->snodes; + } + return rc; +} + LY_ERR lyd_val_diff_add(const struct lyd_node *node, enum lyd_diff_op op, struct lyd_node **diff) { @@ -434,6 +537,18 @@ cleanup: return rc; } +/** + * @brief Compare callback for finding duplicates in hash table. + * + * Implementation of ::lyht_value_equal_cb. + */ +static ly_bool +lyd_val_dup_val_equal(void *val1_p, void *val2_p, ly_bool UNUSED(mod), void *cb_data) +{ + /* always find the same instance, not the exact same pointer (set mod = 0) */ + return lyd_hash_table_val_equal(val1_p, val2_p, 0, cb_data); +} + /** * @brief Validate instance duplication. * @@ -445,7 +560,6 @@ cleanup: static LY_ERR lyd_validate_duplicates(const struct lyd_node *first, const struct lyd_node *node, uint32_t val_opts) { - struct lyd_node **match_p, *match; ly_bool fail = 0; assert(node->flags & LYD_NEW); @@ -458,12 +572,9 @@ lyd_validate_duplicates(const struct lyd_node *first, const struct lyd_node *nod /* find exactly the same next instance using hashes if possible */ if (node->parent && node->parent->children_ht) { - lyd_find_sibling_first(first, node, &match); - assert(match); - - if (match != node) { - fail = 1; - } else if (!lyht_find_next(node->parent->children_ht, &node, node->hash, (void **)&match_p)) { + /* because of the callback used, an instance must always be found (pointer may or may not be equal to node), + * so if we find another instance, there is a duplicate */ + if (!lyht_find_next_with_collision_cb(node->parent->children_ht, &node, node->hash, lyd_val_dup_val_equal, NULL)) { fail = 1; } } else { @@ -783,27 +894,37 @@ lyd_validate_autodel_case_dflt(struct lyd_node **first, struct lyd_node **node, * @param[in,out] first First sibling. * @param[in] sparent Schema parent of the siblings, NULL for top-level siblings. * @param[in] mod Module of the siblings, NULL for nested siblings. + * @param[in] ext Extension instance to use, if relevant. * @param[in] val_opts Validation options. + * @param[in] int_opts Internal parser options. + * @param[in,out] getnext_ht Getnext HT to use, new @p sparent is added to it. * @param[in,out] diff Validation diff. * @return LY_ERR value. */ static LY_ERR lyd_validate_choice_r(struct lyd_node **first, const struct lysc_node *sparent, const struct lys_module *mod, - uint32_t val_opts, struct lyd_node **diff) + const struct lysc_ext_instance *ext, uint32_t val_opts, uint32_t int_opts, struct ly_ht *getnext_ht, + struct lyd_node **diff) { LY_ERR r, rc = LY_SUCCESS; - const struct lysc_node *snode = NULL; + const struct lysc_node **choices, **snodes; + uint32_t i; - while (*first && (snode = lys_getnext(snode, sparent, mod ? mod->compiled : NULL, LYS_GETNEXT_WITHCHOICE))) { + /* get cached getnext schema nodes */ + rc = lyd_val_getnext_get(sparent, mod, ext, int_opts & LYD_INTOPT_REPLY, getnext_ht, &choices, &snodes); + LY_CHECK_GOTO(rc, cleanup); + if (!choices) { + goto cleanup; + } + + for (i = 0; *first && choices[i]; ++i) { /* check case duplicites */ - if (snode->nodetype == LYS_CHOICE) { - r = lyd_validate_cases(first, mod, (struct lysc_node_choice *)snode, diff); - LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); + r = lyd_validate_cases(first, mod, (struct lysc_node_choice *)choices[i], diff); + LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); - /* check for nested choice */ - r = lyd_validate_choice_r(first, snode, mod, val_opts, diff); - LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); - } + /* check for nested choice */ + r = lyd_validate_choice_r(first, choices[i], mod, ext, val_opts, int_opts, getnext_ht, diff); + LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); } cleanup: @@ -812,7 +933,8 @@ cleanup: LY_ERR lyd_validate_new(struct lyd_node **first, const struct lysc_node *sparent, const struct lys_module *mod, - uint32_t val_opts, struct lyd_node **diff) + const struct lysc_ext_instance *ext, uint32_t val_opts, uint32_t int_opts, struct ly_ht *getnext_ht, + struct lyd_node **diff) { LY_ERR r, rc = LY_SUCCESS; struct lyd_node *node; @@ -821,7 +943,7 @@ lyd_validate_new(struct lyd_node **first, const struct lysc_node *sparent, const assert(first && (sparent || mod)); /* validate choices */ - r = lyd_validate_choice_r(first, sparent, mod, val_opts, diff); + r = lyd_validate_choice_r(first, sparent, mod, ext, val_opts, int_opts, getnext_ht, diff); LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); node = *first; @@ -1369,38 +1491,76 @@ cleanup: * @param[in] parent Data parent. * @param[in] sparent Schema parent of the nodes to check. * @param[in] mod Module of the nodes to check. + * @param[in] ext Extension instance to use, if relevant. * @param[in] val_opts Validation options, see @ref datavalidationoptions. * @param[in] int_opts Internal parser options. + * @param[in,out] getnext_ht Getnext HT to use, new @p sparent is added to it. * @return LY_ERR value. */ static LY_ERR lyd_validate_siblings_schema_r(const struct lyd_node *first, const struct lyd_node *parent, - const struct lysc_node *sparent, const struct lysc_module *mod, uint32_t val_opts, uint32_t int_opts) + const struct lysc_node *sparent, const struct lys_module *mod, const struct lysc_ext_instance *ext, + uint32_t val_opts, uint32_t int_opts, struct ly_ht *getnext_ht) { LY_ERR r, rc = LY_SUCCESS; - const struct lysc_node *snode = NULL, *scase; + const struct lysc_node *snode, *scase, **choices, **snodes; struct lysc_node_list *slist; struct lysc_node_leaflist *sllist; - uint32_t getnext_opts; + uint32_t i; - getnext_opts = LYS_GETNEXT_WITHCHOICE | (int_opts & LYD_INTOPT_REPLY ? LYS_GETNEXT_OUTPUT : 0); + /* get cached getnext schema nodes */ + rc = lyd_val_getnext_get(sparent, mod, ext, int_opts & LYD_INTOPT_REPLY, getnext_ht, &choices, &snodes); + LY_CHECK_GOTO(rc, cleanup); + + for (i = 0; choices && choices[i]; ++i) { + snode = choices[i]; - /* disabled nodes are skipped by lys_getnext */ - while ((snode = lys_getnext(snode, sparent, mod, getnext_opts))) { if ((val_opts & LYD_VALIDATE_NO_STATE) && (snode->flags & LYS_CONFIG_R)) { + /* skip state nodes */ + continue; + } + + if (snode->flags & LYS_MAND_TRUE) { + /* check generic mandatory existence */ + r = lyd_validate_mandatory(first, parent, snode, val_opts); + LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); + } + + /* find the existing case, if any */ + LY_LIST_FOR(lysc_node_child(snode), scase) { + if (lys_getnext_data(NULL, first, NULL, scase, NULL)) { + /* validate only this case */ + r = lyd_validate_siblings_schema_r(first, parent, scase, mod, ext, val_opts, int_opts, getnext_ht); + LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); + break; + } + } + } + + for (i = 0; snodes && snodes[i]; ++i) { + snode = snodes[i]; + + if ((val_opts & LYD_VALIDATE_NO_STATE) && (snode->flags & LYS_CONFIG_R)) { + /* skip state nodes */ continue; } /* check min-elements and max-elements */ if (snode->nodetype == LYS_LIST) { slist = (struct lysc_node_list *)snode; - if (slist->min || slist->max) { + if (slist->min || (slist->max < UINT32_MAX)) { r = lyd_validate_minmax(first, parent, snode, slist->min, slist->max, val_opts); LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); } + + /* check unique */ + if (slist->uniques) { + r = lyd_validate_unique(first, snode, (const struct lysc_node_leaf ***)slist->uniques, val_opts); + LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); + } } else if (snode->nodetype == LYS_LEAFLIST) { sllist = (struct lysc_node_leaflist *)snode; - if (sllist->min || sllist->max) { + if (sllist->min || (sllist->max < UINT32_MAX)) { r = lyd_validate_minmax(first, parent, snode, sllist->min, sllist->max, val_opts); LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); } @@ -1410,27 +1570,6 @@ lyd_validate_siblings_schema_r(const struct lyd_node *first, const struct lyd_no r = lyd_validate_mandatory(first, parent, snode, val_opts); LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); } - - /* check unique */ - if (snode->nodetype == LYS_LIST) { - slist = (struct lysc_node_list *)snode; - if (slist->uniques) { - r = lyd_validate_unique(first, snode, (const struct lysc_node_leaf ***)slist->uniques, val_opts); - LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); - } - } - - if (snode->nodetype == LYS_CHOICE) { - /* find the existing case, if any */ - LY_LIST_FOR(lysc_node_child(snode), scase) { - if (lys_getnext_data(NULL, first, NULL, scase, NULL)) { - /* validate only this case */ - r = lyd_validate_siblings_schema_r(first, parent, scase, mod, val_opts, int_opts); - LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); - break; - } - } - } } cleanup: @@ -1557,14 +1696,17 @@ cleanup: * @param[in] parent Data parent. * @param[in] sparent Schema parent of the siblings, NULL for top-level siblings. * @param[in] mod Module of the siblings, NULL for nested siblings. + * @param[in] ext Extension instance to use, if relevant. * @param[in] val_opts Validation options (@ref datavalidationoptions). * @param[in] int_opts Internal parser options. * @param[in] must_xp_opts Additional XPath options to use for evaluating "must". + * @param[in,out] getnext_ht Getnext HT to use. * @return LY_ERR value. */ static LY_ERR lyd_validate_final_r(struct lyd_node *first, const struct lyd_node *parent, const struct lysc_node *sparent, - const struct lys_module *mod, uint32_t val_opts, uint32_t int_opts, uint32_t must_xp_opts) + const struct lys_module *mod, const struct lysc_ext_instance *ext, uint32_t val_opts, uint32_t int_opts, + uint32_t must_xp_opts, struct ly_ht *getnext_ht) { LY_ERR r, rc = LY_SUCCESS; const char *innode; @@ -1626,7 +1768,7 @@ next_iter: } /* validate schema-based restrictions */ - r = lyd_validate_siblings_schema_r(first, parent, sparent, mod ? mod->compiled : NULL, val_opts, int_opts); + r = lyd_validate_siblings_schema_r(first, parent, sparent, mod, ext, val_opts, int_opts, getnext_ht); LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); LY_LIST_FOR(first, node) { @@ -1636,11 +1778,12 @@ next_iter: } /* validate all children recursively */ - r = lyd_validate_final_r(lyd_child(node), node, node->schema, NULL, val_opts, int_opts, must_xp_opts); + r = lyd_validate_final_r(lyd_child(node), node, node->schema, NULL, NULL, val_opts, int_opts, must_xp_opts, + getnext_ht); LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); /* set default for containers */ - lyd_cont_set_dflt(node); + lyd_np_cont_dflt_set(node); } cleanup: @@ -1731,13 +1874,15 @@ lyd_validate_node_ext(struct lyd_node *node, struct ly_set *ext_node) * @param[in,out] ext_node Set with nodes with extensions to validate. * @param[in,out] ext_val Set for parsed extension data to validate. * @param[in] val_opts Validation options. + * @param[in] int_opts Internal parser options. + * @param[in,out] getnext_ht Getnext HT to use. * @param[in,out] diff Validation diff. * @return LY_ERR value. */ static LY_ERR lyd_validate_subtree(struct lyd_node *root, struct ly_set *node_when, struct ly_set *node_types, struct ly_set *meta_types, struct ly_set *ext_node, struct ly_set *ext_val, uint32_t val_opts, - struct lyd_node **diff) + uint32_t int_opts, struct ly_ht *getnext_ht, struct lyd_node **diff) { LY_ERR r, rc = LY_SUCCESS; const struct lyd_meta *meta; @@ -1771,7 +1916,7 @@ lyd_validate_subtree(struct lyd_node *root, struct ly_set *node_when, struct ly_ LY_CHECK_ERR_GOTO(r, rc = r, cleanup); } else if (node->schema->nodetype & LYD_NODE_INNER) { /* new node validation, autodelete */ - r = lyd_validate_new(lyd_node_child_p(node), node->schema, NULL, val_opts, diff); + r = lyd_validate_new(lyd_node_child_p(node), node->schema, NULL, NULL, val_opts, int_opts, getnext_ht, diff); LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); /* add nested defaults */ @@ -1782,7 +1927,7 @@ lyd_validate_subtree(struct lyd_node *root, struct ly_set *node_when, struct ly_ if (val_opts & LYD_VALIDATE_NO_DEFAULTS) { impl_opts |= LYD_IMPLICIT_NO_DEFAULTS; } - r = lyd_new_implicit_r(node, lyd_node_child_p(node), NULL, NULL, NULL, NULL, NULL, impl_opts, diff); + r = lyd_new_implicit(node, lyd_node_child_p(node), NULL, NULL, NULL, NULL, NULL, impl_opts, getnext_ht, diff); LY_CHECK_ERR_GOTO(r, rc = r, cleanup); } @@ -1814,6 +1959,7 @@ lyd_validate(struct lyd_node **tree, const struct lys_module *module, const stru const struct lys_module *mod; struct ly_set node_types = {0}, meta_types = {0}, node_when = {0}, ext_node = {0}, ext_val = {0}; uint32_t i = 0, impl_opts; + struct ly_ht *getnext_ht = NULL; assert(tree && ctx); assert((node_when_p && node_types_p && meta_types_p && ext_node_p && ext_val_p) || @@ -1844,8 +1990,13 @@ lyd_validate(struct lyd_node **tree, const struct lys_module *module, const stru first2 = &first; } + /* create the getnext hash table for this module */ + r = lyd_val_getnext_ht_new(&getnext_ht); + LY_CHECK_ERR_GOTO(r, rc = r, cleanup); + /* validate new top-level nodes of this module, autodelete */ - r = lyd_validate_new(first2, *first2 ? lysc_data_parent((*first2)->schema) : NULL, mod, val_opts, diff); + r = lyd_validate_new(first2, *first2 ? lysc_data_parent((*first2)->schema) : NULL, mod, NULL, val_opts, 0, + getnext_ht, diff); LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); /* add all top-level defaults for this module, if going to validate subtree, do not add into unres sets @@ -1857,9 +2008,15 @@ lyd_validate(struct lyd_node **tree, const struct lys_module *module, const stru if (val_opts & LYD_VALIDATE_NO_DEFAULTS) { impl_opts |= LYD_IMPLICIT_NO_DEFAULTS; } - r = lyd_new_implicit_r(lyd_parent(*first2), first2, NULL, mod, validate_subtree ? NULL : node_when_p, - validate_subtree ? NULL : node_types_p, validate_subtree ? NULL : ext_node_p, impl_opts, diff); - LY_CHECK_ERR_GOTO(r, rc = r, cleanup); + if (validate_subtree) { + r = lyd_new_implicit(lyd_parent(*first2), first2, NULL, mod, NULL, NULL, NULL, impl_opts, getnext_ht, diff); + LY_CHECK_ERR_GOTO(r, rc = r, cleanup); + } else { + /* descendants will not be validated, create them all */ + r = lyd_new_implicit_r(lyd_parent(*first2), first2, NULL, mod, node_when_p, node_types_p, ext_node_p, + impl_opts, getnext_ht, diff); + LY_CHECK_ERR_GOTO(r, rc = r, cleanup); + } /* our first module node pointer may no longer be the first */ first = *first2; @@ -1878,7 +2035,7 @@ lyd_validate(struct lyd_node **tree, const struct lys_module *module, const stru } r = lyd_validate_subtree(iter, node_when_p, node_types_p, meta_types_p, ext_node_p, ext_val_p, - val_opts, diff); + val_opts, 0, getnext_ht, diff); LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); } } @@ -1890,9 +2047,13 @@ lyd_validate(struct lyd_node **tree, const struct lys_module *module, const stru if (!(val_opts & LYD_VALIDATE_NOT_FINAL)) { /* perform final validation that assumes the data tree is final */ - r = lyd_validate_final_r(*first2, NULL, NULL, mod, val_opts, 0, 0); + r = lyd_validate_final_r(*first2, NULL, NULL, mod, NULL, val_opts, 0, 0, getnext_ht); LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); } + + /* free the getnext hash table */ + lyht_free(getnext_ht, lyd_val_getnext_ht_free_cb); + getnext_ht = NULL; } cleanup: @@ -1901,6 +2062,63 @@ cleanup: ly_set_erase(&meta_types, NULL); ly_set_erase(&ext_node, free); ly_set_erase(&ext_val, free); + lyd_val_getnext_ht_free(getnext_ht); + return rc; +} + +LY_ERR +lyd_validate_ext(struct lyd_node **tree, const struct lysc_ext_instance *ext, uint32_t val_opts, + ly_bool validate_subtree, struct ly_set *node_when_p, struct ly_set *node_types_p, struct ly_set *meta_types_p, + struct ly_set *ext_node_p, struct ly_set *ext_val_p, struct lyd_node **diff) +{ + LY_ERR r, rc = LY_SUCCESS; + struct lyd_node *iter; + struct ly_set node_types = {0}, meta_types = {0}, node_when = {0}, ext_node = {0}, ext_val = {0}; + struct ly_ht *getnext_ht = NULL; + + assert(tree); + assert((node_when_p && node_types_p && meta_types_p && ext_node_p && ext_val_p) || + (!node_when_p && !node_types_p && !meta_types_p && !ext_node_p && !ext_val_p)); + + if (!node_when_p) { + node_when_p = &node_when; + node_types_p = &node_types; + meta_types_p = &meta_types; + ext_node_p = &ext_node; + ext_val_p = &ext_val; + } + + /* create the getnext hash table for these data */ + r = lyd_val_getnext_ht_new(&getnext_ht); + LY_CHECK_ERR_GOTO(r, rc = r, cleanup); + + if (validate_subtree) { + /* process nested nodes */ + LY_LIST_FOR(*tree, iter) { + r = lyd_validate_subtree(iter, node_when_p, node_types_p, meta_types_p, ext_node_p, ext_val_p, + val_opts, 0, getnext_ht, diff); + LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); + } + } + + /* finish incompletely validated terminal values/attributes and when conditions */ + r = lyd_validate_unres(tree, NULL, LYD_TYPE_DATA_YANG, node_when_p, 0, node_types_p, meta_types_p, + ext_node_p, ext_val_p, val_opts, diff); + LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); + + if (!(val_opts & LYD_VALIDATE_NOT_FINAL)) { + /* perform final validation that assumes the data tree is final */ + r = lyd_validate_final_r(*tree, NULL, NULL, NULL, ext, val_opts, 0, 0, getnext_ht); + LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); + } + +cleanup: + ly_set_erase(&node_when, NULL); + ly_set_erase(&node_types, NULL); + ly_set_erase(&meta_types, NULL); + ly_set_erase(&ext_node, free); + ly_set_erase(&ext_val, free); + lyd_val_getnext_ht_free(getnext_ht); return rc; } @@ -1938,6 +2156,7 @@ lyd_validate_module_final(struct lyd_node *tree, const struct lys_module *module struct lyd_node *first; const struct lys_module *mod; uint32_t i = 0; + struct ly_ht *getnext_ht = NULL; LY_CHECK_ARG_RET(NULL, module, !(val_opts & (LYD_VALIDATE_PRESENT | LYD_VALIDATE_NOT_FINAL)), LY_EINVAL); LY_CHECK_CTX_EQUAL_RET(tree ? LYD_CTX(tree) : NULL, module->ctx, LY_EINVAL); @@ -1946,11 +2165,16 @@ lyd_validate_module_final(struct lyd_node *tree, const struct lys_module *module mod = lyd_mod_next_module(tree, module, module->ctx, &i, &first); assert(mod); + /* create the getnext hash table for this module */ + r = lyd_val_getnext_ht_new(&getnext_ht); + LY_CHECK_ERR_GOTO(r, rc = r, cleanup); + /* perform final validation that assumes the data tree is final */ - r = lyd_validate_final_r(first, NULL, NULL, mod, val_opts, 0, 0); + r = lyd_validate_final_r(first, NULL, NULL, mod, NULL, val_opts, 0, 0, getnext_ht); LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); cleanup: + lyd_val_getnext_ht_free(getnext_ht); return rc; } @@ -2043,6 +2267,7 @@ _lyd_validate_op(struct lyd_node *op_tree, struct lyd_node *op_node, const struc LY_ERR rc = LY_SUCCESS; struct lyd_node *tree_sibling, *tree_parent, *op_subtree, *op_parent, *op_sibling_before, *op_sibling_after, *child; struct ly_set node_types = {0}, meta_types = {0}, node_when = {0}, ext_node = {0}, ext_val = {0}; + struct ly_ht *getnext_ht = NULL; assert(op_tree && op_node); assert((node_when_p && node_types_p && meta_types_p && ext_node_p && ext_val_p) || @@ -2068,23 +2293,34 @@ _lyd_validate_op(struct lyd_node *op_tree, struct lyd_node *op_node, const struc dep_tree = tree_sibling; } - if (int_opts & LYD_INTOPT_REPLY) { - /* add output children defaults */ - rc = lyd_new_implicit_r(op_node, lyd_node_child_p(op_node), NULL, NULL, node_when_p, node_types_p, - ext_node_p, LYD_IMPLICIT_OUTPUT, diff); - LY_CHECK_GOTO(rc, cleanup); + /* create the getnext hash table for this module */ + rc = lyd_val_getnext_ht_new(&getnext_ht); + LY_CHECK_GOTO(rc, cleanup); + if (int_opts & LYD_INTOPT_REPLY) { if (validate_subtree) { + /* add output children defaults */ + rc = lyd_new_implicit(op_node, lyd_node_child_p(op_node), NULL, NULL, node_when_p, node_types_p, + ext_node_p, LYD_IMPLICIT_OUTPUT, getnext_ht, diff); + LY_CHECK_GOTO(rc, cleanup); + /* skip validating the operation itself, go to children directly */ LY_LIST_FOR(lyd_child(op_node), child) { - rc = lyd_validate_subtree(child, node_when_p, node_types_p, meta_types_p, ext_node_p, ext_val_p, 0, diff); + rc = lyd_validate_subtree(child, node_when_p, node_types_p, meta_types_p, ext_node_p, ext_val_p, 0, + int_opts, getnext_ht, diff); LY_CHECK_GOTO(rc, cleanup); } + } else { + /* add output children defaults and their descendants */ + rc = lyd_new_implicit_r(op_node, lyd_node_child_p(op_node), NULL, NULL, node_when_p, node_types_p, + ext_node_p, LYD_IMPLICIT_OUTPUT, getnext_ht, diff); + LY_CHECK_GOTO(rc, cleanup); } } else { if (validate_subtree) { /* prevalidate whole operation subtree */ - rc = lyd_validate_subtree(op_node, node_when_p, node_types_p, meta_types_p, ext_node_p, ext_val_p, 0, diff); + rc = lyd_validate_subtree(op_node, node_when_p, node_types_p, meta_types_p, ext_node_p, ext_val_p, 0, + int_opts, getnext_ht, diff); LY_CHECK_GOTO(rc, cleanup); } } @@ -2099,7 +2335,8 @@ _lyd_validate_op(struct lyd_node *op_tree, struct lyd_node *op_node, const struc LY_CHECK_GOTO(rc = lyd_validate_must(op_node, 0, int_opts, LYXP_IGNORE_WHEN), cleanup); /* final validation of all the descendants */ - rc = lyd_validate_final_r(lyd_child(op_node), op_node, op_node->schema, NULL, 0, int_opts, LYXP_IGNORE_WHEN); + rc = lyd_validate_final_r(lyd_child(op_node), op_node, op_node->schema, NULL, NULL, 0, int_opts, LYXP_IGNORE_WHEN, + getnext_ht); LY_CHECK_GOTO(rc, cleanup); cleanup: @@ -2120,6 +2357,7 @@ cleanup: ly_set_erase(&meta_types, NULL); ly_set_erase(&ext_node, free); ly_set_erase(&ext_val, free); + lyd_val_getnext_ht_free(getnext_ht); return rc; } diff --git a/src/validation.h b/src/validation.h index db24ef6..01de310 100644 --- a/src/validation.h +++ b/src/validation.h @@ -27,6 +27,48 @@ struct lyd_node; struct lys_module; struct lysc_node; +/** + * @brief Cached getnext schema nodes stored in a validation HT. + */ +struct lyd_val_getnext { + const struct lysc_node *sparent; /**< schema parent, NULL for top-level nodes */ + const struct lysc_node **snodes; /**< array of schema node children excluding choices terminated by NULL */ + const struct lysc_node **choices; /**< array of choice schema node children terminated by NULL */ +}; + +/** + * @brief Create a getnext cached schema node validation HT. + * + * @param[out] getnext_ht_p Created getnext HT. + * @return LY_ERR value. + */ +LY_ERR lyd_val_getnext_ht_new(struct ly_ht **getnext_ht_p); + +/** + * @brief Free a getnext cached schema node validation HT. + * + * @param[in] getnext_ht Getnext HT to free. + */ +void lyd_val_getnext_ht_free(struct ly_ht *getnext_ht); + +/** + * @brief Get the schema children of a schema parent. + * + * Getnext structure cannot be returned because the pointer may become invalid on HT resize. + * + * @param[in] sparent Schema parent to use. + * @param[in] mod Module to use. + * @param[in] ext Extension instance to use, if relevant. + * @param[in] output Whether to traverse operation output instead of input nodes. + * @param[in,out] getnext_ht Getnext HT to use, new @p sparent is added to it. + * @param[out] choices Array of getnext choices of @p sparent. + * @param[out] snodes Array of getnext schema nodes except for choices of @p sparent. + * @return LY_ERR value. + */ +LY_ERR lyd_val_getnext_get(const struct lysc_node *sparent, const struct lys_module *mod, + const struct lysc_ext_instance *ext, ly_bool output, struct ly_ht *getnext_ht, const struct lysc_node ***choices, + const struct lysc_node ***snodes); + /** * @brief Add new changes into a diff. They are always merged. * @@ -69,12 +111,16 @@ LY_ERR lyd_validate_unres(struct lyd_node **tree, const struct lys_module *mod, * @param[in,out] first First sibling. * @param[in] sparent Schema parent of the siblings, NULL for top-level siblings. * @param[in] mod Module of the siblings, NULL for nested siblings. + * @param[in] ext Extension instance to use, if relevant. * @param[in] val_opts Validation options. + * @param[in] int_opts Internal parser options. + * @param[in,out] getnext_ht Getnext HT to use, new @p sparent is added to it. * @param[in,out] diff Validation diff. * @return LY_ERR value. */ LY_ERR lyd_validate_new(struct lyd_node **first, const struct lysc_node *sparent, const struct lys_module *mod, - uint32_t val_opts, struct lyd_node **diff); + const struct lysc_ext_instance *ext, uint32_t val_opts, uint32_t int_opts, struct ly_ht *getnext_ht, + struct lyd_node **diff); /** * @brief Validate data node with an extension instance, if any, by storing it in its unres set. @@ -105,4 +151,24 @@ LY_ERR lyd_validate(struct lyd_node **tree, const struct lys_module *module, con ly_bool validate_subtree, struct ly_set *node_when_p, struct ly_set *node_types_p, struct ly_set *meta_types_p, struct ly_set *ext_node_p, struct ly_set *ext_val_p, struct lyd_node **diff); +/** + * @brief Validate a data tree of an extension instance, which is assumed to be a separate data tree independent of + * normal YANG data. + * + * @param[in,out] tree Data tree to validate, nodes may be autodeleted. + * @param[in] ext Extension instance whose data to validate. + * @param[in] val_opts Validation options, see @ref datavalidationoptions. + * @param[in] validate_subtree Whether subtree was already validated (as part of data parsing) or not (separate validation). + * @param[in] node_when_p Set of nodes with when conditions, if NULL a local set is used. + * @param[in] node_types_p Set of unres node types, if NULL a local set is used. + * @param[in] meta_types_p Set of unres metadata types, if NULL a local set is used. + * @param[in] ext_node_p Set of unres nodes with extensions to validate, if NULL a local set is used. + * @param[in] ext_val_p Set of unres extension data to validate, if NULL a local set is used. + * @param[out] diff Generated validation diff, not generated if NULL. + * @return LY_ERR value. + */ +LY_ERR lyd_validate_ext(struct lyd_node **tree, const struct lysc_ext_instance *ext, uint32_t val_opts, + ly_bool validate_subtree, struct ly_set *node_when_p, struct ly_set *node_types_p, struct ly_set *meta_types_p, + struct ly_set *ext_node_p, struct ly_set *ext_val_p, struct lyd_node **diff); + #endif /* LY_VALIDATION_H_ */ diff --git a/src/xpath.c b/src/xpath.c index 2251eab..9594c48 100644 --- a/src/xpath.c +++ b/src/xpath.c @@ -12,6 +12,7 @@ * https://opensource.org/licenses/BSD-3-Clause */ #define _GNU_SOURCE /* asprintf, strdup */ +#define _DEFAULT_SOURCE /* fmodl */ #include "xpath.h" @@ -4098,6 +4099,29 @@ cleanup: return ret; } +/** + * @brief Get the module of an identity used in derived-from(-or-self)() functions. + * + * @param[in,out] qname Qualified node name. If includes prefix, it is skipped. + * @param[in,out] qname_len Length of @p qname, is updated accordingly. + * @param[in] set Set with general XPath context. + * @param[out] mod Module of the identity. + * @return LY_ERR + */ +static LY_ERR +xpath_derived_ident_module(const char **qname, uint32_t *qname_len, const struct lyxp_set *set, + const struct lys_module **mod) +{ + LY_CHECK_RET(moveto_resolve_model(qname, qname_len, set, set->cur_node ? set->cur_node->schema : NULL, mod)); + if (!*mod) { + /* unprefixed JSON identity */ + assert(set->format == LY_VALUE_JSON); + *mod = set->cur_mod; + } + + return LY_SUCCESS; +} + static LY_ERR xpath_derived_(struct lyxp_set **args, struct lyxp_set *set, uint32_t options, ly_bool self_match, const char *func) { @@ -4147,12 +4171,8 @@ xpath_derived_(struct lyxp_set **args, struct lyxp_set *set, uint32_t options, l /* parse the identity */ id_name = args[1]->val.str; id_len = strlen(id_name); - rc = moveto_resolve_model(&id_name, &id_len, set, set->cur_node ? set->cur_node->schema : NULL, &mod); + rc = xpath_derived_ident_module(&id_name, &id_len, set, &mod); LY_CHECK_RET(rc); - if (!mod) { - LOGVAL(set->ctx, LYVE_XPATH, "Identity \"%.*s\" without a prefix.", (int)id_len, id_name); - return LY_EVALID; - } /* find the identity */ found = 0; @@ -5631,14 +5651,14 @@ xpath_pi_text(struct lyxp_set *set, enum lyxp_axis axis, uint32_t options) } /** - * @brief Skip prefix and return corresponding model if there is a prefix. Logs directly. + * @brief Skip prefix and return corresponding model. Logs directly. * * XPath @p set is expected to be a (sc)node set! * * @param[in,out] qname Qualified node name. If includes prefix, it is skipped. * @param[in,out] qname_len Length of @p qname, is updated accordingly. * @param[in] set Set with general XPath context. - * @param[in] ctx_scnode Context node to inherit module for unprefixed node for ::LY_PREF_JSON. + * @param[in] ctx_scnode Current context schema node (parent). * @param[out] moveto_mod Expected module of a matching node. * @return LY_ERR */ @@ -5683,6 +5703,7 @@ moveto_resolve_model(const char **qname, uint32_t *qname_len, const struct lyxp_ if (ctx_scnode) { mod = ctx_scnode->module; } else { + /* JSON XPath is our own format (except for identityref), which supports node names matching all the modules */ mod = NULL; } break; @@ -7455,7 +7476,7 @@ moveto_op_math(struct lyxp_set *set1, struct lyxp_set *set2, const char *op) /* 'mod' */ case 'm': - set1->val.num = ((long long)set1->val.num) % ((long long)set2->val.num); + set1->val.num = fmodl(set1->val.num, set2->val.num); break; default: @@ -7677,7 +7698,7 @@ eval_name_test_try_compile_predicate_key(const char *nametest, uint32_t len, con /* prefix (module) */ LY_CHECK_RET(moveto_resolve_model(&nametest, &len, set, ctx_scnode, &mod)); - if (mod != key->module) { + if (mod && (mod != key->module)) { return LY_ENOT; } diff --git a/src/xpath.h b/src/xpath.h index 17bda6c..e5c3008 100644 --- a/src/xpath.h +++ b/src/xpath.h @@ -379,7 +379,7 @@ LY_ERR lyxp_atomize(const struct ly_ctx *ctx, const struct lyxp_expr *exp, const #define LYXP_SCNODE 0x04 /**< No special tree access modifiers. */ #define LYXP_SCNODE_SCHEMA LYS_FIND_XP_SCHEMA /**< Apply node access restrictions defined for 'when' and 'must' evaluation. */ #define LYXP_SCNODE_OUTPUT LYS_FIND_XP_OUTPUT /**< Search RPC/action output nodes instead of input ones. */ -#define LYXP_SCNODE_ALL 0x1C /**< mask for all the LYXP_* values */ +#define LYXP_SCNODE_ALL 0x1C /**< mask for all the LYXP_SCNODE_* values */ #define LYXP_SKIP_EXPR 0x20 /**< The rest of the expression will not be evaluated (lazy evaluation) */ #define LYXP_SCNODE_ERROR LYS_FIND_NO_MATCH_ERROR /**< Return error if a path segment matches no nodes, otherwise only warning is printed. */ diff --git a/tests/tool_i.tcl b/tests/tool_i.tcl index d0f3d4b..fa8c964 100644 --- a/tests/tool_i.tcl +++ b/tests/tool_i.tcl @@ -135,8 +135,7 @@ proc ly_completion {input output} { global prompt send -- "${input}\t" - # expecting echoing input, output and 10 terminal control characters - expect -re "^${input}\r${prompt}${output}.*\r.*$" + expect -re "${input}${output}" } # Send a completion request and check if the anchored regex hint options match. @@ -146,11 +145,13 @@ proc ly_hint {input prev_input hints} { set output {} foreach i $hints { # each element might have some number of spaces and CRLF around it - append output "${i} *(?:\\r\\n)?" + append output "${i} *(\\r\\n)?" } + set termcode1 "\r\\u001b\\\[0K" + set termcode2 ".*" send -- "${input}\t" # expecting the hints, previous input from which the hints were generated # and some number of terminal control characters - expect -re "${output}\r${prompt}${prev_input}.*\r.*$" + expect -re "${output}${termcode1}${prompt}${prev_input}${termcode2}" } diff --git a/tests/utests/basic/test_xpath.c b/tests/utests/basic/test_xpath.c index 7a2785b..80ac34a 100644 --- a/tests/utests/basic/test_xpath.c +++ b/tests/utests/basic/test_xpath.c @@ -65,6 +65,13 @@ const char *schema_a = " fraction-digits 5;\n" " }\n" " }\n" + " leaf foo5 {\n" + " type decimal64 {\n" + " fraction-digits 1;\n" + " range \"0.5 .. 99.5\";\n" + " }\n" + " must \"(. - 0.5) mod 0.5 = 0\";\n" + " }\n" " container c {\n" " leaf x {\n" " type string;\n" @@ -519,7 +526,7 @@ test_atomize(void **state) /* some random paths just making sure the API function works */ assert_int_equal(LY_SUCCESS, lys_find_xpath_atoms(UTEST_LYCTX, NULL, "/a:*", 0, &set)); - assert_int_equal(7, set->count); + assert_int_equal(8, set->count); ly_set_free(set, NULL); /* all nodes from all modules (including internal, which can change easily, so check just the test modules) */ @@ -536,7 +543,7 @@ test_atomize(void **state) ly_set_free(set, NULL); assert_int_equal(LY_SUCCESS, lys_find_xpath_atoms(UTEST_LYCTX, NULL, "/*", 0, &set)); - assert_int_equal(14, set->count); + assert_int_equal(15, set->count); ly_set_free(set, NULL); /* @@ -570,7 +577,7 @@ test_atomize(void **state) /* descendant-or-self */ assert_int_equal(LY_SUCCESS, lys_find_xpath_atoms(UTEST_LYCTX, NULL, "/a:*/descendant-or-self::c", 0, &set)); - assert_int_equal(8, set->count); + assert_int_equal(9, set->count); ly_set_free(set, NULL); /* following */ @@ -585,7 +592,7 @@ test_atomize(void **state) /* parent */ assert_int_equal(LY_SUCCESS, lys_find_xpath_atoms(UTEST_LYCTX, NULL, "/child::a:*/c/parent::l1", 0, &set)); - assert_int_equal(8, set->count); + assert_int_equal(9, set->count); ly_set_free(set, NULL); assert_int_equal(LY_SUCCESS, lys_find_xpath_atoms(UTEST_LYCTX, NULL, "/child::a:c//..", 0, &set)); @@ -1240,6 +1247,20 @@ test_trim(void **state) lyd_free_all(tree); } +static void +test_mod(void **state) +{ + const char *data; + struct lyd_node *tree; + + data = "10.5"; + + /* parse and validate */ + assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, &tree)); + assert_non_null(tree); + lyd_free_siblings(tree); +} + int main(void) { @@ -1257,6 +1278,7 @@ main(void) UTEST(test_variables, setup), UTEST(test_axes, setup), UTEST(test_trim, setup), + UTEST(test_mod, setup), }; return cmocka_run_group_tests(tests, NULL, NULL); diff --git a/tests/utests/data/test_new.c b/tests/utests/data/test_new.c index 7194893..47ecc19 100644 --- a/tests/utests/data/test_new.c +++ b/tests/utests/data/test_new.c @@ -353,6 +353,14 @@ test_path(void **state) assert_int_equal(ret, LY_SUCCESS); assert_non_null(node); + /* too high index */ + ret = lyd_new_path2(root, NULL, "/a:c2/l3[8]", NULL, 0, 0, 0, NULL, &node); + assert_int_equal(ret, LY_EINVAL); + CHECK_LOG_CTX("Cannot create \"l3\" on position 8, only 6 instances exist.", NULL, 0); + ret = lyd_new_path2(root, NULL, "/a:l2[2]", NULL, 0, 0, 0, NULL, &node); + assert_int_equal(ret, LY_EINVAL); + CHECK_LOG_CTX("Cannot create \"l2\" on position 2, no instances exist.", NULL, 0); + lyd_print_mem(&str, root, LYD_XML, LYD_PRINT_WITHSIBLINGS); assert_string_equal(str, "\n" diff --git a/tests/utests/data/test_tree_data_sorted.c b/tests/utests/data/test_tree_data_sorted.c index bb6e4d6..9f11878 100644 --- a/tests/utests/data/test_tree_data_sorted.c +++ b/tests/utests/data/test_tree_data_sorted.c @@ -1605,21 +1605,22 @@ test_order_violation(void **state) UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, &mod); /* inserting a new node causes the nodes to be sorted */ - data = "{\"a:ll\":[1,8,2]}"; + data = "{\"a:ll\":[8,2,1]}"; CHECK_PARSE_LYD_PARAM(data, LYD_JSON, LYD_PARSE_ORDERED, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree); - assert_true(tree && !tree->meta && tree->next && tree->next->next); - assert_string_equal(lyd_get_value(tree), "1"); - assert_string_equal(lyd_get_value(tree->next), "8"); - assert_string_equal(lyd_get_value(tree->next->next), "2"); #ifndef NDEBUG CHECK_LOG_CTX("Data in \"ll\" are not sorted, inserted node should not be added to the end.", NULL, 0); + CHECK_LOG_CTX("Data in \"ll\" are not sorted, inserted node should not be added to the end.", NULL, 0); #endif - assert_int_equal(lyd_new_term(NULL, mod, "ll", "3", 0, &node), LY_SUCCESS); - lyd_insert_sibling(tree, node, NULL); - assert_string_equal(lyd_get_value(tree), "1"); + assert_true(tree && !tree->meta && tree->next && tree->next->next); + assert_string_equal(lyd_get_value(tree), "8"); assert_string_equal(lyd_get_value(tree->next), "2"); - assert_string_equal(lyd_get_value(tree->next->next), "3"); - assert_string_equal(lyd_get_value(tree->next->next->next), "8"); + assert_string_equal(lyd_get_value(tree->next->next), "1"); + assert_int_equal(lyd_new_term(NULL, mod, "ll", "3", 0, &node), LY_SUCCESS); + lyd_insert_sibling(tree, node, &first); + assert_string_equal(lyd_get_value(first), "1"); + assert_string_equal(lyd_get_value(first->next), "2"); + assert_string_equal(lyd_get_value(first->next->next), "3"); + assert_string_equal(lyd_get_value(first->next->next->next), "8"); lyd_free_all(tree); /* move unsorted nodes causes the nodes to be sorted */ diff --git a/tests/utests/data/test_validation.c b/tests/utests/data/test_validation.c index 17fd078..4a505fe 100644 --- a/tests/utests/data/test_validation.c +++ b/tests/utests/data/test_validation.c @@ -163,6 +163,37 @@ test_type_incomplete_when(void **state) lyd_free_all(tree); } +static void +test_unprefixed_ident(void **state) +{ + struct lyd_node *tree; + const char *schema = + "module a {\n" + " namespace urn:tests:a;\n" + " prefix a;\n" + " yang-version 1.1;\n" + "\n" + " identity d3 {base d2;}\n" + " identity d2 {base d1;}\n" + " identity d1;\n" + "\n" + " leaf a {type identityref {base d1;}}\n" + " leaf b {type string; must \"derived-from-or-self(/a, 'd2')\";}\n" + " leaf c {type string; when \"derived-from(/a, 'd2')\";}\n" + "}"; + + UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL); + + CHECK_PARSE_LYD_PARAM("hey", LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree); + CHECK_LOG_CTX("Must condition \"derived-from-or-self(/a, 'd2')\" not satisfied.", "/a:b", 0); + + CHECK_PARSE_LYD_PARAM("hey", LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree); + CHECK_LOG_CTX("When condition \"derived-from(/a, 'd2')\" not satisfied.", "/a:c", 0); + + LYD_TREE_CREATE("d3b-valc-val", tree); + lyd_free_all(tree); +} + static void test_mandatory(void **state) { @@ -1515,6 +1546,20 @@ test_case(void **state) CHECK_LOG_CTX("Data for both cases \"v0\" and \"v2\" exist.", "/k:ch", 6); } +static void +test_pattern(void **UNUSED(state)) +{ + pcre2_code *pcode = NULL; + + assert_int_equal(ly_pattern_match(NULL, "a.b.c", "abc", 0, NULL), LY_ENOT); + assert_int_equal(ly_pattern_match(NULL, "a.b.c", "a0b1c", 0, NULL), LY_SUCCESS); + + assert_int_equal(ly_pattern_match(NULL, "a.b.c", "abc", 0, &pcode), LY_ENOT); + assert_int_equal(ly_pattern_match(NULL, NULL, "a0b1c", 0, &pcode), LY_SUCCESS); + + pcre2_code_free(pcode); +} + int main(void) { @@ -1523,6 +1568,7 @@ main(void) UTEST(test_mandatory), UTEST(test_mandatory_when), UTEST(test_type_incomplete_when), + UTEST(test_unprefixed_ident), UTEST(test_minmax), UTEST(test_unique), UTEST(test_unique_nested), @@ -1535,6 +1581,7 @@ main(void) UTEST(test_rpc), UTEST(test_reply), UTEST(test_case), + UTEST(test_pattern), }; return cmocka_run_group_tests(tests, NULL, NULL); diff --git a/tests/yanglint/CMakeLists.txt b/tests/yanglint/CMakeLists.txt index c1e081a..144ba0c 100644 --- a/tests/yanglint/CMakeLists.txt +++ b/tests/yanglint/CMakeLists.txt @@ -1,4 +1,4 @@ -if(WIN32) +if(WIN32 OR NOT ENABLE_YANGLINT_INTERACTIVE) set(YANGLINT_INTERACTIVE OFF) else() set(YANGLINT_INTERACTIVE ON) diff --git a/tests/yanglint/interactive/completion.test b/tests/yanglint/interactive/completion.test index 86ded1f..27fd526 100644 --- a/tests/yanglint/interactive/completion.test +++ b/tests/yanglint/interactive/completion.test @@ -12,14 +12,15 @@ test completion_hints_ietf_ip {Completion and hints for ietf-ip.yang} { ly_cmd "add $mdir/ietf-ip.yang" # completion and hint - ly_completion "print -f info -P " "print -f info -P /ietf-" + ly_completion "print -f info -P " "/ietf-" set hints {"/ietf-yang-schema-mount:schema-mounts" "/ietf-interfaces:interfaces" "/ietf-interfaces:interfaces-state"} ly_hint "" "print -f info -P /ietf-" $hints # double completion - ly_completion "i" "print -f info -P /ietf-interfaces:interfaces" - ly_completion "/" "print -f info -P /ietf-interfaces:interfaces/interface" + ly_completion "i" "nterfaces:interfaces" + ly_completion "/" "interface" + # current cli: print -f info -P /ietf-interfaces:interfaces/interface # a lot of hints set hints {"/ietf-interfaces:interfaces/interface" @@ -31,16 +32,20 @@ test completion_hints_ietf_ip {Completion and hints for ietf-ip.yang} { ly_hint "" "print -f info -P /ietf-interfaces:interfaces/interface" $hints # double tab - ly_completion "/i" "print -f info -P /ietf-interfaces:interfaces/interface/ietf-ip:ipv" - ly_completion "4" "print -f info -P /ietf-interfaces:interfaces/interface/ietf-ip:ipv4" + ly_completion "/i" "etf-ip:ipv" + # current cli: print -f info -P /ietf-interfaces:interfaces/interface/ietf-ip:ipv + ly_completion "4" "" + # current cli: print -f info -P /ietf-interfaces:interfaces/interface/ietf-ip:ipv4 + set hints { "/ietf-interfaces:interfaces/interface/ietf-ip:ipv4" "/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/enabled" "/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/forwarding" "/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/mtu" "/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/address" "/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/neighbor" } - ly_hint "\t" "print -f info -P /ietf-interfaces:interfaces/interface/ietf-ip:ipv" $hints + ly_hint "\t" "print -f info -P /ietf-interfaces:interfaces/interface" $hints # no more completion - ly_completion "/e" "print -f info -P /ietf-interfaces:interfaces/interface/ietf-ip:ipv4/enabled " + ly_completion "/e" "nabled " + # current cli: print -f info -P /ietf-interfaces:interfaces/interface/ietf-ip:ipv4/enabled }} # Note that somehow a command is automatically sent again (\t\t replaced by \r) after the hints. diff --git a/tools/lint/CMakeLists.txt b/tools/lint/CMakeLists.txt index 059305e..42d4309 100644 --- a/tools/lint/CMakeLists.txt +++ b/tools/lint/CMakeLists.txt @@ -24,7 +24,8 @@ if(ENABLE_YANGLINT_INTERACTIVE) main.c completion.c configuration.c - linenoise/linenoise.c) + linenoise/linenoise.c + linenoise/utf8.c) else() set(lintsrc ${lintsrc} main_ni_only.c) diff --git a/tools/lint/completion.c b/tools/lint/completion.c index 3c7503e..f4faeba 100644 --- a/tools/lint/completion.c +++ b/tools/lint/completion.c @@ -15,11 +15,13 @@ #define _GNU_SOURCE #define _POSIX_C_SOURCE 200809L /* strdup */ +#include #include #include #include #include #include +#include #include "libyang.h" @@ -28,6 +30,70 @@ #include "compat.h" #include "linenoise/linenoise.h" +/** + * @brief Fill path completion. + * + * @param[in] hint Path to directory. + * @param[in] lc For adding completions. + */ +static void +path_completion(const char *hint, linenoiseCompletions *lc) +{ + const char *ptr; + char *full_path, *hint_ptr, match[FILENAME_MAX + 2]; + DIR *dir; + struct dirent *ent; + struct stat st; + + lc->path = 1; + + ptr = strrchr(hint, '/'); + + /* new relative path */ + if (ptr == NULL) { + full_path = malloc(2 + FILENAME_MAX + 1); + strcpy(full_path, "./"); + + ptr = hint; + } else { + full_path = malloc((int)(ptr - hint) + FILENAME_MAX + 1); + ++ptr; + sprintf(full_path, "%.*s", (int)(ptr - hint), hint); + } + hint_ptr = full_path + strlen(full_path); + + dir = opendir(full_path); + if (dir == NULL) { + free(full_path); + return; + } + + while ((ent = readdir(dir))) { + if (ent->d_name[0] == '.') { + continue; + } + + if (!strncmp(ptr, ent->d_name, strlen(ptr))) { + /* is it a directory? */ + strcpy(hint_ptr, ent->d_name); + if (stat(full_path, &st)) { + /* skip this item */ + continue; + } + + strcpy(match, ent->d_name); + if (S_ISDIR(st.st_mode)) { + strcat(match, "/"); + } + + linenoiseAddCompletion(lc, match); + } + } + + free(full_path); + closedir(dir); +} + /* from the main.c */ extern struct ly_ctx *ctx; @@ -430,29 +496,28 @@ complete_cmd(const char *buf, const char *hint, linenoiseCompletions *lc) struct autocomplete { enum COMMAND_INDEX ci; /**< command index to global variable 'commands' */ const char *opt; /**< optional option */ - void (*ln_cb)(const char *, const char *, linenoiseCompletions *); /**< linenoise callback to call */ - void (*yl_cb)(const char *, char ***, unsigned int *); /**< yanglint callback to call */ + void (*yl_cb)(const char *, char ***, unsigned int *); /**< yanglint callback to call */ } ac[] = { - {CMD_ADD, NULL, linenoisePathCompletion, NULL}, - {CMD_PRINT, "-f", NULL, get_print_format_arg}, - {CMD_PRINT, "-P", NULL, get_schema_completion}, - {CMD_PRINT, "-o", linenoisePathCompletion, NULL}, - {CMD_PRINT, NULL, NULL, get_model_completion}, - {CMD_SEARCHPATH, NULL, linenoisePathCompletion, NULL}, - {CMD_EXTDATA, NULL, linenoisePathCompletion, NULL}, - {CMD_CLEAR, "-Y", linenoisePathCompletion, NULL}, - {CMD_DATA, "-t", NULL, get_data_type_arg}, - {CMD_DATA, "-O", linenoisePathCompletion, NULL}, - {CMD_DATA, "-R", linenoisePathCompletion, NULL}, - {CMD_DATA, "-f", NULL, get_data_in_format_arg}, - {CMD_DATA, "-F", NULL, get_data_in_format_arg}, - {CMD_DATA, "-d", NULL, get_data_default_arg}, - {CMD_DATA, "-o", linenoisePathCompletion, NULL}, - {CMD_DATA, NULL, linenoisePathCompletion, NULL}, - {CMD_LIST, NULL, NULL, get_list_format_arg}, - {CMD_FEATURE, NULL, NULL, get_model_completion}, - {CMD_VERB, NULL, NULL, get_verb_arg}, - {CMD_DEBUG, NULL, NULL, get_debug_arg}, + {CMD_ADD, NULL, NULL}, + {CMD_PRINT, "-f", get_print_format_arg}, + {CMD_PRINT, "-P", get_schema_completion}, + {CMD_PRINT, "-o", NULL}, + {CMD_PRINT, NULL, get_model_completion}, + {CMD_SEARCHPATH, NULL, NULL}, + {CMD_EXTDATA, NULL, NULL}, + {CMD_CLEAR, "-Y", NULL}, + {CMD_DATA, "-t", get_data_type_arg}, + {CMD_DATA, "-O", NULL}, + {CMD_DATA, "-R", NULL}, + {CMD_DATA, "-f", get_data_in_format_arg}, + {CMD_DATA, "-F", get_data_in_format_arg}, + {CMD_DATA, "-d", get_data_default_arg}, + {CMD_DATA, "-o", NULL}, + {CMD_DATA, NULL, NULL}, + {CMD_LIST, NULL, get_list_format_arg}, + {CMD_FEATURE, NULL, get_model_completion}, + {CMD_VERB, NULL, get_verb_arg}, + {CMD_DEBUG, NULL, get_debug_arg}, }; size_t name_len; const char *last, *name, *getoptstr; @@ -490,10 +555,10 @@ complete_cmd(const char *buf, const char *hint, linenoiseCompletions *lc) } /* callback */ - if (ac[i].ln_cb) { - ac[i].ln_cb(buf, hint, lc); - } else { + if (ac[i].yl_cb) { ac[i].yl_cb(hint, &matches, &match_count); + } else { + path_completion(hint, lc); } break; } diff --git a/tools/lint/linenoise/linenoise.c b/tools/lint/linenoise/linenoise.c index fed3d26..15bdad3 100644 --- a/tools/lint/linenoise/linenoise.c +++ b/tools/lint/linenoise/linenoise.c @@ -77,7 +77,7 @@ * * DSR (Device Status Report) * Sequence: ESC [ 6 n - * Effect: reports the current cusor position as ESC [ n ; m R + * Effect: reports the current cursor position as ESC [ n ; m R * where n is the row and m is the column * * When multi line mode is enabled, we also use an additional escape @@ -122,23 +122,27 @@ #include #include +#include "compat.h" + #define LINENOISE_DEFAULT_HISTORY_MAX_LEN 100 #define LINENOISE_MAX_LINE 4096 static char *unsupported_term[] = {"dumb","cons25","emacs",NULL}; static linenoiseCompletionCallback *completionCallback = NULL; +static linenoiseHintsCallback *hintsCallback = NULL; +static linenoiseFreeHintsCallback *freeHintsCallback = NULL; +static char *linenoiseNoTTY(void); +static void refreshLineWithCompletion(struct linenoiseState *ls, linenoiseCompletions *lc, int flags); +static void refreshLineWithFlags(struct linenoiseState *l, int flags); static struct termios orig_termios; /* In order to restore at exit.*/ +static int maskmode = 0; /* Show "***" instead of input. For passwords. */ +static int rawmode = 0; /* For atexit() function to check if restore is needed*/ static int mlmode = 0; /* Multi line mode. Default is single line. */ static int atexit_registered = 0; /* Register atexit just 1 time. */ static int history_max_len = LINENOISE_DEFAULT_HISTORY_MAX_LEN; static int history_len = 0; static char **history = NULL; -/* The linenoiseState structure represents the state during line editing. - * We pass this state to functions implementing specific editing - * functionalities. */ -struct linenoiseState lss; - enum KEY_ACTION{ KEY_NULL = 0, /* NULL */ CTRL_A = 1, /* Ctrl+a */ @@ -163,6 +167,10 @@ enum KEY_ACTION{ static void linenoiseAtExit(void); int linenoiseHistoryAdd(const char *line); +#define REFRESH_CLEAN (1<<0) // Clean the old prompt from the screen +#define REFRESH_WRITE (1<<1) // Rewrite the prompt on the screen. +#define REFRESH_ALL (REFRESH_CLEAN|REFRESH_WRITE) // Do both. +static void refreshLine(struct linenoiseState *l); /* Debugging macro. */ #if 0 @@ -174,7 +182,7 @@ FILE *lndebug_fp = NULL; fprintf(lndebug_fp, \ "[%d %d %d] p: %d, rows: %d, rpos: %d, max: %d, oldmax: %d\n", \ (int)l->len,(int)l->pos,(int)l->oldpos,plen,rows,rpos, \ - (int)l->maxrows,old_rows); \ + (int)l->oldrows,old_rows); \ } \ fprintf(lndebug_fp, ", " __VA_ARGS__); \ fflush(lndebug_fp); \ @@ -183,8 +191,100 @@ FILE *lndebug_fp = NULL; #define lndebug(...) #endif +/* ========================== Encoding functions ============================= */ + +/* Get byte length and column length of the previous character */ +static size_t defaultPrevCharLen(const char *UNUSED(buf), size_t UNUSED(buf_len), size_t UNUSED(pos), size_t *col_len) { + if (col_len != NULL) *col_len = 1; + return 1; +} + +/* Get byte length and column length of the next character */ +static size_t defaultNextCharLen(const char *UNUSED(buf), size_t UNUSED(buf_len), size_t UNUSED(pos), size_t *col_len) { + if (col_len != NULL) *col_len = 1; + return 1; +} + +/* Read bytes of the next character */ +static size_t defaultReadCode(int fd, char *buf, size_t buf_len, int* c) { + if (buf_len < 1) return -1; + int nread = read(fd,&buf[0],1); + if (nread == 1) *c = buf[0]; + return nread; +} + +/* Set default encoding functions */ +static linenoisePrevCharLen *prevCharLen = defaultPrevCharLen; +static linenoiseNextCharLen *nextCharLen = defaultNextCharLen; +static linenoiseReadCode *readCode = defaultReadCode; + +/* Set used defined encoding functions */ +void linenoiseSetEncodingFunctions( + linenoisePrevCharLen *prevCharLenFunc, + linenoiseNextCharLen *nextCharLenFunc, + linenoiseReadCode *readCodeFunc) { + prevCharLen = prevCharLenFunc; + nextCharLen = nextCharLenFunc; + readCode = readCodeFunc; +} + +/* Get column length from begining of buffer to current byte position */ +static size_t columnPos(const char *buf, size_t buf_len, size_t pos) { + size_t ret = 0; + size_t off = 0; + while (off < pos) { + size_t col_len; + size_t len = nextCharLen(buf,buf_len,off,&col_len); + off += len; + ret += col_len; + } + return ret; +} + +/* Get column length from begining of buffer to current byte position for multiline mode*/ +static size_t columnPosForMultiLine(const char *buf, size_t buf_len, size_t pos, size_t cols, size_t ini_pos) { + size_t ret = 0; + size_t colwid = ini_pos; + size_t len; + + size_t off = 0; + while (off < buf_len) { + size_t col_len; + len = nextCharLen(buf,buf_len,off,&col_len); + + int dif = (int)(colwid + col_len) - (int)cols; + if (dif > 0) { + ret += dif; + colwid = col_len; + } else if (dif == 0) { + colwid = 0; + } else { + colwid += col_len; + } + + if (off >= pos) break; + off += len; + ret += col_len; + } + + return ret; +} + /* ======================= Low level terminal handling ====================== */ +/* Enable "mask mode". When it is enabled, instead of the input that + * the user is typing, the terminal will just display a corresponding + * number of asterisks, like "****". This is useful for passwords and other + * secrets that should not be displayed. */ +void linenoiseMaskModeEnable(void) { + maskmode = 1; +} + +/* Disable mask mode. */ +void linenoiseMaskModeDisable(void) { + maskmode = 0; +} + /* Set if to use or not the multi line mode. */ void linenoiseSetMultiLine(int ml) { mlmode = ml; @@ -203,7 +303,7 @@ static int isUnsupportedTerm(void) { } /* Raw mode: 1960 magic shit. */ -int linenoiseEnableRawMode(int fd) { +int enableRawMode(int fd) { struct termios raw; if (!isatty(STDIN_FILENO)) goto fatal; @@ -230,7 +330,7 @@ int linenoiseEnableRawMode(int fd) { /* put terminal in raw mode after flushing */ if (tcsetattr(fd,TCSAFLUSH,&raw) < 0) goto fatal; - lss.rawmode = 1; + rawmode = 1; return 0; fatal: @@ -238,10 +338,10 @@ fatal: return -1; } -void linenoiseDisableRawMode(int fd) { +static void disableRawMode(int fd) { /* Don't even check the return value as it's too late. */ - if (lss.rawmode && tcsetattr(fd,TCSAFLUSH,&orig_termios) != -1) - lss.rawmode = 0; + if (rawmode && tcsetattr(fd,TCSAFLUSH,&orig_termios) != -1) + rawmode = 0; } /* Use the ESC [6n escape sequence to query the horizontal cursor position @@ -320,26 +420,8 @@ static void linenoiseBeep(void) { /* ============================== Completion ================================ */ -/* Free a list of completion option populated by linenoiseAddCompletion(). */ -static void freeCompletions(linenoiseCompletions *lc) { - size_t i; - for (i = 0; i < lc->len; i++) - free(lc->cvec[i]); - if (lc->cvec != NULL) - free(lc->cvec); -} - -/* This is an helper function for linenoiseEdit() and is called when the - * user types the key in order to complete the string currently in the - * input. - * - * The state of the editing is encapsulated into the pointed linenoiseState - * structure as described in the structure definition. */ -static char completeLine(struct linenoiseState *ls) { - linenoiseCompletions lc = {0, 0, NULL}; - int nread, nwritten, hint_len, hint_line_count, char_count; - char c = 0, *common, *hint; - struct winsize w; +static char *get_last_string(struct linenoiseState *ls) { + char *hint; /* Hint is only the string after the last space */ hint = strrchr(ls->buf, ' '); @@ -349,10 +431,77 @@ static char completeLine(struct linenoiseState *ls) { ++hint; } + return hint; +} + +/* Free a list of completion option populated by linenoiseAddCompletion(). */ +static void freeCompletions(linenoiseCompletions *lc) { + size_t i; + for (i = 0; i < lc->len; i++) + free(lc->cvec[i]); + if (lc->cvec != NULL) + free(lc->cvec); +} + +/* Called by completeLine() and linenoiseShow() to render the current + * edited line with the proposed completion. If the current completion table + * is already available, it is passed as second argument, otherwise the + * function will use the callback to obtain it. + * + * Flags are the same as refreshLine*(), that is REFRESH_* macros. */ +static void refreshLineWithCompletion(struct linenoiseState *ls, linenoiseCompletions *lc, int flags) { + /* Obtain the table of completions if the caller didn't provide one. */ + linenoiseCompletions ctable = {0, 0, NULL}; + if (lc == NULL) { + completionCallback(ls->buf, get_last_string(ls), &ctable); + lc = &ctable; + } + + /* Show the edited line with completion if possible, or just refresh. */ + if (ls->completion_idx < lc->len) { + struct linenoiseState saved = *ls; + ls->len = ls->pos = strlen(lc->cvec[ls->completion_idx]); + ls->buf = lc->cvec[ls->completion_idx]; + refreshLineWithFlags(ls,flags); + ls->len = saved.len; + ls->pos = saved.pos; + ls->buf = saved.buf; + } else { + refreshLineWithFlags(ls,flags); + } + + /* Free the completions table if needed. */ + if (lc != &ctable) freeCompletions(&ctable); +} + +/* This is an helper function for linenoiseEdit*() and is called when the + * user types the key in order to complete the string currently in the + * input. + * + * The state of the editing is encapsulated into the pointed linenoiseState + * structure as described in the structure definition. + * + * If the function returns non-zero, the caller should handle the + * returned value as a byte read from the standard input, and process + * it as usually: this basically means that the function may return a byte + * read from the terminal but not processed. Otherwise, if zero is returned, + * the input was consumed by the completeLine() function to navigate the + * possible completions, and the caller should read for the next characters + * from stdin. */ +static char completeLine(struct linenoiseState *ls, int keypressed) { + (void) keypressed; + linenoiseCompletions lc = {0, 0, NULL}; + int nread, nwritten, hint_len, hint_line_count, char_count; + char c = 0, *common, *hint; + struct winsize w; + + hint = get_last_string(ls); completionCallback(ls->buf, hint, &lc); if (lc.len == 0) { linenoiseBeep(); + ls->in_completion = 0; } else { + /* This block of code was inserted for the special features of yanglint */ unsigned int i, j; /* Learn the longest common part */ @@ -380,7 +529,7 @@ static char completeLine(struct linenoiseState *ls) { } free(common); ls->len = ls->pos = (hint - ls->buf) + nwritten; - linenoiseRefreshLine(); + refreshLine(ls); /* A single hint */ if (lc.len == 1) { @@ -429,7 +578,7 @@ static char completeLine(struct linenoiseState *ls) { while (c == 9) { /* Second tab */ - linenoiseDisableRawMode(ls->ifd); + disableRawMode(ls->ifd); printf("\n"); for (i = 0; i < lc.len; ++i) { printf("%-*s", hint_len, lc.cvec[i]); @@ -440,8 +589,8 @@ static char completeLine(struct linenoiseState *ls) { printf(" "); } } - linenoiseEnableRawMode(ls->ifd); - linenoiseRefreshLine(); + enableRawMode(ls->ifd); + refreshLine(ls); /* Read a char */ nread = read(ls->ifd,&c,1); @@ -461,65 +610,16 @@ void linenoiseSetCompletionCallback(linenoiseCompletionCallback *fn) { completionCallback = fn; } -/* This function can be called in user completion callback to fill - * path completion for them. hint parameter is actually the whole path - * and buf is unused, but included to match the completion callback prototype. */ -void linenoisePathCompletion(const char *buf, const char *hint, linenoiseCompletions *lc) { - const char *ptr; - char *full_path, *hint_ptr, match[FILENAME_MAX + 2]; - DIR *dir; - struct dirent *ent; - struct stat st; +/* Register a hits function to be called to show hits to the user at the + * right of the prompt. */ +void linenoiseSetHintsCallback(linenoiseHintsCallback *fn) { + hintsCallback = fn; +} - (void)buf; - - lc->path = 1; - - ptr = strrchr(hint, '/'); - - /* new relative path */ - if (ptr == NULL) { - full_path = malloc(2 + FILENAME_MAX + 1); - strcpy(full_path, "./"); - - ptr = hint; - } else { - full_path = malloc((int)(ptr - hint) + FILENAME_MAX + 1); - ++ptr; - sprintf(full_path, "%.*s", (int)(ptr - hint), hint); - } - hint_ptr = full_path + strlen(full_path); - - dir = opendir(full_path); - if (dir == NULL) { - free(full_path); - return; - } - - while ((ent = readdir(dir))) { - if (ent->d_name[0] == '.') { - continue; - } - - if (!strncmp(ptr, ent->d_name, strlen(ptr))) { - /* is it a directory? */ - strcpy(hint_ptr, ent->d_name); - if (stat(full_path, &st)) { - /* skip this item */ - continue; - } - - strcpy(match, ent->d_name); - if (S_ISDIR(st.st_mode)) { - strcat(match, "/"); - } - - linenoiseAddCompletion(lc, match); - } - } - - free(full_path); - closedir(dir); +/* Register a function to free the hints returned by the hints callback + * registered with linenoiseSetHintsCallback(). */ +void linenoiseSetFreeHintsCallback(linenoiseFreeHintsCallback *fn) { + freeHintsCallback = fn; } /* This function is used by the callback function registered by the user @@ -571,41 +671,121 @@ static void abFree(struct abuf *ab) { free(ab->b); } +/* Helper of refreshSingleLine() and refreshMultiLine() to show hints + * to the right of the prompt. */ +void refreshShowHints(struct abuf *ab, struct linenoiseState *l, int pcollen) { + char seq[64]; + size_t collen = pcollen+columnPos(l->buf,l->len,l->len); + if (hintsCallback && collen < l->cols) { + int color = -1, bold = 0; + char *hint = hintsCallback(l->buf,&color,&bold); + if (hint) { + int hintlen = strlen(hint); + int hintmaxlen = l->cols-collen; + if (hintlen > hintmaxlen) hintlen = hintmaxlen; + if (bold == 1 && color == -1) color = 37; + if (color != -1 || bold != 0) + snprintf(seq,64,"\033[%d;%d;49m",bold,color); + else + seq[0] = '\0'; + abAppend(ab,seq,strlen(seq)); + abAppend(ab,hint,hintlen); + if (color != -1 || bold != 0) + abAppend(ab,"\033[0m",4); + /* Call the function to free the hint returned. */ + if (freeHintsCallback) freeHintsCallback(hint); + } + } +} + +/* Check if text is an ANSI escape sequence + */ +static int isAnsiEscape(const char *buf, size_t buf_len, size_t* len) { + if (buf_len > 2 && !memcmp("\033[", buf, 2)) { + size_t off = 2; + while (off < buf_len) { + switch (buf[off++]) { + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'J': case 'K': + case 'S': case 'T': case 'f': case 'm': + *len = off; + return 1; + } + } + } + return 0; +} + +/* Get column length of prompt text + */ +static size_t promptTextColumnLen(const char *prompt, size_t plen) { + char buf[LINENOISE_MAX_LINE]; + size_t buf_len = 0; + size_t off = 0; + while (off < plen) { + size_t len; + if (isAnsiEscape(prompt + off, plen - off, &len)) { + off += len; + continue; + } + buf[buf_len++] = prompt[off++]; + } + return columnPos(buf,buf_len,buf_len); +} + /* Single line low level line refresh. * * Rewrite the currently edited line accordingly to the buffer content, - * cursor position, and number of columns of the terminal. */ -static void refreshSingleLine(struct linenoiseState *l) { + * cursor position, and number of columns of the terminal. + * + * Flags is REFRESH_* macros. The function can just remove the old + * prompt, just write it, or both. */ +static void refreshSingleLine(struct linenoiseState *l, int flags) { char seq[64]; - size_t plen = strlen(l->prompt); + size_t pcollen = promptTextColumnLen(l->prompt,strlen(l->prompt)); int fd = l->ofd; char *buf = l->buf; size_t len = l->len; size_t pos = l->pos; struct abuf ab; - while((plen+pos) >= l->cols) { - buf++; - len--; - pos--; + while((pcollen+columnPos(buf,len,pos)) >= l->cols) { + int chlen = nextCharLen(buf,len,0,NULL); + buf += chlen; + len -= chlen; + pos -= chlen; } - while (plen+len > l->cols) { - len--; + while (pcollen+columnPos(buf,len,len) > l->cols) { + len -= prevCharLen(buf,len,len,NULL); } abInit(&ab); /* Cursor to left edge */ - snprintf(seq,64,"\r"); + snprintf(seq,sizeof(seq),"\r"); abAppend(&ab,seq,strlen(seq)); - /* Write the prompt and the current buffer content */ - abAppend(&ab,l->prompt,strlen(l->prompt)); - abAppend(&ab,buf,len); + + if (flags & REFRESH_WRITE) { + /* Write the prompt and the current buffer content */ + abAppend(&ab,l->prompt,strlen(l->prompt)); + if (maskmode == 1) { + while (len--) abAppend(&ab,"*",1); + } else { + abAppend(&ab,buf,len); + } + /* Show hits if any. */ + refreshShowHints(&ab,l,pcollen); + } + /* Erase to right */ - snprintf(seq,64,"\x1b[0K"); - abAppend(&ab,seq,strlen(seq)); - /* Move cursor to original position. */ - snprintf(seq,64,"\r\x1b[%dC", (int)(pos+plen)); + snprintf(seq,sizeof(seq),"\x1b[0K"); abAppend(&ab,seq,strlen(seq)); + + if (flags & REFRESH_WRITE) { + /* Move cursor to original position. */ + snprintf(seq,sizeof(seq),"\r\x1b[%dC", (int)(columnPos(buf,len,pos)+pcollen)); + abAppend(&ab,seq,strlen(seq)); + } + if (write(fd,ab.b,ab.len) == -1) {} /* Can't recover from write error. */ abFree(&ab); } @@ -613,82 +793,123 @@ static void refreshSingleLine(struct linenoiseState *l) { /* Multi line low level line refresh. * * Rewrite the currently edited line accordingly to the buffer content, - * cursor position, and number of columns of the terminal. */ -static void refreshMultiLine(struct linenoiseState *l) { + * cursor position, and number of columns of the terminal. + * + * Flags is REFRESH_* macros. The function can just remove the old + * prompt, just write it, or both. */ +static void refreshMultiLine(struct linenoiseState *l, int flags) { char seq[64]; - int plen = strlen(l->prompt); - int rows = (plen+l->len+l->cols-1)/l->cols; /* rows used by current buf. */ - int rpos = (plen+l->oldpos+l->cols)/l->cols; /* cursor relative row. */ + size_t pcollen = promptTextColumnLen(l->prompt,strlen(l->prompt)); + size_t colpos = columnPosForMultiLine(l->buf, l->len, l->len, l->cols, pcollen); + int colpos2; /* cursor column position. */ + int rows = (pcollen+colpos+l->cols-1)/l->cols; /* rows used by current buf. */ + int rpos = (pcollen+l->oldcolpos+l->cols)/l->cols; /* cursor relative row. */ int rpos2; /* rpos after refresh. */ - int col; /* colum position, zero-based. */ - int old_rows = l->maxrows; + int col; /* column position, zero-based. */ + int old_rows = l->oldrows; int fd = l->ofd, j; struct abuf ab; - /* Update maxrows if needed. */ - if (rows > (int)l->maxrows) l->maxrows = rows; + l->oldrows = rows; /* First step: clear all the lines used before. To do so start by * going to the last row. */ abInit(&ab); - if (old_rows-rpos > 0) { - lndebug("go down %d", old_rows-rpos); - snprintf(seq,64,"\x1b[%dB", old_rows-rpos); + + if ((l->oldcollen < l->len) && // some character was added + (l->pos == l->len) && // at the end of the line + (l->pos <= l->cols) && // no multiline break + (l->prev_history_index == l->history_index) // no buffer change based on history + ) { + /* Ignore flags and just add one character. + * This code was added because redundant ANSI escape codes make tcl-tests incapable. + */ + abAppend(&ab,l->buf + l->oldcollen,strlen(l->buf) - l->oldcollen); + l->oldcolpos = colpos; + l->oldcollen = l->len; + if (write(fd,ab.b,ab.len) == -1) {} /* Can't recover from write error. */ + abFree(&ab); + l->prev_history_index = l->history_index; + return; + } + + if (flags & REFRESH_CLEAN) { + if (old_rows-rpos > 0) { + lndebug("go down %d", old_rows-rpos); + snprintf(seq,64,"\x1b[%dB", old_rows-rpos); + abAppend(&ab,seq,strlen(seq)); + } + + /* Now for every row clear it, go up. */ + for (j = 0; j < old_rows-1; j++) { + lndebug("clear+up"); + snprintf(seq,64,"\r\x1b[0K\x1b[1A"); + abAppend(&ab,seq,strlen(seq)); + } + } + + if (flags & REFRESH_ALL) { + /* Clean the top line. */ + lndebug("clear"); + snprintf(seq,64,"\r\x1b[0K"); abAppend(&ab,seq,strlen(seq)); } - /* Now for every row clear it, go up. */ - for (j = 0; j < old_rows-1; j++) { - lndebug("clear+up"); - snprintf(seq,64,"\r\x1b[0K\x1b[1A"); + /* Get column length to cursor position */ + colpos2 = columnPosForMultiLine(l->buf,l->len,l->pos,l->cols,pcollen); + + if (flags & REFRESH_WRITE) { + /* Write the prompt and the current buffer content */ + abAppend(&ab,l->prompt,strlen(l->prompt)); + if (maskmode == 1) { + unsigned int i; + for (i = 0; i < l->len; i++) abAppend(&ab,"*",1); + } else { + abAppend(&ab,l->buf,l->len); + } + + /* Show hits if any. */ + refreshShowHints(&ab,l,pcollen); + + /* If we are at the very end of the screen with our prompt, we need to + * emit a newline and move the prompt to the first column. */ + if (l->pos && + l->pos == l->len && + (colpos2+pcollen) % l->cols == 0) + { + lndebug(""); + abAppend(&ab,"\n",1); + snprintf(seq,64,"\r"); + abAppend(&ab,seq,strlen(seq)); + rows++; + if (rows > (int)l->oldrows) l->oldrows = rows; + } + + /* Move cursor to right position. */ + rpos2 = (pcollen+colpos2+l->cols)/l->cols; /* Current cursor relative row */ + lndebug("rpos2 %d", rpos2); + + /* Go up till we reach the expected position. */ + if (rows-rpos2 > 0) { + lndebug("go-up %d", rows-rpos2); + snprintf(seq,64,"\x1b[%dA", rows-rpos2); + abAppend(&ab,seq,strlen(seq)); + } + + /* Set column. */ + col = (pcollen+colpos2) % l->cols; + lndebug("set col %d", 1+col); + if (col) + snprintf(seq,64,"\r\x1b[%dC", col); + else + snprintf(seq,64,"\r"); abAppend(&ab,seq,strlen(seq)); } - /* Clean the top line. */ - lndebug("clear"); - snprintf(seq,64,"\r\x1b[0K"); - abAppend(&ab,seq,strlen(seq)); - - /* Write the prompt and the current buffer content */ - abAppend(&ab,l->prompt,strlen(l->prompt)); - abAppend(&ab,l->buf,l->len); - - /* If we are at the very end of the screen with our prompt, we need to - * emit a newline and move the prompt to the first column. */ - if (l->pos && - l->pos == l->len && - (l->pos+plen) % l->cols == 0) - { - lndebug(""); - abAppend(&ab,"\n",1); - snprintf(seq,64,"\r"); - abAppend(&ab,seq,strlen(seq)); - rows++; - if (rows > (int)l->maxrows) l->maxrows = rows; - } - - /* Move cursor to right position. */ - rpos2 = (plen+l->pos+l->cols)/l->cols; /* current cursor relative row. */ - lndebug("rpos2 %d", rpos2); - - /* Go up till we reach the expected positon. */ - if (rows-rpos2 > 0) { - lndebug("go-up %d", rows-rpos2); - snprintf(seq,64,"\x1b[%dA", rows-rpos2); - abAppend(&ab,seq,strlen(seq)); - } - - /* Set column. */ - col = (plen+(int)l->pos) % (int)l->cols; - lndebug("set col %d", 1+col); - if (col) - snprintf(seq,64,"\r\x1b[%dC", col); - else - snprintf(seq,64,"\r"); - abAppend(&ab,seq,strlen(seq)); - lndebug("\n"); - l->oldpos = l->pos; + l->oldcolpos = colpos2; + l->oldcollen = l->len; + l->prev_history_index = l->history_index; if (write(fd,ab.b,ab.len) == -1) {} /* Can't recover from write error. */ abFree(&ab); @@ -696,40 +917,67 @@ static void refreshMultiLine(struct linenoiseState *l) { /* Calls the two low level functions refreshSingleLine() or * refreshMultiLine() according to the selected mode. */ -void linenoiseRefreshLine(void) { - /* Update columns in case the terminal was resized */ - lss.cols = getColumns(STDIN_FILENO, STDOUT_FILENO); - +static void refreshLineWithFlags(struct linenoiseState *l, int flags) { if (mlmode) - refreshMultiLine(&lss); + refreshMultiLine(l,flags); else - refreshSingleLine(&lss); + refreshSingleLine(l,flags); +} + +/* Utility function to avoid specifying REFRESH_ALL all the times. */ +static void refreshLine(struct linenoiseState *l) { + /* Update columns in case the terminal was resized */ + l->cols = getColumns(STDIN_FILENO, STDOUT_FILENO); + + refreshLineWithFlags(l,REFRESH_ALL); +} + +/* Hide the current line, when using the multiplexing API. */ +void linenoiseHide(struct linenoiseState *l) { + if (mlmode) + refreshMultiLine(l,REFRESH_CLEAN); + else + refreshSingleLine(l,REFRESH_CLEAN); +} + +/* Show the current line, when using the multiplexing API. */ +void linenoiseShow(struct linenoiseState *l) { + if (l->in_completion) { + refreshLineWithCompletion(l,NULL,REFRESH_WRITE); + } else { + refreshLineWithFlags(l,REFRESH_WRITE); + } } /* Insert the character 'c' at cursor current position. * * On error writing to the terminal -1 is returned, otherwise 0. */ -int linenoiseEditInsert(struct linenoiseState *l, char c) { - if (l->len < l->buflen) { +int linenoiseEditInsert(struct linenoiseState *l, const char *cbuf, int clen) { + if (l->len+clen <= l->buflen) { if (l->len == l->pos) { - l->buf[l->pos] = c; - l->pos++; - l->len++; + memcpy(&l->buf[l->pos],cbuf,clen); + l->pos+=clen; + l->len+=clen;; l->buf[l->len] = '\0'; - if ((!mlmode && l->plen+l->len < l->cols) /* || mlmode */) { + if ((!mlmode && promptTextColumnLen(l->prompt,l->plen)+columnPos(l->buf,l->len,l->len) < l->cols && !hintsCallback)) { /* Avoid a full update of the line in the * trivial case. */ - if (write(l->ofd,&c,1) == -1) return -1; + if (maskmode == 1) { + static const char d = '*'; + if (write(l->ofd,&d,1) == -1) return -1; + } else { + if (write(l->ofd,cbuf,clen) == -1) return -1; + } } else { - linenoiseRefreshLine(); + refreshLine(l); } } else { - memmove(l->buf+l->pos+1,l->buf+l->pos,l->len-l->pos); - l->buf[l->pos] = c; - l->len++; - l->pos++; + memmove(l->buf+l->pos+clen,l->buf+l->pos,l->len-l->pos); + memcpy(&l->buf[l->pos],cbuf,clen); + l->pos+=clen; + l->len+=clen; l->buf[l->len] = '\0'; - linenoiseRefreshLine(); + refreshLine(l); } } return 0; @@ -738,16 +986,16 @@ int linenoiseEditInsert(struct linenoiseState *l, char c) { /* Move cursor on the left. */ void linenoiseEditMoveLeft(struct linenoiseState *l) { if (l->pos > 0) { - l->pos--; - linenoiseRefreshLine(); + l->pos -= prevCharLen(l->buf,l->len,l->pos,NULL); + refreshLine(l); } } /* Move cursor on the right. */ void linenoiseEditMoveRight(struct linenoiseState *l) { if (l->pos != l->len) { - l->pos++; - linenoiseRefreshLine(); + l->pos += nextCharLen(l->buf,l->len,l->pos,NULL); + refreshLine(l); } } @@ -755,7 +1003,7 @@ void linenoiseEditMoveRight(struct linenoiseState *l) { void linenoiseEditMoveHome(struct linenoiseState *l) { if (l->pos != 0) { l->pos = 0; - linenoiseRefreshLine(); + refreshLine(l); } } @@ -763,7 +1011,7 @@ void linenoiseEditMoveHome(struct linenoiseState *l) { void linenoiseEditMoveEnd(struct linenoiseState *l) { if (l->pos != l->len) { l->pos = l->len; - linenoiseRefreshLine(); + refreshLine(l); } } @@ -789,7 +1037,7 @@ void linenoiseEditHistoryNext(struct linenoiseState *l, int dir) { strncpy(l->buf,history[history_len - 1 - l->history_index],l->buflen); l->buf[l->buflen-1] = '\0'; l->len = l->pos = strlen(l->buf); - linenoiseRefreshLine(); + refreshLine(l); } } @@ -797,25 +1045,27 @@ void linenoiseEditHistoryNext(struct linenoiseState *l, int dir) { * position. Basically this is what happens with the "Delete" keyboard key. */ void linenoiseEditDelete(struct linenoiseState *l) { if (l->len > 0 && l->pos < l->len) { - memmove(l->buf+l->pos,l->buf+l->pos+1,l->len-l->pos-1); - l->len--; + int chlen = nextCharLen(l->buf,l->len,l->pos,NULL); + memmove(l->buf+l->pos,l->buf+l->pos+chlen,l->len-l->pos-chlen); + l->len-=chlen; l->buf[l->len] = '\0'; - linenoiseRefreshLine(); + refreshLine(l); } } /* Backspace implementation. */ void linenoiseEditBackspace(struct linenoiseState *l) { if (l->pos > 0 && l->len > 0) { - memmove(l->buf+l->pos-1,l->buf+l->pos,l->len-l->pos); - l->pos--; - l->len--; + int chlen = prevCharLen(l->buf,l->len,l->pos,NULL); + memmove(l->buf+l->pos-chlen,l->buf+l->pos,l->len-l->pos); + l->pos-=chlen; + l->len-=chlen; l->buf[l->len] = '\0'; - linenoiseRefreshLine(); + refreshLine(l); } } -/* Delete the previosu word, maintaining the cursor at the start of the +/* Delete the previous word, maintaining the cursor at the start of the * current word. */ void linenoiseEditDeletePrevWord(struct linenoiseState *l) { size_t old_pos = l->pos; @@ -828,186 +1078,288 @@ void linenoiseEditDeletePrevWord(struct linenoiseState *l) { diff = old_pos - l->pos; memmove(l->buf+l->pos,l->buf+old_pos,l->len-old_pos+1); l->len -= diff; - linenoiseRefreshLine(); + refreshLine(l); } -/* This function is the core of the line editing capability of linenoise. - * It expects 'fd' to be already in "raw mode" so that every key pressed - * will be returned ASAP to read(). +/* This function is part of the multiplexed API of Linenoise, that is used + * in order to implement the blocking variant of the API but can also be + * called by the user directly in an event driven program. It will: * - * The resulting string is put into 'buf' when the user type enter, or - * when ctrl+d is typed. + * 1. Initialize the linenoise state passed by the user. + * 2. Put the terminal in RAW mode. + * 3. Show the prompt. + * 4. Return control to the user, that will have to call linenoiseEditFeed() + * each time there is some data arriving in the standard input. * - * The function returns the length of the current buffer. */ -static int linenoiseEdit(int stdin_fd, int stdout_fd, char *buf, size_t buflen, const char *prompt) -{ + * The user can also call linenoiseEditHide() and linenoiseEditShow() if it + * is required to show some input arriving asynchronously, without mixing + * it with the currently edited line. + * + * When linenoiseEditFeed() returns non-NULL, the user finished with the + * line editing session (pressed enter CTRL-D/C): in this case the caller + * needs to call linenoiseEditStop() to put back the terminal in normal + * mode. This will not destroy the buffer, as long as the linenoiseState + * is still valid in the context of the caller. + * + * The function returns 0 on success, or -1 if writing to standard output + * fails. If stdin_fd or stdout_fd are set to -1, the default is to use + * STDIN_FILENO and STDOUT_FILENO. + */ +int linenoiseEditStart(struct linenoiseState *l, int stdin_fd, int stdout_fd, char *buf, size_t buflen, const char *prompt) { + if (stdin_fd == -1) stdin_fd = STDIN_FILENO; + if (stdout_fd == -1) stdout_fd = STDOUT_FILENO; + /* Populate the linenoise state that we pass to functions implementing * specific editing functionalities. */ - lss.ifd = stdin_fd; - lss.ofd = stdout_fd; - lss.buf = buf; - lss.buflen = buflen; - lss.prompt = prompt; - lss.plen = strlen(prompt); - lss.oldpos = lss.pos = 0; - lss.len = 0; - lss.cols = getColumns(stdin_fd, stdout_fd); - lss.maxrows = 0; - lss.history_index = 0; + l->in_completion = 0; + l->ifd = stdin_fd; + l->ofd = stdout_fd; + l->buf = buf; + l->buflen = buflen; + l->prompt = prompt; + l->plen = strlen(prompt); + l->oldcolpos = l->pos = 0; + l->oldcollen = 0; + l->len = 0; + + /* Enter raw mode. */ + if (enableRawMode(l->ifd) == -1) return -1; + + l->cols = getColumns(stdin_fd, stdout_fd); + l->oldrows = 0; + l->history_index = 0; + l->prev_history_index = 0; /* Buffer starts empty. */ - lss.buf[0] = '\0'; - lss.buflen--; /* Make sure there is always space for the nulterm */ + l->buf[0] = '\0'; + l->buflen--; /* Make sure there is always space for the nulterm */ + + /* If stdin is not a tty, stop here with the initialization. We + * will actually just read a line from standard input in blocking + * mode later, in linenoiseEditFeed(). */ + if (!isatty(l->ifd)) return 0; /* The latest history entry is always our current buffer, that * initially is just an empty string. */ linenoiseHistoryAdd(""); - if (write(lss.ofd,prompt,lss.plen) == -1) return -1; - while(1) { - char c = 0; - int nread; - char seq[3]; + if (write(l->ofd,prompt,l->plen) == -1) return -1; + return 0; +} - nread = read(lss.ifd,&c,sizeof c); - if (nread <= 0) return lss.len; +char *linenoiseEditMore = "If you see this, you are misusing the API: when linenoiseEditFeed() is called, if it returns linenoiseEditMore the user is yet editing the line. See the README file for more information."; - /* Only autocomplete when the callback is set. It returns < 0 when - * there was an error reading from fd. Otherwise it will return the - * character that should be handled next. */ - if (c == 9 && completionCallback != NULL) { - c = completeLine(&lss); - /* Return on errors */ - if (c < 0) return lss.len; - /* Read next character when 0 */ - if (c == 0) continue; +/* This function is part of the multiplexed API of linenoise, see the top + * comment on linenoiseEditStart() for more information. Call this function + * each time there is some data to read from the standard input file + * descriptor. In the case of blocking operations, this function can just be + * called in a loop, and block. + * + * The function returns linenoiseEditMore to signal that line editing is still + * in progress, that is, the user didn't yet pressed enter / CTRL-D. Otherwise + * the function returns the pointer to the heap-allocated buffer with the + * edited line, that the user should free with linenoiseFree(). + * + * On special conditions, NULL is returned and errno is populated: + * + * EAGAIN if the user pressed Ctrl-C + * ENOENT if the user pressed Ctrl-D + * + * Some other errno: I/O error. + */ +char *linenoiseEditFeed(struct linenoiseState *l) { + /* Not a TTY, pass control to line reading without character + * count limits. */ + if (!isatty(l->ifd)) return linenoiseNoTTY(); + + int c; + int nread; + char cbuf[32]; // large enough for any encoding? + char seq[3]; + + nread = readCode(l->ifd,cbuf,sizeof(cbuf),&c); + if (nread <= 0) return NULL; + + /* Only autocomplete when the callback is set. It returns < 0 when + * there was an error reading from fd. Otherwise it will return the + * character that should be handled next. */ + if ((l->in_completion || c == 9) && completionCallback != NULL) { + c = completeLine(l,c); + /* BUGFIX of utf-8 support */ + *cbuf = c; + /* Return on errors */ + if (c < 0) return NULL; + /* Read next character when 0 */ + if (c == 0) return linenoiseEditMore; + } + + switch(c) { + case ENTER: /* enter */ + history_len--; + free(history[history_len]); + if (mlmode) linenoiseEditMoveEnd(l); + if (hintsCallback) { + /* Force a refresh without hints to leave the previous + * line as the user typed it after a newline. */ + linenoiseHintsCallback *hc = hintsCallback; + hintsCallback = NULL; + refreshLine(l); + hintsCallback = hc; } - - switch(c) { - case ENTER: /* enter */ + return strdup(l->buf); + case CTRL_C: /* ctrl-c */ + errno = EAGAIN; + return NULL; + case BACKSPACE: /* backspace */ + case 8: /* ctrl-h */ + linenoiseEditBackspace(l); + break; + case CTRL_D: /* ctrl-d, remove char at right of cursor, or if the + line is empty, act as end-of-file. */ + if (l->len > 0) { + linenoiseEditDelete(l); + } else { history_len--; free(history[history_len]); - if (mlmode) linenoiseEditMoveEnd(&lss); - return (int)lss.len; - case CTRL_C: /* ctrl-c */ - errno = EAGAIN; - return -1; - case BACKSPACE: /* backspace */ - case 8: /* ctrl-h */ - linenoiseEditBackspace(&lss); - break; - case CTRL_D: /* ctrl-d, remove char at right of cursor, or if the - line is empty, act as end-of-file. */ - if (lss.len > 0) { - linenoiseEditDelete(&lss); - } else { - history_len--; - free(history[history_len]); - return -1; - } - break; - case CTRL_T: /* ctrl-t, swaps current character with previous. */ - if (lss.pos > 0 && lss.pos < lss.len) { - int aux = buf[lss.pos-1]; - buf[lss.pos-1] = buf[lss.pos]; - buf[lss.pos] = aux; - if (lss.pos != lss.len-1) lss.pos++; - linenoiseRefreshLine(); - } - break; - case CTRL_B: /* ctrl-b */ - linenoiseEditMoveLeft(&lss); - break; - case CTRL_F: /* ctrl-f */ - linenoiseEditMoveRight(&lss); - break; - case CTRL_P: /* ctrl-p */ - linenoiseEditHistoryNext(&lss, LINENOISE_HISTORY_PREV); - break; - case CTRL_N: /* ctrl-n */ - linenoiseEditHistoryNext(&lss, LINENOISE_HISTORY_NEXT); - break; - case ESC: /* escape sequence */ - /* Read the next two bytes representing the escape sequence. - * Use two calls to handle slow terminals returning the two - * chars at different times. */ - if (read(lss.ifd,seq,1) == -1) break; - if (read(lss.ifd,seq+1,1) == -1) break; + errno = ENOENT; + return NULL; + } + break; + case CTRL_T: /* ctrl-t, swaps current character with previous. */ + if (l->pos > 0 && l->pos < l->len) { + int aux = l->buf[l->pos-1]; + l->buf[l->pos-1] = l->buf[l->pos]; + l->buf[l->pos] = aux; + if (l->pos != l->len-1) l->pos++; + refreshLine(l); + } + break; + case CTRL_B: /* ctrl-b */ + linenoiseEditMoveLeft(l); + break; + case CTRL_F: /* ctrl-f */ + linenoiseEditMoveRight(l); + break; + case CTRL_P: /* ctrl-p */ + linenoiseEditHistoryNext(l, LINENOISE_HISTORY_PREV); + break; + case CTRL_N: /* ctrl-n */ + linenoiseEditHistoryNext(l, LINENOISE_HISTORY_NEXT); + break; + case ESC: /* escape sequence */ + /* Read the next two bytes representing the escape sequence. + * Use two calls to handle slow terminals returning the two + * chars at different times. */ + if (read(l->ifd,seq,1) == -1) break; + if (read(l->ifd,seq+1,1) == -1) break; - /* ESC [ sequences. */ - if (seq[0] == '[') { - if (seq[1] >= '0' && seq[1] <= '9') { - /* Extended escape, read additional byte. */ - if (read(lss.ifd, seq + 2, 1) == -1) break; - if ((seq[1] == '3') && (seq[2] == '~')) { - /* Delete key. */ - linenoiseEditDelete(&lss); - } - } else { + /* ESC [ sequences. */ + if (seq[0] == '[') { + if (seq[1] >= '0' && seq[1] <= '9') { + /* Extended escape, read additional byte. */ + if (read(l->ifd,seq+2,1) == -1) break; + if (seq[2] == '~') { switch(seq[1]) { - case 'A': /* Up */ - linenoiseEditHistoryNext(&lss, LINENOISE_HISTORY_PREV); - break; - case 'B': /* Down */ - linenoiseEditHistoryNext(&lss, LINENOISE_HISTORY_NEXT); - break; - case 'C': /* Right */ - linenoiseEditMoveRight(&lss); - break; - case 'D': /* Left */ - linenoiseEditMoveLeft(&lss); - break; - case 'H': /* Home */ - linenoiseEditMoveHome(&lss); - break; - case 'F': /* End*/ - linenoiseEditMoveEnd(&lss); + case '3': /* Delete key. */ + linenoiseEditDelete(l); break; } } - } - - /* ESC O sequences. */ - else if (seq[0] == 'O') { + } else { switch(seq[1]) { + case 'A': /* Up */ + linenoiseEditHistoryNext(l, LINENOISE_HISTORY_PREV); + break; + case 'B': /* Down */ + linenoiseEditHistoryNext(l, LINENOISE_HISTORY_NEXT); + break; + case 'C': /* Right */ + linenoiseEditMoveRight(l); + break; + case 'D': /* Left */ + linenoiseEditMoveLeft(l); + break; case 'H': /* Home */ - linenoiseEditMoveHome(&lss); + linenoiseEditMoveHome(l); break; case 'F': /* End*/ - linenoiseEditMoveEnd(&lss); + linenoiseEditMoveEnd(l); break; } } - break; - default: - if (linenoiseEditInsert(&lss,c)) return -1; - break; - case CTRL_U: /* Ctrl+u, delete the whole line. */ - buf[0] = '\0'; - lss.pos = lss.len = 0; - linenoiseRefreshLine(); - break; - case CTRL_K: /* Ctrl+k, delete from current to end of line. */ - buf[lss.pos] = '\0'; - lss.len = lss.pos; - linenoiseRefreshLine(); - break; - case CTRL_A: /* Ctrl+a, go to the start of the line */ - linenoiseEditMoveHome(&lss); - break; - case CTRL_E: /* ctrl+e, go to the end of the line */ - linenoiseEditMoveEnd(&lss); - break; - case CTRL_L: /* ctrl+l, clear screen */ - linenoiseClearScreen(); - linenoiseRefreshLine(); - break; - case CTRL_W: /* ctrl+w, delete previous word */ - linenoiseEditDeletePrevWord(&lss); - break; } + + /* ESC O sequences. */ + else if (seq[0] == 'O') { + switch(seq[1]) { + case 'H': /* Home */ + linenoiseEditMoveHome(l); + break; + case 'F': /* End*/ + linenoiseEditMoveEnd(l); + break; + } + } + break; + default: + if (linenoiseEditInsert(l,cbuf,nread)) return NULL; + break; + case CTRL_U: /* Ctrl+u, delete the whole line. */ + l->buf[0] = '\0'; + l->pos = l->len = 0; + refreshLine(l); + break; + case CTRL_K: /* Ctrl+k, delete from current to end of line. */ + l->buf[l->pos] = '\0'; + l->len = l->pos; + refreshLine(l); + break; + case CTRL_A: /* Ctrl+a, go to the start of the line */ + linenoiseEditMoveHome(l); + break; + case CTRL_E: /* ctrl+e, go to the end of the line */ + linenoiseEditMoveEnd(l); + break; + case CTRL_L: /* ctrl+l, clear screen */ + linenoiseClearScreen(); + refreshLine(l); + break; + case CTRL_W: /* ctrl+w, delete previous word */ + linenoiseEditDeletePrevWord(l); + break; } - return lss.len; + return linenoiseEditMore; +} + +/* This is part of the multiplexed linenoise API. See linenoiseEditStart() + * for more information. This function is called when linenoiseEditFeed() + * returns something different than NULL. At this point the user input + * is in the buffer, and we can restore the terminal in normal mode. */ +void linenoiseEditStop(struct linenoiseState *l) { + if (!isatty(l->ifd)) return; + disableRawMode(l->ifd); + printf("\n"); +} + +/* This just implements a blocking loop for the multiplexed API. + * In many applications that are not event-driven, we can just call + * the blocking linenoise API, wait for the user to complete the editing + * and return the buffer. */ +static char *linenoiseBlockingEdit(int stdin_fd, int stdout_fd, char *buf, size_t buflen, const char *prompt) +{ + struct linenoiseState l; + + /* Editing without a buffer is invalid. */ + if (buflen == 0) { + errno = EINVAL; + return NULL; + } + + linenoiseEditStart(&l,stdin_fd,stdout_fd,buf,buflen,prompt); + char *res; + while((res = linenoiseEditFeed(&l)) == linenoiseEditMore); + linenoiseEditStop(&l); + return res; } /* This special mode is used by linenoise in order to print scan codes @@ -1018,51 +1370,60 @@ void linenoisePrintKeyCodes(void) { printf("Linenoise key codes debugging mode.\n" "Press keys to see scan codes. Type 'quit' at any time to exit.\n"); - if (linenoiseEnableRawMode(STDIN_FILENO) == -1) return; + if (enableRawMode(STDIN_FILENO) == -1) return; memset(quit,' ',4); while(1) { - char c; + char c = 0; int nread; - nread = read(STDIN_FILENO,&c,1); + nread = read(STDIN_FILENO,&c,sizeof c); if (nread <= 0) continue; memmove(quit,quit+1,sizeof(quit)-1); /* shift string to left. */ quit[sizeof(quit)-1] = c; /* Insert current char on the right. */ if (memcmp(quit,"quit",sizeof(quit)) == 0) break; printf("'%c' %02x (%d) (type quit to exit)\n", - isprint(c) ? c : '?', (int)c, (int)c); + isprint((int)c) ? c : '?', (int)c, (int)c); printf("\r"); /* Go left edge manually, we are in raw mode. */ fflush(stdout); } - linenoiseDisableRawMode(STDIN_FILENO); + disableRawMode(STDIN_FILENO); } -/* This function calls the line editing function linenoiseEdit() using - * the STDIN file descriptor set in raw mode. */ -static int linenoiseRaw(char *buf, size_t buflen, const char *prompt) { - int count; +/* This function is called when linenoise() is called with the standard + * input file descriptor not attached to a TTY. So for example when the + * program using linenoise is called in pipe or with a file redirected + * to its standard input. In this case, we want to be able to return the + * line regardless of its length (by default we are limited to 4k). */ +static char *linenoiseNoTTY(void) { + char *line = NULL; + size_t len = 0, maxlen = 0; - if (buflen == 0) { - errno = EINVAL; - return -1; - } - if (!isatty(STDIN_FILENO)) { - /* Not a tty: read from file / pipe. */ - if (fgets(buf, buflen, stdin) == NULL) return -1; - count = strlen(buf); - if (count && buf[count-1] == '\n') { - count--; - buf[count] = '\0'; + while(1) { + if (len == maxlen) { + if (maxlen == 0) maxlen = 16; + maxlen *= 2; + char *oldval = line; + line = realloc(line,maxlen); + if (line == NULL) { + if (oldval) free(oldval); + return NULL; + } + } + int c = fgetc(stdin); + if (c == EOF || c == '\n') { + if (c == EOF && len == 0) { + free(line); + return NULL; + } else { + line[len] = '\0'; + return line; + } + } else { + line[len] = c; + len++; } - } else { - /* Interactive editing. */ - if (linenoiseEnableRawMode(STDIN_FILENO) == -1) return -1; - count = linenoiseEdit(STDIN_FILENO, STDOUT_FILENO, buf, buflen, prompt); - linenoiseDisableRawMode(STDIN_FILENO); - printf("\n"); } - return count; } /* The high level function that is the main API of the linenoise library. @@ -1072,9 +1433,12 @@ static int linenoiseRaw(char *buf, size_t buflen, const char *prompt) { * something even in the most desperate of the conditions. */ char *linenoise(const char *prompt) { char buf[LINENOISE_MAX_LINE]; - int count; - if (isUnsupportedTerm()) { + if (!isatty(STDIN_FILENO)) { + /* Not a tty: read from file / pipe. In this mode we don't want any + * limit to the line size, so we call a function to handle that. */ + return linenoiseNoTTY(); + } else if (isUnsupportedTerm()) { size_t len; printf("%s",prompt); @@ -1087,12 +1451,20 @@ char *linenoise(const char *prompt) { } return strdup(buf); } else { - count = linenoiseRaw(buf,LINENOISE_MAX_LINE,prompt); - if (count == -1) return NULL; - return strdup(buf); + char *retval = linenoiseBlockingEdit(STDIN_FILENO,STDOUT_FILENO,buf,LINENOISE_MAX_LINE,prompt); + return retval; } } +/* This is just a wrapper the user may want to call in order to make sure + * the linenoise returned buffer is freed with the same allocator it was + * created with. Useful when the main program is using an alternative + * allocator. */ +void linenoiseFree(void *ptr) { + if (ptr == linenoiseEditMore) return; // Protect from API misuse. + free(ptr); +} + /* ================================ History ================================= */ /* Free the history, but does not reset it. Only used when we have to @@ -1109,7 +1481,7 @@ static void freeHistory(void) { /* At exit we'll try to fix the terminal to the initial conditions. */ static void linenoiseAtExit(void) { - linenoiseDisableRawMode(STDIN_FILENO); + disableRawMode(STDIN_FILENO); freeHistory(); } @@ -1184,10 +1556,14 @@ int linenoiseHistorySetMaxLen(int len) { /* Save the history in the specified file. On success 0 is returned * otherwise -1 is returned. */ int linenoiseHistorySave(const char *filename) { - FILE *fp = fopen(filename,"w"); + mode_t old_umask = umask(S_IXUSR|S_IRWXG|S_IRWXO); + FILE *fp; int j; + fp = fopen(filename,"w"); + umask(old_umask); if (fp == NULL) return -1; + chmod(filename,S_IRUSR|S_IWUSR); for (j = 0; j < history_len; j++) fprintf(fp,"%s\n",history[j]); fclose(fp); diff --git a/tools/lint/linenoise/linenoise.h b/tools/lint/linenoise/linenoise.h index 8362b1f..8949e3a 100644 --- a/tools/lint/linenoise/linenoise.h +++ b/tools/lint/linenoise/linenoise.h @@ -7,7 +7,7 @@ * * ------------------------------------------------------------------------ * - * Copyright (c) 2010-2014, Salvatore Sanfilippo + * Copyright (c) 2010-2023, Salvatore Sanfilippo * Copyright (c) 2010-2013, Pieter Noordhuis * * All rights reserved. @@ -39,13 +39,21 @@ #ifndef __LINENOISE_H #define __LINENOISE_H -#include - #ifdef __cplusplus extern "C" { #endif +#include /* For size_t. */ + +extern char *linenoiseEditMore; + +/* The linenoiseState structure represents the state during line editing. + * We pass this state to functions implementing specific editing + * functionalities. */ struct linenoiseState { + int in_completion; /* The user pressed TAB and we are now in completion + * mode, so input is handled by completeLine(). */ + size_t completion_idx; /* Index of next completion to propose. */ int ifd; /* Terminal stdin file descriptor. */ int ofd; /* Terminal stdout file descriptor. */ char *buf; /* Edited line buffer. */ @@ -53,39 +61,62 @@ struct linenoiseState { const char *prompt; /* Prompt to display. */ size_t plen; /* Prompt length. */ size_t pos; /* Current cursor position. */ - size_t oldpos; /* Previous refresh cursor position. */ + size_t oldcolpos; /* Previous refresh cursor column position. */ + size_t oldcollen; /* Previous length of buffer. */ size_t len; /* Current edited line length. */ size_t cols; /* Number of columns in terminal. */ - size_t maxrows; /* Maximum num of rows used so far (multiline mode) */ - int rawmode; + size_t oldrows; /* Rows used by last refrehsed line (multiline mode) */ int history_index; /* The history index we are currently editing. */ + int prev_history_index; /* Previous history index. */ }; -extern struct linenoiseState lss; - typedef struct linenoiseCompletions { int path; size_t len; char **cvec; } linenoiseCompletions; +/* Non blocking API. */ +int linenoiseEditStart(struct linenoiseState *l, int stdin_fd, int stdout_fd, char *buf, size_t buflen, const char *prompt); +char *linenoiseEditFeed(struct linenoiseState *l); +void linenoiseEditStop(struct linenoiseState *l); +void linenoiseHide(struct linenoiseState *l); +void linenoiseShow(struct linenoiseState *l); + +/* Blocking API. */ +char *linenoise(const char *prompt); +void linenoiseFree(void *ptr); + +/* Completion API. */ typedef void(linenoiseCompletionCallback)(const char *, const char *, linenoiseCompletions *); +typedef char*(linenoiseHintsCallback)(const char *, int *color, int *bold); +typedef void(linenoiseFreeHintsCallback)(void *); void linenoiseSetCompletionCallback(linenoiseCompletionCallback *); +void linenoiseSetHintsCallback(linenoiseHintsCallback *); +void linenoiseSetFreeHintsCallback(linenoiseFreeHintsCallback *); void linenoiseAddCompletion(linenoiseCompletions *, const char *); -char *linenoise(const char *prompt); +/* History API. */ int linenoiseHistoryAdd(const char *line); int linenoiseHistorySetMaxLen(int len); int linenoiseHistorySave(const char *filename); int linenoiseHistoryLoad(const char *filename); + +/* Other utilities. */ void linenoiseClearScreen(void); void linenoiseSetMultiLine(int ml); void linenoisePrintKeyCodes(void); +void linenoiseMaskModeEnable(void); +void linenoiseMaskModeDisable(void); -void linenoisePathCompletion(const char *, const char *, linenoiseCompletions *); -void linenoiseRefreshLine(void); -int linenoiseEnableRawMode(int fd); -void linenoiseDisableRawMode(int fd); +typedef size_t (linenoisePrevCharLen)(const char *buf, size_t buf_len, size_t pos, size_t *col_len); +typedef size_t (linenoiseNextCharLen)(const char *buf, size_t buf_len, size_t pos, size_t *col_len); +typedef size_t (linenoiseReadCode)(int fd, char *buf, size_t buf_len, int* c); + +void linenoiseSetEncodingFunctions( + linenoisePrevCharLen *prevCharLenFunc, + linenoiseNextCharLen *nextCharLenFunc, + linenoiseReadCode *readCodeFunc); #ifdef __cplusplus } diff --git a/tools/lint/linenoise/utf8.c b/tools/lint/linenoise/utf8.c new file mode 100644 index 0000000..dba1e4b --- /dev/null +++ b/tools/lint/linenoise/utf8.c @@ -0,0 +1,464 @@ +/* encoding/utf8.c -- VERSION 1.0 + * + * Guerrilla line editing library against the idea that a line editing lib + * needs to be 20,000 lines of C code. + * + * You can find the latest source code at: + * + * http://github.com/antirez/linenoise + * + * Does a number of crazy assumptions that happen to be true in 99.9999% of + * the 2010 UNIX computers around. + * + * ------------------------------------------------------------------------ + * + * Copyright (c) 2010-2014, Salvatore Sanfilippo + * Copyright (c) 2010-2013, Pieter Noordhuis + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define _GNU_SOURCE /* required for compat.h before including any other headers */ + +#include +#include + +#include "compat.h" + +/* ============================ UTF8 utilities ============================== */ + +static unsigned long wideCharTable[][2] = { + { 0x1100, 0x115F }, { 0x231A, 0x231B }, { 0x2329, 0x232A }, { 0x23E9, 0x23EC }, + { 0x23F0, 0x23F0 }, { 0x23F3, 0x23F3 }, { 0x25FD, 0x25FE }, { 0x2614, 0x2615 }, + { 0x2648, 0x2653 }, { 0x267F, 0x267F }, { 0x2693, 0x2693 }, { 0x26A1, 0x26A1 }, + { 0x26AA, 0x26AB }, { 0x26BD, 0x26BE }, { 0x26C4, 0x26C5 }, { 0x26CE, 0x26CE }, + { 0x26D4, 0x26D4 }, { 0x26EA, 0x26EA }, { 0x26F2, 0x26F3 }, { 0x26F5, 0x26F5 }, + { 0x26FA, 0x26FA }, { 0x26FD, 0x26FD }, { 0x2705, 0x2705 }, { 0x270A, 0x270B }, + { 0x2728, 0x2728 }, { 0x274C, 0x274C }, { 0x274E, 0x274E }, { 0x2753, 0x2755 }, + { 0x2757, 0x2757 }, { 0x2795, 0x2797 }, { 0x27B0, 0x27B0 }, { 0x27BF, 0x27BF }, + { 0x2B1B, 0x2B1C }, { 0x2B50, 0x2B50 }, { 0x2B55, 0x2B55 }, { 0x2E80, 0x2E99 }, + { 0x2E9B, 0x2EF3 }, { 0x2F00, 0x2FD5 }, { 0x2FF0, 0x2FFB }, { 0x3000, 0x303E }, + { 0x3041, 0x3096 }, { 0x3099, 0x30FF }, { 0x3105, 0x312F }, { 0x3131, 0x318E }, + { 0x3190, 0x31E3 }, { 0x31F0, 0x321E }, { 0x3220, 0x3247 }, { 0x3250, 0x4DBF }, + { 0x4E00, 0xA48C }, { 0xA490, 0xA4C6 }, { 0xA960, 0xA97C }, { 0xAC00, 0xD7A3 }, + { 0xF900, 0xFAFF }, { 0xFE10, 0xFE19 }, { 0xFE30, 0xFE52 }, { 0xFE54, 0xFE66 }, + { 0xFE68, 0xFE6B }, { 0xFF01, 0xFF60 }, { 0xFFE0, 0xFFE6 }, { 0x16FE0, 0x16FE4 }, + { 0x16FF0, 0x16FF1 }, { 0x17000, 0x187F7 }, { 0x18800, 0x18CD5 }, { 0x18D00, 0x18D08 }, + { 0x1AFF0, 0x1AFF3 }, { 0x1AFF5, 0x1AFFB }, { 0x1AFFD, 0x1AFFE }, { 0x1B000, 0x1B122 }, + { 0x1B150, 0x1B152 }, { 0x1B164, 0x1B167 }, { 0x1B170, 0x1B2FB }, { 0x1F004, 0x1F004 }, + { 0x1F0CF, 0x1F0CF }, { 0x1F18E, 0x1F18E }, { 0x1F191, 0x1F19A }, { 0x1F200, 0x1F202 }, + { 0x1F210, 0x1F23B }, { 0x1F240, 0x1F248 }, { 0x1F250, 0x1F251 }, { 0x1F260, 0x1F265 }, + { 0x1F300, 0x1F320 }, { 0x1F32D, 0x1F335 }, { 0x1F337, 0x1F37C }, { 0x1F37E, 0x1F393 }, + { 0x1F3A0, 0x1F3CA }, { 0x1F3CF, 0x1F3D3 }, { 0x1F3E0, 0x1F3F0 }, { 0x1F3F4, 0x1F3F4 }, + { 0x1F3F8, 0x1F43E }, { 0x1F440, 0x1F440 }, { 0x1F442, 0x1F4FC }, { 0x1F4FF, 0x1F53D }, + { 0x1F54B, 0x1F54E }, { 0x1F550, 0x1F567 }, { 0x1F57A, 0x1F57A }, { 0x1F595, 0x1F596 }, + { 0x1F5A4, 0x1F5A4 }, { 0x1F5FB, 0x1F64F }, { 0x1F680, 0x1F6C5 }, { 0x1F6CC, 0x1F6CC }, + { 0x1F6D0, 0x1F6D2 }, { 0x1F6D5, 0x1F6D7 }, { 0x1F6DD, 0x1F6DF }, { 0x1F6EB, 0x1F6EC }, + { 0x1F6F4, 0x1F6FC }, { 0x1F7E0, 0x1F7EB }, { 0x1F7F0, 0x1F7F0 }, { 0x1F90C, 0x1F93A }, + { 0x1F93C, 0x1F945 }, { 0x1F947, 0x1F9FF }, { 0x1FA70, 0x1FA74 }, { 0x1FA78, 0x1FA7C }, + { 0x1FA80, 0x1FA86 }, { 0x1FA90, 0x1FAAC }, { 0x1FAB0, 0x1FABA }, { 0x1FAC0, 0x1FAC5 }, + { 0x1FAD0, 0x1FAD9 }, { 0x1FAE0, 0x1FAE7 }, { 0x1FAF0, 0x1FAF6 }, { 0x20000, 0x2FFFD }, + { 0x30000, 0x3FFFD }, +}; + +static size_t wideCharTableSize = sizeof(wideCharTable) / sizeof(wideCharTable[0]); + +static unsigned long combiningCharTable[] = { + 0x0300, 0x0301, 0x0302, 0x0303, 0x0304, 0x0305, 0x0306, 0x0307, + 0x0308, 0x0309, 0x030A, 0x030B, 0x030C, 0x030D, 0x030E, 0x030F, + 0x0310, 0x0311, 0x0312, 0x0313, 0x0314, 0x0315, 0x0316, 0x0317, + 0x0318, 0x0319, 0x031A, 0x031B, 0x031C, 0x031D, 0x031E, 0x031F, + 0x0320, 0x0321, 0x0322, 0x0323, 0x0324, 0x0325, 0x0326, 0x0327, + 0x0328, 0x0329, 0x032A, 0x032B, 0x032C, 0x032D, 0x032E, 0x032F, + 0x0330, 0x0331, 0x0332, 0x0333, 0x0334, 0x0335, 0x0336, 0x0337, + 0x0338, 0x0339, 0x033A, 0x033B, 0x033C, 0x033D, 0x033E, 0x033F, + 0x0340, 0x0341, 0x0342, 0x0343, 0x0344, 0x0345, 0x0346, 0x0347, + 0x0348, 0x0349, 0x034A, 0x034B, 0x034C, 0x034D, 0x034E, 0x034F, + 0x0350, 0x0351, 0x0352, 0x0353, 0x0354, 0x0355, 0x0356, 0x0357, + 0x0358, 0x0359, 0x035A, 0x035B, 0x035C, 0x035D, 0x035E, 0x035F, + 0x0360, 0x0361, 0x0362, 0x0363, 0x0364, 0x0365, 0x0366, 0x0367, + 0x0368, 0x0369, 0x036A, 0x036B, 0x036C, 0x036D, 0x036E, 0x036F, + 0x0483, 0x0484, 0x0485, 0x0486, 0x0487, 0x0591, 0x0592, 0x0593, + 0x0594, 0x0595, 0x0596, 0x0597, 0x0598, 0x0599, 0x059A, 0x059B, + 0x059C, 0x059D, 0x059E, 0x059F, 0x05A0, 0x05A1, 0x05A2, 0x05A3, + 0x05A4, 0x05A5, 0x05A6, 0x05A7, 0x05A8, 0x05A9, 0x05AA, 0x05AB, + 0x05AC, 0x05AD, 0x05AE, 0x05AF, 0x05B0, 0x05B1, 0x05B2, 0x05B3, + 0x05B4, 0x05B5, 0x05B6, 0x05B7, 0x05B8, 0x05B9, 0x05BA, 0x05BB, + 0x05BC, 0x05BD, 0x05BF, 0x05C1, 0x05C2, 0x05C4, 0x05C5, 0x05C7, + 0x0610, 0x0611, 0x0612, 0x0613, 0x0614, 0x0615, 0x0616, 0x0617, + 0x0618, 0x0619, 0x061A, 0x064B, 0x064C, 0x064D, 0x064E, 0x064F, + 0x0650, 0x0651, 0x0652, 0x0653, 0x0654, 0x0655, 0x0656, 0x0657, + 0x0658, 0x0659, 0x065A, 0x065B, 0x065C, 0x065D, 0x065E, 0x065F, + 0x0670, 0x06D6, 0x06D7, 0x06D8, 0x06D9, 0x06DA, 0x06DB, 0x06DC, + 0x06DF, 0x06E0, 0x06E1, 0x06E2, 0x06E3, 0x06E4, 0x06E7, 0x06E8, + 0x06EA, 0x06EB, 0x06EC, 0x06ED, 0x0711, 0x0730, 0x0731, 0x0732, + 0x0733, 0x0734, 0x0735, 0x0736, 0x0737, 0x0738, 0x0739, 0x073A, + 0x073B, 0x073C, 0x073D, 0x073E, 0x073F, 0x0740, 0x0741, 0x0742, + 0x0743, 0x0744, 0x0745, 0x0746, 0x0747, 0x0748, 0x0749, 0x074A, + 0x07A6, 0x07A7, 0x07A8, 0x07A9, 0x07AA, 0x07AB, 0x07AC, 0x07AD, + 0x07AE, 0x07AF, 0x07B0, 0x07EB, 0x07EC, 0x07ED, 0x07EE, 0x07EF, + 0x07F0, 0x07F1, 0x07F2, 0x07F3, 0x07FD, 0x0816, 0x0817, 0x0818, + 0x0819, 0x081B, 0x081C, 0x081D, 0x081E, 0x081F, 0x0820, 0x0821, + 0x0822, 0x0823, 0x0825, 0x0826, 0x0827, 0x0829, 0x082A, 0x082B, + 0x082C, 0x082D, 0x0859, 0x085A, 0x085B, 0x0898, 0x0899, 0x089A, + 0x089B, 0x089C, 0x089D, 0x089E, 0x089F, 0x08CA, 0x08CB, 0x08CC, + 0x08CD, 0x08CE, 0x08CF, 0x08D0, 0x08D1, 0x08D2, 0x08D3, 0x08D4, + 0x08D5, 0x08D6, 0x08D7, 0x08D8, 0x08D9, 0x08DA, 0x08DB, 0x08DC, + 0x08DD, 0x08DE, 0x08DF, 0x08E0, 0x08E1, 0x08E3, 0x08E4, 0x08E5, + 0x08E6, 0x08E7, 0x08E8, 0x08E9, 0x08EA, 0x08EB, 0x08EC, 0x08ED, + 0x08EE, 0x08EF, 0x08F0, 0x08F1, 0x08F2, 0x08F3, 0x08F4, 0x08F5, + 0x08F6, 0x08F7, 0x08F8, 0x08F9, 0x08FA, 0x08FB, 0x08FC, 0x08FD, + 0x08FE, 0x08FF, 0x0900, 0x0901, 0x0902, 0x093A, 0x093C, 0x0941, + 0x0942, 0x0943, 0x0944, 0x0945, 0x0946, 0x0947, 0x0948, 0x094D, + 0x0951, 0x0952, 0x0953, 0x0954, 0x0955, 0x0956, 0x0957, 0x0962, + 0x0963, 0x0981, 0x09BC, 0x09C1, 0x09C2, 0x09C3, 0x09C4, 0x09CD, + 0x09E2, 0x09E3, 0x09FE, 0x0A01, 0x0A02, 0x0A3C, 0x0A41, 0x0A42, + 0x0A47, 0x0A48, 0x0A4B, 0x0A4C, 0x0A4D, 0x0A51, 0x0A70, 0x0A71, + 0x0A75, 0x0A81, 0x0A82, 0x0ABC, 0x0AC1, 0x0AC2, 0x0AC3, 0x0AC4, + 0x0AC5, 0x0AC7, 0x0AC8, 0x0ACD, 0x0AE2, 0x0AE3, 0x0AFA, 0x0AFB, + 0x0AFC, 0x0AFD, 0x0AFE, 0x0AFF, 0x0B01, 0x0B3C, 0x0B3F, 0x0B41, + 0x0B42, 0x0B43, 0x0B44, 0x0B4D, 0x0B55, 0x0B56, 0x0B62, 0x0B63, + 0x0B82, 0x0BC0, 0x0BCD, 0x0C00, 0x0C04, 0x0C3C, 0x0C3E, 0x0C3F, + 0x0C40, 0x0C46, 0x0C47, 0x0C48, 0x0C4A, 0x0C4B, 0x0C4C, 0x0C4D, + 0x0C55, 0x0C56, 0x0C62, 0x0C63, 0x0C81, 0x0CBC, 0x0CBF, 0x0CC6, + 0x0CCC, 0x0CCD, 0x0CE2, 0x0CE3, 0x0D00, 0x0D01, 0x0D3B, 0x0D3C, + 0x0D41, 0x0D42, 0x0D43, 0x0D44, 0x0D4D, 0x0D62, 0x0D63, 0x0D81, + 0x0DCA, 0x0DD2, 0x0DD3, 0x0DD4, 0x0DD6, 0x0E31, 0x0E34, 0x0E35, + 0x0E36, 0x0E37, 0x0E38, 0x0E39, 0x0E3A, 0x0E47, 0x0E48, 0x0E49, + 0x0E4A, 0x0E4B, 0x0E4C, 0x0E4D, 0x0E4E, 0x0EB1, 0x0EB4, 0x0EB5, + 0x0EB6, 0x0EB7, 0x0EB8, 0x0EB9, 0x0EBA, 0x0EBB, 0x0EBC, 0x0EC8, + 0x0EC9, 0x0ECA, 0x0ECB, 0x0ECC, 0x0ECD, 0x0F18, 0x0F19, 0x0F35, + 0x0F37, 0x0F39, 0x0F71, 0x0F72, 0x0F73, 0x0F74, 0x0F75, 0x0F76, + 0x0F77, 0x0F78, 0x0F79, 0x0F7A, 0x0F7B, 0x0F7C, 0x0F7D, 0x0F7E, + 0x0F80, 0x0F81, 0x0F82, 0x0F83, 0x0F84, 0x0F86, 0x0F87, 0x0F8D, + 0x0F8E, 0x0F8F, 0x0F90, 0x0F91, 0x0F92, 0x0F93, 0x0F94, 0x0F95, + 0x0F96, 0x0F97, 0x0F99, 0x0F9A, 0x0F9B, 0x0F9C, 0x0F9D, 0x0F9E, + 0x0F9F, 0x0FA0, 0x0FA1, 0x0FA2, 0x0FA3, 0x0FA4, 0x0FA5, 0x0FA6, + 0x0FA7, 0x0FA8, 0x0FA9, 0x0FAA, 0x0FAB, 0x0FAC, 0x0FAD, 0x0FAE, + 0x0FAF, 0x0FB0, 0x0FB1, 0x0FB2, 0x0FB3, 0x0FB4, 0x0FB5, 0x0FB6, + 0x0FB7, 0x0FB8, 0x0FB9, 0x0FBA, 0x0FBB, 0x0FBC, 0x0FC6, 0x102D, + 0x102E, 0x102F, 0x1030, 0x1032, 0x1033, 0x1034, 0x1035, 0x1036, + 0x1037, 0x1039, 0x103A, 0x103D, 0x103E, 0x1058, 0x1059, 0x105E, + 0x105F, 0x1060, 0x1071, 0x1072, 0x1073, 0x1074, 0x1082, 0x1085, + 0x1086, 0x108D, 0x109D, 0x135D, 0x135E, 0x135F, 0x1712, 0x1713, + 0x1714, 0x1732, 0x1733, 0x1752, 0x1753, 0x1772, 0x1773, 0x17B4, + 0x17B5, 0x17B7, 0x17B8, 0x17B9, 0x17BA, 0x17BB, 0x17BC, 0x17BD, + 0x17C6, 0x17C9, 0x17CA, 0x17CB, 0x17CC, 0x17CD, 0x17CE, 0x17CF, + 0x17D0, 0x17D1, 0x17D2, 0x17D3, 0x17DD, 0x180B, 0x180C, 0x180D, + 0x180F, 0x1885, 0x1886, 0x18A9, 0x1920, 0x1921, 0x1922, 0x1927, + 0x1928, 0x1932, 0x1939, 0x193A, 0x193B, 0x1A17, 0x1A18, 0x1A1B, + 0x1A56, 0x1A58, 0x1A59, 0x1A5A, 0x1A5B, 0x1A5C, 0x1A5D, 0x1A5E, + 0x1A60, 0x1A62, 0x1A65, 0x1A66, 0x1A67, 0x1A68, 0x1A69, 0x1A6A, + 0x1A6B, 0x1A6C, 0x1A73, 0x1A74, 0x1A75, 0x1A76, 0x1A77, 0x1A78, + 0x1A79, 0x1A7A, 0x1A7B, 0x1A7C, 0x1A7F, 0x1AB0, 0x1AB1, 0x1AB2, + 0x1AB3, 0x1AB4, 0x1AB5, 0x1AB6, 0x1AB7, 0x1AB8, 0x1AB9, 0x1ABA, + 0x1ABB, 0x1ABC, 0x1ABD, 0x1ABF, 0x1AC0, 0x1AC1, 0x1AC2, 0x1AC3, + 0x1AC4, 0x1AC5, 0x1AC6, 0x1AC7, 0x1AC8, 0x1AC9, 0x1ACA, 0x1ACB, + 0x1ACC, 0x1ACD, 0x1ACE, 0x1B00, 0x1B01, 0x1B02, 0x1B03, 0x1B34, + 0x1B36, 0x1B37, 0x1B38, 0x1B39, 0x1B3A, 0x1B3C, 0x1B42, 0x1B6B, + 0x1B6C, 0x1B6D, 0x1B6E, 0x1B6F, 0x1B70, 0x1B71, 0x1B72, 0x1B73, + 0x1B80, 0x1B81, 0x1BA2, 0x1BA3, 0x1BA4, 0x1BA5, 0x1BA8, 0x1BA9, + 0x1BAB, 0x1BAC, 0x1BAD, 0x1BE6, 0x1BE8, 0x1BE9, 0x1BED, 0x1BEF, + 0x1BF0, 0x1BF1, 0x1C2C, 0x1C2D, 0x1C2E, 0x1C2F, 0x1C30, 0x1C31, + 0x1C32, 0x1C33, 0x1C36, 0x1C37, 0x1CD0, 0x1CD1, 0x1CD2, 0x1CD4, + 0x1CD5, 0x1CD6, 0x1CD7, 0x1CD8, 0x1CD9, 0x1CDA, 0x1CDB, 0x1CDC, + 0x1CDD, 0x1CDE, 0x1CDF, 0x1CE0, 0x1CE2, 0x1CE3, 0x1CE4, 0x1CE5, + 0x1CE6, 0x1CE7, 0x1CE8, 0x1CED, 0x1CF4, 0x1CF8, 0x1CF9, 0x1DC0, + 0x1DC1, 0x1DC2, 0x1DC3, 0x1DC4, 0x1DC5, 0x1DC6, 0x1DC7, 0x1DC8, + 0x1DC9, 0x1DCA, 0x1DCB, 0x1DCC, 0x1DCD, 0x1DCE, 0x1DCF, 0x1DD0, + 0x1DD1, 0x1DD2, 0x1DD3, 0x1DD4, 0x1DD5, 0x1DD6, 0x1DD7, 0x1DD8, + 0x1DD9, 0x1DDA, 0x1DDB, 0x1DDC, 0x1DDD, 0x1DDE, 0x1DDF, 0x1DE0, + 0x1DE1, 0x1DE2, 0x1DE3, 0x1DE4, 0x1DE5, 0x1DE6, 0x1DE7, 0x1DE8, + 0x1DE9, 0x1DEA, 0x1DEB, 0x1DEC, 0x1DED, 0x1DEE, 0x1DEF, 0x1DF0, + 0x1DF1, 0x1DF2, 0x1DF3, 0x1DF4, 0x1DF5, 0x1DF6, 0x1DF7, 0x1DF8, + 0x1DF9, 0x1DFA, 0x1DFB, 0x1DFC, 0x1DFD, 0x1DFE, 0x1DFF, 0x20D0, + 0x20D1, 0x20D2, 0x20D3, 0x20D4, 0x20D5, 0x20D6, 0x20D7, 0x20D8, + 0x20D9, 0x20DA, 0x20DB, 0x20DC, 0x20E1, 0x20E5, 0x20E6, 0x20E7, + 0x20E8, 0x20E9, 0x20EA, 0x20EB, 0x20EC, 0x20ED, 0x20EE, 0x20EF, + 0x20F0, 0x2CEF, 0x2CF0, 0x2CF1, 0x2D7F, 0x2DE0, 0x2DE1, 0x2DE2, + 0x2DE3, 0x2DE4, 0x2DE5, 0x2DE6, 0x2DE7, 0x2DE8, 0x2DE9, 0x2DEA, + 0x2DEB, 0x2DEC, 0x2DED, 0x2DEE, 0x2DEF, 0x2DF0, 0x2DF1, 0x2DF2, + 0x2DF3, 0x2DF4, 0x2DF5, 0x2DF6, 0x2DF7, 0x2DF8, 0x2DF9, 0x2DFA, + 0x2DFB, 0x2DFC, 0x2DFD, 0x2DFE, 0x2DFF, 0x302A, 0x302B, 0x302C, + 0x302D, 0x3099, 0x309A, 0xA66F, 0xA674, 0xA675, 0xA676, 0xA677, + 0xA678, 0xA679, 0xA67A, 0xA67B, 0xA67C, 0xA67D, 0xA69E, 0xA69F, + 0xA6F0, 0xA6F1, 0xA802, 0xA806, 0xA80B, 0xA825, 0xA826, 0xA82C, + 0xA8C4, 0xA8C5, 0xA8E0, 0xA8E1, 0xA8E2, 0xA8E3, 0xA8E4, 0xA8E5, + 0xA8E6, 0xA8E7, 0xA8E8, 0xA8E9, 0xA8EA, 0xA8EB, 0xA8EC, 0xA8ED, + 0xA8EE, 0xA8EF, 0xA8F0, 0xA8F1, 0xA8FF, 0xA926, 0xA927, 0xA928, + 0xA929, 0xA92A, 0xA92B, 0xA92C, 0xA92D, 0xA947, 0xA948, 0xA949, + 0xA94A, 0xA94B, 0xA94C, 0xA94D, 0xA94E, 0xA94F, 0xA950, 0xA951, + 0xA980, 0xA981, 0xA982, 0xA9B3, 0xA9B6, 0xA9B7, 0xA9B8, 0xA9B9, + 0xA9BC, 0xA9BD, 0xA9E5, 0xAA29, 0xAA2A, 0xAA2B, 0xAA2C, 0xAA2D, + 0xAA2E, 0xAA31, 0xAA32, 0xAA35, 0xAA36, 0xAA43, 0xAA4C, 0xAA7C, + 0xAAB0, 0xAAB2, 0xAAB3, 0xAAB4, 0xAAB7, 0xAAB8, 0xAABE, 0xAABF, + 0xAAC1, 0xAAEC, 0xAAED, 0xAAF6, 0xABE5, 0xABE8, 0xABED, 0xFB1E, + 0xFE00, 0xFE01, 0xFE02, 0xFE03, 0xFE04, 0xFE05, 0xFE06, 0xFE07, + 0xFE08, 0xFE09, 0xFE0A, 0xFE0B, 0xFE0C, 0xFE0D, 0xFE0E, 0xFE0F, + 0xFE20, 0xFE21, 0xFE22, 0xFE23, 0xFE24, 0xFE25, 0xFE26, 0xFE27, + 0xFE28, 0xFE29, 0xFE2A, 0xFE2B, 0xFE2C, 0xFE2D, 0xFE2E, 0xFE2F, + 0x101FD, 0x102E0, 0x10376, 0x10377, 0x10378, 0x10379, 0x1037A, 0x10A01, + 0x10A02, 0x10A03, 0x10A05, 0x10A06, 0x10A0C, 0x10A0D, 0x10A0E, 0x10A0F, + 0x10A38, 0x10A39, 0x10A3A, 0x10A3F, 0x10AE5, 0x10AE6, 0x10D24, 0x10D25, + 0x10D26, 0x10D27, 0x10EAB, 0x10EAC, 0x10F46, 0x10F47, 0x10F48, 0x10F49, + 0x10F4A, 0x10F4B, 0x10F4C, 0x10F4D, 0x10F4E, 0x10F4F, 0x10F50, 0x10F82, + 0x10F83, 0x10F84, 0x10F85, 0x11001, 0x11038, 0x11039, 0x1103A, 0x1103B, + 0x1103C, 0x1103D, 0x1103E, 0x1103F, 0x11040, 0x11041, 0x11042, 0x11043, + 0x11044, 0x11045, 0x11046, 0x11070, 0x11073, 0x11074, 0x1107F, 0x11080, + 0x11081, 0x110B3, 0x110B4, 0x110B5, 0x110B6, 0x110B9, 0x110BA, 0x110C2, + 0x11100, 0x11101, 0x11102, 0x11127, 0x11128, 0x11129, 0x1112A, 0x1112B, + 0x1112D, 0x1112E, 0x1112F, 0x11130, 0x11131, 0x11132, 0x11133, 0x11134, + 0x11173, 0x11180, 0x11181, 0x111B6, 0x111B7, 0x111B8, 0x111B9, 0x111BA, + 0x111BB, 0x111BC, 0x111BD, 0x111BE, 0x111C9, 0x111CA, 0x111CB, 0x111CC, + 0x111CF, 0x1122F, 0x11230, 0x11231, 0x11234, 0x11236, 0x11237, 0x1123E, + 0x112DF, 0x112E3, 0x112E4, 0x112E5, 0x112E6, 0x112E7, 0x112E8, 0x112E9, + 0x112EA, 0x11300, 0x11301, 0x1133B, 0x1133C, 0x11340, 0x11366, 0x11367, + 0x11368, 0x11369, 0x1136A, 0x1136B, 0x1136C, 0x11370, 0x11371, 0x11372, + 0x11373, 0x11374, 0x11438, 0x11439, 0x1143A, 0x1143B, 0x1143C, 0x1143D, + 0x1143E, 0x1143F, 0x11442, 0x11443, 0x11444, 0x11446, 0x1145E, 0x114B3, + 0x114B4, 0x114B5, 0x114B6, 0x114B7, 0x114B8, 0x114BA, 0x114BF, 0x114C0, + 0x114C2, 0x114C3, 0x115B2, 0x115B3, 0x115B4, 0x115B5, 0x115BC, 0x115BD, + 0x115BF, 0x115C0, 0x115DC, 0x115DD, 0x11633, 0x11634, 0x11635, 0x11636, + 0x11637, 0x11638, 0x11639, 0x1163A, 0x1163D, 0x1163F, 0x11640, 0x116AB, + 0x116AD, 0x116B0, 0x116B1, 0x116B2, 0x116B3, 0x116B4, 0x116B5, 0x116B7, + 0x1171D, 0x1171E, 0x1171F, 0x11722, 0x11723, 0x11724, 0x11725, 0x11727, + 0x11728, 0x11729, 0x1172A, 0x1172B, 0x1182F, 0x11830, 0x11831, 0x11832, + 0x11833, 0x11834, 0x11835, 0x11836, 0x11837, 0x11839, 0x1183A, 0x1193B, + 0x1193C, 0x1193E, 0x11943, 0x119D4, 0x119D5, 0x119D6, 0x119D7, 0x119DA, + 0x119DB, 0x119E0, 0x11A01, 0x11A02, 0x11A03, 0x11A04, 0x11A05, 0x11A06, + 0x11A07, 0x11A08, 0x11A09, 0x11A0A, 0x11A33, 0x11A34, 0x11A35, 0x11A36, + 0x11A37, 0x11A38, 0x11A3B, 0x11A3C, 0x11A3D, 0x11A3E, 0x11A47, 0x11A51, + 0x11A52, 0x11A53, 0x11A54, 0x11A55, 0x11A56, 0x11A59, 0x11A5A, 0x11A5B, + 0x11A8A, 0x11A8B, 0x11A8C, 0x11A8D, 0x11A8E, 0x11A8F, 0x11A90, 0x11A91, + 0x11A92, 0x11A93, 0x11A94, 0x11A95, 0x11A96, 0x11A98, 0x11A99, 0x11C30, + 0x11C31, 0x11C32, 0x11C33, 0x11C34, 0x11C35, 0x11C36, 0x11C38, 0x11C39, + 0x11C3A, 0x11C3B, 0x11C3C, 0x11C3D, 0x11C3F, 0x11C92, 0x11C93, 0x11C94, + 0x11C95, 0x11C96, 0x11C97, 0x11C98, 0x11C99, 0x11C9A, 0x11C9B, 0x11C9C, + 0x11C9D, 0x11C9E, 0x11C9F, 0x11CA0, 0x11CA1, 0x11CA2, 0x11CA3, 0x11CA4, + 0x11CA5, 0x11CA6, 0x11CA7, 0x11CAA, 0x11CAB, 0x11CAC, 0x11CAD, 0x11CAE, + 0x11CAF, 0x11CB0, 0x11CB2, 0x11CB3, 0x11CB5, 0x11CB6, 0x11D31, 0x11D32, + 0x11D33, 0x11D34, 0x11D35, 0x11D36, 0x11D3A, 0x11D3C, 0x11D3D, 0x11D3F, + 0x11D40, 0x11D41, 0x11D42, 0x11D43, 0x11D44, 0x11D45, 0x11D47, 0x11D90, + 0x11D91, 0x11D95, 0x11D97, 0x11EF3, 0x11EF4, 0x16AF0, 0x16AF1, 0x16AF2, + 0x16AF3, 0x16AF4, 0x16B30, 0x16B31, 0x16B32, 0x16B33, 0x16B34, 0x16B35, + 0x16B36, 0x16F4F, 0x16F8F, 0x16F90, 0x16F91, 0x16F92, 0x16FE4, 0x1BC9D, + 0x1BC9E, 0x1CF00, 0x1CF01, 0x1CF02, 0x1CF03, 0x1CF04, 0x1CF05, 0x1CF06, + 0x1CF07, 0x1CF08, 0x1CF09, 0x1CF0A, 0x1CF0B, 0x1CF0C, 0x1CF0D, 0x1CF0E, + 0x1CF0F, 0x1CF10, 0x1CF11, 0x1CF12, 0x1CF13, 0x1CF14, 0x1CF15, 0x1CF16, + 0x1CF17, 0x1CF18, 0x1CF19, 0x1CF1A, 0x1CF1B, 0x1CF1C, 0x1CF1D, 0x1CF1E, + 0x1CF1F, 0x1CF20, 0x1CF21, 0x1CF22, 0x1CF23, 0x1CF24, 0x1CF25, 0x1CF26, + 0x1CF27, 0x1CF28, 0x1CF29, 0x1CF2A, 0x1CF2B, 0x1CF2C, 0x1CF2D, 0x1CF30, + 0x1CF31, 0x1CF32, 0x1CF33, 0x1CF34, 0x1CF35, 0x1CF36, 0x1CF37, 0x1CF38, + 0x1CF39, 0x1CF3A, 0x1CF3B, 0x1CF3C, 0x1CF3D, 0x1CF3E, 0x1CF3F, 0x1CF40, + 0x1CF41, 0x1CF42, 0x1CF43, 0x1CF44, 0x1CF45, 0x1CF46, 0x1D167, 0x1D168, + 0x1D169, 0x1D17B, 0x1D17C, 0x1D17D, 0x1D17E, 0x1D17F, 0x1D180, 0x1D181, + 0x1D182, 0x1D185, 0x1D186, 0x1D187, 0x1D188, 0x1D189, 0x1D18A, 0x1D18B, + 0x1D1AA, 0x1D1AB, 0x1D1AC, 0x1D1AD, 0x1D242, 0x1D243, 0x1D244, 0x1DA00, + 0x1DA01, 0x1DA02, 0x1DA03, 0x1DA04, 0x1DA05, 0x1DA06, 0x1DA07, 0x1DA08, + 0x1DA09, 0x1DA0A, 0x1DA0B, 0x1DA0C, 0x1DA0D, 0x1DA0E, 0x1DA0F, 0x1DA10, + 0x1DA11, 0x1DA12, 0x1DA13, 0x1DA14, 0x1DA15, 0x1DA16, 0x1DA17, 0x1DA18, + 0x1DA19, 0x1DA1A, 0x1DA1B, 0x1DA1C, 0x1DA1D, 0x1DA1E, 0x1DA1F, 0x1DA20, + 0x1DA21, 0x1DA22, 0x1DA23, 0x1DA24, 0x1DA25, 0x1DA26, 0x1DA27, 0x1DA28, + 0x1DA29, 0x1DA2A, 0x1DA2B, 0x1DA2C, 0x1DA2D, 0x1DA2E, 0x1DA2F, 0x1DA30, + 0x1DA31, 0x1DA32, 0x1DA33, 0x1DA34, 0x1DA35, 0x1DA36, 0x1DA3B, 0x1DA3C, + 0x1DA3D, 0x1DA3E, 0x1DA3F, 0x1DA40, 0x1DA41, 0x1DA42, 0x1DA43, 0x1DA44, + 0x1DA45, 0x1DA46, 0x1DA47, 0x1DA48, 0x1DA49, 0x1DA4A, 0x1DA4B, 0x1DA4C, + 0x1DA4D, 0x1DA4E, 0x1DA4F, 0x1DA50, 0x1DA51, 0x1DA52, 0x1DA53, 0x1DA54, + 0x1DA55, 0x1DA56, 0x1DA57, 0x1DA58, 0x1DA59, 0x1DA5A, 0x1DA5B, 0x1DA5C, + 0x1DA5D, 0x1DA5E, 0x1DA5F, 0x1DA60, 0x1DA61, 0x1DA62, 0x1DA63, 0x1DA64, + 0x1DA65, 0x1DA66, 0x1DA67, 0x1DA68, 0x1DA69, 0x1DA6A, 0x1DA6B, 0x1DA6C, + 0x1DA75, 0x1DA84, 0x1DA9B, 0x1DA9C, 0x1DA9D, 0x1DA9E, 0x1DA9F, 0x1DAA1, + 0x1DAA2, 0x1DAA3, 0x1DAA4, 0x1DAA5, 0x1DAA6, 0x1DAA7, 0x1DAA8, 0x1DAA9, + 0x1DAAA, 0x1DAAB, 0x1DAAC, 0x1DAAD, 0x1DAAE, 0x1DAAF, 0x1E000, 0x1E001, + 0x1E002, 0x1E003, 0x1E004, 0x1E005, 0x1E006, 0x1E008, 0x1E009, 0x1E00A, + 0x1E00B, 0x1E00C, 0x1E00D, 0x1E00E, 0x1E00F, 0x1E010, 0x1E011, 0x1E012, + 0x1E013, 0x1E014, 0x1E015, 0x1E016, 0x1E017, 0x1E018, 0x1E01B, 0x1E01C, + 0x1E01D, 0x1E01E, 0x1E01F, 0x1E020, 0x1E021, 0x1E023, 0x1E024, 0x1E026, + 0x1E027, 0x1E028, 0x1E029, 0x1E02A, 0x1E130, 0x1E131, 0x1E132, 0x1E133, + 0x1E134, 0x1E135, 0x1E136, 0x1E2AE, 0x1E2EC, 0x1E2ED, 0x1E2EE, 0x1E2EF, + 0x1E8D0, 0x1E8D1, 0x1E8D2, 0x1E8D3, 0x1E8D4, 0x1E8D5, 0x1E8D6, 0x1E944, + 0x1E945, 0x1E946, 0x1E947, 0x1E948, 0x1E949, 0x1E94A, 0xE0100, 0xE0101, + 0xE0102, 0xE0103, 0xE0104, 0xE0105, 0xE0106, 0xE0107, 0xE0108, 0xE0109, + 0xE010A, 0xE010B, 0xE010C, 0xE010D, 0xE010E, 0xE010F, 0xE0110, 0xE0111, + 0xE0112, 0xE0113, 0xE0114, 0xE0115, 0xE0116, 0xE0117, 0xE0118, 0xE0119, + 0xE011A, 0xE011B, 0xE011C, 0xE011D, 0xE011E, 0xE011F, 0xE0120, 0xE0121, + 0xE0122, 0xE0123, 0xE0124, 0xE0125, 0xE0126, 0xE0127, 0xE0128, 0xE0129, + 0xE012A, 0xE012B, 0xE012C, 0xE012D, 0xE012E, 0xE012F, 0xE0130, 0xE0131, + 0xE0132, 0xE0133, 0xE0134, 0xE0135, 0xE0136, 0xE0137, 0xE0138, 0xE0139, + 0xE013A, 0xE013B, 0xE013C, 0xE013D, 0xE013E, 0xE013F, 0xE0140, 0xE0141, + 0xE0142, 0xE0143, 0xE0144, 0xE0145, 0xE0146, 0xE0147, 0xE0148, 0xE0149, + 0xE014A, 0xE014B, 0xE014C, 0xE014D, 0xE014E, 0xE014F, 0xE0150, 0xE0151, + 0xE0152, 0xE0153, 0xE0154, 0xE0155, 0xE0156, 0xE0157, 0xE0158, 0xE0159, + 0xE015A, 0xE015B, 0xE015C, 0xE015D, 0xE015E, 0xE015F, 0xE0160, 0xE0161, + 0xE0162, 0xE0163, 0xE0164, 0xE0165, 0xE0166, 0xE0167, 0xE0168, 0xE0169, + 0xE016A, 0xE016B, 0xE016C, 0xE016D, 0xE016E, 0xE016F, 0xE0170, 0xE0171, + 0xE0172, 0xE0173, 0xE0174, 0xE0175, 0xE0176, 0xE0177, 0xE0178, 0xE0179, + 0xE017A, 0xE017B, 0xE017C, 0xE017D, 0xE017E, 0xE017F, 0xE0180, 0xE0181, + 0xE0182, 0xE0183, 0xE0184, 0xE0185, 0xE0186, 0xE0187, 0xE0188, 0xE0189, + 0xE018A, 0xE018B, 0xE018C, 0xE018D, 0xE018E, 0xE018F, 0xE0190, 0xE0191, + 0xE0192, 0xE0193, 0xE0194, 0xE0195, 0xE0196, 0xE0197, 0xE0198, 0xE0199, + 0xE019A, 0xE019B, 0xE019C, 0xE019D, 0xE019E, 0xE019F, 0xE01A0, 0xE01A1, + 0xE01A2, 0xE01A3, 0xE01A4, 0xE01A5, 0xE01A6, 0xE01A7, 0xE01A8, 0xE01A9, + 0xE01AA, 0xE01AB, 0xE01AC, 0xE01AD, 0xE01AE, 0xE01AF, 0xE01B0, 0xE01B1, + 0xE01B2, 0xE01B3, 0xE01B4, 0xE01B5, 0xE01B6, 0xE01B7, 0xE01B8, 0xE01B9, + 0xE01BA, 0xE01BB, 0xE01BC, 0xE01BD, 0xE01BE, 0xE01BF, 0xE01C0, 0xE01C1, + 0xE01C2, 0xE01C3, 0xE01C4, 0xE01C5, 0xE01C6, 0xE01C7, 0xE01C8, 0xE01C9, + 0xE01CA, 0xE01CB, 0xE01CC, 0xE01CD, 0xE01CE, 0xE01CF, 0xE01D0, 0xE01D1, + 0xE01D2, 0xE01D3, 0xE01D4, 0xE01D5, 0xE01D6, 0xE01D7, 0xE01D8, 0xE01D9, + 0xE01DA, 0xE01DB, 0xE01DC, 0xE01DD, 0xE01DE, 0xE01DF, 0xE01E0, 0xE01E1, + 0xE01E2, 0xE01E3, 0xE01E4, 0xE01E5, 0xE01E6, 0xE01E7, 0xE01E8, 0xE01E9, + 0xE01EA, 0xE01EB, 0xE01EC, 0xE01ED, 0xE01EE, 0xE01EF, +}; + +static unsigned long combiningCharTableSize = sizeof(combiningCharTable) / sizeof(combiningCharTable[0]); + +/* Check if the code is a wide character + */ +static int isWideChar(unsigned long cp) { + size_t i; + for (i = 0; i < wideCharTableSize; i++) + if (wideCharTable[i][0] <= cp && cp <= wideCharTable[i][1]) return 1; + return 0; +} + +/* Check if the code is a combining character + */ +static int isCombiningChar(unsigned long cp) { + size_t i; + for (i = 0; i < combiningCharTableSize; i++) + if (combiningCharTable[i] == cp) return 1; + return 0; +} + +/* Get length of previous UTF8 character + */ +static size_t prevUtf8CharLen(const char* buf, int pos) { + int end = pos--; + while (pos >= 0 && ((unsigned char)buf[pos] & 0xC0) == 0x80) + pos--; + return end - pos; +} + +/* Convert UTF8 to Unicode code point + */ +static size_t utf8BytesToCodePoint(const char* buf, size_t len, int* cp) { + if (len) { + unsigned char byte = buf[0]; + if ((byte & 0x80) == 0) { + *cp = byte; + return 1; + } else if ((byte & 0xE0) == 0xC0) { + if (len >= 2) { + *cp = (((unsigned long)(buf[0] & 0x1F)) << 6) | + ((unsigned long)(buf[1] & 0x3F)); + return 2; + } + } else if ((byte & 0xF0) == 0xE0) { + if (len >= 3) { + *cp = (((unsigned long)(buf[0] & 0x0F)) << 12) | + (((unsigned long)(buf[1] & 0x3F)) << 6) | + ((unsigned long)(buf[2] & 0x3F)); + return 3; + } + } else if ((byte & 0xF8) == 0xF0) { + if (len >= 4) { + *cp = (((unsigned long)(buf[0] & 0x07)) << 18) | + (((unsigned long)(buf[1] & 0x3F)) << 12) | + (((unsigned long)(buf[2] & 0x3F)) << 6) | + ((unsigned long)(buf[3] & 0x3F)); + return 4; + } + } + } + return 0; +} + +/* Get length of next grapheme + */ +size_t linenoiseUtf8NextCharLen(const char* buf, size_t buf_len, size_t pos, size_t *col_len) { + size_t beg = pos; + int cp; + size_t len = utf8BytesToCodePoint(buf + pos, buf_len - pos, &cp); + if (isCombiningChar(cp)) { + /* NOTREACHED */ + return 0; + } + if (col_len != NULL) *col_len = isWideChar(cp) ? 2 : 1; + pos += len; + while (pos < buf_len) { + len = utf8BytesToCodePoint(buf + pos, buf_len - pos, &cp); + if (!isCombiningChar(cp)) return pos - beg; + pos += len; + } + return pos - beg; +} + +/* Get length of previous grapheme + */ +size_t linenoiseUtf8PrevCharLen(const char* buf, size_t UNUSED(buf_len), size_t pos, size_t *col_len) { + size_t end = pos; + while (pos > 0) { + size_t len = prevUtf8CharLen(buf, pos); + pos -= len; + int cp; + utf8BytesToCodePoint(buf + pos, len, &cp); + if (!isCombiningChar(cp)) { + if (col_len != NULL) *col_len = isWideChar(cp) ? 2 : 1; + return end - pos; + } + } + /* NOTREACHED */ + return 0; +} + +/* Read a Unicode from file. + */ +size_t linenoiseUtf8ReadCode(int fd, char* buf, size_t buf_len, int* cp) { + if (buf_len < 1) return -1; + size_t nread = read(fd,&buf[0],1); + if (nread <= 0) return nread; + + unsigned char byte = buf[0]; + if ((byte & 0x80) == 0) { + ; + } else if ((byte & 0xE0) == 0xC0) { + if (buf_len < 2) return -1; + nread = read(fd,&buf[1],1); + if (nread <= 0) return nread; + } else if ((byte & 0xF0) == 0xE0) { + if (buf_len < 3) return -1; + nread = read(fd,&buf[1],2); + if (nread <= 0) return nread; + } else if ((byte & 0xF8) == 0xF0) { + if (buf_len < 3) return -1; + nread = read(fd,&buf[1],3); + if (nread <= 0) return nread; + } else { + return -1; + } + + return utf8BytesToCodePoint(buf, buf_len, cp); +} diff --git a/tools/lint/linenoise/linenoise.h b/tools/lint/linenoise/utf8.h similarity index 50% copy from tools/lint/linenoise/linenoise.h copy to tools/lint/linenoise/utf8.h index 8362b1f..d401bc8 100644 --- a/tools/lint/linenoise/linenoise.h +++ b/tools/lint/linenoise/utf8.h @@ -1,4 +1,4 @@ -/* linenoise.h -- VERSION 1.0 +/* encodings/utf8.h -- VERSION 1.0 * * Guerrilla line editing library against the idea that a line editing lib * needs to be 20,000 lines of C code. @@ -36,59 +36,20 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef __LINENOISE_H -#define __LINENOISE_H - -#include +#ifndef __LINENOISE_ENCODINGS_UTF8_H +#define __LINENOISE_ENCODINGS_UTF8_H #ifdef __cplusplus extern "C" { #endif -struct linenoiseState { - int ifd; /* Terminal stdin file descriptor. */ - int ofd; /* Terminal stdout file descriptor. */ - char *buf; /* Edited line buffer. */ - size_t buflen; /* Edited line buffer size. */ - const char *prompt; /* Prompt to display. */ - size_t plen; /* Prompt length. */ - size_t pos; /* Current cursor position. */ - size_t oldpos; /* Previous refresh cursor position. */ - size_t len; /* Current edited line length. */ - size_t cols; /* Number of columns in terminal. */ - size_t maxrows; /* Maximum num of rows used so far (multiline mode) */ - int rawmode; - int history_index; /* The history index we are currently editing. */ -}; - -extern struct linenoiseState lss; - -typedef struct linenoiseCompletions { - int path; - size_t len; - char **cvec; -} linenoiseCompletions; - -typedef void(linenoiseCompletionCallback)(const char *, const char *, linenoiseCompletions *); -void linenoiseSetCompletionCallback(linenoiseCompletionCallback *); -void linenoiseAddCompletion(linenoiseCompletions *, const char *); - -char *linenoise(const char *prompt); -int linenoiseHistoryAdd(const char *line); -int linenoiseHistorySetMaxLen(int len); -int linenoiseHistorySave(const char *filename); -int linenoiseHistoryLoad(const char *filename); -void linenoiseClearScreen(void); -void linenoiseSetMultiLine(int ml); -void linenoisePrintKeyCodes(void); - -void linenoisePathCompletion(const char *, const char *, linenoiseCompletions *); -void linenoiseRefreshLine(void); -int linenoiseEnableRawMode(int fd); -void linenoiseDisableRawMode(int fd); +size_t linenoiseUtf8PrevCharLen(const char* buf, size_t buf_len, size_t pos, size_t *col_len); +size_t linenoiseUtf8NextCharLen(const char* buf, size_t buf_len, size_t pos, size_t *col_len); +size_t linenoiseUtf8ReadCode(int fd, char* buf, size_t buf_len, int* cp); #ifdef __cplusplus } #endif -#endif /* __LINENOISE_H */ +#endif /* __LINENOISE_ENCODINGS_UTF8_H */ + diff --git a/tools/lint/main.c b/tools/lint/main.c index 43b90c8..d57ad99 100644 --- a/tools/lint/main.c +++ b/tools/lint/main.c @@ -28,6 +28,7 @@ #include "completion.h" #include "configuration.h" #include "linenoise/linenoise.h" +#include "linenoise/utf8.h" #include "yl_opt.h" int done; @@ -53,6 +54,8 @@ main(int argc, char *argv[]) /* continue in interactive mode */ linenoiseSetCompletionCallback(complete_cmd); + linenoiseSetEncodingFunctions(linenoiseUtf8PrevCharLen, linenoiseUtf8NextCharLen, linenoiseUtf8ReadCode); + linenoiseSetMultiLine(1); load_config(); if (ly_ctx_new(NULL, YL_DEFAULT_CTX_OPTIONS, &ctx)) {