Skip to content

Commit 7d5925c

Browse files
committed
messages server BUGFIX keep rpc-error element order
1 parent 9e242ca commit 7d5925c

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

src/messages_server.c

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ nc_err_get_tag(const struct lyd_node *err)
504504
API int
505505
nc_err_set_app_tag(struct lyd_node *err, const char *error_app_tag)
506506
{
507-
struct lyd_node *match;
507+
struct lyd_node *match, *prev_anchor;
508508

509509
NC_CHECK_ARG_RET(NULL, err, error_app_tag, -1);
510510

@@ -514,9 +514,16 @@ nc_err_set_app_tag(struct lyd_node *err, const char *error_app_tag)
514514
lyd_free_tree(match);
515515
}
516516

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)) {
518522
return -1;
519523
}
524+
if (prev_anchor) {
525+
lyd_insert_after(prev_anchor, match);
526+
}
520527

521528
return 0;
522529
}
@@ -539,7 +546,7 @@ nc_err_get_app_tag(const struct lyd_node *err)
539546
API int
540547
nc_err_set_path(struct lyd_node *err, const char *error_path)
541548
{
542-
struct lyd_node *match;
549+
struct lyd_node *match, *prev_anchor;
543550

544551
NC_CHECK_ARG_RET(NULL, err, error_path, -1);
545552

@@ -549,9 +556,19 @@ nc_err_set_path(struct lyd_node *err, const char *error_path)
549556
lyd_free_tree(match);
550557
}
551558

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 */
552566
if (lyd_new_opaq2(err, NULL, "error-path", error_path, NULL, NC_NS_BASE, NULL)) {
553567
return -1;
554568
}
569+
if (prev_anchor) {
570+
lyd_insert_after(prev_anchor, match);
571+
}
555572

556573
return 0;
557574
}
@@ -574,21 +591,34 @@ nc_err_get_path(const struct lyd_node *err)
574591
API int
575592
nc_err_set_msg(struct lyd_node *err, const char *error_message, const char *lang)
576593
{
577-
struct lyd_node *match;
594+
struct lyd_node *match, *prev_anchor;
578595
struct lyd_attr *attr;
579596

580597
NC_CHECK_ARG_RET(NULL, err, error_message, -1);
581598

599+
/* remove previous node */
582600
lyd_find_sibling_opaq_next(lyd_child(err), "error-message", &match);
583601
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);
588609
}
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 */
589615
if (lyd_new_opaq2(err, NULL, "error-message", error_message, NULL, NC_NS_BASE, &match)) {
590616
return -1;
591617
}
618+
if (prev_anchor) {
619+
lyd_insert_after(prev_anchor, match);
620+
}
621+
592622
if (lang && lyd_new_attr(match, NULL, "xml:lang", lang, &attr)) {
593623
lyd_free_tree(match);
594624
return -1;

0 commit comments

Comments
 (0)