@@ -504,7 +504,7 @@ nc_err_get_tag(const struct lyd_node *err)
504
504
API int
505
505
nc_err_set_app_tag (struct lyd_node * err , const char * error_app_tag )
506
506
{
507
- struct lyd_node * match ;
507
+ struct lyd_node * match , * prev_anchor ;
508
508
509
509
NC_CHECK_ARG_RET (NULL , err , error_app_tag , -1 );
510
510
@@ -514,9 +514,16 @@ nc_err_set_app_tag(struct lyd_node *err, const char *error_app_tag)
514
514
lyd_free_tree (match );
515
515
}
516
516
517
- if (lyd_new_opaq2 (err , NULL , "error-app-tag" , error_app_tag , NULL , NC_NS_BASE , NULL )) {
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 )) {
518
522
return -1 ;
519
523
}
524
+ if (prev_anchor ) {
525
+ lyd_insert_after (prev_anchor , match );
526
+ }
520
527
521
528
return 0 ;
522
529
}
@@ -539,7 +546,7 @@ nc_err_get_app_tag(const struct lyd_node *err)
539
546
API int
540
547
nc_err_set_path (struct lyd_node * err , const char * error_path )
541
548
{
542
- struct lyd_node * match ;
549
+ struct lyd_node * match , * prev_anchor ;
543
550
544
551
NC_CHECK_ARG_RET (NULL , err , error_path , -1 );
545
552
@@ -549,9 +556,19 @@ nc_err_set_path(struct lyd_node *err, const char *error_path)
549
556
lyd_free_tree (match );
550
557
}
551
558
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 */
552
566
if (lyd_new_opaq2 (err , NULL , "error-path" , error_path , NULL , NC_NS_BASE , NULL )) {
553
567
return -1 ;
554
568
}
569
+ if (prev_anchor ) {
570
+ lyd_insert_after (prev_anchor , match );
571
+ }
555
572
556
573
return 0 ;
557
574
}
@@ -574,21 +591,34 @@ nc_err_get_path(const struct lyd_node *err)
574
591
API int
575
592
nc_err_set_msg (struct lyd_node * err , const char * error_message , const char * lang )
576
593
{
577
- struct lyd_node * match ;
594
+ struct lyd_node * match , * prev_anchor ;
578
595
struct lyd_attr * attr ;
579
596
580
597
NC_CHECK_ARG_RET (NULL , err , error_message , -1 );
581
598
599
+ /* remove previous node */
582
600
lyd_find_sibling_opaq_next (lyd_child (err ), "error-message" , & match );
583
601
if (match ) {
584
- /* Change the value of error-message and keep order of elements to comply with appendix-B in RFC 6241. */
585
- lydict_remove (LYD_CTX (err ), ((struct lyd_node_opaq * )match )-> value );
586
- lydict_insert (LYD_CTX (err ), error_message , 0 , & (((struct lyd_node_opaq * )match )-> value ));
587
- return 0 ;
602
+ lyd_free_tree (match );
603
+ }
604
+
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 );
588
609
}
610
+ if (!prev_anchor ) {
611
+ lyd_find_sibling_opaq_next (lyd_child (err ), "error-severity" , & prev_anchor );
612
+ }
613
+
614
+ /* create the node at the right place */
589
615
if (lyd_new_opaq2 (err , NULL , "error-message" , error_message , NULL , NC_NS_BASE , & match )) {
590
616
return -1 ;
591
617
}
618
+ if (prev_anchor ) {
619
+ lyd_insert_after (prev_anchor , match );
620
+ }
621
+
592
622
if (lang && lyd_new_attr (match , NULL , "xml:lang" , lang , & attr )) {
593
623
lyd_free_tree (match );
594
624
return -1 ;
0 commit comments