Skip to content

Commit 174bc73

Browse files
lePicimichalvasko
authored andcommitted
io REFACTOR of rpc-reply
1 parent fedcfb4 commit 174bc73

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

src/io.c

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -919,27 +919,21 @@ nc_write_msg_io(struct nc_session *session, int io_timeout, int type, ...)
919919
rpc_envp = va_arg(ap, struct lyd_node_opaq *);
920920
reply = va_arg(ap, struct nc_server_reply *);
921921

922-
if (!rpc_envp) {
923-
/* can be NULL if replying with a malformed-message error */
924-
nc_write_clb((void *)&arg, "<rpc-reply xmlns=\"" NC_NS_BASE "\">", 18 + strlen(NC_NS_BASE) + 2, 0);
925-
926-
assert(reply->type == NC_RPL_ERROR);
927-
if (lyd_print_clb(nc_write_xmlclb, (void *)&arg, ((struct nc_server_reply_error *)reply)->err, LYD_XML,
928-
LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS)) {
922+
/* build a rpc-reply opaque node that can be simply printed */
923+
if (rpc_envp) {
924+
if (lyd_new_opaq2(NULL, session->ctx, "rpc-reply", NULL, rpc_envp->name.prefix, rpc_envp->name.module_ns,
925+
&reply_envp)) {
926+
ERRINT;
927+
ret = NC_MSG_ERROR;
928+
goto cleanup;
929+
}
930+
} else {
931+
if (lyd_new_opaq2(NULL, session->ctx, "rpc-reply", NULL, NULL, NC_NS_BASE,
932+
&reply_envp)) {
933+
ERRINT;
929934
ret = NC_MSG_ERROR;
930935
goto cleanup;
931936
}
932-
933-
nc_write_clb((void *)&arg, "</rpc-reply>", 12, 0);
934-
break;
935-
}
936-
937-
/* build a rpc-reply opaque node that can be simply printed */
938-
if (lyd_new_opaq2(NULL, session->ctx, "rpc-reply", NULL, rpc_envp->name.prefix, rpc_envp->name.module_ns,
939-
&reply_envp)) {
940-
ERRINT;
941-
ret = NC_MSG_ERROR;
942-
goto cleanup;
943937
}
944938

945939
switch (reply->type) {
@@ -988,7 +982,9 @@ nc_write_msg_io(struct nc_session *session, int io_timeout, int type, ...)
988982
}
989983

990984
/* temporary */
991-
((struct lyd_node_opaq *)reply_envp)->attr = rpc_envp->attr;
985+
if (rpc_envp) {
986+
((struct lyd_node_opaq *)reply_envp)->attr = rpc_envp->attr;
987+
}
992988

993989
/* print */
994990
lyrc = lyd_print_clb(nc_write_xmlclb, (void *)&arg, reply_envp, LYD_XML, LYD_PRINT_SHRINK | wd);

0 commit comments

Comments
 (0)