printers CHANGE rewrite printers mechanism
Instead of specifying output type (memory, stream, file descriptor, ...)
with each printer function call, use printer handler mechanism. The
handler is first created with specifying the output type with necessary
parameters. Then, the handler can be used in the single print function
without the need to specify the specific output type parameters. There
are also a helper functions to update/change the output type parameter
without a need to recreate the printer handler.
This change is necessary due to the increasing complexity of the
printer functions. We want to add another parameters/specific functions,
for example to print a separate node, but together with the specific
output type parameters, the function parameters list would be quite
complex.
diff --git a/src/xpath.c b/src/xpath.c
index 6f7937f..9f9dde4 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -400,6 +400,8 @@
buf = strdup("");
LY_CHECK_ERR_RET(!buf, LOGMEM(LYD_NODE_CTX(node)), LY_EMEM);
} else {
+ struct lyp_out *out;
+
switch (any->value_type) {
case LYD_ANYDATA_STRING:
case LYD_ANYDATA_XML:
@@ -408,8 +410,10 @@
LY_CHECK_ERR_RET(!buf, LOGMEM(LYD_NODE_CTX(node)), LY_EMEM);
break;
case LYD_ANYDATA_DATATREE:
- rc = lyd_print_mem(&buf, any->value.tree, LYD_XML, LYDP_WITHSIBLINGS);
- LY_CHECK_RET(rc);
+ out = lyp_new_memory(&buf, 0);
+ rc = lyd_print(out, any->value.tree, LYD_XML, LYDP_WITHSIBLINGS);
+ lyp_free(out, NULL, 0);
+ LY_CHECK_RET(rc < 0, -rc);
break;
/* TODO case LYD_ANYDATA_LYB:
LOGERR(LYD_NODE_CTX(node), LY_EINVAL, "Cannot convert LYB anydata into string.");