parser json FEATURE support for nested ext instances with data
... such as schema-mount.
diff --git a/src/printer_json.c b/src/printer_json.c
index 7c251a1..cb3e094 100644
--- a/src/printer_json.c
+++ b/src/printer_json.c
@@ -49,14 +49,14 @@
* @brief Mark that something was already written in the current level,
* used to decide if a comma is expected between the items
*/
-#define LEVEL_PRINTED ctx->level_printed = ctx->level
+#define LEVEL_PRINTED pctx->level_printed = pctx->level
#define PRINT_COMMA \
- if (ctx->level_printed >= ctx->level) {\
- ly_print_(ctx->out, ",%s", (DO_FORMAT ? "\n" : ""));\
+ if (pctx->level_printed >= pctx->level) { \
+ ly_print_(pctx->out, ",%s", (DO_FORMAT ? "\n" : "")); \
}
-static LY_ERR json_print_node(struct jsonpr_ctx *ctx, const struct lyd_node *node);
+static LY_ERR json_print_node(struct jsonpr_ctx *pctx, const struct lyd_node *node);
/**
* Compare 2 nodes, despite it is regular data node or an opaq node, and
@@ -96,10 +96,10 @@
* @return LY_ERR value.
*/
static LY_ERR
-json_print_array_open(struct jsonpr_ctx *ctx, const struct lyd_node *node)
+json_print_array_open(struct jsonpr_ctx *pctx, const struct lyd_node *node)
{
- ly_print_(ctx->out, "[%s", DO_FORMAT ? "\n" : "");
- LY_CHECK_RET(ly_set_add(&ctx->open, (void *)node, 0, NULL));
+ ly_print_(pctx->out, "[%s", DO_FORMAT ? "\n" : "");
+ LY_CHECK_RET(ly_set_add(&pctx->open, (void *)node, 0, NULL));
LEVEL_INC;
return LY_SUCCESS;
@@ -114,9 +114,9 @@
* @return 0 in case the provided @p node is not connected with the currently open array (or there is no open array).
*/
static int
-is_open_array(struct jsonpr_ctx *ctx, const struct lyd_node *node)
+is_open_array(struct jsonpr_ctx *pctx, const struct lyd_node *node)
{
- if (ctx->open.count && matching_node(node, (const struct lyd_node *)ctx->open.objs[ctx->open.count - 1])) {
+ if (pctx->open.count && matching_node(node, pctx->open.dnodes[pctx->open.count - 1])) {
return 1;
} else {
return 0;
@@ -129,11 +129,11 @@
* @param[in] ctx JSON printer context.
*/
static void
-json_print_array_close(struct jsonpr_ctx *ctx)
+json_print_array_close(struct jsonpr_ctx *pctx)
{
LEVEL_DEC;
- ly_set_rm_index(&ctx->open, ctx->open.count - 1, NULL);
- ly_print_(ctx->out, "%s%*s]", DO_FORMAT ? "\n" : "", INDENT);
+ ly_set_rm_index(&pctx->open, pctx->open.count - 1, NULL);
+ ly_print_(pctx->out, "%s%*s]", DO_FORMAT ? "\n" : "", INDENT);
}
/**
@@ -256,16 +256,15 @@
* @return LY_ERR value.
*/
static LY_ERR
-json_print_member(struct jsonpr_ctx *ctx, const struct lyd_node *node, ly_bool is_attr)
+json_print_member(struct jsonpr_ctx *pctx, const struct lyd_node *node, ly_bool is_attr)
{
PRINT_COMMA;
- if ((LEVEL == 1) || json_nscmp(node, (const struct lyd_node *)node->parent)) {
+ if ((LEVEL == 1) || json_nscmp(node, lyd_parent(node))) {
/* print "namespace" */
- ly_print_(ctx->out, "%*s\"%s%s:%s\":%s", INDENT, is_attr ? "@" : "",
+ ly_print_(pctx->out, "%*s\"%s%s:%s\":%s", INDENT, is_attr ? "@" : "",
node_prefix(node), node->schema->name, DO_FORMAT ? " " : "");
} else {
- ly_print_(ctx->out, "%*s\"%s%s\":%s", INDENT, is_attr ? "@" : "",
- node->schema->name, DO_FORMAT ? " " : "");
+ ly_print_(pctx->out, "%*s\"%s%s\":%s", INDENT, is_attr ? "@" : "", node->schema->name, DO_FORMAT ? " " : "");
}
return LY_SUCCESS;
@@ -282,7 +281,7 @@
* @return LY_ERR value.
*/
static LY_ERR
-json_print_member2(struct jsonpr_ctx *ctx, const struct lyd_node *parent, LY_VALUE_FORMAT format,
+json_print_member2(struct jsonpr_ctx *pctx, const struct lyd_node *parent, LY_VALUE_FORMAT format,
const struct ly_opaq_name *name, ly_bool is_attr)
{
const char *module_name = NULL, *name_str;
@@ -298,14 +297,14 @@
module_name = name->module_name;
break;
case LY_VALUE_XML:
- mod = ly_ctx_get_module_implemented_ns(ctx->ctx, name->module_ns);
+ mod = ly_ctx_get_module_implemented_ns(pctx->ctx, name->module_ns);
if (mod) {
module_name = mod->name;
}
break;
default:
/* cannot be created */
- LOGINT_RET(ctx->ctx);
+ LOGINT_RET(pctx->ctx);
}
name_str = name->name;
@@ -315,9 +314,9 @@
/* print the member */
if (module_name && (!parent || (node_prefix(parent) != module_name))) {
- ly_print_(ctx->out, "%*s\"%s%s:%s\":%s", INDENT, is_attr ? "@" : "", module_name, name_str, DO_FORMAT ? " " : "");
+ ly_print_(pctx->out, "%*s\"%s%s:%s\":%s", INDENT, is_attr ? "@" : "", module_name, name_str, DO_FORMAT ? " " : "");
} else {
- ly_print_(ctx->out, "%*s\"%s%s\":%s", INDENT, is_attr ? "@" : "", name_str, DO_FORMAT ? " " : "");
+ ly_print_(pctx->out, "%*s\"%s%s\":%s", INDENT, is_attr ? "@" : "", name_str, DO_FORMAT ? " " : "");
}
return LY_SUCCESS;
@@ -326,16 +325,17 @@
/**
* @brief Print data value.
*
- * @param[in] ctx JSON printer context.
+ * @param[in] pctx JSON printer context.
+ * @param[in] ctx Context used to print the value.
* @param[in] val Data value to be printed.
* @return LY_ERR value.
*/
static LY_ERR
-json_print_value(struct jsonpr_ctx *ctx, const struct lyd_value *val)
+json_print_value(struct jsonpr_ctx *pctx, const struct ly_ctx *ctx, const struct lyd_value *val)
{
ly_bool dynamic;
LY_DATA_TYPE basetype;
- const char *value = val->realtype->plugin->print(ctx->ctx, val, LY_VALUE_JSON, NULL, &dynamic, NULL);
+ const char *value = val->realtype->plugin->print(ctx, val, LY_VALUE_JSON, NULL, &dynamic, NULL);
basetype = val->realtype->basetype;
@@ -356,7 +356,7 @@
case LY_TYPE_UINT64:
case LY_TYPE_DEC64:
case LY_TYPE_IDENT:
- json_print_string(ctx->out, value);
+ json_print_string(pctx->out, value);
break;
case LY_TYPE_INT8:
@@ -366,16 +366,16 @@
case LY_TYPE_UINT16:
case LY_TYPE_UINT32:
case LY_TYPE_BOOL:
- ly_print_(ctx->out, "%s", value[0] ? value : "null");
+ ly_print_(pctx->out, "%s", value[0] ? value : "null");
break;
case LY_TYPE_EMPTY:
- ly_print_(ctx->out, "[null]");
+ ly_print_(pctx->out, "[null]");
break;
default:
/* error */
- LOGINT_RET(ctx->ctx);
+ LOGINT_RET(pctx->ctx);
}
if (dynamic) {
@@ -394,25 +394,25 @@
* @return LY_ERR value.
*/
static LY_ERR
-json_print_attribute(struct jsonpr_ctx *ctx, const struct lyd_node_opaq *node, const struct lys_module *wdmod)
+json_print_attribute(struct jsonpr_ctx *pctx, const struct lyd_node_opaq *node, const struct lys_module *wdmod)
{
struct lyd_attr *attr;
if (wdmod) {
- ly_print_(ctx->out, "%*s\"%s:default\":\"true\"", INDENT, wdmod->name);
+ ly_print_(pctx->out, "%*s\"%s:default\":\"true\"", INDENT, wdmod->name);
LEVEL_PRINTED;
}
for (attr = node->attr; attr; attr = attr->next) {
PRINT_COMMA;
- json_print_member2(ctx, &node->node, attr->format, &attr->name, 0);
+ json_print_member2(pctx, &node->node, attr->format, &attr->name, 0);
if (attr->hints & (LYD_VALHINT_BOOLEAN | LYD_VALHINT_DECNUM)) {
- ly_print_(ctx->out, "%s", attr->value[0] ? attr->value : "null");
+ ly_print_(pctx->out, "%s", attr->value[0] ? attr->value : "null");
} else if (attr->hints & LYD_VALHINT_EMPTY) {
- ly_print_(ctx->out, "[null]");
+ ly_print_(pctx->out, "[null]");
} else {
- json_print_string(ctx->out, attr->value);
+ json_print_string(pctx->out, attr->value);
}
LEVEL_PRINTED;
}
@@ -429,19 +429,19 @@
* @return LY_ERR value.
*/
static LY_ERR
-json_print_metadata(struct jsonpr_ctx *ctx, const struct lyd_node *node, const struct lys_module *wdmod)
+json_print_metadata(struct jsonpr_ctx *pctx, const struct lyd_node *node, const struct lys_module *wdmod)
{
struct lyd_meta *meta;
if (wdmod) {
- ly_print_(ctx->out, "%*s\"%s:default\":\"true\"", INDENT, wdmod->name);
+ ly_print_(pctx->out, "%*s\"%s:default\":\"true\"", INDENT, wdmod->name);
LEVEL_PRINTED;
}
for (meta = node->meta; meta; meta = meta->next) {
PRINT_COMMA;
- ly_print_(ctx->out, "%*s\"%s:%s\":%s", INDENT, meta->annotation->module->name, meta->name, DO_FORMAT ? " " : "");
- LY_CHECK_RET(json_print_value(ctx, &meta->value));
+ ly_print_(pctx->out, "%*s\"%s:%s\":%s", INDENT, meta->annotation->module->name, meta->name, DO_FORMAT ? " " : "");
+ LY_CHECK_RET(json_print_value(pctx, LYD_CTX(node), &meta->value));
LEVEL_PRINTED;
}
@@ -457,11 +457,11 @@
* @return LY_ERR value.
*/
static LY_ERR
-json_print_attributes(struct jsonpr_ctx *ctx, const struct lyd_node *node, ly_bool inner)
+json_print_attributes(struct jsonpr_ctx *pctx, const struct lyd_node *node, ly_bool inner)
{
const struct lys_module *wdmod = NULL;
- if ((node->flags & LYD_DEFAULT) && (ctx->options & (LYD_PRINT_WD_ALL_TAG | LYD_PRINT_WD_IMPL_TAG))) {
+ if ((node->flags & LYD_DEFAULT) && (pctx->options & (LYD_PRINT_WD_ALL_TAG | LYD_PRINT_WD_IMPL_TAG))) {
/* we have implicit OR explicit default node */
/* get with-defaults module */
wdmod = ly_ctx_get_module_implemented(LYD_CTX(node), "ietf-netconf-with-defaults");
@@ -469,28 +469,28 @@
if (node->schema && node->meta) {
if (inner) {
- LY_CHECK_RET(json_print_member2(ctx, NULL, LY_VALUE_JSON, NULL, 1));
+ LY_CHECK_RET(json_print_member2(pctx, NULL, LY_VALUE_JSON, NULL, 1));
} else {
- LY_CHECK_RET(json_print_member(ctx, node, 1));
+ LY_CHECK_RET(json_print_member(pctx, node, 1));
}
- ly_print_(ctx->out, "{%s", (DO_FORMAT ? "\n" : ""));
+ ly_print_(pctx->out, "{%s", (DO_FORMAT ? "\n" : ""));
LEVEL_INC;
- LY_CHECK_RET(json_print_metadata(ctx, node, wdmod));
+ LY_CHECK_RET(json_print_metadata(pctx, node, wdmod));
LEVEL_DEC;
- ly_print_(ctx->out, "%s%*s}", DO_FORMAT ? "\n" : "", INDENT);
+ ly_print_(pctx->out, "%s%*s}", DO_FORMAT ? "\n" : "", INDENT);
LEVEL_PRINTED;
} else if (!node->schema && ((struct lyd_node_opaq *)node)->attr) {
if (inner) {
- LY_CHECK_RET(json_print_member2(ctx, NULL, LY_VALUE_JSON, NULL, 1));
+ LY_CHECK_RET(json_print_member2(pctx, NULL, LY_VALUE_JSON, NULL, 1));
} else {
- LY_CHECK_RET(json_print_member2(ctx, node, ((struct lyd_node_opaq *)node)->format,
+ LY_CHECK_RET(json_print_member2(pctx, node, ((struct lyd_node_opaq *)node)->format,
&((struct lyd_node_opaq *)node)->name, 1));
}
- ly_print_(ctx->out, "{%s", (DO_FORMAT ? "\n" : ""));
+ ly_print_(pctx->out, "{%s", (DO_FORMAT ? "\n" : ""));
LEVEL_INC;
- LY_CHECK_RET(json_print_attribute(ctx, (struct lyd_node_opaq *)node, wdmod));
+ LY_CHECK_RET(json_print_attribute(pctx, (struct lyd_node_opaq *)node, wdmod));
LEVEL_DEC;
- ly_print_(ctx->out, "%s%*s}", DO_FORMAT ? "\n" : "", INDENT);
+ ly_print_(pctx->out, "%s%*s}", DO_FORMAT ? "\n" : "", INDENT);
LEVEL_PRINTED;
}
@@ -505,14 +505,14 @@
* @return LY_ERR value.
*/
static LY_ERR
-json_print_leaf(struct jsonpr_ctx *ctx, const struct lyd_node *node)
+json_print_leaf(struct jsonpr_ctx *pctx, const struct lyd_node *node)
{
- LY_CHECK_RET(json_print_member(ctx, node, 0));
- LY_CHECK_RET(json_print_value(ctx, &((const struct lyd_node_term *)node)->value));
+ LY_CHECK_RET(json_print_member(pctx, node, 0));
+ LY_CHECK_RET(json_print_value(pctx, LYD_CTX(node), &((const struct lyd_node_term *)node)->value));
LEVEL_PRINTED;
/* print attributes as sibling */
- json_print_attributes(ctx, node, 0);
+ json_print_attributes(pctx, node, 0);
return LY_SUCCESS;
}
@@ -525,7 +525,7 @@
* @return LY_ERR value.
*/
static LY_ERR
-json_print_any_content(struct jsonpr_ctx *ctx, struct lyd_node_any *any)
+json_print_any_content(struct jsonpr_ctx *pctx, struct lyd_node_any *any)
{
LY_ERR ret = LY_SUCCESS;
struct lyd_node *iter;
@@ -537,7 +537,7 @@
if (!any->value.tree) {
/* no content */
if (any->schema->nodetype == LYS_ANYXML) {
- ly_print_(ctx->out, "null");
+ ly_print_(pctx->out, "null");
}
return LY_SUCCESS;
}
@@ -549,7 +549,7 @@
prev_lo = ly_log_options(0);
/* try to parse it into a data tree */
- if (lyd_parse_data_mem(ctx->ctx, any->value.mem, LYD_LYB, parser_options, 0, &iter) == LY_SUCCESS) {
+ if (lyd_parse_data_mem(pctx->ctx, any->value.mem, LYD_LYB, parser_options, 0, &iter) == LY_SUCCESS) {
/* successfully parsed */
free(any->value.mem);
any->value.tree = iter;
@@ -564,46 +564,46 @@
case LYD_ANYDATA_DATATREE:
if (any->schema->nodetype == LYS_ANYXML) {
/* print always as a string */
- ly_print_(ctx->out, "\"%s", DO_FORMAT ? "\n" : "");
+ ly_print_(pctx->out, "\"%s", DO_FORMAT ? "\n" : "");
}
/* close opening tag and print data */
- prev_opts = ctx->options;
- ctx->options &= ~LYD_PRINT_WITHSIBLINGS;
+ prev_opts = pctx->options;
+ pctx->options &= ~LYD_PRINT_WITHSIBLINGS;
LY_LIST_FOR(any->value.tree, iter) {
- ret = json_print_node(ctx, iter);
+ ret = json_print_node(pctx, iter);
LY_CHECK_ERR_RET(ret, LEVEL_DEC, ret);
}
- ctx->options = prev_opts;
+ pctx->options = prev_opts;
if (any->schema->nodetype == LYS_ANYXML) {
/* terminate the string */
- ly_print_(ctx->out, "\"");
+ ly_print_(pctx->out, "\"");
}
break;
case LYD_ANYDATA_JSON:
/* print without escaping special characters */
if (any->schema->nodetype == LYS_ANYXML) {
/* print as a string */
- ly_print_(ctx->out, "\"%s\"", any->value.str);
+ ly_print_(pctx->out, "\"%s\"", any->value.str);
} else if (any->value.str[0]) {
/* print with indent */
- ly_print_(ctx->out, "%*s%s", INDENT, any->value.str);
+ ly_print_(pctx->out, "%*s%s", INDENT, any->value.str);
}
break;
case LYD_ANYDATA_STRING:
case LYD_ANYDATA_XML:
if (any->schema->nodetype == LYS_ANYXML) {
/* print as a string */
- ly_print_(ctx->out, "\"%s\"", any->value.str);
+ ly_print_(pctx->out, "\"%s\"", any->value.str);
break;
}
/* fallthrough */
case LYD_ANYDATA_LYB:
/* JSON and LYB format is not supported */
- LOGWRN(ctx->ctx, "Unable to print anydata content (type %d) as XML.", any->value_type);
+ LOGWRN(pctx->ctx, "Unable to print anydata content (type %d) as XML.", any->value_type);
break;
}
@@ -619,13 +619,13 @@
* @return LY_ERR value.
*/
static LY_ERR
-json_print_inner(struct jsonpr_ctx *ctx, const struct lyd_node *node)
+json_print_inner(struct jsonpr_ctx *pctx, const struct lyd_node *node)
{
struct lyd_node *child;
ly_bool has_content = 0;
LY_LIST_FOR(lyd_child(node), child) {
- if (ly_should_print(child, ctx->options)) {
+ if (ly_should_print(child, pctx->options)) {
break;
}
}
@@ -637,31 +637,31 @@
if ((node->schema && (node->schema->nodetype == LYS_LIST)) ||
(!node->schema && (((struct lyd_node_opaq *)node)->hints & LYD_NODEHINT_LIST))) {
- ly_print_(ctx->out, "%s%*s{%s", (is_open_array(ctx, node) && ctx->level_printed >= ctx->level) ?
+ ly_print_(pctx->out, "%s%*s{%s", (is_open_array(pctx, node) && (pctx->level_printed >= pctx->level)) ?
(DO_FORMAT ? ",\n" : ",") : "", INDENT, (DO_FORMAT && has_content) ? "\n" : "");
} else {
- ly_print_(ctx->out, "%s{%s", (is_open_array(ctx, node) && ctx->level_printed >= ctx->level) ? "," : "",
+ ly_print_(pctx->out, "%s{%s", (is_open_array(pctx, node) && (pctx->level_printed >= pctx->level)) ? "," : "",
(DO_FORMAT && has_content) ? "\n" : "");
}
LEVEL_INC;
- json_print_attributes(ctx, node, 1);
+ json_print_attributes(pctx, node, 1);
if (!node->schema || !(node->schema->nodetype & LYS_ANYDATA)) {
/* print children */
LY_LIST_FOR(lyd_child(node), child) {
- LY_CHECK_RET(json_print_node(ctx, child));
+ LY_CHECK_RET(json_print_node(pctx, child));
}
} else {
/* anydata */
- json_print_any_content(ctx, (struct lyd_node_any *)node);
+ json_print_any_content(pctx, (struct lyd_node_any *)node);
}
LEVEL_DEC;
if (DO_FORMAT && has_content) {
- ly_print_(ctx->out, "\n%*s}", INDENT);
+ ly_print_(pctx->out, "\n%*s}", INDENT);
} else {
- ly_print_(ctx->out, "}");
+ ly_print_(pctx->out, "}");
}
LEVEL_PRINTED;
@@ -676,10 +676,10 @@
* @return LY_ERR value.
*/
static int
-json_print_container(struct jsonpr_ctx *ctx, const struct lyd_node *node)
+json_print_container(struct jsonpr_ctx *pctx, const struct lyd_node *node)
{
- LY_CHECK_RET(json_print_member(ctx, node, 0));
- LY_CHECK_RET(json_print_inner(ctx, node));
+ LY_CHECK_RET(json_print_member(pctx, node, 0));
+ LY_CHECK_RET(json_print_inner(pctx, node));
return LY_SUCCESS;
}
@@ -692,14 +692,14 @@
* @return LY_ERR value.
*/
static int
-json_print_anyxml(struct jsonpr_ctx *ctx, const struct lyd_node *node)
+json_print_anyxml(struct jsonpr_ctx *pctx, const struct lyd_node *node)
{
- LY_CHECK_RET(json_print_member(ctx, node, 0));
- LY_CHECK_RET(json_print_any_content(ctx, (struct lyd_node_any *)node));
+ LY_CHECK_RET(json_print_member(pctx, node, 0));
+ LY_CHECK_RET(json_print_any_content(pctx, (struct lyd_node_any *)node));
LEVEL_PRINTED;
/* print attributes as sibling */
- json_print_attributes(ctx, node, 0);
+ json_print_attributes(pctx, node, 0);
return LY_SUCCESS;
}
@@ -712,14 +712,14 @@
* @return Whether it is the last printed instance or not.
*/
static ly_bool
-json_print_array_is_last_inst(struct jsonpr_ctx *ctx, const struct lyd_node *node)
+json_print_array_is_last_inst(struct jsonpr_ctx *pctx, const struct lyd_node *node)
{
- if (!is_open_array(ctx, node)) {
+ if (!is_open_array(pctx, node)) {
/* no array open */
return 0;
}
- if ((ctx->root == node) && !(ctx->options & LYD_PRINT_WITHSIBLINGS)) {
+ if ((pctx->root == node) && !(pctx->options & LYD_PRINT_WITHSIBLINGS)) {
/* the only printed instance */
return 1;
}
@@ -744,38 +744,38 @@
* @return LY_ERR value.
*/
static LY_ERR
-json_print_leaf_list(struct jsonpr_ctx *ctx, const struct lyd_node *node)
+json_print_leaf_list(struct jsonpr_ctx *pctx, const struct lyd_node *node)
{
- if (!is_open_array(ctx, node)) {
- LY_CHECK_RET(json_print_member(ctx, node, 0));
- LY_CHECK_RET(json_print_array_open(ctx, node));
+ if (!is_open_array(pctx, node)) {
+ LY_CHECK_RET(json_print_member(pctx, node, 0));
+ LY_CHECK_RET(json_print_array_open(pctx, node));
if (node->schema->nodetype == LYS_LEAFLIST) {
- ly_print_(ctx->out, "%*s", INDENT);
+ ly_print_(pctx->out, "%*s", INDENT);
}
} else if (node->schema->nodetype == LYS_LEAFLIST) {
- ly_print_(ctx->out, ",%s%*s", DO_FORMAT ? "\n" : "", INDENT);
+ ly_print_(pctx->out, ",%s%*s", DO_FORMAT ? "\n" : "", INDENT);
}
if (node->schema->nodetype == LYS_LIST) {
if (!lyd_child(node)) {
/* empty, e.g. in case of filter */
- ly_print_(ctx->out, "%s%snull", (ctx->level_printed >= ctx->level) ? "," : "", DO_FORMAT ? " " : "");
+ ly_print_(pctx->out, "%s%snull", (pctx->level_printed >= pctx->level) ? "," : "", DO_FORMAT ? " " : "");
LEVEL_PRINTED;
} else {
/* print list's content */
- LY_CHECK_RET(json_print_inner(ctx, node));
+ LY_CHECK_RET(json_print_inner(pctx, node));
}
} else {
assert(node->schema->nodetype == LYS_LEAFLIST);
- LY_CHECK_RET(json_print_value(ctx, &((const struct lyd_node_term *)node)->value));
+ LY_CHECK_RET(json_print_value(pctx, LYD_CTX(node), &((const struct lyd_node_term *)node)->value));
- if (node->meta && !ctx->print_sibling_metadata) {
- ctx->print_sibling_metadata = node;
+ if (node->meta && !pctx->print_sibling_metadata) {
+ pctx->print_sibling_metadata = node;
}
}
- if (json_print_array_is_last_inst(ctx, node)) {
- json_print_array_close(ctx);
+ if (json_print_array_is_last_inst(pctx, node)) {
+ json_print_array_close(pctx);
}
return LY_SUCCESS;
@@ -789,33 +789,33 @@
* @return LY_ERR value.
*/
static LY_ERR
-json_print_metadata_leaflist(struct jsonpr_ctx *ctx)
+json_print_metadata_leaflist(struct jsonpr_ctx *pctx)
{
const struct lyd_node *prev, *node, *iter;
- if (!ctx->print_sibling_metadata) {
+ if (!pctx->print_sibling_metadata) {
return LY_SUCCESS;
}
- for (node = ctx->print_sibling_metadata, prev = ctx->print_sibling_metadata->prev;
+ for (node = pctx->print_sibling_metadata, prev = pctx->print_sibling_metadata->prev;
prev->next && matching_node(node, prev);
node = prev, prev = node->prev) {}
/* node is the first instance of the leaf-list */
- LY_CHECK_RET(json_print_member(ctx, node, 1));
- ly_print_(ctx->out, "[%s", (DO_FORMAT ? "\n" : ""));
+ LY_CHECK_RET(json_print_member(pctx, node, 1));
+ ly_print_(pctx->out, "[%s", (DO_FORMAT ? "\n" : ""));
LEVEL_INC;
LY_LIST_FOR(node, iter) {
PRINT_COMMA;
if (iter->meta) {
- ly_print_(ctx->out, "%*s%s", INDENT, DO_FORMAT ? "{\n" : "{");
+ ly_print_(pctx->out, "%*s%s", INDENT, DO_FORMAT ? "{\n" : "{");
LEVEL_INC;
- LY_CHECK_RET(json_print_metadata(ctx, iter, NULL));
+ LY_CHECK_RET(json_print_metadata(pctx, iter, NULL));
LEVEL_DEC;
- ly_print_(ctx->out, "%s%*s}", DO_FORMAT ? "\n" : "", INDENT);
+ ly_print_(pctx->out, "%s%*s}", DO_FORMAT ? "\n" : "", INDENT);
} else {
- ly_print_(ctx->out, "null");
+ ly_print_(pctx->out, "null");
}
LEVEL_PRINTED;
if (!matching_node(iter, iter->next)) {
@@ -823,7 +823,7 @@
}
}
LEVEL_DEC;
- ly_print_(ctx->out, "%s%*s]", DO_FORMAT ? "\n" : "", INDENT);
+ ly_print_(pctx->out, "%s%*s]", DO_FORMAT ? "\n" : "", INDENT);
LEVEL_PRINTED;
return LY_SUCCESS;
@@ -837,7 +837,7 @@
* @return LY_ERR value.
*/
static LY_ERR
-json_print_opaq(struct jsonpr_ctx *ctx, const struct lyd_node_opaq *node)
+json_print_opaq(struct jsonpr_ctx *pctx, const struct lyd_node_opaq *node)
{
ly_bool first = 1, last = 1;
@@ -851,37 +851,37 @@
}
if (first) {
- LY_CHECK_RET(json_print_member2(ctx, lyd_parent(&node->node), node->format, &node->name, 0));
+ LY_CHECK_RET(json_print_member2(pctx, lyd_parent(&node->node), node->format, &node->name, 0));
if (node->hints & (LYD_NODEHINT_LIST | LYD_NODEHINT_LEAFLIST)) {
- LY_CHECK_RET(json_print_array_open(ctx, &node->node));
+ LY_CHECK_RET(json_print_array_open(pctx, &node->node));
}
if (node->hints & LYD_NODEHINT_LEAFLIST) {
- ly_print_(ctx->out, "%*s", INDENT);
+ ly_print_(pctx->out, "%*s", INDENT);
}
} else if (node->hints & LYD_NODEHINT_LEAFLIST) {
- ly_print_(ctx->out, ",%s%*s", DO_FORMAT ? "\n" : "", INDENT);
+ ly_print_(pctx->out, ",%s%*s", DO_FORMAT ? "\n" : "", INDENT);
}
if (node->child || (node->hints & LYD_NODEHINT_LIST)) {
- LY_CHECK_RET(json_print_inner(ctx, &node->node));
+ LY_CHECK_RET(json_print_inner(pctx, &node->node));
LEVEL_PRINTED;
} else {
if (node->hints & LYD_VALHINT_EMPTY) {
- ly_print_(ctx->out, "[null]");
+ ly_print_(pctx->out, "[null]");
} else if (node->hints & (LYD_VALHINT_BOOLEAN | LYD_VALHINT_DECNUM)) {
- ly_print_(ctx->out, "%s", node->value);
+ ly_print_(pctx->out, "%s", node->value);
} else {
/* string */
- ly_print_(ctx->out, "\"%s\"", node->value);
+ ly_print_(pctx->out, "\"%s\"", node->value);
}
LEVEL_PRINTED;
/* attributes */
- json_print_attributes(ctx, (const struct lyd_node *)node, 0);
+ json_print_attributes(pctx, (const struct lyd_node *)node, 0);
}
if (last && (node->hints & (LYD_NODEHINT_LIST | LYD_NODEHINT_LEAFLIST))) {
- json_print_array_close(ctx);
+ json_print_array_close(pctx);
LEVEL_PRINTED;
}
@@ -896,17 +896,17 @@
* @return LY_ERR value.
*/
static LY_ERR
-json_print_node(struct jsonpr_ctx *ctx, const struct lyd_node *node)
+json_print_node(struct jsonpr_ctx *pctx, const struct lyd_node *node)
{
- if (!ly_should_print(node, ctx->options)) {
- if (json_print_array_is_last_inst(ctx, node)) {
- json_print_array_close(ctx);
+ if (!ly_should_print(node, pctx->options)) {
+ if (json_print_array_is_last_inst(pctx, node)) {
+ json_print_array_close(pctx);
}
return LY_SUCCESS;
}
if (!node->schema) {
- LY_CHECK_RET(json_print_opaq(ctx, (const struct lyd_node_opaq *)node));
+ LY_CHECK_RET(json_print_opaq(pctx, (const struct lyd_node_opaq *)node));
} else {
switch (node->schema->nodetype) {
case LYS_RPC:
@@ -914,29 +914,29 @@
case LYS_NOTIF:
case LYS_ANYDATA:
case LYS_CONTAINER:
- LY_CHECK_RET(json_print_container(ctx, node));
+ LY_CHECK_RET(json_print_container(pctx, node));
break;
case LYS_LEAF:
- LY_CHECK_RET(json_print_leaf(ctx, node));
+ LY_CHECK_RET(json_print_leaf(pctx, node));
break;
case LYS_LEAFLIST:
case LYS_LIST:
- LY_CHECK_RET(json_print_leaf_list(ctx, node));
+ LY_CHECK_RET(json_print_leaf_list(pctx, node));
break;
case LYS_ANYXML:
- LY_CHECK_RET(json_print_anyxml(ctx, node));
+ LY_CHECK_RET(json_print_anyxml(pctx, node));
break;
default:
- LOGINT(node->schema->module->ctx);
+ LOGINT(pctx->ctx);
return EXIT_FAILURE;
}
}
- ctx->level_printed = ctx->level;
+ pctx->level_printed = pctx->level;
- if (ctx->print_sibling_metadata && !matching_node(node->next, ctx->print_sibling_metadata)) {
- json_print_metadata_leaflist(ctx);
- ctx->print_sibling_metadata = NULL;
+ if (pctx->print_sibling_metadata && !matching_node(node->next, pctx->print_sibling_metadata)) {
+ json_print_metadata_leaflist(pctx);
+ pctx->print_sibling_metadata = NULL;
}
return LY_SUCCESS;
@@ -946,7 +946,7 @@
json_print_data(struct ly_out *out, const struct lyd_node *root, uint32_t options)
{
const struct lyd_node *node;
- struct jsonpr_ctx ctx = {0};
+ struct jsonpr_ctx pctx = {0};
const char *delimiter = (options & LYD_PRINT_SHRINK) ? "" : "\n";
if (!root) {
@@ -955,19 +955,19 @@
return LY_SUCCESS;
}
- ctx.out = out;
- ctx.level = 1;
- ctx.level_printed = 0;
- ctx.options = options;
- ctx.ctx = LYD_CTX(root);
+ pctx.out = out;
+ pctx.level = 1;
+ pctx.level_printed = 0;
+ pctx.options = options;
+ pctx.ctx = LYD_CTX(root);
/* start */
- ly_print_(ctx.out, "{%s", delimiter);
+ ly_print_(pctx.out, "{%s", delimiter);
/* content */
LY_LIST_FOR(root, node) {
- ctx.root = node;
- LY_CHECK_RET(json_print_node(&ctx, node));
+ pctx.root = node;
+ LY_CHECK_RET(json_print_node(&pctx, node));
if (!(options & LYD_PRINT_WITHSIBLINGS)) {
break;
}
@@ -976,8 +976,8 @@
/* end */
ly_print_(out, "%s}%s", delimiter, delimiter);
- assert(!ctx.open.count);
- ly_set_erase(&ctx.open, NULL);
+ assert(!pctx.open.count);
+ ly_set_erase(&pctx.open, NULL);
ly_print_flush(out);
return LY_SUCCESS;