schema compile CHANGE store default values as in lyd_value structure
Use the data trees's structure to store the default values even in
the compiled schema tree. It is necessary for default value validation
and useful for instanciating default nodes in data trees.
diff --git a/src/printer_yang.c b/src/printer_yang.c
index 445afc2..f3ff74b 100755
--- a/src/printer_yang.c
+++ b/src/printer_yang.c
@@ -26,6 +26,7 @@
#include "tree.h"
#include "tree_schema.h"
#include "tree_schema_internal.h"
+#include "plugins_types.h"
#include "xpath.h"
/**
@@ -898,6 +899,19 @@
}
static void
+yprc_dflt_value(struct ypr_ctx *ctx, const struct lyd_value *value, struct lysc_ext_instance *exts)
+{
+ int dynamic;
+ const char *str;
+
+ str = value->realtype->plugin->print(value, LYD_JSON, json_print_get_prefix, NULL, &dynamic);
+ ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, str, exts);
+ if (dynamic) {
+ free((void*)str);
+ }
+}
+
+static void
yprc_type(struct ypr_ctx *ctx, const struct lysc_type *type)
{
unsigned int u;
@@ -909,7 +923,7 @@
yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
if (type->dflt) {
ypr_open(ctx->out, &flag);
- ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, type->dflt, type->exts);
+ yprc_dflt_value(ctx, type->dflt, type->exts);
}
switch(type->basetype) {
@@ -1537,7 +1551,10 @@
LY_ARRAY_FOR(leaf->musts, u) {
yprc_must(ctx, &leaf->musts[u], NULL);
}
- ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts);
+
+ if (leaf->dflt) {
+ yprc_dflt_value(ctx, leaf->dflt, leaf->exts);
+ }
yprc_node_common2(ctx, node, NULL);
@@ -1601,7 +1618,7 @@
yprc_must(ctx, &llist->musts[u], NULL);
}
LY_ARRAY_FOR(llist->dflts, u) {
- ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts);
+ yprc_dflt_value(ctx, llist->dflts[u], llist->exts);
}
ypr_config(ctx, node->flags, node->exts, NULL);