Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1 | /** |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 2 | * @file parser.h |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 4 | * @brief Parsers for libyang |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 7 | * |
Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame] | 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
Michal Vasko | 8de098c | 2016-02-26 10:00:25 +0100 | [diff] [blame] | 11 | * |
Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame] | 12 | * https://opensource.org/licenses/BSD-3-Clause |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 15 | #ifndef LY_PARSER_H_ |
| 16 | #define LY_PARSER_H_ |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 17 | |
Michal Vasko | 0aee5c1 | 2016-06-17 14:27:26 +0200 | [diff] [blame] | 18 | #include <pcre.h> |
| 19 | |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 20 | #include "libyang.h" |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 21 | #include "tree_schema.h" |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 22 | #include "tree_internal.h" |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * @defgroup yin YIN format support |
| 26 | * @{ |
| 27 | */ |
Radek Krejci | ff4874d | 2016-03-07 12:30:50 +0100 | [diff] [blame] | 28 | struct lys_module *yin_read_module(struct ly_ctx *ctx, const char *data, const char *revision, int implement); |
| 29 | struct lys_submodule *yin_read_submodule(struct lys_module *module, const char *data,struct unres_schema *unres); |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 30 | |
| 31 | /**@} yin */ |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 32 | |
Radek Krejci | b20c62d | 2015-07-07 17:07:14 +0200 | [diff] [blame] | 33 | /** |
| 34 | * @defgroup xmldata XML data format support |
| 35 | * @{ |
| 36 | */ |
Radek Krejci | 25b9fd3 | 2015-08-10 15:06:07 +0200 | [diff] [blame] | 37 | struct lyd_node *xml_read_data(struct ly_ctx *ctx, const char *data, int options); |
Radek Krejci | b20c62d | 2015-07-07 17:07:14 +0200 | [diff] [blame] | 38 | |
| 39 | /**@} xmldata */ |
| 40 | |
Radek Krejci | 5449d47 | 2015-10-26 14:35:56 +0100 | [diff] [blame] | 41 | /** |
| 42 | * @defgroup jsondata JSON data format support |
| 43 | * @{ |
| 44 | */ |
Michal Vasko | 945b96b | 2016-10-18 11:49:12 +0200 | [diff] [blame] | 45 | struct lyd_node *lyd_parse_json(struct ly_ctx *ctx, const char *data, int options, const struct lyd_node *rpc_act, |
| 46 | const struct lyd_node *data_tree); |
Radek Krejci | 5449d47 | 2015-10-26 14:35:56 +0100 | [diff] [blame] | 47 | |
| 48 | /**@} jsondata */ |
| 49 | |
Radek Krejci | 06a9aa0 | 2017-02-17 10:50:24 +0100 | [diff] [blame^] | 50 | /* list of YANG statement strings */ |
| 51 | extern const char *ly_stmt_str[]; |
| 52 | |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 53 | enum LY_IDENT { |
| 54 | LY_IDENT_SIMPLE, /* only syntax rules */ |
| 55 | LY_IDENT_FEATURE, |
| 56 | LY_IDENT_IDENTITY, |
| 57 | LY_IDENT_TYPE, |
| 58 | LY_IDENT_NODE, |
| 59 | LY_IDENT_NAME, /* uniqueness across the siblings */ |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 60 | LY_IDENT_PREFIX, |
| 61 | LY_IDENT_EXTENSION |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 62 | }; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 63 | int lyp_yin_fill_ext(void *parent, LYEXT_PAR parent_type, LYEXT_SUBSTMT substmt, uint8_t substmt_index, |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 64 | struct lys_module *module, struct lyxml_elem *yin, struct lys_ext_instance ***ext, |
| 65 | uint8_t ext_index, struct unres_schema *unres); |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 66 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 67 | int lyp_yin_parse_complex_ext(struct lys_module *mod, struct lys_ext_instance_complex *ext, |
| 68 | struct lyxml_elem *yin, struct unres_schema *unres); |
| 69 | int lyp_yin_parse_subnode_ext(struct lys_module *mod, void *elem, LYEXT_PAR elem_type, |
| 70 | struct lyxml_elem *yin, LYEXT_SUBSTMT type, uint8_t i, struct unres_schema *unres); |
| 71 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 72 | struct lys_module *lyp_search_file(struct ly_ctx *ctx, struct lys_module *module, const char *name, |
Michal Vasko | 58e5f3e | 2016-07-28 11:06:34 +0200 | [diff] [blame] | 73 | const char *revision, int implement, struct unres_schema *unres); |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 74 | |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 75 | struct lys_type *lyp_get_next_union_type(struct lys_type *type, struct lys_type *prev_type, int *found); |
| 76 | |
Radek Krejci | 1899d6a | 2016-11-03 13:48:07 +0100 | [diff] [blame] | 77 | struct lys_type *lyp_parse_value(struct lys_type *type, const char **value_, struct lyxml_elem *xml, |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 78 | struct lyd_node_leaf_list *leaf, int store, int dflt); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 79 | |
| 80 | int lyp_check_length_range(const char *expr, struct lys_type *type); |
| 81 | |
Michal Vasko | 0aee5c1 | 2016-06-17 14:27:26 +0200 | [diff] [blame] | 82 | int lyp_check_pattern(const char *pattern, pcre **pcre_precomp); |
| 83 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 84 | int fill_yin_type(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_type *type, |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 85 | int tpdftype, struct unres_schema *unres); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 86 | |
Radek Krejci | 4372b4e | 2016-04-14 17:42:16 +0200 | [diff] [blame] | 87 | int lyp_check_status(uint16_t flags1, struct lys_module *mod1, const char *name1, |
| 88 | uint16_t flags2, struct lys_module *mod2, const char *name2, |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 89 | const struct lys_node *node); |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 90 | |
Michal Vasko | 7b460e5 | 2017-02-10 14:50:26 +0100 | [diff] [blame] | 91 | void lyp_del_includedup(struct lys_module *mod); |
| 92 | |
Pavol Vican | 810892e | 2016-07-12 16:55:34 +0200 | [diff] [blame] | 93 | int dup_typedef_check(const char *type, struct lys_tpdf *tpdf, int size); |
Pavol Vican | d6cda45 | 2016-07-13 15:08:29 +0200 | [diff] [blame] | 94 | |
| 95 | int dup_identities_check(const char *id, struct lys_module *module); |
| 96 | |
Radek Krejci | 5449d47 | 2015-10-26 14:35:56 +0100 | [diff] [blame] | 97 | /** |
Michal Vasko | b1b1944 | 2016-07-13 12:26:01 +0200 | [diff] [blame] | 98 | * @brief Get know if the node is part of the RPC/action's input/output |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 99 | * |
| 100 | * @param node Schema node to be examined. |
| 101 | * @return 1 for true, 0 for false |
| 102 | */ |
Michal Vasko | b1b1944 | 2016-07-13 12:26:01 +0200 | [diff] [blame] | 103 | int lyp_is_rpc_action(struct lys_node *node); |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * @brief Check validity of parser options. |
| 107 | * |
| 108 | * @param options Parser options to be checked. |
Michal Vasko | a55d96b | 2016-12-07 12:20:42 +0100 | [diff] [blame] | 109 | * @return 0 for ok, 1 when multiple data types bits are set, or incompatible options are used together. |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 110 | */ |
| 111 | int lyp_check_options(int options); |
| 112 | |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 113 | int lyp_check_identifier(const char *id, enum LY_IDENT type, struct lys_module *module, struct lys_node *parent); |
| 114 | int lyp_check_date(const char *date); |
Radek Krejci | df24cbe | 2016-11-08 11:55:51 +0100 | [diff] [blame] | 115 | int lyp_check_mandatory_augment(struct lys_node_augment *node, const struct lys_node *target); |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 116 | int lyp_check_mandatory_choice(struct lys_node *node); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 117 | |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 118 | int lyp_check_include(struct lys_module *module, const char *value, |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 119 | struct lys_include *inc, struct unres_schema *unres); |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 120 | int lyp_check_include_missing(struct lys_module *main_module); |
Pavol Vican | 58d2d4c | 2016-03-08 15:26:10 +0100 | [diff] [blame] | 121 | |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 122 | int lyp_check_import(struct lys_module *module, const char *value, struct lys_import *imp); |
Pavol Vican | 0da132e | 2016-03-21 12:03:03 +0100 | [diff] [blame] | 123 | |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 124 | void lyp_sort_revisions(struct lys_module *module); |
Radek Krejci | bf28583 | 2017-01-26 16:05:41 +0100 | [diff] [blame] | 125 | int lyp_rfn_apply_ext(struct lys_module *module); |
Radek Krejci | fe311c3 | 2017-01-27 16:58:59 +0100 | [diff] [blame] | 126 | int lyp_deviation_apply_ext(struct lys_module *module); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 127 | |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 128 | void lyp_ext_instance_rm(struct ly_ctx *ctx, struct lys_ext_instance ***ext, uint8_t *size, uint8_t index); |
| 129 | |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 130 | /** |
Pavol Vican | aa1eba9 | 2016-03-09 12:27:11 +0100 | [diff] [blame] | 131 | * @brief Propagate imports and includes into the main module |
| 132 | * |
| 133 | * @param module Main module |
Radek Krejci | b8f98c1 | 2016-06-24 10:30:46 +0200 | [diff] [blame] | 134 | * @param inc Filled include structure |
Pavol Vican | aa1eba9 | 2016-03-09 12:27:11 +0100 | [diff] [blame] | 135 | * @return 0 for success, 1 for failure |
| 136 | */ |
Radek Krejci | b8f98c1 | 2016-06-24 10:30:46 +0200 | [diff] [blame] | 137 | int lyp_propagate_submodule(struct lys_module *module, struct lys_include *inc); |
Pavol Vican | aa1eba9 | 2016-03-09 12:27:11 +0100 | [diff] [blame] | 138 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 139 | /* return: -1 = error, 0 = succes, 1 = already there */ |
| 140 | int lyp_ctx_check_module(struct lys_module *module); |
| 141 | |
| 142 | int lyp_ctx_add_module(struct lys_module *module); |
Pavol Vican | c99b59e | 2016-03-22 15:46:39 +0100 | [diff] [blame] | 143 | |
Pavol Vican | aa1eba9 | 2016-03-09 12:27:11 +0100 | [diff] [blame] | 144 | /** |
Radek Krejci | 0fb1150 | 2017-01-31 16:45:42 +0100 | [diff] [blame] | 145 | * @brief mmap() wrapper for parsers. To unmap, use lyp_munmap(). |
| 146 | * |
| 147 | * @param[in] prot The desired memory protection as in case of mmap(). |
| 148 | * @param[in] fd File descriptor for getting data. |
| 149 | * @param[in] addsize Number of additional bytes to be allocated (and zeroed) after the implicitly added |
| 150 | * string-terminating NULL byte. |
| 151 | * @param[out] length length of the allocated memory. |
| 152 | * @return On success, the pointer to the memory where the file data resists is returned. On error, the value MAP_FAILED |
| 153 | * is returned and #ly_errno value is set. |
| 154 | */ |
| 155 | void * |
| 156 | lyp_mmap(int fd, size_t addsize, size_t *length); |
| 157 | |
| 158 | /** |
| 159 | * @brief Unmap function for the data mapped by lyp_mmap() |
| 160 | */ |
| 161 | int lyp_munmap(void *addr, size_t length); |
| 162 | |
| 163 | /** |
Radek Krejci | 5449d47 | 2015-10-26 14:35:56 +0100 | [diff] [blame] | 164 | * Store UTF-8 character specified as 4byte integer into the dst buffer. |
| 165 | * Returns number of written bytes (4 max), expects that dst has enough space. |
| 166 | * |
| 167 | * UTF-8 mapping: |
| 168 | * 00000000 -- 0000007F: 0xxxxxxx |
| 169 | * 00000080 -- 000007FF: 110xxxxx 10xxxxxx |
| 170 | * 00000800 -- 0000FFFF: 1110xxxx 10xxxxxx 10xxxxxx |
| 171 | * 00010000 -- 001FFFFF: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx |
| 172 | * |
| 173 | */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 174 | unsigned int pututf8(char *dst, int32_t value); |
Radek Krejci | deee60e | 2016-09-23 15:21:14 +0200 | [diff] [blame] | 175 | unsigned int copyutf8(char *dst, const char *src); |
Radek Krejci | 5449d47 | 2015-10-26 14:35:56 +0100 | [diff] [blame] | 176 | |
Radek Krejci | 0a498f8 | 2017-01-04 16:24:15 +0100 | [diff] [blame] | 177 | /* |
| 178 | * Internal functions implementing YANG extensions support |
| 179 | * - implemented in extensions.c |
| 180 | */ |
| 181 | |
| 182 | /** |
| 183 | * @brief If available, get the extension plugin for the specified extension |
| 184 | * @param[in] name Name of the extension |
| 185 | * @param[in] module Name of the extension's module |
| 186 | * @param[in] revision Revision of the extension's module |
| 187 | * @return pointer to the extension plugin structure, NULL if no plugin available |
| 188 | */ |
| 189 | struct lyext_plugin *ext_get_plugin(const char *name, const char *module, const char *revision); |
| 190 | |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 191 | #endif /* LY_PARSER_H_ */ |