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