From fbd822816f154d3a4f99225e5eac7b2886ff0fcd Mon Sep 17 00:00:00 2001 From: roman Date: Thu, 16 Jan 2025 16:13:14 +0100 Subject: [PATCH 01/25] plugins types REFACTOR shorter ids --- src/plugins_types/binary.c | 2 +- src/plugins_types/bits.c | 2 +- src/plugins_types/boolean.c | 2 +- src/plugins_types/date_and_time.c | 2 +- src/plugins_types/decimal64.c | 2 +- src/plugins_types/empty.c | 2 +- src/plugins_types/enumeration.c | 2 +- src/plugins_types/hex_string.c | 8 ++++---- src/plugins_types/identityref.c | 2 +- src/plugins_types/instanceid.c | 2 +- src/plugins_types/instanceid_keys.c | 2 +- src/plugins_types/integer.c | 16 ++++++++-------- src/plugins_types/ipv4_address.c | 2 +- src/plugins_types/ipv4_address_no_zone.c | 2 +- src/plugins_types/ipv4_prefix.c | 2 +- src/plugins_types/ipv6_address.c | 2 +- src/plugins_types/ipv6_address_no_zone.c | 2 +- src/plugins_types/ipv6_prefix.c | 2 +- src/plugins_types/leafref.c | 2 +- src/plugins_types/lyds_tree.c | 2 +- src/plugins_types/node_instanceid.c | 4 ++-- src/plugins_types/string.c | 2 +- src/plugins_types/time_period.c | 2 +- src/plugins_types/union.c | 2 +- src/plugins_types/xpath1.0.c | 2 +- tests/utests/types/binary.c | 2 +- tests/utests/types/bits.c | 2 +- tests/utests/types/int8.c | 2 +- tests/utests/types/string.c | 2 +- tests/utests/types/union.c | 14 +++++++------- 30 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/plugins_types/binary.c b/src/plugins_types/binary.c index a0204385d..24f2c2960 100644 --- a/src/plugins_types/binary.c +++ b/src/plugins_types/binary.c @@ -471,7 +471,7 @@ const struct lyplg_type_record plugins_binary[] = { .revision = NULL, .name = LY_TYPE_BINARY_STR, - .plugin.id = "libyang 2 - binary, version 1", + .plugin.id = "ly2 - binary", .plugin.store = lyplg_type_store_binary, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_binary, diff --git a/src/plugins_types/bits.c b/src/plugins_types/bits.c index badf2b1e9..cdeb84d34 100644 --- a/src/plugins_types/bits.c +++ b/src/plugins_types/bits.c @@ -507,7 +507,7 @@ const struct lyplg_type_record plugins_bits[] = { .revision = NULL, .name = LY_TYPE_BITS_STR, - .plugin.id = "libyang 2 - bits, version 1", + .plugin.id = "ly2 - bits", .plugin.store = lyplg_type_store_bits, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_bits, diff --git a/src/plugins_types/boolean.c b/src/plugins_types/boolean.c index 3e055d278..42b7918d4 100644 --- a/src/plugins_types/boolean.c +++ b/src/plugins_types/boolean.c @@ -159,7 +159,7 @@ const struct lyplg_type_record plugins_boolean[] = { .revision = NULL, .name = LY_TYPE_BOOL_STR, - .plugin.id = "libyang 2 - boolean, version 1", + .plugin.id = "ly2 - boolean", .plugin.store = lyplg_type_store_boolean, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_boolean, diff --git a/src/plugins_types/date_and_time.c b/src/plugins_types/date_and_time.c index 1d013c15f..c2aaf794e 100644 --- a/src/plugins_types/date_and_time.c +++ b/src/plugins_types/date_and_time.c @@ -386,7 +386,7 @@ const struct lyplg_type_record plugins_date_and_time[] = { .revision = "2013-07-15", .name = "date-and-time", - .plugin.id = "libyang 2 - date-and-time, version 1", + .plugin.id = "ly2 - date-and-time", .plugin.store = lyplg_type_store_date_and_time, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_date_and_time, diff --git a/src/plugins_types/decimal64.c b/src/plugins_types/decimal64.c index a6ac54b55..5a9b7ab2d 100644 --- a/src/plugins_types/decimal64.c +++ b/src/plugins_types/decimal64.c @@ -237,7 +237,7 @@ const struct lyplg_type_record plugins_decimal64[] = { .revision = NULL, .name = LY_TYPE_DEC64_STR, - .plugin.id = "libyang 2 - decimal64, version 1", + .plugin.id = "ly2 - decimal64", .plugin.store = lyplg_type_store_decimal64, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_decimal64, diff --git a/src/plugins_types/empty.c b/src/plugins_types/empty.c index b7b82dcfd..8b88e6154 100644 --- a/src/plugins_types/empty.c +++ b/src/plugins_types/empty.c @@ -89,7 +89,7 @@ const struct lyplg_type_record plugins_empty[] = { .revision = NULL, .name = LY_TYPE_EMPTY_STR, - .plugin.id = "libyang 2 - empty, version 1", + .plugin.id = "ly2 - empty", .plugin.store = lyplg_type_store_empty, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, diff --git a/src/plugins_types/enumeration.c b/src/plugins_types/enumeration.c index 462b7e3bc..d3159a6e3 100644 --- a/src/plugins_types/enumeration.c +++ b/src/plugins_types/enumeration.c @@ -201,7 +201,7 @@ const struct lyplg_type_record plugins_enumeration[] = { .revision = NULL, .name = LY_TYPE_ENUM_STR, - .plugin.id = "libyang 2 - enumeration, version 1", + .plugin.id = "ly2 - enumeration", .plugin.store = lyplg_type_store_enum, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, diff --git a/src/plugins_types/hex_string.c b/src/plugins_types/hex_string.c index b013cf407..285967b67 100644 --- a/src/plugins_types/hex_string.c +++ b/src/plugins_types/hex_string.c @@ -118,7 +118,7 @@ const struct lyplg_type_record plugins_hex_string[] = { .revision = "2013-07-15", .name = "phys-address", - .plugin.id = "libyang 2 - hex-string, version 1", + .plugin.id = "ly2 - hex-string", .plugin.store = lyplg_type_store_hex_string, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, @@ -133,7 +133,7 @@ const struct lyplg_type_record plugins_hex_string[] = { .revision = "2013-07-15", .name = "mac-address", - .plugin.id = "libyang 2 - hex-string, version 1", + .plugin.id = "ly2 - hex-string", .plugin.store = lyplg_type_store_hex_string, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, @@ -148,7 +148,7 @@ const struct lyplg_type_record plugins_hex_string[] = { .revision = "2013-07-15", .name = "hex-string", - .plugin.id = "libyang 2 - hex-string, version 1", + .plugin.id = "ly2 - hex-string", .plugin.store = lyplg_type_store_hex_string, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, @@ -163,7 +163,7 @@ const struct lyplg_type_record plugins_hex_string[] = { .revision = "2013-07-15", .name = "uuid", - .plugin.id = "libyang 2 - hex-string, version 1", + .plugin.id = "ly2 - hex-string", .plugin.store = lyplg_type_store_hex_string, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, diff --git a/src/plugins_types/identityref.c b/src/plugins_types/identityref.c index 757595cdb..9941b4a38 100644 --- a/src/plugins_types/identityref.c +++ b/src/plugins_types/identityref.c @@ -354,7 +354,7 @@ const struct lyplg_type_record plugins_identityref[] = { .revision = NULL, .name = LY_TYPE_IDENT_STR, - .plugin.id = "libyang 2 - identityref, version 1", + .plugin.id = "ly2 - identityref", .plugin.store = lyplg_type_store_identityref, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_identityref, diff --git a/src/plugins_types/instanceid.c b/src/plugins_types/instanceid.c index fb0ac21a9..78f221b87 100644 --- a/src/plugins_types/instanceid.c +++ b/src/plugins_types/instanceid.c @@ -321,7 +321,7 @@ const struct lyplg_type_record plugins_instanceid[] = { .revision = NULL, .name = LY_TYPE_INST_STR, - .plugin.id = "libyang 2 - instance-identifier, version 1", + .plugin.id = "ly2 - instance-identifier", .plugin.store = lyplg_type_store_instanceid, .plugin.validate = lyplg_type_validate_instanceid, .plugin.compare = lyplg_type_compare_simple, diff --git a/src/plugins_types/instanceid_keys.c b/src/plugins_types/instanceid_keys.c index 12d28e5d4..6d7423cad 100644 --- a/src/plugins_types/instanceid_keys.c +++ b/src/plugins_types/instanceid_keys.c @@ -239,7 +239,7 @@ const struct lyplg_type_record plugins_instanceid_keys[] = { .revision = NULL, .name = "instance-identifier-keys", - .plugin.id = "libyang 2 - instance-identifier-keys, version 1", + .plugin.id = "ly2 - instance-identifier-keys", .plugin.store = lyplg_type_store_instanceid_keys, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, diff --git a/src/plugins_types/integer.c b/src/plugins_types/integer.c index ac165acdb..5a52ad7fb 100644 --- a/src/plugins_types/integer.c +++ b/src/plugins_types/integer.c @@ -565,7 +565,7 @@ const struct lyplg_type_record plugins_integer[] = { .revision = NULL, .name = LY_TYPE_UINT8_STR, - .plugin.id = "libyang 2 - integers, version 1", + .plugin.id = "ly2 - integers", .plugin.store = lyplg_type_store_uint, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_uint, @@ -579,7 +579,7 @@ const struct lyplg_type_record plugins_integer[] = { .revision = NULL, .name = LY_TYPE_UINT16_STR, - .plugin.id = "libyang 2 - integers, version 1", + .plugin.id = "ly2 - integers", .plugin.store = lyplg_type_store_uint, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_uint, @@ -593,7 +593,7 @@ const struct lyplg_type_record plugins_integer[] = { .revision = NULL, .name = LY_TYPE_UINT32_STR, - .plugin.id = "libyang 2 - integers, version 1", + .plugin.id = "ly2 - integers", .plugin.store = lyplg_type_store_uint, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_uint, @@ -607,7 +607,7 @@ const struct lyplg_type_record plugins_integer[] = { .revision = NULL, .name = LY_TYPE_UINT64_STR, - .plugin.id = "libyang 2 - integers, version 1", + .plugin.id = "ly2 - integers", .plugin.store = lyplg_type_store_uint, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_uint, @@ -621,7 +621,7 @@ const struct lyplg_type_record plugins_integer[] = { .revision = NULL, .name = LY_TYPE_INT8_STR, - .plugin.id = "libyang 2 - integers, version 1", + .plugin.id = "ly2 - integers", .plugin.store = lyplg_type_store_int, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_int, @@ -635,7 +635,7 @@ const struct lyplg_type_record plugins_integer[] = { .revision = NULL, .name = LY_TYPE_INT16_STR, - .plugin.id = "libyang 2 - integers, version 1", + .plugin.id = "ly2 - integers", .plugin.store = lyplg_type_store_int, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_int, @@ -649,7 +649,7 @@ const struct lyplg_type_record plugins_integer[] = { .revision = NULL, .name = LY_TYPE_INT32_STR, - .plugin.id = "libyang 2 - integers, version 1", + .plugin.id = "ly2 - integers", .plugin.store = lyplg_type_store_int, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_int, @@ -663,7 +663,7 @@ const struct lyplg_type_record plugins_integer[] = { .revision = NULL, .name = LY_TYPE_INT64_STR, - .plugin.id = "libyang 2 - integers, version 1", + .plugin.id = "ly2 - integers", .plugin.store = lyplg_type_store_int, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_int, diff --git a/src/plugins_types/ipv4_address.c b/src/plugins_types/ipv4_address.c index 0ed6d36a1..98d88c6f3 100644 --- a/src/plugins_types/ipv4_address.c +++ b/src/plugins_types/ipv4_address.c @@ -392,7 +392,7 @@ const struct lyplg_type_record plugins_ipv4_address[] = { .revision = "2013-07-15", .name = "ipv4-address", - .plugin.id = "libyang 2 - ipv4-address, version 1", + .plugin.id = "ly2 - ipv4-address", .plugin.store = lyplg_type_store_ipv4_address, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_ipv4_address, diff --git a/src/plugins_types/ipv4_address_no_zone.c b/src/plugins_types/ipv4_address_no_zone.c index 5a0f00900..ffe1cbac4 100644 --- a/src/plugins_types/ipv4_address_no_zone.c +++ b/src/plugins_types/ipv4_address_no_zone.c @@ -209,7 +209,7 @@ const struct lyplg_type_record plugins_ipv4_address_no_zone[] = { .revision = "2013-07-15", .name = "ipv4-address-no-zone", - .plugin.id = "libyang 2 - ipv4-address-no-zone, version 1", + .plugin.id = "ly2 - ipv4-address-no-zone", .plugin.store = lyplg_type_store_ipv4_address_no_zone, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_ipv4_address_no_zone, diff --git a/src/plugins_types/ipv4_prefix.c b/src/plugins_types/ipv4_prefix.c index 4d1916ef8..7f422cce0 100644 --- a/src/plugins_types/ipv4_prefix.c +++ b/src/plugins_types/ipv4_prefix.c @@ -339,7 +339,7 @@ const struct lyplg_type_record plugins_ipv4_prefix[] = { .revision = "2013-07-15", .name = "ipv4-prefix", - .plugin.id = "libyang 2 - ipv4-prefix, version 1", + .plugin.id = "ly2 - ipv4-prefix", .plugin.store = lyplg_type_store_ipv4_prefix, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_ipv4_prefix, diff --git a/src/plugins_types/ipv6_address.c b/src/plugins_types/ipv6_address.c index 147df3e45..8b0057de4 100644 --- a/src/plugins_types/ipv6_address.c +++ b/src/plugins_types/ipv6_address.c @@ -394,7 +394,7 @@ const struct lyplg_type_record plugins_ipv6_address[] = { .revision = "2013-07-15", .name = "ipv6-address", - .plugin.id = "libyang 2 - ipv6-address, version 1", + .plugin.id = "ly2 - ipv6-address", .plugin.store = lyplg_type_store_ipv6_address, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_ipv6_address, diff --git a/src/plugins_types/ipv6_address_no_zone.c b/src/plugins_types/ipv6_address_no_zone.c index 76d47ae25..b4422cd33 100644 --- a/src/plugins_types/ipv6_address_no_zone.c +++ b/src/plugins_types/ipv6_address_no_zone.c @@ -300,7 +300,7 @@ const struct lyplg_type_record plugins_ipv6_address_no_zone[] = { .revision = "2013-07-15", .name = "ipv6-address-no-zone", - .plugin.id = "libyang 2 - ipv6-address-no-zone, version 1", + .plugin.id = "ly2 - ipv6-address-no-zone", .plugin.store = lyplg_type_store_ipv6_address_no_zone, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_ipv6_address_no_zone, diff --git a/src/plugins_types/ipv6_prefix.c b/src/plugins_types/ipv6_prefix.c index 4643e8523..6730172a2 100644 --- a/src/plugins_types/ipv6_prefix.c +++ b/src/plugins_types/ipv6_prefix.c @@ -353,7 +353,7 @@ const struct lyplg_type_record plugins_ipv6_prefix[] = { .revision = "2013-07-15", .name = "ipv6-prefix", - .plugin.id = "libyang 2 - ipv6-prefix, version 1", + .plugin.id = "ly2 - ipv6-prefix", .plugin.store = lyplg_type_store_ipv6_prefix, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_ipv6_prefix, diff --git a/src/plugins_types/leafref.c b/src/plugins_types/leafref.c index 5863895f9..78c3280bc 100644 --- a/src/plugins_types/leafref.c +++ b/src/plugins_types/leafref.c @@ -145,7 +145,7 @@ const struct lyplg_type_record plugins_leafref[] = { .revision = NULL, .name = LY_TYPE_LEAFREF_STR, - .plugin.id = "libyang 2 - leafref, version 1", + .plugin.id = "ly2 - leafref", .plugin.store = lyplg_type_store_leafref, .plugin.validate = lyplg_type_validate_leafref, .plugin.compare = lyplg_type_compare_leafref, diff --git a/src/plugins_types/lyds_tree.c b/src/plugins_types/lyds_tree.c index 4dc73fb7b..9dbe28e7b 100644 --- a/src/plugins_types/lyds_tree.c +++ b/src/plugins_types/lyds_tree.c @@ -132,7 +132,7 @@ const struct lyplg_type_record plugins_lyds_tree[] = { .revision = NULL, .name = "lyds_tree", - .plugin.id = "libyang 2 - lyds_tree, version 1", + .plugin.id = "ly2 - lyds_tree", .plugin.store = lyplg_type_store_lyds, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_lyds, diff --git a/src/plugins_types/node_instanceid.c b/src/plugins_types/node_instanceid.c index f5d074990..34f5ff7fa 100644 --- a/src/plugins_types/node_instanceid.c +++ b/src/plugins_types/node_instanceid.c @@ -334,7 +334,7 @@ const struct lyplg_type_record plugins_node_instanceid[] = { .revision = "2012-02-22", .name = "node-instance-identifier", - .plugin.id = "libyang 2 - node-instance-identifier, version 1", + .plugin.id = "ly2 - node-instance-identifier", .plugin.store = lyplg_type_store_node_instanceid, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, @@ -349,7 +349,7 @@ const struct lyplg_type_record plugins_node_instanceid[] = { .revision = "2018-02-14", .name = "node-instance-identifier", - .plugin.id = "libyang 2 - node-instance-identifier, version 1", + .plugin.id = "ly2 - node-instance-identifier", .plugin.store = lyplg_type_store_node_instanceid, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, diff --git a/src/plugins_types/string.c b/src/plugins_types/string.c index d1888f398..c998aeec8 100644 --- a/src/plugins_types/string.c +++ b/src/plugins_types/string.c @@ -130,7 +130,7 @@ const struct lyplg_type_record plugins_string[] = { .revision = NULL, .name = LY_TYPE_STRING_STR, - .plugin.id = "libyang 2 - string, version 1", + .plugin.id = "ly2 - string", .plugin.store = lyplg_type_store_string, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, diff --git a/src/plugins_types/time_period.c b/src/plugins_types/time_period.c index e2fbcd6f3..4e76cf42a 100644 --- a/src/plugins_types/time_period.c +++ b/src/plugins_types/time_period.c @@ -86,7 +86,7 @@ const struct lyplg_type_record plugins_time_period[] = { .revision = "2024-07-09", .name = "time-period", - .plugin.id = "libyang 2 - time-period, version 1", + .plugin.id = "ly2 - time-period", .plugin.store = lyplg_type_store_string, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, diff --git a/src/plugins_types/union.c b/src/plugins_types/union.c index 64281c61e..cd1574cbb 100644 --- a/src/plugins_types/union.c +++ b/src/plugins_types/union.c @@ -691,7 +691,7 @@ const struct lyplg_type_record plugins_union[] = { .revision = NULL, .name = LY_TYPE_UNION_STR, - .plugin.id = "libyang 2 - union,version 1", + .plugin.id = "ly2 - union", .plugin.store = lyplg_type_store_union, .plugin.validate = lyplg_type_validate_union, .plugin.compare = lyplg_type_compare_union, diff --git a/src/plugins_types/xpath1.0.c b/src/plugins_types/xpath1.0.c index 0c5dfce2d..8af4ede6a 100644 --- a/src/plugins_types/xpath1.0.c +++ b/src/plugins_types/xpath1.0.c @@ -524,7 +524,7 @@ const struct lyplg_type_record plugins_xpath10[] = { .revision = "2013-07-15", .name = "xpath1.0", - .plugin.id = "libyang 2 - xpath1.0, version 1", + .plugin.id = "ly2 - xpath1.0", .plugin.store = lyplg_type_store_xpath10, .plugin.validate = lyplg_type_validate_xpath10, .plugin.compare = lyplg_type_compare_simple, diff --git a/tests/utests/types/binary.c b/tests/utests/types/binary.c index efdc8f112..6abf26fb8 100644 --- a/tests/utests/types/binary.c +++ b/tests/utests/types/binary.c @@ -63,7 +63,7 @@ test_plugin_store(void **state) lysc_type2 = ((struct lysc_node_leaf *)mod->compiled->data->next)->type; /* check proper type */ - assert_string_equal("libyang 2 - binary, version 1", type->id); + assert_string_equal("ly2 - binary", type->id); /* check store XML double pad */ val = "YWhveQ=="; diff --git a/tests/utests/types/bits.c b/tests/utests/types/bits.c index 35553773d..dab299a6b 100644 --- a/tests/utests/types/bits.c +++ b/tests/utests/types/bits.c @@ -814,7 +814,7 @@ test_plugin_store(void **state) lysc_type = ((struct lysc_node_leaf *)mod->compiled->data)->type; /* check proper type */ - assert_string_equal("libyang 2 - bits, version 1", type->id); + assert_string_equal("ly2 - bits", type->id); /* check store */ diff --git a/tests/utests/types/int8.c b/tests/utests/types/int8.c index f40c1ddc2..0be4ad83d 100644 --- a/tests/utests/types/int8.c +++ b/tests/utests/types/int8.c @@ -1412,7 +1412,7 @@ test_plugin_store(void **state) lysc_type = ((struct lysc_node_leaf *)mod->compiled->data)->type; /* check proper type */ - assert_string_equal("libyang 2 - integers, version 1", type->id); + assert_string_equal("ly2 - integers", type->id); /* check store * options = LY_TYPE_STORE_IMPLEMENT | LY_TYPE_STORE_DYNAMIC diff --git a/tests/utests/types/string.c b/tests/utests/types/string.c index 2f002b73a..a3d590e50 100644 --- a/tests/utests/types/string.c +++ b/tests/utests/types/string.c @@ -1073,7 +1073,7 @@ test_plugin_store(void **state) lysc_type = ((struct lysc_node_leaf *) mod->compiled->data)->type; /* check proper type */ - assert_string_equal("libyang 2 - string, version 1", type->id); + assert_string_equal("ly2 - string", type->id); /* check store */ val_text = "20"; diff --git a/tests/utests/types/union.c b/tests/utests/types/union.c index c2541aaaf..573abc7bf 100644 --- a/tests/utests/types/union.c +++ b/tests/utests/types/union.c @@ -105,11 +105,11 @@ test_data_xml(void **state) TEST_ERROR_XML2("", "defs", "", "un1", "123456789012345678901", LY_EVALID); CHECK_LOG_CTX("Invalid union value \"123456789012345678901\" - no matching subtype found:\n" - " libyang 2 - leafref, version 1: Invalid type int8 value \"123456789012345678901\".\n" - " libyang 2 - leafref, version 1: Invalid type int64 value \"123456789012345678901\".\n" - " libyang 2 - identityref, version 1: Invalid identityref \"123456789012345678901\" value - identity not found in module \"defs\".\n" - " libyang 2 - instance-identifier, version 1: Invalid instance-identifier \"123456789012345678901\" value - syntax error.\n" - " libyang 2 - string, version 1: Unsatisfied length - string \"123456789012345678901\" length is not allowed.\n", + " ly2 - leafref: Invalid type int8 value \"123456789012345678901\".\n" + " ly2 - leafref: Invalid type int64 value \"123456789012345678901\".\n" + " ly2 - identityref: Invalid identityref \"123456789012345678901\" value - identity not found in module \"defs\".\n" + " ly2 - instance-identifier: Invalid instance-identifier \"123456789012345678901\" value - syntax error.\n" + " ly2 - string: Unsatisfied length - string \"123456789012345678901\" length is not allowed.\n", "/defs:un1", 1); } @@ -294,8 +294,8 @@ test_validation(void **state) assert_int_equal(LY_SUCCESS, lyd_new_list(tree, NULL, "b", LYD_NEW_VAL_BIN, NULL, &uint_val, sizeof uint_val)); assert_int_equal(LY_EVALID, lyd_validate_all(&tree, NULL, LYD_VALIDATE_PRESENT, NULL)); CHECK_LOG_CTX("Invalid LYB union value - no matching subtype found:\n" - " libyang 2 - leafref, version 1: Invalid leafref value \"one\" - no target instance \"../../a/name\" with the same value.\n" - " libyang 2 - leafref, version 1: Invalid type uint32 value \"one\".\n", "/lref:test/community[name='test']/view", 0); + " ly2 - leafref: Invalid leafref value \"one\" - no target instance \"../../a/name\" with the same value.\n" + " ly2 - leafref: Invalid type uint32 value \"one\".\n", "/lref:test/community[name='test']/view", 0); lyd_free_all(tree); } From f3630679e6c8eab3905c228c183381a5525a6cc3 Mon Sep 17 00:00:00 2001 From: roman Date: Thu, 16 Jan 2025 16:18:48 +0100 Subject: [PATCH 02/25] plugins types UPDATE index/ptr plugin retrieval --- src/parser_lyb.c | 4 +-- src/plugins.c | 56 +++++++++++++++++++++++++++++++++---- src/plugins_internal.h | 2 ++ src/plugins_types.c | 10 +++---- src/plugins_types/leafref.c | 14 +++++----- src/plugins_types/union.c | 42 +++++++++++++++------------- src/printer_json.c | 2 +- src/printer_lyb.c | 7 ++--- src/printer_xml.c | 4 +-- src/schema_compile.c | 4 +-- src/schema_compile_node.c | 39 ++++++++++++++++---------- src/tree_data.c | 6 ++-- src/tree_data_common.c | 26 ++++++++--------- src/tree_data_free.c | 4 +-- src/tree_data_hash.c | 4 +-- src/tree_data_new.c | 16 +++++------ src/tree_data_sorted.c | 2 +- src/tree_schema.h | 31 ++++++++++++-------- src/validation.c | 4 +-- src/xpath.c | 10 +++---- tests/utests/types/binary.c | 2 +- tests/utests/types/bits.c | 2 +- tests/utests/types/int8.c | 6 ++-- tests/utests/types/string.c | 2 +- tests/utests/utests.h | 36 +++++++++++++----------- 25 files changed, 204 insertions(+), 131 deletions(-) diff --git a/src/parser_lyb.c b/src/parser_lyb.c index 08491b528..8d6e0f96e 100644 --- a/src/parser_lyb.c +++ b/src/parser_lyb.c @@ -267,9 +267,9 @@ lyb_read_term_value(const struct lysc_node_leaf *term, uint8_t **term_value, uin if (term->type->basetype == LY_TYPE_LEAFREF) { /* Leafref itself is ignored, the target is loaded directly. */ type_lf = (struct lysc_type_leafref *)term->type; - lyb_data_len = type_lf->realtype->plugin->lyb_data_len; + lyb_data_len = lysc_get_type_plugin(type_lf->realtype->plugin)->lyb_data_len; } else { - lyb_data_len = term->type->plugin->lyb_data_len; + lyb_data_len = lysc_get_type_plugin(term->type->plugin)->lyb_data_len; } if (lyb_data_len < 0) { diff --git a/src/plugins.c b/src/plugins.c index ea97eb19e..221a98c8e 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -132,6 +132,16 @@ static struct ly_set plugins_handlers = {0}; static struct ly_set plugins_types = {0}; static struct ly_set plugins_extensions = {0}; +LIBYANG_API_DEF struct lyplg_type * +lysc_get_type_plugin(uintptr_t plugin_id) +{ + if (plugin_id < plugins_types.count) { + return &((struct lyplg_type_record *)plugins_types.objs[plugin_id])->plugin; + } else { + return (struct lyplg_type *)plugin_id; + } +} + /** * @brief Iterate over list of loaded plugins of the given @p type. * @@ -162,7 +172,7 @@ plugins_iter(const struct ly_ctx *ctx, enum LYPLG type, uint32_t *index) } static void * -lyplg_record_find(const struct ly_ctx *ctx, enum LYPLG type, const char *module, const char *revision, const char *name) +lyplg_record_find(const struct ly_ctx *ctx, enum LYPLG type, const char *module, const char *revision, const char *name, uint32_t *record_idx) { uint32_t i = 0; struct lyplg_record *item; @@ -178,6 +188,11 @@ lyplg_record_find(const struct ly_ctx *ctx, enum LYPLG type, const char *module, continue; } + if (record_idx) { + /* return the record idx, -1 because the iterator is already increased */ + *record_idx = i - 1; + } + return item; } } @@ -185,6 +200,37 @@ lyplg_record_find(const struct ly_ctx *ctx, enum LYPLG type, const char *module, return NULL; } +LY_ERR +_lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name, uintptr_t *out) +{ + struct lyplg_type_record *record = NULL; + uint32_t record_idx; + + if (ctx) { + /* try to find context specific plugin */ + record = lyplg_record_find(ctx, LYPLG_TYPE, module, revision, name, &record_idx); + } + + if (!record) { + /* try to find shared plugin */ + record = lyplg_record_find(NULL, LYPLG_TYPE, module, revision, name, &record_idx); + } + + if (!record) { + return LY_ENOTFOUND; + } + + if (!strncmp(record->plugin.id, "ly2 - ", 6)) { + /* internal plugin, return an index */ + *out = record_idx; + } else { + /* external plugin, return the pointer */ + *out = (uintptr_t)&record->plugin; + } + + return LY_SUCCESS; +} + struct lyplg_type * lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name) { @@ -192,12 +238,12 @@ lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char if (ctx) { /* try to find context specific plugin */ - record = lyplg_record_find(ctx, LYPLG_TYPE, module, revision, name); + record = lyplg_record_find(ctx, LYPLG_TYPE, module, revision, name, NULL); } if (!record) { /* try to find shared plugin */ - record = lyplg_record_find(NULL, LYPLG_TYPE, module, revision, name); + record = lyplg_record_find(NULL, LYPLG_TYPE, module, revision, name, NULL); } return record ? &record->plugin : NULL; @@ -210,12 +256,12 @@ lyplg_ext_plugin_find(const struct ly_ctx *ctx, const char *module, const char * if (ctx) { /* try to find context specific plugin */ - record = lyplg_record_find(ctx, LYPLG_EXTENSION, module, revision, name); + record = lyplg_record_find(ctx, LYPLG_EXTENSION, module, revision, name, NULL); } if (!record) { /* try to find shared plugin */ - record = lyplg_record_find(NULL, LYPLG_EXTENSION, module, revision, name); + record = lyplg_record_find(NULL, LYPLG_EXTENSION, module, revision, name, NULL); } return record ? &record->plugin : NULL; diff --git a/src/plugins_internal.h b/src/plugins_internal.h index ac5484db3..d59a81214 100644 --- a/src/plugins_internal.h +++ b/src/plugins_internal.h @@ -60,6 +60,8 @@ LY_ERR lyplg_init(ly_bool builtin_type_plugins_only); */ void lyplg_clean(void); +LY_ERR _lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name, uintptr_t *out); + /** * @brief Find a type plugin. * diff --git a/src/plugins_types.c b/src/plugins_types.c index 18b5f636e..bd7827b70 100644 --- a/src/plugins_types.c +++ b/src/plugins_types.c @@ -904,7 +904,7 @@ lyplg_type_print_val(const struct lysc_node *node, const char *canon, LY_VALUE_F type = ((struct lysc_node_leaf *)node)->type; /* store the value */ - r = type->plugin->store(node->module->ctx, type, canon, strlen(canon), LYPLG_TYPE_STORE_ONLY, LY_VALUE_CANON, + r = lysc_get_type_plugin(type->plugin)->store(node->module->ctx, type, canon, strlen(canon), LYPLG_TYPE_STORE_ONLY, LY_VALUE_CANON, NULL, LYD_HINT_DATA, node, &storage, NULL, &err); if (r && (r != LY_EINCOMPLETE)) { if (err) { @@ -915,7 +915,7 @@ lyplg_type_print_val(const struct lysc_node *node, const char *canon, LY_VALUE_F } /* print it in the specific format */ - v = type->plugin->print(node->module->ctx, &storage, format, prefix_data, &dyn, NULL); + v = lysc_get_type_plugin(type->plugin)->print(node->module->ctx, &storage, format, prefix_data, &dyn, NULL); /* store it in the dictionary, storage will be freed */ if (dyn) { @@ -924,7 +924,7 @@ lyplg_type_print_val(const struct lysc_node *node, const char *canon, LY_VALUE_F lydict_dup(node->module->ctx, v, value); } - type->plugin->free(node->module->ctx, &storage); + lysc_get_type_plugin(type->plugin)->free(node->module->ctx, &storage); return LY_SUCCESS; } @@ -1110,7 +1110,7 @@ lyplg_type_resolve_leafref(const struct lysc_type_leafref *lref, const struct ly continue; } - if (!lref->plugin->compare(LYD_CTX(node), &((struct lyd_node_term *)set.val.nodes[i].node)->value, value)) { + if (!lysc_get_type_plugin(lref->plugin)->compare(LYD_CTX(node), &((struct lyd_node_term *)set.val.nodes[i].node)->value, value)) { break; } } @@ -1135,7 +1135,7 @@ lyplg_type_resolve_leafref(const struct lysc_type_leafref *lref, const struct ly continue; } - if (!lref->plugin->compare(LYD_CTX(node), &((struct lyd_node_term *)set.val.nodes[i].node)->value, value)) { + if (!lysc_get_type_plugin(lref->plugin)->compare(LYD_CTX(node), &((struct lyd_node_term *)set.val.nodes[i].node)->value, value)) { rc = ly_set_add(*targets, set.val.nodes[i].node, 0, NULL); LY_CHECK_GOTO(rc, cleanup); } diff --git a/src/plugins_types/leafref.c b/src/plugins_types/leafref.c index 78c3280bc..8de07dbdd 100644 --- a/src/plugins_types/leafref.c +++ b/src/plugins_types/leafref.c @@ -47,8 +47,8 @@ lyplg_type_store_leafref(const struct ly_ctx *ctx, const struct lysc_type *type, assert(type_lr->realtype); /* store the value as the real type of the leafref target */ - rc = type_lr->realtype->plugin->store(ctx, type_lr->realtype, value, value_len, options, format, prefix_data, - hints, ctx_node, storage, unres, err); + rc = lysc_get_type_plugin(type_lr->realtype->plugin)->store(ctx, type_lr->realtype, value, value_len, options, + format, prefix_data, hints, ctx_node, storage, unres, err); if (rc == LY_EINCOMPLETE) { /* it is irrelevant whether the target type needs some resolving */ rc = LY_SUCCESS; @@ -104,32 +104,32 @@ lyplg_type_validate_leafref(const struct ly_ctx *ctx, const struct lysc_type *ty LIBYANG_API_DEF LY_ERR lyplg_type_compare_leafref(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2) { - return val1->realtype->plugin->compare(ctx, val1, val2); + return lysc_get_type_plugin(val1->realtype->plugin)->compare(ctx, val1, val2); } LIBYANG_API_DEF int lyplg_type_sort_leafref(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2) { - return val1->realtype->plugin->sort(ctx, val1, val2); + return lysc_get_type_plugin(val1->realtype->plugin)->sort(ctx, val1, val2); } LIBYANG_API_DEF const void * lyplg_type_print_leafref(const struct ly_ctx *ctx, const struct lyd_value *value, LY_VALUE_FORMAT format, void *prefix_data, ly_bool *dynamic, size_t *value_len) { - return value->realtype->plugin->print(ctx, value, format, prefix_data, dynamic, value_len); + return lysc_get_type_plugin(value->realtype->plugin)->print(ctx, value, format, prefix_data, dynamic, value_len); } LIBYANG_API_DEF LY_ERR lyplg_type_dup_leafref(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup) { - return original->realtype->plugin->duplicate(ctx, original, dup); + return lysc_get_type_plugin(original->realtype->plugin)->duplicate(ctx, original, dup); } LIBYANG_API_DEF void lyplg_type_free_leafref(const struct ly_ctx *ctx, struct lyd_value *value) { - value->realtype->plugin->free(ctx, value); + lysc_get_type_plugin(value->realtype->plugin)->free(ctx, value); } /** diff --git a/src/plugins_types/union.c b/src/plugins_types/union.c index cd1574cbb..36618d1c9 100644 --- a/src/plugins_types/union.c +++ b/src/plugins_types/union.c @@ -185,8 +185,9 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3 lyb_parse_union(subvalue->original, subvalue->orig_len, &ti, &value, &value_len); if (ti != type_idx) { /* value of another type, first store the value properly and then use its JSON value for parsing */ - rc = type_u->types[ti]->plugin->store(ctx, type_u->types[ti], value, value_len, LYPLG_TYPE_STORE_ONLY, - subvalue->format, subvalue->prefix_data, subvalue->hints, subvalue->ctx_node, &subvalue->value, unres, err); + rc = lysc_get_type_plugin(type_u->types[ti]->plugin)->store(ctx, type_u->types[ti], value, value_len, + LYPLG_TYPE_STORE_ONLY, subvalue->format, subvalue->prefix_data, subvalue->hints, + subvalue->ctx_node, &subvalue->value, unres, err); if ((rc != LY_SUCCESS) && (rc != LY_EINCOMPLETE)) { /* clear any leftover/freed garbage */ memset(&subvalue->value, 0, sizeof subvalue->value); @@ -194,14 +195,15 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3 } assert(subvalue->value.realtype); - value = subvalue->value.realtype->plugin->print(ctx, &subvalue->value, LY_VALUE_JSON, NULL, &dynamic, &value_len); + value = lysc_get_type_plugin(subvalue->value.realtype->plugin)->print(ctx, &subvalue->value, + LY_VALUE_JSON, NULL, &dynamic, &value_len); /* to avoid leaks, free subvalue->value, but we need the value, which may be stored there */ if (!dynamic) { value = strndup(value, value_len); dynamic = 1; } - type_u->types[ti]->plugin->free(ctx, &subvalue->value); + lysc_get_type_plugin(type_u->types[ti]->plugin)->free(ctx, &subvalue->value); format = LY_VALUE_JSON; prefix_data = NULL; @@ -223,8 +225,8 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3 opts |= LYPLG_TYPE_STORE_DYNAMIC; } - rc = type->plugin->store(ctx, type, value, value_len, opts, format, prefix_data, subvalue->hints, - subvalue->ctx_node, &subvalue->value, unres, err); + rc = lysc_get_type_plugin(type->plugin)->store(ctx, type, value, value_len, opts, format, prefix_data, + subvalue->hints, subvalue->ctx_node, &subvalue->value, unres, err); if ((rc != LY_SUCCESS) && (rc != LY_EINCOMPLETE)) { /* clear any leftover/freed garbage */ memset(&subvalue->value, 0, sizeof subvalue->value); @@ -233,10 +235,10 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3 if (validate && (rc == LY_EINCOMPLETE)) { /* we need the value validated */ - rc = type->plugin->validate(ctx, type, ctx_node, tree, &subvalue->value, err); + rc = lysc_get_type_plugin(type->plugin)->validate(ctx, type, ctx_node, tree, &subvalue->value, err); if (rc) { /* validate failed, we need to free the stored value */ - type->plugin->free(ctx, &subvalue->value); + lysc_get_type_plugin(type->plugin)->free(ctx, &subvalue->value); } } @@ -306,9 +308,9 @@ union_find_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct continue; } - msg = ly_realloc(msg, msg_len + 4 + strlen(type_u->types[u]->plugin->id) + 2 + strlen(errs[u]->msg) + 2); + msg = ly_realloc(msg, msg_len + 4 + strlen(lysc_get_type_plugin(type_u->types[u]->plugin)->id) + 2 + strlen(errs[u]->msg) + 2); LY_CHECK_ERR_GOTO(!msg, ret = LY_EMEM, cleanup); - msg_len += sprintf(msg + msg_len, " %s: %s\n", type_u->types[u]->plugin->id, errs[u]->msg); + msg_len += sprintf(msg + msg_len, " %s: %s\n", lysc_get_type_plugin(type_u->types[u]->plugin)->id, errs[u]->msg); } ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "%s", msg); @@ -449,8 +451,8 @@ lyplg_type_validate_union(const struct ly_ctx *ctx, const struct lysc_type *type /* because of types that do not store their own type as realtype (leafref), we are not able to call their * validate callback (there is no way to get the type) but even if possible, the value may be invalid * for the type, so we may have to perform union value storing again from scratch, but keep a value backup */ - LY_CHECK_RET(subvalue->value.realtype->plugin->duplicate(ctx, &subvalue->value, &orig)); - subvalue->value.realtype->plugin->free(ctx, &subvalue->value); + LY_CHECK_RET(lysc_get_type_plugin(subvalue->value.realtype->plugin)->duplicate(ctx, &subvalue->value, &orig)); + lysc_get_type_plugin(subvalue->value.realtype->plugin)->free(ctx, &subvalue->value); if (subvalue->format == LY_VALUE_LYB) { /* use the specific type to store and validate the value */ @@ -480,7 +482,7 @@ lyplg_type_validate_union(const struct ly_ctx *ctx, const struct lysc_type *type LY_CHECK_RET(lydict_insert(ctx, subvalue->value._canonical, 0, &storage->_canonical)); /* free backup value */ - orig.realtype->plugin->free(ctx, &orig); + lysc_get_type_plugin(orig.realtype->plugin)->free(ctx, &orig); return LY_SUCCESS; } @@ -490,7 +492,7 @@ lyplg_type_compare_union(const struct ly_ctx *ctx, const struct lyd_value *val1, if (val1->subvalue->value.realtype != val2->subvalue->value.realtype) { return LY_ENOT; } - return val1->subvalue->value.realtype->plugin->compare(ctx, &val1->subvalue->value, &val2->subvalue->value); + return lysc_get_type_plugin(val1->subvalue->value.realtype->plugin)->compare(ctx, &val1->subvalue->value, &val2->subvalue->value); } LIBYANG_API_DEF int @@ -501,7 +503,7 @@ lyplg_type_sort_union(const struct ly_ctx *ctx, const struct lyd_value *val1, co struct lysc_type **types; if (val1->subvalue->value.realtype == val2->subvalue->value.realtype) { - return val1->subvalue->value.realtype->plugin->sort(ctx, &val1->subvalue->value, &val2->subvalue->value); + return lysc_get_type_plugin(val1->subvalue->value.realtype->plugin)->sort(ctx, &val1->subvalue->value, &val2->subvalue->value); } /* compare according to the order of types */ @@ -553,13 +555,13 @@ lyb_union_print(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct assert(subvalue->ctx_node); ctx = subvalue->ctx_node->module->ctx; } - subvalue->value.realtype->plugin->free(ctx, &subvalue->value); + lysc_get_type_plugin(subvalue->value.realtype->plugin)->free(ctx, &subvalue->value); r = union_find_type(ctx, type_u, subvalue, 0, 0, NULL, NULL, &type_idx, NULL, &err); ly_err_free(err); LY_CHECK_RET((r != LY_SUCCESS) && (r != LY_EINCOMPLETE), NULL); /* Print subvalue in LYB format. */ - pval = (void *)subvalue->value.realtype->plugin->print(NULL, &subvalue->value, LY_VALUE_LYB, prefix_data, &dynamic, + pval = (void *)lysc_get_type_plugin(subvalue->value.realtype->plugin)->print(NULL, &subvalue->value, LY_VALUE_LYB, prefix_data, &dynamic, &pval_len); LY_CHECK_RET(!pval, NULL); @@ -607,7 +609,7 @@ lyplg_type_print_union(const struct ly_ctx *ctx, const struct lyd_value *value, } assert(format != LY_VALUE_LYB); - ret = (void *)subvalue->value.realtype->plugin->print(ctx, &subvalue->value, format, prefix_data, dynamic, value_len); + ret = (void *)lysc_get_type_plugin(subvalue->value.realtype->plugin)->print(ctx, &subvalue->value, format, prefix_data, dynamic, value_len); if (!value->_canonical && (format == LY_VALUE_CANON)) { /* the canonical value is supposed to be stored now */ lydict_insert(ctx, subvalue->value._canonical, 0, (const char **)&value->_canonical); @@ -633,7 +635,7 @@ lyplg_type_dup_union(const struct ly_ctx *ctx, const struct lyd_value *original, LY_CHECK_ERR_GOTO(!dup_val, LOGMEM(ctx); ret = LY_EMEM, cleanup); dup->subvalue = dup_val; - ret = orig_val->value.realtype->plugin->duplicate(ctx, &orig_val->value, &dup_val->value); + ret = lysc_get_type_plugin(orig_val->value.realtype->plugin)->duplicate(ctx, &orig_val->value, &dup_val->value); LY_CHECK_GOTO(ret, cleanup); if (orig_val->orig_len) { @@ -669,7 +671,7 @@ lyplg_type_free_union(const struct ly_ctx *ctx, struct lyd_value *value) LYD_VALUE_GET(value, val); if (val) { if (val->value.realtype) { - val->value.realtype->plugin->free(ctx, &val->value); + lysc_get_type_plugin(val->value.realtype->plugin)->free(ctx, &val->value); } lyplg_type_prefix_data_free(val->format, val->prefix_data); free(val->original); diff --git a/src/printer_json.c b/src/printer_json.c index 233bc0254..d7f6e909f 100644 --- a/src/printer_json.c +++ b/src/printer_json.c @@ -354,7 +354,7 @@ json_print_value(struct jsonpr_ctx *pctx, const struct ly_ctx *ctx, const struct LY_DATA_TYPE basetype; const char *value; - value = val->realtype->plugin->print(ctx, val, LY_VALUE_JSON, (void *)local_mod, &dynamic, NULL); + value = lysc_get_type_plugin(val->realtype->plugin)->print(ctx, val, LY_VALUE_JSON, (void *)local_mod, &dynamic, NULL); LY_CHECK_RET(!value, LY_EINVAL); basetype = val->realtype->basetype; diff --git a/src/printer_lyb.c b/src/printer_lyb.c index 95ec23d2e..f1ca2b183 100644 --- a/src/printer_lyb.c +++ b/src/printer_lyb.c @@ -679,14 +679,13 @@ lyb_print_term_value(struct lyd_node_term *term, struct ly_out *out, struct lyly int32_t lyb_data_len; lyplg_type_print_clb print; - assert(term->value.realtype && term->value.realtype->plugin && term->value.realtype->plugin->print && - term->schema); + assert(term->value.realtype && lysc_get_type_plugin(term->value.realtype->plugin)->print && term->schema); /* Get length of LYB data to print. */ - lyb_data_len = term->value.realtype->plugin->lyb_data_len; + lyb_data_len = lysc_get_type_plugin(term->value.realtype->plugin)->lyb_data_len; /* Get value and also print its length only if size is not fixed. */ - print = term->value.realtype->plugin->print; + print = lysc_get_type_plugin(term->value.realtype->plugin)->print; if (lyb_data_len < 0) { /* Variable-length data. */ diff --git a/src/printer_xml.c b/src/printer_xml.c index 31c5ad4ca..e7201234c 100644 --- a/src/printer_xml.c +++ b/src/printer_xml.c @@ -217,7 +217,7 @@ xml_print_meta(struct xmlpr_ctx *pctx, const struct lyd_node *node) ly_set_add(&ns_list, NULL, 0, NULL); /* print the value */ - value = meta->value.realtype->plugin->print(LYD_CTX(node), &meta->value, LY_VALUE_XML, &ns_list, &dynamic, NULL); + value = lysc_get_type_plugin(meta->value.realtype->plugin)->print(LYD_CTX(node), &meta->value, LY_VALUE_XML, &ns_list, &dynamic, NULL); /* print namespaces connected with the value's prefixes */ for (i = 1; i < ns_list.count; ++i) { @@ -339,7 +339,7 @@ xml_print_term(struct xmlpr_ctx *pctx, const struct lyd_node_term *node) } /* print the value */ - value = ((struct lysc_node_leaf *)node->schema)->type->plugin->print(LYD_CTX(node), &node->value, LY_VALUE_XML, + value = lysc_get_type_plugin(((struct lysc_node_leaf *)node->schema)->type->plugin)->print(LYD_CTX(node), &node->value, LY_VALUE_XML, &ns_list, &dynamic, NULL); LY_CHECK_ERR_GOTO(!value, rc = LY_EINVAL, cleanup); diff --git a/src/schema_compile.c b/src/schema_compile.c index f9d130bdf..094f5f17b 100644 --- a/src/schema_compile.c +++ b/src/schema_compile.c @@ -898,7 +898,7 @@ lys_compile_unres_dflt(struct lysc_ctx *ctx, struct lysc_node *node, struct lysc LY_VALUE_FORMAT format; options = (ctx->ctx->opts & LY_CTX_REF_IMPLEMENTED) ? LYPLG_TYPE_STORE_IMPLEMENT : 0; - rc = type->plugin->store(ctx->ctx, type, dflt, strlen(dflt), options, LY_VALUE_SCHEMA, (void *)dflt_pmod, + rc = lysc_get_type_plugin(type->plugin)->store(ctx->ctx, type, dflt, strlen(dflt), options, LY_VALUE_SCHEMA, (void *)dflt_pmod, LYD_HINT_SCHEMA, node, &storage, unres, &err); if (rc == LY_ERECOMPILE) { /* fine, but we need to recompile */ @@ -925,7 +925,7 @@ lys_compile_unres_dflt(struct lysc_ctx *ctx, struct lysc_node *node, struct lysc } cleanup: - type->plugin->free(ctx->ctx, &storage); + lysc_get_type_plugin(type->plugin)->free(ctx->ctx, &storage); return rc; } diff --git a/src/schema_compile_node.c b/src/schema_compile_node.c index 8bba29751..cd9730309 100644 --- a/src/schema_compile_node.c +++ b/src/schema_compile_node.c @@ -1773,7 +1773,7 @@ lys_new_type(const struct ly_ctx *ctx, LY_DATA_TYPE basetype, const char *tpdf_n static LY_ERR lys_compile_type_(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t context_flags, const char *context_name, const struct lysp_type *type_p, LY_DATA_TYPE basetype, const char *tpdfname, const struct lysc_type *base, - struct lyplg_type *plugin, struct ly_set *tpdf_chain, uint32_t tpdf_chain_last, struct lysc_type **type) + uintptr_t plugin, struct ly_set *tpdf_chain, uint32_t tpdf_chain_last, struct lysc_type **type) { LY_ERR rc = LY_SUCCESS; struct lysc_type_bin *bin; @@ -2133,7 +2133,7 @@ LY_ERR lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t context_flags, const char *context_name, const struct lysp_type *type_p, struct lysc_type **type, const char **units, struct lysp_qname **dflt) { - LY_ERR ret = LY_SUCCESS; + LY_ERR ret = LY_SUCCESS, r; ly_bool dummyloops = 0, has_leafref; struct lys_type_item *tctx, *tctx_prev = NULL, *tctx_iter; LY_DATA_TYPE basetype = LY_TYPE_UNKNOWN; @@ -2141,7 +2141,8 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t struct lysc_type_union *base_un; LY_ARRAY_COUNT_TYPE u; struct ly_set tpdf_chain = {0}; - struct lyplg_type *plugin; + uintptr_t plugin_id = -1; + ly_bool plugin_found = 0; *type = NULL; if (dflt) { @@ -2264,20 +2265,26 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t } /* try to find loaded user type plugins */ - plugin = lyplg_type_plugin_find(ctx->ctx, tctx->tpdf->type.pmod->mod->name, tctx->tpdf->type.pmod->mod->revision, - tctx->tpdf->name); - if (!plugin && base) { + r = _lyplg_type_plugin_find(ctx->ctx, tctx->tpdf->type.pmod->mod->name, tctx->tpdf->type.pmod->mod->revision, + tctx->tpdf->name, &plugin_id); + if (r == LY_SUCCESS) { + plugin_found = 1; + } else if ((r == LY_ENOTFOUND) && base) { /* use the base type implementation if available */ - plugin = base->plugin; + plugin_id = base->plugin; + plugin_found = 1; } - if (!plugin) { + if (!plugin_found) { /* use the internal built-in type implementation */ - plugin = lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype]); + r = _lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype], &plugin_id); + if (r == LY_SUCCESS) { + plugin_found = 1; + } } - assert(plugin); + assert(plugin_found); if ((basetype != LY_TYPE_LEAFREF) && (u != tpdf_chain.count - 1) && !tctx->tpdf->type.flags && - !tctx->tpdf->type.exts && (plugin == base->plugin)) { + !tctx->tpdf->type.exts && (plugin_id == base->plugin)) { /* no change, reuse the compiled base */ ((struct lysp_tpdf *)tctx->tpdf)->type.compiled = base; LY_ATOMIC_INC_BARRIER(base->refcount); @@ -2298,7 +2305,7 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t /* compile the typedef type */ ret = lys_compile_type_(ctx, tctx->node, tctx->tpdf->flags, tctx->tpdf->name, &tctx->tpdf->type, basetype, - tctx->tpdf->name, base, plugin, &tpdf_chain, u + 1, &base); + tctx->tpdf->name, base, plugin_id, &tpdf_chain, u + 1, &base); LY_CHECK_GOTO(ret, cleanup); /* store separately compiled typedef type to be reused */ @@ -2329,9 +2336,13 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t /* process the type definition in leaf */ if (type_p->flags || type_p->exts || !base || has_leafref) { /* leaf type has changes that need to be compiled into the type */ - plugin = base ? base->plugin : lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype]); + if (base) { + plugin_id = base->plugin; + } else { + _lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype], &plugin_id); + } ret = lys_compile_type_(ctx, context_pnode, context_flags, context_name, (struct lysp_type *)type_p, basetype, - NULL, base, plugin, &tpdf_chain, 0, type); + NULL, base, plugin_id, &tpdf_chain, 0, type); LY_CHECK_GOTO(ret, cleanup); } else { /* no changes of the type in the leaf, just use the base compiled type */ diff --git a/src/tree_data.c b/src/tree_data.c index ef64e2644..8b4781a4c 100644 --- a/src/tree_data.c +++ b/src/tree_data.c @@ -1872,7 +1872,7 @@ lyd_compare_meta(const struct lyd_meta *meta1, const struct lyd_meta *meta2) return LY_ENOT; } - return meta1->value.realtype->plugin->compare(ctx, &meta1->value, &meta2->value); + return lysc_get_type_plugin(meta1->value.realtype->plugin)->compare(ctx, &meta1->value, &meta2->value); } /** @@ -2129,7 +2129,7 @@ lyd_dup_r(const struct lyd_node *node, const struct ly_ctx *trg_ctx, struct lyd_ term->hash = orig->hash; if (trg_ctx == LYD_CTX(node)) { - ret = orig->value.realtype->plugin->duplicate(trg_ctx, &orig->value, &term->value); + ret = lysc_get_type_plugin(orig->value.realtype->plugin)->duplicate(trg_ctx, &orig->value, &term->value); LY_CHECK_ERR_GOTO(ret, LOGERR(trg_ctx, ret, "Value duplication failed."), error); } else { /* store canonical value in the target context */ @@ -2438,7 +2438,7 @@ lyd_dup_meta_single_to_ctx(const struct ly_ctx *parent_ctx, const struct lyd_met /* annotation */ mt->annotation = meta->annotation; /* duplication of value */ - ret = meta->value.realtype->plugin->duplicate(parent_ctx, &meta->value, &mt->value); + ret = lysc_get_type_plugin(meta->value.realtype->plugin)->duplicate(parent_ctx, &meta->value, &mt->value); } LY_CHECK_ERR_GOTO(ret, LOGERR(LYD_CTX(parent), LY_EINT, "Value duplication failed."), finish); LY_CHECK_GOTO(ret = lydict_insert(parent_ctx, meta->name, 0, &mt->name), finish); diff --git a/src/tree_data_common.c b/src/tree_data_common.c index 9bb0a5951..36dfed980 100644 --- a/src/tree_data_common.c +++ b/src/tree_data_common.c @@ -531,7 +531,7 @@ lyd_value_store(const struct ly_ctx *ctx, struct lyd_value *val, const struct ly options |= LYPLG_TYPE_STORE_ONLY; } - r = type->plugin->store(ctx, type, value, value_len, options, format, prefix_data, hints, ctx_node, val, NULL, &err); + r = lysc_get_type_plugin(type->plugin)->store(ctx, type, value, value_len, options, format, prefix_data, hints, ctx_node, val, NULL, &err); if (dynamic) { *dynamic = 0; } @@ -560,16 +560,16 @@ lyd_value_validate_incomplete(const struct ly_ctx *ctx, const struct lysc_type * LY_ERR ret; struct ly_err_item *err = NULL; - assert(type->plugin->validate); + assert(lysc_get_type_plugin(type->plugin)->validate); - ret = type->plugin->validate(ctx, type, ctx_node, tree, val, &err); + ret = lysc_get_type_plugin(type->plugin)->validate(ctx, type, ctx_node, tree, val, &err); if (ret) { if (err) { ly_err_print_build_path(ctx, ctx_node, NULL, err); ly_err_free(err); } else { LOGVAL(ctx, LYVE_OTHER, "Resolving value \"%s\" failed.", - (char *)type->plugin->print(ctx, val, LY_VALUE_CANON, NULL, NULL, NULL)); + (char *)lysc_get_type_plugin(type->plugin)->print(ctx, val, LY_VALUE_CANON, NULL, NULL, NULL)); } return ret; } @@ -594,7 +594,7 @@ ly_value_validate(const struct ly_ctx *ctx, const struct lysc_node *node, const } type = ((struct lysc_node_leaf *)node)->type; - rc = type->plugin->store(ctx ? ctx : node->module->ctx, type, value, value_len, 0, format, prefix_data, hints, node, + rc = lysc_get_type_plugin(type->plugin)->store(ctx ? ctx : node->module->ctx, type, value, value_len, 0, format, prefix_data, hints, node, &storage, NULL, &err); if (rc == LY_EINCOMPLETE) { /* actually success */ @@ -608,7 +608,7 @@ ly_value_validate(const struct ly_ctx *ctx, const struct lysc_node *node, const } if (!rc) { - type->plugin->free(ctx ? ctx : node->module->ctx, &storage); + lysc_get_type_plugin(type->plugin)->free(ctx ? ctx : node->module->ctx, &storage); } return rc; } @@ -643,14 +643,14 @@ lyd_value_validate2(const struct ly_ctx *ctx, const struct lysc_node *schema, co type = ((struct lysc_node_leaf *)schema)->type; /* store */ - rc = type->plugin->store(ctx, type, value, value_len, 0, format, prefix_data, LYD_HINT_DATA, schema, &val, NULL, &err); + rc = lysc_get_type_plugin(type->plugin)->store(ctx, type, value, value_len, 0, format, prefix_data, LYD_HINT_DATA, schema, &val, NULL, &err); if (!rc || (rc == LY_EINCOMPLETE)) { stored = 1; } if (ctx_node && (rc == LY_EINCOMPLETE)) { /* resolve */ - rc = type->plugin->validate(ctx, type, ctx_node, ctx_node, &val, &err); + rc = lysc_get_type_plugin(type->plugin)->validate(ctx, type, ctx_node, ctx_node, &val, &err); } if (rc && (rc != LY_EINCOMPLETE) && err) { @@ -673,13 +673,13 @@ lyd_value_validate2(const struct ly_ctx *ctx, const struct lysc_node *schema, co if (canonical) { /* return canonical value */ - lydict_dup(ctx, val.realtype->plugin->print(ctx, &val, LY_VALUE_CANON, NULL, NULL, NULL), canonical); + lydict_dup(ctx, lysc_get_type_plugin(val.realtype->plugin)->print(ctx, &val, LY_VALUE_CANON, NULL, NULL, NULL), canonical); } } if (stored) { /* free value */ - type->plugin->free(ctx, &val); + lysc_get_type_plugin(type->plugin)->free(ctx, &val); } return rc; } @@ -704,9 +704,9 @@ lyd_value_compare(const struct lyd_node_term *node, const char *value, size_t va LY_CHECK_RET(ret); /* compare values */ - ret = type->plugin->compare(ctx, &node->value, &val); + ret = lysc_get_type_plugin(type->plugin)->compare(ctx, &node->value, &val); - type->plugin->free(ctx, &val); + lysc_get_type_plugin(type->plugin)->free(ctx, &val); return ret; } @@ -982,7 +982,7 @@ lyd_value_get_canonical(const struct ly_ctx *ctx, const struct lyd_value *value) LY_CHECK_ARG_RET(ctx, ctx, value, NULL); return value->_canonical ? value->_canonical : - (const char *)value->realtype->plugin->print(ctx, value, LY_VALUE_CANON, NULL, NULL, NULL); + (const char *)lysc_get_type_plugin(value->realtype->plugin)->print(ctx, value, LY_VALUE_CANON, NULL, NULL, NULL); } LIBYANG_API_DEF LY_ERR diff --git a/src/tree_data_free.c b/src/tree_data_free.c index 805c988d2..c259298d5 100644 --- a/src/tree_data_free.c +++ b/src/tree_data_free.c @@ -64,7 +64,7 @@ lyd_free_meta(struct lyd_meta *meta, ly_bool siblings) iter = iter->next; lydict_remove(meta->annotation->module->ctx, meta->name); - meta->value.realtype->plugin->free(meta->annotation->module->ctx, &meta->value); + lysc_get_type_plugin(meta->value.realtype->plugin)->free(meta->annotation->module->ctx, &meta->value); free(meta); } } @@ -234,7 +234,7 @@ lyd_free_subtree(struct lyd_node *node) } else if (node->schema->nodetype & LYD_NODE_TERM) { struct lyd_node_term *node_term = (struct lyd_node_term *)node; - ((struct lysc_node_leaf *)node->schema)->type->plugin->free(LYD_CTX(node), &node_term->value); + lysc_get_type_plugin(((struct lysc_node_leaf *)node->schema)->type->plugin)->free(LYD_CTX(node), &node_term->value); lyd_free_leafref_nodes(node_term); } diff --git a/src/tree_data_hash.c b/src/tree_data_hash.c index 9be655ca4..66ba634e4 100644 --- a/src/tree_data_hash.c +++ b/src/tree_data_hash.c @@ -55,7 +55,7 @@ lyd_hash(struct lyd_node *node) for (iter = list->child; iter && iter->schema && (iter->schema->flags & LYS_KEY); iter = iter->next) { struct lyd_node_term *key = (struct lyd_node_term *)iter; - hash_key = key->value.realtype->plugin->print(NULL, &key->value, LY_VALUE_LYB, NULL, &dyn, &key_len); + hash_key = lysc_get_type_plugin(key->value.realtype->plugin)->print(NULL, &key->value, LY_VALUE_LYB, NULL, &dyn, &key_len); node->hash = lyht_hash_multi(node->hash, hash_key, key_len); if (dyn) { free((void *)hash_key); @@ -66,7 +66,7 @@ lyd_hash(struct lyd_node *node) /* leaf-list adds its hash key */ struct lyd_node_term *llist = (struct lyd_node_term *)node; - hash_key = llist->value.realtype->plugin->print(NULL, &llist->value, LY_VALUE_LYB, NULL, &dyn, &key_len); + hash_key = lysc_get_type_plugin(llist->value.realtype->plugin)->print(NULL, &llist->value, LY_VALUE_LYB, NULL, &dyn, &key_len); node->hash = lyht_hash_multi(node->hash, hash_key, key_len); if (dyn) { free((void *)hash_key); diff --git a/src/tree_data_new.c b/src/tree_data_new.c index 3da3f1ce0..a440c7088 100644 --- a/src/tree_data_new.c +++ b/src/tree_data_new.c @@ -1225,11 +1225,11 @@ lyd_change_node_value(struct lyd_node_term *term, struct lyd_value *val, ly_bool target = (struct lyd_node *)term->parent; } else { /* just change the value */ - term->value.realtype->plugin->free(LYD_CTX(term), &term->value); + lysc_get_type_plugin(term->value.realtype->plugin)->free(LYD_CTX(term), &term->value); if (use_val) { term->value = *val; } else { - rc = ((struct lysc_node_leaf *)term->schema)->type->plugin->duplicate(LYD_CTX(term), val, &term->value); + rc = lysc_get_type_plugin(((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 */ @@ -1245,11 +1245,11 @@ lyd_change_node_value(struct lyd_node_term *term, struct lyd_value *val, ly_bool lyd_unlink_tree(target); /* change value */ - term->value.realtype->plugin->free(LYD_CTX(term), &term->value); + lysc_get_type_plugin(term->value.realtype->plugin)->free(LYD_CTX(term), &term->value); if (use_val) { term->value = *val; } else { - rc = ((struct lysc_node_leaf *)term->schema)->type->plugin->duplicate(LYD_CTX(term), val, &term->value); + rc = lysc_get_type_plugin(((struct lysc_node_leaf *)term->schema)->type->plugin)->duplicate(LYD_CTX(term), val, &term->value); } /* reinserting */ @@ -1259,11 +1259,11 @@ lyd_change_node_value(struct lyd_node_term *term, struct lyd_value *val, ly_bool lyd_unlink_hash(target); /* change value */ - term->value.realtype->plugin->free(LYD_CTX(term), &term->value); + lysc_get_type_plugin(term->value.realtype->plugin)->free(LYD_CTX(term), &term->value); if (use_val) { term->value = *val; } else { - rc = ((struct lysc_node_leaf *)term->schema)->type->plugin->duplicate(LYD_CTX(term), val, &term->value); + rc = lysc_get_type_plugin(((struct lysc_node_leaf *)term->schema)->type->plugin)->duplicate(LYD_CTX(term), val, &term->value); } } @@ -1285,7 +1285,7 @@ lyd_change_term_val(struct lyd_node *term, struct lyd_value *val, ly_bool use_va type = ((struct lysc_node_leaf *)term->schema)->type; /* compare original and new value */ - if (type->plugin->compare(LYD_CTX(term), &t->value, val)) { + if (lysc_get_type_plugin(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); @@ -1295,7 +1295,7 @@ lyd_change_term_val(struct lyd_node *term, struct lyd_value *val, ly_bool use_va } else { /* same values, free the new stored one */ if (use_val) { - type->plugin->free(LYD_CTX(term), val); + lysc_get_type_plugin(type->plugin)->free(LYD_CTX(term), val); } val_change = 0; } diff --git a/src/tree_data_sorted.c b/src/tree_data_sorted.c index ce0820ce7..473bc077f 100644 --- a/src/tree_data_sorted.c +++ b/src/tree_data_sorted.c @@ -196,7 +196,7 @@ static int rb_sort_clb(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2) { assert(val1->realtype == val2->realtype); - return val1->realtype->plugin->sort(ctx, val1, val2); + return lysc_get_type_plugin(val1->realtype->plugin)->sort(ctx, val1, val2); } /** diff --git a/src/tree_schema.h b/src/tree_schema.h index 1b5ed4831..5ff141a34 100644 --- a/src/tree_schema.h +++ b/src/tree_schema.h @@ -1279,7 +1279,7 @@ struct lysc_must { struct lysc_type { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin use lysc_get_type_plugin*/ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing, it may be accessed concurrently when creating/freeing data node values that reference it (instance-identifier) */ @@ -1288,7 +1288,7 @@ struct lysc_type { struct lysc_type_num { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1298,7 +1298,7 @@ struct lysc_type_num { struct lysc_type_dec { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1309,7 +1309,7 @@ struct lysc_type_dec { struct lysc_type_str { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1334,7 +1334,7 @@ struct lysc_type_bitenum_item { struct lysc_type_enum { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1344,7 +1344,7 @@ struct lysc_type_enum { struct lysc_type_bits { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1355,7 +1355,7 @@ struct lysc_type_bits { struct lysc_type_leafref { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1368,7 +1368,7 @@ struct lysc_type_leafref { struct lysc_type_identityref { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1379,7 +1379,7 @@ struct lysc_type_identityref { struct lysc_type_instanceid { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1389,7 +1389,7 @@ struct lysc_type_instanceid { struct lysc_type_union { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1399,7 +1399,7 @@ struct lysc_type_union { struct lysc_type_bin { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1797,6 +1797,15 @@ struct lysc_module { ((lysc_node && (((lysc_node->nodetype == LYS_LIST) && (lysc_node->flags & LYS_KEYLESS)) || \ ((lysc_node->nodetype == LYS_LEAFLIST) && !(lysc_node->flags & LYS_CONFIG_W)))) ? 1 : 0) +/** + * @brief + * + * @param[in] plugin_id The plugin identifier + * + * @return { description_of_the_return_value } + */ +LIBYANG_API_DECL struct lyplg_type *lysc_get_type_plugin(uintptr_t plugin_id); + /** * @brief Get nearest @p schema parent (including the node itself) that can be instantiated in data. * diff --git a/src/validation.c b/src/validation.c index 1e2772537..3ed11b1f8 100644 --- a/src/validation.c +++ b/src/validation.c @@ -1904,14 +1904,14 @@ lyd_validate_subtree(struct lyd_node *root, struct ly_set *node_when, struct ly_ LY_LIST_FOR(node->meta, meta) { lyplg_ext_get_storage(meta->annotation, LY_STMT_TYPE, sizeof type, (const void **)&type); - if (type->plugin->validate) { + if (lysc_get_type_plugin(type->plugin)->validate) { /* metadata type resolution */ r = ly_set_add(meta_types, (void *)meta, 1, NULL); LY_CHECK_ERR_GOTO(r, rc = r, cleanup); } } - if ((node->schema->nodetype & LYD_NODE_TERM) && ((struct lysc_node_leaf *)node->schema)->type->plugin->validate) { + if ((node->schema->nodetype & LYD_NODE_TERM) && lysc_get_type_plugin(((struct lysc_node_leaf *)node->schema)->type->plugin)->validate) { /* node type resolution */ r = ly_set_add(node_types, (void *)node, 1, NULL); LY_CHECK_ERR_GOTO(r, rc = r, cleanup); diff --git a/src/xpath.c b/src/xpath.c index 87b9a7320..ad65540fd 100644 --- a/src/xpath.c +++ b/src/xpath.c @@ -1714,15 +1714,15 @@ set_comp_canonize(struct lyxp_set *set, const struct lyxp_set_node *xp_node) } /* check for built-in types without required canonization */ - if ((type->basetype == LY_TYPE_STRING) && (type->plugin->store == lyplg_type_store_string)) { + if ((type->basetype == LY_TYPE_STRING) && (lysc_get_type_plugin(type->plugin)->store == lyplg_type_store_string)) { /* string */ return LY_SUCCESS; } - if ((type->basetype == LY_TYPE_BOOL) && (type->plugin->store == lyplg_type_store_boolean)) { + if ((type->basetype == LY_TYPE_BOOL) && (lysc_get_type_plugin(type->plugin)->store == lyplg_type_store_boolean)) { /* boolean */ return LY_SUCCESS; } - if ((type->basetype == LY_TYPE_ENUM) && (type->plugin->store == lyplg_type_store_enum)) { + if ((type->basetype == LY_TYPE_ENUM) && (lysc_get_type_plugin(type->plugin)->store == lyplg_type_store_enum)) { /* enumeration */ return LY_SUCCESS; } @@ -3643,7 +3643,7 @@ warn_equality_value(const struct lyxp_expr *exp, struct lyxp_set *set, uint32_t type = ((struct lysc_node_leaf *)scnode)->type; if (type->basetype != LY_TYPE_IDENT) { - rc = type->plugin->store(set->ctx, type, value, strlen(value), 0, set->format, set->prefix_data, + rc = lysc_get_type_plugin(type->plugin)->store(set->ctx, type, value, strlen(value), 0, set->format, set->prefix_data, LYD_HINT_DATA, scnode, &storage, NULL, &err); if (rc == LY_EINCOMPLETE) { rc = LY_SUCCESS; @@ -3660,7 +3660,7 @@ warn_equality_value(const struct lyxp_expr *exp, struct lyxp_set *set, uint32_t (exp->tok_pos[last_equal_exp] - exp->tok_pos[equal_exp]) + exp->tok_len[last_equal_exp], set->cur_scnode); } else { - type->plugin->free(set->ctx, &storage); + lysc_get_type_plugin(type->plugin)->free(set->ctx, &storage); } } free(value); diff --git a/tests/utests/types/binary.c b/tests/utests/types/binary.c index 6abf26fb8..0fc2db3bf 100644 --- a/tests/utests/types/binary.c +++ b/tests/utests/types/binary.c @@ -262,7 +262,7 @@ test_plugin_print(void **state) val = ""; assert_int_equal(LY_SUCCESS, type->store(UTEST_LYCTX, lysc_type, val, strlen(val), 0, LY_VALUE_XML, NULL, LYD_VALHINT_STRING, NULL, &value, NULL, &err)); - assert_string_equal("", value.realtype->plugin->print(UTEST_LYCTX, &(value), LY_VALUE_CANON, NULL, NULL, NULL)); + assert_string_equal("", lysc_get_type_plugin(value.realtype->plugin)->print(UTEST_LYCTX, &(value), LY_VALUE_CANON, NULL, NULL, NULL)); type->free(UTEST_LYCTX, &value); } diff --git a/tests/utests/types/bits.c b/tests/utests/types/bits.c index dab299a6b..e22a7f1a8 100644 --- a/tests/utests/types/bits.c +++ b/tests/utests/types/bits.c @@ -938,7 +938,7 @@ test_plugin_compare(void **state) */ diff_type_text = val_init[2]; diff_type = ((struct lysc_node_leaf *)mod->compiled->data->next)->type; - ly_ret = diff_type->plugin->store(UTEST_LYCTX, diff_type, diff_type_text, strlen(diff_type_text), + ly_ret = lysc_get_type_plugin(diff_type->plugin)->store(UTEST_LYCTX, diff_type, diff_type_text, strlen(diff_type_text), 0, LY_VALUE_XML, NULL, LYD_VALHINT_STRING, NULL, &diff_type_val, NULL, &err); assert_int_equal(LY_SUCCESS, ly_ret); assert_int_equal(LY_SUCCESS, type->compare(UTEST_LYCTX, &diff_type_val, &(values[2]))); diff --git a/tests/utests/types/int8.c b/tests/utests/types/int8.c index 0be4ad83d..7125e9beb 100644 --- a/tests/utests/types/int8.c +++ b/tests/utests/types/int8.c @@ -1588,7 +1588,7 @@ test_plugin_compare(void **state) */ diff_type_text = "20"; diff_type = ((struct lysc_node_leaf *)mod->compiled->data->next)->type; - ly_ret = diff_type->plugin->store(UTEST_LYCTX, diff_type, diff_type_text, strlen(diff_type_text), + ly_ret = lysc_get_type_plugin(diff_type->plugin)->store(UTEST_LYCTX, diff_type, diff_type_text, strlen(diff_type_text), 0, LY_VALUE_XML, NULL, LYD_VALHINT_DECNUM, NULL, &diff_type_val, NULL, &err); assert_int_equal(LY_SUCCESS, ly_ret); assert_int_equal(LY_SUCCESS, type->compare(UTEST_LYCTX, &diff_type_val, &(values[0]))); @@ -1600,7 +1600,7 @@ test_plugin_compare(void **state) */ diff_type_text = "20"; diff_type = ((struct lysc_node_leaf *)mod->compiled->data->next->next)->type; - ly_ret = diff_type->plugin->store(UTEST_LYCTX, diff_type, diff_type_text, strlen(diff_type_text), + ly_ret = lysc_get_type_plugin(diff_type->plugin)->store(UTEST_LYCTX, diff_type, diff_type_text, strlen(diff_type_text), 0, LY_VALUE_XML, NULL, LYD_VALHINT_DECNUM, NULL, &diff_type_val, NULL, &err); assert_int_equal(LY_SUCCESS, ly_ret); assert_int_equal(LY_ENOT, type->compare(UTEST_LYCTX, &diff_type_val, &(values[0]))); @@ -1612,7 +1612,7 @@ test_plugin_compare(void **state) */ diff_type_text = "20"; diff_type = ((struct lysc_node_leaf *)mod->compiled->data->next->next->next)->type; - ly_ret = diff_type->plugin->store(UTEST_LYCTX, diff_type, diff_type_text, strlen(diff_type_text), + ly_ret = lysc_get_type_plugin(diff_type->plugin)->store(UTEST_LYCTX, diff_type, diff_type_text, strlen(diff_type_text), 0, LY_VALUE_XML, NULL, LYD_VALHINT_DECNUM, NULL, &diff_type_val, NULL, &err); assert_int_equal(LY_SUCCESS, ly_ret); assert_int_equal(LY_ENOT, type->compare(UTEST_LYCTX, &diff_type_val, &(values[0]))); diff --git a/tests/utests/types/string.c b/tests/utests/types/string.c index a3d590e50..94bc8ea42 100644 --- a/tests/utests/types/string.c +++ b/tests/utests/types/string.c @@ -1240,7 +1240,7 @@ test_plugin_compare(void **state) /* SAME TYPE but different node */ diff_type_text = "hi"; diff_type = ((struct lysc_node_leaf *) mod->compiled->data->next)->type; - ly_ret = diff_type->plugin->store(UTEST_LYCTX, diff_type, diff_type_text, strlen(diff_type_text), + ly_ret = lysc_get_type_plugin(diff_type->plugin)->store(UTEST_LYCTX, diff_type, diff_type_text, strlen(diff_type_text), 0, LY_VALUE_XML, NULL, LYD_VALHINT_STRING, NULL, &diff_type_val, NULL, &err); assert_int_equal(LY_SUCCESS, ly_ret); assert_int_equal(LY_SUCCESS, type->compare(UTEST_LYCTX, &diff_type_val, &(values[0]))); diff --git a/tests/utests/utests.h b/tests/utests/utests.h index bb277ad49..50b79abc5 100644 --- a/tests/utests/utests.h +++ b/tests/utests/utests.h @@ -229,7 +229,11 @@ struct utest_context { assert_non_null(NODE); \ assert_int_equal((NODE)->basetype, TYPE); \ CHECK_ARRAY((NODE)->exts, EXTS); \ - assert_ptr_equal((NODE)->plugin, lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[TYPE])) + do { \ + uintptr_t plugin_id; \ + _lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[TYPE], &plugin_id); \ + assert_ptr_equal((NODE)->plugin, plugin_id); \ + } while (0) /** * @brief check compileted numeric type @@ -933,7 +937,7 @@ struct utest_context { * @param[in] CANNONICAL_VAL expected cannonical value */ #define CHECK_LYD_VALUE_EMPTY(NODE, CANNONICAL_VAL) \ - assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal((NODE).realtype->basetype, LY_TYPE_EMPTY); @@ -951,7 +955,7 @@ struct utest_context { * CHECK_LYD_VALUE_ ## TYPE_VAL. */ #define CHECK_LYD_VALUE_UNION(NODE, CANNONICAL_VAL, TYPE_VAL, ...) \ - assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_UNION, (NODE).realtype->basetype); \ @@ -973,7 +977,7 @@ struct utest_context { * @param[in] VALUE expected array of bits names */ #define CHECK_LYD_VALUE_BITS(NODE, ...) \ - assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, _GETARG1(__VA_ARGS__, DUMMY)); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_BITS, (NODE).realtype->basetype); \ @@ -997,7 +1001,7 @@ struct utest_context { * @brief Example enum arr[] = {0x0, 0x1}; CHECK_LYD_VALUE(node->value, INST, "test/d", arr); */ #define CHECK_LYD_VALUE_INST(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_INST, (NODE).realtype->basetype); \ @@ -1020,7 +1024,7 @@ struct utest_context { * @param[in] VALUE expected enum item name */ #define CHECK_LYD_VALUE_ENUM(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_ENUM, (NODE).realtype->basetype); \ @@ -1035,7 +1039,7 @@ struct utest_context { * @param[in] VALUE expected inteager value (-128 to 127). */ #define CHECK_LYD_VALUE_INT8(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_INT8, (NODE).realtype->basetype); \ @@ -1050,7 +1054,7 @@ struct utest_context { * @param[in] VALUE expected inteager value. */ #define CHECK_LYD_VALUE_INT16(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_INT16, (NODE).realtype->basetype); \ @@ -1065,7 +1069,7 @@ struct utest_context { * @param[in] VALUE expected inteager (0 to 255). */ #define CHECK_LYD_VALUE_UINT8(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_UINT8, (NODE).realtype->basetype); \ @@ -1080,7 +1084,7 @@ struct utest_context { * @param[in] VALUE expected inteager (0 to MAX_UINT32). */ #define CHECK_LYD_VALUE_UINT32(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_UINT32, (NODE).realtype->basetype); \ @@ -1094,7 +1098,7 @@ struct utest_context { * @param[in] CANNONICAL_VAL expected cannonical value */ #define CHECK_LYD_VALUE_STRING(NODE, CANNONICAL_VAL) \ - assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_STRING, (NODE).realtype->basetype); @@ -1107,7 +1111,7 @@ struct utest_context { * @param[in] CANNONICAL_VAL expected cannonical value */ #define CHECK_LYD_VALUE_LEAFREF(NODE, CANNONICAL_VAL) \ - assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_LEAFREF, (NODE).realtype->basetype); \ @@ -1122,7 +1126,7 @@ struct utest_context { * @param[in] VALUE expected value 64bit inteager */ #define CHECK_LYD_VALUE_DEC64(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_DEC64, (NODE).realtype->basetype); \ @@ -1143,7 +1147,7 @@ struct utest_context { LYD_VALUE_GET(&(NODE), _val); \ assert_int_equal(_val->size, SIZE); \ assert_int_equal(0, memcmp(_val->data, VALUE, SIZE)); \ - assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_BINARY, (NODE).realtype->basetype); \ @@ -1158,7 +1162,7 @@ struct utest_context { * @param[in] VALUE expected boolean value 0,1 */ #define CHECK_LYD_VALUE_BOOL(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_BOOL, (NODE).realtype->basetype); \ @@ -1173,7 +1177,7 @@ struct utest_context { * @param[in] VALUE expected ident name */ #define CHECK_LYD_VALUE_IDENT(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_IDENT, (NODE).realtype->basetype); \ From 6a54fb7c6c78eb7fdb1c49d23fd07f75615ae5c5 Mon Sep 17 00:00:00 2001 From: roman Date: Fri, 17 Jan 2025 14:41:04 +0100 Subject: [PATCH 03/25] context UPDATE widen options from 16 to 32-bit --- src/context.c | 8 ++++---- src/context.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/context.c b/src/context.c index c7f3cbb94..5607988d5 100644 --- a/src/context.c +++ b/src/context.c @@ -268,7 +268,7 @@ ly_ctx_ht_leafref_links_equal_cb(void *val1_p, void *val2_p, ly_bool UNUSED(mod) } LIBYANG_API_DEF LY_ERR -ly_ctx_new(const char *search_dir, uint16_t options, struct ly_ctx **new_ctx) +ly_ctx_new(const char *search_dir, uint32_t options, struct ly_ctx **new_ctx) { struct ly_ctx *ctx = NULL; struct lys_module *module; @@ -601,7 +601,7 @@ ly_ctx_compile(struct ly_ctx *ctx) return ret; } -LIBYANG_API_DEF uint16_t +LIBYANG_API_DEF uint32_t ly_ctx_get_options(const struct ly_ctx *ctx) { LY_CHECK_ARG_RET(ctx, ctx, 0); @@ -610,7 +610,7 @@ ly_ctx_get_options(const struct ly_ctx *ctx) } LIBYANG_API_DEF LY_ERR -ly_ctx_set_options(struct ly_ctx *ctx, uint16_t option) +ly_ctx_set_options(struct ly_ctx *ctx, uint32_t option) { LY_ERR lyrc = LY_SUCCESS; struct ly_ctx_data *ctx_data; @@ -685,7 +685,7 @@ ly_ctx_ht_leafref_links_rec_free(void *val_p) } LIBYANG_API_DEF LY_ERR -ly_ctx_unset_options(struct ly_ctx *ctx, uint16_t option) +ly_ctx_unset_options(struct ly_ctx *ctx, uint32_t option) { LY_ARRAY_COUNT_TYPE u, v; const struct lysc_ext_instance *ext; diff --git a/src/context.h b/src/context.h index 2f67138a1..6603e9bab 100644 --- a/src/context.h +++ b/src/context.h @@ -236,7 +236,7 @@ struct ly_ctx; * @param[out] new_ctx Pointer to the created libyang context if LY_SUCCESS returned. * @return LY_ERR return value. */ -LIBYANG_API_DECL LY_ERR ly_ctx_new(const char *search_dir, uint16_t options, struct ly_ctx **new_ctx); +LIBYANG_API_DECL LY_ERR ly_ctx_new(const char *search_dir, uint32_t options, struct ly_ctx **new_ctx); /** * @brief Create libyang context according to the provided yang-library data in a file. @@ -356,7 +356,7 @@ LIBYANG_API_DECL const char * const *ly_ctx_get_searchdirs(const struct ly_ctx * * @param[in] ctx Context to query. * @return Combination of all the currently set context's options, see @ref contextoptions. */ -LIBYANG_API_DECL uint16_t ly_ctx_get_options(const struct ly_ctx *ctx); +LIBYANG_API_DECL uint32_t ly_ctx_get_options(const struct ly_ctx *ctx); /** * @brief Set some of the context's options, see @ref contextoptions. @@ -366,7 +366,7 @@ LIBYANG_API_DECL uint16_t ly_ctx_get_options(const struct ly_ctx *ctx); * and all ::lysc_node.priv in the modules will be overwritten, see ::LY_CTX_SET_PRIV_PARSED. * @return LY_ERR value. */ -LIBYANG_API_DECL LY_ERR ly_ctx_set_options(struct ly_ctx *ctx, uint16_t option); +LIBYANG_API_DECL LY_ERR ly_ctx_set_options(struct ly_ctx *ctx, uint32_t option); /** * @brief Unset some of the context's options, see @ref contextoptions. @@ -374,7 +374,7 @@ LIBYANG_API_DECL LY_ERR ly_ctx_set_options(struct ly_ctx *ctx, uint16_t option); * @param[in] option Combination of the context's options to be unset, see @ref contextoptions. * @return LY_ERR value. */ -LIBYANG_API_DECL LY_ERR ly_ctx_unset_options(struct ly_ctx *ctx, uint16_t option); +LIBYANG_API_DECL LY_ERR ly_ctx_unset_options(struct ly_ctx *ctx, uint32_t option); /** * @brief Get the change count of the context (module set) during its life-time. From 1f6ac6d12c7ee219d530964996219c4fc003146c Mon Sep 17 00:00:00 2001 From: roman Date: Fri, 17 Jan 2025 15:04:40 +0100 Subject: [PATCH 04/25] context UPDATE add static plugins only flag --- src/context.c | 20 +++++++++++++++++--- src/context.h | 4 ++++ src/plugins.c | 12 +++++++----- src/plugins_internal.h | 3 ++- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/context.c b/src/context.c index 5607988d5..15b724538 100644 --- a/src/context.c +++ b/src/context.c @@ -279,7 +279,7 @@ ly_ctx_new(const char *search_dir, uint32_t options, struct ly_ctx **new_ctx) struct ly_in *in = NULL; LY_ERR rc = LY_SUCCESS; struct lys_glob_unres unres = {0}; - ly_bool builtin_plugins_only; + ly_bool builtin_plugins_only, static_plugins_only; LY_CHECK_ARG_RET(NULL, new_ctx, LY_EINVAL); @@ -291,7 +291,8 @@ ly_ctx_new(const char *search_dir, uint32_t options, struct ly_ctx **new_ctx) /* plugins */ builtin_plugins_only = (options & LY_CTX_BUILTIN_PLUGINS_ONLY) ? 1 : 0; - LY_CHECK_ERR_GOTO(lyplg_init(builtin_plugins_only), LOGINT(NULL); rc = LY_EINT, cleanup); + static_plugins_only = (options & LY_CTX_STATIC_PLUGINS_ONLY) ? 1 : 0; + LY_CHECK_ERR_GOTO(lyplg_init(builtin_plugins_only, static_plugins_only), LOGINT(NULL); rc = LY_EINT, cleanup); /* ctx data */ ctx_data = ly_ctx_data_add(ctx); @@ -628,6 +629,13 @@ ly_ctx_set_options(struct ly_ctx *ctx, uint32_t option) return LY_EINVAL; } + if (!(ctx->opts & LY_CTX_STATIC_PLUGINS_ONLY) && (option & LY_CTX_STATIC_PLUGINS_ONLY)) { + LOGERR(ctx, LY_EINVAL, + "Invalid argument %s (LY_CTX_STATIC_PLUGINS_ONLY can be set only when creating a new context) (%s()).", + "option", __func__); + return LY_EINVAL; + } + if (!(ctx->opts & LY_CTX_LEAFREF_LINKING) && (option & LY_CTX_LEAFREF_LINKING)) { ctx_data = ly_ctx_data_get(ctx); ctx_data->leafref_links_ht = lyht_new(1, sizeof(struct lyd_leafref_links_rec), ly_ctx_ht_leafref_links_equal_cb, NULL, 1); @@ -1392,7 +1400,7 @@ ly_ctx_compiled_print(const struct ly_ctx *ctx, void *mem, void **mem_end) LY_CHECK_ARG_RET(ctx, ctx, mem, LY_EINVAL); - if (ctx->plugins_types.count || ctx->plugins_extensions.count) { + if (ctx->plugins_types.count || ctx->plugins_extensions.count || !(ctx->opts & LY_CTX_STATIC_PLUGINS_ONLY)) { LOGERR(ctx, LY_EINVAL, "Printing context with dynamic type or extension plugins is not supported."); return LY_EINVAL; } @@ -1430,6 +1438,7 @@ ly_ctx_new_printed(const void *mem, struct ly_ctx **ctx) { LY_ERR rc = LY_SUCCESS; struct ly_ctx_data *ctx_data = NULL; + ly_bool builtin_plugins_only, static_plugins_only; LY_CHECK_ARG_RET(NULL, mem, ctx, LY_EINVAL); @@ -1438,6 +1447,11 @@ ly_ctx_new_printed(const void *mem, struct ly_ctx **ctx) /* ctx data */ ctx_data = ly_ctx_data_add(*ctx); + /* plugins */ + builtin_plugins_only = ((*ctx)->opts & LY_CTX_BUILTIN_PLUGINS_ONLY) ? 1 : 0; + static_plugins_only = 1; + LY_CHECK_ERR_GOTO(lyplg_init(builtin_plugins_only, static_plugins_only), LOGINT(NULL); rc = LY_EINT, cleanup); + /* data dictionary */ ctx_data->data_dict = malloc(sizeof *ctx_data->data_dict); LY_CHECK_ERR_GOTO(!ctx_data->data_dict, rc = LY_EMEM, cleanup); diff --git a/src/context.h b/src/context.h index 6603e9bab..36763ec4e 100644 --- a/src/context.h +++ b/src/context.h @@ -209,6 +209,10 @@ struct ly_ctx; invalid data needs to be stored in YANG node values. */ #define LY_CTX_LYB_HASHES 0x1000 /**< Generate hashes for all the schema nodes. Required when using LYB data parse or print. */ +#define LY_CTX_STATIC_PLUGINS_ONLY 0x2000 /**< By default, external plugins from directories the path to which is obtained + from the `LIBYANG_TYPES_PLUGINS_DIR` and `LIBYANG_EXTENSIONS_PLUGINS_DIR` environmental variables + are loaded. This option prevents loading of all external plugins and only + the static (built-in) plugins are loaded. /* 0x80000000 reserved for internal use */ diff --git a/src/plugins.c b/src/plugins.c index 221a98c8e..4ff61ef78 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -526,7 +526,7 @@ plugins_insert_dir(enum LYPLG type) #endif LY_ERR -lyplg_init(ly_bool builtin_type_plugins_only) +lyplg_init(ly_bool builtin_type_plugins_only, ly_bool static_plugins_only) { LY_ERR ret; @@ -587,11 +587,13 @@ lyplg_init(ly_bool builtin_type_plugins_only) } #ifndef STATIC - /* external types */ - LY_CHECK_GOTO(ret = plugins_insert_dir(LYPLG_TYPE), error); + if (!static_plugins_only) { + /* external types */ + LY_CHECK_GOTO(ret = plugins_insert_dir(LYPLG_TYPE), error); - /* external extensions */ - LY_CHECK_GOTO(ret = plugins_insert_dir(LYPLG_EXTENSION), error); + /* external extensions */ + LY_CHECK_GOTO(ret = plugins_insert_dir(LYPLG_EXTENSION), error); + } #endif /* initiation done, wake-up possibly waiting threads creating another contexts */ diff --git a/src/plugins_internal.h b/src/plugins_internal.h index d59a81214..0f561869f 100644 --- a/src/plugins_internal.h +++ b/src/plugins_internal.h @@ -49,11 +49,12 @@ * Covers both the types and extensions plugins. * * @param[in] builtin_type_plugins_only Whether to load only built-in YANG type plugins and no included extension plugins. + * @param[in] static_plugins_only Whether to load only static plugins, meaning no external directories with plugins. * @return LY_SUCCESS in case of success * @return LY_EINT in case of internal error * @return LY_EMEM in case of memory allocation failure. */ -LY_ERR lyplg_init(ly_bool builtin_type_plugins_only); +LY_ERR lyplg_init(ly_bool builtin_type_plugins_only, ly_bool static_plugins_only); /** * @brief Remove (unload) all the plugins currently available. From ab23d01272d48edb95d9bdb83314323ce0a673a2 Mon Sep 17 00:00:00 2001 From: roman Date: Fri, 17 Jan 2025 15:33:35 +0100 Subject: [PATCH 05/25] plugins extension REFACTOR add a dash to ext IDs --- src/plugins_exts/metadata.c | 2 +- src/plugins_exts/nacm.c | 8 +++---- src/plugins_exts/schema_mount.c | 2 +- src/plugins_exts/structure.c | 4 ++-- src/plugins_exts/yangdata.c | 2 +- src/tree_data.c | 2 +- tests/utests/extensions/test_metadata.c | 8 +++---- tests/utests/extensions/test_nacm.c | 8 +++---- tests/utests/extensions/test_schema_mount.c | 26 ++++++++++----------- tests/utests/extensions/test_structure.c | 6 ++--- tests/utests/extensions/test_yangdata.c | 14 +++++------ 11 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/plugins_exts/metadata.c b/src/plugins_exts/metadata.c index e699e120e..f6f37b45b 100644 --- a/src/plugins_exts/metadata.c +++ b/src/plugins_exts/metadata.c @@ -257,7 +257,7 @@ const struct lyplg_ext_record plugins_metadata[] = { .revision = "2016-08-05", .name = "annotation", - .plugin.id = "ly2 metadata", + .plugin.id = "ly2 - metadata", .plugin.parse = annotation_parse, .plugin.compile = annotation_compile, .plugin.printer_info = annotation_printer_info, diff --git a/src/plugins_exts/nacm.c b/src/plugins_exts/nacm.c index 85f1722d9..8bd77a6ce 100644 --- a/src/plugins_exts/nacm.c +++ b/src/plugins_exts/nacm.c @@ -173,7 +173,7 @@ const struct lyplg_ext_record plugins_nacm[] = { .revision = "2012-02-22", .name = "default-deny-write", - .plugin.id = "ly2 NACM", + .plugin.id = "ly2 - NACM", .plugin.parse = nacm_parse, .plugin.compile = nacm_compile, .plugin.printer_info = NULL, @@ -191,7 +191,7 @@ const struct lyplg_ext_record plugins_nacm[] = { .revision = "2018-02-14", .name = "default-deny-write", - .plugin.id = "ly2 NACM", + .plugin.id = "ly2 - NACM", .plugin.parse = nacm_parse, .plugin.compile = nacm_compile, .plugin.printer_info = NULL, @@ -209,7 +209,7 @@ const struct lyplg_ext_record plugins_nacm[] = { .revision = "2012-02-22", .name = "default-deny-all", - .plugin.id = "ly2 NACM", + .plugin.id = "ly2 - NACM", .plugin.parse = nacm_parse, .plugin.compile = nacm_compile, .plugin.printer_info = NULL, @@ -227,7 +227,7 @@ const struct lyplg_ext_record plugins_nacm[] = { .revision = "2018-02-14", .name = "default-deny-all", - .plugin.id = "ly2 NACM", + .plugin.id = "ly2 - NACM", .plugin.parse = nacm_parse, .plugin.compile = nacm_compile, .plugin.printer_info = NULL, diff --git a/src/plugins_exts/schema_mount.c b/src/plugins_exts/schema_mount.c index 325f8427b..bc23d62a8 100644 --- a/src/plugins_exts/schema_mount.c +++ b/src/plugins_exts/schema_mount.c @@ -1422,7 +1422,7 @@ const struct lyplg_ext_record plugins_schema_mount[] = { .revision = "2019-01-14", .name = "mount-point", - .plugin.id = "ly2 schema mount", + .plugin.id = "ly2 - schema mount", .plugin.parse = schema_mount_parse, .plugin.compile = schema_mount_compile, .plugin.printer_info = NULL, diff --git a/src/plugins_exts/structure.c b/src/plugins_exts/structure.c index 98321b9b8..bdea41932 100644 --- a/src/plugins_exts/structure.c +++ b/src/plugins_exts/structure.c @@ -562,7 +562,7 @@ const struct lyplg_ext_record plugins_structure[] = { .revision = "2020-06-17", .name = "structure", - .plugin.id = "ly2 structure", + .plugin.id = "ly2 - structure", .plugin.parse = structure_parse, .plugin.compile = structure_compile, .plugin.printer_info = structure_printer_info, @@ -581,7 +581,7 @@ const struct lyplg_ext_record plugins_structure[] = { .revision = "2020-06-17", .name = "augment-structure", - .plugin.id = "ly2 structure", + .plugin.id = "ly2 - structure", .plugin.parse = structure_aug_parse, .plugin.compile = NULL, .plugin.printer_info = NULL, diff --git a/src/plugins_exts/yangdata.c b/src/plugins_exts/yangdata.c index 917ce19dd..ea3bc9b10 100644 --- a/src/plugins_exts/yangdata.c +++ b/src/plugins_exts/yangdata.c @@ -278,7 +278,7 @@ const struct lyplg_ext_record plugins_yangdata[] = { .revision = "2017-01-26", .name = "yang-data", - .plugin.id = "ly2 yang-data", + .plugin.id = "ly2 - yang-data", .plugin.parse = yangdata_parse, .plugin.compile = yangdata_compile, .plugin.printer_info = yangdata_printer_info, diff --git a/src/tree_data.c b/src/tree_data.c index 8b4781a4c..7cc5271f7 100644 --- a/src/tree_data.c +++ b/src/tree_data.c @@ -1329,7 +1329,7 @@ lyd_get_meta_annotation(const struct lys_module *mod, const char *name, size_t n LY_ARRAY_FOR(mod->compiled->exts, u) { plugin = mod->compiled->exts[u].def->plugin; - if (plugin && !strncmp(plugin->id, "ly2 metadata", 12) && + if (plugin && !strncmp(plugin->id, "ly2 - metadata", 12) && !ly_strncmp(mod->compiled->exts[u].argument, name, name_len)) { return &mod->compiled->exts[u]; } diff --git a/tests/utests/extensions/test_metadata.c b/tests/utests/extensions/test_metadata.c index c3b58b2b1..f526323ad 100644 --- a/tests/utests/extensions/test_metadata.c +++ b/tests/utests/extensions/test_metadata.c @@ -52,7 +52,7 @@ test_yang(void **state) "import ietf-yang-metadata {prefix md;}" "md:annotation aa;}"; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 metadata\": Missing mandatory keyword \"type\" as a child of \"md:annotation aa\".", + CHECK_LOG_CTX("Ext plugin \"ly2 - metadata\": Missing mandatory keyword \"type\" as a child of \"md:annotation aa\".", "/aa:{extension='md:annotation'}/aa", 0); /* not allowed substatement */ @@ -89,7 +89,7 @@ test_yang(void **state) "import ietf-yang-metadata {prefix md;}" "md:annotation aa {type string;} md:annotation aa {type uint8;}}"; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 metadata\": Extension md:annotation is instantiated multiple times.", + CHECK_LOG_CTX("Ext plugin \"ly2 - metadata\": Extension md:annotation is instantiated multiple times.", "/aa:{extension='md:annotation'}/aa", 0); } @@ -130,7 +130,7 @@ test_yin(void **state) "\n" ""; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YIN, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 metadata\": Missing mandatory keyword \"type\" as a child of \"md:annotation aa\".", + CHECK_LOG_CTX("Ext plugin \"ly2 - metadata\": Missing mandatory keyword \"type\" as a child of \"md:annotation aa\".", "/aa:{extension='md:annotation'}/aa", 0); /* not allowed substatement */ @@ -189,7 +189,7 @@ test_yin(void **state) " \n" ""; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YIN, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 metadata\": Extension md:annotation is instantiated multiple times.", + CHECK_LOG_CTX("Ext plugin \"ly2 - metadata\": Extension md:annotation is instantiated multiple times.", "/aa:{extension='md:annotation'}/aa", 0); } diff --git a/tests/utests/extensions/test_nacm.c b/tests/utests/extensions/test_nacm.c index 9cbad1e3f..44daf3bf0 100644 --- a/tests/utests/extensions/test_nacm.c +++ b/tests/utests/extensions/test_nacm.c @@ -56,7 +56,7 @@ test_deny_all(void **state) "import ietf-netconf-acm {revision-date 2018-02-14; prefix nacm;}" "nacm:default-deny-all;}"; assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 NACM\": " + CHECK_LOG_CTX("Ext plugin \"ly2 - NACM\": " "Extension nacm:default-deny-all is allowed only in a data nodes, but it is placed in \"module\" statement.", "/b:{extension='nacm:default-deny-all'}", 0); @@ -65,7 +65,7 @@ test_deny_all(void **state) "import ietf-netconf-acm {revision-date 2018-02-14; prefix nacm;}" "leaf l { type string; nacm:default-deny-all; nacm:default-deny-write;}}"; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 NACM\": " + CHECK_LOG_CTX("Ext plugin \"ly2 - NACM\": " "Extension nacm:default-deny-write is mixed with nacm:default-deny-all.", "/aa:l/{extension='nacm:default-deny-all'}", 0); } @@ -98,7 +98,7 @@ test_deny_write(void **state) "import ietf-netconf-acm {revision-date 2018-02-14; prefix nacm;}" "notification notif {nacm:default-deny-write;}}"; assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 NACM\": " + CHECK_LOG_CTX("Ext plugin \"ly2 - NACM\": " "Extension nacm:default-deny-write is not allowed in notification statement.", "/b:notif/{extension='nacm:default-deny-write'}", 0); @@ -107,7 +107,7 @@ test_deny_write(void **state) "import ietf-netconf-acm {revision-date 2018-02-14; prefix nacm;}" "leaf l { type string; nacm:default-deny-write; nacm:default-deny-write;}}"; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 NACM\": " + CHECK_LOG_CTX("Ext plugin \"ly2 - NACM\": " "Extension nacm:default-deny-write is instantiated multiple times.", "/aa:l/{extension='nacm:default-deny-write'}", 0); } diff --git a/tests/utests/extensions/test_schema_mount.c b/tests/utests/extensions/test_schema_mount.c index 75cfa88ed..e1c4fcbc9 100644 --- a/tests/utests/extensions/test_schema_mount.c +++ b/tests/utests/extensions/test_schema_mount.c @@ -73,7 +73,7 @@ test_schema(void **state) " }\n" "}\n"; assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": " + CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": " "Extension \"yangmnt:mount-point\" instance not allowed in YANG version 1 module.", "/sm:root/{extension='yangmnt:mount-point'}/root", 0); @@ -90,7 +90,7 @@ test_schema(void **state) " yangmnt:mount-point \"root\";\n" "}\n"; assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": " + CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": " "Extension \"yangmnt:mount-point\" instance allowed only in container or list statement.", "/sm:{extension='yangmnt:mount-point'}/root", 0); @@ -112,7 +112,7 @@ test_schema(void **state) " }\n" "}\n"; assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": " + CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": " "Extension \"yangmnt:mount-point\" instance allowed only in container or list statement.", "/sm:root/l/{extension='yangmnt:mount-point'}/root", 0); @@ -136,7 +136,7 @@ test_schema(void **state) " }\n" "}\n"; assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": " + CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": " "Multiple extension \"yangmnt:mount-point\" instances.", "/sm:l/{extension='yangmnt:mount-point'}/root", 0); @@ -196,7 +196,7 @@ test_parse_invalid(void **state) " " ""; CHECK_PARSE_LYD_PARAM(xml, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EINVAL, data); - CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": Failed to get extension data, no callback set.", + CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": Failed to get extension data, no callback set.", NULL, 0); json = @@ -213,7 +213,7 @@ test_parse_invalid(void **state) " }" "}"; CHECK_PARSE_LYD_PARAM(json, LYD_JSON, 0, LYD_VALIDATE_PRESENT, LY_EINVAL, data); - CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": Failed to get extension data, no callback set.", + CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": Failed to get extension data, no callback set.", NULL, 0); /* unknown data */ @@ -401,22 +401,22 @@ test_parse_invalid(void **state) " " ""); CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); - CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": Mandatory node \"type\" instance does not exist.", + CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": Mandatory node \"type\" instance does not exist.", "/ietf-interfaces:interfaces/interface[name='bu']", 0); CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); - CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": Mandatory node \"type\" instance does not exist.", + CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": Mandatory node \"type\" instance does not exist.", "/ietf-interfaces:interfaces/interface[name='bu']", 0); /* same validation fail in separate validation */ CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT | LYD_PARSE_ONLY, 0, LY_SUCCESS, data); assert_int_equal(LY_EVALID, lyd_validate_all(&data, NULL, LYD_VALIDATE_PRESENT, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": Mandatory node \"type\" instance does not exist.", + CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": Mandatory node \"type\" instance does not exist.", "/ietf-interfaces:interfaces/interface[name='bu']", 0); lyd_free_siblings(data); CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT | LYD_PARSE_ONLY, 0, LY_SUCCESS, data); assert_int_equal(LY_EVALID, lyd_validate_all(&data, NULL, LYD_VALIDATE_PRESENT, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": Mandatory node \"type\" instance does not exist.", + CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": Mandatory node \"type\" instance does not exist.", "/ietf-interfaces:interfaces/interface[name='bu']", 0); lyd_free_siblings(data); @@ -865,7 +865,7 @@ test_parse_shared(void **state) " \n" "\n"; CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); - CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": " + CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": " "Shared-schema yang-library content-id \"2\" differs from \"1\" used previously.", "/ietf-yang-library:yang-library/content-id", 0); @@ -1121,7 +1121,7 @@ test_parse_shared_parent_ref(void **state) "\n" "wrong-target-value\n"; CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); - CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": " + CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": " "Invalid leafref value \"target-value\" - no target instance \"/sm:target\" with the same value.", "/ietf-interfaces:interfaces/interface[name='bu']/sm:sm-name", 0); @@ -1146,7 +1146,7 @@ test_parse_shared_parent_ref(void **state) " \"sm:target\": \"wrong-target-value\"\n" "}\n"; CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); - CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": " + CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": " "Invalid leafref value \"target-value\" - no target instance \"/sm:target\" with the same value.", "/ietf-interfaces:interfaces/interface[name='bu']/sm:sm-name", 0); diff --git a/tests/utests/extensions/test_structure.c b/tests/utests/extensions/test_structure.c index 026f6e7db..d67c001dd 100644 --- a/tests/utests/extensions/test_structure.c +++ b/tests/utests/extensions/test_structure.c @@ -154,7 +154,7 @@ test_schema_invalid(void **state) "import ietf-yang-structure-ext {prefix sx;}" "container b { sx:structure struct { container x { leaf x {type string;}}}}}"; UTEST_INVALID_MODULE(data, LYS_IN_YANG, NULL, LY_EVALID); - CHECK_LOG_CTX("Ext plugin \"ly2 structure\": " + CHECK_LOG_CTX("Ext plugin \"ly2 - structure\": " "Extension sx:structure must not be used as a non top-level statement in \"container\" statement.", "/a:b/{extension='sx:structure'}/struct", 0); @@ -170,7 +170,7 @@ test_schema_invalid(void **state) "sx:structure struct { container x { leaf x {type string;}}}" "sx:structure struct { container y { leaf y {type string;}}}}"; UTEST_INVALID_MODULE(data, LYS_IN_YANG, NULL, LY_EVALID); - CHECK_LOG_CTX("Ext plugin \"ly2 structure\": Extension sx:structure is instantiated multiple times.", + CHECK_LOG_CTX("Ext plugin \"ly2 - structure\": Extension sx:structure is instantiated multiple times.", "/a:{extension='sx:structure'}/struct", 0); data = "module a {yang-version 1.1; namespace urn:tests:extensions:structure:a; prefix self;" @@ -178,7 +178,7 @@ test_schema_invalid(void **state) "sx:structure struct { container x { leaf x {type string;}}}" "choice struct { container y { leaf y {type string;}}}}"; UTEST_INVALID_MODULE(data, LYS_IN_YANG, NULL, LY_EVALID); - CHECK_LOG_CTX("Ext plugin \"ly2 structure\": Extension sx:structure collides with a choice with the same identifier.", + CHECK_LOG_CTX("Ext plugin \"ly2 - structure\": Extension sx:structure collides with a choice with the same identifier.", "/a:{extension='sx:structure'}/struct", 0); /* augment-structure */ diff --git a/tests/utests/extensions/test_yangdata.c b/tests/utests/extensions/test_yangdata.c index 3977992da..424789369 100644 --- a/tests/utests/extensions/test_yangdata.c +++ b/tests/utests/extensions/test_yangdata.c @@ -117,7 +117,7 @@ test_schema(void **state) "}\n"; assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, &mod)); assert_null(mod->compiled->exts); - CHECK_LOG_CTX("Ext plugin \"ly2 yang-data\": " + CHECK_LOG_CTX("Ext plugin \"ly2 - yang-data\": " "Extension rc:yang-data is ignored since it appears as a non top-level statement in \"container\" statement.", "/b:b/{extension='rc:yang-data'}/template", 0); assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YANG_COMPILED, 0)); @@ -174,7 +174,7 @@ test_schema_invalid(void **state) "import ietf-restconf {revision-date 2017-01-26; prefix rc;}" "rc:yang-data template { choice x { leaf x {type string;}}}}"; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 yang-data\": " + CHECK_LOG_CTX("Ext plugin \"ly2 - yang-data\": " "Extension rc:yang-data is instantiated with leaf top level data node (inside a choice), " "but only a single container data node is allowed.", "/a:{extension='rc:yang-data'}/template", 0); @@ -182,7 +182,7 @@ test_schema_invalid(void **state) "import ietf-restconf {revision-date 2017-01-26; prefix rc;}" "rc:yang-data template { choice x { case x { container z {presence ppp;} leaf x {type string;}}}}}"; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 yang-data\": " + CHECK_LOG_CTX("Ext plugin \"ly2 - yang-data\": " "Extension rc:yang-data is instantiated with multiple top level data nodes (inside a single choice's case), " "but only a single container data node is allowed.", "/a:{extension='rc:yang-data'}/template", 0); @@ -190,7 +190,7 @@ test_schema_invalid(void **state) "import ietf-restconf {revision-date 2017-01-26; prefix rc;}" "rc:yang-data template { container x { leaf x {type string;}} container y { leaf y {type string;}}}}"; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 yang-data\": " + CHECK_LOG_CTX("Ext plugin \"ly2 - yang-data\": " "Extension rc:yang-data is instantiated with multiple top level data nodes, " "but only a single container data node is allowed.", "/a:{extension='rc:yang-data'}/template", 0); @@ -198,7 +198,7 @@ test_schema_invalid(void **state) "import ietf-restconf {revision-date 2017-01-26; prefix rc;}" "rc:yang-data template;}"; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 yang-data\": " + CHECK_LOG_CTX("Ext plugin \"ly2 - yang-data\": " "Extension rc:yang-data is instantiated without any top level data node, " "but exactly one container data node is expected.", "/a:{extension='rc:yang-data'}/template", 0); @@ -214,7 +214,7 @@ test_schema_invalid(void **state) "rc:yang-data template { container x { leaf x {type string;}}}" "rc:yang-data template { container y { leaf y {type string;}}}}"; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 yang-data\": " + CHECK_LOG_CTX("Ext plugin \"ly2 - yang-data\": " "Extension rc:yang-data is instantiated multiple times.", "/a:{extension='rc:yang-data'}/template", 0); data = "module a {yang-version 1.1; namespace urn:tests:extensions:yangdata:a; prefix self;" @@ -222,7 +222,7 @@ test_schema_invalid(void **state) "grouping t { leaf-list x {type string;}}" "rc:yang-data template { uses t;}}"; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 yang-data\": " + CHECK_LOG_CTX("Ext plugin \"ly2 - yang-data\": " "Extension rc:yang-data is instantiated with leaf-list top level data node, " "but only a single container data node is allowed.", "/a:{extension='rc:yang-data'}/template", 0); } From 1615a6c3e1a4281bb11fa73295680bd8fbb69d20 Mon Sep 17 00:00:00 2001 From: roman Date: Mon, 20 Jan 2025 11:11:37 +0100 Subject: [PATCH 06/25] plugins types UPDATE simplify type plugin getter --- src/context.h | 2 +- src/plugins.c | 52 ++++++++++++++++++++++--------- src/plugins_internal.h | 7 ++--- src/plugins_types.c | 15 ++++++--- src/plugins_types/union.c | 38 ++++++++++++++-------- src/printer_lyb.c | 8 +++-- src/printer_xml.c | 7 +++-- src/schema_compile.c | 6 ++-- src/schema_compile_node.c | 26 ++++++---------- src/tree_data_common.c | 28 +++++++++++------ src/tree_data_hash.c | 7 +++-- src/tree_data_new.c | 16 ++++++---- src/tree_schema.h | 30 +++++++++--------- src/validation.c | 3 +- src/xpath.c | 6 ++-- tests/utests/basic/test_plugins.c | 4 +-- tests/utests/types/binary.c | 8 ++--- tests/utests/types/bits.c | 10 +++--- tests/utests/types/enumeration.c | 2 +- tests/utests/types/inet_types.c | 8 ++--- tests/utests/types/int8.c | 8 ++--- tests/utests/types/leafref.c | 2 +- tests/utests/types/string.c | 8 ++--- tests/utests/types/union.c | 2 +- tests/utests/types/yang_types.c | 2 +- tests/utests/utests.h | 6 +--- 26 files changed, 181 insertions(+), 130 deletions(-) diff --git a/src/context.h b/src/context.h index 36763ec4e..d97ce7f00 100644 --- a/src/context.h +++ b/src/context.h @@ -212,7 +212,7 @@ struct ly_ctx; #define LY_CTX_STATIC_PLUGINS_ONLY 0x2000 /**< By default, external plugins from directories the path to which is obtained from the `LIBYANG_TYPES_PLUGINS_DIR` and `LIBYANG_EXTENSIONS_PLUGINS_DIR` environmental variables are loaded. This option prevents loading of all external plugins and only - the static (built-in) plugins are loaded. + the static (built-in) plugins are loaded. */ /* 0x80000000 reserved for internal use */ diff --git a/src/plugins.c b/src/plugins.c index 4ff61ef78..b84199901 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -132,16 +132,41 @@ static struct ly_set plugins_handlers = {0}; static struct ly_set plugins_types = {0}; static struct ly_set plugins_extensions = {0}; -LIBYANG_API_DEF struct lyplg_type * -lysc_get_type_plugin(uintptr_t plugin_id) +/** + * @brief Get the plugin of the given @p type. + * + * @param[in] plugin_id Either an index of the built-in plugin (offset by +1) or a pointer to the external plugin. + * @param[in] type Type of the plugin to get. + * @param[in] plugins Array of the built-in plugins used in case @p plugin_id is an index of a built-in plugin. + * @return Plugin of the given @p type or NULL if not found. + */ +static void * +lysc_get_plugin(uintptr_t plugin_id, enum LYPLG type, const struct ly_set *plugins) { - if (plugin_id < plugins_types.count) { - return &((struct lyplg_type_record *)plugins_types.objs[plugin_id])->plugin; + /* plugin_id is offset by +1, so 0 is invalid (NULL ptr equivalent) */ + if (!plugin_id) { + return NULL; + } + + if (plugin_id <= plugins->count) { + /* plugin is built-in, fetch it from the global list */ + if (type == LYPLG_EXTENSION) { + return &((struct lyplg_ext_record *)plugins->objs[plugin_id - 1])->plugin; + } else { + return &((struct lyplg_type_record *)plugins->objs[plugin_id - 1])->plugin; + } } else { - return (struct lyplg_type *)plugin_id; + /* plugin is external, return the pointer */ + return (void *)plugin_id; } } +LIBYANG_API_DEF struct lyplg_type * +lysc_get_type_plugin(uintptr_t plugin_id) +{ + return lysc_get_plugin(plugin_id, LYPLG_TYPE, &plugins_types); +} + /** * @brief Iterate over list of loaded plugins of the given @p type. * @@ -200,11 +225,11 @@ lyplg_record_find(const struct ly_ctx *ctx, enum LYPLG type, const char *module, return NULL; } -LY_ERR -_lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name, uintptr_t *out) +uintptr_t +lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name) { struct lyplg_type_record *record = NULL; - uint32_t record_idx; + uint32_t record_idx = 0; if (ctx) { /* try to find context specific plugin */ @@ -217,18 +242,17 @@ _lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char } if (!record) { - return LY_ENOTFOUND; + /* not found */ + return 0; } if (!strncmp(record->plugin.id, "ly2 - ", 6)) { - /* internal plugin, return an index */ - *out = record_idx; + /* internal plugin, return an index with an offset of +1 in order to keep 0 as an invalid index (a NULL ptr) */ + return record_idx + 1; } else { /* external plugin, return the pointer */ - *out = (uintptr_t)&record->plugin; + return (uintptr_t)&record->plugin; } - - return LY_SUCCESS; } struct lyplg_type * diff --git a/src/plugins_internal.h b/src/plugins_internal.h index 0f561869f..983a08027 100644 --- a/src/plugins_internal.h +++ b/src/plugins_internal.h @@ -61,8 +61,6 @@ LY_ERR lyplg_init(ly_bool builtin_type_plugins_only, ly_bool static_plugins_only */ void lyplg_clean(void); -LY_ERR _lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name, uintptr_t *out); - /** * @brief Find a type plugin. * @@ -72,9 +70,10 @@ LY_ERR _lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, con * @param[in] revision Revision of the module for which the plugin is implemented. NULL is not a wildcard, it matches * only the plugins with NULL revision specified. * @param[in] name Name of the type which the plugin implements. - * @return Found type plugin, NULL if none found. + * @return ID of the found type plugin, 0 if none found. The type plugin can be obtained + * by passing the returned ID to ::lysc_get_type_plugin(). */ -struct lyplg_type *lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name); +uintptr_t lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name); /** * @brief Find an extension plugin. diff --git a/src/plugins_types.c b/src/plugins_types.c index bd7827b70..56cac666d 100644 --- a/src/plugins_types.c +++ b/src/plugins_types.c @@ -900,11 +900,13 @@ lyplg_type_print_val(const struct lysc_node *node, const char *canon, LY_VALUE_F struct ly_err_item *err = NULL; const char *v; ly_bool dyn; + struct lyplg_type *type_plugin; type = ((struct lysc_node_leaf *)node)->type; + type_plugin = lysc_get_type_plugin(type->plugin); /* store the value */ - r = lysc_get_type_plugin(type->plugin)->store(node->module->ctx, type, canon, strlen(canon), LYPLG_TYPE_STORE_ONLY, LY_VALUE_CANON, + r = type_plugin->store(node->module->ctx, type, canon, strlen(canon), LYPLG_TYPE_STORE_ONLY, LY_VALUE_CANON, NULL, LYD_HINT_DATA, node, &storage, NULL, &err); if (r && (r != LY_EINCOMPLETE)) { if (err) { @@ -915,7 +917,7 @@ lyplg_type_print_val(const struct lysc_node *node, const char *canon, LY_VALUE_F } /* print it in the specific format */ - v = lysc_get_type_plugin(type->plugin)->print(node->module->ctx, &storage, format, prefix_data, &dyn, NULL); + v = type_plugin->print(node->module->ctx, &storage, format, prefix_data, &dyn, NULL); /* store it in the dictionary, storage will be freed */ if (dyn) { @@ -924,7 +926,7 @@ lyplg_type_print_val(const struct lysc_node *node, const char *canon, LY_VALUE_F lydict_dup(node->module->ctx, v, value); } - lysc_get_type_plugin(type->plugin)->free(node->module->ctx, &storage); + type_plugin->free(node->module->ctx, &storage); return LY_SUCCESS; } @@ -1050,6 +1052,7 @@ lyplg_type_resolve_leafref(const struct lysc_type_leafref *lref, const struct ly const char *val_str, *xp_err_msg; uint32_t i; int r; + struct lyplg_type *type; LY_CHECK_ARG_RET(NULL, lref, node, value, errmsg, LY_EINVAL); @@ -1096,6 +1099,8 @@ lyplg_type_resolve_leafref(const struct lysc_type_leafref *lref, const struct ly goto cleanup; } + type = lysc_get_type_plugin(lref->plugin); + /* check the result */ if (target_path) { /* no or exact match(es) */ @@ -1110,7 +1115,7 @@ lyplg_type_resolve_leafref(const struct lysc_type_leafref *lref, const struct ly continue; } - if (!lysc_get_type_plugin(lref->plugin)->compare(LYD_CTX(node), &((struct lyd_node_term *)set.val.nodes[i].node)->value, value)) { + if (!type->compare(LYD_CTX(node), &((struct lyd_node_term *)set.val.nodes[i].node)->value, value)) { break; } } @@ -1135,7 +1140,7 @@ lyplg_type_resolve_leafref(const struct lysc_type_leafref *lref, const struct ly continue; } - if (!lysc_get_type_plugin(lref->plugin)->compare(LYD_CTX(node), &((struct lyd_node_term *)set.val.nodes[i].node)->value, value)) { + if (!type->compare(LYD_CTX(node), &((struct lyd_node_term *)set.val.nodes[i].node)->value, value)) { rc = ly_set_add(*targets, set.val.nodes[i].node, 0, NULL); LY_CHECK_GOTO(rc, cleanup); } diff --git a/src/plugins_types/union.c b/src/plugins_types/union.c index 36618d1c9..1fb3d8382 100644 --- a/src/plugins_types/union.c +++ b/src/plugins_types/union.c @@ -178,6 +178,7 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3 LY_VALUE_FORMAT format; void *prefix_data; uint32_t opts = 0, ti; + struct lyplg_type *type_plugin; *err = NULL; @@ -196,7 +197,7 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3 assert(subvalue->value.realtype); value = lysc_get_type_plugin(subvalue->value.realtype->plugin)->print(ctx, &subvalue->value, - LY_VALUE_JSON, NULL, &dynamic, &value_len); + LY_VALUE_JSON, NULL, &dynamic, &value_len); /* to avoid leaks, free subvalue->value, but we need the value, which may be stored there */ if (!dynamic) { @@ -225,7 +226,9 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3 opts |= LYPLG_TYPE_STORE_DYNAMIC; } - rc = lysc_get_type_plugin(type->plugin)->store(ctx, type, value, value_len, opts, format, prefix_data, + type_plugin = lysc_get_type_plugin(type->plugin); + + rc = type_plugin->store(ctx, type, value, value_len, opts, format, prefix_data, subvalue->hints, subvalue->ctx_node, &subvalue->value, unres, err); if ((rc != LY_SUCCESS) && (rc != LY_EINCOMPLETE)) { /* clear any leftover/freed garbage */ @@ -235,10 +238,10 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3 if (validate && (rc == LY_EINCOMPLETE)) { /* we need the value validated */ - rc = lysc_get_type_plugin(type->plugin)->validate(ctx, type, ctx_node, tree, &subvalue->value, err); + rc = type_plugin->validate(ctx, type, ctx_node, tree, &subvalue->value, err); if (rc) { /* validate failed, we need to free the stored value */ - lysc_get_type_plugin(type->plugin)->free(ctx, &subvalue->value); + type_plugin->free(ctx, &subvalue->value); } } @@ -271,6 +274,7 @@ union_find_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct uint32_t *prev_lo, temp_lo = 0; char *msg = NULL; int msg_len = 0; + struct lyplg_type *type; *err = NULL; @@ -308,9 +312,11 @@ union_find_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct continue; } - msg = ly_realloc(msg, msg_len + 4 + strlen(lysc_get_type_plugin(type_u->types[u]->plugin)->id) + 2 + strlen(errs[u]->msg) + 2); + type = lysc_get_type_plugin(type_u->types[u]->plugin); + + msg = ly_realloc(msg, msg_len + 4 + strlen(type->id) + 2 + strlen(errs[u]->msg) + 2); LY_CHECK_ERR_GOTO(!msg, ret = LY_EMEM, cleanup); - msg_len += sprintf(msg + msg_len, " %s: %s\n", lysc_get_type_plugin(type_u->types[u]->plugin)->id, errs[u]->msg); + msg_len += sprintf(msg + msg_len, " %s: %s\n", type->id, errs[u]->msg); } ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "%s", msg); @@ -445,14 +451,16 @@ lyplg_type_validate_union(const struct ly_ctx *ctx, const struct lysc_type *type struct lyd_value orig = {0}; uint32_t type_idx; ly_bool validated = 0; + struct lyplg_type *subvalue_type; *err = NULL; /* because of types that do not store their own type as realtype (leafref), we are not able to call their * validate callback (there is no way to get the type) but even if possible, the value may be invalid * for the type, so we may have to perform union value storing again from scratch, but keep a value backup */ - LY_CHECK_RET(lysc_get_type_plugin(subvalue->value.realtype->plugin)->duplicate(ctx, &subvalue->value, &orig)); - lysc_get_type_plugin(subvalue->value.realtype->plugin)->free(ctx, &subvalue->value); + subvalue_type = lysc_get_type_plugin(subvalue->value.realtype->plugin); + LY_CHECK_RET(subvalue_type->duplicate(ctx, &subvalue->value, &orig)); + subvalue_type->free(ctx, &subvalue->value); if (subvalue->format == LY_VALUE_LYB) { /* use the specific type to store and validate the value */ @@ -492,7 +500,8 @@ lyplg_type_compare_union(const struct ly_ctx *ctx, const struct lyd_value *val1, if (val1->subvalue->value.realtype != val2->subvalue->value.realtype) { return LY_ENOT; } - return lysc_get_type_plugin(val1->subvalue->value.realtype->plugin)->compare(ctx, &val1->subvalue->value, &val2->subvalue->value); + return lysc_get_type_plugin(val1->subvalue->value.realtype->plugin)->compare(ctx, + &val1->subvalue->value, &val2->subvalue->value); } LIBYANG_API_DEF int @@ -503,7 +512,8 @@ lyplg_type_sort_union(const struct ly_ctx *ctx, const struct lyd_value *val1, co struct lysc_type **types; if (val1->subvalue->value.realtype == val2->subvalue->value.realtype) { - return lysc_get_type_plugin(val1->subvalue->value.realtype->plugin)->sort(ctx, &val1->subvalue->value, &val2->subvalue->value); + return lysc_get_type_plugin(val1->subvalue->value.realtype->plugin)->sort(ctx, + &val1->subvalue->value, &val2->subvalue->value); } /* compare according to the order of types */ @@ -561,8 +571,8 @@ lyb_union_print(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct LY_CHECK_RET((r != LY_SUCCESS) && (r != LY_EINCOMPLETE), NULL); /* Print subvalue in LYB format. */ - pval = (void *)lysc_get_type_plugin(subvalue->value.realtype->plugin)->print(NULL, &subvalue->value, LY_VALUE_LYB, prefix_data, &dynamic, - &pval_len); + pval = (void *)lysc_get_type_plugin(subvalue->value.realtype->plugin)->print(NULL, &subvalue->value, LY_VALUE_LYB, + prefix_data, &dynamic, &pval_len); LY_CHECK_RET(!pval, NULL); /* Create LYB data. */ @@ -590,6 +600,7 @@ lyplg_type_print_union(const struct ly_ctx *ctx, const struct lyd_value *value, struct lyd_value_union *subvalue = value->subvalue; struct lysc_type_union *type_u = (struct lysc_type_union *)value->realtype; size_t lyb_data_len = 0; + struct lyplg_type *type; if ((format == LY_VALUE_LYB) && (subvalue->format == LY_VALUE_LYB)) { /* The return value is already ready. */ @@ -609,7 +620,8 @@ lyplg_type_print_union(const struct ly_ctx *ctx, const struct lyd_value *value, } assert(format != LY_VALUE_LYB); - ret = (void *)lysc_get_type_plugin(subvalue->value.realtype->plugin)->print(ctx, &subvalue->value, format, prefix_data, dynamic, value_len); + type = lysc_get_type_plugin(subvalue->value.realtype->plugin); + ret = (void *)type->print(ctx, &subvalue->value, format, prefix_data, dynamic, value_len); if (!value->_canonical && (format == LY_VALUE_CANON)) { /* the canonical value is supposed to be stored now */ lydict_insert(ctx, subvalue->value._canonical, 0, (const char **)&value->_canonical); diff --git a/src/printer_lyb.c b/src/printer_lyb.c index f1ca2b183..95094b86c 100644 --- a/src/printer_lyb.c +++ b/src/printer_lyb.c @@ -678,14 +678,16 @@ lyb_print_term_value(struct lyd_node_term *term, struct ly_out *out, struct lyly size_t value_len = 0; int32_t lyb_data_len; lyplg_type_print_clb print; + struct lyplg_type *type; - assert(term->value.realtype && lysc_get_type_plugin(term->value.realtype->plugin)->print && term->schema); + assert(term->value.realtype && (type = lysc_get_type_plugin(term->value.realtype->plugin)) && + type->print && term->schema); /* Get length of LYB data to print. */ - lyb_data_len = lysc_get_type_plugin(term->value.realtype->plugin)->lyb_data_len; + lyb_data_len = type->lyb_data_len; /* Get value and also print its length only if size is not fixed. */ - print = lysc_get_type_plugin(term->value.realtype->plugin)->print; + print = type->print; if (lyb_data_len < 0) { /* Variable-length data. */ diff --git a/src/printer_xml.c b/src/printer_xml.c index e7201234c..0907bb948 100644 --- a/src/printer_xml.c +++ b/src/printer_xml.c @@ -217,7 +217,8 @@ xml_print_meta(struct xmlpr_ctx *pctx, const struct lyd_node *node) ly_set_add(&ns_list, NULL, 0, NULL); /* print the value */ - value = lysc_get_type_plugin(meta->value.realtype->plugin)->print(LYD_CTX(node), &meta->value, LY_VALUE_XML, &ns_list, &dynamic, NULL); + value = lysc_get_type_plugin(meta->value.realtype->plugin)->print(LYD_CTX(node), + &meta->value, LY_VALUE_XML, &ns_list, &dynamic, NULL); /* print namespaces connected with the value's prefixes */ for (i = 1; i < ns_list.count; ++i) { @@ -339,8 +340,8 @@ xml_print_term(struct xmlpr_ctx *pctx, const struct lyd_node_term *node) } /* print the value */ - value = lysc_get_type_plugin(((struct lysc_node_leaf *)node->schema)->type->plugin)->print(LYD_CTX(node), &node->value, LY_VALUE_XML, - &ns_list, &dynamic, NULL); + value = lysc_get_type_plugin(((struct lysc_node_leaf *)node->schema)->type->plugin)->print(LYD_CTX(node), + &node->value, LY_VALUE_XML, &ns_list, &dynamic, NULL); LY_CHECK_ERR_GOTO(!value, rc = LY_EINVAL, cleanup); /* print node opening */ diff --git a/src/schema_compile.c b/src/schema_compile.c index 094f5f17b..3e43344d4 100644 --- a/src/schema_compile.c +++ b/src/schema_compile.c @@ -896,9 +896,11 @@ lys_compile_unres_dflt(struct lysc_ctx *ctx, struct lysc_node *node, struct lysc struct lyd_value storage = {0}; struct ly_err_item *err = NULL; LY_VALUE_FORMAT format; + struct lyplg_type *type_plugin; options = (ctx->ctx->opts & LY_CTX_REF_IMPLEMENTED) ? LYPLG_TYPE_STORE_IMPLEMENT : 0; - rc = lysc_get_type_plugin(type->plugin)->store(ctx->ctx, type, dflt, strlen(dflt), options, LY_VALUE_SCHEMA, (void *)dflt_pmod, + type_plugin = lysc_get_type_plugin(type->plugin); + rc = type_plugin->store(ctx->ctx, type, dflt, strlen(dflt), options, LY_VALUE_SCHEMA, (void *)dflt_pmod, LYD_HINT_SCHEMA, node, &storage, unres, &err); if (rc == LY_ERECOMPILE) { /* fine, but we need to recompile */ @@ -925,7 +927,7 @@ lys_compile_unres_dflt(struct lysc_ctx *ctx, struct lysc_node *node, struct lysc } cleanup: - lysc_get_type_plugin(type->plugin)->free(ctx->ctx, &storage); + type_plugin->free(ctx->ctx, &storage); return rc; } diff --git a/src/schema_compile_node.c b/src/schema_compile_node.c index cd9730309..b6f681a5a 100644 --- a/src/schema_compile_node.c +++ b/src/schema_compile_node.c @@ -2133,7 +2133,7 @@ LY_ERR lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t context_flags, const char *context_name, const struct lysp_type *type_p, struct lysc_type **type, const char **units, struct lysp_qname **dflt) { - LY_ERR ret = LY_SUCCESS, r; + LY_ERR ret = LY_SUCCESS; ly_bool dummyloops = 0, has_leafref; struct lys_type_item *tctx, *tctx_prev = NULL, *tctx_iter; LY_DATA_TYPE basetype = LY_TYPE_UNKNOWN; @@ -2141,8 +2141,7 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t struct lysc_type_union *base_un; LY_ARRAY_COUNT_TYPE u; struct ly_set tpdf_chain = {0}; - uintptr_t plugin_id = -1; - ly_bool plugin_found = 0; + uintptr_t plugin_id = 0; *type = NULL; if (dflt) { @@ -2265,23 +2264,16 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t } /* try to find loaded user type plugins */ - r = _lyplg_type_plugin_find(ctx->ctx, tctx->tpdf->type.pmod->mod->name, tctx->tpdf->type.pmod->mod->revision, - tctx->tpdf->name, &plugin_id); - if (r == LY_SUCCESS) { - plugin_found = 1; - } else if ((r == LY_ENOTFOUND) && base) { - /* use the base type implementation if available */ + plugin_id = lyplg_type_plugin_find(ctx->ctx, tctx->tpdf->type.pmod->mod->name, tctx->tpdf->type.pmod->mod->revision, + tctx->tpdf->name); + if (!plugin_id && base) { plugin_id = base->plugin; - plugin_found = 1; } - if (!plugin_found) { + if (!plugin_id) { /* use the internal built-in type implementation */ - r = _lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype], &plugin_id); - if (r == LY_SUCCESS) { - plugin_found = 1; - } + plugin_id = lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype]); } - assert(plugin_found); + assert(plugin_id); if ((basetype != LY_TYPE_LEAFREF) && (u != tpdf_chain.count - 1) && !tctx->tpdf->type.flags && !tctx->tpdf->type.exts && (plugin_id == base->plugin)) { @@ -2339,7 +2331,7 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t if (base) { plugin_id = base->plugin; } else { - _lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype], &plugin_id); + plugin_id = lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype]); } ret = lys_compile_type_(ctx, context_pnode, context_flags, context_name, (struct lysp_type *)type_p, basetype, NULL, base, plugin_id, &tpdf_chain, 0, type); diff --git a/src/tree_data_common.c b/src/tree_data_common.c index 36dfed980..20309f6e8 100644 --- a/src/tree_data_common.c +++ b/src/tree_data_common.c @@ -531,7 +531,8 @@ lyd_value_store(const struct ly_ctx *ctx, struct lyd_value *val, const struct ly options |= LYPLG_TYPE_STORE_ONLY; } - r = lysc_get_type_plugin(type->plugin)->store(ctx, type, value, value_len, options, format, prefix_data, hints, ctx_node, val, NULL, &err); + r = lysc_get_type_plugin(type->plugin)->store(ctx, type, value, value_len, options, + format, prefix_data, hints, ctx_node, val, NULL, &err); if (dynamic) { *dynamic = 0; } @@ -559,17 +560,19 @@ lyd_value_validate_incomplete(const struct ly_ctx *ctx, const struct lysc_type * { LY_ERR ret; struct ly_err_item *err = NULL; + struct lyplg_type *type_plugin; - assert(lysc_get_type_plugin(type->plugin)->validate); + type_plugin = lysc_get_type_plugin(type->plugin); + assert(type_plugin && type_plugin->validate); - ret = lysc_get_type_plugin(type->plugin)->validate(ctx, type, ctx_node, tree, val, &err); + ret = type_plugin->validate(ctx, type, ctx_node, tree, val, &err); if (ret) { if (err) { ly_err_print_build_path(ctx, ctx_node, NULL, err); ly_err_free(err); } else { LOGVAL(ctx, LYVE_OTHER, "Resolving value \"%s\" failed.", - (char *)lysc_get_type_plugin(type->plugin)->print(ctx, val, LY_VALUE_CANON, NULL, NULL, NULL)); + (char *)type_plugin->print(ctx, val, LY_VALUE_CANON, NULL, NULL, NULL)); } return ret; } @@ -594,8 +597,8 @@ ly_value_validate(const struct ly_ctx *ctx, const struct lysc_node *node, const } type = ((struct lysc_node_leaf *)node)->type; - rc = lysc_get_type_plugin(type->plugin)->store(ctx ? ctx : node->module->ctx, type, value, value_len, 0, format, prefix_data, hints, node, - &storage, NULL, &err); + rc = lysc_get_type_plugin(type->plugin)->store(ctx ? ctx : node->module->ctx, type, value, + value_len, 0, format, prefix_data, hints, node, &storage, NULL, &err); if (rc == LY_EINCOMPLETE) { /* actually success */ rc = LY_SUCCESS; @@ -632,6 +635,7 @@ lyd_value_validate2(const struct ly_ctx *ctx, const struct lysc_node *schema, co struct lysc_type *type; struct lyd_value val = {0}; ly_bool stored = 0, log = 1; + struct lyplg_type *type_plugin, *realtype_plugin; if (!ctx) { ctx = schema->module->ctx; @@ -642,15 +646,18 @@ lyd_value_validate2(const struct ly_ctx *ctx, const struct lysc_node *schema, co } type = ((struct lysc_node_leaf *)schema)->type; + type_plugin = lysc_get_type_plugin(type->plugin); + /* store */ - rc = lysc_get_type_plugin(type->plugin)->store(ctx, type, value, value_len, 0, format, prefix_data, LYD_HINT_DATA, schema, &val, NULL, &err); + rc = type_plugin->store(ctx, type, value, value_len, 0, format, + prefix_data, LYD_HINT_DATA, schema, &val, NULL, &err); if (!rc || (rc == LY_EINCOMPLETE)) { stored = 1; } if (ctx_node && (rc == LY_EINCOMPLETE)) { /* resolve */ - rc = lysc_get_type_plugin(type->plugin)->validate(ctx, type, ctx_node, ctx_node, &val, &err); + rc = type_plugin->validate(ctx, type, ctx_node, ctx_node, &val, &err); } if (rc && (rc != LY_EINCOMPLETE) && err) { @@ -673,13 +680,14 @@ lyd_value_validate2(const struct ly_ctx *ctx, const struct lysc_node *schema, co if (canonical) { /* return canonical value */ - lydict_dup(ctx, lysc_get_type_plugin(val.realtype->plugin)->print(ctx, &val, LY_VALUE_CANON, NULL, NULL, NULL), canonical); + realtype_plugin = lysc_get_type_plugin(val.realtype->plugin); + lydict_dup(ctx, realtype_plugin->print(ctx, &val, LY_VALUE_CANON, NULL, NULL, NULL), canonical); } } if (stored) { /* free value */ - lysc_get_type_plugin(type->plugin)->free(ctx, &val); + type_plugin->free(ctx, &val); } return rc; } diff --git a/src/tree_data_hash.c b/src/tree_data_hash.c index 66ba634e4..32a6b2d3d 100644 --- a/src/tree_data_hash.c +++ b/src/tree_data_hash.c @@ -33,6 +33,7 @@ lyd_hash(struct lyd_node *node) const void *hash_key; ly_bool dyn; size_t key_len; + struct lyplg_type *type; if (!node->schema) { return LY_SUCCESS; @@ -55,7 +56,8 @@ lyd_hash(struct lyd_node *node) for (iter = list->child; iter && iter->schema && (iter->schema->flags & LYS_KEY); iter = iter->next) { struct lyd_node_term *key = (struct lyd_node_term *)iter; - hash_key = lysc_get_type_plugin(key->value.realtype->plugin)->print(NULL, &key->value, LY_VALUE_LYB, NULL, &dyn, &key_len); + type = lysc_get_type_plugin(key->value.realtype->plugin); + hash_key = type->print(NULL, &key->value, LY_VALUE_LYB, NULL, &dyn, &key_len); node->hash = lyht_hash_multi(node->hash, hash_key, key_len); if (dyn) { free((void *)hash_key); @@ -66,7 +68,8 @@ lyd_hash(struct lyd_node *node) /* leaf-list adds its hash key */ struct lyd_node_term *llist = (struct lyd_node_term *)node; - hash_key = lysc_get_type_plugin(llist->value.realtype->plugin)->print(NULL, &llist->value, LY_VALUE_LYB, NULL, &dyn, &key_len); + type = lysc_get_type_plugin(llist->value.realtype->plugin); + hash_key = type->print(NULL, &llist->value, LY_VALUE_LYB, NULL, &dyn, &key_len); node->hash = lyht_hash_multi(node->hash, hash_key, key_len); if (dyn) { free((void *)hash_key); diff --git a/src/tree_data_new.c b/src/tree_data_new.c index a440c7088..584648ab6 100644 --- a/src/tree_data_new.c +++ b/src/tree_data_new.c @@ -1218,6 +1218,10 @@ lyd_change_node_value(struct lyd_node_term *term, struct lyd_value *val, ly_bool { LY_ERR rc = LY_SUCCESS; struct lyd_node *target, *first; + struct lyplg_type *real_type, *schema_type; + + real_type = lysc_get_type_plugin(term->value.realtype->plugin); + schema_type = lysc_get_type_plugin(((struct lysc_node_leaf *)term->schema)->type->plugin); if (term->schema->nodetype == LYS_LEAFLIST) { target = (struct lyd_node *)term; @@ -1225,11 +1229,11 @@ lyd_change_node_value(struct lyd_node_term *term, struct lyd_value *val, ly_bool target = (struct lyd_node *)term->parent; } else { /* just change the value */ - lysc_get_type_plugin(term->value.realtype->plugin)->free(LYD_CTX(term), &term->value); + real_type->free(LYD_CTX(term), &term->value); if (use_val) { term->value = *val; } else { - rc = lysc_get_type_plugin(((struct lysc_node_leaf *)term->schema)->type->plugin)->duplicate(LYD_CTX(term), val, &term->value); + rc = schema_type->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 */ @@ -1245,11 +1249,11 @@ lyd_change_node_value(struct lyd_node_term *term, struct lyd_value *val, ly_bool lyd_unlink_tree(target); /* change value */ - lysc_get_type_plugin(term->value.realtype->plugin)->free(LYD_CTX(term), &term->value); + real_type->free(LYD_CTX(term), &term->value); if (use_val) { term->value = *val; } else { - rc = lysc_get_type_plugin(((struct lysc_node_leaf *)term->schema)->type->plugin)->duplicate(LYD_CTX(term), val, &term->value); + rc = schema_type->duplicate(LYD_CTX(term), val, &term->value); } /* reinserting */ @@ -1259,11 +1263,11 @@ lyd_change_node_value(struct lyd_node_term *term, struct lyd_value *val, ly_bool lyd_unlink_hash(target); /* change value */ - lysc_get_type_plugin(term->value.realtype->plugin)->free(LYD_CTX(term), &term->value); + real_type->free(LYD_CTX(term), &term->value); if (use_val) { term->value = *val; } else { - rc = lysc_get_type_plugin(((struct lysc_node_leaf *)term->schema)->type->plugin)->duplicate(LYD_CTX(term), val, &term->value); + rc = schema_type->duplicate(LYD_CTX(term), val, &term->value); } } diff --git a/src/tree_schema.h b/src/tree_schema.h index 5ff141a34..c9b02062d 100644 --- a/src/tree_schema.h +++ b/src/tree_schema.h @@ -1279,7 +1279,7 @@ struct lysc_must { struct lysc_type { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin use lysc_get_type_plugin*/ + uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing, it may be accessed concurrently when creating/freeing data node values that reference it (instance-identifier) */ @@ -1288,7 +1288,7 @@ struct lysc_type { struct lysc_type_num { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1298,7 +1298,7 @@ struct lysc_type_num { struct lysc_type_dec { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1309,7 +1309,7 @@ struct lysc_type_dec { struct lysc_type_str { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1334,7 +1334,7 @@ struct lysc_type_bitenum_item { struct lysc_type_enum { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1344,7 +1344,7 @@ struct lysc_type_enum { struct lysc_type_bits { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1355,7 +1355,7 @@ struct lysc_type_bits { struct lysc_type_leafref { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1368,7 +1368,7 @@ struct lysc_type_leafref { struct lysc_type_identityref { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1379,7 +1379,7 @@ struct lysc_type_identityref { struct lysc_type_instanceid { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1389,7 +1389,7 @@ struct lysc_type_instanceid { struct lysc_type_union { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1399,7 +1399,7 @@ struct lysc_type_union { struct lysc_type_bin { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin */ + uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1798,11 +1798,11 @@ struct lysc_module { ((lysc_node->nodetype == LYS_LEAFLIST) && !(lysc_node->flags & LYS_CONFIG_W)))) ? 1 : 0) /** - * @brief + * @brief Get a type plugin. * - * @param[in] plugin_id The plugin identifier - * - * @return { description_of_the_return_value } + * @param[in] plugin_id Either an index in the type plugins array (e.g. 1 -> binary type) + * or a pointer to the user defined plugin. Indexes start at 1. + * @return Type plugin or NULL. */ LIBYANG_API_DECL struct lyplg_type *lysc_get_type_plugin(uintptr_t plugin_id); diff --git a/src/validation.c b/src/validation.c index 3ed11b1f8..1252059c2 100644 --- a/src/validation.c +++ b/src/validation.c @@ -1911,7 +1911,8 @@ lyd_validate_subtree(struct lyd_node *root, struct ly_set *node_when, struct ly_ } } - if ((node->schema->nodetype & LYD_NODE_TERM) && lysc_get_type_plugin(((struct lysc_node_leaf *)node->schema)->type->plugin)->validate) { + if ((node->schema->nodetype & LYD_NODE_TERM) && + lysc_get_type_plugin(((struct lysc_node_leaf *)node->schema)->type->plugin)->validate) { /* node type resolution */ r = ly_set_add(node_types, (void *)node, 1, NULL); LY_CHECK_ERR_GOTO(r, rc = r, cleanup); diff --git a/src/xpath.c b/src/xpath.c index ad65540fd..ed5a68f7c 100644 --- a/src/xpath.c +++ b/src/xpath.c @@ -3619,6 +3619,7 @@ warn_equality_value(const struct lyxp_expr *exp, struct lyxp_set *set, uint32_t struct lyd_value storage; LY_ERR rc; struct ly_err_item *err = NULL; + struct lyplg_type *type_plugin; if ((scnode = warn_get_scnode_in_ctx(set)) && (scnode->nodetype & (LYS_LEAF | LYS_LEAFLIST)) && ((exp->tokens[val_exp] == LYXP_TOKEN_LITERAL) || (exp->tokens[val_exp] == LYXP_TOKEN_NUMBER))) { @@ -3643,7 +3644,8 @@ warn_equality_value(const struct lyxp_expr *exp, struct lyxp_set *set, uint32_t type = ((struct lysc_node_leaf *)scnode)->type; if (type->basetype != LY_TYPE_IDENT) { - rc = lysc_get_type_plugin(type->plugin)->store(set->ctx, type, value, strlen(value), 0, set->format, set->prefix_data, + type_plugin = lysc_get_type_plugin(type->plugin); + rc = type_plugin->store(set->ctx, type, value, strlen(value), 0, set->format, set->prefix_data, LYD_HINT_DATA, scnode, &storage, NULL, &err); if (rc == LY_EINCOMPLETE) { rc = LY_SUCCESS; @@ -3660,7 +3662,7 @@ warn_equality_value(const struct lyxp_expr *exp, struct lyxp_set *set, uint32_t (exp->tok_pos[last_equal_exp] - exp->tok_pos[equal_exp]) + exp->tok_len[last_equal_exp], set->cur_scnode); } else { - lysc_get_type_plugin(type->plugin)->free(set->ctx, &storage); + type_plugin->free(set->ctx, &storage); } } free(value); diff --git a/tests/utests/basic/test_plugins.c b/tests/utests/basic/test_plugins.c index b957b52f1..54c85f1c2 100644 --- a/tests/utests/basic/test_plugins.c +++ b/tests/utests/basic/test_plugins.c @@ -54,12 +54,12 @@ test_add_simple(void **state) leaf = (struct lysc_node_leaf *)mod->compiled->data; assert_int_equal(LYS_LEAF, leaf->nodetype); - assert_non_null(plugin_t = lyplg_type_plugin_find(NULL, "libyang-plugins-simple", NULL, "note")); + assert_non_null(plugin_t = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "libyang-plugins-simple", NULL, "note"))); assert_string_equal("ly2 simple test v1", plugin_t->id); assert_ptr_equal(leaf->type->plugin, plugin_t); assert_int_equal(1, LY_ARRAY_COUNT(leaf->exts)); - assert_non_null(plugin_e = lyplg_ext_plugin_find(NULL, "libyang-plugins-simple", NULL, "hint")); + assert_non_null(plugin_e = lysc_get_ext_plugin(lyplg_ext_plugin_find(NULL, "libyang-plugins-simple", NULL, "hint"))); assert_string_equal("ly2 simple test v1", plugin_e->id); assert_ptr_equal(leaf->exts[0].def->plugin, plugin_e); diff --git a/tests/utests/types/binary.c b/tests/utests/types/binary.c index 0fc2db3bf..484ac4102 100644 --- a/tests/utests/types/binary.c +++ b/tests/utests/types/binary.c @@ -51,7 +51,7 @@ test_plugin_store(void **state) struct ly_err_item *err = NULL; struct lys_module *mod; struct lyd_value value = {0}; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BINARY]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BINARY])); struct lysc_type *lysc_type, *lysc_type2; LY_ERR ly_ret; const char *schema; @@ -250,7 +250,7 @@ test_plugin_print(void **state) struct lyd_value value = {0}; struct lys_module *mod; struct lysc_type *lysc_type; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BINARY]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BINARY])); struct ly_err_item *err = NULL; /* create schema. Prepare common used variables */ @@ -273,7 +273,7 @@ test_plugin_duplicate(void **state) struct lyd_value value = {0}, dup; struct lys_module *mod; struct lysc_type *lysc_type; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BINARY]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BINARY])); struct ly_err_item *err = NULL; /* create schema. Prepare common used variables */ @@ -298,7 +298,7 @@ test_plugin_sort(void **state) const char *schema; struct lys_module *mod; struct lyd_value val1 = {0}, val2 = {0}; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BINARY]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BINARY])); struct lysc_type *lysc_type; struct ly_err_item *err = NULL; diff --git a/tests/utests/types/bits.c b/tests/utests/types/bits.c index e22a7f1a8..94595ee06 100644 --- a/tests/utests/types/bits.c +++ b/tests/utests/types/bits.c @@ -800,7 +800,7 @@ test_plugin_store(void **state) struct ly_err_item *err = NULL; struct lys_module *mod; struct lyd_value value = {0}; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BITS]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BITS])); struct lysc_type *lysc_type; struct lysc_type lysc_type_test; LY_ERR ly_ret; @@ -894,7 +894,7 @@ test_plugin_compare(void **state) struct ly_err_item *err = NULL; struct lys_module *mod; struct lyd_value values[10]; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BITS]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BITS])); struct lysc_type *lysc_type; LY_ERR ly_ret; const char *schema; @@ -956,7 +956,7 @@ test_plugin_sort(void **state) { const char *schema; struct lys_module *mod; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BITS]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BITS])); struct lysc_type *lysc_type; struct ly_err_item *err = NULL; struct lyd_value val1 = {0}, val2 = {0}; @@ -993,7 +993,7 @@ test_plugin_print(void **state) struct ly_err_item *err = NULL; struct lys_module *mod; struct lyd_value values[10]; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BITS]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BITS])); struct lysc_type *lysc_type; LY_ERR ly_ret; const char *schema; @@ -1035,7 +1035,7 @@ test_plugin_dup(void **state) struct ly_err_item *err = NULL; struct lys_module *mod; struct lyd_value values[10]; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BITS]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BITS])); struct lysc_type *lysc_type; const char *schema; LY_ERR ly_ret; diff --git a/tests/utests/types/enumeration.c b/tests/utests/types/enumeration.c index 8ff1c8ca9..ba23765cd 100644 --- a/tests/utests/types/enumeration.c +++ b/tests/utests/types/enumeration.c @@ -94,7 +94,7 @@ test_plugin_sort(void **state) const char *schema; struct lys_module *mod; struct lyd_value val1 = {0}, val2 = {0}; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_ENUM]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_ENUM])); struct lysc_type *lysc_type; struct ly_err_item *err = NULL; diff --git a/tests/utests/types/inet_types.c b/tests/utests/types/inet_types.c index 402cadea1..a97768226 100644 --- a/tests/utests/types/inet_types.c +++ b/tests/utests/types/inet_types.c @@ -196,7 +196,7 @@ test_plugin_sort(void **state) const char *schema; struct lys_module *mod; struct lyd_value val1 = {0}, val2 = {0}; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_UNION]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_UNION])); struct lysc_type *lysc_type; struct ly_err_item *err = NULL; @@ -238,7 +238,7 @@ test_plugin_sort(void **state) /* ipv6-address */ lysc_type = ((struct lysc_node_leaflist *)mod->compiled->data->next)->type; - type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_STRING]); + type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_STRING])); v1 = "2008:15:0:0:0:0:feAC:1"; assert_int_equal(LY_SUCCESS, type->store(UTEST_LYCTX, lysc_type, v1, strlen(v1), @@ -266,7 +266,7 @@ test_plugin_sort(void **state) /* ipv4-address-no-zone */ lysc_type = ((struct lysc_node_leaflist *)mod->compiled->data->next->next)->type; - type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_UNION]); + type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_UNION])); v1 = "127.0.0.1"; assert_int_equal(LY_SUCCESS, type->store(UTEST_LYCTX, lysc_type, v1, strlen(v1), 0, LY_VALUE_JSON, NULL, LYD_VALHINT_STRING, NULL, &val1, NULL, &err)); @@ -281,7 +281,7 @@ test_plugin_sort(void **state) /* ipv6-address-no-zone */ lysc_type = ((struct lysc_node_leaflist *)mod->compiled->data->next->next->next)->type; - type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_STRING]); + type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_STRING])); v1 = "A:B:c:D:e:f:1:1"; assert_int_equal(LY_SUCCESS, type->store(UTEST_LYCTX, lysc_type, v1, strlen(v1), 0, LY_VALUE_JSON, NULL, LYD_VALHINT_STRING, NULL, &val1, NULL, &err)); diff --git a/tests/utests/types/int8.c b/tests/utests/types/int8.c index 7125e9beb..8c5ce6bc1 100644 --- a/tests/utests/types/int8.c +++ b/tests/utests/types/int8.c @@ -1399,7 +1399,7 @@ test_plugin_store(void **state) struct ly_err_item *err = NULL; struct lys_module *mod; struct lyd_value value = {0}; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_INT8]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_INT8])); struct lysc_type *lysc_type; LY_ERR ly_ret; char *alloc; @@ -1546,7 +1546,7 @@ test_plugin_compare(void **state) struct ly_err_item *err = NULL; struct lys_module *mod; struct lyd_value values[10]; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_INT8]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_INT8])); struct lysc_type *lysc_type; LY_ERR ly_ret; const char *schema; @@ -1631,7 +1631,7 @@ test_plugin_print(void **state) struct ly_err_item *err = NULL; struct lys_module *mod; struct lyd_value values[10]; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_INT8]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_INT8])); struct lysc_type *lysc_type; LY_ERR ly_ret; const char *schema; @@ -1671,7 +1671,7 @@ test_plugin_dup(void **state) struct ly_err_item *err = NULL; struct lys_module *mod; struct lyd_value values[10]; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_INT8]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_INT8])); struct lysc_type *lysc_type[2]; const char *schema; LY_ERR ly_ret; diff --git a/tests/utests/types/leafref.c b/tests/utests/types/leafref.c index 002763ca1..8411eb2cc 100644 --- a/tests/utests/types/leafref.c +++ b/tests/utests/types/leafref.c @@ -216,7 +216,7 @@ test_plugin_sort(void **state) const char *schema; struct lys_module *mod; struct lyd_value val1 = {0}, val2 = {0}; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_LEAFREF]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_LEAFREF])); struct lysc_type *lysc_type; struct ly_err_item *err = NULL; diff --git a/tests/utests/types/string.c b/tests/utests/types/string.c index 94bc8ea42..c07f372f5 100644 --- a/tests/utests/types/string.c +++ b/tests/utests/types/string.c @@ -1060,7 +1060,7 @@ test_plugin_store(void **state) struct ly_err_item *err = NULL; struct lys_module *mod; struct lyd_value value = {0}; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_STRING]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_STRING])); struct lysc_type *lysc_type; char *alloc_text; unsigned int alloc_text_size; @@ -1201,7 +1201,7 @@ test_plugin_compare(void **state) struct ly_err_item *err = NULL; struct lys_module *mod; struct lyd_value values[10]; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_STRING]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_STRING])); struct lysc_type *lysc_type; LY_ERR ly_ret; const char *schema; @@ -1259,7 +1259,7 @@ test_plugin_print(void **state) struct ly_err_item *err = NULL; struct lys_module *mod; struct lyd_value values[10]; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_STRING]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_STRING])); struct lysc_type *lysc_type; LY_ERR ly_ret; @@ -1298,7 +1298,7 @@ test_plugin_dup(void **state) struct ly_err_item *err = NULL; struct lys_module *mod; struct lyd_value values[10]; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_STRING]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_STRING])); struct lysc_type *lysc_type[2]; const char *schema; LY_ERR ly_ret; diff --git a/tests/utests/types/union.c b/tests/utests/types/union.c index 573abc7bf..6131c1581 100644 --- a/tests/utests/types/union.c +++ b/tests/utests/types/union.c @@ -154,7 +154,7 @@ test_plugin_sort(void **state) const char *schema; struct lys_module *mod; struct lyd_value val1 = {0}, val2 = {0}; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_UNION]); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_UNION])); struct lysc_type *lysc_type; struct ly_err_item *err = NULL; diff --git a/tests/utests/types/yang_types.c b/tests/utests/types/yang_types.c index 07c5e162b..c5cf8d7c9 100644 --- a/tests/utests/types/yang_types.c +++ b/tests/utests/types/yang_types.c @@ -234,7 +234,7 @@ test_sort(void **state) const char *schema; struct lys_module *mod; struct lyd_value val1 = {0}, val2 = {0}; - struct lyplg_type *type = lyplg_type_plugin_find(NULL, "ietf-yang-types", "2013-07-15", "date-and-time"); + struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "ietf-yang-types", "2013-07-15", "date-and-time")); struct lysc_type *lysc_type; struct ly_err_item *err = NULL; diff --git a/tests/utests/utests.h b/tests/utests/utests.h index 50b79abc5..4bba32d70 100644 --- a/tests/utests/utests.h +++ b/tests/utests/utests.h @@ -229,11 +229,7 @@ struct utest_context { assert_non_null(NODE); \ assert_int_equal((NODE)->basetype, TYPE); \ CHECK_ARRAY((NODE)->exts, EXTS); \ - do { \ - uintptr_t plugin_id; \ - _lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[TYPE], &plugin_id); \ - assert_ptr_equal((NODE)->plugin, plugin_id); \ - } while (0) + assert_ptr_equal((NODE)->plugin, lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[TYPE])) /** * @brief check compileted numeric type From dd4f6bcf85d2d9d459891aea619aa973b56c1b92 Mon Sep 17 00:00:00 2001 From: roman Date: Mon, 20 Jan 2025 11:14:17 +0100 Subject: [PATCH 07/25] plugins exts UPDATE simplify ext plugin getter --- src/log.c | 9 ++++---- src/plugins.c | 42 +++++++++++++++++++------------------- src/plugins_exts.h | 2 +- src/plugins_exts/nacm.c | 6 +++++- src/plugins_internal.h | 5 +++-- src/printer_context.c | 10 +++++---- src/printer_tree.c | 12 +++++------ src/printer_yang.c | 6 ++++-- src/schema_compile.c | 4 ++-- src/schema_compile_amend.c | 4 ++-- src/tree_data.c | 2 +- src/tree_data_common.c | 2 +- src/tree_schema.c | 7 ++++--- src/tree_schema.h | 13 ++++++++++-- src/tree_schema_free.c | 8 ++++---- src/validation.c | 9 ++++---- 16 files changed, 81 insertions(+), 60 deletions(-) diff --git a/src/log.c b/src/log.c index ae76a583e..5fc558764 100644 --- a/src/log.c +++ b/src/log.c @@ -885,7 +885,7 @@ lyplg_ext_parse_log(const struct lysp_ctx *pctx, const struct lysp_ext_instance ly_vlog_build_path_line(PARSER_CTX(pctx), &data_path, &schema_path, &line); va_start(ap, format); - ly_ext_log(PARSER_CTX(pctx), ext->plugin->id, level, err, data_path, schema_path, line, format, ap); + ly_ext_log(PARSER_CTX(pctx), lysc_get_ext_plugin(ext->plugin)->id, level, err, data_path, schema_path, line, format, ap); va_end(ap); } @@ -902,7 +902,7 @@ lyplg_ext_compile_log(const struct lysc_ctx *cctx, const struct lysc_ext_instanc } va_start(ap, format); - ly_ext_log(ext->module->ctx, ext->def->plugin->id, level, err, NULL, schema_path, 0, format, ap); + ly_ext_log(ext->module->ctx, lysc_get_ext_plugin(ext->def->plugin)->id, level, err, NULL, schema_path, 0, format, ap); va_end(ap); } @@ -919,7 +919,7 @@ lyplg_ext_compile_log_path(const char *path, const struct lysc_ext_instance *ext } va_start(ap, format); - ly_ext_log(ext->module->ctx, ext->def->plugin->id, level, err, NULL, schema_path, 0, format, ap); + ly_ext_log(ext->module->ctx, lysc_get_ext_plugin(ext->def->plugin)->id, level, err, NULL, schema_path, 0, format, ap); va_end(ap); } @@ -940,7 +940,8 @@ _lyplg_ext_compile_log_err(const struct ly_err_item *eitem, const struct lysc_ex } va_start(ap, ext); - ly_ext_log(ext->module->ctx, ext->def->plugin->id, eitem->level, eitem->err, data_path, schema_path, eitem->line, "%s", ap); + ly_ext_log(ext->module->ctx, lysc_get_ext_plugin(ext->def->plugin)->id, eitem->level, eitem->err, + data_path, schema_path, eitem->line, "%s", ap); va_end(ap); } diff --git a/src/plugins.c b/src/plugins.c index b84199901..e9920081b 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -167,6 +167,12 @@ lysc_get_type_plugin(uintptr_t plugin_id) return lysc_get_plugin(plugin_id, LYPLG_TYPE, &plugins_types); } +LIBYANG_API_DEF struct lyplg_ext * +lysc_get_ext_plugin(uintptr_t plugin_id) +{ + return lysc_get_plugin(plugin_id, LYPLG_EXTENSION, &plugins_extensions); +} + /** * @brief Iterate over list of loaded plugins of the given @p type. * @@ -255,40 +261,34 @@ lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char } } -struct lyplg_type * -lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name) +uintptr_t +lyplg_ext_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name) { - struct lyplg_type_record *record = NULL; + struct lyplg_ext_record *record = NULL; + uint32_t record_idx = 0; if (ctx) { /* try to find context specific plugin */ - record = lyplg_record_find(ctx, LYPLG_TYPE, module, revision, name, NULL); + record = lyplg_record_find(ctx, LYPLG_EXTENSION, module, revision, name, &record_idx); } if (!record) { /* try to find shared plugin */ - record = lyplg_record_find(NULL, LYPLG_TYPE, module, revision, name, NULL); - } - - return record ? &record->plugin : NULL; -} - -struct lyplg_ext * -lyplg_ext_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name) -{ - struct lyplg_ext_record *record = NULL; - - if (ctx) { - /* try to find context specific plugin */ - record = lyplg_record_find(ctx, LYPLG_EXTENSION, module, revision, name, NULL); + record = lyplg_record_find(NULL, LYPLG_EXTENSION, module, revision, name, &record_idx); } if (!record) { - /* try to find shared plugin */ - record = lyplg_record_find(NULL, LYPLG_EXTENSION, module, revision, name, NULL); + /* not found */ + return 0; } - return record ? &record->plugin : NULL; + if (!strncmp(record->plugin.id, "ly2 - ", 6)) { + /* internal plugin, return an index with an offset of +1 in order to keep 0 as an invalid index (a NULL ptr) */ + return record_idx + 1; + } else { + /* external plugin, return the pointer */ + return (uintptr_t)&record->plugin; + } } /** diff --git a/src/plugins_exts.h b/src/plugins_exts.h index 477834be7..71fdee7a2 100644 --- a/src/plugins_exts.h +++ b/src/plugins_exts.h @@ -405,7 +405,7 @@ struct lysp_ext_instance { const char *argument; /**< optional value of the extension's argument */ LY_VALUE_FORMAT format; /**< prefix format of the extension name/argument (::LY_VALUE_XML is YIN format) */ void *prefix_data; /**< format-specific data for prefix resolution (see ly_resolve_prefix()) */ - struct lyplg_ext *plugin; /**< pointer to the extension plugin, if any */ + uintptr_t plugin; /**< extension plugin, use ::lysc_get_ext_plugin() */ void *parent; /**< pointer to the parent statement holding the extension instance(s), use ::lysp_ext_instance#parent_stmt to access the value/structure */ diff --git a/src/plugins_exts/nacm.c b/src/plugins_exts/nacm.c index 8bd77a6ce..adda9d28a 100644 --- a/src/plugins_exts/nacm.c +++ b/src/plugins_exts/nacm.c @@ -81,6 +81,7 @@ nacm_parse(struct lysp_ctx *pctx, struct lysp_ext_instance *ext) { struct lysp_node *parent = NULL; LY_ARRAY_COUNT_TYPE u; + struct lyplg_ext *ext_plugin, *parent_ext_plugin; /* check that the extension is instantiated at an allowed place - data node */ if (!(ext->parent_stmt & LY_STMT_NODE_MASK)) { @@ -100,9 +101,12 @@ nacm_parse(struct lysp_ctx *pctx, struct lysp_ext_instance *ext) return LY_ENOT; } + ext_plugin = lysc_get_ext_plugin(ext->plugin); + /* check for duplication */ LY_ARRAY_FOR(parent->exts, u) { - if ((&parent->exts[u] != ext) && parent->exts[u].plugin && !strcmp(parent->exts[u].plugin->id, ext->plugin->id)) { + parent_ext_plugin = lysc_get_ext_plugin(parent->exts[u].plugin); + if ((&parent->exts[u] != ext) && parent_ext_plugin && !strcmp(parent_ext_plugin->id, ext_plugin->id)) { /* duplication of a NACM extension on a single node * We check for all NACM plugins since we want to catch even the situation that there is default-deny-all * AND default-deny-write */ diff --git a/src/plugins_internal.h b/src/plugins_internal.h index 983a08027..0526bdef5 100644 --- a/src/plugins_internal.h +++ b/src/plugins_internal.h @@ -83,8 +83,9 @@ uintptr_t lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, c * @param[in] revision Revision of the module for which the plugin is implemented. NULL is not a wildcard, it matches * only the plugins with NULL revision specified. * @param[in] name Name of the extension which the plugin implements. - * @return Found extension plugin, NULL if none found. + * @return ID of the found extension plugin, 0 if none found. The extension plugin can be obtained + * by passing the returned ID to ::lysc_get_ext_plugin(). */ -struct lyplg_ext *lyplg_ext_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name); +uintptr_t lyplg_ext_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name); #endif /* LY_PLUGINS_INTERNAL_H_ */ diff --git a/src/printer_context.c b/src/printer_context.c index 0f56dcb2c..6ff911d80 100644 --- a/src/printer_context.c +++ b/src/printer_context.c @@ -112,6 +112,7 @@ static void ctxs_exts(const struct lysc_ext_instance *exts, struct ly_ht *ht, int *size) { LY_ARRAY_COUNT_TYPE u; + struct lyplg_ext *ext; /* sized array */ *size += CTXS_SIZED_ARRAY(exts); @@ -123,8 +124,9 @@ ctxs_exts(const struct lysc_ext_instance *exts, struct ly_ht *ht, int *size) *size += sizeof(LY_ARRAY_COUNT_TYPE) + LY_ARRAY_COUNT(exts[u].substmts) * sizeof *exts[u].substmts; /* compiled, substmts storage */ - if (exts[u].def->plugin && exts[u].def->plugin->compiled_size) { - *size += exts[u].def->plugin->compiled_size(&exts[u], ht); + ext = lysc_get_ext_plugin(exts[u].def->plugin); + if (ext && ext->compiled_size) { + *size += ext->compiled_size(&exts[u], ht); } } } @@ -814,8 +816,8 @@ ctxp_ext(const struct lysc_ext_instance *orig_ext, struct lysc_ext_instance *ext } /* compiled, substmts storage, use the plugin */ - if (ext->def->plugin && ext->def->plugin->compiled_print) { - ext->def->plugin->compiled_print(orig_ext, ext, addr_ht, ptr_set, mem); + if (ext->def->plugin && lysc_get_ext_plugin(ext->def->plugin)->compiled_print) { + lysc_get_ext_plugin(ext->def->plugin)->compiled_print(orig_ext, ext, addr_ht, ptr_set, mem); } else { ext->compiled = NULL; } diff --git a/src/printer_tree.c b/src/printer_tree.c index dfb52c9da..d177373cd 100644 --- a/src/printer_tree.c +++ b/src/printer_tree.c @@ -1861,7 +1861,7 @@ trp_ext_is_present(ly_bool lysc_tree, const void *node) if (lysc_tree) { cn = (const struct lysc_node *)node; LY_ARRAY_FOR(cn->exts, i) { - if (!cn->exts[i].def->plugin || !cn->exts[i].def->plugin->printer_ctree) { + if (!cn->exts[i].def->plugin || !lysc_get_ext_plugin(cn->exts[i].def->plugin)->printer_ctree) { continue; } if (!trp_ext_parent_is_valid(1, &cn->exts[i])) { @@ -1873,7 +1873,7 @@ trp_ext_is_present(ly_bool lysc_tree, const void *node) } else { pn = (const struct lysp_node *)node; LY_ARRAY_FOR(pn->exts, i) { - if (!pn->exts[i].plugin || !pn->exts[i].plugin->printer_ptree) { + if (!pn->exts[i].plugin || !lysc_get_ext_plugin(pn->exts[i].plugin)->printer_ptree) { continue; } if (!trp_ext_parent_is_valid(0, &pn->exts[i])) { @@ -2162,9 +2162,9 @@ tro_set_node_overr(ly_bool lysc_tree, const void *node, ly_bool erase_node_overr } no = &plc->node_overr; if (!plc->ctx && lysc_tree && (ce = trp_ext_is_present(lysc_tree, node))) { - rc = ce->def->plugin->printer_ctree(ce, NULL, &no->flags, &no->add_opts); + rc = lysc_get_ext_plugin(ce->def->plugin)->printer_ctree(ce, NULL, &no->flags, &no->add_opts); } else if (!plc->ctx && (pe = trp_ext_is_present(lysc_tree, node))) { - rc = pe->plugin->printer_ptree(pe, NULL, &no->flags, &no->add_opts); + rc = lysc_get_ext_plugin(pe->plugin)->printer_ptree(pe, NULL, &no->flags, &no->add_opts); } else if (plc->ctx) { if (plc->schema && plc->schema->compiled && plc->schema->cn_overr) { rc = plc->schema->cn_overr(node, plc->ctx->plugin_priv, &plc->filtered, &no->flags, &no->add_opts); @@ -3873,7 +3873,7 @@ tro_ext_printer_tree(ly_bool compiled, void *ext, const struct lyspr_tree_ctx *p if (compiled) { ext_comp = ext; - plugin = ext_comp->def->plugin; + plugin = lysc_get_ext_plugin(ext_comp->def->plugin); if (!plugin->printer_ctree) { *ignore = 1; return LY_SUCCESS; @@ -3881,7 +3881,7 @@ tro_ext_printer_tree(ly_bool compiled, void *ext, const struct lyspr_tree_ctx *p return plugin->printer_ctree(ext, plug_ctx, &flags, &add_opts); } else { ext_pars = ext; - plugin = ext_pars->plugin; + plugin = lysc_get_ext_plugin(ext_pars->plugin); if (!plugin->printer_ptree) { *ignore = 1; return LY_SUCCESS; diff --git a/src/printer_yang.c b/src/printer_yang.c index ae75c6ff3..8fcc3d482 100644 --- a/src/printer_yang.c +++ b/src/printer_yang.c @@ -356,6 +356,7 @@ yprc_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t { LY_ARRAY_COUNT_TYPE u; ly_bool inner_flag; + struct lyplg_ext *ext; LY_ARRAY_FOR(exts, u) { if ((exts[u].parent_stmt != substmt) || (exts[u].parent_stmt_index != substmt_index)) { @@ -375,8 +376,9 @@ yprc_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t inner_flag = 0; yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0, exts[u].exts, &inner_flag); - if (exts[u].def->plugin && exts[u].def->plugin->printer_info) { - exts[u].def->plugin->printer_info(&pctx->printer_ctx, &exts[u], &inner_flag); + ext = lysc_get_ext_plugin(exts[u].def->plugin); + if (ext && ext->printer_info) { + ext->printer_info(&pctx->printer_ctx, &exts[u], &inner_flag); } LEVEL--; diff --git a/src/schema_compile.c b/src/schema_compile.c index 3e43344d4..70d7ee236 100644 --- a/src/schema_compile.c +++ b/src/schema_compile.c @@ -132,11 +132,11 @@ lys_compile_ext(struct lysc_ctx *ctx, struct lysp_ext_instance *extp, struct lys COMPILE_EXTS_GOTO(ctx, extp->exts, ext->exts, ext, ret, cleanup); /* compile this extension */ - if (ext->def->plugin && ext->def->plugin->compile) { + if (ext->def->plugin && lysc_get_ext_plugin(ext->def->plugin)->compile) { if (ext->argument) { lysc_update_path(ctx, ext->module, ext->argument); } - ret = ext->def->plugin->compile(ctx, extp, ext); + ret = lysc_get_ext_plugin(ext->def->plugin)->compile(ctx, extp, ext); if (ret == LY_ENOT) { lysc_ext_instance_free(ctx->ctx, ext); } diff --git a/src/schema_compile_amend.c b/src/schema_compile_amend.c index 62ebab1b1..81257ea3c 100644 --- a/src/schema_compile_amend.c +++ b/src/schema_compile_amend.c @@ -485,10 +485,10 @@ lysp_ext_dup(const struct ly_ctx *ctx, const struct lysp_module *pmod, void *par ext->flags = orig_ext->flags; LY_CHECK_GOTO(ret = lysp_ext_children_dup(ctx, orig_ext->child, &ext->child), cleanup); - if (ext->plugin && ext->plugin->parse) { + if (ext->plugin && lysc_get_ext_plugin(ext->plugin)->parse) { /* parse again */ LY_CHECK_GOTO(ret = ly_set_add(&pmods, pmod, 1, NULL), cleanup); - LY_CHECK_GOTO(ret = ext->plugin->parse(&pctx, ext), cleanup); + LY_CHECK_GOTO(ret = lysc_get_ext_plugin(ext->plugin)->parse(&pctx, ext), cleanup); } cleanup: diff --git a/src/tree_data.c b/src/tree_data.c index 7cc5271f7..07daa6e10 100644 --- a/src/tree_data.c +++ b/src/tree_data.c @@ -1328,7 +1328,7 @@ lyd_get_meta_annotation(const struct lys_module *mod, const char *name, size_t n } LY_ARRAY_FOR(mod->compiled->exts, u) { - plugin = mod->compiled->exts[u].def->plugin; + plugin = lysc_get_ext_plugin(mod->compiled->exts[u].def->plugin); if (plugin && !strncmp(plugin->id, "ly2 - metadata", 12) && !ly_strncmp(mod->compiled->exts[u].argument, name, name_len)) { return &mod->compiled->exts[u]; diff --git a/src/tree_data_common.c b/src/tree_data_common.c index 20309f6e8..7f50c1c2d 100644 --- a/src/tree_data_common.c +++ b/src/tree_data_common.c @@ -1344,7 +1344,7 @@ ly_nested_ext_schema(const struct lyd_node *parent, const struct lysc_node *spar continue; } - ext_snode_cb = nested_exts[u].def->plugin->snode; + ext_snode_cb = lysc_get_ext_plugin(nested_exts[u].def->plugin)->snode; if (!ext_snode_cb) { /* not an extension with nested data */ continue; diff --git a/src/tree_schema.c b/src/tree_schema.c index abe86e204..5d2edccf5 100644 --- a/src/tree_schema.c +++ b/src/tree_schema.c @@ -1377,7 +1377,7 @@ lysp_resolve_ext_instance_records(struct lysp_ctx *pctx) u = 0; while (u < LY_ARRAY_COUNT(exts)) { ext = &exts[u]; - if (!ext->plugin || !ext->plugin->parse) { + if (!ext->plugin || !lysc_get_ext_plugin(ext->plugin)->parse) { goto next_iter; } @@ -1388,7 +1388,7 @@ lysp_resolve_ext_instance_records(struct lysp_ctx *pctx) ly_log_location(NULL, NULL, path, NULL); /* parse */ - r = ext->plugin->parse(pctx, ext); + r = lysc_get_ext_plugin(ext->plugin)->parse(pctx, ext); ly_log_location_revert(0, 0, 1, 0); free(path); @@ -1964,7 +1964,8 @@ lys_parse_in(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, /* resolve extension plugins and parse extension instances */ LY_ARRAY_FOR(mod->parsed->extensions, u) { - mod->parsed->extensions[u].plugin = lyplg_ext_plugin_find(mod->ctx, mod->name, mod->revision, mod->parsed->extensions[u].name); + mod->parsed->extensions[u].plugin = lyplg_ext_plugin_find(mod->ctx, mod->name, + mod->revision, mod->parsed->extensions[u].name); } LY_CHECK_GOTO(ret = lysp_resolve_ext_instance_records(pctx), cleanup); diff --git a/src/tree_schema.h b/src/tree_schema.h index c9b02062d..6bec597d6 100644 --- a/src/tree_schema.h +++ b/src/tree_schema.h @@ -299,7 +299,7 @@ struct lysp_ext { const char *dsc; /**< description statement */ const char *ref; /**< reference statement */ struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - struct lyplg_ext *plugin; /**< extension definition plugin, if any */ + uintptr_t plugin; /**< extension definition plugin, use ::lysc_get_ext_plugin() */ uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM_* values (@ref snodeflags) */ }; @@ -1183,7 +1183,7 @@ struct lysc_ext { const char *name; /**< extension name */ const char *argname; /**< argument name, NULL if not specified */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - struct lyplg_ext *plugin; /**< plugin implementing the specific extension, if any */ + uintptr_t plugin; /**< plugin implementing the specific extension, use ::lysc_get_ext_plugin() */ struct lys_module *module; /**< module structure */ uint16_t flags; /**< LYS_STATUS_* value (@ref snodeflags) */ }; @@ -1806,6 +1806,15 @@ struct lysc_module { */ LIBYANG_API_DECL struct lyplg_type *lysc_get_type_plugin(uintptr_t plugin_id); +/** + * @brief Get an extension plugin. + * + * @param[in] plugin_id Either an index in the extension plugins array (e.g. 1 -> metadata extension) + * or a pointer to the user defined plugin. Indexes start at 1. + * @return Extension plugin or NULL. + */ +LIBYANG_API_DECL struct lyplg_ext *lysc_get_ext_plugin(uintptr_t plugin_id); + /** * @brief Get nearest @p schema parent (including the node itself) that can be instantiated in data. * diff --git a/src/tree_schema_free.c b/src/tree_schema_free.c index 1fb36cdf2..c7188a23a 100644 --- a/src/tree_schema_free.c +++ b/src/tree_schema_free.c @@ -73,8 +73,8 @@ lysp_ext_instance_free(const struct ly_ctx *ctx, struct lysp_ext_instance *ext) lydict_remove(ctx, ext->name); lydict_remove(ctx, ext->argument); ly_free_prefix_data(ext->format, ext->prefix_data); - if (ext->plugin && ext->plugin->pfree) { - ext->plugin->pfree(ctx, ext); + if (ext->plugin && lysc_get_ext_plugin(ext->plugin)->pfree) { + lysc_get_ext_plugin(ext->plugin)->pfree(ctx, ext); } LY_LIST_FOR_SAFE(ext->child, next, stmt) { @@ -639,8 +639,8 @@ lysp_module_free(const struct ly_ctx *ctx, struct lysp_module *module) void lysc_ext_instance_free(const struct ly_ctx *ctx, struct lysc_ext_instance *ext) { - if (ext->def && ext->def->plugin && ext->def->plugin->cfree) { - ext->def->plugin->cfree(ctx, ext); + if (ext->def && ext->def->plugin && lysc_get_ext_plugin(ext->def->plugin)->cfree) { + lysc_get_ext_plugin(ext->def->plugin)->cfree(ctx, ext); } lydict_remove(ctx, ext->argument); FREE_ARRAY(ctx, ext->exts, lysc_ext_instance_free); diff --git a/src/validation.c b/src/validation.c index 1252059c2..297f908c9 100644 --- a/src/validation.c +++ b/src/validation.c @@ -453,7 +453,8 @@ lyd_validate_unres(struct lyd_node **tree, const struct lys_module *mod, enum ly struct lyd_ctx_ext_val *ext_v = ext_val->objs[i]; /* validate extension data */ - r = ext_v->ext->def->plugin->validate(ext_v->ext, ext_v->sibling, *tree, data_type, val_opts, diff); + r = lysc_get_ext_plugin(ext_v->ext->def->plugin)->validate(ext_v->ext, ext_v->sibling, *tree, + data_type, val_opts, diff); LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); /* remove this item from the set */ @@ -470,7 +471,7 @@ lyd_validate_unres(struct lyd_node **tree, const struct lys_module *mod, enum ly struct lyd_ctx_ext_node *ext_n = ext_node->objs[i]; /* validate the node */ - r = ext_n->ext->def->plugin->node(ext_n->ext, ext_n->node, val_opts); + r = lysc_get_ext_plugin(ext_n->ext->def->plugin)->node(ext_n->ext, ext_n->node, val_opts); LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); /* remove this item from the set */ @@ -1819,7 +1820,7 @@ lyd_validate_nested_ext(struct lyd_node *sibling, struct ly_set *ext_val) /* try to find the extension instance */ nested_exts = sibling->parent->schema->exts; LY_ARRAY_FOR(nested_exts, u) { - if (nested_exts[u].def->plugin->validate) { + if (lysc_get_ext_plugin(nested_exts[u].def->plugin)->validate) { if (ext) { /* more extension instances with validate callback */ LOGINT_RET(LYD_CTX(sibling)); @@ -1852,7 +1853,7 @@ lyd_validate_node_ext(struct lyd_node *node, struct ly_set *ext_node) /* try to find a relevant extension instance with node callback */ exts = node->schema->exts; LY_ARRAY_FOR(exts, u) { - if (exts[u].def->plugin && exts[u].def->plugin->node) { + if (exts[u].def->plugin && lysc_get_ext_plugin(exts[u].def->plugin)->node) { /* store for validation */ ext_n = malloc(sizeof *ext_n); LY_CHECK_ERR_RET(!ext_n, LOGMEM(LYD_CTX(node)), LY_EMEM); From 4268b7ffe104a4446f4e642ef1b4733b9a0fcca5 Mon Sep 17 00:00:00 2001 From: roman Date: Mon, 20 Jan 2025 15:07:20 +0100 Subject: [PATCH 08/25] context BUGFIX free plugins with printed ctx --- src/context.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/context.c b/src/context.c index 15b724538..b4c3cd18f 100644 --- a/src/context.c +++ b/src/context.c @@ -1484,6 +1484,7 @@ ly_ctx_destroy(struct ly_ctx *ctx) if (ctx->opts & LY_CTX_INT_IMMUTABLE) { /* ctx data */ ly_ctx_data_del(ctx); + lyplg_clean(); return; } From 73eddc6f7db9376056ed1ab6e3ef5430005ccc4a Mon Sep 17 00:00:00 2001 From: roman Date: Mon, 20 Jan 2025 15:14:45 +0100 Subject: [PATCH 09/25] test schema UPDATE finish compiled ctx print test --- tests/utests/schema/test_schema.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/tests/utests/schema/test_schema.c b/tests/utests/schema/test_schema.c index b7bcb779d..077d7ebd4 100644 --- a/tests/utests/schema/test_schema.c +++ b/tests/utests/schema/test_schema.c @@ -1893,10 +1893,14 @@ test_lysc_path(void **state) static void test_compiled_print(void **state) { - struct ly_ctx *pctx; - struct lyd_node *tree; int size, fd; - void *mem, *mem_end; + void *mem, *mem_end, *printed_ctx_mem; + struct lyd_node *tree = NULL; + struct ly_ctx *printed_ctx = NULL; + + /* recreate the context, get rid of all the plugins and use builtin/static only */ + ly_ctx_destroy(UTEST_LYCTX); + assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_BUILTIN_PLUGINS_ONLY | LY_CTX_STATIC_PLUGINS_ONLY, &UTEST_LYCTX)); /* load another module */ assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {yang-version 1.1; namespace urn:c;prefix c;" @@ -1937,20 +1941,27 @@ test_compiled_print(void **state) assert_int_equal(LY_SUCCESS, ly_ctx_compiled_print(UTEST_LYCTX, mem, &mem_end)); assert_int_equal((char *)mem_end - (char *)mem, size); - /* use the printed context */ - assert_int_equal(LY_SUCCESS, ly_ctx_new_printed(mem, &pctx)); + /* remap the region and parse the context from mem */ + munmap(mem, size); + + /* mmap the same address again */ + printed_ctx_mem = mmap(mem, size, PROT_READ, MAP_PRIVATE | MAP_FIXED_NOREPLACE, fd, 0); + assert_ptr_not_equal(printed_ctx_mem, MAP_FAILED); + + /* create a new printed ctx from this address */ + assert_int_equal(LY_SUCCESS, ly_ctx_new_printed(printed_ctx_mem, &printed_ctx)); - /* use it to parse some data */ - assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(pctx, + /* try to parse data with it */ + assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(printed_ctx, "/c:b" "true" "ahoi", LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree)); /* cleanup */ - lyd_free_siblings(tree); - ly_ctx_destroy(pctx); - munmap(mem, size); + lyd_free_all(tree); + ly_ctx_destroy(printed_ctx); + munmap(printed_ctx_mem, size); close(fd); shm_unlink("/ly_test_schema_ctx"); } From c22a49b7836a3a432362fd95d639b3b23d735804 Mon Sep 17 00:00:00 2001 From: roman Date: Mon, 20 Jan 2025 15:37:04 +0100 Subject: [PATCH 10/25] plugins REFACTOR add doxygen to static func --- src/plugins.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/plugins.c b/src/plugins.c index e9920081b..850c86c12 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -176,7 +176,7 @@ lysc_get_ext_plugin(uintptr_t plugin_id) /** * @brief Iterate over list of loaded plugins of the given @p type. * - * @param[in] ctx The context for which the plugin is searched for + * @param[in] ctx The context for which the plugin is searched for. * @param[in] type Type of the plugins to iterate. * @param[in,out] index The iterator - set to 0 for the first call. * @return The plugin records, NULL if no more record is available. @@ -202,6 +202,17 @@ plugins_iter(const struct ly_ctx *ctx, enum LYPLG type, uint32_t *index) return plugins->objs[*index - 1]; } +/** + * @brief Find the give @p type plugin record. + * + * @param[in] ctx The context for which the plugin record is searched for, NULL for built-in plugins. + * @param[in] type Type of the plugin record to find. + * @param[in] module Module name of the plugin record. + * @param[in] revision Revision of the @p module. + * @param[in] name Name of the plugin record. + * @param[out] record_idx Optional output parameter to get the index of the found plugin record. + * @return Found plugin record or NULL if not found. + */ static void * lyplg_record_find(const struct ly_ctx *ctx, enum LYPLG type, const char *module, const char *revision, const char *name, uint32_t *record_idx) { From 579d38cdb468361e043d9fdeb6f6c37a8d38f87a Mon Sep 17 00:00:00 2001 From: roman Date: Mon, 20 Jan 2025 15:49:24 +0100 Subject: [PATCH 11/25] plugins UPDATE merge type/ext plugin find funcs --- src/plugins.c | 53 ++++++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/src/plugins.c b/src/plugins.c index 850c86c12..dfbff3a75 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -205,7 +205,7 @@ plugins_iter(const struct ly_ctx *ctx, enum LYPLG type, uint32_t *index) /** * @brief Find the give @p type plugin record. * - * @param[in] ctx The context for which the plugin record is searched for, NULL for built-in plugins. + * @param[in] ctx Context for which the plugin record is searched for, NULL for built-in plugins. * @param[in] type Type of the plugin record to find. * @param[in] module Module name of the plugin record. * @param[in] revision Revision of the @p module. @@ -242,20 +242,31 @@ lyplg_record_find(const struct ly_ctx *ctx, enum LYPLG type, const char *module, return NULL; } -uintptr_t -lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name) +/** + * @brief Find the plugin of the given @p type. + * + * @param[in] ctx Context for which the plugin record is searched for, NULL for built-in plugins. + * @param[in] type Type of the plugin record to find. + * @param[in] module Module name of the plugin. + * @param[in] revision Revision of the @p module. + * @param[in] name Name of the plugin. + * @return Accessor to the callbacks plugin structure, use ::lysc_get_type_plugin() + * or ::lysc_get_ext_plugin() on the returned value to get the actual plugin. 0 if not found. + */ +static uintptr_t +lyplg_plugin_find(const struct ly_ctx *ctx, enum LYPLG type, const char *module, const char *revision, const char *name) { struct lyplg_type_record *record = NULL; uint32_t record_idx = 0; if (ctx) { /* try to find context specific plugin */ - record = lyplg_record_find(ctx, LYPLG_TYPE, module, revision, name, &record_idx); + record = lyplg_record_find(ctx, type, module, revision, name, &record_idx); } if (!record) { /* try to find shared plugin */ - record = lyplg_record_find(NULL, LYPLG_TYPE, module, revision, name, &record_idx); + record = lyplg_record_find(NULL, type, module, revision, name, &record_idx); } if (!record) { @@ -273,33 +284,15 @@ lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char } uintptr_t -lyplg_ext_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name) +lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name) { - struct lyplg_ext_record *record = NULL; - uint32_t record_idx = 0; - - if (ctx) { - /* try to find context specific plugin */ - record = lyplg_record_find(ctx, LYPLG_EXTENSION, module, revision, name, &record_idx); - } - - if (!record) { - /* try to find shared plugin */ - record = lyplg_record_find(NULL, LYPLG_EXTENSION, module, revision, name, &record_idx); - } - - if (!record) { - /* not found */ - return 0; - } + return lyplg_plugin_find(ctx, LYPLG_TYPE, module, revision, name); +} - if (!strncmp(record->plugin.id, "ly2 - ", 6)) { - /* internal plugin, return an index with an offset of +1 in order to keep 0 as an invalid index (a NULL ptr) */ - return record_idx + 1; - } else { - /* external plugin, return the pointer */ - return (uintptr_t)&record->plugin; - } +uintptr_t +lyplg_ext_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name) +{ + return lyplg_plugin_find(ctx, LYPLG_EXTENSION, module, revision, name); } /** From 291118341a98470453f436ee4bf4936441b7b364 Mon Sep 17 00:00:00 2001 From: roman Date: Wed, 22 Jan 2025 10:50:55 +0100 Subject: [PATCH 12/25] plugins BUGFIX move ext plgs outside builtin only --- src/plugins.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/plugins.c b/src/plugins.c index dfbff3a75..756f8c819 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -606,14 +606,14 @@ lyplg_init(ly_bool builtin_type_plugins_only, ly_bool static_plugins_only) /* ietf-netconf-acm */ LY_CHECK_GOTO(ret = plugins_insert(NULL, LYPLG_TYPE, plugins_node_instanceid), error); - - /* internal extensions */ - LY_CHECK_GOTO(ret = plugins_insert(NULL, LYPLG_EXTENSION, plugins_nacm), error); - LY_CHECK_GOTO(ret = plugins_insert(NULL, LYPLG_EXTENSION, plugins_yangdata), error); - LY_CHECK_GOTO(ret = plugins_insert(NULL, LYPLG_EXTENSION, plugins_schema_mount), error); - LY_CHECK_GOTO(ret = plugins_insert(NULL, LYPLG_EXTENSION, plugins_structure), error); } + /* internal extensions */ + LY_CHECK_GOTO(ret = plugins_insert(NULL, LYPLG_EXTENSION, plugins_nacm), error); + LY_CHECK_GOTO(ret = plugins_insert(NULL, LYPLG_EXTENSION, plugins_yangdata), error); + LY_CHECK_GOTO(ret = plugins_insert(NULL, LYPLG_EXTENSION, plugins_schema_mount), error); + LY_CHECK_GOTO(ret = plugins_insert(NULL, LYPLG_EXTENSION, plugins_structure), error); + #ifndef STATIC if (!static_plugins_only) { /* external types */ From 6178f9a2c9df3d778574dfb0c5b6786ade5bc25e Mon Sep 17 00:00:00 2001 From: roman Date: Wed, 22 Jan 2025 10:53:00 +0100 Subject: [PATCH 13/25] printer context BUGFIX build addr ht first --- src/printer_context.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/printer_context.c b/src/printer_context.c index 6ff911d80..94e494854 100644 --- a/src/printer_context.c +++ b/src/printer_context.c @@ -1741,13 +1741,15 @@ ly_ctx_compiled_print_context(const struct ly_ctx *orig_ctx, struct ly_ctx *ctx, /* no search paths */ memset(&ctx->search_paths, 0, sizeof ctx->search_paths); - /* modules, referenced */ + /* modules, referenced, 2 loops because of augments (forward reference), build the ht first */ ctxp_set(&orig_ctx->modules, &ctx->modules, mem); for (i = 0; i < ctx->modules.count; ++i) { ctx->modules.objs[i] = *mem; *mem = (char *)*mem + sizeof(struct lys_module); ly_ctx_compiled_addr_ht_add(addr_ht, orig_ctx->modules.objs[i], ctx->modules.objs[i]); + } + for (i = 0; i < ctx->modules.count; ++i) { ctxp_module(orig_ctx->modules.objs[i], ctx->modules.objs[i], addr_ht, ptr_set, mem); } From d18e6df937e085779d7f25b31a4a7ec7d5e91579 Mon Sep 17 00:00:00 2001 From: roman Date: Wed, 22 Jan 2025 10:54:11 +0100 Subject: [PATCH 14/25] printer context BUGFIX struct ext handling --- src/printer_context.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/printer_context.c b/src/printer_context.c index 94e494854..2fa0e27dc 100644 --- a/src/printer_context.c +++ b/src/printer_context.c @@ -121,7 +121,7 @@ ctxs_exts(const struct lysc_ext_instance *exts, struct ly_ht *ht, int *size) ctxs_exts(exts[u].exts, ht, size); /* substmts */ - *size += sizeof(LY_ARRAY_COUNT_TYPE) + LY_ARRAY_COUNT(exts[u].substmts) * sizeof *exts[u].substmts; + *size += CTXS_SIZED_ARRAY(exts[u].substmts); /* compiled, substmts storage */ ext = lysc_get_ext_plugin(exts[u].def->plugin); @@ -591,6 +591,11 @@ ly_ctx_compiled_ext_stmts_storage_size(const struct lysc_ext_substmt *substmts, const struct lysc_node *node; LY_ARRAY_FOR(substmts, u) { + if (!substmts[u].storage_p) { + /* nothing is compiled */ + continue; + } + switch (substmts[u].stmt) { case LY_STMT_NOTIFICATION: case LY_STMT_INPUT: @@ -1775,10 +1780,17 @@ ly_ctx_compiled_ext_stmts_storage_print(const struct lysc_ext_substmt *orig_subs { LY_ERR rc = LY_SUCCESS; LY_ARRAY_COUNT_TYPE u, v; + uint32_t hash; + const struct lysc_node *node; LY_ARRAY_FOR(orig_substmts, u) { assert(orig_substmts[u].stmt == substmts[u].stmt); + if (!orig_substmts[u].storage_p) { + /* nothing is compiled */ + continue; + } + switch (orig_substmts[u].stmt) { case LY_STMT_NOTIFICATION: case LY_STMT_INPUT: @@ -1794,7 +1806,15 @@ ly_ctx_compiled_ext_stmts_storage_print(const struct lysc_ext_substmt *orig_subs case LY_STMT_LEAF_LIST: case LY_STMT_LIST: case LY_STMT_USES: - ctxp_children(*orig_substmts[u].storage_p, (struct lysc_node **)substmts[u].storage_p, addr_ht, ptr_set, mem); + node = *(const struct lysc_node **)orig_substmts[u].storage_p; + + /* ht check, make sure the node list is stored only once */ + hash = lyht_hash((const char *)&node, sizeof node); + if (lyht_insert(addr_ht, &node, hash, NULL) == LY_EEXIST) { + break; + } + + ctxp_children(node, (struct lysc_node **)substmts[u].storage_p, addr_ht, ptr_set, mem); break; case LY_STMT_ARGUMENT: case LY_STMT_CONTACT: From 701f955e3cdc9ac8acdf4547fead5c85835673c2 Mon Sep 17 00:00:00 2001 From: roman Date: Wed, 22 Jan 2025 12:37:12 +0100 Subject: [PATCH 15/25] test schema UPDATE compiled print test --- tests/utests/schema/test_schema.c | 121 +++++++++++++++++++++++------- 1 file changed, 95 insertions(+), 26 deletions(-) diff --git a/tests/utests/schema/test_schema.c b/tests/utests/schema/test_schema.c index 077d7ebd4..25aee2321 100644 --- a/tests/utests/schema/test_schema.c +++ b/tests/utests/schema/test_schema.c @@ -1894,23 +1894,30 @@ static void test_compiled_print(void **state) { int size, fd; - void *mem, *mem_end, *printed_ctx_mem; + void *mem, *mem_end; struct lyd_node *tree = NULL; struct ly_ctx *printed_ctx = NULL; + struct lys_module *mod = NULL; + const char *yang, *xml; + struct lysc_ext_instance *ext; + const char *features[] = {"feat", NULL}; - /* recreate the context, get rid of all the plugins and use builtin/static only */ + /* recreate the context, using builtin/static plugins only */ ly_ctx_destroy(UTEST_LYCTX); assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_BUILTIN_PLUGINS_ONLY | LY_CTX_STATIC_PLUGINS_ONLY, &UTEST_LYCTX)); - /* load another module */ - assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {yang-version 1.1; namespace urn:c;prefix c;" + /* load the base module */ + yang = "module m1 {yang-version 1.1; namespace urn:m1;prefix m1;" + "import ietf-yang-metadata {prefix md;}" + "identity baseid;" + "identity id1 {base baseid;}" "feature feat;" - "feature feat2;" + "container root {" "leaf a {type instance-identifier;}" - "leaf b {type boolean; must \"/a\";}" - "leaf c {type binary; when \"/c:b = 'true'\";}" + "leaf b {type boolean; must \"/m1:root/a\";}" + "leaf c {type binary; when \"/m1:root/b = 'true'\";}" "leaf d {type decimal64 {fraction-digits 2;}}" - "leaf-list e {type instance-identifier; default \"/c:a\"; default \"/c:b\"; default \"/c:c\";}" + "leaf-list e {type instance-identifier; default \"/m1:root/m1:a\"; default \"/m1:root/m1:b\"; default \"/m1:root/m1:c\";}" "anydata f;" "list g {" " key a;" @@ -1922,12 +1929,48 @@ test_compiled_print(void **state) " leaf d {type empty;}" " leaf e {type int8;}" "}" + "}" "rpc h {" " input {leaf a {type string;}}" "}" - "}", LYS_IN_YANG, NULL)); + "md:annotation i {" + " description \"test\";" + " if-feature feat;" + " reference \"test\";" + " status \"current\";" + " type uint8;" + " units meters;" + "}" + "}"; + UTEST_ADD_MODULE(yang, LYS_IN_YANG, features, NULL); + + /* load an augment of the base module */ + yang = "module m2 {namespace urn:m2;prefix m2;" + "import m1 {prefix m1;}" + "identity id2 {base m1:baseid;}" + "grouping leaf_group {leaf a {type identityref {base m1:baseid;}}}" + "augment /m1:root {uses leaf_group;}}"; + assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, yang, LYS_IN_YANG, NULL)); + + /* load a structure extension module */ + yang = "module m3 {yang-version 1.1; namespace urn:m3; prefix m3;" + "import ietf-yang-structure-ext {prefix sx;}" + "sx:structure struct { container a { leaf b { type string;}}}}"; + UTEST_ADD_MODULE(yang, LYS_IN_YANG, NULL, &mod); + + /* load a structure augment extension module */ + yang = "module m4 {yang-version 1.1; namespace urn:m4; prefix m4;" + "import ietf-yang-structure-ext {prefix sx;}" + "import m3 {prefix m3;}" + "sx:augment-structure \"/m3:struct/m3:a\" {" + " leaf c {type uint32;}" + "}}"; + UTEST_ADD_MODULE(yang, LYS_IN_YANG, NULL, NULL); + + /* get the structure extension */ + assert_non_null(ext = &mod->compiled->exts[0]); - /* get the size */ + /* get the size of the compiled ctx */ size = ly_ctx_compiled_size(UTEST_LYCTX); /* prepare the shared memory segment */ @@ -1937,31 +1980,57 @@ test_compiled_print(void **state) mem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); assert_ptr_not_equal(mem, MAP_FAILED); - /* print the context */ + /* print the context into the shared memory */ assert_int_equal(LY_SUCCESS, ly_ctx_compiled_print(UTEST_LYCTX, mem, &mem_end)); assert_int_equal((char *)mem_end - (char *)mem, size); - /* remap the region and parse the context from mem */ - munmap(mem, size); + /* create a new printed ctx from this address */ + assert_int_equal(LY_SUCCESS, ly_ctx_new_printed(mem, &printed_ctx)); + + /* try to parse data with the printed ctx */ + xml = "\n" + " /m1:root/m1:b\n" + " true\n" + " Zm9vYmFy\n" + " 123.45\n" + " /m1:root/m1:a\n" + " /m1:root/m1:b\n" + " /m1:root/m1:c\n" + " \n" + " \n" + " abc\n" + " \n" + " \n" + " \n" + " key\n" + " unique\n" + " 123\n" + " \n" + " -10\n" + " \n" + " m1:id1\n" + "\n"; + assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(printed_ctx, xml, + LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, &tree)); + + CHECK_LYD_STRING_PARAM(tree, xml, LYD_XML, 0); + lyd_free_all(tree); - /* mmap the same address again */ - printed_ctx_mem = mmap(mem, size, PROT_READ, MAP_PRIVATE | MAP_FIXED_NOREPLACE, fd, 0); - assert_ptr_not_equal(printed_ctx_mem, MAP_FAILED); + /* parse structure extension data with the printed ctx */ + xml = "\n" + " abc\n" + " 24\n" + "\n"; + assert_int_equal(LY_SUCCESS, ly_in_new_memory(xml, &UTEST_IN)); + assert_int_equal(LY_SUCCESS, lyd_parse_ext_data(ext, NULL, UTEST_IN, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, &tree)); - /* create a new printed ctx from this address */ - assert_int_equal(LY_SUCCESS, ly_ctx_new_printed(printed_ctx_mem, &printed_ctx)); + CHECK_LYD_STRING_PARAM(tree, xml, LYD_XML, 0); - /* try to parse data with it */ - assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(printed_ctx, - "/c:b" - "true" - "ahoi", - LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree)); + lyd_free_all(tree); /* cleanup */ - lyd_free_all(tree); ly_ctx_destroy(printed_ctx); - munmap(printed_ctx_mem, size); + munmap(mem, size); close(fd); shm_unlink("/ly_test_schema_ctx"); } From f5b9361b93c51bad6c63b1b00a4c18ba8b0884c9 Mon Sep 17 00:00:00 2001 From: roman Date: Wed, 22 Jan 2025 13:13:53 +0100 Subject: [PATCH 16/25] plguins REFACTOR various smaller docs refactoring --- src/context.h | 2 +- src/plugins.c | 8 ++++++-- src/plugins_internal.h | 2 +- src/printer_context.c | 3 ++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/context.h b/src/context.h index d97ce7f00..9d1effcd6 100644 --- a/src/context.h +++ b/src/context.h @@ -212,7 +212,7 @@ struct ly_ctx; #define LY_CTX_STATIC_PLUGINS_ONLY 0x2000 /**< By default, external plugins from directories the path to which is obtained from the `LIBYANG_TYPES_PLUGINS_DIR` and `LIBYANG_EXTENSIONS_PLUGINS_DIR` environmental variables are loaded. This option prevents loading of all external plugins and only - the static (built-in) plugins are loaded. */ + the static (libyang built-in) plugins are loaded. */ /* 0x80000000 reserved for internal use */ diff --git a/src/plugins.c b/src/plugins.c index 756f8c819..dd81ae362 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -176,9 +176,9 @@ lysc_get_ext_plugin(uintptr_t plugin_id) /** * @brief Iterate over list of loaded plugins of the given @p type. * - * @param[in] ctx The context for which the plugin is searched for. + * @param[in] ctx Context for which the plugin is searched for. * @param[in] type Type of the plugins to iterate. - * @param[in,out] index The iterator - set to 0 for the first call. + * @param[in,out] index Iterator - set to 0 for the first call. * @return The plugin records, NULL if no more record is available. */ static struct lyplg_record * @@ -222,6 +222,10 @@ lyplg_record_find(const struct ly_ctx *ctx, enum LYPLG type, const char *module, assert(module); assert(name); + if (record_idx) { + *record_idx = 0; + } + while ((item = plugins_iter(ctx, type, &i)) != NULL) { if (!strcmp(item->module, module) && !strcmp(item->name, name)) { if (item->revision && revision && strcmp(item->revision, revision)) { diff --git a/src/plugins_internal.h b/src/plugins_internal.h index 0526bdef5..5520060f5 100644 --- a/src/plugins_internal.h +++ b/src/plugins_internal.h @@ -49,7 +49,7 @@ * Covers both the types and extensions plugins. * * @param[in] builtin_type_plugins_only Whether to load only built-in YANG type plugins and no included extension plugins. - * @param[in] static_plugins_only Whether to load only static plugins, meaning no external directories with plugins. + * @param[in] static_plugins_only Whether to load only static (libyang built-in) plugins, meaning no external directories with plugins. * @return LY_SUCCESS in case of success * @return LY_EINT in case of internal error * @return LY_EMEM in case of memory allocation failure. diff --git a/src/printer_context.c b/src/printer_context.c index 2fa0e27dc..a159c9f9e 100644 --- a/src/printer_context.c +++ b/src/printer_context.c @@ -1749,12 +1749,13 @@ ly_ctx_compiled_print_context(const struct ly_ctx *orig_ctx, struct ly_ctx *ctx, /* modules, referenced, 2 loops because of augments (forward reference), build the ht first */ ctxp_set(&orig_ctx->modules, &ctx->modules, mem); for (i = 0; i < ctx->modules.count; ++i) { + /* build the address ht */ ctx->modules.objs[i] = *mem; *mem = (char *)*mem + sizeof(struct lys_module); - ly_ctx_compiled_addr_ht_add(addr_ht, orig_ctx->modules.objs[i], ctx->modules.objs[i]); } for (i = 0; i < ctx->modules.count; ++i) { + /* parse the modules */ ctxp_module(orig_ctx->modules.objs[i], ctx->modules.objs[i], addr_ht, ptr_set, mem); } From 750c5f349c9f82f0d1ff59312a4b627817c7e62a Mon Sep 17 00:00:00 2001 From: roman Date: Wed, 22 Jan 2025 13:20:33 +0100 Subject: [PATCH 17/25] plugins REFACTOR s/plugin_id/plugin_ref --- src/plugins.c | 27 ++++++++++++++------------- src/schema_compile_node.c | 30 +++++++++++++++--------------- src/tree_schema.h | 12 ++++++------ 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/plugins.c b/src/plugins.c index dd81ae362..45ed051a7 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -135,42 +135,43 @@ static struct ly_set plugins_extensions = {0}; /** * @brief Get the plugin of the given @p type. * - * @param[in] plugin_id Either an index of the built-in plugin (offset by +1) or a pointer to the external plugin. + * @param[in] plugin_ref Reference to a plugin. Either an index of a built-in plugin (offset by +1) + * or a pointer to an external plugin. * @param[in] type Type of the plugin to get. - * @param[in] plugins Array of the built-in plugins used in case @p plugin_id is an index of a built-in plugin. + * @param[in] plugins Array of the built-in plugins used in case @p plugin_ref is an index of a built-in plugin. * @return Plugin of the given @p type or NULL if not found. */ static void * -lysc_get_plugin(uintptr_t plugin_id, enum LYPLG type, const struct ly_set *plugins) +lysc_get_plugin(uintptr_t plugin_ref, enum LYPLG type, const struct ly_set *plugins) { - /* plugin_id is offset by +1, so 0 is invalid (NULL ptr equivalent) */ - if (!plugin_id) { + /* plugin_ref is offset by +1, so 0 is invalid (NULL ptr equivalent) */ + if (!plugin_ref) { return NULL; } - if (plugin_id <= plugins->count) { + if (plugin_ref <= plugins->count) { /* plugin is built-in, fetch it from the global list */ if (type == LYPLG_EXTENSION) { - return &((struct lyplg_ext_record *)plugins->objs[plugin_id - 1])->plugin; + return &((struct lyplg_ext_record *)plugins->objs[plugin_ref - 1])->plugin; } else { - return &((struct lyplg_type_record *)plugins->objs[plugin_id - 1])->plugin; + return &((struct lyplg_type_record *)plugins->objs[plugin_ref - 1])->plugin; } } else { /* plugin is external, return the pointer */ - return (void *)plugin_id; + return (void *)plugin_ref; } } LIBYANG_API_DEF struct lyplg_type * -lysc_get_type_plugin(uintptr_t plugin_id) +lysc_get_type_plugin(uintptr_t plugin_ref) { - return lysc_get_plugin(plugin_id, LYPLG_TYPE, &plugins_types); + return lysc_get_plugin(plugin_ref, LYPLG_TYPE, &plugins_types); } LIBYANG_API_DEF struct lyplg_ext * -lysc_get_ext_plugin(uintptr_t plugin_id) +lysc_get_ext_plugin(uintptr_t plugin_ref) { - return lysc_get_plugin(plugin_id, LYPLG_EXTENSION, &plugins_extensions); + return lysc_get_plugin(plugin_ref, LYPLG_EXTENSION, &plugins_extensions); } /** diff --git a/src/schema_compile_node.c b/src/schema_compile_node.c index b6f681a5a..7c67e408e 100644 --- a/src/schema_compile_node.c +++ b/src/schema_compile_node.c @@ -1764,7 +1764,7 @@ lys_new_type(const struct ly_ctx *ctx, LY_DATA_TYPE basetype, const char *tpdf_n * @param[in] basetype Base YANG built-in type of the type to compile. * @param[in] tpdfname Name of the type's typedef, serves as a flag - if it is leaf/leaf-list's type, it is NULL. * @param[in] base Latest base (compiled) type from which the current type is being derived. - * @param[in] plugin Type plugin to use. + * @param[in] plugin_ref Reference to the type plugin to use. * @param[in] tpdf_chain Chain of the used typedefs, traversed backwards. * @param[in] tpdf_chain_last Index of the last (backwards) typedef in @p tpdf_chain to use. * @param[out] type Compiled type. @@ -1773,7 +1773,7 @@ lys_new_type(const struct ly_ctx *ctx, LY_DATA_TYPE basetype, const char *tpdf_n static LY_ERR lys_compile_type_(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t context_flags, const char *context_name, const struct lysp_type *type_p, LY_DATA_TYPE basetype, const char *tpdfname, const struct lysc_type *base, - uintptr_t plugin, struct ly_set *tpdf_chain, uint32_t tpdf_chain_last, struct lysc_type **type) + uintptr_t plugin_ref, struct ly_set *tpdf_chain, uint32_t tpdf_chain_last, struct lysc_type **type) { LY_ERR rc = LY_SUCCESS; struct lysc_type_bin *bin; @@ -1794,7 +1794,7 @@ lys_compile_type_(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_ LY_CHECK_GOTO(rc, cleanup); (*type)->basetype = basetype; - (*type)->plugin = plugin; + (*type)->plugin = plugin_ref; switch (basetype) { case LY_TYPE_BINARY: @@ -2141,7 +2141,7 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t struct lysc_type_union *base_un; LY_ARRAY_COUNT_TYPE u; struct ly_set tpdf_chain = {0}; - uintptr_t plugin_id = 0; + uintptr_t plugin_ref = 0; *type = NULL; if (dflt) { @@ -2264,19 +2264,19 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t } /* try to find loaded user type plugins */ - plugin_id = lyplg_type_plugin_find(ctx->ctx, tctx->tpdf->type.pmod->mod->name, tctx->tpdf->type.pmod->mod->revision, + plugin_ref = lyplg_type_plugin_find(ctx->ctx, tctx->tpdf->type.pmod->mod->name, tctx->tpdf->type.pmod->mod->revision, tctx->tpdf->name); - if (!plugin_id && base) { - plugin_id = base->plugin; + if (!plugin_ref && base) { + plugin_ref = base->plugin; } - if (!plugin_id) { + if (!plugin_ref) { /* use the internal built-in type implementation */ - plugin_id = lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype]); + plugin_ref = lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype]); } - assert(plugin_id); + assert(plugin_ref); if ((basetype != LY_TYPE_LEAFREF) && (u != tpdf_chain.count - 1) && !tctx->tpdf->type.flags && - !tctx->tpdf->type.exts && (plugin_id == base->plugin)) { + !tctx->tpdf->type.exts && (plugin_ref == base->plugin)) { /* no change, reuse the compiled base */ ((struct lysp_tpdf *)tctx->tpdf)->type.compiled = base; LY_ATOMIC_INC_BARRIER(base->refcount); @@ -2297,7 +2297,7 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t /* compile the typedef type */ ret = lys_compile_type_(ctx, tctx->node, tctx->tpdf->flags, tctx->tpdf->name, &tctx->tpdf->type, basetype, - tctx->tpdf->name, base, plugin_id, &tpdf_chain, u + 1, &base); + tctx->tpdf->name, base, plugin_ref, &tpdf_chain, u + 1, &base); LY_CHECK_GOTO(ret, cleanup); /* store separately compiled typedef type to be reused */ @@ -2329,12 +2329,12 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t if (type_p->flags || type_p->exts || !base || has_leafref) { /* leaf type has changes that need to be compiled into the type */ if (base) { - plugin_id = base->plugin; + plugin_ref = base->plugin; } else { - plugin_id = lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype]); + plugin_ref = lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype]); } ret = lys_compile_type_(ctx, context_pnode, context_flags, context_name, (struct lysp_type *)type_p, basetype, - NULL, base, plugin_id, &tpdf_chain, 0, type); + NULL, base, plugin_ref, &tpdf_chain, 0, type); LY_CHECK_GOTO(ret, cleanup); } else { /* no changes of the type in the leaf, just use the base compiled type */ diff --git a/src/tree_schema.h b/src/tree_schema.h index 6bec597d6..80d074dd7 100644 --- a/src/tree_schema.h +++ b/src/tree_schema.h @@ -1800,20 +1800,20 @@ struct lysc_module { /** * @brief Get a type plugin. * - * @param[in] plugin_id Either an index in the type plugins array (e.g. 1 -> binary type) - * or a pointer to the user defined plugin. Indexes start at 1. + * @param[in] plugin_ref Reference to a type plugin. Either an index in the type plugins + * array (e.g. 1 -> binary type) or a pointer to the user defined plugin. Indexes start at 1. * @return Type plugin or NULL. */ -LIBYANG_API_DECL struct lyplg_type *lysc_get_type_plugin(uintptr_t plugin_id); +LIBYANG_API_DECL struct lyplg_type *lysc_get_type_plugin(uintptr_t plugin_ref); /** * @brief Get an extension plugin. * - * @param[in] plugin_id Either an index in the extension plugins array (e.g. 1 -> metadata extension) - * or a pointer to the user defined plugin. Indexes start at 1. + * @param[in] plugin_ref Reference to an extension plugin. Either an index in the extension plugins + * array (e.g. 1 -> metadata extension) or a pointer to the user defined plugin. Indexes start at 1. * @return Extension plugin or NULL. */ -LIBYANG_API_DECL struct lyplg_ext *lysc_get_ext_plugin(uintptr_t plugin_id); +LIBYANG_API_DECL struct lyplg_ext *lysc_get_ext_plugin(uintptr_t plugin_ref); /** * @brief Get nearest @p schema parent (including the node itself) that can be instantiated in data. From 9732792219a6a5efbbecd93a311ac4ad1baf6a41 Mon Sep 17 00:00:00 2001 From: roman Date: Fri, 24 Jan 2025 11:20:44 +0100 Subject: [PATCH 18/25] plugins REFACTOR remove dash from id --- src/plugins_exts/metadata.c | 2 +- src/plugins_exts/nacm.c | 8 +++---- src/plugins_exts/schema_mount.c | 2 +- src/plugins_exts/structure.c | 4 ++-- src/plugins_exts/yangdata.c | 2 +- src/plugins_types/binary.c | 2 +- src/plugins_types/bits.c | 2 +- src/plugins_types/boolean.c | 2 +- src/plugins_types/date_and_time.c | 2 +- src/plugins_types/decimal64.c | 2 +- src/plugins_types/empty.c | 2 +- src/plugins_types/enumeration.c | 2 +- src/plugins_types/hex_string.c | 8 +++---- src/plugins_types/identityref.c | 2 +- src/plugins_types/instanceid.c | 2 +- src/plugins_types/instanceid_keys.c | 2 +- src/plugins_types/integer.c | 16 ++++++------- src/plugins_types/ipv4_address.c | 2 +- src/plugins_types/ipv4_address_no_zone.c | 2 +- src/plugins_types/ipv4_prefix.c | 2 +- src/plugins_types/ipv6_address.c | 2 +- src/plugins_types/ipv6_address_no_zone.c | 2 +- src/plugins_types/ipv6_prefix.c | 2 +- src/plugins_types/leafref.c | 2 +- src/plugins_types/lyds_tree.c | 2 +- src/plugins_types/node_instanceid.c | 4 ++-- src/plugins_types/string.c | 2 +- src/plugins_types/time_period.c | 2 +- src/plugins_types/union.c | 2 +- src/plugins_types/xpath1.0.c | 2 +- tests/utests/extensions/test_metadata.c | 8 +++---- tests/utests/extensions/test_nacm.c | 8 +++---- tests/utests/extensions/test_schema_mount.c | 26 ++++++++++----------- tests/utests/extensions/test_structure.c | 6 ++--- tests/utests/extensions/test_yangdata.c | 14 +++++------ tests/utests/types/binary.c | 2 +- tests/utests/types/bits.c | 2 +- tests/utests/types/int8.c | 2 +- tests/utests/types/string.c | 2 +- tests/utests/types/union.c | 14 +++++------ 40 files changed, 87 insertions(+), 87 deletions(-) diff --git a/src/plugins_exts/metadata.c b/src/plugins_exts/metadata.c index f6f37b45b..e699e120e 100644 --- a/src/plugins_exts/metadata.c +++ b/src/plugins_exts/metadata.c @@ -257,7 +257,7 @@ const struct lyplg_ext_record plugins_metadata[] = { .revision = "2016-08-05", .name = "annotation", - .plugin.id = "ly2 - metadata", + .plugin.id = "ly2 metadata", .plugin.parse = annotation_parse, .plugin.compile = annotation_compile, .plugin.printer_info = annotation_printer_info, diff --git a/src/plugins_exts/nacm.c b/src/plugins_exts/nacm.c index adda9d28a..faa5c6a4d 100644 --- a/src/plugins_exts/nacm.c +++ b/src/plugins_exts/nacm.c @@ -177,7 +177,7 @@ const struct lyplg_ext_record plugins_nacm[] = { .revision = "2012-02-22", .name = "default-deny-write", - .plugin.id = "ly2 - NACM", + .plugin.id = "ly2 NACM", .plugin.parse = nacm_parse, .plugin.compile = nacm_compile, .plugin.printer_info = NULL, @@ -195,7 +195,7 @@ const struct lyplg_ext_record plugins_nacm[] = { .revision = "2018-02-14", .name = "default-deny-write", - .plugin.id = "ly2 - NACM", + .plugin.id = "ly2 NACM", .plugin.parse = nacm_parse, .plugin.compile = nacm_compile, .plugin.printer_info = NULL, @@ -213,7 +213,7 @@ const struct lyplg_ext_record plugins_nacm[] = { .revision = "2012-02-22", .name = "default-deny-all", - .plugin.id = "ly2 - NACM", + .plugin.id = "ly2 NACM", .plugin.parse = nacm_parse, .plugin.compile = nacm_compile, .plugin.printer_info = NULL, @@ -231,7 +231,7 @@ const struct lyplg_ext_record plugins_nacm[] = { .revision = "2018-02-14", .name = "default-deny-all", - .plugin.id = "ly2 - NACM", + .plugin.id = "ly2 NACM", .plugin.parse = nacm_parse, .plugin.compile = nacm_compile, .plugin.printer_info = NULL, diff --git a/src/plugins_exts/schema_mount.c b/src/plugins_exts/schema_mount.c index bc23d62a8..325f8427b 100644 --- a/src/plugins_exts/schema_mount.c +++ b/src/plugins_exts/schema_mount.c @@ -1422,7 +1422,7 @@ const struct lyplg_ext_record plugins_schema_mount[] = { .revision = "2019-01-14", .name = "mount-point", - .plugin.id = "ly2 - schema mount", + .plugin.id = "ly2 schema mount", .plugin.parse = schema_mount_parse, .plugin.compile = schema_mount_compile, .plugin.printer_info = NULL, diff --git a/src/plugins_exts/structure.c b/src/plugins_exts/structure.c index bdea41932..98321b9b8 100644 --- a/src/plugins_exts/structure.c +++ b/src/plugins_exts/structure.c @@ -562,7 +562,7 @@ const struct lyplg_ext_record plugins_structure[] = { .revision = "2020-06-17", .name = "structure", - .plugin.id = "ly2 - structure", + .plugin.id = "ly2 structure", .plugin.parse = structure_parse, .plugin.compile = structure_compile, .plugin.printer_info = structure_printer_info, @@ -581,7 +581,7 @@ const struct lyplg_ext_record plugins_structure[] = { .revision = "2020-06-17", .name = "augment-structure", - .plugin.id = "ly2 - structure", + .plugin.id = "ly2 structure", .plugin.parse = structure_aug_parse, .plugin.compile = NULL, .plugin.printer_info = NULL, diff --git a/src/plugins_exts/yangdata.c b/src/plugins_exts/yangdata.c index ea3bc9b10..917ce19dd 100644 --- a/src/plugins_exts/yangdata.c +++ b/src/plugins_exts/yangdata.c @@ -278,7 +278,7 @@ const struct lyplg_ext_record plugins_yangdata[] = { .revision = "2017-01-26", .name = "yang-data", - .plugin.id = "ly2 - yang-data", + .plugin.id = "ly2 yang-data", .plugin.parse = yangdata_parse, .plugin.compile = yangdata_compile, .plugin.printer_info = yangdata_printer_info, diff --git a/src/plugins_types/binary.c b/src/plugins_types/binary.c index 24f2c2960..ff47b3082 100644 --- a/src/plugins_types/binary.c +++ b/src/plugins_types/binary.c @@ -471,7 +471,7 @@ const struct lyplg_type_record plugins_binary[] = { .revision = NULL, .name = LY_TYPE_BINARY_STR, - .plugin.id = "ly2 - binary", + .plugin.id = "ly2 binary", .plugin.store = lyplg_type_store_binary, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_binary, diff --git a/src/plugins_types/bits.c b/src/plugins_types/bits.c index cdeb84d34..47012a324 100644 --- a/src/plugins_types/bits.c +++ b/src/plugins_types/bits.c @@ -507,7 +507,7 @@ const struct lyplg_type_record plugins_bits[] = { .revision = NULL, .name = LY_TYPE_BITS_STR, - .plugin.id = "ly2 - bits", + .plugin.id = "ly2 bits", .plugin.store = lyplg_type_store_bits, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_bits, diff --git a/src/plugins_types/boolean.c b/src/plugins_types/boolean.c index 42b7918d4..bef336ea3 100644 --- a/src/plugins_types/boolean.c +++ b/src/plugins_types/boolean.c @@ -159,7 +159,7 @@ const struct lyplg_type_record plugins_boolean[] = { .revision = NULL, .name = LY_TYPE_BOOL_STR, - .plugin.id = "ly2 - boolean", + .plugin.id = "ly2 boolean", .plugin.store = lyplg_type_store_boolean, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_boolean, diff --git a/src/plugins_types/date_and_time.c b/src/plugins_types/date_and_time.c index c2aaf794e..0d6cc25d3 100644 --- a/src/plugins_types/date_and_time.c +++ b/src/plugins_types/date_and_time.c @@ -386,7 +386,7 @@ const struct lyplg_type_record plugins_date_and_time[] = { .revision = "2013-07-15", .name = "date-and-time", - .plugin.id = "ly2 - date-and-time", + .plugin.id = "ly2 date-and-time", .plugin.store = lyplg_type_store_date_and_time, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_date_and_time, diff --git a/src/plugins_types/decimal64.c b/src/plugins_types/decimal64.c index 5a9b7ab2d..9dc4e4826 100644 --- a/src/plugins_types/decimal64.c +++ b/src/plugins_types/decimal64.c @@ -237,7 +237,7 @@ const struct lyplg_type_record plugins_decimal64[] = { .revision = NULL, .name = LY_TYPE_DEC64_STR, - .plugin.id = "ly2 - decimal64", + .plugin.id = "ly2 decimal64", .plugin.store = lyplg_type_store_decimal64, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_decimal64, diff --git a/src/plugins_types/empty.c b/src/plugins_types/empty.c index 8b88e6154..7ad10683b 100644 --- a/src/plugins_types/empty.c +++ b/src/plugins_types/empty.c @@ -89,7 +89,7 @@ const struct lyplg_type_record plugins_empty[] = { .revision = NULL, .name = LY_TYPE_EMPTY_STR, - .plugin.id = "ly2 - empty", + .plugin.id = "ly2 empty", .plugin.store = lyplg_type_store_empty, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, diff --git a/src/plugins_types/enumeration.c b/src/plugins_types/enumeration.c index d3159a6e3..561c73022 100644 --- a/src/plugins_types/enumeration.c +++ b/src/plugins_types/enumeration.c @@ -201,7 +201,7 @@ const struct lyplg_type_record plugins_enumeration[] = { .revision = NULL, .name = LY_TYPE_ENUM_STR, - .plugin.id = "ly2 - enumeration", + .plugin.id = "ly2 enumeration", .plugin.store = lyplg_type_store_enum, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, diff --git a/src/plugins_types/hex_string.c b/src/plugins_types/hex_string.c index 285967b67..646a545ff 100644 --- a/src/plugins_types/hex_string.c +++ b/src/plugins_types/hex_string.c @@ -118,7 +118,7 @@ const struct lyplg_type_record plugins_hex_string[] = { .revision = "2013-07-15", .name = "phys-address", - .plugin.id = "ly2 - hex-string", + .plugin.id = "ly2 hex-string", .plugin.store = lyplg_type_store_hex_string, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, @@ -133,7 +133,7 @@ const struct lyplg_type_record plugins_hex_string[] = { .revision = "2013-07-15", .name = "mac-address", - .plugin.id = "ly2 - hex-string", + .plugin.id = "ly2 hex-string", .plugin.store = lyplg_type_store_hex_string, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, @@ -148,7 +148,7 @@ const struct lyplg_type_record plugins_hex_string[] = { .revision = "2013-07-15", .name = "hex-string", - .plugin.id = "ly2 - hex-string", + .plugin.id = "ly2 hex-string", .plugin.store = lyplg_type_store_hex_string, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, @@ -163,7 +163,7 @@ const struct lyplg_type_record plugins_hex_string[] = { .revision = "2013-07-15", .name = "uuid", - .plugin.id = "ly2 - hex-string", + .plugin.id = "ly2 hex-string", .plugin.store = lyplg_type_store_hex_string, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, diff --git a/src/plugins_types/identityref.c b/src/plugins_types/identityref.c index 9941b4a38..cad37c6d7 100644 --- a/src/plugins_types/identityref.c +++ b/src/plugins_types/identityref.c @@ -354,7 +354,7 @@ const struct lyplg_type_record plugins_identityref[] = { .revision = NULL, .name = LY_TYPE_IDENT_STR, - .plugin.id = "ly2 - identityref", + .plugin.id = "ly2 identityref", .plugin.store = lyplg_type_store_identityref, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_identityref, diff --git a/src/plugins_types/instanceid.c b/src/plugins_types/instanceid.c index 78f221b87..59da3ab9c 100644 --- a/src/plugins_types/instanceid.c +++ b/src/plugins_types/instanceid.c @@ -321,7 +321,7 @@ const struct lyplg_type_record plugins_instanceid[] = { .revision = NULL, .name = LY_TYPE_INST_STR, - .plugin.id = "ly2 - instance-identifier", + .plugin.id = "ly2 instance-identifier", .plugin.store = lyplg_type_store_instanceid, .plugin.validate = lyplg_type_validate_instanceid, .plugin.compare = lyplg_type_compare_simple, diff --git a/src/plugins_types/instanceid_keys.c b/src/plugins_types/instanceid_keys.c index 6d7423cad..9ddf1e43c 100644 --- a/src/plugins_types/instanceid_keys.c +++ b/src/plugins_types/instanceid_keys.c @@ -239,7 +239,7 @@ const struct lyplg_type_record plugins_instanceid_keys[] = { .revision = NULL, .name = "instance-identifier-keys", - .plugin.id = "ly2 - instance-identifier-keys", + .plugin.id = "ly2 instance-identifier-keys", .plugin.store = lyplg_type_store_instanceid_keys, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, diff --git a/src/plugins_types/integer.c b/src/plugins_types/integer.c index 5a52ad7fb..082c24b10 100644 --- a/src/plugins_types/integer.c +++ b/src/plugins_types/integer.c @@ -565,7 +565,7 @@ const struct lyplg_type_record plugins_integer[] = { .revision = NULL, .name = LY_TYPE_UINT8_STR, - .plugin.id = "ly2 - integers", + .plugin.id = "ly2 integers", .plugin.store = lyplg_type_store_uint, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_uint, @@ -579,7 +579,7 @@ const struct lyplg_type_record plugins_integer[] = { .revision = NULL, .name = LY_TYPE_UINT16_STR, - .plugin.id = "ly2 - integers", + .plugin.id = "ly2 integers", .plugin.store = lyplg_type_store_uint, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_uint, @@ -593,7 +593,7 @@ const struct lyplg_type_record plugins_integer[] = { .revision = NULL, .name = LY_TYPE_UINT32_STR, - .plugin.id = "ly2 - integers", + .plugin.id = "ly2 integers", .plugin.store = lyplg_type_store_uint, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_uint, @@ -607,7 +607,7 @@ const struct lyplg_type_record plugins_integer[] = { .revision = NULL, .name = LY_TYPE_UINT64_STR, - .plugin.id = "ly2 - integers", + .plugin.id = "ly2 integers", .plugin.store = lyplg_type_store_uint, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_uint, @@ -621,7 +621,7 @@ const struct lyplg_type_record plugins_integer[] = { .revision = NULL, .name = LY_TYPE_INT8_STR, - .plugin.id = "ly2 - integers", + .plugin.id = "ly2 integers", .plugin.store = lyplg_type_store_int, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_int, @@ -635,7 +635,7 @@ const struct lyplg_type_record plugins_integer[] = { .revision = NULL, .name = LY_TYPE_INT16_STR, - .plugin.id = "ly2 - integers", + .plugin.id = "ly2 integers", .plugin.store = lyplg_type_store_int, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_int, @@ -649,7 +649,7 @@ const struct lyplg_type_record plugins_integer[] = { .revision = NULL, .name = LY_TYPE_INT32_STR, - .plugin.id = "ly2 - integers", + .plugin.id = "ly2 integers", .plugin.store = lyplg_type_store_int, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_int, @@ -663,7 +663,7 @@ const struct lyplg_type_record plugins_integer[] = { .revision = NULL, .name = LY_TYPE_INT64_STR, - .plugin.id = "ly2 - integers", + .plugin.id = "ly2 integers", .plugin.store = lyplg_type_store_int, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_int, diff --git a/src/plugins_types/ipv4_address.c b/src/plugins_types/ipv4_address.c index 98d88c6f3..e2fedf80e 100644 --- a/src/plugins_types/ipv4_address.c +++ b/src/plugins_types/ipv4_address.c @@ -392,7 +392,7 @@ const struct lyplg_type_record plugins_ipv4_address[] = { .revision = "2013-07-15", .name = "ipv4-address", - .plugin.id = "ly2 - ipv4-address", + .plugin.id = "ly2 ipv4-address", .plugin.store = lyplg_type_store_ipv4_address, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_ipv4_address, diff --git a/src/plugins_types/ipv4_address_no_zone.c b/src/plugins_types/ipv4_address_no_zone.c index ffe1cbac4..55eff628c 100644 --- a/src/plugins_types/ipv4_address_no_zone.c +++ b/src/plugins_types/ipv4_address_no_zone.c @@ -209,7 +209,7 @@ const struct lyplg_type_record plugins_ipv4_address_no_zone[] = { .revision = "2013-07-15", .name = "ipv4-address-no-zone", - .plugin.id = "ly2 - ipv4-address-no-zone", + .plugin.id = "ly2 ipv4-address-no-zone", .plugin.store = lyplg_type_store_ipv4_address_no_zone, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_ipv4_address_no_zone, diff --git a/src/plugins_types/ipv4_prefix.c b/src/plugins_types/ipv4_prefix.c index 7f422cce0..d92ebdfcb 100644 --- a/src/plugins_types/ipv4_prefix.c +++ b/src/plugins_types/ipv4_prefix.c @@ -339,7 +339,7 @@ const struct lyplg_type_record plugins_ipv4_prefix[] = { .revision = "2013-07-15", .name = "ipv4-prefix", - .plugin.id = "ly2 - ipv4-prefix", + .plugin.id = "ly2 ipv4-prefix", .plugin.store = lyplg_type_store_ipv4_prefix, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_ipv4_prefix, diff --git a/src/plugins_types/ipv6_address.c b/src/plugins_types/ipv6_address.c index 8b0057de4..c50be8d07 100644 --- a/src/plugins_types/ipv6_address.c +++ b/src/plugins_types/ipv6_address.c @@ -394,7 +394,7 @@ const struct lyplg_type_record plugins_ipv6_address[] = { .revision = "2013-07-15", .name = "ipv6-address", - .plugin.id = "ly2 - ipv6-address", + .plugin.id = "ly2 ipv6-address", .plugin.store = lyplg_type_store_ipv6_address, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_ipv6_address, diff --git a/src/plugins_types/ipv6_address_no_zone.c b/src/plugins_types/ipv6_address_no_zone.c index b4422cd33..7d977396c 100644 --- a/src/plugins_types/ipv6_address_no_zone.c +++ b/src/plugins_types/ipv6_address_no_zone.c @@ -300,7 +300,7 @@ const struct lyplg_type_record plugins_ipv6_address_no_zone[] = { .revision = "2013-07-15", .name = "ipv6-address-no-zone", - .plugin.id = "ly2 - ipv6-address-no-zone", + .plugin.id = "ly2 ipv6-address-no-zone", .plugin.store = lyplg_type_store_ipv6_address_no_zone, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_ipv6_address_no_zone, diff --git a/src/plugins_types/ipv6_prefix.c b/src/plugins_types/ipv6_prefix.c index 6730172a2..752eefd2e 100644 --- a/src/plugins_types/ipv6_prefix.c +++ b/src/plugins_types/ipv6_prefix.c @@ -353,7 +353,7 @@ const struct lyplg_type_record plugins_ipv6_prefix[] = { .revision = "2013-07-15", .name = "ipv6-prefix", - .plugin.id = "ly2 - ipv6-prefix", + .plugin.id = "ly2 ipv6-prefix", .plugin.store = lyplg_type_store_ipv6_prefix, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_ipv6_prefix, diff --git a/src/plugins_types/leafref.c b/src/plugins_types/leafref.c index 8de07dbdd..7a3961428 100644 --- a/src/plugins_types/leafref.c +++ b/src/plugins_types/leafref.c @@ -145,7 +145,7 @@ const struct lyplg_type_record plugins_leafref[] = { .revision = NULL, .name = LY_TYPE_LEAFREF_STR, - .plugin.id = "ly2 - leafref", + .plugin.id = "ly2 leafref", .plugin.store = lyplg_type_store_leafref, .plugin.validate = lyplg_type_validate_leafref, .plugin.compare = lyplg_type_compare_leafref, diff --git a/src/plugins_types/lyds_tree.c b/src/plugins_types/lyds_tree.c index 9dbe28e7b..04741432e 100644 --- a/src/plugins_types/lyds_tree.c +++ b/src/plugins_types/lyds_tree.c @@ -132,7 +132,7 @@ const struct lyplg_type_record plugins_lyds_tree[] = { .revision = NULL, .name = "lyds_tree", - .plugin.id = "ly2 - lyds_tree", + .plugin.id = "ly2 lyds_tree", .plugin.store = lyplg_type_store_lyds, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_lyds, diff --git a/src/plugins_types/node_instanceid.c b/src/plugins_types/node_instanceid.c index 34f5ff7fa..e7e720751 100644 --- a/src/plugins_types/node_instanceid.c +++ b/src/plugins_types/node_instanceid.c @@ -334,7 +334,7 @@ const struct lyplg_type_record plugins_node_instanceid[] = { .revision = "2012-02-22", .name = "node-instance-identifier", - .plugin.id = "ly2 - node-instance-identifier", + .plugin.id = "ly2 node-instance-identifier", .plugin.store = lyplg_type_store_node_instanceid, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, @@ -349,7 +349,7 @@ const struct lyplg_type_record plugins_node_instanceid[] = { .revision = "2018-02-14", .name = "node-instance-identifier", - .plugin.id = "ly2 - node-instance-identifier", + .plugin.id = "ly2 node-instance-identifier", .plugin.store = lyplg_type_store_node_instanceid, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, diff --git a/src/plugins_types/string.c b/src/plugins_types/string.c index c998aeec8..4d18cd92c 100644 --- a/src/plugins_types/string.c +++ b/src/plugins_types/string.c @@ -130,7 +130,7 @@ const struct lyplg_type_record plugins_string[] = { .revision = NULL, .name = LY_TYPE_STRING_STR, - .plugin.id = "ly2 - string", + .plugin.id = "ly2 string", .plugin.store = lyplg_type_store_string, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, diff --git a/src/plugins_types/time_period.c b/src/plugins_types/time_period.c index 4e76cf42a..98c47c12c 100644 --- a/src/plugins_types/time_period.c +++ b/src/plugins_types/time_period.c @@ -86,7 +86,7 @@ const struct lyplg_type_record plugins_time_period[] = { .revision = "2024-07-09", .name = "time-period", - .plugin.id = "ly2 - time-period", + .plugin.id = "ly2 time-period", .plugin.store = lyplg_type_store_string, .plugin.validate = NULL, .plugin.compare = lyplg_type_compare_simple, diff --git a/src/plugins_types/union.c b/src/plugins_types/union.c index 1fb3d8382..7fdb9770c 100644 --- a/src/plugins_types/union.c +++ b/src/plugins_types/union.c @@ -705,7 +705,7 @@ const struct lyplg_type_record plugins_union[] = { .revision = NULL, .name = LY_TYPE_UNION_STR, - .plugin.id = "ly2 - union", + .plugin.id = "ly2 union", .plugin.store = lyplg_type_store_union, .plugin.validate = lyplg_type_validate_union, .plugin.compare = lyplg_type_compare_union, diff --git a/src/plugins_types/xpath1.0.c b/src/plugins_types/xpath1.0.c index 8af4ede6a..4d77f95ae 100644 --- a/src/plugins_types/xpath1.0.c +++ b/src/plugins_types/xpath1.0.c @@ -524,7 +524,7 @@ const struct lyplg_type_record plugins_xpath10[] = { .revision = "2013-07-15", .name = "xpath1.0", - .plugin.id = "ly2 - xpath1.0", + .plugin.id = "ly2 xpath1.0", .plugin.store = lyplg_type_store_xpath10, .plugin.validate = lyplg_type_validate_xpath10, .plugin.compare = lyplg_type_compare_simple, diff --git a/tests/utests/extensions/test_metadata.c b/tests/utests/extensions/test_metadata.c index f526323ad..c3b58b2b1 100644 --- a/tests/utests/extensions/test_metadata.c +++ b/tests/utests/extensions/test_metadata.c @@ -52,7 +52,7 @@ test_yang(void **state) "import ietf-yang-metadata {prefix md;}" "md:annotation aa;}"; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 - metadata\": Missing mandatory keyword \"type\" as a child of \"md:annotation aa\".", + CHECK_LOG_CTX("Ext plugin \"ly2 metadata\": Missing mandatory keyword \"type\" as a child of \"md:annotation aa\".", "/aa:{extension='md:annotation'}/aa", 0); /* not allowed substatement */ @@ -89,7 +89,7 @@ test_yang(void **state) "import ietf-yang-metadata {prefix md;}" "md:annotation aa {type string;} md:annotation aa {type uint8;}}"; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 - metadata\": Extension md:annotation is instantiated multiple times.", + CHECK_LOG_CTX("Ext plugin \"ly2 metadata\": Extension md:annotation is instantiated multiple times.", "/aa:{extension='md:annotation'}/aa", 0); } @@ -130,7 +130,7 @@ test_yin(void **state) "\n" ""; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YIN, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 - metadata\": Missing mandatory keyword \"type\" as a child of \"md:annotation aa\".", + CHECK_LOG_CTX("Ext plugin \"ly2 metadata\": Missing mandatory keyword \"type\" as a child of \"md:annotation aa\".", "/aa:{extension='md:annotation'}/aa", 0); /* not allowed substatement */ @@ -189,7 +189,7 @@ test_yin(void **state) " \n" ""; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YIN, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 - metadata\": Extension md:annotation is instantiated multiple times.", + CHECK_LOG_CTX("Ext plugin \"ly2 metadata\": Extension md:annotation is instantiated multiple times.", "/aa:{extension='md:annotation'}/aa", 0); } diff --git a/tests/utests/extensions/test_nacm.c b/tests/utests/extensions/test_nacm.c index 44daf3bf0..9cbad1e3f 100644 --- a/tests/utests/extensions/test_nacm.c +++ b/tests/utests/extensions/test_nacm.c @@ -56,7 +56,7 @@ test_deny_all(void **state) "import ietf-netconf-acm {revision-date 2018-02-14; prefix nacm;}" "nacm:default-deny-all;}"; assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 - NACM\": " + CHECK_LOG_CTX("Ext plugin \"ly2 NACM\": " "Extension nacm:default-deny-all is allowed only in a data nodes, but it is placed in \"module\" statement.", "/b:{extension='nacm:default-deny-all'}", 0); @@ -65,7 +65,7 @@ test_deny_all(void **state) "import ietf-netconf-acm {revision-date 2018-02-14; prefix nacm;}" "leaf l { type string; nacm:default-deny-all; nacm:default-deny-write;}}"; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 - NACM\": " + CHECK_LOG_CTX("Ext plugin \"ly2 NACM\": " "Extension nacm:default-deny-write is mixed with nacm:default-deny-all.", "/aa:l/{extension='nacm:default-deny-all'}", 0); } @@ -98,7 +98,7 @@ test_deny_write(void **state) "import ietf-netconf-acm {revision-date 2018-02-14; prefix nacm;}" "notification notif {nacm:default-deny-write;}}"; assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 - NACM\": " + CHECK_LOG_CTX("Ext plugin \"ly2 NACM\": " "Extension nacm:default-deny-write is not allowed in notification statement.", "/b:notif/{extension='nacm:default-deny-write'}", 0); @@ -107,7 +107,7 @@ test_deny_write(void **state) "import ietf-netconf-acm {revision-date 2018-02-14; prefix nacm;}" "leaf l { type string; nacm:default-deny-write; nacm:default-deny-write;}}"; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 - NACM\": " + CHECK_LOG_CTX("Ext plugin \"ly2 NACM\": " "Extension nacm:default-deny-write is instantiated multiple times.", "/aa:l/{extension='nacm:default-deny-write'}", 0); } diff --git a/tests/utests/extensions/test_schema_mount.c b/tests/utests/extensions/test_schema_mount.c index e1c4fcbc9..75cfa88ed 100644 --- a/tests/utests/extensions/test_schema_mount.c +++ b/tests/utests/extensions/test_schema_mount.c @@ -73,7 +73,7 @@ test_schema(void **state) " }\n" "}\n"; assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": " + CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": " "Extension \"yangmnt:mount-point\" instance not allowed in YANG version 1 module.", "/sm:root/{extension='yangmnt:mount-point'}/root", 0); @@ -90,7 +90,7 @@ test_schema(void **state) " yangmnt:mount-point \"root\";\n" "}\n"; assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": " + CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": " "Extension \"yangmnt:mount-point\" instance allowed only in container or list statement.", "/sm:{extension='yangmnt:mount-point'}/root", 0); @@ -112,7 +112,7 @@ test_schema(void **state) " }\n" "}\n"; assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": " + CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": " "Extension \"yangmnt:mount-point\" instance allowed only in container or list statement.", "/sm:root/l/{extension='yangmnt:mount-point'}/root", 0); @@ -136,7 +136,7 @@ test_schema(void **state) " }\n" "}\n"; assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": " + CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": " "Multiple extension \"yangmnt:mount-point\" instances.", "/sm:l/{extension='yangmnt:mount-point'}/root", 0); @@ -196,7 +196,7 @@ test_parse_invalid(void **state) " " ""; CHECK_PARSE_LYD_PARAM(xml, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EINVAL, data); - CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": Failed to get extension data, no callback set.", + CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": Failed to get extension data, no callback set.", NULL, 0); json = @@ -213,7 +213,7 @@ test_parse_invalid(void **state) " }" "}"; CHECK_PARSE_LYD_PARAM(json, LYD_JSON, 0, LYD_VALIDATE_PRESENT, LY_EINVAL, data); - CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": Failed to get extension data, no callback set.", + CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": Failed to get extension data, no callback set.", NULL, 0); /* unknown data */ @@ -401,22 +401,22 @@ test_parse_invalid(void **state) " " ""); CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); - CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": Mandatory node \"type\" instance does not exist.", + CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": Mandatory node \"type\" instance does not exist.", "/ietf-interfaces:interfaces/interface[name='bu']", 0); CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); - CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": Mandatory node \"type\" instance does not exist.", + CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": Mandatory node \"type\" instance does not exist.", "/ietf-interfaces:interfaces/interface[name='bu']", 0); /* same validation fail in separate validation */ CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT | LYD_PARSE_ONLY, 0, LY_SUCCESS, data); assert_int_equal(LY_EVALID, lyd_validate_all(&data, NULL, LYD_VALIDATE_PRESENT, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": Mandatory node \"type\" instance does not exist.", + CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": Mandatory node \"type\" instance does not exist.", "/ietf-interfaces:interfaces/interface[name='bu']", 0); lyd_free_siblings(data); CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT | LYD_PARSE_ONLY, 0, LY_SUCCESS, data); assert_int_equal(LY_EVALID, lyd_validate_all(&data, NULL, LYD_VALIDATE_PRESENT, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": Mandatory node \"type\" instance does not exist.", + CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": Mandatory node \"type\" instance does not exist.", "/ietf-interfaces:interfaces/interface[name='bu']", 0); lyd_free_siblings(data); @@ -865,7 +865,7 @@ test_parse_shared(void **state) " \n" "\n"; CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); - CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": " + CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": " "Shared-schema yang-library content-id \"2\" differs from \"1\" used previously.", "/ietf-yang-library:yang-library/content-id", 0); @@ -1121,7 +1121,7 @@ test_parse_shared_parent_ref(void **state) "\n" "wrong-target-value\n"; CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); - CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": " + CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": " "Invalid leafref value \"target-value\" - no target instance \"/sm:target\" with the same value.", "/ietf-interfaces:interfaces/interface[name='bu']/sm:sm-name", 0); @@ -1146,7 +1146,7 @@ test_parse_shared_parent_ref(void **state) " \"sm:target\": \"wrong-target-value\"\n" "}\n"; CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data); - CHECK_LOG_CTX("Ext plugin \"ly2 - schema mount\": " + CHECK_LOG_CTX("Ext plugin \"ly2 schema mount\": " "Invalid leafref value \"target-value\" - no target instance \"/sm:target\" with the same value.", "/ietf-interfaces:interfaces/interface[name='bu']/sm:sm-name", 0); diff --git a/tests/utests/extensions/test_structure.c b/tests/utests/extensions/test_structure.c index d67c001dd..026f6e7db 100644 --- a/tests/utests/extensions/test_structure.c +++ b/tests/utests/extensions/test_structure.c @@ -154,7 +154,7 @@ test_schema_invalid(void **state) "import ietf-yang-structure-ext {prefix sx;}" "container b { sx:structure struct { container x { leaf x {type string;}}}}}"; UTEST_INVALID_MODULE(data, LYS_IN_YANG, NULL, LY_EVALID); - CHECK_LOG_CTX("Ext plugin \"ly2 - structure\": " + CHECK_LOG_CTX("Ext plugin \"ly2 structure\": " "Extension sx:structure must not be used as a non top-level statement in \"container\" statement.", "/a:b/{extension='sx:structure'}/struct", 0); @@ -170,7 +170,7 @@ test_schema_invalid(void **state) "sx:structure struct { container x { leaf x {type string;}}}" "sx:structure struct { container y { leaf y {type string;}}}}"; UTEST_INVALID_MODULE(data, LYS_IN_YANG, NULL, LY_EVALID); - CHECK_LOG_CTX("Ext plugin \"ly2 - structure\": Extension sx:structure is instantiated multiple times.", + CHECK_LOG_CTX("Ext plugin \"ly2 structure\": Extension sx:structure is instantiated multiple times.", "/a:{extension='sx:structure'}/struct", 0); data = "module a {yang-version 1.1; namespace urn:tests:extensions:structure:a; prefix self;" @@ -178,7 +178,7 @@ test_schema_invalid(void **state) "sx:structure struct { container x { leaf x {type string;}}}" "choice struct { container y { leaf y {type string;}}}}"; UTEST_INVALID_MODULE(data, LYS_IN_YANG, NULL, LY_EVALID); - CHECK_LOG_CTX("Ext plugin \"ly2 - structure\": Extension sx:structure collides with a choice with the same identifier.", + CHECK_LOG_CTX("Ext plugin \"ly2 structure\": Extension sx:structure collides with a choice with the same identifier.", "/a:{extension='sx:structure'}/struct", 0); /* augment-structure */ diff --git a/tests/utests/extensions/test_yangdata.c b/tests/utests/extensions/test_yangdata.c index 424789369..3977992da 100644 --- a/tests/utests/extensions/test_yangdata.c +++ b/tests/utests/extensions/test_yangdata.c @@ -117,7 +117,7 @@ test_schema(void **state) "}\n"; assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, &mod)); assert_null(mod->compiled->exts); - CHECK_LOG_CTX("Ext plugin \"ly2 - yang-data\": " + CHECK_LOG_CTX("Ext plugin \"ly2 yang-data\": " "Extension rc:yang-data is ignored since it appears as a non top-level statement in \"container\" statement.", "/b:b/{extension='rc:yang-data'}/template", 0); assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YANG_COMPILED, 0)); @@ -174,7 +174,7 @@ test_schema_invalid(void **state) "import ietf-restconf {revision-date 2017-01-26; prefix rc;}" "rc:yang-data template { choice x { leaf x {type string;}}}}"; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 - yang-data\": " + CHECK_LOG_CTX("Ext plugin \"ly2 yang-data\": " "Extension rc:yang-data is instantiated with leaf top level data node (inside a choice), " "but only a single container data node is allowed.", "/a:{extension='rc:yang-data'}/template", 0); @@ -182,7 +182,7 @@ test_schema_invalid(void **state) "import ietf-restconf {revision-date 2017-01-26; prefix rc;}" "rc:yang-data template { choice x { case x { container z {presence ppp;} leaf x {type string;}}}}}"; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 - yang-data\": " + CHECK_LOG_CTX("Ext plugin \"ly2 yang-data\": " "Extension rc:yang-data is instantiated with multiple top level data nodes (inside a single choice's case), " "but only a single container data node is allowed.", "/a:{extension='rc:yang-data'}/template", 0); @@ -190,7 +190,7 @@ test_schema_invalid(void **state) "import ietf-restconf {revision-date 2017-01-26; prefix rc;}" "rc:yang-data template { container x { leaf x {type string;}} container y { leaf y {type string;}}}}"; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 - yang-data\": " + CHECK_LOG_CTX("Ext plugin \"ly2 yang-data\": " "Extension rc:yang-data is instantiated with multiple top level data nodes, " "but only a single container data node is allowed.", "/a:{extension='rc:yang-data'}/template", 0); @@ -198,7 +198,7 @@ test_schema_invalid(void **state) "import ietf-restconf {revision-date 2017-01-26; prefix rc;}" "rc:yang-data template;}"; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 - yang-data\": " + CHECK_LOG_CTX("Ext plugin \"ly2 yang-data\": " "Extension rc:yang-data is instantiated without any top level data node, " "but exactly one container data node is expected.", "/a:{extension='rc:yang-data'}/template", 0); @@ -214,7 +214,7 @@ test_schema_invalid(void **state) "rc:yang-data template { container x { leaf x {type string;}}}" "rc:yang-data template { container y { leaf y {type string;}}}}"; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 - yang-data\": " + CHECK_LOG_CTX("Ext plugin \"ly2 yang-data\": " "Extension rc:yang-data is instantiated multiple times.", "/a:{extension='rc:yang-data'}/template", 0); data = "module a {yang-version 1.1; namespace urn:tests:extensions:yangdata:a; prefix self;" @@ -222,7 +222,7 @@ test_schema_invalid(void **state) "grouping t { leaf-list x {type string;}}" "rc:yang-data template { uses t;}}"; assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL)); - CHECK_LOG_CTX("Ext plugin \"ly2 - yang-data\": " + CHECK_LOG_CTX("Ext plugin \"ly2 yang-data\": " "Extension rc:yang-data is instantiated with leaf-list top level data node, " "but only a single container data node is allowed.", "/a:{extension='rc:yang-data'}/template", 0); } diff --git a/tests/utests/types/binary.c b/tests/utests/types/binary.c index 484ac4102..5e6bf8de0 100644 --- a/tests/utests/types/binary.c +++ b/tests/utests/types/binary.c @@ -63,7 +63,7 @@ test_plugin_store(void **state) lysc_type2 = ((struct lysc_node_leaf *)mod->compiled->data->next)->type; /* check proper type */ - assert_string_equal("ly2 - binary", type->id); + assert_string_equal("ly2 binary", type->id); /* check store XML double pad */ val = "YWhveQ=="; diff --git a/tests/utests/types/bits.c b/tests/utests/types/bits.c index 94595ee06..2b11989d9 100644 --- a/tests/utests/types/bits.c +++ b/tests/utests/types/bits.c @@ -814,7 +814,7 @@ test_plugin_store(void **state) lysc_type = ((struct lysc_node_leaf *)mod->compiled->data)->type; /* check proper type */ - assert_string_equal("ly2 - bits", type->id); + assert_string_equal("ly2 bits", type->id); /* check store */ diff --git a/tests/utests/types/int8.c b/tests/utests/types/int8.c index 8c5ce6bc1..8a9f2f4ca 100644 --- a/tests/utests/types/int8.c +++ b/tests/utests/types/int8.c @@ -1412,7 +1412,7 @@ test_plugin_store(void **state) lysc_type = ((struct lysc_node_leaf *)mod->compiled->data)->type; /* check proper type */ - assert_string_equal("ly2 - integers", type->id); + assert_string_equal("ly2 integers", type->id); /* check store * options = LY_TYPE_STORE_IMPLEMENT | LY_TYPE_STORE_DYNAMIC diff --git a/tests/utests/types/string.c b/tests/utests/types/string.c index c07f372f5..7c4742117 100644 --- a/tests/utests/types/string.c +++ b/tests/utests/types/string.c @@ -1073,7 +1073,7 @@ test_plugin_store(void **state) lysc_type = ((struct lysc_node_leaf *) mod->compiled->data)->type; /* check proper type */ - assert_string_equal("ly2 - string", type->id); + assert_string_equal("ly2 string", type->id); /* check store */ val_text = "20"; diff --git a/tests/utests/types/union.c b/tests/utests/types/union.c index 6131c1581..2649e0318 100644 --- a/tests/utests/types/union.c +++ b/tests/utests/types/union.c @@ -105,11 +105,11 @@ test_data_xml(void **state) TEST_ERROR_XML2("", "defs", "", "un1", "123456789012345678901", LY_EVALID); CHECK_LOG_CTX("Invalid union value \"123456789012345678901\" - no matching subtype found:\n" - " ly2 - leafref: Invalid type int8 value \"123456789012345678901\".\n" - " ly2 - leafref: Invalid type int64 value \"123456789012345678901\".\n" - " ly2 - identityref: Invalid identityref \"123456789012345678901\" value - identity not found in module \"defs\".\n" - " ly2 - instance-identifier: Invalid instance-identifier \"123456789012345678901\" value - syntax error.\n" - " ly2 - string: Unsatisfied length - string \"123456789012345678901\" length is not allowed.\n", + " ly2 leafref: Invalid type int8 value \"123456789012345678901\".\n" + " ly2 leafref: Invalid type int64 value \"123456789012345678901\".\n" + " ly2 identityref: Invalid identityref \"123456789012345678901\" value - identity not found in module \"defs\".\n" + " ly2 instance-identifier: Invalid instance-identifier \"123456789012345678901\" value - syntax error.\n" + " ly2 string: Unsatisfied length - string \"123456789012345678901\" length is not allowed.\n", "/defs:un1", 1); } @@ -294,8 +294,8 @@ test_validation(void **state) assert_int_equal(LY_SUCCESS, lyd_new_list(tree, NULL, "b", LYD_NEW_VAL_BIN, NULL, &uint_val, sizeof uint_val)); assert_int_equal(LY_EVALID, lyd_validate_all(&tree, NULL, LYD_VALIDATE_PRESENT, NULL)); CHECK_LOG_CTX("Invalid LYB union value - no matching subtype found:\n" - " ly2 - leafref: Invalid leafref value \"one\" - no target instance \"../../a/name\" with the same value.\n" - " ly2 - leafref: Invalid type uint32 value \"one\".\n", "/lref:test/community[name='test']/view", 0); + " ly2 leafref: Invalid leafref value \"one\" - no target instance \"../../a/name\" with the same value.\n" + " ly2 leafref: Invalid type uint32 value \"one\".\n", "/lref:test/community[name='test']/view", 0); lyd_free_all(tree); } From 3d552c6268e718a7320f062129400f5c63906632 Mon Sep 17 00:00:00 2001 From: roman Date: Fri, 24 Jan 2025 13:20:36 +0100 Subject: [PATCH 19/25] plugins UPDATE replace plg get fn call with macro Also replace plugin by plugin_ref --- src/log.c | 9 +-- src/parser_lyb.c | 5 +- src/plugins.c | 112 +++++++++++++++--------------- src/plugins_exts.h | 3 +- src/plugins_exts/nacm.c | 5 +- src/plugins_internal.h | 44 ++++++++++++ src/plugins_types.c | 4 +- src/plugins_types/leafref.c | 12 ++-- src/plugins_types/union.c | 28 ++++---- src/printer_context.c | 11 +-- src/printer_json.c | 3 +- src/printer_lyb.c | 3 +- src/printer_tree.c | 15 ++-- src/printer_xml.c | 5 +- src/printer_yang.c | 8 +-- src/schema_compile.c | 8 +-- src/schema_compile_amend.c | 7 +- src/schema_compile_node.c | 8 +-- src/tree_data.c | 10 +-- src/tree_data_common.c | 23 +++--- src/tree_data_free.c | 5 +- src/tree_data_hash.c | 5 +- src/tree_data_new.c | 8 +-- src/tree_data_sorted.c | 2 +- src/tree_schema.c | 8 +-- src/tree_schema.h | 26 +++---- src/tree_schema_free.c | 9 +-- src/validation.c | 13 ++-- src/xpath.c | 9 +-- tests/utests/basic/test_plugins.c | 4 +- tests/utests/types/binary.c | 2 +- tests/utests/types/bits.c | 2 +- tests/utests/types/int8.c | 6 +- tests/utests/types/string.c | 2 +- tests/utests/utests.h | 32 ++++----- 35 files changed, 259 insertions(+), 197 deletions(-) diff --git a/src/log.c b/src/log.c index 5fc558764..e5a90b94f 100644 --- a/src/log.c +++ b/src/log.c @@ -30,6 +30,7 @@ #include "in_internal.h" #include "ly_common.h" #include "plugins_exts.h" +#include "plugins_internal.h" #include "set.h" #include "tree_data.h" #include "tree_data_internal.h" @@ -885,7 +886,7 @@ lyplg_ext_parse_log(const struct lysp_ctx *pctx, const struct lysp_ext_instance ly_vlog_build_path_line(PARSER_CTX(pctx), &data_path, &schema_path, &line); va_start(ap, format); - ly_ext_log(PARSER_CTX(pctx), lysc_get_ext_plugin(ext->plugin)->id, level, err, data_path, schema_path, line, format, ap); + ly_ext_log(PARSER_CTX(pctx), LYSC_GET_EXT_PLG(ext->plugin_ref)->id, level, err, data_path, schema_path, line, format, ap); va_end(ap); } @@ -902,7 +903,7 @@ lyplg_ext_compile_log(const struct lysc_ctx *cctx, const struct lysc_ext_instanc } va_start(ap, format); - ly_ext_log(ext->module->ctx, lysc_get_ext_plugin(ext->def->plugin)->id, level, err, NULL, schema_path, 0, format, ap); + ly_ext_log(ext->module->ctx, LYSC_GET_EXT_PLG(ext->def->plugin_ref)->id, level, err, NULL, schema_path, 0, format, ap); va_end(ap); } @@ -919,7 +920,7 @@ lyplg_ext_compile_log_path(const char *path, const struct lysc_ext_instance *ext } va_start(ap, format); - ly_ext_log(ext->module->ctx, lysc_get_ext_plugin(ext->def->plugin)->id, level, err, NULL, schema_path, 0, format, ap); + ly_ext_log(ext->module->ctx, LYSC_GET_EXT_PLG(ext->def->plugin_ref)->id, level, err, NULL, schema_path, 0, format, ap); va_end(ap); } @@ -940,7 +941,7 @@ _lyplg_ext_compile_log_err(const struct ly_err_item *eitem, const struct lysc_ex } va_start(ap, ext); - ly_ext_log(ext->module->ctx, lysc_get_ext_plugin(ext->def->plugin)->id, eitem->level, eitem->err, + ly_ext_log(ext->module->ctx, LYSC_GET_EXT_PLG(ext->def->plugin_ref)->id, eitem->level, eitem->err, data_path, schema_path, eitem->line, "%s", ap); va_end(ap); } diff --git a/src/parser_lyb.c b/src/parser_lyb.c index 8d6e0f96e..d26ed4e9f 100644 --- a/src/parser_lyb.c +++ b/src/parser_lyb.c @@ -32,6 +32,7 @@ #include "parser_internal.h" #include "plugins_exts.h" #include "plugins_exts/metadata.h" +#include "plugins_internal.h" #include "set.h" #include "tree.h" #include "tree_data.h" @@ -267,9 +268,9 @@ lyb_read_term_value(const struct lysc_node_leaf *term, uint8_t **term_value, uin if (term->type->basetype == LY_TYPE_LEAFREF) { /* Leafref itself is ignored, the target is loaded directly. */ type_lf = (struct lysc_type_leafref *)term->type; - lyb_data_len = lysc_get_type_plugin(type_lf->realtype->plugin)->lyb_data_len; + lyb_data_len = LYSC_GET_TYPE_PLG(type_lf->realtype->plugin_ref)->lyb_data_len; } else { - lyb_data_len = lysc_get_type_plugin(term->type->plugin)->lyb_data_len; + lyb_data_len = LYSC_GET_TYPE_PLG(term->type->plugin_ref)->lyb_data_len; } if (lyb_data_len < 0) { diff --git a/src/plugins.c b/src/plugins.c index 45ed051a7..6cf44fcd8 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -108,7 +108,7 @@ static pthread_mutex_t plugins_guard = PTHREAD_MUTEX_INITIALIZER; * unloaded with the destroy of the last context. Therefore, to reload the list of plugins, all the contexts must be * destroyed and with the creation of a first new context after that, the plugins will be reloaded. */ -static uint32_t context_refcount = 0; +static uint32_t context_refcount; /** * @brief Record describing an implemented extension. @@ -127,51 +127,45 @@ struct lyplg_record { }; #ifndef STATIC -static struct ly_set plugins_handlers = {0}; +static struct ly_set plugins_handlers; #endif -static struct ly_set plugins_types = {0}; -static struct ly_set plugins_extensions = {0}; +struct ly_set ly_plugins_types; +struct ly_set ly_plugins_extensions; -/** - * @brief Get the plugin of the given @p type. - * - * @param[in] plugin_ref Reference to a plugin. Either an index of a built-in plugin (offset by +1) - * or a pointer to an external plugin. - * @param[in] type Type of the plugin to get. - * @param[in] plugins Array of the built-in plugins used in case @p plugin_ref is an index of a built-in plugin. - * @return Plugin of the given @p type or NULL if not found. - */ -static void * -lysc_get_plugin(uintptr_t plugin_ref, enum LYPLG type, const struct ly_set *plugins) +/* global counters for the number of static plugins */ +uint32_t ly_static_type_plugins_count; +uint32_t ly_static_ext_plugins_count; + +LIBYANG_API_DEF struct lyplg_type * +lysc_get_type_plugin(uintptr_t plugin_ref) { - /* plugin_ref is offset by +1, so 0 is invalid (NULL ptr equivalent) */ if (!plugin_ref) { return NULL; } - if (plugin_ref <= plugins->count) { - /* plugin is built-in, fetch it from the global list */ - if (type == LYPLG_EXTENSION) { - return &((struct lyplg_ext_record *)plugins->objs[plugin_ref - 1])->plugin; - } else { - return &((struct lyplg_type_record *)plugins->objs[plugin_ref - 1])->plugin; - } + if (plugin_ref <= ly_plugins_types.count) { + /* plugin is static, fetch it from the global list */ + return &((struct lyplg_type_record *)ly_plugins_types.objs[plugin_ref - 1])->plugin; } else { - /* plugin is external, return the pointer */ - return (void *)plugin_ref; + /* plugin is dynamic, return the pointer */ + return (struct lyplg_type *)plugin_ref; } } -LIBYANG_API_DEF struct lyplg_type * -lysc_get_type_plugin(uintptr_t plugin_ref) -{ - return lysc_get_plugin(plugin_ref, LYPLG_TYPE, &plugins_types); -} - LIBYANG_API_DEF struct lyplg_ext * lysc_get_ext_plugin(uintptr_t plugin_ref) { - return lysc_get_plugin(plugin_ref, LYPLG_EXTENSION, &plugins_extensions); + if (!plugin_ref) { + return NULL; + } + + if (plugin_ref <= ly_plugins_extensions.count) { + /* plugin is static, fetch it from the global list */ + return &((struct lyplg_ext_record *)ly_plugins_extensions.objs[plugin_ref - 1])->plugin; + } else { + /* plugin is dynamic, return the pointer */ + return (struct lyplg_ext *)plugin_ref; + } } /** @@ -190,9 +184,9 @@ plugins_iter(const struct ly_ctx *ctx, enum LYPLG type, uint32_t *index) assert(index); if (type == LYPLG_EXTENSION) { - plugins = ctx ? &ctx->plugins_extensions : &plugins_extensions; + plugins = ctx ? &ctx->plugins_extensions : &ly_plugins_extensions; } else { - plugins = ctx ? &ctx->plugins_types : &plugins_types; + plugins = ctx ? &ctx->plugins_types : &ly_plugins_types; } if (*index == plugins->count) { @@ -255,35 +249,37 @@ lyplg_record_find(const struct ly_ctx *ctx, enum LYPLG type, const char *module, * @param[in] module Module name of the plugin. * @param[in] revision Revision of the @p module. * @param[in] name Name of the plugin. - * @return Accessor to the callbacks plugin structure, use ::lysc_get_type_plugin() - * or ::lysc_get_ext_plugin() on the returned value to get the actual plugin. 0 if not found. + * @return Reference to the callbacks plugin structure. Use ::LYSC_GET_TYPE_PLG() + * or ::LYSC_GET_EXT_PLG() on the returned value to get the actual plugin. 0 if not found. */ static uintptr_t lyplg_plugin_find(const struct ly_ctx *ctx, enum LYPLG type, const char *module, const char *revision, const char *name) { struct lyplg_type_record *record = NULL; - uint32_t record_idx = 0; + uint32_t record_idx = 0, static_plugin_count; if (ctx) { /* try to find context specific plugin */ record = lyplg_record_find(ctx, type, module, revision, name, &record_idx); + if (record) { + /* plugin found in the context, hence it is dynamic so return the ptr to it */ + return (uintptr_t)&record->plugin; + } } - if (!record) { - /* try to find shared plugin */ - record = lyplg_record_find(NULL, type, module, revision, name, &record_idx); - } - + /* try to find shared plugin */ + record = lyplg_record_find(NULL, type, module, revision, name, &record_idx); if (!record) { /* not found */ return 0; } - if (!strncmp(record->plugin.id, "ly2 - ", 6)) { - /* internal plugin, return an index with an offset of +1 in order to keep 0 as an invalid index (a NULL ptr) */ + static_plugin_count = (type == LYPLG_TYPE) ? ly_static_type_plugins_count : ly_static_ext_plugins_count; + if (record_idx < static_plugin_count) { + /* static plugin, return an index with an offset of +1 in order to keep 0 as an invalid index (a NULL ptr) */ return record_idx + 1; } else { - /* external plugin, return the pointer */ + /* dynamic plugin, return the pointer to it */ return (uintptr_t)&record->plugin; } } @@ -324,7 +320,7 @@ plugins_insert(struct ly_ctx *ctx, enum LYPLG type, const void *recs) if (type == LYPLG_EXTENSION) { const struct lyplg_ext_record *rec = (const struct lyplg_ext_record *)recs; - plugins = ctx ? &ctx->plugins_extensions : &plugins_extensions; + plugins = ctx ? &ctx->plugins_extensions : &ly_plugins_extensions; for (uint32_t i = 0; rec[i].name; i++) { LY_CHECK_RET(ly_set_add(plugins, (void *)&rec[i], 0, NULL)); @@ -332,7 +328,7 @@ plugins_insert(struct ly_ctx *ctx, enum LYPLG type, const void *recs) } else { /* LYPLG_TYPE */ const struct lyplg_type_record *rec = (const struct lyplg_type_record *)recs; - plugins = ctx ? &ctx->plugins_types : &plugins_types; + plugins = ctx ? &ctx->plugins_types : &ly_plugins_types; for (uint32_t i = 0; rec[i].name; i++) { LY_CHECK_RET(ly_set_add(plugins, (void *)&rec[i], 0, NULL)); @@ -358,9 +354,10 @@ lyplg_clean_(void) return; } - ly_set_erase(&plugins_types, NULL); - ly_set_erase(&plugins_extensions, NULL); + ly_set_erase(&ly_plugins_types, NULL); + ly_set_erase(&ly_plugins_extensions, NULL); ly_set_erase(&plugins_handlers, lyplg_close_cb); + ly_static_type_plugins_count = ly_static_ext_plugins_count = 0; } #endif @@ -475,8 +472,8 @@ plugins_load_module(const char *pathname) } /* remember the current plugins lists for recovery */ - types_count = plugins_types.count; - extensions_count = plugins_extensions.count; + types_count = ly_plugins_types.count; + extensions_count = ly_plugins_extensions.count; /* type plugin */ ret = plugins_load(dlhandler, pathname, LYPLG_TYPE); @@ -496,11 +493,11 @@ plugins_load_module(const char *pathname) dlclose(dlhandler); /* revert changes in the lists */ - while (plugins_types.count > types_count) { - ly_set_rm_index(&plugins_types, plugins_types.count - 1, NULL); + while (ly_plugins_types.count > types_count) { + ly_set_rm_index(&ly_plugins_types, ly_plugins_types.count - 1, NULL); } - while (plugins_extensions.count > extensions_count) { - ly_set_rm_index(&plugins_extensions, plugins_extensions.count - 1, NULL); + while (ly_plugins_extensions.count > extensions_count) { + ly_set_rm_index(&ly_plugins_extensions, ly_plugins_extensions.count - 1, NULL); } return ret; @@ -619,6 +616,11 @@ lyplg_init(ly_bool builtin_type_plugins_only, ly_bool static_plugins_only) LY_CHECK_GOTO(ret = plugins_insert(NULL, LYPLG_EXTENSION, plugins_schema_mount), error); LY_CHECK_GOTO(ret = plugins_insert(NULL, LYPLG_EXTENSION, plugins_structure), error); + /* the global plugin sets contain only static plugins at this point, so assign to the counters here. + * the counters are used to determine whether a plugin is static or not */ + ly_static_type_plugins_count = ly_plugins_types.count; + ly_static_ext_plugins_count = ly_plugins_extensions.count; + #ifndef STATIC if (!static_plugins_only) { /* external types */ diff --git a/src/plugins_exts.h b/src/plugins_exts.h index 71fdee7a2..5d688700a 100644 --- a/src/plugins_exts.h +++ b/src/plugins_exts.h @@ -405,7 +405,8 @@ struct lysp_ext_instance { const char *argument; /**< optional value of the extension's argument */ LY_VALUE_FORMAT format; /**< prefix format of the extension name/argument (::LY_VALUE_XML is YIN format) */ void *prefix_data; /**< format-specific data for prefix resolution (see ly_resolve_prefix()) */ - uintptr_t plugin; /**< extension plugin, use ::lysc_get_ext_plugin() */ + uintptr_t plugin_ref; /**< reference to extension's manipulation callbacks plugin, + use ::lysc_get_ext_plugin() to get the plugin */ void *parent; /**< pointer to the parent statement holding the extension instance(s), use ::lysp_ext_instance#parent_stmt to access the value/structure */ diff --git a/src/plugins_exts/nacm.c b/src/plugins_exts/nacm.c index faa5c6a4d..45e34f844 100644 --- a/src/plugins_exts/nacm.c +++ b/src/plugins_exts/nacm.c @@ -20,6 +20,7 @@ #include "compat.h" #include "libyang.h" #include "plugins_exts.h" +#include "plugins_internal.h" struct nacm_dfs_arg { struct lysc_ext_instance *ext; @@ -101,11 +102,11 @@ nacm_parse(struct lysp_ctx *pctx, struct lysp_ext_instance *ext) return LY_ENOT; } - ext_plugin = lysc_get_ext_plugin(ext->plugin); + ext_plugin = LYSC_GET_EXT_PLG(ext->plugin_ref); /* check for duplication */ LY_ARRAY_FOR(parent->exts, u) { - parent_ext_plugin = lysc_get_ext_plugin(parent->exts[u].plugin); + parent_ext_plugin = LYSC_GET_EXT_PLG(parent->exts[u].plugin_ref); if ((&parent->exts[u] != ext) && parent_ext_plugin && !strcmp(parent_ext_plugin->id, ext_plugin->id)) { /* duplication of a NACM extension on a single node * We check for all NACM plugins since we want to catch even the situation that there is default-deny-all diff --git a/src/plugins_internal.h b/src/plugins_internal.h index 5520060f5..3ff7188f0 100644 --- a/src/plugins_internal.h +++ b/src/plugins_internal.h @@ -43,6 +43,50 @@ #define LY_TYPE_INT32_STR "32bit integer" /**< text representation of ::LY_TYPE_INT32 */ #define LY_TYPE_INT64_STR "64bit integer" /**< text representation of ::LY_TYPE_INT64 */ +/** + * @brief Shared (= not context specific) type plugins set. + */ +extern struct ly_set ly_plugins_types; + +/** + * @brief Shared (= not context specific) extension plugins set. + */ +extern struct ly_set ly_plugins_extensions; + +/** + * @brief Count of static type plugins. + */ +extern uint32_t ly_static_type_plugins_count; + +/** + * @brief Count of static extension plugins. + */ +extern uint32_t ly_static_ext_plugins_count; + +/** + * @brief Get a type plugin. + * + * @param[in] PLUGIN_REF Reference to a plugin. Either an index of a static plugin (offset by +1) + * or a pointer to an external plugin. + * @return Type plugin. + */ +#define LYSC_GET_TYPE_PLG(PLUGIN_REF) \ + (((uintptr_t)(PLUGIN_REF) <= (uintptr_t)ly_static_type_plugins_count) ? \ + (struct lyplg_type *)&((struct lyplg_type_record *)ly_plugins_types.objs[(PLUGIN_REF) - 1])->plugin : \ + (struct lyplg_type *)(PLUGIN_REF)) + +/** + * @brief Get an extension plugin. + * + * @param[in] PLUGIN_REF Reference to a plugin. Either an index of a static plugin (offset by +1) + * or a pointer to an external plugin. + * @return Extension plugin. + */ +#define LYSC_GET_EXT_PLG(PLUGIN_REF) \ + (((uintptr_t)(PLUGIN_REF) <= (uintptr_t)ly_static_ext_plugins_count) ? \ + (struct lyplg_ext *)&((struct lyplg_ext_record *)ly_plugins_extensions.objs[(PLUGIN_REF) - 1])->plugin : \ + (struct lyplg_ext *)(PLUGIN_REF)) + /** * @brief Initiate libyang plugins. * diff --git a/src/plugins_types.c b/src/plugins_types.c index 56cac666d..31f3da196 100644 --- a/src/plugins_types.c +++ b/src/plugins_types.c @@ -903,7 +903,7 @@ lyplg_type_print_val(const struct lysc_node *node, const char *canon, LY_VALUE_F struct lyplg_type *type_plugin; type = ((struct lysc_node_leaf *)node)->type; - type_plugin = lysc_get_type_plugin(type->plugin); + type_plugin = LYSC_GET_TYPE_PLG(type->plugin_ref); /* store the value */ r = type_plugin->store(node->module->ctx, type, canon, strlen(canon), LYPLG_TYPE_STORE_ONLY, LY_VALUE_CANON, @@ -1099,7 +1099,7 @@ lyplg_type_resolve_leafref(const struct lysc_type_leafref *lref, const struct ly goto cleanup; } - type = lysc_get_type_plugin(lref->plugin); + type = LYSC_GET_TYPE_PLG(lref->plugin_ref); /* check the result */ if (target_path) { diff --git a/src/plugins_types/leafref.c b/src/plugins_types/leafref.c index 7a3961428..deb8cc424 100644 --- a/src/plugins_types/leafref.c +++ b/src/plugins_types/leafref.c @@ -47,7 +47,7 @@ lyplg_type_store_leafref(const struct ly_ctx *ctx, const struct lysc_type *type, assert(type_lr->realtype); /* store the value as the real type of the leafref target */ - rc = lysc_get_type_plugin(type_lr->realtype->plugin)->store(ctx, type_lr->realtype, value, value_len, options, + rc = LYSC_GET_TYPE_PLG(type_lr->realtype->plugin_ref)->store(ctx, type_lr->realtype, value, value_len, options, format, prefix_data, hints, ctx_node, storage, unres, err); if (rc == LY_EINCOMPLETE) { /* it is irrelevant whether the target type needs some resolving */ @@ -104,32 +104,32 @@ lyplg_type_validate_leafref(const struct ly_ctx *ctx, const struct lysc_type *ty LIBYANG_API_DEF LY_ERR lyplg_type_compare_leafref(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2) { - return lysc_get_type_plugin(val1->realtype->plugin)->compare(ctx, val1, val2); + return LYSC_GET_TYPE_PLG(val1->realtype->plugin_ref)->compare(ctx, val1, val2); } LIBYANG_API_DEF int lyplg_type_sort_leafref(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2) { - return lysc_get_type_plugin(val1->realtype->plugin)->sort(ctx, val1, val2); + return LYSC_GET_TYPE_PLG(val1->realtype->plugin_ref)->sort(ctx, val1, val2); } LIBYANG_API_DEF const void * lyplg_type_print_leafref(const struct ly_ctx *ctx, const struct lyd_value *value, LY_VALUE_FORMAT format, void *prefix_data, ly_bool *dynamic, size_t *value_len) { - return lysc_get_type_plugin(value->realtype->plugin)->print(ctx, value, format, prefix_data, dynamic, value_len); + return LYSC_GET_TYPE_PLG(value->realtype->plugin_ref)->print(ctx, value, format, prefix_data, dynamic, value_len); } LIBYANG_API_DEF LY_ERR lyplg_type_dup_leafref(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup) { - return lysc_get_type_plugin(original->realtype->plugin)->duplicate(ctx, original, dup); + return LYSC_GET_TYPE_PLG(original->realtype->plugin_ref)->duplicate(ctx, original, dup); } LIBYANG_API_DEF void lyplg_type_free_leafref(const struct ly_ctx *ctx, struct lyd_value *value) { - lysc_get_type_plugin(value->realtype->plugin)->free(ctx, value); + LYSC_GET_TYPE_PLG(value->realtype->plugin_ref)->free(ctx, value); } /** diff --git a/src/plugins_types/union.c b/src/plugins_types/union.c index 7fdb9770c..4c33b3718 100644 --- a/src/plugins_types/union.c +++ b/src/plugins_types/union.c @@ -186,7 +186,7 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3 lyb_parse_union(subvalue->original, subvalue->orig_len, &ti, &value, &value_len); if (ti != type_idx) { /* value of another type, first store the value properly and then use its JSON value for parsing */ - rc = lysc_get_type_plugin(type_u->types[ti]->plugin)->store(ctx, type_u->types[ti], value, value_len, + rc = LYSC_GET_TYPE_PLG(type_u->types[ti]->plugin_ref)->store(ctx, type_u->types[ti], value, value_len, LYPLG_TYPE_STORE_ONLY, subvalue->format, subvalue->prefix_data, subvalue->hints, subvalue->ctx_node, &subvalue->value, unres, err); if ((rc != LY_SUCCESS) && (rc != LY_EINCOMPLETE)) { @@ -196,7 +196,7 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3 } assert(subvalue->value.realtype); - value = lysc_get_type_plugin(subvalue->value.realtype->plugin)->print(ctx, &subvalue->value, + value = LYSC_GET_TYPE_PLG(subvalue->value.realtype->plugin_ref)->print(ctx, &subvalue->value, LY_VALUE_JSON, NULL, &dynamic, &value_len); /* to avoid leaks, free subvalue->value, but we need the value, which may be stored there */ @@ -204,7 +204,7 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3 value = strndup(value, value_len); dynamic = 1; } - lysc_get_type_plugin(type_u->types[ti]->plugin)->free(ctx, &subvalue->value); + LYSC_GET_TYPE_PLG(type_u->types[ti]->plugin_ref)->free(ctx, &subvalue->value); format = LY_VALUE_JSON; prefix_data = NULL; @@ -226,7 +226,7 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3 opts |= LYPLG_TYPE_STORE_DYNAMIC; } - type_plugin = lysc_get_type_plugin(type->plugin); + type_plugin = LYSC_GET_TYPE_PLG(type->plugin_ref); rc = type_plugin->store(ctx, type, value, value_len, opts, format, prefix_data, subvalue->hints, subvalue->ctx_node, &subvalue->value, unres, err); @@ -312,7 +312,7 @@ union_find_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct continue; } - type = lysc_get_type_plugin(type_u->types[u]->plugin); + type = LYSC_GET_TYPE_PLG(type_u->types[u]->plugin_ref); msg = ly_realloc(msg, msg_len + 4 + strlen(type->id) + 2 + strlen(errs[u]->msg) + 2); LY_CHECK_ERR_GOTO(!msg, ret = LY_EMEM, cleanup); @@ -458,7 +458,7 @@ lyplg_type_validate_union(const struct ly_ctx *ctx, const struct lysc_type *type /* because of types that do not store their own type as realtype (leafref), we are not able to call their * validate callback (there is no way to get the type) but even if possible, the value may be invalid * for the type, so we may have to perform union value storing again from scratch, but keep a value backup */ - subvalue_type = lysc_get_type_plugin(subvalue->value.realtype->plugin); + subvalue_type = LYSC_GET_TYPE_PLG(subvalue->value.realtype->plugin_ref); LY_CHECK_RET(subvalue_type->duplicate(ctx, &subvalue->value, &orig)); subvalue_type->free(ctx, &subvalue->value); @@ -490,7 +490,7 @@ lyplg_type_validate_union(const struct ly_ctx *ctx, const struct lysc_type *type LY_CHECK_RET(lydict_insert(ctx, subvalue->value._canonical, 0, &storage->_canonical)); /* free backup value */ - lysc_get_type_plugin(orig.realtype->plugin)->free(ctx, &orig); + LYSC_GET_TYPE_PLG(orig.realtype->plugin_ref)->free(ctx, &orig); return LY_SUCCESS; } @@ -500,7 +500,7 @@ lyplg_type_compare_union(const struct ly_ctx *ctx, const struct lyd_value *val1, if (val1->subvalue->value.realtype != val2->subvalue->value.realtype) { return LY_ENOT; } - return lysc_get_type_plugin(val1->subvalue->value.realtype->plugin)->compare(ctx, + return LYSC_GET_TYPE_PLG(val1->subvalue->value.realtype->plugin_ref)->compare(ctx, &val1->subvalue->value, &val2->subvalue->value); } @@ -512,7 +512,7 @@ lyplg_type_sort_union(const struct ly_ctx *ctx, const struct lyd_value *val1, co struct lysc_type **types; if (val1->subvalue->value.realtype == val2->subvalue->value.realtype) { - return lysc_get_type_plugin(val1->subvalue->value.realtype->plugin)->sort(ctx, + return LYSC_GET_TYPE_PLG(val1->subvalue->value.realtype->plugin_ref)->sort(ctx, &val1->subvalue->value, &val2->subvalue->value); } @@ -565,13 +565,13 @@ lyb_union_print(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct assert(subvalue->ctx_node); ctx = subvalue->ctx_node->module->ctx; } - lysc_get_type_plugin(subvalue->value.realtype->plugin)->free(ctx, &subvalue->value); + LYSC_GET_TYPE_PLG(subvalue->value.realtype->plugin_ref)->free(ctx, &subvalue->value); r = union_find_type(ctx, type_u, subvalue, 0, 0, NULL, NULL, &type_idx, NULL, &err); ly_err_free(err); LY_CHECK_RET((r != LY_SUCCESS) && (r != LY_EINCOMPLETE), NULL); /* Print subvalue in LYB format. */ - pval = (void *)lysc_get_type_plugin(subvalue->value.realtype->plugin)->print(NULL, &subvalue->value, LY_VALUE_LYB, + pval = (void *)LYSC_GET_TYPE_PLG(subvalue->value.realtype->plugin_ref)->print(NULL, &subvalue->value, LY_VALUE_LYB, prefix_data, &dynamic, &pval_len); LY_CHECK_RET(!pval, NULL); @@ -620,7 +620,7 @@ lyplg_type_print_union(const struct ly_ctx *ctx, const struct lyd_value *value, } assert(format != LY_VALUE_LYB); - type = lysc_get_type_plugin(subvalue->value.realtype->plugin); + type = LYSC_GET_TYPE_PLG(subvalue->value.realtype->plugin_ref); ret = (void *)type->print(ctx, &subvalue->value, format, prefix_data, dynamic, value_len); if (!value->_canonical && (format == LY_VALUE_CANON)) { /* the canonical value is supposed to be stored now */ @@ -647,7 +647,7 @@ lyplg_type_dup_union(const struct ly_ctx *ctx, const struct lyd_value *original, LY_CHECK_ERR_GOTO(!dup_val, LOGMEM(ctx); ret = LY_EMEM, cleanup); dup->subvalue = dup_val; - ret = lysc_get_type_plugin(orig_val->value.realtype->plugin)->duplicate(ctx, &orig_val->value, &dup_val->value); + ret = LYSC_GET_TYPE_PLG(orig_val->value.realtype->plugin_ref)->duplicate(ctx, &orig_val->value, &dup_val->value); LY_CHECK_GOTO(ret, cleanup); if (orig_val->orig_len) { @@ -683,7 +683,7 @@ lyplg_type_free_union(const struct ly_ctx *ctx, struct lyd_value *value) LYD_VALUE_GET(value, val); if (val) { if (val->value.realtype) { - lysc_get_type_plugin(val->value.realtype->plugin)->free(ctx, &val->value); + LYSC_GET_TYPE_PLG(val->value.realtype->plugin_ref)->free(ctx, &val->value); } lyplg_type_prefix_data_free(val->format, val->prefix_data); free(val->original); diff --git a/src/printer_context.c b/src/printer_context.c index a159c9f9e..79083c71f 100644 --- a/src/printer_context.c +++ b/src/printer_context.c @@ -22,6 +22,7 @@ #include "log.h" #include "ly_common.h" #include "plugins_exts.h" +#include "plugins_internal.h" #include "tree_schema_internal.h" #include "xpath.h" @@ -124,7 +125,7 @@ ctxs_exts(const struct lysc_ext_instance *exts, struct ly_ht *ht, int *size) *size += CTXS_SIZED_ARRAY(exts[u].substmts); /* compiled, substmts storage */ - ext = lysc_get_ext_plugin(exts[u].def->plugin); + ext = LYSC_GET_EXT_PLG(exts[u].def->plugin_ref); if (ext && ext->compiled_size) { *size += ext->compiled_size(&exts[u], ht); } @@ -821,8 +822,8 @@ ctxp_ext(const struct lysc_ext_instance *orig_ext, struct lysc_ext_instance *ext } /* compiled, substmts storage, use the plugin */ - if (ext->def->plugin && lysc_get_ext_plugin(ext->def->plugin)->compiled_print) { - lysc_get_ext_plugin(ext->def->plugin)->compiled_print(orig_ext, ext, addr_ht, ptr_set, mem); + if (ext->def->plugin_ref && LYSC_GET_EXT_PLG(ext->def->plugin_ref)->compiled_print) { + LYSC_GET_EXT_PLG(ext->def->plugin_ref)->compiled_print(orig_ext, ext, addr_ht, ptr_set, mem); } else { ext->compiled = NULL; } @@ -1281,7 +1282,7 @@ ctxp_type(const struct lysc_type *orig_type, struct lysc_type **type, struct ly_ } /* static structures in the shared library */ - t->plugin = orig_type->plugin; + t->plugin_ref = orig_type->plugin_ref; t->basetype = orig_type->basetype; t->refcount = orig_type->refcount; @@ -1624,7 +1625,7 @@ ctxp_extension(const struct lysc_ext *orig_extension, struct lysc_ext *extension } /* static structures in the shared library */ - extension->plugin = orig_extension->plugin; + extension->plugin_ref = orig_extension->plugin_ref; extension->module = ly_ctx_compiled_addr_ht_get(addr_ht, orig_extension->module, 0); extension->flags = orig_extension->flags; diff --git a/src/printer_json.c b/src/printer_json.c index d7f6e909f..df700394d 100644 --- a/src/printer_json.c +++ b/src/printer_json.c @@ -25,6 +25,7 @@ #include "out_internal.h" #include "parser_data.h" #include "plugins_exts/metadata.h" +#include "plugins_internal.h" #include "plugins_types.h" #include "printer_data.h" #include "printer_internal.h" @@ -354,7 +355,7 @@ json_print_value(struct jsonpr_ctx *pctx, const struct ly_ctx *ctx, const struct LY_DATA_TYPE basetype; const char *value; - value = lysc_get_type_plugin(val->realtype->plugin)->print(ctx, val, LY_VALUE_JSON, (void *)local_mod, &dynamic, NULL); + value = LYSC_GET_TYPE_PLG(val->realtype->plugin_ref)->print(ctx, val, LY_VALUE_JSON, (void *)local_mod, &dynamic, NULL); LY_CHECK_RET(!value, LY_EINVAL); basetype = val->realtype->basetype; diff --git a/src/printer_lyb.c b/src/printer_lyb.c index 95094b86c..5a1fe1b23 100644 --- a/src/printer_lyb.c +++ b/src/printer_lyb.c @@ -28,6 +28,7 @@ #include "out.h" #include "out_internal.h" #include "plugins_exts/metadata.h" +#include "plugins_internal.h" #include "printer_data.h" #include "printer_internal.h" #include "set.h" @@ -680,7 +681,7 @@ lyb_print_term_value(struct lyd_node_term *term, struct ly_out *out, struct lyly lyplg_type_print_clb print; struct lyplg_type *type; - assert(term->value.realtype && (type = lysc_get_type_plugin(term->value.realtype->plugin)) && + assert(term->value.realtype && (type = LYSC_GET_TYPE_PLG(term->value.realtype->plugin_ref)) && type->print && term->schema); /* Get length of LYB data to print. */ diff --git a/src/printer_tree.c b/src/printer_tree.c index d177373cd..7a74dda6b 100644 --- a/src/printer_tree.c +++ b/src/printer_tree.c @@ -94,6 +94,7 @@ #include "ly_common.h" #include "out_internal.h" #include "plugins_exts.h" +#include "plugins_internal.h" #include "plugins_types.h" #include "printer_internal.h" #include "printer_schema.h" @@ -1861,7 +1862,7 @@ trp_ext_is_present(ly_bool lysc_tree, const void *node) if (lysc_tree) { cn = (const struct lysc_node *)node; LY_ARRAY_FOR(cn->exts, i) { - if (!cn->exts[i].def->plugin || !lysc_get_ext_plugin(cn->exts[i].def->plugin)->printer_ctree) { + if (!cn->exts[i].def->plugin_ref || !LYSC_GET_EXT_PLG(cn->exts[i].def->plugin_ref)->printer_ctree) { continue; } if (!trp_ext_parent_is_valid(1, &cn->exts[i])) { @@ -1873,7 +1874,7 @@ trp_ext_is_present(ly_bool lysc_tree, const void *node) } else { pn = (const struct lysp_node *)node; LY_ARRAY_FOR(pn->exts, i) { - if (!pn->exts[i].plugin || !lysc_get_ext_plugin(pn->exts[i].plugin)->printer_ptree) { + if (!pn->exts[i].plugin_ref || !LYSC_GET_EXT_PLG(pn->exts[i].plugin_ref)->printer_ptree) { continue; } if (!trp_ext_parent_is_valid(0, &pn->exts[i])) { @@ -2162,9 +2163,9 @@ tro_set_node_overr(ly_bool lysc_tree, const void *node, ly_bool erase_node_overr } no = &plc->node_overr; if (!plc->ctx && lysc_tree && (ce = trp_ext_is_present(lysc_tree, node))) { - rc = lysc_get_ext_plugin(ce->def->plugin)->printer_ctree(ce, NULL, &no->flags, &no->add_opts); + rc = LYSC_GET_EXT_PLG(ce->def->plugin_ref)->printer_ctree(ce, NULL, &no->flags, &no->add_opts); } else if (!plc->ctx && (pe = trp_ext_is_present(lysc_tree, node))) { - rc = lysc_get_ext_plugin(pe->plugin)->printer_ptree(pe, NULL, &no->flags, &no->add_opts); + rc = LYSC_GET_EXT_PLG(pe->plugin_ref)->printer_ptree(pe, NULL, &no->flags, &no->add_opts); } else if (plc->ctx) { if (plc->schema && plc->schema->compiled && plc->schema->cn_overr) { rc = plc->schema->cn_overr(node, plc->ctx->plugin_priv, &plc->filtered, &no->flags, &no->add_opts); @@ -3799,7 +3800,7 @@ trb_ext_iter_next(ly_bool lysc_tree, void *exts, LY_ARRAY_COUNT_TYPE *i) if (lysc_tree) { ce = exts; while (*i < LY_ARRAY_COUNT(ce)) { - if (ce->def->plugin && trp_ext_parent_is_valid(1, &ce[*i])) { + if (ce->def->plugin_ref && trp_ext_parent_is_valid(1, &ce[*i])) { ext = &ce[*i]; break; } @@ -3873,7 +3874,7 @@ tro_ext_printer_tree(ly_bool compiled, void *ext, const struct lyspr_tree_ctx *p if (compiled) { ext_comp = ext; - plugin = lysc_get_ext_plugin(ext_comp->def->plugin); + plugin = LYSC_GET_EXT_PLG(ext_comp->def->plugin_ref); if (!plugin->printer_ctree) { *ignore = 1; return LY_SUCCESS; @@ -3881,7 +3882,7 @@ tro_ext_printer_tree(ly_bool compiled, void *ext, const struct lyspr_tree_ctx *p return plugin->printer_ctree(ext, plug_ctx, &flags, &add_opts); } else { ext_pars = ext; - plugin = lysc_get_ext_plugin(ext_pars->plugin); + plugin = LYSC_GET_EXT_PLG(ext_pars->plugin_ref); if (!plugin->printer_ptree) { *ignore = 1; return LY_SUCCESS; diff --git a/src/printer_xml.c b/src/printer_xml.c index 0907bb948..e8fb4dbc8 100644 --- a/src/printer_xml.c +++ b/src/printer_xml.c @@ -26,6 +26,7 @@ #include "out_internal.h" #include "parser_data.h" #include "plugins_exts/metadata.h" +#include "plugins_internal.h" #include "plugins_types.h" #include "printer_data.h" #include "printer_internal.h" @@ -217,7 +218,7 @@ xml_print_meta(struct xmlpr_ctx *pctx, const struct lyd_node *node) ly_set_add(&ns_list, NULL, 0, NULL); /* print the value */ - value = lysc_get_type_plugin(meta->value.realtype->plugin)->print(LYD_CTX(node), + value = LYSC_GET_TYPE_PLG(meta->value.realtype->plugin_ref)->print(LYD_CTX(node), &meta->value, LY_VALUE_XML, &ns_list, &dynamic, NULL); /* print namespaces connected with the value's prefixes */ @@ -340,7 +341,7 @@ xml_print_term(struct xmlpr_ctx *pctx, const struct lyd_node_term *node) } /* print the value */ - value = lysc_get_type_plugin(((struct lysc_node_leaf *)node->schema)->type->plugin)->print(LYD_CTX(node), + value = LYSC_GET_TYPE_PLG(((struct lysc_node_leaf *)node->schema)->type->plugin_ref)->print(LYD_CTX(node), &node->value, LY_VALUE_XML, &ns_list, &dynamic, NULL); LY_CHECK_ERR_GOTO(!value, rc = LY_EINVAL, cleanup); diff --git a/src/printer_yang.c b/src/printer_yang.c index 8fcc3d482..bc195f1d0 100644 --- a/src/printer_yang.c +++ b/src/printer_yang.c @@ -29,6 +29,7 @@ #include "out.h" #include "out_internal.h" #include "plugins_exts.h" +#include "plugins_internal.h" #include "plugins_types.h" #include "printer_internal.h" #include "printer_schema.h" @@ -356,7 +357,7 @@ yprc_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t { LY_ARRAY_COUNT_TYPE u; ly_bool inner_flag; - struct lyplg_ext *ext; + struct lyplg_ext *ext_plg; LY_ARRAY_FOR(exts, u) { if ((exts[u].parent_stmt != substmt) || (exts[u].parent_stmt_index != substmt_index)) { @@ -376,9 +377,8 @@ yprc_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t inner_flag = 0; yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0, exts[u].exts, &inner_flag); - ext = lysc_get_ext_plugin(exts[u].def->plugin); - if (ext && ext->printer_info) { - ext->printer_info(&pctx->printer_ctx, &exts[u], &inner_flag); + if (exts[u].def->plugin_ref && (ext_plg = LYSC_GET_EXT_PLG(exts[u].def->plugin_ref))->printer_info) { + ext_plg->printer_info(&pctx->printer_ctx, &exts[u], &inner_flag); } LEVEL--; diff --git a/src/schema_compile.c b/src/schema_compile.c index 70d7ee236..b14adcac3 100644 --- a/src/schema_compile.c +++ b/src/schema_compile.c @@ -132,11 +132,11 @@ lys_compile_ext(struct lysc_ctx *ctx, struct lysp_ext_instance *extp, struct lys COMPILE_EXTS_GOTO(ctx, extp->exts, ext->exts, ext, ret, cleanup); /* compile this extension */ - if (ext->def->plugin && lysc_get_ext_plugin(ext->def->plugin)->compile) { + if (ext->def->plugin_ref && LYSC_GET_EXT_PLG(ext->def->plugin_ref)->compile) { if (ext->argument) { lysc_update_path(ctx, ext->module, ext->argument); } - ret = lysc_get_ext_plugin(ext->def->plugin)->compile(ctx, extp, ext); + ret = LYSC_GET_EXT_PLG(ext->def->plugin_ref)->compile(ctx, extp, ext); if (ret == LY_ENOT) { lysc_ext_instance_free(ctx->ctx, ext); } @@ -899,7 +899,7 @@ lys_compile_unres_dflt(struct lysc_ctx *ctx, struct lysc_node *node, struct lysc struct lyplg_type *type_plugin; options = (ctx->ctx->opts & LY_CTX_REF_IMPLEMENTED) ? LYPLG_TYPE_STORE_IMPLEMENT : 0; - type_plugin = lysc_get_type_plugin(type->plugin); + type_plugin = LYSC_GET_TYPE_PLG(type->plugin_ref); rc = type_plugin->store(ctx->ctx, type, dflt, strlen(dflt), options, LY_VALUE_SCHEMA, (void *)dflt_pmod, LYD_HINT_SCHEMA, node, &storage, unres, &err); if (rc == LY_ERECOMPILE) { @@ -1816,7 +1816,7 @@ lys_compile_extensions(struct lys_module *mod) DUP_STRING_GOTO(ctx.ctx, ep->name, ec->name, rc, cleanup); DUP_STRING_GOTO(ctx.ctx, ep->argname, ec->argname, rc, cleanup); ec->module = mod; - ec->plugin = ep->plugin; + ec->plugin_ref = ep->plugin_ref; LY_ARRAY_INCREMENT(mod->extensions); } diff --git a/src/schema_compile_amend.c b/src/schema_compile_amend.c index 81257ea3c..ab802c3c0 100644 --- a/src/schema_compile_amend.c +++ b/src/schema_compile_amend.c @@ -26,6 +26,7 @@ #include "dict.h" #include "log.h" #include "ly_common.h" +#include "plugins_internal.h" #include "schema_compile.h" #include "schema_compile_node.h" #include "schema_features.h" @@ -477,7 +478,7 @@ lysp_ext_dup(const struct ly_ctx *ctx, const struct lysp_module *pmod, void *par DUP_STRING_GOTO(ctx, orig_ext->argument, ext->argument, ret, cleanup); ext->format = orig_ext->format; LY_CHECK_GOTO(ret = ly_dup_prefix_data(ctx, orig_ext->format, orig_ext->prefix_data, &ext->prefix_data), cleanup); - ext->plugin = orig_ext->plugin; + ext->plugin_ref = orig_ext->plugin_ref; ext->parent = parent; ext->parent_stmt = parent_stmt; @@ -485,10 +486,10 @@ lysp_ext_dup(const struct ly_ctx *ctx, const struct lysp_module *pmod, void *par ext->flags = orig_ext->flags; LY_CHECK_GOTO(ret = lysp_ext_children_dup(ctx, orig_ext->child, &ext->child), cleanup); - if (ext->plugin && lysc_get_ext_plugin(ext->plugin)->parse) { + if (ext->plugin_ref && LYSC_GET_EXT_PLG(ext->plugin_ref)->parse) { /* parse again */ LY_CHECK_GOTO(ret = ly_set_add(&pmods, pmod, 1, NULL), cleanup); - LY_CHECK_GOTO(ret = lysc_get_ext_plugin(ext->plugin)->parse(&pctx, ext), cleanup); + LY_CHECK_GOTO(ret = LYSC_GET_EXT_PLG(ext->plugin_ref)->parse(&pctx, ext), cleanup); } cleanup: diff --git a/src/schema_compile_node.c b/src/schema_compile_node.c index 7c67e408e..4ab25ba7c 100644 --- a/src/schema_compile_node.c +++ b/src/schema_compile_node.c @@ -1794,7 +1794,7 @@ lys_compile_type_(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_ LY_CHECK_GOTO(rc, cleanup); (*type)->basetype = basetype; - (*type)->plugin = plugin_ref; + (*type)->plugin_ref = plugin_ref; switch (basetype) { case LY_TYPE_BINARY: @@ -2267,7 +2267,7 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t plugin_ref = lyplg_type_plugin_find(ctx->ctx, tctx->tpdf->type.pmod->mod->name, tctx->tpdf->type.pmod->mod->revision, tctx->tpdf->name); if (!plugin_ref && base) { - plugin_ref = base->plugin; + plugin_ref = base->plugin_ref; } if (!plugin_ref) { /* use the internal built-in type implementation */ @@ -2276,7 +2276,7 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t assert(plugin_ref); if ((basetype != LY_TYPE_LEAFREF) && (u != tpdf_chain.count - 1) && !tctx->tpdf->type.flags && - !tctx->tpdf->type.exts && (plugin_ref == base->plugin)) { + !tctx->tpdf->type.exts && (plugin_ref == base->plugin_ref)) { /* no change, reuse the compiled base */ ((struct lysp_tpdf *)tctx->tpdf)->type.compiled = base; LY_ATOMIC_INC_BARRIER(base->refcount); @@ -2329,7 +2329,7 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t if (type_p->flags || type_p->exts || !base || has_leafref) { /* leaf type has changes that need to be compiled into the type */ if (base) { - plugin_ref = base->plugin; + plugin_ref = base->plugin_ref; } else { plugin_ref = lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype]); } diff --git a/src/tree_data.c b/src/tree_data.c index 07daa6e10..921e9b480 100644 --- a/src/tree_data.c +++ b/src/tree_data.c @@ -1328,8 +1328,8 @@ lyd_get_meta_annotation(const struct lys_module *mod, const char *name, size_t n } LY_ARRAY_FOR(mod->compiled->exts, u) { - plugin = lysc_get_ext_plugin(mod->compiled->exts[u].def->plugin); - if (plugin && !strncmp(plugin->id, "ly2 - metadata", 12) && + plugin = LYSC_GET_EXT_PLG(mod->compiled->exts[u].def->plugin_ref); + if (plugin && !strcmp(plugin->id, "ly2 metadata") && !ly_strncmp(mod->compiled->exts[u].argument, name, name_len)) { return &mod->compiled->exts[u]; } @@ -1872,7 +1872,7 @@ lyd_compare_meta(const struct lyd_meta *meta1, const struct lyd_meta *meta2) return LY_ENOT; } - return lysc_get_type_plugin(meta1->value.realtype->plugin)->compare(ctx, &meta1->value, &meta2->value); + return LYSC_GET_TYPE_PLG(meta1->value.realtype->plugin_ref)->compare(ctx, &meta1->value, &meta2->value); } /** @@ -2129,7 +2129,7 @@ lyd_dup_r(const struct lyd_node *node, const struct ly_ctx *trg_ctx, struct lyd_ term->hash = orig->hash; if (trg_ctx == LYD_CTX(node)) { - ret = lysc_get_type_plugin(orig->value.realtype->plugin)->duplicate(trg_ctx, &orig->value, &term->value); + ret = LYSC_GET_TYPE_PLG(orig->value.realtype->plugin_ref)->duplicate(trg_ctx, &orig->value, &term->value); LY_CHECK_ERR_GOTO(ret, LOGERR(trg_ctx, ret, "Value duplication failed."), error); } else { /* store canonical value in the target context */ @@ -2438,7 +2438,7 @@ lyd_dup_meta_single_to_ctx(const struct ly_ctx *parent_ctx, const struct lyd_met /* annotation */ mt->annotation = meta->annotation; /* duplication of value */ - ret = lysc_get_type_plugin(meta->value.realtype->plugin)->duplicate(parent_ctx, &meta->value, &mt->value); + ret = LYSC_GET_TYPE_PLG(meta->value.realtype->plugin_ref)->duplicate(parent_ctx, &meta->value, &mt->value); } LY_CHECK_ERR_GOTO(ret, LOGERR(LYD_CTX(parent), LY_EINT, "Value duplication failed."), finish); LY_CHECK_GOTO(ret = lydict_insert(parent_ctx, meta->name, 0, &mt->name), finish); diff --git a/src/tree_data_common.c b/src/tree_data_common.c index 7f50c1c2d..bb27d0905 100644 --- a/src/tree_data_common.c +++ b/src/tree_data_common.c @@ -32,6 +32,7 @@ #include "metadata.h" #include "parser_data.h" #include "plugins_exts.h" +#include "plugins_internal.h" #include "printer_data.h" #include "schema_compile_node.h" #include "set.h" @@ -531,7 +532,7 @@ lyd_value_store(const struct ly_ctx *ctx, struct lyd_value *val, const struct ly options |= LYPLG_TYPE_STORE_ONLY; } - r = lysc_get_type_plugin(type->plugin)->store(ctx, type, value, value_len, options, + r = LYSC_GET_TYPE_PLG(type->plugin_ref)->store(ctx, type, value, value_len, options, format, prefix_data, hints, ctx_node, val, NULL, &err); if (dynamic) { *dynamic = 0; @@ -562,7 +563,7 @@ lyd_value_validate_incomplete(const struct ly_ctx *ctx, const struct lysc_type * struct ly_err_item *err = NULL; struct lyplg_type *type_plugin; - type_plugin = lysc_get_type_plugin(type->plugin); + type_plugin = LYSC_GET_TYPE_PLG(type->plugin_ref); assert(type_plugin && type_plugin->validate); ret = type_plugin->validate(ctx, type, ctx_node, tree, val, &err); @@ -597,7 +598,7 @@ ly_value_validate(const struct ly_ctx *ctx, const struct lysc_node *node, const } type = ((struct lysc_node_leaf *)node)->type; - rc = lysc_get_type_plugin(type->plugin)->store(ctx ? ctx : node->module->ctx, type, value, + rc = LYSC_GET_TYPE_PLG(type->plugin_ref)->store(ctx ? ctx : node->module->ctx, type, value, value_len, 0, format, prefix_data, hints, node, &storage, NULL, &err); if (rc == LY_EINCOMPLETE) { /* actually success */ @@ -611,7 +612,7 @@ ly_value_validate(const struct ly_ctx *ctx, const struct lysc_node *node, const } if (!rc) { - lysc_get_type_plugin(type->plugin)->free(ctx ? ctx : node->module->ctx, &storage); + LYSC_GET_TYPE_PLG(type->plugin_ref)->free(ctx ? ctx : node->module->ctx, &storage); } return rc; } @@ -646,7 +647,7 @@ lyd_value_validate2(const struct ly_ctx *ctx, const struct lysc_node *schema, co } type = ((struct lysc_node_leaf *)schema)->type; - type_plugin = lysc_get_type_plugin(type->plugin); + type_plugin = LYSC_GET_TYPE_PLG(type->plugin_ref); /* store */ rc = type_plugin->store(ctx, type, value, value_len, 0, format, @@ -680,7 +681,7 @@ lyd_value_validate2(const struct ly_ctx *ctx, const struct lysc_node *schema, co if (canonical) { /* return canonical value */ - realtype_plugin = lysc_get_type_plugin(val.realtype->plugin); + realtype_plugin = LYSC_GET_TYPE_PLG(val.realtype->plugin_ref); lydict_dup(ctx, realtype_plugin->print(ctx, &val, LY_VALUE_CANON, NULL, NULL, NULL), canonical); } } @@ -712,9 +713,9 @@ lyd_value_compare(const struct lyd_node_term *node, const char *value, size_t va LY_CHECK_RET(ret); /* compare values */ - ret = lysc_get_type_plugin(type->plugin)->compare(ctx, &node->value, &val); + ret = LYSC_GET_TYPE_PLG(type->plugin_ref)->compare(ctx, &node->value, &val); - lysc_get_type_plugin(type->plugin)->free(ctx, &val); + LYSC_GET_TYPE_PLG(type->plugin_ref)->free(ctx, &val); return ret; } @@ -990,7 +991,7 @@ lyd_value_get_canonical(const struct ly_ctx *ctx, const struct lyd_value *value) LY_CHECK_ARG_RET(ctx, ctx, value, NULL); return value->_canonical ? value->_canonical : - (const char *)lysc_get_type_plugin(value->realtype->plugin)->print(ctx, value, LY_VALUE_CANON, NULL, NULL, NULL); + (const char *)LYSC_GET_TYPE_PLG(value->realtype->plugin_ref)->print(ctx, value, LY_VALUE_CANON, NULL, NULL, NULL); } LIBYANG_API_DEF LY_ERR @@ -1339,12 +1340,12 @@ ly_nested_ext_schema(const struct lyd_node *parent, const struct lysc_node *spar nested_exts = sparent->exts; } LY_ARRAY_FOR(nested_exts, u) { - if (!nested_exts[u].def->plugin) { + if (!nested_exts[u].def->plugin_ref) { /* no plugin */ continue; } - ext_snode_cb = lysc_get_ext_plugin(nested_exts[u].def->plugin)->snode; + ext_snode_cb = LYSC_GET_EXT_PLG(nested_exts[u].def->plugin_ref)->snode; if (!ext_snode_cb) { /* not an extension with nested data */ continue; diff --git a/src/tree_data_free.c b/src/tree_data_free.c index c259298d5..115a2d623 100644 --- a/src/tree_data_free.c +++ b/src/tree_data_free.c @@ -20,6 +20,7 @@ #include "log.h" #include "ly_common.h" #include "plugins_exts/metadata.h" +#include "plugins_internal.h" #include "plugins_types.h" #include "tree.h" #include "tree_data.h" @@ -64,7 +65,7 @@ lyd_free_meta(struct lyd_meta *meta, ly_bool siblings) iter = iter->next; lydict_remove(meta->annotation->module->ctx, meta->name); - lysc_get_type_plugin(meta->value.realtype->plugin)->free(meta->annotation->module->ctx, &meta->value); + LYSC_GET_TYPE_PLG(meta->value.realtype->plugin_ref)->free(meta->annotation->module->ctx, &meta->value); free(meta); } } @@ -234,7 +235,7 @@ lyd_free_subtree(struct lyd_node *node) } else if (node->schema->nodetype & LYD_NODE_TERM) { struct lyd_node_term *node_term = (struct lyd_node_term *)node; - lysc_get_type_plugin(((struct lysc_node_leaf *)node->schema)->type->plugin)->free(LYD_CTX(node), &node_term->value); + LYSC_GET_TYPE_PLG(((struct lysc_node_leaf *)node->schema)->type->plugin_ref)->free(LYD_CTX(node), &node_term->value); lyd_free_leafref_nodes(node_term); } diff --git a/src/tree_data_hash.c b/src/tree_data_hash.c index 32a6b2d3d..692c0278f 100644 --- a/src/tree_data_hash.c +++ b/src/tree_data_hash.c @@ -21,6 +21,7 @@ #include "hash_table.h" #include "log.h" #include "ly_common.h" +#include "plugins_internal.h" #include "plugins_types.h" #include "tree.h" #include "tree_data.h" @@ -56,7 +57,7 @@ lyd_hash(struct lyd_node *node) for (iter = list->child; iter && iter->schema && (iter->schema->flags & LYS_KEY); iter = iter->next) { struct lyd_node_term *key = (struct lyd_node_term *)iter; - type = lysc_get_type_plugin(key->value.realtype->plugin); + type = LYSC_GET_TYPE_PLG(key->value.realtype->plugin_ref); hash_key = type->print(NULL, &key->value, LY_VALUE_LYB, NULL, &dyn, &key_len); node->hash = lyht_hash_multi(node->hash, hash_key, key_len); if (dyn) { @@ -68,7 +69,7 @@ lyd_hash(struct lyd_node *node) /* leaf-list adds its hash key */ struct lyd_node_term *llist = (struct lyd_node_term *)node; - type = lysc_get_type_plugin(llist->value.realtype->plugin); + type = LYSC_GET_TYPE_PLG(llist->value.realtype->plugin_ref); hash_key = type->print(NULL, &llist->value, LY_VALUE_LYB, NULL, &dyn, &key_len); node->hash = lyht_hash_multi(node->hash, hash_key, key_len); if (dyn) { diff --git a/src/tree_data_new.c b/src/tree_data_new.c index 584648ab6..9c7504091 100644 --- a/src/tree_data_new.c +++ b/src/tree_data_new.c @@ -1220,8 +1220,8 @@ lyd_change_node_value(struct lyd_node_term *term, struct lyd_value *val, ly_bool struct lyd_node *target, *first; struct lyplg_type *real_type, *schema_type; - real_type = lysc_get_type_plugin(term->value.realtype->plugin); - schema_type = lysc_get_type_plugin(((struct lysc_node_leaf *)term->schema)->type->plugin); + real_type = LYSC_GET_TYPE_PLG(term->value.realtype->plugin_ref); + schema_type = LYSC_GET_TYPE_PLG(((struct lysc_node_leaf *)term->schema)->type->plugin_ref); if (term->schema->nodetype == LYS_LEAFLIST) { target = (struct lyd_node *)term; @@ -1289,7 +1289,7 @@ lyd_change_term_val(struct lyd_node *term, struct lyd_value *val, ly_bool use_va type = ((struct lysc_node_leaf *)term->schema)->type; /* compare original and new value */ - if (lysc_get_type_plugin(type->plugin)->compare(LYD_CTX(term), &t->value, val)) { + if (LYSC_GET_TYPE_PLG(type->plugin_ref)->compare(LYD_CTX(term), &t->value, val)) { /* since they are different, they cannot both be default */ assert(!(term->flags & LYD_DEFAULT) || !is_dflt); @@ -1299,7 +1299,7 @@ lyd_change_term_val(struct lyd_node *term, struct lyd_value *val, ly_bool use_va } else { /* same values, free the new stored one */ if (use_val) { - lysc_get_type_plugin(type->plugin)->free(LYD_CTX(term), val); + LYSC_GET_TYPE_PLG(type->plugin_ref)->free(LYD_CTX(term), val); } val_change = 0; } diff --git a/src/tree_data_sorted.c b/src/tree_data_sorted.c index 473bc077f..e27927a87 100644 --- a/src/tree_data_sorted.c +++ b/src/tree_data_sorted.c @@ -196,7 +196,7 @@ static int rb_sort_clb(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2) { assert(val1->realtype == val2->realtype); - return lysc_get_type_plugin(val1->realtype->plugin)->sort(ctx, val1, val2); + return LYSC_GET_TYPE_PLG(val1->realtype->plugin_ref)->sort(ctx, val1, val2); } /** diff --git a/src/tree_schema.c b/src/tree_schema.c index 5d2edccf5..3a4ae8b20 100644 --- a/src/tree_schema.c +++ b/src/tree_schema.c @@ -1364,7 +1364,7 @@ lysp_resolve_ext_instance_records(struct lysp_ctx *pctx) /* find the extension definition, use its plugin */ LY_CHECK_RET(lysp_ext_find_definition(PARSER_CTX(pctx), ext, &mod, &ext_def)); - ext->plugin = ext_def->plugin; + ext->plugin_ref = ext_def->plugin_ref; /* resolve the argument, if needed */ LY_CHECK_RET(lysp_ext_instance_resolve_argument(PARSER_CTX(pctx), ext_def, ext)); @@ -1377,7 +1377,7 @@ lysp_resolve_ext_instance_records(struct lysp_ctx *pctx) u = 0; while (u < LY_ARRAY_COUNT(exts)) { ext = &exts[u]; - if (!ext->plugin || !lysc_get_ext_plugin(ext->plugin)->parse) { + if (!ext->plugin_ref || !LYSC_GET_EXT_PLG(ext->plugin_ref)->parse) { goto next_iter; } @@ -1388,7 +1388,7 @@ lysp_resolve_ext_instance_records(struct lysp_ctx *pctx) ly_log_location(NULL, NULL, path, NULL); /* parse */ - r = lysc_get_ext_plugin(ext->plugin)->parse(pctx, ext); + r = LYSC_GET_EXT_PLG(ext->plugin_ref)->parse(pctx, ext); ly_log_location_revert(0, 0, 1, 0); free(path); @@ -1964,7 +1964,7 @@ lys_parse_in(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, /* resolve extension plugins and parse extension instances */ LY_ARRAY_FOR(mod->parsed->extensions, u) { - mod->parsed->extensions[u].plugin = lyplg_ext_plugin_find(mod->ctx, mod->name, + mod->parsed->extensions[u].plugin_ref = lyplg_ext_plugin_find(mod->ctx, mod->name, mod->revision, mod->parsed->extensions[u].name); } LY_CHECK_GOTO(ret = lysp_resolve_ext_instance_records(pctx), cleanup); diff --git a/src/tree_schema.h b/src/tree_schema.h index 80d074dd7..fec48fee0 100644 --- a/src/tree_schema.h +++ b/src/tree_schema.h @@ -299,7 +299,7 @@ struct lysp_ext { const char *dsc; /**< description statement */ const char *ref; /**< reference statement */ struct lysp_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< extension definition plugin, use ::lysc_get_ext_plugin() */ + uintptr_t plugin_ref; /**< reference to extension plugin, use ::lysc_get_ext_plugin() to get the plugin */ uint16_t flags; /**< LYS_STATUS_* and LYS_YINELEM_* values (@ref snodeflags) */ }; @@ -1183,7 +1183,7 @@ struct lysc_ext { const char *name; /**< extension name */ const char *argname; /**< argument name, NULL if not specified */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< plugin implementing the specific extension, use ::lysc_get_ext_plugin() */ + uintptr_t plugin_ref; /**< reference to extension plugin, use ::lysc_get_ext_plugin() to get the plugin */ struct lys_module *module; /**< module structure */ uint16_t flags; /**< LYS_STATUS_* value (@ref snodeflags) */ }; @@ -1279,7 +1279,7 @@ struct lysc_must { struct lysc_type { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ + uintptr_t plugin_ref; /**< reference to type plugin, use ::lysc_get_ext_plugin() to get the plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing, it may be accessed concurrently when creating/freeing data node values that reference it (instance-identifier) */ @@ -1288,7 +1288,7 @@ struct lysc_type { struct lysc_type_num { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ + uintptr_t plugin_ref; /**< reference to type plugin, use ::lysc_get_ext_plugin() to get the plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1298,7 +1298,7 @@ struct lysc_type_num { struct lysc_type_dec { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ + uintptr_t plugin_ref; /**< reference to type plugin, use ::lysc_get_ext_plugin() to get the plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1309,7 +1309,7 @@ struct lysc_type_dec { struct lysc_type_str { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ + uintptr_t plugin_ref; /**< reference to type plugin, use ::lysc_get_ext_plugin() to get the plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1334,7 +1334,7 @@ struct lysc_type_bitenum_item { struct lysc_type_enum { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ + uintptr_t plugin_ref; /**< reference to type plugin, use ::lysc_get_ext_plugin() to get the plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1344,7 +1344,7 @@ struct lysc_type_enum { struct lysc_type_bits { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ + uintptr_t plugin_ref; /**< reference to type plugin, use ::lysc_get_ext_plugin() to get the plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1355,7 +1355,7 @@ struct lysc_type_bits { struct lysc_type_leafref { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ + uintptr_t plugin_ref; /**< reference to type plugin, use ::lysc_get_ext_plugin() to get the plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1368,7 +1368,7 @@ struct lysc_type_leafref { struct lysc_type_identityref { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ + uintptr_t plugin_ref; /**< reference to type plugin, use ::lysc_get_ext_plugin() to get the plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1379,7 +1379,7 @@ struct lysc_type_identityref { struct lysc_type_instanceid { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ + uintptr_t plugin_ref; /**< reference to type plugin, use ::lysc_get_ext_plugin() to get the plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1389,7 +1389,7 @@ struct lysc_type_instanceid { struct lysc_type_union { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ + uintptr_t plugin_ref; /**< reference to type plugin, use ::lysc_get_ext_plugin() to get the plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ @@ -1399,7 +1399,7 @@ struct lysc_type_union { struct lysc_type_bin { const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */ struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */ - uintptr_t plugin; /**< type's manipulation callbacks plugin, use ::lysc_get_type_plugin() */ + uintptr_t plugin_ref; /**< reference to type plugin, use ::lysc_get_ext_plugin() to get the plugin */ LY_DATA_TYPE basetype; /**< base type of the type */ uint32_t refcount; /**< reference counter for type sharing */ diff --git a/src/tree_schema_free.c b/src/tree_schema_free.c index c7188a23a..7a74c240f 100644 --- a/src/tree_schema_free.c +++ b/src/tree_schema_free.c @@ -23,6 +23,7 @@ #include "log.h" #include "ly_common.h" #include "plugins_exts.h" +#include "plugins_internal.h" #include "plugins_types.h" #include "tree.h" #include "tree_data.h" @@ -73,8 +74,8 @@ lysp_ext_instance_free(const struct ly_ctx *ctx, struct lysp_ext_instance *ext) lydict_remove(ctx, ext->name); lydict_remove(ctx, ext->argument); ly_free_prefix_data(ext->format, ext->prefix_data); - if (ext->plugin && lysc_get_ext_plugin(ext->plugin)->pfree) { - lysc_get_ext_plugin(ext->plugin)->pfree(ctx, ext); + if (ext->plugin_ref && LYSC_GET_EXT_PLG(ext->plugin_ref)->pfree) { + LYSC_GET_EXT_PLG(ext->plugin_ref)->pfree(ctx, ext); } LY_LIST_FOR_SAFE(ext->child, next, stmt) { @@ -639,8 +640,8 @@ lysp_module_free(const struct ly_ctx *ctx, struct lysp_module *module) void lysc_ext_instance_free(const struct ly_ctx *ctx, struct lysc_ext_instance *ext) { - if (ext->def && ext->def->plugin && lysc_get_ext_plugin(ext->def->plugin)->cfree) { - lysc_get_ext_plugin(ext->def->plugin)->cfree(ctx, ext); + if (ext->def && ext->def->plugin_ref && LYSC_GET_EXT_PLG(ext->def->plugin_ref)->cfree) { + LYSC_GET_EXT_PLG(ext->def->plugin_ref)->cfree(ctx, ext); } lydict_remove(ctx, ext->argument); FREE_ARRAY(ctx, ext->exts, lysc_ext_instance_free); diff --git a/src/validation.c b/src/validation.c index 297f908c9..de4000908 100644 --- a/src/validation.c +++ b/src/validation.c @@ -32,6 +32,7 @@ #include "parser_internal.h" #include "plugins_exts.h" #include "plugins_exts/metadata.h" +#include "plugins_internal.h" #include "plugins_types.h" #include "set.h" #include "tree.h" @@ -453,7 +454,7 @@ lyd_validate_unres(struct lyd_node **tree, const struct lys_module *mod, enum ly struct lyd_ctx_ext_val *ext_v = ext_val->objs[i]; /* validate extension data */ - r = lysc_get_ext_plugin(ext_v->ext->def->plugin)->validate(ext_v->ext, ext_v->sibling, *tree, + r = LYSC_GET_EXT_PLG(ext_v->ext->def->plugin_ref)->validate(ext_v->ext, ext_v->sibling, *tree, data_type, val_opts, diff); LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); @@ -471,7 +472,7 @@ lyd_validate_unres(struct lyd_node **tree, const struct lys_module *mod, enum ly struct lyd_ctx_ext_node *ext_n = ext_node->objs[i]; /* validate the node */ - r = lysc_get_ext_plugin(ext_n->ext->def->plugin)->node(ext_n->ext, ext_n->node, val_opts); + r = LYSC_GET_EXT_PLG(ext_n->ext->def->plugin_ref)->node(ext_n->ext, ext_n->node, val_opts); LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup); /* remove this item from the set */ @@ -1820,7 +1821,7 @@ lyd_validate_nested_ext(struct lyd_node *sibling, struct ly_set *ext_val) /* try to find the extension instance */ nested_exts = sibling->parent->schema->exts; LY_ARRAY_FOR(nested_exts, u) { - if (lysc_get_ext_plugin(nested_exts[u].def->plugin)->validate) { + if (LYSC_GET_EXT_PLG(nested_exts[u].def->plugin_ref)->validate) { if (ext) { /* more extension instances with validate callback */ LOGINT_RET(LYD_CTX(sibling)); @@ -1853,7 +1854,7 @@ lyd_validate_node_ext(struct lyd_node *node, struct ly_set *ext_node) /* try to find a relevant extension instance with node callback */ exts = node->schema->exts; LY_ARRAY_FOR(exts, u) { - if (exts[u].def->plugin && lysc_get_ext_plugin(exts[u].def->plugin)->node) { + if (exts[u].def->plugin_ref && LYSC_GET_EXT_PLG(exts[u].def->plugin_ref)->node) { /* store for validation */ ext_n = malloc(sizeof *ext_n); LY_CHECK_ERR_RET(!ext_n, LOGMEM(LYD_CTX(node)), LY_EMEM); @@ -1905,7 +1906,7 @@ lyd_validate_subtree(struct lyd_node *root, struct ly_set *node_when, struct ly_ LY_LIST_FOR(node->meta, meta) { lyplg_ext_get_storage(meta->annotation, LY_STMT_TYPE, sizeof type, (const void **)&type); - if (lysc_get_type_plugin(type->plugin)->validate) { + if (LYSC_GET_TYPE_PLG(type->plugin_ref)->validate) { /* metadata type resolution */ r = ly_set_add(meta_types, (void *)meta, 1, NULL); LY_CHECK_ERR_GOTO(r, rc = r, cleanup); @@ -1913,7 +1914,7 @@ lyd_validate_subtree(struct lyd_node *root, struct ly_set *node_when, struct ly_ } if ((node->schema->nodetype & LYD_NODE_TERM) && - lysc_get_type_plugin(((struct lysc_node_leaf *)node->schema)->type->plugin)->validate) { + LYSC_GET_TYPE_PLG(((struct lysc_node_leaf *)node->schema)->type->plugin_ref)->validate) { /* node type resolution */ r = ly_set_add(node_types, (void *)node, 1, NULL); LY_CHECK_ERR_GOTO(r, rc = r, cleanup); diff --git a/src/xpath.c b/src/xpath.c index ed5a68f7c..4e8cb7566 100644 --- a/src/xpath.c +++ b/src/xpath.c @@ -34,6 +34,7 @@ #include "parser_data.h" #include "path.h" #include "plugins_exts/metadata.h" +#include "plugins_internal.h" #include "plugins_types.h" #include "printer_data.h" #include "schema_compile_node.h" @@ -1714,15 +1715,15 @@ set_comp_canonize(struct lyxp_set *set, const struct lyxp_set_node *xp_node) } /* check for built-in types without required canonization */ - if ((type->basetype == LY_TYPE_STRING) && (lysc_get_type_plugin(type->plugin)->store == lyplg_type_store_string)) { + if ((type->basetype == LY_TYPE_STRING) && (LYSC_GET_TYPE_PLG(type->plugin_ref)->store == lyplg_type_store_string)) { /* string */ return LY_SUCCESS; } - if ((type->basetype == LY_TYPE_BOOL) && (lysc_get_type_plugin(type->plugin)->store == lyplg_type_store_boolean)) { + if ((type->basetype == LY_TYPE_BOOL) && (LYSC_GET_TYPE_PLG(type->plugin_ref)->store == lyplg_type_store_boolean)) { /* boolean */ return LY_SUCCESS; } - if ((type->basetype == LY_TYPE_ENUM) && (lysc_get_type_plugin(type->plugin)->store == lyplg_type_store_enum)) { + if ((type->basetype == LY_TYPE_ENUM) && (LYSC_GET_TYPE_PLG(type->plugin_ref)->store == lyplg_type_store_enum)) { /* enumeration */ return LY_SUCCESS; } @@ -3644,7 +3645,7 @@ warn_equality_value(const struct lyxp_expr *exp, struct lyxp_set *set, uint32_t type = ((struct lysc_node_leaf *)scnode)->type; if (type->basetype != LY_TYPE_IDENT) { - type_plugin = lysc_get_type_plugin(type->plugin); + type_plugin = LYSC_GET_TYPE_PLG(type->plugin_ref); rc = type_plugin->store(set->ctx, type, value, strlen(value), 0, set->format, set->prefix_data, LYD_HINT_DATA, scnode, &storage, NULL, &err); if (rc == LY_EINCOMPLETE) { diff --git a/tests/utests/basic/test_plugins.c b/tests/utests/basic/test_plugins.c index 54c85f1c2..5c724db9c 100644 --- a/tests/utests/basic/test_plugins.c +++ b/tests/utests/basic/test_plugins.c @@ -56,12 +56,12 @@ test_add_simple(void **state) assert_non_null(plugin_t = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "libyang-plugins-simple", NULL, "note"))); assert_string_equal("ly2 simple test v1", plugin_t->id); - assert_ptr_equal(leaf->type->plugin, plugin_t); + assert_ptr_equal(leaf->type->plugin_ref, plugin_t); assert_int_equal(1, LY_ARRAY_COUNT(leaf->exts)); assert_non_null(plugin_e = lysc_get_ext_plugin(lyplg_ext_plugin_find(NULL, "libyang-plugins-simple", NULL, "hint"))); assert_string_equal("ly2 simple test v1", plugin_e->id); - assert_ptr_equal(leaf->exts[0].def->plugin, plugin_e); + assert_ptr_equal(leaf->exts[0].def->plugin_ref, plugin_e); /* the second loading of the same plugin - still success */ assert_int_equal(LY_SUCCESS, lyplg_add(TESTS_BIN "/plugins/plugin_simple" LYPLG_SUFFIX)); diff --git a/tests/utests/types/binary.c b/tests/utests/types/binary.c index 5e6bf8de0..7ed94185e 100644 --- a/tests/utests/types/binary.c +++ b/tests/utests/types/binary.c @@ -262,7 +262,7 @@ test_plugin_print(void **state) val = ""; assert_int_equal(LY_SUCCESS, type->store(UTEST_LYCTX, lysc_type, val, strlen(val), 0, LY_VALUE_XML, NULL, LYD_VALHINT_STRING, NULL, &value, NULL, &err)); - assert_string_equal("", lysc_get_type_plugin(value.realtype->plugin)->print(UTEST_LYCTX, &(value), LY_VALUE_CANON, NULL, NULL, NULL)); + assert_string_equal("", lysc_get_type_plugin(value.realtype->plugin_ref)->print(UTEST_LYCTX, &(value), LY_VALUE_CANON, NULL, NULL, NULL)); type->free(UTEST_LYCTX, &value); } diff --git a/tests/utests/types/bits.c b/tests/utests/types/bits.c index 2b11989d9..05f4660d1 100644 --- a/tests/utests/types/bits.c +++ b/tests/utests/types/bits.c @@ -938,7 +938,7 @@ test_plugin_compare(void **state) */ diff_type_text = val_init[2]; diff_type = ((struct lysc_node_leaf *)mod->compiled->data->next)->type; - ly_ret = lysc_get_type_plugin(diff_type->plugin)->store(UTEST_LYCTX, diff_type, diff_type_text, strlen(diff_type_text), + ly_ret = lysc_get_type_plugin(diff_type->plugin_ref)->store(UTEST_LYCTX, diff_type, diff_type_text, strlen(diff_type_text), 0, LY_VALUE_XML, NULL, LYD_VALHINT_STRING, NULL, &diff_type_val, NULL, &err); assert_int_equal(LY_SUCCESS, ly_ret); assert_int_equal(LY_SUCCESS, type->compare(UTEST_LYCTX, &diff_type_val, &(values[2]))); diff --git a/tests/utests/types/int8.c b/tests/utests/types/int8.c index 8a9f2f4ca..48fe8f3a3 100644 --- a/tests/utests/types/int8.c +++ b/tests/utests/types/int8.c @@ -1588,7 +1588,7 @@ test_plugin_compare(void **state) */ diff_type_text = "20"; diff_type = ((struct lysc_node_leaf *)mod->compiled->data->next)->type; - ly_ret = lysc_get_type_plugin(diff_type->plugin)->store(UTEST_LYCTX, diff_type, diff_type_text, strlen(diff_type_text), + ly_ret = lysc_get_type_plugin(diff_type->plugin_ref)->store(UTEST_LYCTX, diff_type, diff_type_text, strlen(diff_type_text), 0, LY_VALUE_XML, NULL, LYD_VALHINT_DECNUM, NULL, &diff_type_val, NULL, &err); assert_int_equal(LY_SUCCESS, ly_ret); assert_int_equal(LY_SUCCESS, type->compare(UTEST_LYCTX, &diff_type_val, &(values[0]))); @@ -1600,7 +1600,7 @@ test_plugin_compare(void **state) */ diff_type_text = "20"; diff_type = ((struct lysc_node_leaf *)mod->compiled->data->next->next)->type; - ly_ret = lysc_get_type_plugin(diff_type->plugin)->store(UTEST_LYCTX, diff_type, diff_type_text, strlen(diff_type_text), + ly_ret = lysc_get_type_plugin(diff_type->plugin_ref)->store(UTEST_LYCTX, diff_type, diff_type_text, strlen(diff_type_text), 0, LY_VALUE_XML, NULL, LYD_VALHINT_DECNUM, NULL, &diff_type_val, NULL, &err); assert_int_equal(LY_SUCCESS, ly_ret); assert_int_equal(LY_ENOT, type->compare(UTEST_LYCTX, &diff_type_val, &(values[0]))); @@ -1612,7 +1612,7 @@ test_plugin_compare(void **state) */ diff_type_text = "20"; diff_type = ((struct lysc_node_leaf *)mod->compiled->data->next->next->next)->type; - ly_ret = lysc_get_type_plugin(diff_type->plugin)->store(UTEST_LYCTX, diff_type, diff_type_text, strlen(diff_type_text), + ly_ret = lysc_get_type_plugin(diff_type->plugin_ref)->store(UTEST_LYCTX, diff_type, diff_type_text, strlen(diff_type_text), 0, LY_VALUE_XML, NULL, LYD_VALHINT_DECNUM, NULL, &diff_type_val, NULL, &err); assert_int_equal(LY_SUCCESS, ly_ret); assert_int_equal(LY_ENOT, type->compare(UTEST_LYCTX, &diff_type_val, &(values[0]))); diff --git a/tests/utests/types/string.c b/tests/utests/types/string.c index 7c4742117..56ff396ac 100644 --- a/tests/utests/types/string.c +++ b/tests/utests/types/string.c @@ -1240,7 +1240,7 @@ test_plugin_compare(void **state) /* SAME TYPE but different node */ diff_type_text = "hi"; diff_type = ((struct lysc_node_leaf *) mod->compiled->data->next)->type; - ly_ret = lysc_get_type_plugin(diff_type->plugin)->store(UTEST_LYCTX, diff_type, diff_type_text, strlen(diff_type_text), + ly_ret = lysc_get_type_plugin(diff_type->plugin_ref)->store(UTEST_LYCTX, diff_type, diff_type_text, strlen(diff_type_text), 0, LY_VALUE_XML, NULL, LYD_VALHINT_STRING, NULL, &diff_type_val, NULL, &err); assert_int_equal(LY_SUCCESS, ly_ret); assert_int_equal(LY_SUCCESS, type->compare(UTEST_LYCTX, &diff_type_val, &(values[0]))); diff --git a/tests/utests/utests.h b/tests/utests/utests.h index 4bba32d70..70abf8eb5 100644 --- a/tests/utests/utests.h +++ b/tests/utests/utests.h @@ -229,7 +229,7 @@ struct utest_context { assert_non_null(NODE); \ assert_int_equal((NODE)->basetype, TYPE); \ CHECK_ARRAY((NODE)->exts, EXTS); \ - assert_ptr_equal((NODE)->plugin, lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[TYPE])) + assert_ptr_equal((NODE)->plugin_ref, lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[TYPE])) /** * @brief check compileted numeric type @@ -933,7 +933,7 @@ struct utest_context { * @param[in] CANNONICAL_VAL expected cannonical value */ #define CHECK_LYD_VALUE_EMPTY(NODE, CANNONICAL_VAL) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal((NODE).realtype->basetype, LY_TYPE_EMPTY); @@ -951,7 +951,7 @@ struct utest_context { * CHECK_LYD_VALUE_ ## TYPE_VAL. */ #define CHECK_LYD_VALUE_UNION(NODE, CANNONICAL_VAL, TYPE_VAL, ...) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_UNION, (NODE).realtype->basetype); \ @@ -973,7 +973,7 @@ struct utest_context { * @param[in] VALUE expected array of bits names */ #define CHECK_LYD_VALUE_BITS(NODE, ...) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, _GETARG1(__VA_ARGS__, DUMMY)); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_BITS, (NODE).realtype->basetype); \ @@ -997,7 +997,7 @@ struct utest_context { * @brief Example enum arr[] = {0x0, 0x1}; CHECK_LYD_VALUE(node->value, INST, "test/d", arr); */ #define CHECK_LYD_VALUE_INST(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_INST, (NODE).realtype->basetype); \ @@ -1020,7 +1020,7 @@ struct utest_context { * @param[in] VALUE expected enum item name */ #define CHECK_LYD_VALUE_ENUM(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_ENUM, (NODE).realtype->basetype); \ @@ -1035,7 +1035,7 @@ struct utest_context { * @param[in] VALUE expected inteager value (-128 to 127). */ #define CHECK_LYD_VALUE_INT8(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_INT8, (NODE).realtype->basetype); \ @@ -1050,7 +1050,7 @@ struct utest_context { * @param[in] VALUE expected inteager value. */ #define CHECK_LYD_VALUE_INT16(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_INT16, (NODE).realtype->basetype); \ @@ -1065,7 +1065,7 @@ struct utest_context { * @param[in] VALUE expected inteager (0 to 255). */ #define CHECK_LYD_VALUE_UINT8(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_UINT8, (NODE).realtype->basetype); \ @@ -1080,7 +1080,7 @@ struct utest_context { * @param[in] VALUE expected inteager (0 to MAX_UINT32). */ #define CHECK_LYD_VALUE_UINT32(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_UINT32, (NODE).realtype->basetype); \ @@ -1094,7 +1094,7 @@ struct utest_context { * @param[in] CANNONICAL_VAL expected cannonical value */ #define CHECK_LYD_VALUE_STRING(NODE, CANNONICAL_VAL) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_STRING, (NODE).realtype->basetype); @@ -1107,7 +1107,7 @@ struct utest_context { * @param[in] CANNONICAL_VAL expected cannonical value */ #define CHECK_LYD_VALUE_LEAFREF(NODE, CANNONICAL_VAL) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_LEAFREF, (NODE).realtype->basetype); \ @@ -1122,7 +1122,7 @@ struct utest_context { * @param[in] VALUE expected value 64bit inteager */ #define CHECK_LYD_VALUE_DEC64(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_DEC64, (NODE).realtype->basetype); \ @@ -1143,7 +1143,7 @@ struct utest_context { LYD_VALUE_GET(&(NODE), _val); \ assert_int_equal(_val->size, SIZE); \ assert_int_equal(0, memcmp(_val->data, VALUE, SIZE)); \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_BINARY, (NODE).realtype->basetype); \ @@ -1158,7 +1158,7 @@ struct utest_context { * @param[in] VALUE expected boolean value 0,1 */ #define CHECK_LYD_VALUE_BOOL(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_BOOL, (NODE).realtype->basetype); \ @@ -1173,7 +1173,7 @@ struct utest_context { * @param[in] VALUE expected ident name */ #define CHECK_LYD_VALUE_IDENT(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_IDENT, (NODE).realtype->basetype); \ From 17acb3a6e0fffb1979bdddad29a575238267482c Mon Sep 17 00:00:00 2001 From: roman Date: Fri, 24 Jan 2025 13:24:10 +0100 Subject: [PATCH 20/25] context UPDATE clarify static and builtin flags --- src/context.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/context.h b/src/context.h index 9d1effcd6..52235bf4f 100644 --- a/src/context.h +++ b/src/context.h @@ -202,17 +202,20 @@ struct ly_ctx; 'require-instance false;'. It also enables usage of [lyd_leafref_get_links](@ref lyd_leafref_get_links) and [lyd_leafref_link_node_tree](@ref lyd_leafref_link_node_tree) APIs. */ -#define LY_CTX_BUILTIN_PLUGINS_ONLY 0x0800 /**< By default, context uses all available plugins for types and extensions, - both included and external. This options prevents all included plugins to be - loaded except for built-in YANG types so all derived types will use these and - for all purposes behave as the base type. The option can be used for cases when - invalid data needs to be stored in YANG node values. */ +#define LY_CTX_BUILTIN_PLUGINS_ONLY 0x0800 /**< Limits the context to use only built-in YANG type plugins, + treating all derived types as their base type. + Useful for storing invalid data in YANG node values. + This option has a global effect: the global plugin array is initialized only when no contexts exist. + If any context was created without this flag and is still alive, + creating a new context with this flag will not have the intended effect. */ + #define LY_CTX_LYB_HASHES 0x1000 /**< Generate hashes for all the schema nodes. Required when using LYB data parse or print. */ -#define LY_CTX_STATIC_PLUGINS_ONLY 0x2000 /**< By default, external plugins from directories the path to which is obtained - from the `LIBYANG_TYPES_PLUGINS_DIR` and `LIBYANG_EXTENSIONS_PLUGINS_DIR` environmental variables - are loaded. This option prevents loading of all external plugins and only - the static (libyang built-in) plugins are loaded. */ +#define LY_CTX_STATIC_PLUGINS_ONLY 0x2000 /**< Restricts the context to load only static (built-in) plugins, + ignoring external plugins from directories specified by `LIBYANG_TYPES_PLUGINS_DIR` and + `LIBYANG_EXTENSIONS_PLUGINS_DIR`. This option has a global effect: the global plugin array + is initialized only when no contexts exist. If any context was created without this flag + and is still alive, creating a new context with this flag will not have the intended effect. */ /* 0x80000000 reserved for internal use */ From 91a9b249772bd166a5f01054778338ae6ea29523 Mon Sep 17 00:00:00 2001 From: roman Date: Fri, 24 Jan 2025 14:59:42 +0100 Subject: [PATCH 21/25] tests UPDATE replace canonical print by func call --- tests/utests/utests.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/utests/utests.h b/tests/utests/utests.h index 70abf8eb5..0c28dbba8 100644 --- a/tests/utests/utests.h +++ b/tests/utests/utests.h @@ -933,7 +933,7 @@ struct utest_context { * @param[in] CANNONICAL_VAL expected cannonical value */ #define CHECK_LYD_VALUE_EMPTY(NODE, CANNONICAL_VAL) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lyd_value_get_canonical(UTEST_LYCTX, &(NODE))); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal((NODE).realtype->basetype, LY_TYPE_EMPTY); @@ -951,7 +951,7 @@ struct utest_context { * CHECK_LYD_VALUE_ ## TYPE_VAL. */ #define CHECK_LYD_VALUE_UNION(NODE, CANNONICAL_VAL, TYPE_VAL, ...) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lyd_value_get_canonical(UTEST_LYCTX, &(NODE))); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_UNION, (NODE).realtype->basetype); \ @@ -973,7 +973,7 @@ struct utest_context { * @param[in] VALUE expected array of bits names */ #define CHECK_LYD_VALUE_BITS(NODE, ...) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lyd_value_get_canonical(UTEST_LYCTX, &(NODE))); \ assert_string_equal((NODE)._canonical, _GETARG1(__VA_ARGS__, DUMMY)); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_BITS, (NODE).realtype->basetype); \ @@ -997,7 +997,7 @@ struct utest_context { * @brief Example enum arr[] = {0x0, 0x1}; CHECK_LYD_VALUE(node->value, INST, "test/d", arr); */ #define CHECK_LYD_VALUE_INST(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lyd_value_get_canonical(UTEST_LYCTX, &(NODE))); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_INST, (NODE).realtype->basetype); \ @@ -1020,7 +1020,7 @@ struct utest_context { * @param[in] VALUE expected enum item name */ #define CHECK_LYD_VALUE_ENUM(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lyd_value_get_canonical(UTEST_LYCTX, &(NODE))); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_ENUM, (NODE).realtype->basetype); \ @@ -1035,7 +1035,7 @@ struct utest_context { * @param[in] VALUE expected inteager value (-128 to 127). */ #define CHECK_LYD_VALUE_INT8(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lyd_value_get_canonical(UTEST_LYCTX, &(NODE))); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_INT8, (NODE).realtype->basetype); \ @@ -1050,7 +1050,7 @@ struct utest_context { * @param[in] VALUE expected inteager value. */ #define CHECK_LYD_VALUE_INT16(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lyd_value_get_canonical(UTEST_LYCTX, &(NODE))); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_INT16, (NODE).realtype->basetype); \ @@ -1065,7 +1065,7 @@ struct utest_context { * @param[in] VALUE expected inteager (0 to 255). */ #define CHECK_LYD_VALUE_UINT8(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lyd_value_get_canonical(UTEST_LYCTX, &(NODE))); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_UINT8, (NODE).realtype->basetype); \ @@ -1080,7 +1080,7 @@ struct utest_context { * @param[in] VALUE expected inteager (0 to MAX_UINT32). */ #define CHECK_LYD_VALUE_UINT32(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lyd_value_get_canonical(UTEST_LYCTX, &(NODE))); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_UINT32, (NODE).realtype->basetype); \ @@ -1094,7 +1094,7 @@ struct utest_context { * @param[in] CANNONICAL_VAL expected cannonical value */ #define CHECK_LYD_VALUE_STRING(NODE, CANNONICAL_VAL) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lyd_value_get_canonical(UTEST_LYCTX, &(NODE))); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_STRING, (NODE).realtype->basetype); @@ -1107,7 +1107,7 @@ struct utest_context { * @param[in] CANNONICAL_VAL expected cannonical value */ #define CHECK_LYD_VALUE_LEAFREF(NODE, CANNONICAL_VAL) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lyd_value_get_canonical(UTEST_LYCTX, &(NODE))); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_LEAFREF, (NODE).realtype->basetype); \ @@ -1122,7 +1122,7 @@ struct utest_context { * @param[in] VALUE expected value 64bit inteager */ #define CHECK_LYD_VALUE_DEC64(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lyd_value_get_canonical(UTEST_LYCTX, &(NODE))); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_DEC64, (NODE).realtype->basetype); \ @@ -1143,7 +1143,7 @@ struct utest_context { LYD_VALUE_GET(&(NODE), _val); \ assert_int_equal(_val->size, SIZE); \ assert_int_equal(0, memcmp(_val->data, VALUE, SIZE)); \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lyd_value_get_canonical(UTEST_LYCTX, &(NODE))); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_BINARY, (NODE).realtype->basetype); \ @@ -1158,7 +1158,7 @@ struct utest_context { * @param[in] VALUE expected boolean value 0,1 */ #define CHECK_LYD_VALUE_BOOL(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lyd_value_get_canonical(UTEST_LYCTX, &(NODE))); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_BOOL, (NODE).realtype->basetype); \ @@ -1173,7 +1173,7 @@ struct utest_context { * @param[in] VALUE expected ident name */ #define CHECK_LYD_VALUE_IDENT(NODE, CANNONICAL_VAL, VALUE) \ - assert_non_null(lysc_get_type_plugin((NODE).realtype->plugin_ref)->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ + assert_non_null(lyd_value_get_canonical(UTEST_LYCTX, &(NODE))); \ assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ assert_non_null((NODE).realtype); \ assert_int_equal(LY_TYPE_IDENT, (NODE).realtype->basetype); \ From 508c21c166b4e393fd4f0748b996540af673e164 Mon Sep 17 00:00:00 2001 From: roman Date: Fri, 24 Jan 2025 15:04:50 +0100 Subject: [PATCH 22/25] printer lyb BUGFIX move assignment from assert --- src/printer_lyb.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/printer_lyb.c b/src/printer_lyb.c index 5a1fe1b23..669e7378d 100644 --- a/src/printer_lyb.c +++ b/src/printer_lyb.c @@ -679,16 +679,18 @@ lyb_print_term_value(struct lyd_node_term *term, struct ly_out *out, struct lyly size_t value_len = 0; int32_t lyb_data_len; lyplg_type_print_clb print; - struct lyplg_type *type; + struct lyplg_type *type_plg; - assert(term->value.realtype && (type = LYSC_GET_TYPE_PLG(term->value.realtype->plugin_ref)) && - type->print && term->schema); + assert(term->value.realtype && term->value.realtype->plugin_ref && + LYSC_GET_TYPE_PLG(term->value.realtype->plugin_ref)->print && term->schema); + + type_plg = LYSC_GET_TYPE_PLG(term->value.realtype->plugin_ref); /* Get length of LYB data to print. */ - lyb_data_len = type->lyb_data_len; + lyb_data_len = type_plg->lyb_data_len; /* Get value and also print its length only if size is not fixed. */ - print = type->print; + print = type_plg->print; if (lyb_data_len < 0) { /* Variable-length data. */ From c107fd2ded91d10a096df26addc1983fe53d1de5 Mon Sep 17 00:00:00 2001 From: roman Date: Fri, 24 Jan 2025 15:05:25 +0100 Subject: [PATCH 23/25] printer context UPDATE clarify addr_ht building --- src/printer_context.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/printer_context.c b/src/printer_context.c index 79083c71f..885858ae5 100644 --- a/src/printer_context.c +++ b/src/printer_context.c @@ -1747,10 +1747,10 @@ ly_ctx_compiled_print_context(const struct ly_ctx *orig_ctx, struct ly_ctx *ctx, /* no search paths */ memset(&ctx->search_paths, 0, sizeof ctx->search_paths); - /* modules, referenced, 2 loops because of augments (forward reference), build the ht first */ + /* modules, referenced, 2 loops because of augments (forward reference) */ ctxp_set(&orig_ctx->modules, &ctx->modules, mem); for (i = 0; i < ctx->modules.count; ++i) { - /* build the address ht */ + /* allocate the shared module and store its new address in HT so it can be referenced */ ctx->modules.objs[i] = *mem; *mem = (char *)*mem + sizeof(struct lys_module); ly_ctx_compiled_addr_ht_add(addr_ht, orig_ctx->modules.objs[i], ctx->modules.objs[i]); From 9b7711a243c9ffcb5f770dee5a411c84f78c728e Mon Sep 17 00:00:00 2001 From: roman Date: Fri, 24 Jan 2025 15:30:23 +0100 Subject: [PATCH 24/25] plugins BUGFIX use correct array bound --- src/plugins.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins.c b/src/plugins.c index 6cf44fcd8..673b1068f 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -143,7 +143,7 @@ lysc_get_type_plugin(uintptr_t plugin_ref) return NULL; } - if (plugin_ref <= ly_plugins_types.count) { + if (plugin_ref <= ly_static_type_plugins_count) { /* plugin is static, fetch it from the global list */ return &((struct lyplg_type_record *)ly_plugins_types.objs[plugin_ref - 1])->plugin; } else { @@ -159,7 +159,7 @@ lysc_get_ext_plugin(uintptr_t plugin_ref) return NULL; } - if (plugin_ref <= ly_plugins_extensions.count) { + if (plugin_ref <= ly_static_ext_plugins_count) { /* plugin is static, fetch it from the global list */ return &((struct lyplg_ext_record *)ly_plugins_extensions.objs[plugin_ref - 1])->plugin; } else { From 417a6bccfcdd80c2954dbad645170078f79aa631 Mon Sep 17 00:00:00 2001 From: roman Date: Fri, 24 Jan 2025 16:34:05 +0100 Subject: [PATCH 25/25] plugins REFACTOR various small changes --- src/plugins.c | 10 +++++----- src/plugins_exts.h | 3 +-- src/plugins_internal.h | 8 ++++---- src/plugins_types.c | 18 +++++++++--------- src/plugins_types/union.c | 36 ++++++++++++++++++------------------ src/printer_context.c | 13 +++++++------ src/schema_compile.c | 13 +++++++------ src/schema_compile_amend.c | 5 +++-- src/tree_data_common.c | 30 ++++++++++++++++-------------- src/tree_data_hash.c | 9 ++++----- src/tree_data_new.c | 24 +++++++++++++----------- src/tree_schema.c | 5 +++-- src/tree_schema_free.c | 11 +++++++---- src/xpath.c | 17 ++++++++++------- 14 files changed, 107 insertions(+), 95 deletions(-) diff --git a/src/plugins.c b/src/plugins.c index 673b1068f..4a2adb0b9 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -198,9 +198,9 @@ plugins_iter(const struct ly_ctx *ctx, enum LYPLG type, uint32_t *index) } /** - * @brief Find the give @p type plugin record. + * @brief Find the given @p type plugin record. * - * @param[in] ctx Context for which the plugin record is searched for, NULL for built-in plugins. + * @param[in] ctx Context for which the plugin record is searched for, NULL for static plugins. * @param[in] type Type of the plugin record to find. * @param[in] module Module name of the plugin record. * @param[in] revision Revision of the @p module. @@ -244,13 +244,13 @@ lyplg_record_find(const struct ly_ctx *ctx, enum LYPLG type, const char *module, /** * @brief Find the plugin of the given @p type. * - * @param[in] ctx Context for which the plugin record is searched for, NULL for built-in plugins. + * @param[in] ctx Context for which the plugin record is searched for, NULL for static plugins. * @param[in] type Type of the plugin record to find. * @param[in] module Module name of the plugin. * @param[in] revision Revision of the @p module. * @param[in] name Name of the plugin. - * @return Reference to the callbacks plugin structure. Use ::LYSC_GET_TYPE_PLG() - * or ::LYSC_GET_EXT_PLG() on the returned value to get the actual plugin. 0 if not found. + * @return Reference to the callbacks plugin structure. Use ::LYSC_GET_TYPE_PLG + * or ::LYSC_GET_EXT_PLG on the returned value to get the actual plugin. 0 if not found. */ static uintptr_t lyplg_plugin_find(const struct ly_ctx *ctx, enum LYPLG type, const char *module, const char *revision, const char *name) diff --git a/src/plugins_exts.h b/src/plugins_exts.h index 5d688700a..5539b5d3d 100644 --- a/src/plugins_exts.h +++ b/src/plugins_exts.h @@ -405,8 +405,7 @@ struct lysp_ext_instance { const char *argument; /**< optional value of the extension's argument */ LY_VALUE_FORMAT format; /**< prefix format of the extension name/argument (::LY_VALUE_XML is YIN format) */ void *prefix_data; /**< format-specific data for prefix resolution (see ly_resolve_prefix()) */ - uintptr_t plugin_ref; /**< reference to extension's manipulation callbacks plugin, - use ::lysc_get_ext_plugin() to get the plugin */ + uintptr_t plugin_ref; /**< reference to extension plugin, use ::lysc_get_ext_plugin() to get the plugin */ void *parent; /**< pointer to the parent statement holding the extension instance(s), use ::lysp_ext_instance#parent_stmt to access the value/structure */ diff --git a/src/plugins_internal.h b/src/plugins_internal.h index 3ff7188f0..29ffbfada 100644 --- a/src/plugins_internal.h +++ b/src/plugins_internal.h @@ -66,7 +66,7 @@ extern uint32_t ly_static_ext_plugins_count; /** * @brief Get a type plugin. * - * @param[in] PLUGIN_REF Reference to a plugin. Either an index of a static plugin (offset by +1) + * @param[in] PLUGIN_REF Reference to a type plugin. Either an index of a static plugin (offset by +1) * or a pointer to an external plugin. * @return Type plugin. */ @@ -78,7 +78,7 @@ extern uint32_t ly_static_ext_plugins_count; /** * @brief Get an extension plugin. * - * @param[in] PLUGIN_REF Reference to a plugin. Either an index of a static plugin (offset by +1) + * @param[in] PLUGIN_REF Reference to an extension plugin. Either an index of a static plugin (offset by +1) * or a pointer to an external plugin. * @return Extension plugin. */ @@ -115,7 +115,7 @@ void lyplg_clean(void); * only the plugins with NULL revision specified. * @param[in] name Name of the type which the plugin implements. * @return ID of the found type plugin, 0 if none found. The type plugin can be obtained - * by passing the returned ID to ::lysc_get_type_plugin(). + * by passing the returned ID to ::lysc_get_type_plugin() or ::LYSC_GET_TYPE_PLG. */ uintptr_t lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name); @@ -128,7 +128,7 @@ uintptr_t lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, c * only the plugins with NULL revision specified. * @param[in] name Name of the extension which the plugin implements. * @return ID of the found extension plugin, 0 if none found. The extension plugin can be obtained - * by passing the returned ID to ::lysc_get_ext_plugin(). + * by passing the returned ID to ::lysc_get_ext_plugin() or ::LYSC_GET_EXT_PLG. */ uintptr_t lyplg_ext_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name); diff --git a/src/plugins_types.c b/src/plugins_types.c index 31f3da196..fc5c7bbd1 100644 --- a/src/plugins_types.c +++ b/src/plugins_types.c @@ -900,13 +900,13 @@ lyplg_type_print_val(const struct lysc_node *node, const char *canon, LY_VALUE_F struct ly_err_item *err = NULL; const char *v; ly_bool dyn; - struct lyplg_type *type_plugin; + struct lyplg_type *type_plg; type = ((struct lysc_node_leaf *)node)->type; - type_plugin = LYSC_GET_TYPE_PLG(type->plugin_ref); + type_plg = LYSC_GET_TYPE_PLG(type->plugin_ref); /* store the value */ - r = type_plugin->store(node->module->ctx, type, canon, strlen(canon), LYPLG_TYPE_STORE_ONLY, LY_VALUE_CANON, + r = type_plg->store(node->module->ctx, type, canon, strlen(canon), LYPLG_TYPE_STORE_ONLY, LY_VALUE_CANON, NULL, LYD_HINT_DATA, node, &storage, NULL, &err); if (r && (r != LY_EINCOMPLETE)) { if (err) { @@ -917,7 +917,7 @@ lyplg_type_print_val(const struct lysc_node *node, const char *canon, LY_VALUE_F } /* print it in the specific format */ - v = type_plugin->print(node->module->ctx, &storage, format, prefix_data, &dyn, NULL); + v = type_plg->print(node->module->ctx, &storage, format, prefix_data, &dyn, NULL); /* store it in the dictionary, storage will be freed */ if (dyn) { @@ -926,7 +926,7 @@ lyplg_type_print_val(const struct lysc_node *node, const char *canon, LY_VALUE_F lydict_dup(node->module->ctx, v, value); } - type_plugin->free(node->module->ctx, &storage); + type_plg->free(node->module->ctx, &storage); return LY_SUCCESS; } @@ -1052,7 +1052,7 @@ lyplg_type_resolve_leafref(const struct lysc_type_leafref *lref, const struct ly const char *val_str, *xp_err_msg; uint32_t i; int r; - struct lyplg_type *type; + struct lyplg_type *type_plg; LY_CHECK_ARG_RET(NULL, lref, node, value, errmsg, LY_EINVAL); @@ -1099,7 +1099,7 @@ lyplg_type_resolve_leafref(const struct lysc_type_leafref *lref, const struct ly goto cleanup; } - type = LYSC_GET_TYPE_PLG(lref->plugin_ref); + type_plg = LYSC_GET_TYPE_PLG(lref->plugin_ref); /* check the result */ if (target_path) { @@ -1115,7 +1115,7 @@ lyplg_type_resolve_leafref(const struct lysc_type_leafref *lref, const struct ly continue; } - if (!type->compare(LYD_CTX(node), &((struct lyd_node_term *)set.val.nodes[i].node)->value, value)) { + if (!type_plg->compare(LYD_CTX(node), &((struct lyd_node_term *)set.val.nodes[i].node)->value, value)) { break; } } @@ -1140,7 +1140,7 @@ lyplg_type_resolve_leafref(const struct lysc_type_leafref *lref, const struct ly continue; } - if (!type->compare(LYD_CTX(node), &((struct lyd_node_term *)set.val.nodes[i].node)->value, value)) { + if (!type_plg->compare(LYD_CTX(node), &((struct lyd_node_term *)set.val.nodes[i].node)->value, value)) { rc = ly_set_add(*targets, set.val.nodes[i].node, 0, NULL); LY_CHECK_GOTO(rc, cleanup); } diff --git a/src/plugins_types/union.c b/src/plugins_types/union.c index 4c33b3718..67f395afb 100644 --- a/src/plugins_types/union.c +++ b/src/plugins_types/union.c @@ -178,7 +178,7 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3 LY_VALUE_FORMAT format; void *prefix_data; uint32_t opts = 0, ti; - struct lyplg_type *type_plugin; + struct lyplg_type *type_plg; *err = NULL; @@ -186,7 +186,8 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3 lyb_parse_union(subvalue->original, subvalue->orig_len, &ti, &value, &value_len); if (ti != type_idx) { /* value of another type, first store the value properly and then use its JSON value for parsing */ - rc = LYSC_GET_TYPE_PLG(type_u->types[ti]->plugin_ref)->store(ctx, type_u->types[ti], value, value_len, + type_plg = LYSC_GET_TYPE_PLG(type_u->types[ti]->plugin_ref); + rc = type_plg->store(ctx, type_u->types[ti], value, value_len, LYPLG_TYPE_STORE_ONLY, subvalue->format, subvalue->prefix_data, subvalue->hints, subvalue->ctx_node, &subvalue->value, unres, err); if ((rc != LY_SUCCESS) && (rc != LY_EINCOMPLETE)) { @@ -204,7 +205,7 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3 value = strndup(value, value_len); dynamic = 1; } - LYSC_GET_TYPE_PLG(type_u->types[ti]->plugin_ref)->free(ctx, &subvalue->value); + type_plg->free(ctx, &subvalue->value); format = LY_VALUE_JSON; prefix_data = NULL; @@ -226,9 +227,9 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3 opts |= LYPLG_TYPE_STORE_DYNAMIC; } - type_plugin = LYSC_GET_TYPE_PLG(type->plugin_ref); + type_plg = LYSC_GET_TYPE_PLG(type->plugin_ref); - rc = type_plugin->store(ctx, type, value, value_len, opts, format, prefix_data, + rc = type_plg->store(ctx, type, value, value_len, opts, format, prefix_data, subvalue->hints, subvalue->ctx_node, &subvalue->value, unres, err); if ((rc != LY_SUCCESS) && (rc != LY_EINCOMPLETE)) { /* clear any leftover/freed garbage */ @@ -238,10 +239,10 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3 if (validate && (rc == LY_EINCOMPLETE)) { /* we need the value validated */ - rc = type_plugin->validate(ctx, type, ctx_node, tree, &subvalue->value, err); + rc = type_plg->validate(ctx, type, ctx_node, tree, &subvalue->value, err); if (rc) { /* validate failed, we need to free the stored value */ - type_plugin->free(ctx, &subvalue->value); + type_plg->free(ctx, &subvalue->value); } } @@ -274,7 +275,7 @@ union_find_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct uint32_t *prev_lo, temp_lo = 0; char *msg = NULL; int msg_len = 0; - struct lyplg_type *type; + struct lyplg_type *type_plg; *err = NULL; @@ -312,11 +313,11 @@ union_find_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct continue; } - type = LYSC_GET_TYPE_PLG(type_u->types[u]->plugin_ref); + type_plg = LYSC_GET_TYPE_PLG(type_u->types[u]->plugin_ref); - msg = ly_realloc(msg, msg_len + 4 + strlen(type->id) + 2 + strlen(errs[u]->msg) + 2); + msg = ly_realloc(msg, msg_len + 4 + strlen(type_plg->id) + 2 + strlen(errs[u]->msg) + 2); LY_CHECK_ERR_GOTO(!msg, ret = LY_EMEM, cleanup); - msg_len += sprintf(msg + msg_len, " %s: %s\n", type->id, errs[u]->msg); + msg_len += sprintf(msg + msg_len, " %s: %s\n", type_plg->id, errs[u]->msg); } ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "%s", msg); @@ -451,16 +452,16 @@ lyplg_type_validate_union(const struct ly_ctx *ctx, const struct lysc_type *type struct lyd_value orig = {0}; uint32_t type_idx; ly_bool validated = 0; - struct lyplg_type *subvalue_type; + struct lyplg_type *subvalue_type_plg; *err = NULL; /* because of types that do not store their own type as realtype (leafref), we are not able to call their * validate callback (there is no way to get the type) but even if possible, the value may be invalid * for the type, so we may have to perform union value storing again from scratch, but keep a value backup */ - subvalue_type = LYSC_GET_TYPE_PLG(subvalue->value.realtype->plugin_ref); - LY_CHECK_RET(subvalue_type->duplicate(ctx, &subvalue->value, &orig)); - subvalue_type->free(ctx, &subvalue->value); + subvalue_type_plg = LYSC_GET_TYPE_PLG(subvalue->value.realtype->plugin_ref); + LY_CHECK_RET(subvalue_type_plg->duplicate(ctx, &subvalue->value, &orig)); + subvalue_type_plg->free(ctx, &subvalue->value); if (subvalue->format == LY_VALUE_LYB) { /* use the specific type to store and validate the value */ @@ -600,7 +601,6 @@ lyplg_type_print_union(const struct ly_ctx *ctx, const struct lyd_value *value, struct lyd_value_union *subvalue = value->subvalue; struct lysc_type_union *type_u = (struct lysc_type_union *)value->realtype; size_t lyb_data_len = 0; - struct lyplg_type *type; if ((format == LY_VALUE_LYB) && (subvalue->format == LY_VALUE_LYB)) { /* The return value is already ready. */ @@ -620,8 +620,8 @@ lyplg_type_print_union(const struct ly_ctx *ctx, const struct lyd_value *value, } assert(format != LY_VALUE_LYB); - type = LYSC_GET_TYPE_PLG(subvalue->value.realtype->plugin_ref); - ret = (void *)type->print(ctx, &subvalue->value, format, prefix_data, dynamic, value_len); + ret = (void *)LYSC_GET_TYPE_PLG(subvalue->value.realtype->plugin_ref)->print(ctx, &subvalue->value, + format, prefix_data, dynamic, value_len); if (!value->_canonical && (format == LY_VALUE_CANON)) { /* the canonical value is supposed to be stored now */ lydict_insert(ctx, subvalue->value._canonical, 0, (const char **)&value->_canonical); diff --git a/src/printer_context.c b/src/printer_context.c index 885858ae5..73b6d43bd 100644 --- a/src/printer_context.c +++ b/src/printer_context.c @@ -113,7 +113,7 @@ static void ctxs_exts(const struct lysc_ext_instance *exts, struct ly_ht *ht, int *size) { LY_ARRAY_COUNT_TYPE u; - struct lyplg_ext *ext; + struct lyplg_ext *ext_plg; /* sized array */ *size += CTXS_SIZED_ARRAY(exts); @@ -125,9 +125,9 @@ ctxs_exts(const struct lysc_ext_instance *exts, struct ly_ht *ht, int *size) *size += CTXS_SIZED_ARRAY(exts[u].substmts); /* compiled, substmts storage */ - ext = LYSC_GET_EXT_PLG(exts[u].def->plugin_ref); - if (ext && ext->compiled_size) { - *size += ext->compiled_size(&exts[u], ht); + ext_plg = LYSC_GET_EXT_PLG(exts[u].def->plugin_ref); + if (ext_plg && ext_plg->compiled_size) { + *size += ext_plg->compiled_size(&exts[u], ht); } } } @@ -789,6 +789,7 @@ ctxp_ext(const struct lysc_ext_instance *orig_ext, struct lysc_ext_instance *ext struct ly_set *ptr_set, void **mem) { LY_ARRAY_COUNT_TYPE u; + struct lyplg_ext *ext_plg; if (orig_ext->exts) { /* may be referenced in the parent */ @@ -822,8 +823,8 @@ ctxp_ext(const struct lysc_ext_instance *orig_ext, struct lysc_ext_instance *ext } /* compiled, substmts storage, use the plugin */ - if (ext->def->plugin_ref && LYSC_GET_EXT_PLG(ext->def->plugin_ref)->compiled_print) { - LYSC_GET_EXT_PLG(ext->def->plugin_ref)->compiled_print(orig_ext, ext, addr_ht, ptr_set, mem); + if (ext->def->plugin_ref && (ext_plg = LYSC_GET_EXT_PLG(ext->def->plugin_ref))->compiled_print) { + ext_plg->compiled_print(orig_ext, ext, addr_ht, ptr_set, mem); } else { ext->compiled = NULL; } diff --git a/src/schema_compile.c b/src/schema_compile.c index b14adcac3..b5e6b4da0 100644 --- a/src/schema_compile.c +++ b/src/schema_compile.c @@ -114,6 +114,7 @@ LY_ERR lys_compile_ext(struct lysc_ctx *ctx, struct lysp_ext_instance *extp, struct lysc_ext_instance *ext, void *parent) { LY_ERR ret = LY_SUCCESS; + struct lyplg_ext *ext_plg; DUP_STRING_GOTO(ctx->ctx, extp->argument, ext->argument, ret, cleanup); ext->module = ctx->cur_mod; @@ -132,11 +133,11 @@ lys_compile_ext(struct lysc_ctx *ctx, struct lysp_ext_instance *extp, struct lys COMPILE_EXTS_GOTO(ctx, extp->exts, ext->exts, ext, ret, cleanup); /* compile this extension */ - if (ext->def->plugin_ref && LYSC_GET_EXT_PLG(ext->def->plugin_ref)->compile) { + if (ext->def->plugin_ref && (ext_plg = LYSC_GET_EXT_PLG(ext->def->plugin_ref))->compile) { if (ext->argument) { lysc_update_path(ctx, ext->module, ext->argument); } - ret = LYSC_GET_EXT_PLG(ext->def->plugin_ref)->compile(ctx, extp, ext); + ret = ext_plg->compile(ctx, extp, ext); if (ret == LY_ENOT) { lysc_ext_instance_free(ctx->ctx, ext); } @@ -896,11 +897,11 @@ lys_compile_unres_dflt(struct lysc_ctx *ctx, struct lysc_node *node, struct lysc struct lyd_value storage = {0}; struct ly_err_item *err = NULL; LY_VALUE_FORMAT format; - struct lyplg_type *type_plugin; + struct lyplg_type *type_plg; options = (ctx->ctx->opts & LY_CTX_REF_IMPLEMENTED) ? LYPLG_TYPE_STORE_IMPLEMENT : 0; - type_plugin = LYSC_GET_TYPE_PLG(type->plugin_ref); - rc = type_plugin->store(ctx->ctx, type, dflt, strlen(dflt), options, LY_VALUE_SCHEMA, (void *)dflt_pmod, + type_plg = LYSC_GET_TYPE_PLG(type->plugin_ref); + rc = type_plg->store(ctx->ctx, type, dflt, strlen(dflt), options, LY_VALUE_SCHEMA, (void *)dflt_pmod, LYD_HINT_SCHEMA, node, &storage, unres, &err); if (rc == LY_ERECOMPILE) { /* fine, but we need to recompile */ @@ -927,7 +928,7 @@ lys_compile_unres_dflt(struct lysc_ctx *ctx, struct lysc_node *node, struct lysc } cleanup: - type_plugin->free(ctx->ctx, &storage); + type_plg->free(ctx->ctx, &storage); return rc; } diff --git a/src/schema_compile_amend.c b/src/schema_compile_amend.c index ab802c3c0..7d58fe1bf 100644 --- a/src/schema_compile_amend.c +++ b/src/schema_compile_amend.c @@ -473,6 +473,7 @@ lysp_ext_dup(const struct ly_ctx *ctx, const struct lysp_module *pmod, void *par LY_ERR ret = LY_SUCCESS; struct ly_set pmods = {0}; struct lysp_ctx pctx = {.parsed_mods = &pmods}; + struct lyplg_ext *ext_plg; DUP_STRING_GOTO(ctx, orig_ext->name, ext->name, ret, cleanup); DUP_STRING_GOTO(ctx, orig_ext->argument, ext->argument, ret, cleanup); @@ -486,10 +487,10 @@ lysp_ext_dup(const struct ly_ctx *ctx, const struct lysp_module *pmod, void *par ext->flags = orig_ext->flags; LY_CHECK_GOTO(ret = lysp_ext_children_dup(ctx, orig_ext->child, &ext->child), cleanup); - if (ext->plugin_ref && LYSC_GET_EXT_PLG(ext->plugin_ref)->parse) { + if (ext->plugin_ref && (ext_plg = LYSC_GET_EXT_PLG(ext->plugin_ref))->parse) { /* parse again */ LY_CHECK_GOTO(ret = ly_set_add(&pmods, pmod, 1, NULL), cleanup); - LY_CHECK_GOTO(ret = LYSC_GET_EXT_PLG(ext->plugin_ref)->parse(&pctx, ext), cleanup); + LY_CHECK_GOTO(ret = ext_plg->parse(&pctx, ext), cleanup); } cleanup: diff --git a/src/tree_data_common.c b/src/tree_data_common.c index bb27d0905..048508e39 100644 --- a/src/tree_data_common.c +++ b/src/tree_data_common.c @@ -561,19 +561,19 @@ lyd_value_validate_incomplete(const struct ly_ctx *ctx, const struct lysc_type * { LY_ERR ret; struct ly_err_item *err = NULL; - struct lyplg_type *type_plugin; + struct lyplg_type *type_plg; - type_plugin = LYSC_GET_TYPE_PLG(type->plugin_ref); - assert(type_plugin && type_plugin->validate); + type_plg = LYSC_GET_TYPE_PLG(type->plugin_ref); + assert(type_plg && type_plg->validate); - ret = type_plugin->validate(ctx, type, ctx_node, tree, val, &err); + ret = type_plg->validate(ctx, type, ctx_node, tree, val, &err); if (ret) { if (err) { ly_err_print_build_path(ctx, ctx_node, NULL, err); ly_err_free(err); } else { LOGVAL(ctx, LYVE_OTHER, "Resolving value \"%s\" failed.", - (char *)type_plugin->print(ctx, val, LY_VALUE_CANON, NULL, NULL, NULL)); + (char *)type_plg->print(ctx, val, LY_VALUE_CANON, NULL, NULL, NULL)); } return ret; } @@ -636,7 +636,7 @@ lyd_value_validate2(const struct ly_ctx *ctx, const struct lysc_node *schema, co struct lysc_type *type; struct lyd_value val = {0}; ly_bool stored = 0, log = 1; - struct lyplg_type *type_plugin, *realtype_plugin; + struct lyplg_type *type_plg; if (!ctx) { ctx = schema->module->ctx; @@ -647,10 +647,10 @@ lyd_value_validate2(const struct ly_ctx *ctx, const struct lysc_node *schema, co } type = ((struct lysc_node_leaf *)schema)->type; - type_plugin = LYSC_GET_TYPE_PLG(type->plugin_ref); + type_plg = LYSC_GET_TYPE_PLG(type->plugin_ref); /* store */ - rc = type_plugin->store(ctx, type, value, value_len, 0, format, + rc = type_plg->store(ctx, type, value, value_len, 0, format, prefix_data, LYD_HINT_DATA, schema, &val, NULL, &err); if (!rc || (rc == LY_EINCOMPLETE)) { stored = 1; @@ -658,7 +658,7 @@ lyd_value_validate2(const struct ly_ctx *ctx, const struct lysc_node *schema, co if (ctx_node && (rc == LY_EINCOMPLETE)) { /* resolve */ - rc = type_plugin->validate(ctx, type, ctx_node, ctx_node, &val, &err); + rc = type_plg->validate(ctx, type, ctx_node, ctx_node, &val, &err); } if (rc && (rc != LY_EINCOMPLETE) && err) { @@ -681,14 +681,14 @@ lyd_value_validate2(const struct ly_ctx *ctx, const struct lysc_node *schema, co if (canonical) { /* return canonical value */ - realtype_plugin = LYSC_GET_TYPE_PLG(val.realtype->plugin_ref); - lydict_dup(ctx, realtype_plugin->print(ctx, &val, LY_VALUE_CANON, NULL, NULL, NULL), canonical); + lydict_dup(ctx, LYSC_GET_TYPE_PLG(val.realtype->plugin_ref)->print(ctx, &val, + LY_VALUE_CANON, NULL, NULL, NULL), canonical); } } if (stored) { /* free value */ - type_plugin->free(ctx, &val); + type_plg->free(ctx, &val); } return rc; } @@ -700,6 +700,7 @@ lyd_value_compare(const struct lyd_node_term *node, const char *value, size_t va struct ly_ctx *ctx; struct lysc_type *type; struct lyd_value val = {0}; + struct lyplg_type *type_plg; LY_CHECK_ARG_RET(node ? node->schema->module->ctx : NULL, node, value, LY_EINVAL); @@ -713,9 +714,10 @@ lyd_value_compare(const struct lyd_node_term *node, const char *value, size_t va LY_CHECK_RET(ret); /* compare values */ - ret = LYSC_GET_TYPE_PLG(type->plugin_ref)->compare(ctx, &node->value, &val); + type_plg = LYSC_GET_TYPE_PLG(type->plugin_ref); + ret = type_plg->compare(ctx, &node->value, &val); - LYSC_GET_TYPE_PLG(type->plugin_ref)->free(ctx, &val); + type_plg->free(ctx, &val); return ret; } diff --git a/src/tree_data_hash.c b/src/tree_data_hash.c index 692c0278f..d82e9203f 100644 --- a/src/tree_data_hash.c +++ b/src/tree_data_hash.c @@ -34,7 +34,6 @@ lyd_hash(struct lyd_node *node) const void *hash_key; ly_bool dyn; size_t key_len; - struct lyplg_type *type; if (!node->schema) { return LY_SUCCESS; @@ -57,8 +56,8 @@ lyd_hash(struct lyd_node *node) for (iter = list->child; iter && iter->schema && (iter->schema->flags & LYS_KEY); iter = iter->next) { struct lyd_node_term *key = (struct lyd_node_term *)iter; - type = LYSC_GET_TYPE_PLG(key->value.realtype->plugin_ref); - hash_key = type->print(NULL, &key->value, LY_VALUE_LYB, NULL, &dyn, &key_len); + hash_key = LYSC_GET_TYPE_PLG(key->value.realtype->plugin_ref)->print(NULL, &key->value, + LY_VALUE_LYB, NULL, &dyn, &key_len); node->hash = lyht_hash_multi(node->hash, hash_key, key_len); if (dyn) { free((void *)hash_key); @@ -69,8 +68,8 @@ lyd_hash(struct lyd_node *node) /* leaf-list adds its hash key */ struct lyd_node_term *llist = (struct lyd_node_term *)node; - type = LYSC_GET_TYPE_PLG(llist->value.realtype->plugin_ref); - hash_key = type->print(NULL, &llist->value, LY_VALUE_LYB, NULL, &dyn, &key_len); + hash_key = LYSC_GET_TYPE_PLG(llist->value.realtype->plugin_ref)->print(NULL, &llist->value, + LY_VALUE_LYB, NULL, &dyn, &key_len); node->hash = lyht_hash_multi(node->hash, hash_key, key_len); if (dyn) { free((void *)hash_key); diff --git a/src/tree_data_new.c b/src/tree_data_new.c index 9c7504091..8dcde8287 100644 --- a/src/tree_data_new.c +++ b/src/tree_data_new.c @@ -1218,10 +1218,10 @@ lyd_change_node_value(struct lyd_node_term *term, struct lyd_value *val, ly_bool { LY_ERR rc = LY_SUCCESS; struct lyd_node *target, *first; - struct lyplg_type *real_type, *schema_type; + struct lyplg_type *realtype_plg, *schema_type_plg; - real_type = LYSC_GET_TYPE_PLG(term->value.realtype->plugin_ref); - schema_type = LYSC_GET_TYPE_PLG(((struct lysc_node_leaf *)term->schema)->type->plugin_ref); + realtype_plg = LYSC_GET_TYPE_PLG(term->value.realtype->plugin_ref); + schema_type_plg = LYSC_GET_TYPE_PLG(((struct lysc_node_leaf *)term->schema)->type->plugin_ref); if (term->schema->nodetype == LYS_LEAFLIST) { target = (struct lyd_node *)term; @@ -1229,11 +1229,11 @@ lyd_change_node_value(struct lyd_node_term *term, struct lyd_value *val, ly_bool target = (struct lyd_node *)term->parent; } else { /* just change the value */ - real_type->free(LYD_CTX(term), &term->value); + realtype_plg->free(LYD_CTX(term), &term->value); if (use_val) { term->value = *val; } else { - rc = schema_type->duplicate(LYD_CTX(term), val, &term->value); + rc = schema_type_plg->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 */ @@ -1249,11 +1249,11 @@ lyd_change_node_value(struct lyd_node_term *term, struct lyd_value *val, ly_bool lyd_unlink_tree(target); /* change value */ - real_type->free(LYD_CTX(term), &term->value); + realtype_plg->free(LYD_CTX(term), &term->value); if (use_val) { term->value = *val; } else { - rc = schema_type->duplicate(LYD_CTX(term), val, &term->value); + rc = schema_type_plg->duplicate(LYD_CTX(term), val, &term->value); } /* reinserting */ @@ -1263,11 +1263,11 @@ lyd_change_node_value(struct lyd_node_term *term, struct lyd_value *val, ly_bool lyd_unlink_hash(target); /* change value */ - real_type->free(LYD_CTX(term), &term->value); + realtype_plg->free(LYD_CTX(term), &term->value); if (use_val) { term->value = *val; } else { - rc = schema_type->duplicate(LYD_CTX(term), val, &term->value); + rc = schema_type_plg->duplicate(LYD_CTX(term), val, &term->value); } } @@ -1284,12 +1284,14 @@ lyd_change_term_val(struct lyd_node *term, struct lyd_value *val, ly_bool use_va struct lysc_type *type; struct lyd_node_term *t; ly_bool dflt_change, val_change; + struct lyplg_type *type_plg; t = (struct lyd_node_term *)term; type = ((struct lysc_node_leaf *)term->schema)->type; + type_plg = LYSC_GET_TYPE_PLG(type->plugin_ref); /* compare original and new value */ - if (LYSC_GET_TYPE_PLG(type->plugin_ref)->compare(LYD_CTX(term), &t->value, val)) { + if (type_plg->compare(LYD_CTX(term), &t->value, val)) { /* since they are different, they cannot both be default */ assert(!(term->flags & LYD_DEFAULT) || !is_dflt); @@ -1299,7 +1301,7 @@ lyd_change_term_val(struct lyd_node *term, struct lyd_value *val, ly_bool use_va } else { /* same values, free the new stored one */ if (use_val) { - LYSC_GET_TYPE_PLG(type->plugin_ref)->free(LYD_CTX(term), val); + type_plg->free(LYD_CTX(term), val); } val_change = 0; } diff --git a/src/tree_schema.c b/src/tree_schema.c index 3a4ae8b20..f13e67376 100644 --- a/src/tree_schema.c +++ b/src/tree_schema.c @@ -1355,6 +1355,7 @@ lysp_resolve_ext_instance_records(struct lysp_ctx *pctx) uint32_t i; LY_ARRAY_COUNT_TYPE u; char *path = NULL; + struct lyplg_ext *ext_plg; /* first finish parsing all extension instances ... */ for (i = 0; i < pctx->ext_inst.count; ++i) { @@ -1377,7 +1378,7 @@ lysp_resolve_ext_instance_records(struct lysp_ctx *pctx) u = 0; while (u < LY_ARRAY_COUNT(exts)) { ext = &exts[u]; - if (!ext->plugin_ref || !LYSC_GET_EXT_PLG(ext->plugin_ref)->parse) { + if (!ext->plugin_ref || !(ext_plg = LYSC_GET_EXT_PLG(ext->plugin_ref))->parse) { goto next_iter; } @@ -1388,7 +1389,7 @@ lysp_resolve_ext_instance_records(struct lysp_ctx *pctx) ly_log_location(NULL, NULL, path, NULL); /* parse */ - r = LYSC_GET_EXT_PLG(ext->plugin_ref)->parse(pctx, ext); + r = ext_plg->parse(pctx, ext); ly_log_location_revert(0, 0, 1, 0); free(path); diff --git a/src/tree_schema_free.c b/src/tree_schema_free.c index 7a74c240f..e0699eb4f 100644 --- a/src/tree_schema_free.c +++ b/src/tree_schema_free.c @@ -70,12 +70,13 @@ void lysp_ext_instance_free(const struct ly_ctx *ctx, struct lysp_ext_instance *ext) { struct lysp_stmt *stmt, *next; + struct lyplg_ext *ext_plg; lydict_remove(ctx, ext->name); lydict_remove(ctx, ext->argument); ly_free_prefix_data(ext->format, ext->prefix_data); - if (ext->plugin_ref && LYSC_GET_EXT_PLG(ext->plugin_ref)->pfree) { - LYSC_GET_EXT_PLG(ext->plugin_ref)->pfree(ctx, ext); + if (ext->plugin_ref && (ext_plg = LYSC_GET_EXT_PLG(ext->plugin_ref))->pfree) { + ext_plg->pfree(ctx, ext); } LY_LIST_FOR_SAFE(ext->child, next, stmt) { @@ -640,8 +641,10 @@ lysp_module_free(const struct ly_ctx *ctx, struct lysp_module *module) void lysc_ext_instance_free(const struct ly_ctx *ctx, struct lysc_ext_instance *ext) { - if (ext->def && ext->def->plugin_ref && LYSC_GET_EXT_PLG(ext->def->plugin_ref)->cfree) { - LYSC_GET_EXT_PLG(ext->def->plugin_ref)->cfree(ctx, ext); + struct lyplg_ext *ext_plg; + + if (ext->def && ext->def->plugin_ref && (ext_plg = LYSC_GET_EXT_PLG(ext->def->plugin_ref))->cfree) { + ext_plg->cfree(ctx, ext); } lydict_remove(ctx, ext->argument); FREE_ARRAY(ctx, ext->exts, lysc_ext_instance_free); diff --git a/src/xpath.c b/src/xpath.c index 4e8cb7566..1ad042843 100644 --- a/src/xpath.c +++ b/src/xpath.c @@ -1699,6 +1699,7 @@ set_comp_canonize(struct lyxp_set *set, const struct lyxp_set_node *xp_node) const struct lysc_type *type = NULL; const char *canon; LY_ERR r; + struct lyplg_type *type_plg; /* is there anything to canonize even? */ if (set->type == LYXP_SET_STRING) { @@ -1714,16 +1715,18 @@ set_comp_canonize(struct lyxp_set *set, const struct lyxp_set_node *xp_node) return LY_SUCCESS; } + type_plg = LYSC_GET_TYPE_PLG(type->plugin_ref); + /* check for built-in types without required canonization */ - if ((type->basetype == LY_TYPE_STRING) && (LYSC_GET_TYPE_PLG(type->plugin_ref)->store == lyplg_type_store_string)) { + if ((type->basetype == LY_TYPE_STRING) && (type_plg->store == lyplg_type_store_string)) { /* string */ return LY_SUCCESS; } - if ((type->basetype == LY_TYPE_BOOL) && (LYSC_GET_TYPE_PLG(type->plugin_ref)->store == lyplg_type_store_boolean)) { + if ((type->basetype == LY_TYPE_BOOL) && (type_plg->store == lyplg_type_store_boolean)) { /* boolean */ return LY_SUCCESS; } - if ((type->basetype == LY_TYPE_ENUM) && (LYSC_GET_TYPE_PLG(type->plugin_ref)->store == lyplg_type_store_enum)) { + if ((type->basetype == LY_TYPE_ENUM) && (type_plg->store == lyplg_type_store_enum)) { /* enumeration */ return LY_SUCCESS; } @@ -3620,7 +3623,7 @@ warn_equality_value(const struct lyxp_expr *exp, struct lyxp_set *set, uint32_t struct lyd_value storage; LY_ERR rc; struct ly_err_item *err = NULL; - struct lyplg_type *type_plugin; + struct lyplg_type *type_plg; if ((scnode = warn_get_scnode_in_ctx(set)) && (scnode->nodetype & (LYS_LEAF | LYS_LEAFLIST)) && ((exp->tokens[val_exp] == LYXP_TOKEN_LITERAL) || (exp->tokens[val_exp] == LYXP_TOKEN_NUMBER))) { @@ -3645,8 +3648,8 @@ warn_equality_value(const struct lyxp_expr *exp, struct lyxp_set *set, uint32_t type = ((struct lysc_node_leaf *)scnode)->type; if (type->basetype != LY_TYPE_IDENT) { - type_plugin = LYSC_GET_TYPE_PLG(type->plugin_ref); - rc = type_plugin->store(set->ctx, type, value, strlen(value), 0, set->format, set->prefix_data, + type_plg = LYSC_GET_TYPE_PLG(type->plugin_ref); + rc = type_plg->store(set->ctx, type, value, strlen(value), 0, set->format, set->prefix_data, LYD_HINT_DATA, scnode, &storage, NULL, &err); if (rc == LY_EINCOMPLETE) { rc = LY_SUCCESS; @@ -3663,7 +3666,7 @@ warn_equality_value(const struct lyxp_expr *exp, struct lyxp_set *set, uint32_t (exp->tok_pos[last_equal_exp] - exp->tok_pos[equal_exp]) + exp->tok_len[last_equal_exp], set->cur_scnode); } else { - type_plugin->free(set->ctx, &storage); + type_plg->free(set->ctx, &storage); } } free(value);