@@ -261,14 +261,21 @@ nc_err(const struct ly_ctx *ctx, NC_ERR tag, ...)
261
261
{
262
262
va_list ap ;
263
263
struct lyd_node * err = NULL ;
264
+ const struct lys_module * nc_mod ;
264
265
NC_ERR_TYPE type ;
265
266
const char * arg1 , * arg2 ;
266
267
uint32_t sid ;
267
268
268
- NC_CHECK_ARG_RET (NULL , tag , NULL );
269
+ NC_CHECK_ARG_RET (NULL , tag , ctx , NULL );
270
+
271
+ nc_mod = ly_ctx_get_module_implemented (ctx , "ietf-netconf" );
272
+ if (!nc_mod ) {
273
+ ERR (NULL , "Module \"ietf-netconf\" missing in the context." );
274
+ return NULL ;
275
+ }
269
276
270
277
/* rpc-error */
271
- if (lyd_new_opaq2 (NULL , ctx , "rpc-error" , NULL , NULL , NC_NS_BASE , & err )) {
278
+ if (lyd_new_inner (NULL , nc_mod , "rpc-error" , 0 , & err )) {
272
279
return NULL ;
273
280
}
274
281
@@ -337,17 +344,17 @@ nc_err(const struct ly_ctx *ctx, NC_ERR tag, ...)
337
344
ERRARG (NULL , "tag" );
338
345
goto fail ;
339
346
}
340
- if (lyd_new_opaq2 (err , NULL , "error-type" , nc_err_type2str (type ), NULL , NC_NS_BASE , NULL )) {
347
+ if (lyd_new_term (err , NULL , "error-type" , nc_err_type2str (type ), 0 , NULL )) {
341
348
goto fail ;
342
349
}
343
350
344
351
/* error-tag */
345
- if (lyd_new_opaq2 (err , NULL , "error-tag" , nc_err_tag2str (tag ), NULL , NC_NS_BASE , NULL )) {
352
+ if (lyd_new_term (err , NULL , "error-tag" , nc_err_tag2str (tag ), 0 , NULL )) {
346
353
goto fail ;
347
354
}
348
355
349
356
/* error-severity */
350
- if (lyd_new_opaq2 (err , NULL , "error-severity" , "error" , NULL , NC_NS_BASE , NULL )) {
357
+ if (lyd_new_term (err , NULL , "error-severity" , "error" , 0 , NULL )) {
351
358
goto fail ;
352
359
}
353
360
@@ -474,13 +481,17 @@ nc_err(const struct ly_ctx *ctx, NC_ERR tag, ...)
474
481
API NC_ERR_TYPE
475
482
nc_err_get_type (const struct lyd_node * err )
476
483
{
477
- struct lyd_node * match ;
484
+ const struct lysc_node * schema ;
485
+ struct lyd_node * match = NULL ;
478
486
479
487
NC_CHECK_ARG_RET (NULL , err , 0 );
480
488
481
- lyd_find_sibling_opaq_next (lyd_child (err ), "error-type" , & match );
489
+ schema = lys_find_path (NULL , err -> schema , "error-type" , 0 );
490
+ if (schema ) {
491
+ lyd_find_sibling_val (lyd_child (err ), schema , NULL , 0 , & match );
492
+ }
482
493
if (match ) {
483
- return nc_err_str2type ((( struct lyd_node_opaq * ) match )-> value );
494
+ return nc_err_str2type (lyd_get_value ( match ));
484
495
}
485
496
486
497
return 0 ;
@@ -489,13 +500,17 @@ nc_err_get_type(const struct lyd_node *err)
489
500
API NC_ERR
490
501
nc_err_get_tag (const struct lyd_node * err )
491
502
{
492
- struct lyd_node * match ;
503
+ const struct lysc_node * schema ;
504
+ struct lyd_node * match = NULL ;
493
505
494
506
NC_CHECK_ARG_RET (NULL , err , 0 );
495
507
496
- lyd_find_sibling_opaq_next (lyd_child (err ), "error-tag" , & match );
508
+ schema = lys_find_path (NULL , err -> schema , "error-tag" , 0 );
509
+ if (schema ) {
510
+ lyd_find_sibling_val (lyd_child (err ), schema , NULL , 0 , & match );
511
+ }
497
512
if (match ) {
498
- return nc_err_str2tag ((( struct lyd_node_opaq * ) match )-> value );
513
+ return nc_err_str2tag (lyd_get_value ( match ));
499
514
}
500
515
501
516
return 0 ;
@@ -504,40 +519,45 @@ nc_err_get_tag(const struct lyd_node *err)
504
519
API int
505
520
nc_err_set_app_tag (struct lyd_node * err , const char * error_app_tag )
506
521
{
507
- struct lyd_node * match , * prev_anchor ;
522
+ const struct lysc_node * schema ;
523
+ struct lyd_node * match ;
508
524
509
525
NC_CHECK_ARG_RET (NULL , err , error_app_tag , -1 );
510
526
527
+ /* find the schema node */
528
+ schema = lys_find_path (NULL , err -> schema , "error-app-tag" , 0 );
529
+ if (!schema ) {
530
+ return -1 ;
531
+ }
532
+
511
533
/* remove previous node */
512
- lyd_find_sibling_opaq_next (lyd_child (err ), "error-app-tag" , & match );
534
+ lyd_find_sibling_val (lyd_child (err ), schema , NULL , 0 , & match );
513
535
if (match ) {
514
536
lyd_free_tree (match );
515
537
}
516
538
517
- /* find the previous node anchor */
518
- lyd_find_sibling_opaq_next (lyd_child (err ), "error-severity" , & prev_anchor );
519
-
520
- /* create the node at the right place */
521
- if (lyd_new_opaq2 (err , NULL , "error-app-tag" , error_app_tag , NULL , NC_NS_BASE , & match )) {
539
+ /* create the node */
540
+ if (lyd_new_term (err , NULL , "error-app-tag" , error_app_tag , 0 , & match )) {
522
541
return -1 ;
523
542
}
524
- if (prev_anchor ) {
525
- lyd_insert_after (prev_anchor , match );
526
- }
527
543
528
544
return 0 ;
529
545
}
530
546
531
547
API const char *
532
548
nc_err_get_app_tag (const struct lyd_node * err )
533
549
{
534
- struct lyd_node * match ;
550
+ const struct lysc_node * schema ;
551
+ struct lyd_node * match = NULL ;
535
552
536
553
NC_CHECK_ARG_RET (NULL , err , NULL );
537
554
538
- lyd_find_sibling_opaq_next (lyd_child (err ), "error-app-tag" , & match );
555
+ schema = lys_find_path (NULL , err -> schema , "error-tag" , 0 );
556
+ if (schema ) {
557
+ lyd_find_sibling_val (lyd_child (err ), schema , NULL , 0 , & match );
558
+ }
539
559
if (match ) {
540
- return (( struct lyd_node_opaq * ) match )-> value ;
560
+ return lyd_get_value ( match );
541
561
}
542
562
543
563
return NULL ;
@@ -546,43 +566,45 @@ nc_err_get_app_tag(const struct lyd_node *err)
546
566
API int
547
567
nc_err_set_path (struct lyd_node * err , const char * error_path )
548
568
{
549
- struct lyd_node * match , * prev_anchor ;
569
+ const struct lysc_node * schema ;
570
+ struct lyd_node * match ;
550
571
551
572
NC_CHECK_ARG_RET (NULL , err , error_path , -1 );
552
573
574
+ /* find the schema node */
575
+ schema = lys_find_path (NULL , err -> schema , "error-path" , 0 );
576
+ if (!schema ) {
577
+ return -1 ;
578
+ }
579
+
553
580
/* remove previous node */
554
- lyd_find_sibling_opaq_next (lyd_child (err ), "error-path" , & match );
581
+ lyd_find_sibling_val (lyd_child (err ), schema , NULL , 0 , & match );
555
582
if (match ) {
556
583
lyd_free_tree (match );
557
584
}
558
585
559
- /* find the previous node anchor */
560
- lyd_find_sibling_opaq_next (lyd_child (err ), "error-app-tag" , & prev_anchor );
561
- if (!prev_anchor ) {
562
- lyd_find_sibling_opaq_next (lyd_child (err ), "error-severity" , & prev_anchor );
563
- }
564
-
565
- /* create the node at the right place */
566
- if (lyd_new_opaq2 (err , NULL , "error-path" , error_path , NULL , NC_NS_BASE , & match )) {
586
+ /* create the node */
587
+ if (lyd_new_term (err , NULL , "error-path" , error_path , 0 , & match )) {
567
588
return -1 ;
568
589
}
569
- if (prev_anchor ) {
570
- lyd_insert_after (prev_anchor , match );
571
- }
572
590
573
591
return 0 ;
574
592
}
575
593
576
594
API const char *
577
595
nc_err_get_path (const struct lyd_node * err )
578
596
{
579
- struct lyd_node * match ;
597
+ const struct lysc_node * schema ;
598
+ struct lyd_node * match = NULL ;
580
599
581
600
NC_CHECK_ARG_RET (NULL , err , NULL );
582
601
583
- lyd_find_sibling_opaq_next (lyd_child (err ), "error-path" , & match );
602
+ schema = lys_find_path (NULL , err -> schema , "error-path" , 0 );
603
+ if (schema ) {
604
+ lyd_find_sibling_val (lyd_child (err ), schema , NULL , 0 , & match );
605
+ }
584
606
if (match ) {
585
- return (( struct lyd_node_opaq * ) match )-> value ;
607
+ return lyd_get_value ( match );
586
608
}
587
609
588
610
return NULL ;
@@ -602,13 +624,13 @@ nc_err_set_msg(struct lyd_node *err, const char *error_message, const char *lang
602
624
lyd_free_tree (match );
603
625
}
604
626
605
- /* find the previous node anchor */
606
- lyd_find_sibling_opaq_next ( lyd_child (err ), "error-path" , & prev_anchor );
607
- if (! prev_anchor ) {
608
- lyd_find_sibling_opaq_next ( lyd_child ( err ), "error-app-tag" , & prev_anchor ) ;
627
+ /* find the previous node anchor (last non-opaque node) */
628
+ prev_anchor = lyd_child (err );
629
+ while ( prev_anchor && prev_anchor -> next && prev_anchor -> next -> schema ) {
630
+ prev_anchor = prev_anchor -> next ;
609
631
}
610
- if (!prev_anchor ) {
611
- lyd_find_sibling_opaq_next ( lyd_child ( err ), "error-severity" , & prev_anchor ) ;
632
+ if (!prev_anchor -> schema ) {
633
+ prev_anchor = NULL ;
612
634
}
613
635
614
636
/* create the node at the right place */
@@ -617,6 +639,9 @@ nc_err_set_msg(struct lyd_node *err, const char *error_message, const char *lang
617
639
}
618
640
if (prev_anchor ) {
619
641
lyd_insert_after (prev_anchor , match );
642
+ } else if (match -> prev != match ) {
643
+ /* some opaque nodes existed, this must be the first */
644
+ lyd_insert_before (lyd_child (err ), match );
620
645
}
621
646
622
647
if (lang && lyd_new_attr (match , NULL , "xml:lang" , lang , & attr )) {
0 commit comments