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