static void info_print_mnodes(FILE *f, struct ly_mnode *mnode, const char *label) { assert(strlen(label) < INDENT_LEN-1); fprintf(f, "%-*s", INDENT_LEN, label); if (mnode) { if (mnode->name) { fprintf(f, "%s \"%s\"\n", strnodetype(mnode->nodetype), mnode->name); } else { fprintf(f, "%s\n", (mnode->nodetype == LY_NODE_INPUT ? "input" : "output")); } mnode = mnode->next; for (; mnode; mnode = mnode->next) { if (mnode->name) { fprintf(f, "%*s%s \"%s\"\n", INDENT_LEN, "", strnodetype(mnode->nodetype), mnode->name); } else { fprintf(f, "%*s%s\n", INDENT_LEN, "", (mnode->nodetype == LY_NODE_INPUT ? "input" : "output")); } } } else { fprintf(f, "\n"); } }
static void info_print_mnodes_all(FILE *f, struct ly_module *mod) { int first = 1, i; struct ly_mnode *mnode; fprintf(f, "%-*s", INDENT_LEN, "Data: "); if (mod->data) { fprintf(f, "%s \"%s\"\n", strnodetype(mod->data->nodetype), mod->data->name); mnode = mod->data->next; first = 0; for (; mnode; mnode = mnode->next) { fprintf(f, "%*s%s \"%s\"\n", INDENT_LEN, "", strnodetype(mnode->nodetype), mnode->name); } } for (i = 0; i < mod->inc_size; ++i) { if (mod->inc[i].submodule->data) { if (first) { fprintf(f, "%s \"%s\"\n", strnodetype(mod->inc[i].submodule->data->nodetype), mod->inc[i].submodule->data->name); mnode = mod->inc[i].submodule->data->next; } else { mnode = mod->inc[i].submodule->data; } first = 0; for (; mnode; mnode = mnode->next) { fprintf(f, "%*s%s \"%s\"\n", INDENT_LEN, "", strnodetype(mnode->nodetype), mnode->name); } } } if (first) { fprintf(f, "\n"); } }
int lys_print_target(struct lyout *out, const struct lys_module *module, const char *target_schema_path, void (*clb_print_typedef)(struct lyout*, const struct lys_tpdf*, int*), void (*clb_print_identity)(struct lyout*, const struct lys_ident*, int*), void (*clb_print_feature)(struct lyout*, const struct lys_feature*, int*), void (*clb_print_type)(struct lyout*, const struct lys_type*, int*), void (*clb_print_grouping)(struct lyout*, const struct lys_node*, int*), void (*clb_print_container)(struct lyout*, const struct lys_node*, int*), void (*clb_print_choice)(struct lyout*, const struct lys_node*, int*), void (*clb_print_leaf)(struct lyout*, const struct lys_node*, int*), void (*clb_print_leaflist)(struct lyout*, const struct lys_node*, int*), void (*clb_print_list)(struct lyout*, const struct lys_node*, int*), void (*clb_print_anydata)(struct lyout*, const struct lys_node*, int*), void (*clb_print_case)(struct lyout*, const struct lys_node*, int*), void (*clb_print_notif)(struct lyout*, const struct lys_node*, int*), void (*clb_print_rpc)(struct lyout*, const struct lys_node*, int*), void (*clb_print_action)(struct lyout*, const struct lys_node*, int*), void (*clb_print_input)(struct lyout*, const struct lys_node*, int*), void (*clb_print_output)(struct lyout*, const struct lys_node*, int*)) { int rc, i, f = 1; char *spec_target = NULL; struct lys_node *target = NULL; struct lys_tpdf *tpdf = NULL; uint8_t tpdf_size = 0; if ((target_schema_path[0] == '/') || !strncmp(target_schema_path, "type/", 5)) { rc = resolve_absolute_schema_nodeid((target_schema_path[0] == '/' ? target_schema_path : target_schema_path + 4), module, LYS_ANY & ~(LYS_USES | LYS_AUGMENT | LYS_GROUPING), (const struct lys_node **)&target); if (rc || !target) { LOGERR(module->ctx, LY_EINVAL, "Target %s could not be resolved.", (target_schema_path[0] == '/' ? target_schema_path : target_schema_path + 4)); return EXIT_FAILURE; } } else if (!strncmp(target_schema_path, "grouping/", 9)) { /* cut the data part off */ if ((spec_target = strchr(target_schema_path + 9, '/'))) { /* HACK only temporary */ spec_target[0] = '\0'; ++spec_target; } rc = resolve_absolute_schema_nodeid(target_schema_path + 8, module, LYS_GROUPING, (const struct lys_node **)&target); if (rc || !target) { ly_print(out, "Grouping %s not found.\n", target_schema_path + 8); return EXIT_FAILURE; } } else if (!strncmp(target_schema_path, "typedef/", 8)) { if ((spec_target = strrchr(target_schema_path + 8, '/'))) { /* schema node typedef */ /* HACK only temporary */ spec_target[0] = '\0'; ++spec_target; rc = resolve_absolute_schema_nodeid(target_schema_path + 7, module, LYS_CONTAINER | LYS_LIST | LYS_NOTIF | LYS_RPC | LYS_ACTION, (const struct lys_node **)&target); if (rc || !target) { /* perhaps it's in a grouping */ rc = resolve_absolute_schema_nodeid(target_schema_path + 7, module, LYS_GROUPING, (const struct lys_node **)&target); } if (!rc && target) { switch (target->nodetype) { case LYS_CONTAINER: tpdf = ((struct lys_node_container *)target)->tpdf; tpdf_size = ((struct lys_node_container *)target)->tpdf_size; break; case LYS_LIST: tpdf = ((struct lys_node_list *)target)->tpdf; tpdf_size = ((struct lys_node_list *)target)->tpdf_size; break; case LYS_NOTIF: tpdf = ((struct lys_node_notif *)target)->tpdf; tpdf_size = ((struct lys_node_notif *)target)->tpdf_size; break; case LYS_RPC: case LYS_ACTION: tpdf = ((struct lys_node_rpc_action *)target)->tpdf; tpdf_size = ((struct lys_node_rpc_action *)target)->tpdf_size; break; case LYS_GROUPING: tpdf = ((struct lys_node_grp *)target)->tpdf; tpdf_size = ((struct lys_node_grp *)target)->tpdf_size; break; default: LOGINT(module->ctx); return EXIT_FAILURE; } } } else { /* module typedef */ spec_target = (char *)target_schema_path + 8; tpdf = module->tpdf; tpdf_size = module->tpdf_size; } for (i = 0; i < tpdf_size; ++i) { if (!strcmp(tpdf[i].name, spec_target)) { clb_print_typedef(out, &tpdf[i], &f); break; } } /* HACK return previous hack */ --spec_target; spec_target[0] = '/'; if (i == tpdf_size) { ly_print(out, "Typedef %s not found.\n", target_schema_path); return EXIT_FAILURE; } return EXIT_SUCCESS; } else if (!strncmp(target_schema_path, "identity/", 9)) { target_schema_path += 9; for (i = 0; i < (signed)module->ident_size; ++i) { if (!strcmp(module->ident[i].name, target_schema_path)) { break; } } if (i == (signed)module->ident_size) { ly_print(out, "Identity %s not found.\n", target_schema_path); return EXIT_FAILURE; } clb_print_identity(out, &module->ident[i], &f); return EXIT_SUCCESS; } else if (!strncmp(target_schema_path, "feature/", 8)) { target_schema_path += 8; for (i = 0; i < module->features_size; ++i) { if (!strcmp(module->features[i].name, target_schema_path)) { break; } } if (i == module->features_size) { ly_print(out, "Feature %s not found.\n", target_schema_path); return EXIT_FAILURE; } clb_print_feature(out, &module->features[i], &f); return EXIT_SUCCESS; } else { ly_print(out, "Target could not be resolved.\n"); return EXIT_FAILURE; } if (!strncmp(target_schema_path, "type/", 5)) { if (!(target->nodetype & (LYS_LEAF | LYS_LEAFLIST))) { LOGERR(module->ctx, LY_EINVAL, "Target is not a leaf or a leaf-list."); return EXIT_FAILURE; } clb_print_type(out, &((struct lys_node_leaf *)target)->type, &f); return EXIT_SUCCESS; } else if (!strncmp(target_schema_path, "grouping/", 9) && !spec_target) { clb_print_grouping(out, target, &f); return EXIT_SUCCESS; } /* find the node in the grouping */ if (spec_target) { rc = resolve_descendant_schema_nodeid(spec_target, target->child, LYS_NO_RPC_NOTIF_NODE, 0, (const struct lys_node **)&target); if (rc || !target) { ly_print(out, "Grouping %s child \"%s\" not found.\n", target_schema_path + 9, spec_target); return EXIT_FAILURE; } /* HACK return previous hack */ --spec_target; spec_target[0] = '/'; } switch (target->nodetype) { case LYS_CONTAINER: clb_print_container(out, target, &f); break; case LYS_CHOICE: clb_print_choice(out, target, &f); break; case LYS_LEAF: clb_print_leaf(out, target, &f); break; case LYS_LEAFLIST: clb_print_leaflist(out, target, &f); break; case LYS_LIST: clb_print_list(out, target, &f); break; case LYS_ANYXML: case LYS_ANYDATA: clb_print_anydata(out, target, &f); break; case LYS_CASE: clb_print_case(out, target, &f); break; case LYS_NOTIF: clb_print_notif(out, target, &f); break; case LYS_RPC: clb_print_rpc(out, target, &f); break; case LYS_ACTION: clb_print_action(out, target, &f); break; case LYS_INPUT: clb_print_input(out, target, &f); break; case LYS_OUTPUT: clb_print_output(out, target, &f); break; default: ly_print(out, "Nodetype %s not supported.\n", strnodetype(target->nodetype)); break; } return EXIT_SUCCESS; }
int info_print_model(FILE *f, struct ly_module *module, const char *target_node) { int i; struct ly_mnode *target; if (!target_node) { if (f == stdout) { fprintf(f, "\n"); } if (module->type == 0) { info_print_module(f, module); } else { info_print_submodule(f, (struct ly_submodule *)module); } } else { if ((target_node[0] == '/') || !strncmp(target_node, "type/", 5)) { target = resolve_schema_nodeid((target_node[0] == '/' ? target_node : target_node+4), module->data, module, LY_NODE_AUGMENT); if (!target) { fprintf(f, "Target %s could not be resolved.\n", (target_node[0] == '/' ? target_node : target_node+4)); return EXIT_FAILURE; } } else if (!strncmp(target_node, "typedef/", 8)) { target_node += 8; for (i = 0; i < module->tpdf_size; ++i) { if (!strcmp(module->tpdf[i].name, target_node)) { break; } } if (i == module->tpdf_size) { fprintf(f, "Typedef %s not found.\n", target_node); return EXIT_FAILURE; } if (f == stdout) { fprintf(f, "\n"); } info_print_typedef_detail(f, &module->tpdf[i]); return EXIT_SUCCESS; } else if (!strncmp(target_node, "identity/", 9)) { target_node += 9; for (i = 0; i < (signed)module->ident_size; ++i) { if (!strcmp(module->ident[i].name, target_node)) { break; } } if (i == (signed)module->ident_size) { fprintf(f, "Identity %s not found.\n", target_node); return EXIT_FAILURE; } if (f == stdout) { fprintf(f, "\n"); } info_print_ident_detail(f, &module->ident[i]); return EXIT_SUCCESS; } else if (!strncmp(target_node, "feature/", 8)) { target_node += 8; for (i = 0; i < module->features_size; ++i) { if (!strcmp(module->features[i].name, target_node)) { break; } } if (i == module->features_size) { fprintf(f, "Feature %s not found.\n", target_node); return EXIT_FAILURE; } if (f == stdout) { fprintf(f, "\n"); } info_print_feature_detail(f, &module->features[i]); return EXIT_SUCCESS; } else { fprintf(f, "Target could not be resolved.\n"); return EXIT_FAILURE; } if (target_node[0] != '/') { if (!(target->nodetype & (LY_NODE_LEAF | LY_NODE_LEAFLIST))) { fprintf(f, "Target is not a leaf or a leaf-list.\n"); return EXIT_FAILURE; } if (f == stdout) { fprintf(f, "\n"); } info_print_type_detail(f, &((struct ly_mnode_leaf *)target)->type); return EXIT_SUCCESS; } switch (target->nodetype) { case LY_NODE_CONTAINER: if (f == stdout) { fprintf(f, "\n"); } info_print_container(f, target); break; case LY_NODE_CHOICE: if (f == stdout) { fprintf(f, "\n"); } info_print_choice(f, target); break; case LY_NODE_LEAF: if (f == stdout) { fprintf(f, "\n"); } info_print_leaf(f, target); break; case LY_NODE_LEAFLIST: if (f == stdout) { fprintf(f, "\n"); } info_print_leaflist(f, target); break; case LY_NODE_LIST: if (f == stdout) { fprintf(f, "\n"); } info_print_list(f, target); break; case LY_NODE_ANYXML: if (f == stdout) { fprintf(f, "\n"); } info_print_anyxml(f, target); break; case LY_NODE_GROUPING: if (f == stdout) { fprintf(f, "\n"); } info_print_grouping(f, target); break; case LY_NODE_CASE: if (f == stdout) { fprintf(f, "\n"); } info_print_case(f, target); break; case LY_NODE_NOTIF: if (f == stdout) { fprintf(f, "\n"); } info_print_notif(f, target); break; case LY_NODE_RPC: if (f == stdout) { fprintf(f, "\n"); } info_print_rpc(f, target); break; case LY_NODE_INPUT: if (f == stdout) { fprintf(f, "\n"); } info_print_input(f, target); break; case LY_NODE_OUTPUT: if (f == stdout) { fprintf(f, "\n"); } info_print_output(f, target); break; default: fprintf(f, "Nodetype %s not supported.\n", strnodetype(target->nodetype)); break; } } return EXIT_SUCCESS; }