#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <libyang/libyang.h>
static LY_ERR
sm_ext_data_clb(const struct lysc_ext_instance *ext, const struct lyd_node *parent, void *user_data, void **ext_data,
ly_bool *ext_data_free)
{
static int recursive_call = 0;
LY_ERR r;
*ext_data = NULL;
*ext_data_free = 0;
if (recursive_call) {
return LY_SUCCESS;
}
recursive_call = 1;
r = lyd_parse_data_path(ext->module->ctx, "sm_oper_data.xml", LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT,
(struct lyd_node **)ext_data);
recursive_call = 0;
if (r) {
return r;
}
*ext_data_free = 1;
return LY_SUCCESS;
}
int
main(int argc, char **argv)
{
struct ly_ctx *ctx;
struct lyd_node *data;
const struct lys_module *mod;
ly_ctx_new(".", 0, &ctx);
mod = ly_ctx_load_module(ctx, "ietf-interfaces", NULL, NULL);
assert(mod);
mod = ly_ctx_load_module(ctx, "ietf-ip", NULL, NULL);
assert(mod);
mod = ly_ctx_load_module(ctx, "ietf-network-instance", NULL, NULL);
assert(mod);
ly_ctx_set_ext_data_clb(ctx, sm_ext_data_clb, NULL);
lyd_parse_data_path(ctx, "config_data.xml", LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, &data);
assert(data);
lyd_print_file(stdout, data, LYD_XML, 0);
lyd_free_siblings(data);
ly_ctx_destroy(ctx);
return 0;
}