data parser CHANGE unify API with schema parser and use input handler
diff --git a/src/parser_lyb.c b/src/parser_lyb.c
index 74ff62b..d9366f8 100644
--- a/src/parser_lyb.c
+++ b/src/parser_lyb.c
@@ -25,6 +25,8 @@
 #include "context.h"
 #include "dict.h"
 #include "log.h"
+#include "parser_data.h"
+#include "parser_internal.h"
 #include "set.h"
 #include "tree.h"
 #include "tree_data_internal.h"
@@ -272,7 +274,7 @@
     if (rev) {
         sprintf(mod_rev, "%04u-%02u-%02u", ((rev & 0xFE00) >> 9) + 2000, (rev & 0x01E0) >> 5, rev & 0x001Fu);
         *mod = ly_ctx_get_module(lybctx->ctx, mod_name, mod_rev);
-        if ((lybctx->options & LYD_OPT_LYB_MOD_UPDATE) && !(*mod)) {
+        if ((lybctx->parse_options & LYD_PARSE_LYB_MOD_UPDATE) && !(*mod)) {
             /* try to use an updated module */
             *mod = ly_ctx_get_module_implemented(lybctx->ctx, mod_name);
             if (*mod && (!(*mod)->revision || (strcmp((*mod)->revision, mod_rev) < 0))) {
@@ -293,7 +295,7 @@
     }*/
 
     if (!*mod || !(*mod)->implemented) {
-        if (lybctx->options & LYD_OPT_STRICT) {
+        if (lybctx->parse_options & LYD_PARSE_STRICT) {
             if (!*mod) {
                 LOGERR(lybctx->ctx, LY_EINVAL, "Invalid context for LYB data parsing, missing module \"%s%s%s\".",
                     mod_name, rev ? "@" : "", rev ? mod_rev : "");
@@ -571,7 +573,7 @@
 {
     LY_ERR ret = LY_SUCCESS;
 
-    if ((lybctx->options & LYD_OPT_NO_STATE) && (snode->flags & LYS_CONFIG_R)) {
+    if ((lybctx->parse_options & LYD_PARSE_NO_STATE) && (snode->flags & LYS_CONFIG_R)) {
         LOGVAL(lybctx->ctx, LY_VLOG_LYSC, snode, LY_VCODE_INNODE, "state", snode->name);
         return LY_EVALID;
     }
@@ -669,7 +671,7 @@
         }
     }
 
-    if (!sibling && (lybctx->options & LYD_OPT_STRICT)) {
+    if (!sibling && (lybctx->parse_options & LYD_PARSE_STRICT)) {
         if (mod) {
             LOGVAL(lybctx->ctx, LY_VLOG_NONE, NULL, LYVE_REFERENCE, "Failed to find matching hash for a top-level node"
                    " from \"%s\".", mod->name);
@@ -748,7 +750,7 @@
         LY_CHECK_GOTO(ret, cleanup);
     }
 
-     if (!snode && !(lybctx->options & LYD_OPT_OPAQ)) {
+     if (!snode && !(lybctx->parse_options & LYD_PARSE_OPAQ)) {
         /* unknown data, skip them */
         lyb_skip_subtree(lybctx);
         goto stop_subtree;
@@ -812,7 +814,7 @@
         }
         value = NULL;
         if (ret == LY_EINCOMPLETE) {
-            if (!(lybctx->options & LYD_OPT_PARSE_ONLY)) {
+            if (!(lybctx->parse_options & LYD_PARSE_ONLY)) {
                 ly_set_add(&lybctx->unres_node_type, node, LY_SET_OPT_USEASLIST);
             }
             ret = LY_SUCCESS;
@@ -830,14 +832,14 @@
             LY_CHECK_GOTO(ret, cleanup);
         }
 
-        if (!(lybctx->options & LYD_OPT_PARSE_ONLY)) {
+        if (!(lybctx->parse_options & LYD_PARSE_ONLY)) {
             /* new node validation, autodelete CANNOT occur, all nodes are new */
             ret = lyd_validate_new(lyd_node_children_p(node), snode, NULL);
             LY_CHECK_GOTO(ret, cleanup);
 
             /* add any missing default children */
             ret = lyd_validate_defaults_r((struct lyd_node_inner *)node, lyd_node_children_p(node), NULL, NULL,
-                                          &lybctx->unres_node_type, &lybctx->when_check, lybctx->options);
+                                          &lybctx->unres_node_type, &lybctx->when_check, lybctx->validate_options);
             LY_CHECK_GOTO(ret, cleanup);
         }
 
@@ -867,15 +869,15 @@
             prev_lo = ly_log_options(0);
 
             /* try to parse LYB into a data tree */
-            tree = lyd_parse_mem((struct ly_ctx *)lybctx->ctx, value, LYD_LYB,
-                                 LYD_OPT_PARSE_ONLY | LYD_OPT_OPAQ | LYD_OPT_STRICT);
-            ly_log_options(prev_lo);
-            if (!ly_errcode(lybctx->ctx)) {
+            if (lyd_parse_data_mem((struct ly_ctx *)lybctx->ctx, value, LYD_LYB, LYD_PARSE_ONLY | LYD_PARSE_OPAQ | LYD_PARSE_STRICT, 0, &tree) == LY_SUCCESS) {
                 /* successfully parsed */
                 free(value);
                 value = (char *)tree;
                 value_type = LYD_ANYDATA_DATATREE;
             }
+
+            /* turn logging on again */
+            ly_log_options(prev_lo);
         }
 
         /* create node */
@@ -889,7 +891,7 @@
 
     /* add/correct flags */
     if (snode) {
-        lyd_parse_set_data_flags(node, &lybctx->when_check, &meta, lybctx->options);
+        lyd_parse_set_data_flags(node, &lybctx->when_check, &meta, lybctx->parse_options);
     }
 
     /* add metadata/attributes */
@@ -1018,16 +1020,20 @@
 }
 
 LY_ERR
-lyd_parse_lyb_data(struct ly_ctx *ctx, const char *data, int options, struct lyd_node **tree, int *parsed_bytes)
+lyd_parse_lyb_data(const struct ly_ctx *ctx, const char *data, int parse_options, int validate_options, struct lyd_node **tree, int *parsed_bytes)
 {
     LY_ERR ret = LY_SUCCESS;
     struct lyd_lyb_ctx lybctx = {0};
 
+    assert(!(parse_options & ~LYD_PARSE_OPTS_MASK));
+    assert(!(validate_options & ~LYD_VALIDATE_OPTS_MASK));
+
     *tree = NULL;
 
     lybctx.data = data;
     lybctx.ctx = ctx;
-    lybctx.options = options;
+    lybctx.parse_options = parse_options;
+    lybctx.validate_options = validate_options;
 
     /* read magic number */
     ret = lyb_parse_magic_number(&lybctx);
@@ -1071,14 +1077,14 @@
 }
 
 LY_ERR
-lyd_parse_lyb_rpc(struct ly_ctx *ctx, const char *data, struct lyd_node **tree, struct lyd_node **op, int *parsed_bytes)
+lyd_parse_lyb_rpc(const struct ly_ctx *ctx, const char *data, struct lyd_node **tree, struct lyd_node **op, int *parsed_bytes)
 {
     LY_ERR ret = LY_SUCCESS;
     struct lyd_lyb_ctx lybctx = {0};
 
     lybctx.data = data;
     lybctx.ctx = ctx;
-    lybctx.options = LYD_OPT_PARSE_ONLY | LYD_OPT_STRICT;
+    lybctx.parse_options = LYD_PARSE_ONLY | LYD_PARSE_STRICT;
     lybctx.int_opts = LYD_INTOPT_RPC;
 
     *tree = NULL;
@@ -1136,14 +1142,14 @@
 }
 
 LY_ERR
-lyd_parse_lyb_notif(struct ly_ctx *ctx, const char *data, struct lyd_node **tree, struct lyd_node **ntf, int *parsed_bytes)
+lyd_parse_lyb_notif(const struct ly_ctx *ctx, const char *data, struct lyd_node **tree, struct lyd_node **ntf, int *parsed_bytes)
 {
     LY_ERR ret = LY_SUCCESS;
     struct lyd_lyb_ctx lybctx = {0};
 
     lybctx.data = data;
     lybctx.ctx = ctx;
-    lybctx.options = LYD_OPT_PARSE_ONLY | LYD_OPT_STRICT;
+    lybctx.parse_options = LYD_PARSE_ONLY | LYD_PARSE_STRICT;
     lybctx.int_opts = LYD_INTOPT_NOTIF;
 
     *tree = NULL;
@@ -1201,7 +1207,7 @@
 }
 
 LY_ERR
-lyd_parse_lyb_reply(struct lyd_node *request, const char *data, struct lyd_node **tree, struct lyd_node **op,
+lyd_parse_lyb_reply(const struct lyd_node *request, const char *data, struct lyd_node **tree, struct lyd_node **op,
                     int *parsed_bytes)
 {
     LY_ERR ret = LY_SUCCESS;
@@ -1210,7 +1216,7 @@
 
     lybctx.data = data;
     lybctx.ctx = LYD_NODE_CTX(request);
-    lybctx.options = LYD_OPT_PARSE_ONLY | LYD_OPT_STRICT;
+    lybctx.parse_options = LYD_PARSE_ONLY | LYD_PARSE_STRICT;
     lybctx.int_opts = LYD_INTOPT_REPLY;
 
     *tree = NULL;