Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file printer/tree.c |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief TREE printer for libyang data model structure |
| 5 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 7 | * |
Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame] | 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
Michal Vasko | 8de098c | 2016-02-26 10:00:25 +0100 | [diff] [blame] | 11 | * |
Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame] | 12 | * https://opensource.org/licenses/BSD-3-Clause |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <stdlib.h> |
| 16 | #include <stdio.h> |
| 17 | #include <string.h> |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 18 | #include <assert.h> |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 19 | |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 20 | #include "common.h" |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 21 | #include "printer.h" |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 22 | #include "tree_schema.h" |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 23 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 24 | /* spec_config = 0 (no special config status), 1 (read-only - rpc output, notification), 2 (write-only - rpc input) */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 25 | static void tree_print_choice_content(struct lyout *out, const struct lys_module* module, int level, char *indent, |
| 26 | unsigned int max_name_len, const struct lys_node *node, int mask, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 27 | int spec_config); |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 28 | static void tree_print_snode(struct lyout *out, const struct lys_module *module, int level, char *indent, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 29 | unsigned int max_name_len, const struct lys_node *node, int mask, int spec_config); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 30 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 31 | static int |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 32 | sibling_is_valid_child(const struct lys_node *node, int including, const struct lys_module *module) |
Michal Vasko | 6db4fce | 2015-06-08 14:13:49 +0200 | [diff] [blame] | 33 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 34 | struct lys_node *cur; |
Michal Vasko | 7ea0a31 | 2015-06-08 10:36:48 +0200 | [diff] [blame] | 35 | |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 36 | if (!node) { |
Michal Vasko | 07898f9 | 2015-06-15 12:17:11 +0200 | [diff] [blame] | 37 | return 0; |
| 38 | } |
Michal Vasko | 7ea0a31 | 2015-06-08 10:36:48 +0200 | [diff] [blame] | 39 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 40 | /* has a following printed child */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 41 | LY_TREE_FOR((struct lys_node *)(including ? node : node->next), cur) { |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 42 | if (module->type && (cur->module != module)) { |
| 43 | continue; |
| 44 | } |
| 45 | |
Michal Vasko | f6f18f4 | 2015-09-24 13:06:14 +0200 | [diff] [blame] | 46 | if (!lys_is_disabled(cur, 0)) { |
| 47 | if (cur->nodetype & (LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | LYS_ANYXML | LYS_CHOICE | |
Radek Krejci | 029e790 | 2015-12-10 13:20:55 +0100 | [diff] [blame] | 48 | LYS_INPUT | LYS_OUTPUT | LYS_CASE)) { |
Michal Vasko | f6f18f4 | 2015-09-24 13:06:14 +0200 | [diff] [blame] | 49 | return 1; |
| 50 | } |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 51 | if ((cur->nodetype == LYS_USES) && sibling_is_valid_child(cur->child, 1, module)) { |
Michal Vasko | f6f18f4 | 2015-09-24 13:06:14 +0200 | [diff] [blame] | 52 | return 1; |
| 53 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 54 | } |
| 55 | } |
Michal Vasko | 7ea0a31 | 2015-06-08 10:36:48 +0200 | [diff] [blame] | 56 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 57 | /* if in uses, the following printed child can actually be in the parent node :-/ */ |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 58 | if (node->parent && (node->parent->nodetype == LYS_USES)) { |
| 59 | return sibling_is_valid_child(node->parent, 0, module); |
Michal Vasko | 07898f9 | 2015-06-15 12:17:11 +0200 | [diff] [blame] | 60 | } |
| 61 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 62 | return 0; |
Michal Vasko | 7ea0a31 | 2015-06-08 10:36:48 +0200 | [diff] [blame] | 63 | } |
| 64 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 65 | static char * |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 66 | create_indent(int level, const char *old_indent, const struct lys_node *node, int shorthand, const struct lys_module *module) |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 67 | { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 68 | int next_is_case = 0, is_case = 0, has_next = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 69 | char *new_indent = malloc((level * 4 + 1) * sizeof (char)); |
Michal Vasko | 1441046 | 2015-06-05 15:08:54 +0200 | [diff] [blame] | 70 | |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 71 | if (!new_indent) { |
| 72 | LOGMEM; |
| 73 | return NULL; |
| 74 | } |
| 75 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 76 | strcpy(new_indent, old_indent); |
Michal Vasko | 1441046 | 2015-06-05 15:08:54 +0200 | [diff] [blame] | 77 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 78 | /* this is the indent of a case (standard or shorthand) */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 79 | if ((node->nodetype == LYS_CASE) || shorthand) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 80 | is_case = 1; |
| 81 | } |
Michal Vasko | 1441046 | 2015-06-05 15:08:54 +0200 | [diff] [blame] | 82 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 83 | /* this is the direct child of a case */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 84 | if (!is_case && node->parent && (node->parent->nodetype & (LYS_CASE | LYS_CHOICE))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 85 | /* it is not the only child */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 86 | if (node->next && node->next->parent && (node->next->parent->nodetype == LYS_CHOICE)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 87 | next_is_case = 1; |
| 88 | } |
| 89 | } |
Michal Vasko | 1441046 | 2015-06-05 15:08:54 +0200 | [diff] [blame] | 90 | |
Michal Vasko | 07898f9 | 2015-06-15 12:17:11 +0200 | [diff] [blame] | 91 | /* next is a node that will actually be printed */ |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 92 | has_next = sibling_is_valid_child(node, 0, module); |
Michal Vasko | 1441046 | 2015-06-05 15:08:54 +0200 | [diff] [blame] | 93 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 94 | if (has_next && !next_is_case) { |
| 95 | strcat(new_indent, "| "); |
| 96 | } else { |
| 97 | strcat(new_indent, " "); |
| 98 | } |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 99 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 100 | return new_indent; |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 101 | } |
| 102 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 103 | static unsigned int |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 104 | get_max_name_len(const struct lys_module *module, const struct lys_node *node) |
Michal Vasko | 8d479bd | 2015-06-05 10:50:03 +0200 | [diff] [blame] | 105 | { |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 106 | const struct lys_node *sub; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 107 | struct lys_module *mod; |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 108 | unsigned int max_name_len = 0, uses_max_name_len, name_len; |
Michal Vasko | 8d479bd | 2015-06-05 10:50:03 +0200 | [diff] [blame] | 109 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 110 | LY_TREE_FOR(node, sub) { |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 111 | if (module->type && (sub->module != module)) { |
| 112 | /* when printing submodule, we are only concerned with its own data (they are in the module data) */ |
| 113 | continue; |
| 114 | } |
| 115 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 116 | if (sub->nodetype == LYS_USES) { |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 117 | uses_max_name_len = get_max_name_len(module, sub->child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 118 | if (uses_max_name_len > max_name_len) { |
| 119 | max_name_len = uses_max_name_len; |
| 120 | } |
| 121 | } else if (sub->nodetype & |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 122 | (LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST |
| 123 | | LYS_ANYXML | LYS_CASE)) { |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 124 | mod = lys_node_module(sub); |
| 125 | name_len = strlen(sub->name) + (module == mod ? 0 : strlen(mod->name) + 1); |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 126 | if (name_len > max_name_len) { |
| 127 | max_name_len = name_len; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | } |
Michal Vasko | 8d479bd | 2015-06-05 10:50:03 +0200 | [diff] [blame] | 131 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 132 | return max_name_len; |
Michal Vasko | 8d479bd | 2015-06-05 10:50:03 +0200 | [diff] [blame] | 133 | } |
| 134 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 135 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 136 | tree_print_type(struct lyout *out, const struct lys_type *type) |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 137 | { |
Michal Vasko | 2d22b2d | 2015-09-24 13:53:31 +0200 | [diff] [blame] | 138 | if ((type->base == LY_TYPE_LEAFREF) && !type->der->module) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 139 | ly_print(out, "-> %s", type->info.lref.path); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 140 | } else if (type->module_name) { |
| 141 | ly_print(out, "%s:%s", type->module_name, type->der->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 142 | } else { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 143 | ly_print(out, "%s", type->der->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 144 | } |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 145 | } |
| 146 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 147 | static void |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 148 | tree_print_features(struct lyout *out, const struct lys_feature **features, uint8_t features_size) |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 149 | { |
| 150 | int i; |
| 151 | |
| 152 | if (!features_size) { |
| 153 | return; |
| 154 | } |
| 155 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 156 | ly_print(out, " {"); |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 157 | for (i = 0; i < features_size; i++) { |
| 158 | if (i > 0) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 159 | ly_print(out, ","); |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 160 | } |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 161 | ly_print(out, "%s", features[i]->name); |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 162 | } |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 163 | ly_print(out, "}?"); |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 167 | tree_print_inout(struct lyout *out, const struct lys_module *module, int level, char *indent, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 168 | const struct lys_node *node, int spec_config) |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 169 | { |
| 170 | unsigned int max_child_len; |
| 171 | char *new_indent; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 172 | struct lys_node *sub; |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 173 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 174 | assert(spec_config); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 175 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 176 | ly_print(out, "%s+--%s %s\n", indent, (spec_config == 1 ? "-w" : "ro"), (spec_config == 1 ? "input" : "output")); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 177 | |
| 178 | level++; |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 179 | new_indent = create_indent(level, indent, node, 0, module); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 180 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 181 | max_child_len = get_max_name_len(module, node->child); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 182 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 183 | LY_TREE_FOR(node->child, sub) { |
Michal Vasko | 3510f89 | 2016-02-15 14:33:52 +0100 | [diff] [blame] | 184 | /* submodule, foreign augments */ |
| 185 | if (module->type && (sub->parent != node) && (sub->module != module)) { |
| 186 | continue; |
| 187 | } |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 188 | tree_print_snode(out, module, level, new_indent, max_child_len, sub, |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 189 | LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | LYS_ANYXML | LYS_USES, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 190 | spec_config); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | free(new_indent); |
| 194 | } |
| 195 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 196 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 197 | tree_print_container(struct lyout *out, const struct lys_module *module, int level, char *indent, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 198 | const struct lys_node *node, int spec_config) |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 199 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 200 | unsigned int max_child_len; |
| 201 | char *new_indent; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 202 | struct lys_node_container *cont = (struct lys_node_container *)node; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 203 | struct lys_node *sub; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 204 | struct lys_module *nodemod; |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 205 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 206 | assert(spec_config >= 0 && spec_config <= 2); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 207 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 208 | ly_print(out, "%s%s--", indent, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 209 | (cont->flags & LYS_STATUS_DEPRC ? "x" : (cont->flags & LYS_STATUS_OBSLT ? "o" : "+"))); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 210 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 211 | if (spec_config == 0) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 212 | ly_print(out, "%s ", (cont->flags & LYS_CONFIG_W ? "rw" : "ro")); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 213 | } else if (spec_config == 1) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 214 | ly_print(out, "-w "); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 215 | } else if (spec_config == 2) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 216 | ly_print(out, "ro "); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 217 | } |
| 218 | |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 219 | nodemod = lys_node_module(node); |
| 220 | if (lys_module(module) != nodemod) { |
Radek Krejci | 662f1c0 | 2016-02-11 11:31:24 +0100 | [diff] [blame] | 221 | ly_print(out, "%s:", nodemod->name); |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 222 | } |
| 223 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 224 | ly_print(out, "%s%s", cont->name, (cont->presence ? "!" : "")); |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 225 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 226 | tree_print_features(out, (const struct lys_feature **)cont->features, cont->features_size); |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 227 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 228 | ly_print(out, "\n"); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 229 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 230 | level++; |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 231 | new_indent = create_indent(level, indent, node, 0, module); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 232 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 233 | max_child_len = get_max_name_len(module, node->child); |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 234 | |
Michal Vasko | 3510f89 | 2016-02-15 14:33:52 +0100 | [diff] [blame] | 235 | LY_TREE_FOR(node->child, sub) { |
| 236 | /* submodule, foreign augments */ |
| 237 | if (module->type && (sub->parent != node) && (sub->module != module)) { |
| 238 | continue; |
| 239 | } |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 240 | tree_print_snode(out, module, level, new_indent, max_child_len, sub, |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 241 | LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | LYS_ANYXML | LYS_USES, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 242 | spec_config); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 243 | } |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 244 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 245 | free(new_indent); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 246 | } |
| 247 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 248 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 249 | tree_print_choice(struct lyout *out, const struct lys_module *module, int level, char *indent, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 250 | const struct lys_node *node, int spec_config) |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 251 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 252 | unsigned int max_child_len; |
| 253 | char *new_indent; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 254 | struct lys_node_choice *choice = (struct lys_node_choice *)node; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 255 | struct lys_node *sub; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 256 | struct lys_module *nodemod; |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 257 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 258 | assert(spec_config >= 0 && spec_config <= 2); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 259 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 260 | ly_print(out, "%s%s--", indent, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 261 | (choice->flags & LYS_STATUS_DEPRC ? "x" : (choice->flags & LYS_STATUS_OBSLT ? "o" : "+"))); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 262 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 263 | if (spec_config == 0) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 264 | ly_print(out, "%s ", (choice->flags & LYS_CONFIG_W ? "rw" : "ro")); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 265 | } else if (spec_config == 1) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 266 | ly_print(out, "-w "); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 267 | } else if (spec_config == 2) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 268 | ly_print(out, "ro "); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 269 | } |
| 270 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 271 | ly_print(out, "("); |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 272 | |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 273 | nodemod = lys_node_module(node); |
| 274 | if (lys_module(module) != nodemod) { |
Radek Krejci | 662f1c0 | 2016-02-11 11:31:24 +0100 | [diff] [blame] | 275 | ly_print(out, "%s:", nodemod->name); |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 276 | } |
| 277 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 278 | ly_print(out, "%s)%s", choice->name, (choice->flags & LYS_MAND_TRUE ? "" : "?")); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 279 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 280 | if (choice->dflt != NULL) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 281 | ly_print(out, " <%s>", choice->dflt->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 282 | } |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 283 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 284 | tree_print_features(out, (const struct lys_feature **)choice->features, choice->features_size); |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 285 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 286 | ly_print(out, "\n"); |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 287 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 288 | level++; |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 289 | new_indent = create_indent(level, indent, node, 0, module); |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 290 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 291 | max_child_len = get_max_name_len(module, node->child); |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 292 | |
Michal Vasko | 3510f89 | 2016-02-15 14:33:52 +0100 | [diff] [blame] | 293 | LY_TREE_FOR(node->child, sub) { |
| 294 | /* submodule, foreign augments */ |
| 295 | if (module->type && (sub->parent != node) && (sub->module != module)) { |
| 296 | continue; |
| 297 | } |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 298 | tree_print_choice_content(out, module, level, new_indent, max_child_len, sub, |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 299 | LYS_CASE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | LYS_ANYXML, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 300 | spec_config); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 301 | } |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 302 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 303 | free(new_indent); |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 304 | } |
| 305 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 306 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 307 | tree_print_case(struct lyout *out, const struct lys_module *module, int level, char *indent, unsigned int max_name_len, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 308 | const struct lys_node *node, int shorthand, int spec_config) |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 309 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 310 | char *new_indent; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 311 | struct lys_node_case *cas = (struct lys_node_case *)node; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 312 | struct lys_node *sub; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 313 | struct lys_module *nodemod; |
Radek Krejci | 7e97c35 | 2015-06-19 16:26:34 +0200 | [diff] [blame] | 314 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 315 | ly_print(out, "%s%s--:(", indent, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 316 | (cas->flags & LYS_STATUS_DEPRC ? "x" : (cas->flags & LYS_STATUS_OBSLT ? "o" : "+"))); |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 317 | |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 318 | nodemod = lys_node_module(node); |
| 319 | if (lys_module(module) != nodemod) { |
Radek Krejci | 662f1c0 | 2016-02-11 11:31:24 +0100 | [diff] [blame] | 320 | ly_print(out, "%s:", nodemod->name); |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 321 | } |
| 322 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 323 | ly_print(out, "%s)", cas->name); |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 324 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 325 | tree_print_features(out, (const struct lys_feature **)cas->features, cas->features_size); |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 326 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 327 | ly_print(out, "\n"); |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 328 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 329 | level++; |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 330 | new_indent = create_indent(level, indent, node, shorthand, module); |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 331 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 332 | if (shorthand) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 333 | tree_print_snode(out, module, level, new_indent, max_name_len, node, |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 334 | LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | LYS_ANYXML | LYS_USES, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 335 | spec_config); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 336 | } else { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 337 | LY_TREE_FOR(node->child, sub) { |
Michal Vasko | 3510f89 | 2016-02-15 14:33:52 +0100 | [diff] [blame] | 338 | /* submodule, foreign augments */ |
| 339 | if (module->type && (sub->parent != node) && (sub->module != module)) { |
| 340 | continue; |
| 341 | } |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 342 | tree_print_snode(out, module, level, new_indent, max_name_len, sub, |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 343 | LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | LYS_ANYXML | LYS_USES, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 344 | spec_config); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 345 | } |
| 346 | } |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 347 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 348 | free(new_indent); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 349 | } |
| 350 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 351 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 352 | tree_print_anyxml(struct lyout *out, const struct lys_module *module, char *indent, unsigned int max_name_len, |
| 353 | const struct lys_node *node, int spec_config) |
Michal Vasko | 315f70b | 2015-06-05 10:48:59 +0200 | [diff] [blame] | 354 | { |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 355 | uint8_t prefix_len; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 356 | struct lys_module *nodemod; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 357 | struct lys_node_anyxml *anyxml = (struct lys_node_anyxml *)node; |
Michal Vasko | 315f70b | 2015-06-05 10:48:59 +0200 | [diff] [blame] | 358 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 359 | assert(spec_config >= 0 && spec_config <= 2); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 360 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 361 | ly_print(out, "%s%s--", indent, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 362 | (anyxml->flags & LYS_STATUS_DEPRC ? "x" : (anyxml->flags & LYS_STATUS_OBSLT ? "o" : "+"))); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 363 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 364 | if (spec_config == 0) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 365 | ly_print(out, "%s ", (anyxml->flags & LYS_CONFIG_W ? "rw" : "ro")); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 366 | } else if (spec_config == 1) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 367 | ly_print(out, "-w "); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 368 | } else if (spec_config == 2) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 369 | ly_print(out, "ro "); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 370 | } |
| 371 | |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 372 | prefix_len = 0; |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 373 | nodemod = lys_node_module(node); |
| 374 | if (lys_module(module) != nodemod) { |
Radek Krejci | 662f1c0 | 2016-02-11 11:31:24 +0100 | [diff] [blame] | 375 | ly_print(out, "%s:", nodemod->name); |
| 376 | prefix_len = strlen(nodemod->name)+1; |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 377 | } |
| 378 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 379 | ly_print(out, "%s%s%*sanyxml", anyxml->name, (anyxml->flags & LYS_MAND_TRUE ? " " : "?"), |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 380 | 3 + (int)((max_name_len - strlen(anyxml->name)) - prefix_len), " "); |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 381 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 382 | tree_print_features(out, (const struct lys_feature **)anyxml->features, anyxml->features_size); |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 383 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 384 | ly_print(out, "\n"); |
Michal Vasko | 315f70b | 2015-06-05 10:48:59 +0200 | [diff] [blame] | 385 | } |
| 386 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 387 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 388 | tree_print_leaf(struct lyout *out, const struct lys_module *module, char *indent, unsigned int max_name_len, |
| 389 | const struct lys_node *node, int spec_config) |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 390 | { |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 391 | uint8_t prefix_len; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 392 | struct lys_node_leaf *leaf = (struct lys_node_leaf *)node; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 393 | struct lys_node *parent; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 394 | struct lys_node_list *list; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 395 | struct lys_module *nodemod; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 396 | int i, is_key = 0; |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 397 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 398 | assert(spec_config >= 0 && spec_config <= 2); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 399 | |
Radek Krejci | 69372e2 | 2015-08-13 09:55:27 +0200 | [diff] [blame] | 400 | /* get know if the leaf is a key in a list, in that case it is |
| 401 | * mandatory by default */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 402 | for (parent = leaf->parent; parent && parent->nodetype == LYS_USES; parent = parent->parent); |
Radek Krejci | 69372e2 | 2015-08-13 09:55:27 +0200 | [diff] [blame] | 403 | if (parent && parent->nodetype == LYS_LIST) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 404 | list = (struct lys_node_list *)parent; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 405 | for (i = 0; i < list->keys_size; i++) { |
Michal Vasko | 96929d9 | 2015-08-03 15:30:22 +0200 | [diff] [blame] | 406 | if (list->keys[i] == leaf) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 407 | is_key = 1; |
| 408 | break; |
| 409 | } |
| 410 | } |
| 411 | } |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 412 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 413 | ly_print(out, "%s%s--", indent, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 414 | (leaf->flags & LYS_STATUS_DEPRC ? "x" : (leaf->flags & LYS_STATUS_OBSLT ? "o" : "+"))); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 415 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 416 | if (spec_config == 0) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 417 | ly_print(out, "%s ", (leaf->flags & LYS_CONFIG_W ? "rw" : "ro")); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 418 | } else if (spec_config == 1) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 419 | ly_print(out, "-w "); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 420 | } else if (spec_config == 2) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 421 | ly_print(out, "ro "); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 422 | } |
| 423 | |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 424 | prefix_len = 0; |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 425 | nodemod = lys_node_module(node); |
| 426 | if (lys_module(module) != nodemod) { |
Radek Krejci | 662f1c0 | 2016-02-11 11:31:24 +0100 | [diff] [blame] | 427 | ly_print(out, "%s:", nodemod->name); |
| 428 | prefix_len = strlen(nodemod->name)+1; |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 429 | } |
| 430 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 431 | ly_print(out, "%s%s%*s", leaf->name, ((leaf->flags & LYS_MAND_TRUE) || is_key ? " " : "?"), |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 432 | 3 + (int)((max_name_len - strlen(leaf->name)) - prefix_len), " "); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 433 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 434 | tree_print_type(out, &leaf->type); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 435 | |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 436 | if (leaf->dflt) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 437 | ly_print(out, " <%s>", leaf->dflt); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 438 | } |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 439 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 440 | tree_print_features(out, (const struct lys_feature **)leaf->features, leaf->features_size); |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 441 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 442 | ly_print(out, "\n"); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 443 | } |
| 444 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 445 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 446 | tree_print_leaflist(struct lyout *out, const struct lys_module *module, char *indent, unsigned int max_name_len, |
| 447 | const struct lys_node *node, int spec_config) |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 448 | { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 449 | struct lys_node_leaflist *leaflist = (struct lys_node_leaflist *)node; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 450 | struct lys_module *nodemod; |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 451 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 452 | assert(spec_config >= 0 && spec_config <= 2); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 453 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 454 | ly_print(out, "%s%s--", indent, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 455 | (leaflist->flags & LYS_STATUS_DEPRC ? "x" : (leaflist->flags & LYS_STATUS_OBSLT ? "o" : "+"))); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 456 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 457 | if (spec_config == 0) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 458 | ly_print(out, "%s ", (leaflist->flags & LYS_CONFIG_W ? "rw" : "ro")); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 459 | } else if (spec_config == 1) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 460 | ly_print(out, "-w "); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 461 | } else if (spec_config == 2) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 462 | ly_print(out, "ro "); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 463 | } |
| 464 | |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 465 | nodemod = lys_node_module(node); |
| 466 | if (lys_module(module) != nodemod) { |
Radek Krejci | 662f1c0 | 2016-02-11 11:31:24 +0100 | [diff] [blame] | 467 | ly_print(out, "%s:", nodemod->name); |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 468 | } |
| 469 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 470 | ly_print(out, "%s*%*s", leaflist->name, 3 + (int)(max_name_len - strlen(leaflist->name)), " "); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 471 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 472 | tree_print_type(out, &leaflist->type); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 473 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 474 | tree_print_features(out, (const struct lys_feature **)leaflist->features, leaflist->features_size); |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 475 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 476 | ly_print(out, "\n"); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 477 | } |
| 478 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 479 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 480 | tree_print_list(struct lyout *out, const struct lys_module *module, int level, char *indent, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 481 | const struct lys_node *node, int spec_config) |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 482 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 483 | int i; |
| 484 | unsigned int max_child_len; |
| 485 | char *new_indent; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 486 | struct lys_node *sub; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 487 | struct lys_node_list *list = (struct lys_node_list *)node; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 488 | struct lys_module *nodemod; |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 489 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 490 | ly_print(out, "%s%s--", indent, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 491 | (list->flags & LYS_STATUS_DEPRC ? "x" : (list->flags & LYS_STATUS_OBSLT ? "o" : "+"))); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 492 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 493 | if (spec_config == 0) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 494 | ly_print(out, "%s ", (list->flags & LYS_CONFIG_W ? "rw" : "ro")); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 495 | } else if (spec_config == 1) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 496 | ly_print(out, "-w "); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 497 | } else if (spec_config == 2) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 498 | ly_print(out, "ro "); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 499 | } |
| 500 | |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 501 | nodemod = lys_node_module(node); |
| 502 | if (lys_module(module) != nodemod) { |
Radek Krejci | 662f1c0 | 2016-02-11 11:31:24 +0100 | [diff] [blame] | 503 | ly_print(out, "%s:", nodemod->name); |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 504 | } |
| 505 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 506 | ly_print(out, "%s*", list->name); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 507 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 508 | for (i = 0; i < list->keys_size; i++) { |
| 509 | if (i == 0) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 510 | ly_print(out, " ["); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 511 | } |
Radek Krejci | f396653 | 2015-12-09 14:19:35 +0100 | [diff] [blame] | 512 | ly_print(out, "%s%s", list->keys[i]->name, i + 1 < list->keys_size ? " " : "]"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 513 | } |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 514 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 515 | tree_print_features(out, (const struct lys_feature **)list->features, list->features_size); |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 516 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 517 | ly_print(out, "\n"); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 518 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 519 | level++; |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 520 | new_indent = create_indent(level, indent, node, 0, module); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 521 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 522 | max_child_len = get_max_name_len(module, node->child); |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 523 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 524 | LY_TREE_FOR(node->child, sub) { |
Michal Vasko | 3510f89 | 2016-02-15 14:33:52 +0100 | [diff] [blame] | 525 | /* submodule, foreign augments */ |
| 526 | if (module->type && (sub->parent != node) && (sub->module != module)) { |
| 527 | continue; |
| 528 | } |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 529 | tree_print_snode(out, module, level, new_indent, max_child_len, sub, |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 530 | LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | LYS_USES | LYS_ANYXML, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 531 | spec_config); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 532 | } |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 533 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 534 | free(new_indent); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 535 | } |
| 536 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 537 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 538 | tree_print_uses(struct lyout *out, const struct lys_module *module, int level, char *indent, unsigned int max_name_len, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 539 | const struct lys_node *node, int spec_config) |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 540 | { |
Michal Vasko | 3510f89 | 2016-02-15 14:33:52 +0100 | [diff] [blame] | 541 | struct lys_node *sub; |
Radek Krejci | 7e97c35 | 2015-06-19 16:26:34 +0200 | [diff] [blame] | 542 | |
Michal Vasko | 3510f89 | 2016-02-15 14:33:52 +0100 | [diff] [blame] | 543 | LY_TREE_FOR(node->child, sub) { |
| 544 | tree_print_snode(out, module, level, indent, max_name_len, sub, |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 545 | LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | LYS_USES | LYS_ANYXML, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 546 | spec_config); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 547 | } |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 548 | } |
| 549 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 550 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 551 | tree_print_rpc(struct lyout *out, const struct lys_module *module, int level, char *indent, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 552 | const struct lys_node *node) |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 553 | { |
| 554 | char *new_indent; |
Michal Vasko | 3510f89 | 2016-02-15 14:33:52 +0100 | [diff] [blame] | 555 | struct lys_node *sub; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 556 | struct lys_node_rpc *rpc = (struct lys_node_rpc *)node; |
Radek Krejci | 7e97c35 | 2015-06-19 16:26:34 +0200 | [diff] [blame] | 557 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 558 | if (lys_is_disabled(node, 0)) { |
Michal Vasko | efbb319 | 2015-07-08 10:35:00 +0200 | [diff] [blame] | 559 | return; |
Radek Krejci | 7e97c35 | 2015-06-19 16:26:34 +0200 | [diff] [blame] | 560 | } |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 561 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 562 | ly_print(out, "%s%s---x %s", indent, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 563 | (rpc->flags & LYS_STATUS_DEPRC ? "x" : (rpc->flags & LYS_STATUS_OBSLT ? "o" : "+")), rpc->name); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 564 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 565 | tree_print_features(out, (const struct lys_feature **)rpc->features, rpc->features_size); |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 566 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 567 | ly_print(out, "\n"); |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 568 | |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 569 | level++; |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 570 | new_indent = create_indent(level, indent, node, 0, module); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 571 | |
Michal Vasko | 3510f89 | 2016-02-15 14:33:52 +0100 | [diff] [blame] | 572 | LY_TREE_FOR(node->child, sub) { |
| 573 | /* submodule, foreign augments */ |
| 574 | if (module->type && (sub->parent != node) && (sub->module != module)) { |
| 575 | continue; |
| 576 | } |
| 577 | if (sub->nodetype == LYS_INPUT) { |
| 578 | tree_print_inout(out, module, level, new_indent, sub, 1); |
| 579 | } else if (sub->nodetype == LYS_OUTPUT) { |
| 580 | tree_print_inout(out, module, level, new_indent, sub, 2); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 581 | } |
| 582 | } |
| 583 | |
| 584 | free(new_indent); |
| 585 | } |
| 586 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 587 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 588 | tree_print_notif(struct lyout *out, const struct lys_module *module, int level, char *indent, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 589 | const struct lys_node *node) |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 590 | { |
| 591 | unsigned int max_child_len; |
| 592 | char *new_indent; |
Michal Vasko | 3510f89 | 2016-02-15 14:33:52 +0100 | [diff] [blame] | 593 | struct lys_node *sub; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 594 | struct lys_node_notif *notif = (struct lys_node_notif *)node; |
Radek Krejci | 7e97c35 | 2015-06-19 16:26:34 +0200 | [diff] [blame] | 595 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 596 | if (lys_is_disabled(node, 0)) { |
Michal Vasko | efbb319 | 2015-07-08 10:35:00 +0200 | [diff] [blame] | 597 | return; |
Radek Krejci | 7e97c35 | 2015-06-19 16:26:34 +0200 | [diff] [blame] | 598 | } |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 599 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 600 | ly_print(out, "%s%s---n %s", indent, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 601 | (notif->flags & LYS_STATUS_DEPRC ? "x" : (notif->flags & LYS_STATUS_OBSLT ? "o" : "+")), |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 602 | notif->name); |
| 603 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 604 | tree_print_features(out, (const struct lys_feature **)notif->features, notif->features_size); |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 605 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 606 | ly_print(out, "\n"); |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 607 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 608 | level++; |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 609 | new_indent = create_indent(level, indent, node, 0, module); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 610 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 611 | max_child_len = get_max_name_len(module, node->child); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 612 | |
Michal Vasko | 3510f89 | 2016-02-15 14:33:52 +0100 | [diff] [blame] | 613 | LY_TREE_FOR(node->child, sub) { |
| 614 | /* submodule, foreign augments */ |
| 615 | if (module->type && (sub->parent != node) && (sub->module != module)) { |
| 616 | continue; |
| 617 | } |
| 618 | tree_print_snode(out, module, level, new_indent, max_child_len, sub, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 619 | LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | LYS_ANYXML | LYS_USES, 2); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | free(new_indent); |
| 623 | } |
| 624 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 625 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 626 | tree_print_choice_content(struct lyout *out, const struct lys_module *module, int level, char *indent, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 627 | unsigned int max_name_len, const struct lys_node *node, int mask, int spec_config) |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 628 | { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 629 | if (lys_is_disabled(node, 0)) { |
Michal Vasko | efbb319 | 2015-07-08 10:35:00 +0200 | [diff] [blame] | 630 | return; |
| 631 | } |
| 632 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 633 | if (node->nodetype & mask) { |
| 634 | if (node->nodetype == LYS_CASE) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 635 | tree_print_case(out, module, level, indent, max_name_len, node, 0, spec_config); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 636 | } else { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 637 | tree_print_case(out, module, level, indent, max_name_len, node, 1, spec_config); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 638 | } |
| 639 | } |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 640 | } |
| 641 | |
Michal Vasko | c176b68 | 2015-12-09 14:30:14 +0100 | [diff] [blame] | 642 | /* spec_config = 0 (no special config status), 1 (read-only - rpc output, notification), 2 (write-only - rpc input) */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 643 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 644 | tree_print_snode(struct lyout *out, const struct lys_module *module, int level, char *indent, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 645 | unsigned int max_name_len, const struct lys_node *node, int mask, int spec_config) |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 646 | { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 647 | if (lys_is_disabled(node, 0)) { |
Michal Vasko | efbb319 | 2015-07-08 10:35:00 +0200 | [diff] [blame] | 648 | return; |
Radek Krejci | 87e840c | 2015-06-19 16:44:54 +0200 | [diff] [blame] | 649 | } |
| 650 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 651 | switch (node->nodetype & mask) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 652 | case LYS_CONTAINER: |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 653 | tree_print_container(out, module, level, indent, node, spec_config); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 654 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 655 | case LYS_CHOICE: |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 656 | tree_print_choice(out, module, level, indent, node, spec_config); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 657 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 658 | case LYS_LEAF: |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 659 | tree_print_leaf(out, module, indent, max_name_len, node, spec_config); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 660 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 661 | case LYS_LEAFLIST: |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 662 | tree_print_leaflist(out, module, indent, max_name_len, node, spec_config); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 663 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 664 | case LYS_LIST: |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 665 | tree_print_list(out, module, level, indent, node, spec_config); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 666 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 667 | case LYS_ANYXML: |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 668 | tree_print_anyxml(out, module, indent, max_name_len, node, spec_config); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 669 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 670 | case LYS_USES: |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 671 | tree_print_uses(out, module, level, indent, max_name_len, node, spec_config); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 672 | break; |
Michal Vasko | d4742e6 | 2016-02-15 15:11:55 +0100 | [diff] [blame] | 673 | case LYS_CASE: |
| 674 | /* a very special case of cases in an augment */ |
| 675 | tree_print_case(out, module, level, indent, max_name_len, node, 0, spec_config); |
| 676 | break; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 677 | default: |
| 678 | break; |
| 679 | } |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 680 | } |
| 681 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 682 | int |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 683 | tree_print_model(struct lyout *out, const struct lys_module *module) |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 684 | { |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 685 | struct lys_node *node, *data; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 686 | unsigned int max_child_len; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 687 | int level = 1, have_rpcs = 0, have_notifs = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 688 | char *indent = malloc((level * 4 + 1) * sizeof (char)); |
Radek Krejci | d49202f | 2016-02-11 12:53:39 +0100 | [diff] [blame] | 689 | int i; |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 690 | |
| 691 | if (!indent) { |
| 692 | LOGMEM; |
| 693 | return EXIT_FAILURE; |
| 694 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 695 | strcpy(indent, " "); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 696 | |
Michal Vasko | fc6ac17 | 2015-07-07 09:46:46 +0200 | [diff] [blame] | 697 | if (module->type) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 698 | ly_print(out, "submodule: %s (belongs-to %s)\n", module->name, |
| 699 | ((struct lys_submodule *)module)->belongsto->name); |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 700 | data = ((struct lys_submodule *)module)->belongsto->data; |
Michal Vasko | fc6ac17 | 2015-07-07 09:46:46 +0200 | [diff] [blame] | 701 | } else { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 702 | ly_print(out, "module: %s\n", module->name); |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 703 | data = module->data; |
Michal Vasko | fc6ac17 | 2015-07-07 09:46:46 +0200 | [diff] [blame] | 704 | } |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 705 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 706 | /* module */ |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 707 | max_child_len = get_max_name_len(module, data); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 708 | level++; |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 709 | |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 710 | LY_TREE_FOR(data, node) { |
| 711 | if (module->type && (node->module != module)) { |
| 712 | /* we're printing the submodule only */ |
| 713 | continue; |
| 714 | } |
| 715 | |
Radek Krejci | 9272055 | 2015-10-05 15:28:27 +0200 | [diff] [blame] | 716 | switch(node->nodetype) { |
| 717 | case LYS_RPC: |
Radek Krejci | adf7a8e | 2015-12-10 13:11:17 +0100 | [diff] [blame] | 718 | if (!lys_is_disabled(node, 0)) { |
| 719 | have_rpcs++; |
| 720 | } |
Radek Krejci | 9272055 | 2015-10-05 15:28:27 +0200 | [diff] [blame] | 721 | break; |
| 722 | case LYS_NOTIF: |
Radek Krejci | adf7a8e | 2015-12-10 13:11:17 +0100 | [diff] [blame] | 723 | if (!lys_is_disabled(node, 0)) { |
| 724 | have_notifs++; |
| 725 | } |
Radek Krejci | 9272055 | 2015-10-05 15:28:27 +0200 | [diff] [blame] | 726 | break; |
| 727 | default: |
Radek Krejci | bac8176 | 2015-10-09 10:19:52 +0200 | [diff] [blame] | 728 | tree_print_snode(out, module, level, indent, max_child_len, node, |
Radek Krejci | 9272055 | 2015-10-05 15:28:27 +0200 | [diff] [blame] | 729 | LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 730 | | LYS_ANYXML | LYS_USES, 0); |
Radek Krejci | 9272055 | 2015-10-05 15:28:27 +0200 | [diff] [blame] | 731 | break; |
| 732 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 733 | } |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 734 | |
Radek Krejci | d49202f | 2016-02-11 12:53:39 +0100 | [diff] [blame] | 735 | /* augment */ |
| 736 | for (i = 0; i < module->augment_size; i++) { |
Michal Vasko | 861ee6d | 2016-02-15 15:11:31 +0100 | [diff] [blame] | 737 | if ((module->type && (module->augment[i].target->module == module)) |
| 738 | || (!module->type && (lys_node_module(module->augment[i].target) == module))) { |
Michal Vasko | e79abe8 | 2016-02-15 12:33:23 +0100 | [diff] [blame] | 739 | /* submodule, target is our submodule or module, target is in our module or any submodules */ |
| 740 | continue; |
| 741 | } |
| 742 | |
Radek Krejci | d49202f | 2016-02-11 12:53:39 +0100 | [diff] [blame] | 743 | ly_print(out, "augment %s:\n", module->augment[i].target_name); |
| 744 | LY_TREE_FOR(module->augment[i].child, node) { |
Michal Vasko | d4742e6 | 2016-02-15 15:11:55 +0100 | [diff] [blame] | 745 | /* submodule, foreign augments */ |
| 746 | if (module->type && (node->module != module)) { |
| 747 | continue; |
| 748 | } |
Radek Krejci | d49202f | 2016-02-11 12:53:39 +0100 | [diff] [blame] | 749 | tree_print_snode(out, module, level, indent, max_child_len, node, |
Michal Vasko | d4742e6 | 2016-02-15 15:11:55 +0100 | [diff] [blame] | 750 | LYS_CHOICE | LYS_CASE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST |
| 751 | | LYS_LIST | LYS_ANYXML | LYS_USES, 0); |
Radek Krejci | d49202f | 2016-02-11 12:53:39 +0100 | [diff] [blame] | 752 | } |
| 753 | } |
| 754 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 755 | /* rpc */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 756 | if (have_rpcs) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 757 | ly_print(out, "rpcs:\n"); |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 758 | LY_TREE_FOR(data, node) { |
Radek Krejci | 9272055 | 2015-10-05 15:28:27 +0200 | [diff] [blame] | 759 | if (!have_rpcs) { |
| 760 | break; |
| 761 | } |
| 762 | if (node->nodetype == LYS_RPC) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 763 | tree_print_rpc(out, module, level, indent, node); |
Radek Krejci | 9272055 | 2015-10-05 15:28:27 +0200 | [diff] [blame] | 764 | have_rpcs--; |
| 765 | } |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 766 | } |
| 767 | } |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 768 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 769 | /* notification */ |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 770 | if (have_notifs) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 771 | ly_print(out, "notifications:\n"); |
Michal Vasko | bda3719 | 2016-02-15 11:09:13 +0100 | [diff] [blame] | 772 | LY_TREE_FOR(data, node) { |
Radek Krejci | 9272055 | 2015-10-05 15:28:27 +0200 | [diff] [blame] | 773 | if (!have_notifs) { |
| 774 | break; |
| 775 | } |
| 776 | if (node->nodetype == LYS_NOTIF) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 777 | tree_print_notif(out, module, level, indent, node); |
Radek Krejci | 9272055 | 2015-10-05 15:28:27 +0200 | [diff] [blame] | 778 | have_notifs--; |
| 779 | } |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 780 | } |
| 781 | } |
Michal Vasko | 95068c4 | 2016-03-24 14:58:11 +0100 | [diff] [blame^] | 782 | ly_print_flush(out); |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 783 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 784 | free(indent); |
| 785 | return EXIT_SUCCESS; |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 786 | } |