io FEATURE automatically add action elem as needed
Refs cesnet/netopeer2#1045
diff --git a/src/io.c b/src/io.c
index 7048430..ddbc8e6 100644
--- a/src/io.c
+++ b/src/io.c
@@ -915,7 +915,7 @@
{
va_list ap;
int count, ret;
- const char *attrs;
+ const char *attrs, *str;
struct lyd_node *op, *reply_envp, *node, *next;
struct lyd_node_opaq *rpc_envp;
struct nc_server_notif *notif;
@@ -951,6 +951,7 @@
op = va_arg(ap, struct lyd_node *);
attrs = va_arg(ap, const char *);
+ /* <rpc> open */
count = asprintf(&buf, "<rpc xmlns=\"%s\" message-id=\"%" PRIu64 "\"%s>",
NC_NS_BASE, session->opts.client.msgid + 1, attrs ? attrs : "");
if (count == -1) {
@@ -961,11 +962,27 @@
nc_write_clb((void *)&arg, buf, count, 0);
free(buf);
+ if (op->schema->nodetype != LYS_RPC) {
+ /* <action> open */
+ str = "<action xmlns=\"urn:ietf:params:xml:ns:yang:1\">";
+ nc_write_clb((void *)&arg, str, strlen(str), 0);
+ }
+
+ /* rpc data */
if (lyd_print_clb(nc_write_xmlclb, (void *)&arg, op, LYD_XML, LYD_PRINT_SHRINK)) {
ret = NC_MSG_ERROR;
goto cleanup;
}
- nc_write_clb((void *)&arg, "</rpc>", 6, 0);
+
+ if (op->schema->nodetype != LYS_RPC) {
+ /* <action> close */
+ str = "</action>";
+ nc_write_clb((void *)&arg, str, strlen(str), 0);
+ }
+
+ /* <rpc> close */
+ str = "</rpc>";
+ nc_write_clb((void *)&arg, str, strlen(str), 0);
session->opts.client.msgid++;
break;
diff --git a/src/messages_client.h b/src/messages_client.h
index 2286753..dda44dc 100644
--- a/src/messages_client.h
+++ b/src/messages_client.h
@@ -174,6 +174,8 @@
* Note that created object can be sent via any NETCONF session that shares the context
* of the @p data.
*
+ * @note In case of action, the \<action\> element is added automatically and should not be in @p data.
+ *
* @param[in] data NETCONF RPC data as a data tree.
* @param[in] paramtype How to further manage data parameters.
* @return Created RPC object to send via a NETCONF session or NULL in case of (memory allocation) error.
@@ -185,6 +187,8 @@
*
* For details, see ::nc_rpc.
*
+ * @note In case of action, the \<action\> element is added automatically and should not be in @p xml_str.
+ *
* @param[in] xml_str NETCONF RPC data as an XML string.
* @param[in] paramtype How to further manage data parameters.
* @return Created RPC object to send via a NETCONF session or NULL in case of (memory allocation) error.