session CHANGE libyang changes reflected
But they were required cause of lnc2 bugs.
diff --git a/src/io.c b/src/io.c
index 42413ae..c5f1100 100644
--- a/src/io.c
+++ b/src/io.c
@@ -973,9 +973,7 @@
nc_write_clb((void *)&arg, "<ok/>", 5, 0);
break;
case NC_RPL_DATA:
- nc_write_clb((void *)&arg, "<data>", 6, 0);
lyd_print_clb(nc_write_xmlclb, (void *)&arg, ((struct nc_reply_data *)reply)->data, LYD_XML, LYP_WITHSIBLINGS);
- nc_write_clb((void *)&arg, "</data>", 7, 0);
break;
case NC_RPL_ERROR:
error_rpl = (struct nc_server_reply_error *)reply;
diff --git a/src/session_client.c b/src/session_client.c
index 0865801..68f7818 100644
--- a/src/session_client.c
+++ b/src/session_client.c
@@ -199,7 +199,7 @@
struct nc_reply *reply;
struct nc_reply_data *data_rpl;
NC_MSG_TYPE msg;
- char *model_data = NULL, *ptr, *ptr2, *anyxml = NULL;
+ char *model_data = NULL;
uint64_t msgid;
/* TODO later replace with yang to reduce model size? */
@@ -233,21 +233,14 @@
}
data_rpl = (struct nc_reply_data *)reply;
- lyxml_print_mem(&anyxml, ((struct lyd_node_anyxml *)data_rpl->data)->value, 0);
+ if (((struct lyd_node_anyxml *)data_rpl->data)->xml_struct) {
+ lyxml_print_mem(&model_data, ((struct lyd_node_anyxml *)data_rpl->data)->value.xml, LYXML_PRINT_SIBLINGS);
+ } else {
+ model_data = strdup(((struct lyd_node_anyxml *)data_rpl->data)->value.str);
+ }
nc_reply_free(reply);
*free_model_data = free;
- /* it's with the data root node, remove it */
- if (anyxml) {
- ptr = strchr(anyxml, '>');
- ++ptr;
-
- ptr2 = strrchr(anyxml, '<');
-
- model_data = strndup(ptr, strlen(ptr) - strlen(ptr2));
- free(anyxml);
- }
-
return model_data;
}
@@ -1225,7 +1218,7 @@
struct nc_rpc_subscribe *rpc_sub;
struct lyd_node *data, *node;
const struct lys_module *ietfnc = NULL, *ietfncmon, *notifs, *ietfncwd = NULL;
- char str[11];
+ char str[11], *filter;
uint64_t cur_msgid;
if (!session || !rpc || !msgid) {
@@ -1267,10 +1260,18 @@
}
if (rpc_gc->filter) {
if (!rpc_gc->filter[0] || (rpc_gc->filter[0] == '<')) {
- node = lyd_new_anyxml(data, ietfnc, "filter", rpc_gc->filter);
+ /* we need a copy of the filter */
+ filter = strdup(rpc_gc->filter);
+ if (!filter) {
+ ERRMEM;
+ lyd_free(data);
+ return NC_MSG_ERROR;
+ }
+
+ node = lyd_new_anyxml_str(data, ietfnc, "filter", filter);
lyd_insert_attr(node, NULL, "type", "subtree");
} else {
- node = lyd_new_anyxml(data, ietfnc, "filter", NULL);
+ node = lyd_new_anyxml_str(data, ietfnc, "filter", NULL);
lyd_insert_attr(node, NULL, "type", "xpath");
lyd_insert_attr(node, NULL, "select", rpc_gc->filter);
}
@@ -1348,7 +1349,15 @@
}
if (rpc_e->edit_cont[0] == '<') {
- node = lyd_new_anyxml(data, ietfnc, "config", rpc_e->edit_cont);
+ /* we need a copy of the content */
+ filter = strdup(rpc_e->edit_cont);
+ if (!filter) {
+ ERRMEM;
+ lyd_free(data);
+ return NC_MSG_ERROR;
+ }
+
+ node = lyd_new_anyxml_str(data, ietfnc, "config", filter);
} else {
node = lyd_new_leaf(data, ietfnc, "url", rpc_e->edit_cont);
}
@@ -1376,7 +1385,15 @@
node = lyd_new(data, ietfnc, "source");
if (rpc_cp->url_config_src) {
if (rpc_cp->url_config_src[0] == '<') {
- node = lyd_new_anyxml(node, ietfnc, "config", rpc_cp->url_config_src);
+ /* we need a copy of the content */
+ filter = strdup(rpc_cp->url_config_src);
+ if (!filter) {
+ ERRMEM;
+ lyd_free(data);
+ return NC_MSG_ERROR;
+ }
+
+ node = lyd_new_anyxml_str(node, ietfnc, "config", filter);
} else {
node = lyd_new_leaf(node, ietfnc, "url", rpc_cp->url_config_src);
}
@@ -1466,10 +1483,18 @@
data = lyd_new(NULL, ietfnc, "get");
if (rpc_g->filter) {
if (!rpc_g->filter[0] || (rpc_g->filter[0] == '<')) {
- node = lyd_new_anyxml(data, ietfnc, "filter", rpc_g->filter);
+ /* we need a copy of the filter */
+ filter = strdup(rpc_g->filter);
+ if (!filter) {
+ ERRMEM;
+ lyd_free(data);
+ return NC_MSG_ERROR;
+ }
+
+ node = lyd_new_anyxml_str(data, ietfnc, "filter", filter);
lyd_insert_attr(node, NULL, "type", "subtree");
} else {
- node = lyd_new_anyxml(data, ietfnc, "filter", NULL);
+ node = lyd_new_anyxml_str(data, ietfnc, "filter", NULL);
lyd_insert_attr(node, NULL, "type", "xpath");
lyd_insert_attr(node, NULL, "select", rpc_g->filter);
}
@@ -1573,7 +1598,15 @@
node = lyd_new(data, ietfnc, "source");
if (rpc_val->url_config_src) {
if (rpc_val->url_config_src[0] == '<') {
- node = lyd_new_anyxml(node, ietfnc, "config", rpc_val->url_config_src);
+ /* we need a copy of the config */
+ filter = strdup(rpc_val->url_config_src);
+ if (!filter) {
+ ERRMEM;
+ lyd_free(data);
+ return NC_MSG_ERROR;
+ }
+
+ node = lyd_new_anyxml_str(node, ietfnc, "config", filter);
} else {
node = lyd_new_leaf(node, ietfnc, "url", rpc_val->url_config_src);
}
@@ -1637,10 +1670,18 @@
if (rpc_sub->filter) {
if (!rpc_sub->filter[0] || (rpc_sub->filter[0] == '<')) {
- node = lyd_new_anyxml(data, notifs, "filter", rpc_sub->filter);
+ /* we need a copy of the filter */
+ filter = strdup(rpc_sub->filter);
+ if (!filter) {
+ ERRMEM;
+ lyd_free(data);
+ return NC_MSG_ERROR;
+ }
+
+ node = lyd_new_anyxml_str(data, notifs, "filter", filter);
lyd_insert_attr(node, NULL, "type", "subtree");
} else {
- node = lyd_new_anyxml(data, notifs, "filter", NULL);
+ node = lyd_new_anyxml_str(data, notifs, "filter", NULL);
lyd_insert_attr(node, NULL, "type", "xpath");
lyd_insert_attr(node, NULL, "select", rpc_sub->filter);
}
diff --git a/src/session_server.c b/src/session_server.c
index fa1ad85..25b888c 100644
--- a/src/session_server.c
+++ b/src/session_server.c
@@ -301,6 +301,9 @@
/* check and get module with the name identifier */
module = ly_ctx_get_module(server_opts.ctx, identifier, version);
if (!module) {
+ module = (const struct lys_module *)ly_ctx_get_submodule(server_opts.ctx, NULL, NULL, identifier, version);
+ }
+ if (!module) {
err = nc_err(NC_ERR_INVALID_VALUE, NC_ERR_TYPE_APP);
nc_err_set_msg(err, "The requested schema was not found.", "en");
return nc_server_reply_err(err);
@@ -316,14 +319,22 @@
nc_err_set_msg(err, "The requested format is not supported.", "en");
return nc_server_reply_err(err);
}
+ if (!model_data) {
+ ERRINT;
+ return NULL;
+ }
sdata = ly_ctx_get_node(server_opts.ctx, NULL, "/ietf-netconf-monitoring:get-schema/output/data");
- if (model_data && sdata) {
- data = lyd_output_new_anyxml(sdata, model_data);
+ if (!sdata) {
+ ERRINT;
+ free(model_data);
+ return NULL;
}
- free(model_data);
+
+ data = lyd_output_new_anyxml_str(sdata, model_data);
if (!data) {
ERRINT;
+ free(model_data);
return NULL;
}