session CHANGE libyang changes reflected

But they were required cause of lnc2 bugs.
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);
             }