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 | * |
| 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 | #ifndef LY_PARSER_YANG_H_ |
| 23 | #define LY_PARSER_YANG_H_ |
| 24 | |
Pavol Vican | bf80547 | 2016-01-26 14:24:56 +0100 | [diff] [blame] | 25 | #include <stdlib.h> |
Pavol Vican | 6eb14e8 | 2016-02-03 12:27:13 +0100 | [diff] [blame] | 26 | #include <string.h> |
Pavol Vican | bf80547 | 2016-01-26 14:24:56 +0100 | [diff] [blame] | 27 | |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 28 | #include "tree_schema.h" |
| 29 | #include "resolve.h" |
Pavol Vican | bf80547 | 2016-01-26 14:24:56 +0100 | [diff] [blame] | 30 | #include "common.h" |
Pavol Vican | 6eb14e8 | 2016-02-03 12:27:13 +0100 | [diff] [blame] | 31 | #include "context.h" |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 32 | |
Pavol Vican | 1eeb199 | 2016-02-09 11:10:45 +0100 | [diff] [blame] | 33 | #define LY_ARRAY_SIZE 32 |
| 34 | #define LY_READ_ALL 1 |
| 35 | #define LY_READ_ONLY_SIZE 0 |
Pavol Vican | be057c0 | 2016-02-11 19:08:08 +0100 | [diff] [blame] | 36 | #define LYS_SYSTEMORDERED 0x40 |
| 37 | #define LYS_ORDERED_MASK 0xC0 |
Pavol Vican | 339d4ad | 2016-02-12 12:49:22 +0100 | [diff] [blame] | 38 | #define LYS_MIN_ELEMENTS 0x01 |
| 39 | #define LYS_MAX_ELEMENTS 0x02 |
Pavol Vican | 52ed67d | 2016-03-02 17:46:15 +0100 | [diff] [blame] | 40 | #define LYS_RPC_INPUT 0x01 |
| 41 | #define LYS_RPC_OUTPUT 0x02 |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 42 | #define LYS_DATADEF 0x04 |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 43 | #define LYS_TYPE_DEF 0x08 |
Pavol Vican | 1ff0e22 | 2016-02-26 12:27:01 +0100 | [diff] [blame] | 44 | #define LYS_TYPE_BASE 0x40 |
Pavol Vican | 1eeb199 | 2016-02-09 11:10:45 +0100 | [diff] [blame] | 45 | |
| 46 | struct lys_node_array{ |
| 47 | uint8_t if_features; |
| 48 | uint8_t must; |
| 49 | uint8_t unique; |
| 50 | uint8_t tpdf; |
| 51 | uint8_t keys; |
| 52 | uint8_t expr_size; |
| 53 | uint16_t refine; |
| 54 | uint16_t augment; |
| 55 | |
| 56 | }; |
| 57 | |
| 58 | struct lys_array_size { |
| 59 | uint8_t rev; |
| 60 | uint8_t imp; |
| 61 | uint8_t inc; |
| 62 | uint32_t ident; |
| 63 | uint8_t features; |
| 64 | uint8_t augment; |
| 65 | uint8_t deviation; |
Pavol Vican | 0df02b0 | 2016-03-01 10:28:50 +0100 | [diff] [blame] | 66 | uint8_t tpdf; |
Pavol Vican | e1354e9 | 2016-02-09 14:02:09 +0100 | [diff] [blame] | 67 | uint32_t size; |
Pavol Vican | 1eeb199 | 2016-02-09 11:10:45 +0100 | [diff] [blame] | 68 | uint32_t next; |
| 69 | struct lys_node_array *node; |
| 70 | }; |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 71 | |
Pavol Vican | 1f06ba8 | 2016-02-10 17:39:50 +0100 | [diff] [blame] | 72 | struct type_choice { |
| 73 | char *s; |
| 74 | struct lys_node_choice *ptr_choice; |
| 75 | }; |
| 76 | |
Pavol Vican | 339d4ad | 2016-02-12 12:49:22 +0100 | [diff] [blame] | 77 | struct type_leaflist { |
| 78 | struct lys_node_leaflist *ptr_leaflist; |
Pavol Vican | a55992a | 2016-03-01 13:37:17 +0100 | [diff] [blame] | 79 | int line; |
Pavol Vican | 339d4ad | 2016-02-12 12:49:22 +0100 | [diff] [blame] | 80 | uint8_t flag; |
| 81 | }; |
| 82 | |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 83 | struct type_list { |
| 84 | struct lys_node_list *ptr_list; |
| 85 | uint8_t flag; |
| 86 | int line; |
| 87 | }; |
| 88 | |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 89 | struct type_leaf { |
| 90 | struct lys_node_leaf *ptr_leaf; |
Pavol Vican | 6295f12 | 2016-02-26 12:53:33 +0100 | [diff] [blame] | 91 | int line; |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 92 | uint8_t flag; |
| 93 | }; |
| 94 | |
Pavol Vican | 0df02b0 | 2016-03-01 10:28:50 +0100 | [diff] [blame] | 95 | struct type_tpdf { |
| 96 | struct lys_tpdf *ptr_tpdf; |
| 97 | int line; |
| 98 | uint8_t flag; |
| 99 | }; |
| 100 | |
Pavol Vican | 92fa0dc | 2016-03-02 14:20:39 +0100 | [diff] [blame] | 101 | struct type_augment { |
| 102 | struct lys_node_augment *ptr_augment; |
| 103 | uint8_t flag; |
| 104 | }; |
| 105 | |
Pavol Vican | 52ed67d | 2016-03-02 17:46:15 +0100 | [diff] [blame] | 106 | struct type_rpc { |
| 107 | struct lys_node_rpc *ptr_rpc; |
| 108 | uint8_t flag; |
| 109 | }; |
| 110 | |
Pavol Vican | 531a913 | 2016-03-03 10:10:09 +0100 | [diff] [blame] | 111 | struct type_inout { |
| 112 | struct lys_node_rpc_inout *ptr_inout; |
| 113 | uint8_t flag; |
| 114 | }; |
| 115 | |
Pavol Vican | 220e5a1 | 2016-03-03 14:19:43 +0100 | [diff] [blame^] | 116 | struct type_deviation { |
| 117 | struct lys_deviation *deviation; |
| 118 | struct lys_node *target; |
| 119 | struct lys_deviate *deviate; |
| 120 | }; |
| 121 | |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 122 | struct type_ident { |
| 123 | int line; |
| 124 | char s[0]; |
| 125 | }; |
| 126 | |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 127 | struct yang_type { |
| 128 | char flags; /**< this is used to distinguish lyxml_elem * from a YANG temporary parsing structure */ |
| 129 | char *name; |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 130 | struct lys_type *type; |
| 131 | int line; |
| 132 | }; |
| 133 | |
| 134 | struct yang_schema { |
| 135 | struct yang_type type; |
| 136 | struct yang_schema *next; |
| 137 | }; |
| 138 | |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 139 | int yang_read_common(struct lys_module *module,char *value, int type, int line); |
| 140 | |
Pavol Vican | bf80547 | 2016-01-26 14:24:56 +0100 | [diff] [blame] | 141 | int yang_read_prefix(struct lys_module *module, void *save, char *value,int type,int line); |
| 142 | |
Pavol Vican | 6eb14e8 | 2016-02-03 12:27:13 +0100 | [diff] [blame] | 143 | /** |
| 144 | * @brief Get free member of array |
| 145 | * |
| 146 | * @param[in/out] ptr Pointer to the array. |
| 147 | * @param[in/out] act_size Pointer to the current size of array. |
| 148 | * @param[in] type Type of array. |
| 149 | * @param[in] sizeof_struct |
| 150 | * @return first free member of array, NULL on error. |
| 151 | */ |
| 152 | void *yang_elem_of_array(void **ptr, uint8_t *act_size, int type, int sizeof_struct); |
| 153 | |
Pavol Vican | 1eeb199 | 2016-02-09 11:10:45 +0100 | [diff] [blame] | 154 | /** |
| 155 | * @brief Add node to the array |
| 156 | * |
| 157 | * @param[in/out] node Pointer to the array. |
| 158 | * @param[in/out] size Pointer to the current size of array. |
| 159 | * @return 1 on success, 0 on error. |
| 160 | */ |
Pavol Vican | a182796 | 2016-02-29 15:39:42 +0100 | [diff] [blame] | 161 | int yang_add_elem(struct lys_node_array **node, uint32_t *size); |
Pavol Vican | 1eeb199 | 2016-02-09 11:10:45 +0100 | [diff] [blame] | 162 | |
Pavol Vican | 6eb14e8 | 2016-02-03 12:27:13 +0100 | [diff] [blame] | 163 | int yang_fill_import(struct lys_module *module, struct lys_import *imp, char *value, int line); |
| 164 | |
Pavol Vican | 1ca072c | 2016-02-03 13:03:56 +0100 | [diff] [blame] | 165 | int yang_read_description(struct lys_module *module, void *node, char *value, int type, int line); |
| 166 | |
| 167 | int yang_read_reference(struct lys_module *module, void *node, char *value, int type, int line); |
| 168 | |
Pavol Vican | bedff69 | 2016-02-03 14:29:17 +0100 | [diff] [blame] | 169 | void *yang_read_revision(struct lys_module *module, char *value); |
| 170 | |
Pavol Vican | e1354e9 | 2016-02-09 14:02:09 +0100 | [diff] [blame] | 171 | void *yang_read_feature(struct lys_module *module, char *value, int line); |
Pavol Vican | bedff69 | 2016-02-03 14:29:17 +0100 | [diff] [blame] | 172 | |
Pavol Vican | f37eeaa | 2016-02-09 20:54:06 +0100 | [diff] [blame] | 173 | int yang_read_if_feature(struct lys_module *module, void *ptr, char *value, struct unres_schema *unres, int type, int line); |
Pavol Vican | e1354e9 | 2016-02-09 14:02:09 +0100 | [diff] [blame] | 174 | |
| 175 | int yang_read_status(void *node, int value, int type, int line); |
Pavol Vican | 1ca072c | 2016-02-03 13:03:56 +0100 | [diff] [blame] | 176 | |
Pavol Vican | bbdef53 | 2016-02-09 14:52:12 +0100 | [diff] [blame] | 177 | void *yang_read_identity(struct lys_module *module, char *value); |
| 178 | |
| 179 | int yang_read_base(struct lys_module *module, struct lys_ident *ident, char *value, struct unres_schema *unres, int line); |
| 180 | |
Pavol Vican | f37eeaa | 2016-02-09 20:54:06 +0100 | [diff] [blame] | 181 | void *yang_read_must(struct lys_module *module, struct lys_node *node, char *value, int type, int line); |
| 182 | |
| 183 | int yang_read_message(struct lys_module *module,struct lys_restr *save,char *value, int type, int message, int line); |
| 184 | |
Pavol Vican | b568711 | 2016-02-09 22:35:59 +0100 | [diff] [blame] | 185 | int yang_read_presence(struct lys_module *module, struct lys_node_container *cont, char *value, int line); |
| 186 | |
| 187 | int yang_read_config(void *node, int value, int type, int line); |
| 188 | |
Pavol Vican | 235dbd4 | 2016-02-10 10:34:19 +0100 | [diff] [blame] | 189 | void *yang_read_when(struct lys_module *module, struct lys_node *node, int type, char *value, int line); |
| 190 | |
Pavol Vican | 8c82fa8 | 2016-02-10 13:13:24 +0100 | [diff] [blame] | 191 | int yang_read_mandatory(void *node, int value, int type, int line); |
| 192 | |
Pavol Vican | 7cadfe7 | 2016-02-11 12:33:34 +0100 | [diff] [blame] | 193 | /** |
| 194 | * @brief Allocate memory for node and add to the tree |
| 195 | * |
| 196 | * @param[in/out] node Pointer to the array. |
| 197 | * @param[in] parent Pointer to the parent. |
| 198 | * @param[in] value Name of node |
| 199 | * @param[in] nodetype Type of node |
| 200 | * @param[in] sizeof_struct Size of struct |
| 201 | * @return Pointer to the node, NULL on error. |
| 202 | */ |
| 203 | void * yang_read_node(struct lys_module *module, struct lys_node *parent, char *value, int nodetype, int sizeof_struct); |
Pavol Vican | 12f53c3 | 2016-02-11 11:40:00 +0100 | [diff] [blame] | 204 | |
Pavol Vican | 096c6db | 2016-02-11 15:08:10 +0100 | [diff] [blame] | 205 | int yang_read_default(struct lys_module *module, void *node, char *value, int type, int line); |
| 206 | |
| 207 | int yang_read_units(struct lys_module *module, void *node, char *value, int type, int line); |
| 208 | |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 209 | int yang_read_key(struct lys_module *module, struct lys_node_list *list, struct unres_schema *unres, int line); |
| 210 | |
| 211 | int yang_read_unique(struct lys_module *module, struct lys_node_list *list, struct unres_schema *unres); |
| 212 | |
Pavol Vican | d01d8ae | 2016-03-01 10:45:59 +0100 | [diff] [blame] | 213 | void *yang_read_type(void *parent, char *value, int type, int line); |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 214 | |
| 215 | void *yang_read_length(struct lys_module *module, struct yang_type *typ, char *value, int line); |
| 216 | |
| 217 | int yang_check_type(struct lys_module *module, struct lys_node *parent, struct yang_type *typ, struct unres_schema *unres); |
| 218 | |
Pavol Vican | 1c203db | 2016-02-24 14:05:23 +0100 | [diff] [blame] | 219 | void *yang_read_pattern(struct lys_module *module, struct yang_type *typ, char *value, int line); |
| 220 | |
Pavol Vican | aff5c80 | 2016-02-24 15:56:45 +0100 | [diff] [blame] | 221 | void *yang_read_range(struct lys_module *module, struct yang_type *typ, char *value, int line); |
| 222 | |
Pavol Vican | 07ea68d | 2016-02-25 12:01:37 +0100 | [diff] [blame] | 223 | int yang_read_fraction(struct yang_type *typ, uint32_t value, int line); |
| 224 | |
Pavol Vican | 79a763d | 2016-02-25 15:41:27 +0100 | [diff] [blame] | 225 | void *yang_read_enum(struct lys_module *module, struct yang_type *typ, char *value, int line); |
| 226 | |
| 227 | int yang_check_enum(struct yang_type *typ, struct lys_type_enum *enm, int64_t *value, int assign, int line); |
| 228 | |
Pavol Vican | 9887c68 | 2016-02-29 11:32:01 +0100 | [diff] [blame] | 229 | void *yang_read_bit(struct lys_module *module, struct yang_type *typ, char *value, int line); |
| 230 | |
| 231 | int yang_check_bit(struct yang_type *typ, struct lys_type_bit *bit, int64_t *value, int assign, int line); |
| 232 | |
Pavol Vican | 0df02b0 | 2016-03-01 10:28:50 +0100 | [diff] [blame] | 233 | void *yang_read_typedef(struct lys_module *module, struct lys_node *parent, char *value, int line); |
| 234 | |
Pavol Vican | 1003ead | 2016-03-02 12:24:52 +0100 | [diff] [blame] | 235 | void *yang_read_refine(struct lys_module *module, struct lys_node_uses *uses, char *value, int line); |
| 236 | |
Pavol Vican | 92fa0dc | 2016-03-02 14:20:39 +0100 | [diff] [blame] | 237 | void *yang_read_augment(struct lys_module *module, struct lys_node *parent, char *value, int line); |
| 238 | |
Pavol Vican | 220e5a1 | 2016-03-03 14:19:43 +0100 | [diff] [blame^] | 239 | void *yang_read_deviation(struct lys_module *module, char *value, int line); |
| 240 | |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 241 | #endif /* LY_PARSER_YANG_H_ */ |