Skip to content

Commit 77f043b

Browse files
committed
tree schema UPDATE log ext-inst path
1 parent 43a500e commit 77f043b

6 files changed

Lines changed: 34 additions & 21 deletions

File tree

src/tree_schema.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1891,7 +1891,7 @@ lysp_resolve_ext_instance_records(struct lysp_ctx *pctx)
18911891
ext->plugin_ref = ext_def->plugin_ref;
18921892

18931893
/* resolve the argument, if needed */
1894-
LY_CHECK_RET(lysp_ext_instance_resolve_argument(PARSER_CTX(pctx), ext_def, ext));
1894+
LY_CHECK_RET(lysp_ext_instance_resolve_argument(PARSER_CTX(pctx), PARSER_CUR_PMOD(pctx), ext_def, ext));
18951895
}
18961896
}
18971897

src/tree_schema_common.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,10 +2373,13 @@ lysc_ext_find_definition(const struct ly_ctx *ctx, const struct lysp_ext_instanc
23732373
}
23742374

23752375
LY_ERR
2376-
lysp_ext_instance_resolve_argument(const struct ly_ctx *ctx, const struct lysp_ext *ext_def, struct lysp_ext_instance *ext_p)
2376+
lysp_ext_instance_resolve_argument(const struct ly_ctx *ctx, const struct lysp_module *pmod,
2377+
const struct lysp_ext *ext_def, struct lysp_ext_instance *ext_p)
23772378
{
23782379
const char *ext, *arg, *prefix_arg, *name_arg, *prefix_ext, *name_ext;
23792380
uint32_t prefix_arg_len, name_arg_len, prefix_ext_len, name_ext_len;
2381+
struct lysp_stmt *stmt = NULL;
2382+
char *path;
23802383

23812384
if (!ext_def->argname || ext_p->argument) {
23822385
/* nothing to do */
@@ -2385,8 +2388,6 @@ lysp_ext_instance_resolve_argument(const struct ly_ctx *ctx, const struct lysp_e
23852388

23862389
if (ext_p->format == LY_VALUE_XML) {
23872390
/* schema was parsed from YIN and an argument is expected, ... */
2388-
struct lysp_stmt *stmt = NULL;
2389-
23902391
if (ext_def->flags & LYS_YINELEM_TRUE) {
23912392
/* ... argument was the first XML child element */
23922393
for (stmt = ext_p->child; stmt && (stmt->flags & LYS_YIN_ATTR); stmt = stmt->next) {}
@@ -2396,9 +2397,15 @@ lysp_ext_instance_resolve_argument(const struct ly_ctx *ctx, const struct lysp_e
23962397
arg = stmt->stmt;
23972398
ly_parse_nodeid(&arg, &prefix_arg, &prefix_arg_len, &name_arg, &name_arg_len);
23982399
if (ly_strncmp(ext_def->argname, name_arg, name_arg_len)) {
2400+
LY_CHECK_RET(lysp_ext_instance_path(ctx, pmod, ext_p, &path));
2401+
ly_log_location(NULL, path, NULL);
2402+
23992403
LOGVAL(ctx, NULL, LYVE_SEMANTICS, "Extension instance \"%s\" expects argument element \"%s\" as its "
24002404
"first XML child, but \"%.*s\" element found.", ext_p->name, ext_def->argname,
24012405
(int)name_arg_len, name_arg);
2406+
2407+
ly_log_location_revert(0, 1, 0);
2408+
free(path);
24022409
return LY_EVALID;
24032410
}
24042411

@@ -2409,8 +2416,14 @@ lysp_ext_instance_resolve_argument(const struct ly_ctx *ctx, const struct lysp_e
24092416

24102417
if (ly_resolve_prefix(ctx, prefix_ext, prefix_ext_len, ext_p->format, ext_p->prefix_data) !=
24112418
ly_resolve_prefix(ctx, prefix_arg, prefix_arg_len, stmt->format, stmt->prefix_data)) {
2419+
LY_CHECK_RET(lysp_ext_instance_path(ctx, pmod, ext_p, &path));
2420+
ly_log_location(NULL, path, NULL);
2421+
24122422
LOGVAL(ctx, NULL, LYVE_SEMANTICS, "Extension instance \"%s\" element and its argument element \"%s\" are "
24132423
"expected in the same namespace, but they differ.", ext_p->name, ext_def->argname);
2424+
2425+
ly_log_location_revert(0, 1, 0);
2426+
free(path);
24142427
return LY_EVALID;
24152428
}
24162429
}
@@ -2432,8 +2445,14 @@ lysp_ext_instance_resolve_argument(const struct ly_ctx *ctx, const struct lysp_e
24322445

24332446
if (!ext_p->argument) {
24342447
/* missing extension's argument */
2448+
LY_CHECK_RET(lysp_ext_instance_path(ctx, pmod, ext_p, &path));
2449+
ly_log_location(NULL, path, NULL);
2450+
24352451
LOGVAL(ctx, NULL, LYVE_SEMANTICS, "Extension instance \"%s\" missing argument %s\"%s\".",
24362452
ext_p->name, (ext_def->flags & LYS_YINELEM_TRUE) ? "element " : "", ext_def->argname);
2453+
2454+
ly_log_location_revert(0, 1, 0);
2455+
free(path);
24372456
return LY_EVALID;
24382457
}
24392458

src/tree_schema_internal.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,13 +518,14 @@ LY_ERR lys_find_child_node(const struct ly_ctx *ctx, const struct lysc_node *par
518518
* (it might come from import modules which is not yet parsed at that time). Therefore, all the attributes are stored
519519
* as substatements and resolving argument is postponed.
520520
*
521-
* @param[in] ctx libyang context
521+
* @param[in] ctx libyang context.
522+
* @param[in] pmod Current module for logging.
522523
* @param[in] ext_def Parsed extension definition.
523524
* @param[in,out] ext_p Parsed extension to be updated.
524525
* @return LY_ERR value.
525526
*/
526-
LY_ERR lysp_ext_instance_resolve_argument(const struct ly_ctx *ctx, const struct lysp_ext *ext_def,
527-
struct lysp_ext_instance *ext_p);
527+
LY_ERR lysp_ext_instance_resolve_argument(const struct ly_ctx *ctx, const struct lysp_module *pmod,
528+
const struct lysp_ext *ext_def, struct lysp_ext_instance *ext_p);
528529

529530
/**
530531
* @brief Iterate over the specified type of the extension instances

tests/utests/extensions/test_structure.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ test_schema_invalid(void **state)
167167
"import ietf-yang-structure-ext {prefix sx;}"
168168
"sx:structure { container x { leaf x {type string;}}}}";
169169
UTEST_INVALID_MODULE(data, LYS_IN_YANG, NULL, LY_EVALID);
170-
CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL, 0);
171-
CHECK_LOG_CTX("Extension instance \"sx:structure\" missing argument element \"name\".", NULL, 0);
170+
CHECK_LOG_CTX("Extension instance \"sx:structure\" missing argument element \"name\".", "/a:{ext-inst='sx:structure'}", 0);
172171

173172
data = "module a {yang-version 1.1; namespace urn:tests:extensions:structure:a; prefix self;"
174173
"import ietf-yang-structure-ext {prefix sx;}"

tests/utests/extensions/test_yangdata.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ test_schema_invalid(void **state)
206206
"import ietf-restconf {revision-date 2017-01-26; prefix rc;}"
207207
"rc:yang-data { container x { leaf x {type string;}}}}";
208208
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL));
209-
CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL, 0);
210-
CHECK_LOG_CTX("Extension instance \"rc:yang-data\" missing argument element \"name\".", NULL, 0);
209+
CHECK_LOG_CTX("Extension instance \"rc:yang-data\" missing argument element \"name\".", "/a:{ext-inst='rc:yang-data'}", 0);
211210

212211
data = "module a {yang-version 1.1; namespace urn:tests:extensions:yangdata:a; prefix self;"
213212
"import ietf-restconf {revision-date 2017-01-26; prefix rc;}"

tests/utests/schema/test_schema.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,8 +1619,7 @@ test_extension_argument_element(void **state)
16191619
/* invalid */
16201620
mod_test_yang = "module x { namespace \"urn:x\"; prefix x; import a { prefix a; } a:e; }";
16211621
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, mod_test_yang, LYS_IN_YANG, NULL));
1622-
CHECK_LOG_CTX("Parsing module \"x\" failed.", NULL, 0);
1623-
CHECK_LOG_CTX("Extension instance \"a:e\" missing argument element \"name\".", NULL, 0);
1622+
CHECK_LOG_CTX("Extension instance \"a:e\" missing argument element \"name\".", "/x:{ext-inst='a:e'}", 0);
16241623

16251624
mod_test_yin = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
16261625
"<module name=\"x\"\n"
@@ -1635,8 +1634,7 @@ test_extension_argument_element(void **state)
16351634
" <a:e/>\n"
16361635
"</module>\n";
16371636
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, mod_test_yin, LYS_IN_YIN, NULL));
1638-
CHECK_LOG_CTX("Parsing module \"x\" failed.", NULL, 0);
1639-
CHECK_LOG_CTX("Extension instance \"a:e\" missing argument element \"name\".", NULL, 0);
1637+
CHECK_LOG_CTX("Extension instance \"a:e\" missing argument element \"name\".", "/x:{ext-inst='a:e'}", 0);
16401638

16411639
mod_test_yin = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
16421640
"<module name=\"x\"\n"
@@ -1651,8 +1649,7 @@ test_extension_argument_element(void **state)
16511649
" <a:e name=\"xxx\"/>\n"
16521650
"</module>\n";
16531651
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, mod_test_yin, LYS_IN_YIN, NULL));
1654-
CHECK_LOG_CTX("Parsing module \"x\" failed.", NULL, 0);
1655-
CHECK_LOG_CTX("Extension instance \"a:e\" missing argument element \"name\".", NULL, 0);
1652+
CHECK_LOG_CTX("Extension instance \"a:e\" missing argument element \"name\".", "/x:{ext-inst='a:e'}", 0);
16561653

16571654
mod_test_yin = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
16581655
"<module name=\"x\"\n"
@@ -1669,9 +1666,8 @@ test_extension_argument_element(void **state)
16691666
" </a:e>\n"
16701667
"</module>\n";
16711668
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, mod_test_yin, LYS_IN_YIN, NULL));
1672-
CHECK_LOG_CTX("Parsing module \"x\" failed.", NULL, 0);
16731669
CHECK_LOG_CTX("Extension instance \"a:e\" element and its argument element \"name\" are expected in the same namespace, but they differ.",
1674-
NULL, 0);
1670+
"/x:{ext-inst='a:e'}", 0);
16751671

16761672
mod_test_yin = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
16771673
"<module name=\"x\"\n"
@@ -1688,9 +1684,8 @@ test_extension_argument_element(void **state)
16881684
" </a:e>\n"
16891685
"</module>\n";
16901686
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, mod_test_yin, LYS_IN_YIN, NULL));
1691-
CHECK_LOG_CTX("Parsing module \"x\" failed.", NULL, 0);
16921687
CHECK_LOG_CTX("Extension instance \"a:e\" expects argument element \"name\" as its first XML child, but \"value\" element found.",
1693-
NULL, 0);
1688+
"/x:{ext-inst='a:e'}", 0);
16941689

16951690
}
16961691

0 commit comments

Comments
 (0)