Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 1 | /** |
| 2 | * @file parser_yang.h |
| 3 | * @author Pavol Vican |
| 4 | * @brief Parsers for libyang |
| 5 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 7 | * |
Pavol Vican | 9a3a721 | 2016-03-23 10:04:00 +0100 | [diff] [blame] | 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #ifndef LY_PARSER_YANG_H_ |
| 16 | #define LY_PARSER_YANG_H_ |
| 17 | |
Pavol Vican | bf80547 | 2016-01-26 14:24:56 +0100 | [diff] [blame] | 18 | #include <stdlib.h> |
Pavol Vican | 6eb14e8 | 2016-02-03 12:27:13 +0100 | [diff] [blame] | 19 | #include <string.h> |
Pavol Vican | bf80547 | 2016-01-26 14:24:56 +0100 | [diff] [blame] | 20 | |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 21 | #include "tree_schema.h" |
| 22 | #include "resolve.h" |
Pavol Vican | bf80547 | 2016-01-26 14:24:56 +0100 | [diff] [blame] | 23 | #include "common.h" |
Pavol Vican | 6eb14e8 | 2016-02-03 12:27:13 +0100 | [diff] [blame] | 24 | #include "context.h" |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 25 | |
Pavol Vican | be057c0 | 2016-02-11 19:08:08 +0100 | [diff] [blame] | 26 | #define LYS_SYSTEMORDERED 0x40 |
| 27 | #define LYS_ORDERED_MASK 0xC0 |
Pavol Vican | 339d4ad | 2016-02-12 12:49:22 +0100 | [diff] [blame] | 28 | #define LYS_MIN_ELEMENTS 0x01 |
| 29 | #define LYS_MAX_ELEMENTS 0x02 |
Pavol Vican | 52ed67d | 2016-03-02 17:46:15 +0100 | [diff] [blame] | 30 | #define LYS_RPC_INPUT 0x01 |
| 31 | #define LYS_RPC_OUTPUT 0x02 |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 32 | #define LYS_DATADEF 0x04 |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 33 | #define LYS_TYPE_DEF 0x08 |
Pavol Vican | 1dac40c | 2016-09-28 11:39:26 +0200 | [diff] [blame] | 34 | #define CONFIG_INHERIT_DISABLE 0x00 |
| 35 | #define CONFIG_INHERIT_ENABLE 0x01 |
| 36 | #define CONFIG_IGNORE 0x02 |
Pavol Vican | ab75ce0 | 2016-09-29 01:31:09 +0200 | [diff] [blame] | 37 | #define CONFIG_MASK 0x03 |
Pavol Vican | 8e5f119 | 2016-08-15 10:25:44 +0200 | [diff] [blame] | 38 | #define LYS_CHOICE_DEFAULT 0x10 |
Pavol Vican | b60a1d1 | 2016-12-03 01:56:55 +0100 | [diff] [blame] | 39 | #define LYS_NO_ERASE_IDENTITY 0x20 |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 40 | #define LY_YANG_ARRAY_SIZE 8 |
Pavol Vican | 1eeb199 | 2016-02-09 11:10:45 +0100 | [diff] [blame] | 41 | |
Pavol Vican | d946c0d | 2016-03-23 12:53:08 +0100 | [diff] [blame] | 42 | struct type_node { |
| 43 | union { |
| 44 | struct lys_node_leaflist *ptr_leaflist; |
| 45 | struct lys_node_list *ptr_list; |
| 46 | struct lys_node_leaf *ptr_leaf; |
| 47 | struct lys_tpdf *ptr_tpdf; |
Pavol Vican | db7489e | 2016-08-23 17:23:39 +0200 | [diff] [blame] | 48 | struct lys_node_anydata *ptr_anydata; |
Michal Vasko | 44fb638 | 2016-06-29 11:12:27 +0200 | [diff] [blame] | 49 | struct lys_node_rpc_action *ptr_rpc; |
Pavol Vican | 8e5f119 | 2016-08-15 10:25:44 +0200 | [diff] [blame] | 50 | struct lys_node_choice *ptr_choice; |
Pavol Vican | d946c0d | 2016-03-23 12:53:08 +0100 | [diff] [blame] | 51 | }; |
Pavol Vican | db7489e | 2016-08-23 17:23:39 +0200 | [diff] [blame] | 52 | uint flag; |
Pavol Vican | 531a913 | 2016-03-03 10:10:09 +0100 | [diff] [blame] | 53 | }; |
| 54 | |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 55 | struct yang_parameter { |
| 56 | struct lys_module *module; |
| 57 | struct lys_submodule *submodule; |
| 58 | struct unres_schema *unres; |
| 59 | struct lys_node **node; |
| 60 | char **value; |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 61 | void **data_node; |
| 62 | void **actual_node; |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 63 | uint8_t remove_import; |
| 64 | uint8_t exist_module; |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 65 | }; |
| 66 | |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 67 | struct yang_type { |
| 68 | char flags; /**< this is used to distinguish lyxml_elem * from a YANG temporary parsing structure */ |
Pavol Vican | 6b07251 | 2016-04-04 10:50:21 +0200 | [diff] [blame] | 69 | LY_DATA_TYPE base; |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 70 | const char *name; |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 71 | struct lys_type *type; |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 72 | }; |
| 73 | |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 74 | #include "parser_yang_bis.h" |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 75 | |
PavolVican | 1bc2206 | 2017-01-19 15:09:04 +0100 | [diff] [blame] | 76 | char *yang_read_string(const char *input, char *output, int size, int offset, int indent); |
Pavol Vican | 8760bb7 | 2016-04-07 09:44:01 +0200 | [diff] [blame] | 77 | |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 78 | int yang_read_common(struct lys_module *module,char *value, enum yytokentype type); |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 79 | |
Pavol Vican | e024ab7 | 2016-07-27 14:27:43 +0200 | [diff] [blame] | 80 | int yang_read_prefix(struct lys_module *module, struct lys_import *imp, char *value); |
Pavol Vican | 6eb14e8 | 2016-02-03 12:27:13 +0100 | [diff] [blame] | 81 | |
Pavol Vican | d0b64c1 | 2016-07-15 09:56:19 +0200 | [diff] [blame] | 82 | int yang_check_version(struct lys_module *module, struct lys_submodule *submodule, char *value, int repeat); |
| 83 | |
Pavol Vican | ec423c9 | 2016-10-24 21:33:43 +0200 | [diff] [blame] | 84 | int yang_check_imports(struct lys_module *module, struct unres_schema *unres); |
Pavol Vican | 6eb14e8 | 2016-02-03 12:27:13 +0100 | [diff] [blame] | 85 | |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 86 | int yang_read_description(struct lys_module *module, void *node, char *value, char *where, enum yytokentype type); |
Pavol Vican | 1ca072c | 2016-02-03 13:03:56 +0100 | [diff] [blame] | 87 | |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 88 | int yang_read_reference(struct lys_module *module, void *node, char *value, char *where, enum yytokentype type); |
Pavol Vican | 1ca072c | 2016-02-03 13:03:56 +0100 | [diff] [blame] | 89 | |
PavolVican | 171717d | 2017-02-01 14:49:55 +0100 | [diff] [blame] | 90 | void *yang_read_revision(struct lys_module *module, char *value, struct lys_revision *retval); |
Pavol Vican | bedff69 | 2016-02-03 14:29:17 +0100 | [diff] [blame] | 91 | |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 92 | int yang_read_message(struct lys_module *module,struct lys_restr *save,char *value, char *what, int message); |
Pavol Vican | f37eeaa | 2016-02-09 20:54:06 +0100 | [diff] [blame] | 93 | |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 94 | int yang_read_presence(struct lys_module *module, struct lys_node_container *cont, char *value); |
Pavol Vican | b568711 | 2016-02-09 22:35:59 +0100 | [diff] [blame] | 95 | |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 96 | int yang_read_config(void *node, int value, enum yytokentype type); |
Pavol Vican | b568711 | 2016-02-09 22:35:59 +0100 | [diff] [blame] | 97 | |
Pavol Vican | 1dac40c | 2016-09-28 11:39:26 +0200 | [diff] [blame] | 98 | int store_flags(struct lys_node *node, uint8_t flags, int config_opt); |
Pavol Vican | 4fb66c9 | 2016-03-17 10:32:27 +0100 | [diff] [blame] | 99 | |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 100 | void *yang_read_when(struct lys_module *module, struct lys_node *node, enum yytokentype type, char *value); |
Pavol Vican | 235dbd4 | 2016-02-10 10:34:19 +0100 | [diff] [blame] | 101 | |
Pavol Vican | 7cadfe7 | 2016-02-11 12:33:34 +0100 | [diff] [blame] | 102 | /** |
| 103 | * @brief Allocate memory for node and add to the tree |
| 104 | * |
| 105 | * @param[in/out] node Pointer to the array. |
| 106 | * @param[in] parent Pointer to the parent. |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 107 | * @param[in] root Pointer to the root of schema tree. |
Pavol Vican | 7cadfe7 | 2016-02-11 12:33:34 +0100 | [diff] [blame] | 108 | * @param[in] value Name of node |
| 109 | * @param[in] nodetype Type of node |
| 110 | * @param[in] sizeof_struct Size of struct |
| 111 | * @return Pointer to the node, NULL on error. |
| 112 | */ |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 113 | void *yang_read_node(struct lys_module *module, struct lys_node *parent, struct lys_node **root, |
| 114 | char *value, int nodetype, int sizeof_struct); |
Pavol Vican | 12f53c3 | 2016-02-11 11:40:00 +0100 | [diff] [blame] | 115 | |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 116 | int yang_read_default(struct lys_module *module, void *node, char *value, enum yytokentype type); |
Pavol Vican | 096c6db | 2016-02-11 15:08:10 +0100 | [diff] [blame] | 117 | |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 118 | int yang_read_units(struct lys_module *module, void *node, char *value, enum yytokentype type); |
Pavol Vican | 096c6db | 2016-02-11 15:08:10 +0100 | [diff] [blame] | 119 | |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 120 | int yang_read_key(struct lys_module *module, struct lys_node_list *list, struct unres_schema *unres); |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 121 | |
| 122 | int yang_read_unique(struct lys_module *module, struct lys_node_list *list, struct unres_schema *unres); |
| 123 | |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 124 | void *yang_read_type(struct lys_module *module, void *parent, char *value, enum yytokentype type); |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 125 | |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 126 | void *yang_read_length(struct lys_module *module, struct yang_type *typ, char *value); |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 127 | |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 128 | int yang_check_type(struct lys_module *module, struct lys_node *parent, struct yang_type *typ, struct lys_type *type, int tpdftype, struct unres_schema *unres); |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 129 | |
Pavol Vican | cf2af4d | 2016-12-21 14:13:06 +0100 | [diff] [blame] | 130 | void yang_free_type_union(struct ly_ctx *ctx, struct lys_type *type); |
| 131 | |
Pavol Vican | 81344ac | 2016-09-02 14:23:06 +0200 | [diff] [blame] | 132 | int yang_read_leafref_path(struct lys_module *module, struct yang_type *stype, char *value); |
| 133 | |
| 134 | int yang_read_require_instance(struct yang_type *stype, int req); |
| 135 | |
Pavol Vican | 6eecf30 | 2016-08-10 11:09:05 +0200 | [diff] [blame] | 136 | int yang_read_pattern(struct lys_module *module, struct lys_restr *pattern, char *value, char modifier); |
Pavol Vican | 1c203db | 2016-02-24 14:05:23 +0100 | [diff] [blame] | 137 | |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 138 | void *yang_read_range(struct lys_module *module, struct yang_type *typ, char *value); |
Pavol Vican | aff5c80 | 2016-02-24 15:56:45 +0100 | [diff] [blame] | 139 | |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 140 | int yang_read_fraction(struct yang_type *typ, uint32_t value); |
Pavol Vican | 07ea68d | 2016-02-25 12:01:37 +0100 | [diff] [blame] | 141 | |
Pavol Vican | 874715f | 2016-10-25 14:52:08 +0200 | [diff] [blame] | 142 | int yang_read_enum(struct lys_module *module, struct yang_type *typ, struct lys_type_enum *enm, char *value); |
Pavol Vican | 79a763d | 2016-02-25 15:41:27 +0100 | [diff] [blame] | 143 | |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 144 | int yang_check_enum(struct yang_type *typ, struct lys_type_enum *enm, int64_t *value, int assign); |
Pavol Vican | 79a763d | 2016-02-25 15:41:27 +0100 | [diff] [blame] | 145 | |
Pavol Vican | 59e8dee | 2016-10-25 15:29:38 +0200 | [diff] [blame] | 146 | int yang_read_bit(struct lys_module *module, struct yang_type *typ, struct lys_type_bit *bit, char *value); |
Pavol Vican | 9887c68 | 2016-02-29 11:32:01 +0100 | [diff] [blame] | 147 | |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 148 | int yang_check_bit(struct yang_type *typ, struct lys_type_bit *bit, int64_t *value, int assign); |
Pavol Vican | 9887c68 | 2016-02-29 11:32:01 +0100 | [diff] [blame] | 149 | |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 150 | void *yang_read_typedef(struct lys_module *module, struct lys_node *parent, char *value); |
Pavol Vican | 0df02b0 | 2016-03-01 10:28:50 +0100 | [diff] [blame] | 151 | |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 152 | int yang_read_augment(struct lys_module *module, struct lys_node *parent, struct lys_node_augment *aug, char *value); |
Pavol Vican | 92fa0dc | 2016-03-02 14:20:39 +0100 | [diff] [blame] | 153 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 154 | void *yang_read_deviate(struct lys_deviation *dev, LYS_DEVIATE_TYPE mod); |
Pavol Vican | 220e5a1 | 2016-03-03 14:19:43 +0100 | [diff] [blame] | 155 | |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame^] | 156 | void *yang_read_deviate_unsupported(struct lys_deviation *dev); |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 157 | |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 158 | int yang_fill_unique(struct lys_module *module, struct lys_node_list *list, struct lys_unique *unique, char *value, struct unres_schema *unres); |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 159 | |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 160 | int yang_use_extension(struct lys_module *module, struct lys_node *data_node, void *actual, char *value); |
Pavol Vican | f4717e6 | 2016-03-16 11:30:01 +0100 | [diff] [blame] | 161 | |
Radek Krejci | 4372b4e | 2016-04-14 17:42:16 +0200 | [diff] [blame] | 162 | int yang_check_flags(uint16_t *flags, uint16_t mask, char *what, char *where, uint16_t value, int shortint); |
Pavol Vican | 4fb66c9 | 2016-03-17 10:32:27 +0100 | [diff] [blame] | 163 | |
PavolVican | c180726 | 2017-01-31 18:00:27 +0100 | [diff] [blame] | 164 | void *yang_read_ext(struct lys_module *module, void *actual, char *ext_name, char *ext_arg, |
| 165 | enum yytokentype actual_type, enum yytokentype backup_type); |
| 166 | |
| 167 | int yang_check_ext_instance(struct lys_module *module, struct lys_ext_instance ***ext, uint size, |
| 168 | void *parent, struct unres_schema *unres); |
| 169 | |
| 170 | |
Pavol Vican | 1d68410 | 2016-03-23 10:18:54 +0100 | [diff] [blame] | 171 | /* ** |
| 172 | * @brief Parse YANG from in-memory string |
| 173 | * |
| 174 | * yang parser expected at the end of the input string 2 zero byte |
| 175 | * |
| 176 | * @param[in] module Pointer to the libyang module. |
| 177 | * @param[in] submodule Pointer to the libyang submodule. |
| 178 | * @param[in] unres Pointer to a unres_schema |
| 179 | * @param[in] data Pointer to a NULL-terminated string containing YANG data to parse. |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 180 | * @param[in] size_data Size of input string |
Pavol Vican | 9d50a77 | 2016-10-14 22:23:36 +0200 | [diff] [blame] | 181 | * @param[in/out] node Pointer to node |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 182 | * @return 0 on success, -1 on error, 1 on module is already in context. |
Pavol Vican | 1d68410 | 2016-03-23 10:18:54 +0100 | [diff] [blame] | 183 | */ |
Pavol Vican | 9d50a77 | 2016-10-14 22:23:36 +0200 | [diff] [blame] | 184 | int yang_parse_mem(struct lys_module *module, struct lys_submodule *submodule, struct unres_schema *unres, |
| 185 | const char *data, unsigned int size_data, struct lys_node **node); |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 186 | |
Pavol Vican | 974377b | 2016-03-23 00:38:53 +0100 | [diff] [blame] | 187 | struct lys_module *yang_read_module(struct ly_ctx *ctx, const char* data, unsigned int size, const char *revision, int implement); |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 188 | |
Pavol Vican | 974377b | 2016-03-23 00:38:53 +0100 | [diff] [blame] | 189 | struct lys_submodule *yang_read_submodule(struct lys_module *module, const char *data, unsigned int size, struct unres_schema *unres); |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 190 | |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 191 | #endif /* LY_PARSER_YANG_H_ */ |