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> |
Radek Krejci | b7970f2 | 2017-03-17 16:12:12 +0100 | [diff] [blame] | 19 | #include <sys/mman.h> |
Michal Vasko | 0aee5c1 | 2016-06-17 14:27:26 +0200 | [diff] [blame] | 20 | |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 21 | #include "libyang.h" |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 22 | #include "tree_schema.h" |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 23 | #include "tree_internal.h" |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 24 | |
Andrew Fort | 892203a | 2018-02-16 16:37:16 -0800 | [diff] [blame] | 25 | #ifdef __APPLE__ |
Andrew Fort | 2341f3c | 2018-03-26 15:27:42 -0700 | [diff] [blame] | 26 | # ifndef MAP_ANONYMOUS |
| 27 | # define MAP_ANONYMOUS MAP_ANON |
| 28 | # endif |
Andrew Fort | 892203a | 2018-02-16 16:37:16 -0800 | [diff] [blame] | 29 | #endif |
| 30 | |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 31 | /** |
| 32 | * @defgroup yin YIN format support |
| 33 | * @{ |
| 34 | */ |
Radek Krejci | ff4874d | 2016-03-07 12:30:50 +0100 | [diff] [blame] | 35 | struct lys_module *yin_read_module(struct ly_ctx *ctx, const char *data, const char *revision, int implement); |
Michal Vasko | ed79390 | 2019-11-18 19:36:03 +0100 | [diff] [blame] | 36 | 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] | 37 | |
| 38 | /**@} yin */ |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 39 | |
Radek Krejci | b20c62d | 2015-07-07 17:07:14 +0200 | [diff] [blame] | 40 | /** |
| 41 | * @defgroup xmldata XML data format support |
| 42 | * @{ |
| 43 | */ |
Radek Krejci | 25b9fd3 | 2015-08-10 15:06:07 +0200 | [diff] [blame] | 44 | 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] | 45 | |
| 46 | /**@} xmldata */ |
| 47 | |
Radek Krejci | 5449d47 | 2015-10-26 14:35:56 +0100 | [diff] [blame] | 48 | /** |
| 49 | * @defgroup jsondata JSON data format support |
| 50 | * @{ |
| 51 | */ |
Michal Vasko | 945b96b | 2016-10-18 11:49:12 +0200 | [diff] [blame] | 52 | struct lyd_node *lyd_parse_json(struct ly_ctx *ctx, const char *data, int options, const struct lyd_node *rpc_act, |
PavolVican | 832f543 | 2018-02-21 00:54:45 +0100 | [diff] [blame] | 53 | const struct lyd_node *data_tree, const char *yang_data_name); |
Radek Krejci | 5449d47 | 2015-10-26 14:35:56 +0100 | [diff] [blame] | 54 | |
| 55 | /**@} jsondata */ |
| 56 | |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 57 | /** |
Michal Vasko | 1e82a3b | 2018-07-03 12:16:58 +0200 | [diff] [blame] | 58 | * @defgroup lybdata LYB data format support |
| 59 | * @{ |
| 60 | */ |
Michal Vasko | 228431e | 2018-07-10 15:47:11 +0200 | [diff] [blame] | 61 | struct lyd_node *lyd_parse_lyb(struct ly_ctx *ctx, const char *data, int options, const struct lyd_node *data_tree, |
| 62 | const char *yang_data_name, int *parsed); |
Michal Vasko | 1e82a3b | 2018-07-03 12:16:58 +0200 | [diff] [blame] | 63 | |
| 64 | /**@} lybdata */ |
| 65 | |
| 66 | /** |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 67 | * internal options values for schema parsers |
| 68 | */ |
| 69 | #define LYS_PARSE_OPT_CFG_NOINHERIT 0x01 /**< do not inherit config flag */ |
| 70 | #define LYS_PARSE_OPT_CFG_IGNORE 0x02 /**< ignore config flag (in rpc, actions, notifications) */ |
| 71 | #define LYS_PARSE_OPT_CFG_MASK 0x03 |
| 72 | #define LYS_PARSE_OPT_INGRP 0x04 /**< flag to know that parser is inside a grouping */ |
| 73 | |
Radek Krejci | 06a9aa0 | 2017-02-17 10:50:24 +0100 | [diff] [blame] | 74 | /* list of YANG statement strings */ |
| 75 | extern const char *ly_stmt_str[]; |
| 76 | |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 77 | enum LY_IDENT { |
| 78 | LY_IDENT_SIMPLE, /* only syntax rules */ |
| 79 | LY_IDENT_FEATURE, |
| 80 | LY_IDENT_IDENTITY, |
| 81 | LY_IDENT_TYPE, |
| 82 | LY_IDENT_NODE, |
| 83 | LY_IDENT_NAME, /* uniqueness across the siblings */ |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 84 | LY_IDENT_PREFIX, |
| 85 | LY_IDENT_EXTENSION |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 86 | }; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 87 | 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] | 88 | struct lys_module *module, struct lyxml_elem *yin, struct lys_ext_instance ***ext, |
fanchanghu | bf5c9c3 | 2021-01-21 20:56:39 +0800 | [diff] [blame] | 89 | uint8_t *ext_size, struct unres_schema *unres); |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 90 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 91 | int lyp_yin_parse_complex_ext(struct lys_module *mod, struct lys_ext_instance_complex *ext, |
| 92 | struct lyxml_elem *yin, struct unres_schema *unres); |
| 93 | int lyp_yin_parse_subnode_ext(struct lys_module *mod, void *elem, LYEXT_PAR elem_type, |
| 94 | struct lyxml_elem *yin, LYEXT_SUBSTMT type, uint8_t i, struct unres_schema *unres); |
| 95 | |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 96 | struct lys_type *lyp_get_next_union_type(struct lys_type *type, struct lys_type *prev_type, int *found); |
| 97 | |
Michal Vasko | 7675c62 | 2017-03-02 10:50:07 +0100 | [diff] [blame] | 98 | /* return: 0 - ret set, ok; 1 - ret not set, no log, unknown meta; -1 - ret not set, log, fatal error */ |
| 99 | int lyp_fill_attr(struct ly_ctx *ctx, struct lyd_node *parent, const char *module_ns, const char *module_name, |
Michal Vasko | 0abb1bc | 2020-02-25 15:47:10 +0100 | [diff] [blame] | 100 | const char *attr_name, const char *attr_value, struct lyxml_elem *xml, struct lyd_attr **ret); |
Michal Vasko | 7675c62 | 2017-03-02 10:50:07 +0100 | [diff] [blame] | 101 | |
| 102 | int lyp_check_edit_attr(struct ly_ctx *ctx, struct lyd_attr *attr, struct lyd_node *parent, int *editbits); |
| 103 | |
Radek Krejci | 1899d6a | 2016-11-03 13:48:07 +0100 | [diff] [blame] | 104 | struct lys_type *lyp_parse_value(struct lys_type *type, const char **value_, struct lyxml_elem *xml, |
Michal Vasko | 31a2d32 | 2018-01-12 13:36:12 +0100 | [diff] [blame] | 105 | struct lyd_node_leaf_list *leaf, struct lyd_attr *attr, struct lys_module *local_mod, |
Michal Vasko | 0abb1bc | 2020-02-25 15:47:10 +0100 | [diff] [blame] | 106 | int store, int dflt); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 107 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 108 | int lyp_check_length_range(struct ly_ctx *ctx, const char *expr, struct lys_type *type); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 109 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 110 | int lyp_check_pattern(struct ly_ctx *ctx, const char *pattern, pcre **pcre_precomp); |
| 111 | int lyp_precompile_pattern(struct ly_ctx *ctx, const char *pattern, pcre** pcre_cmp, pcre_extra **pcre_std); |
Michal Vasko | 0aee5c1 | 2016-06-17 14:27:26 +0200 | [diff] [blame] | 112 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 113 | 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] | 114 | int tpdftype, struct unres_schema *unres); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 115 | |
Radek Krejci | 4372b4e | 2016-04-14 17:42:16 +0200 | [diff] [blame] | 116 | int lyp_check_status(uint16_t flags1, struct lys_module *mod1, const char *name1, |
| 117 | uint16_t flags2, struct lys_module *mod2, const char *name2, |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 118 | const struct lys_node *node); |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 119 | |
Michal Vasko | 10681e8 | 2018-01-16 14:54:16 +0100 | [diff] [blame] | 120 | void lyp_del_includedup(struct lys_module *mod, int free_subs); |
Michal Vasko | 7b460e5 | 2017-02-10 14:50:26 +0100 | [diff] [blame] | 121 | |
Pavol Vican | 810892e | 2016-07-12 16:55:34 +0200 | [diff] [blame] | 122 | 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] | 123 | |
| 124 | int dup_identities_check(const char *id, struct lys_module *module); |
| 125 | |
Radek Krejci | 5449d47 | 2015-10-26 14:35:56 +0100 | [diff] [blame] | 126 | /** |
Michal Vasko | b1b1944 | 2016-07-13 12:26:01 +0200 | [diff] [blame] | 127 | * @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] | 128 | * |
| 129 | * @param node Schema node to be examined. |
| 130 | * @return 1 for true, 0 for false |
| 131 | */ |
Michal Vasko | b1b1944 | 2016-07-13 12:26:01 +0200 | [diff] [blame] | 132 | int lyp_is_rpc_action(struct lys_node *node); |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 133 | |
| 134 | /** |
Michal Vasko | e746a50 | 2017-08-11 10:56:40 +0200 | [diff] [blame] | 135 | * @brief Check validity of data parser options. |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 136 | * |
| 137 | * @param options Parser options to be checked. |
Radek Krejci | 86bafc2 | 2017-08-02 15:08:14 +0200 | [diff] [blame] | 138 | * @param func name of the function where called |
Michal Vasko | a55d96b | 2016-12-07 12:20:42 +0100 | [diff] [blame] | 139 | * @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] | 140 | */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 141 | int lyp_data_check_options(struct ly_ctx *ctx, int options, const char *func); |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 142 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 143 | int lyp_check_identifier(struct ly_ctx *ctx, const char *id, enum LY_IDENT type, struct lys_module *module, struct lys_node *parent); |
| 144 | int lyp_check_date(struct ly_ctx *ctx, const char *date); |
Radek Krejci | df24cbe | 2016-11-08 11:55:51 +0100 | [diff] [blame] | 145 | 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] | 146 | int lyp_check_mandatory_choice(struct lys_node *node); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 147 | |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 148 | int lyp_check_include(struct lys_module *module, const char *value, |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 149 | struct lys_include *inc, struct unres_schema *unres); |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 150 | int lyp_check_include_missing(struct lys_module *main_module); |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 151 | int lyp_check_import(struct lys_module *module, const char *value, struct lys_import *imp); |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 152 | int lyp_check_circmod_add(struct lys_module *module); |
| 153 | void lyp_check_circmod_pop(struct ly_ctx *ctx); |
Pavol Vican | 0da132e | 2016-03-21 12:03:03 +0100 | [diff] [blame] | 154 | |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 155 | void lyp_sort_revisions(struct lys_module *module); |
Radek Krejci | bf28583 | 2017-01-26 16:05:41 +0100 | [diff] [blame] | 156 | int lyp_rfn_apply_ext(struct lys_module *module); |
Radek Krejci | fe311c3 | 2017-01-27 16:58:59 +0100 | [diff] [blame] | 157 | int lyp_deviation_apply_ext(struct lys_module *module); |
PavolVican | c4b798e | 2017-02-20 23:15:27 +0100 | [diff] [blame] | 158 | int lyp_mand_check_ext(struct lys_ext_instance_complex *ext, const char *ext_name); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 159 | |
PavolVican | 205e67b | 2018-02-21 00:38:31 +0100 | [diff] [blame] | 160 | const char *lyp_get_yang_data_template_name(const struct lyd_node *node); |
| 161 | const struct lys_node *lyp_get_yang_data_template(const struct lys_module *module, const char *yang_data_name, int yang_data_name_len); |
| 162 | |
Michal Vasko | a310a45 | 2018-11-21 12:34:29 +0100 | [diff] [blame] | 163 | void lyp_ext_instance_rm(struct ly_ctx *ctx, struct lys_ext_instance ***ext, uint8_t *size, uint8_t index); |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 164 | |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 165 | /** |
fanchanghu | bf5c9c3 | 2021-01-21 20:56:39 +0800 | [diff] [blame] | 166 | * @brief Get extension instances from given parent node |
| 167 | * |
| 168 | * @param[in] ctx Context with the modules |
| 169 | * @param[in] elem Parent of the extension instances |
| 170 | * @param[in] elem_type Parent type of the extension instances |
| 171 | * @param[out] ext_list Address of the extension instance pointer array |
| 172 | * @param[out] ext_size Address of size of the extension instance pointer array |
| 173 | * @param[out] stmt Short name of the extension instance parent |
| 174 | * @return 0 for success, -1 for failure |
| 175 | */ |
| 176 | int lyp_get_ext_list(struct ly_ctx *ctx, void *elem, LYEXT_PAR elem_type, |
| 177 | struct lys_ext_instance ****ext_list, uint8_t **ext_size, const char **stmt); |
| 178 | |
| 179 | /** |
| 180 | * @brief Reduce extension instance pointer array |
| 181 | * |
| 182 | * @param[in] ext Address of the extension instance pointer array |
| 183 | * @param[in] new_size New size of the extension instance pointer array |
| 184 | * @param[in] orig_size Origin size of the extension instance pointer array |
| 185 | * @return 0 for success, -1 for failure |
| 186 | */ |
| 187 | void lyp_reduce_ext_list(struct lys_ext_instance ***ext, uint8_t new_size, uint8_t orig_size); |
| 188 | |
| 189 | /** |
Pavol Vican | aa1eba9 | 2016-03-09 12:27:11 +0100 | [diff] [blame] | 190 | * @brief Propagate imports and includes into the main module |
| 191 | * |
| 192 | * @param module Main module |
Radek Krejci | b8f98c1 | 2016-06-24 10:30:46 +0200 | [diff] [blame] | 193 | * @param inc Filled include structure |
Pavol Vican | aa1eba9 | 2016-03-09 12:27:11 +0100 | [diff] [blame] | 194 | * @return 0 for success, 1 for failure |
| 195 | */ |
Radek Krejci | b8f98c1 | 2016-06-24 10:30:46 +0200 | [diff] [blame] | 196 | int lyp_propagate_submodule(struct lys_module *module, struct lys_include *inc); |
Pavol Vican | aa1eba9 | 2016-03-09 12:27:11 +0100 | [diff] [blame] | 197 | |
Alanscut | 54723f0 | 2019-07-18 23:21:04 +0800 | [diff] [blame] | 198 | /* return: -1 = error, 0 = success, 1 = already there (if it was disabled, it is enabled first) */ |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 199 | int lyp_ctx_check_module(struct lys_module *module); |
| 200 | |
| 201 | int lyp_ctx_add_module(struct lys_module *module); |
Pavol Vican | c99b59e | 2016-03-22 15:46:39 +0100 | [diff] [blame] | 202 | |
Pavol Vican | aa1eba9 | 2016-03-09 12:27:11 +0100 | [diff] [blame] | 203 | /** |
Michal Vasko | b3d6d19 | 2018-11-05 10:02:10 +0100 | [diff] [blame] | 204 | * @brief Add annotations definitions of attributes and URL config used in ietf-netconf RPCs. |
Radek Krejci | 5b19066 | 2017-04-13 08:56:14 +0200 | [diff] [blame] | 205 | */ |
Michal Vasko | b3d6d19 | 2018-11-05 10:02:10 +0100 | [diff] [blame] | 206 | int lyp_add_ietf_netconf_annotations_config(struct lys_module *mod); |
Radek Krejci | 5b19066 | 2017-04-13 08:56:14 +0200 | [diff] [blame] | 207 | |
| 208 | /** |
Radek Krejci | 0fb1150 | 2017-01-31 16:45:42 +0100 | [diff] [blame] | 209 | * @brief mmap() wrapper for parsers. To unmap, use lyp_munmap(). |
| 210 | * |
| 211 | * @param[in] prot The desired memory protection as in case of mmap(). |
| 212 | * @param[in] fd File descriptor for getting data. |
| 213 | * @param[in] addsize Number of additional bytes to be allocated (and zeroed) after the implicitly added |
| 214 | * string-terminating NULL byte. |
| 215 | * @param[out] length length of the allocated memory. |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 216 | * @param[out] addr Pointer to the memory where the file data is mapped. |
| 217 | * @return 0 on success, non-zero on error. |
Radek Krejci | 0fb1150 | 2017-01-31 16:45:42 +0100 | [diff] [blame] | 218 | */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 219 | int lyp_mmap(struct ly_ctx *ctx, int fd, size_t addsize, size_t *length, void **addr); |
Radek Krejci | 0fb1150 | 2017-01-31 16:45:42 +0100 | [diff] [blame] | 220 | |
| 221 | /** |
| 222 | * @brief Unmap function for the data mapped by lyp_mmap() |
| 223 | */ |
| 224 | int lyp_munmap(void *addr, size_t length); |
| 225 | |
| 226 | /** |
Radek Krejci | 5449d47 | 2015-10-26 14:35:56 +0100 | [diff] [blame] | 227 | * Store UTF-8 character specified as 4byte integer into the dst buffer. |
| 228 | * Returns number of written bytes (4 max), expects that dst has enough space. |
| 229 | * |
| 230 | * UTF-8 mapping: |
| 231 | * 00000000 -- 0000007F: 0xxxxxxx |
| 232 | * 00000080 -- 000007FF: 110xxxxx 10xxxxxx |
| 233 | * 00000800 -- 0000FFFF: 1110xxxx 10xxxxxx 10xxxxxx |
| 234 | * 00010000 -- 001FFFFF: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx |
| 235 | * |
| 236 | */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 237 | unsigned int pututf8(struct ly_ctx *ctx, char *dst, int32_t value); |
| 238 | unsigned int copyutf8(struct ly_ctx *ctx, char *dst, const char *src); |
Radek Krejci | 5449d47 | 2015-10-26 14:35:56 +0100 | [diff] [blame] | 239 | |
Michal Vasko | 921eb6b | 2017-10-13 10:01:39 +0200 | [diff] [blame] | 240 | /** |
| 241 | * @brief Find a module. First, imports from \p module with matching \p prefix, \p name, or both are checked, |
| 242 | * \p module itself is also compared, and lastly a callback is used if allowed. |
| 243 | * |
| 244 | * @param[in] module Module with imports. |
| 245 | * @param[in] prefix Module prefix to search for. |
| 246 | * @param[in] pref_len Module \p prefix length. If 0, the whole prefix is used, if not NULL. |
| 247 | * @param[in] name Module name to search for. |
| 248 | * @param[in] name_len Module \p name length. If 0, the whole name is used, if not NULL. |
| 249 | * @param[in] in_data Whether to use data callback if not found after trying all the rest. |
| 250 | * Import callback is never used because there is no use-case for that. |
| 251 | * |
| 252 | * @return Matching module, NULL if not found. |
| 253 | */ |
| 254 | const struct lys_module *lyp_get_module(const struct lys_module *module, const char *prefix, int pref_len, |
| 255 | const char *name, int name_len, int in_data); |
| 256 | |
| 257 | /** |
| 258 | * @brief Find an import from \p module with matching namespace, the \p module itself is also considered. |
| 259 | * |
| 260 | * @param[in] module Module with imports. |
| 261 | * @param[in] ns Namespace to be found. |
| 262 | */ |
| 263 | const struct lys_module *lyp_get_import_module_ns(const struct lys_module *module, const char *ns); |
| 264 | |
Michal Vasko | c6cd3f0 | 2018-03-02 14:07:42 +0100 | [diff] [blame] | 265 | /* |
| 266 | * Internal functions implementing YANG (extension and user type) plugin support |
| 267 | * - implemented in plugins.c |
| 268 | */ |
| 269 | |
| 270 | /** |
| 271 | * @brief If available, get the extension plugin for the specified extension |
| 272 | * |
| 273 | * @param[in] name Name of the extension |
| 274 | * @param[in] module Name of the extension's module |
| 275 | * @param[in] revision Revision of the extension's module |
| 276 | * @return pointer to the extension plugin structure, NULL if no plugin available |
| 277 | */ |
| 278 | struct lyext_plugin *ext_get_plugin(const char *name, const char *module, const char *revision); |
| 279 | |
| 280 | /** |
| 281 | * @brief Try to store a value as a user type defined by a plugin. |
| 282 | * |
| 283 | * @param[in] mod Module of the type. |
| 284 | * @param[in] type_name Type (typedef) name. |
Michal Vasko | 717cb69 | 2018-12-19 15:13:25 +0100 | [diff] [blame] | 285 | * @param[in,out] value_str Stored string value, can be overwritten by the user store callback. |
Michal Vasko | c6cd3f0 | 2018-03-02 14:07:42 +0100 | [diff] [blame] | 286 | * @param[in,out] value Filled value to be overwritten by the user store callback. |
| 287 | * @return 0 on successful storing, 1 if the type is not a user type, -1 on error. |
| 288 | */ |
Michal Vasko | 717cb69 | 2018-12-19 15:13:25 +0100 | [diff] [blame] | 289 | int lytype_store(const struct lys_module *mod, const char *type_name, const char **value_str, lyd_val *value); |
Michal Vasko | c6cd3f0 | 2018-03-02 14:07:42 +0100 | [diff] [blame] | 290 | |
| 291 | /** |
| 292 | * @brief Free a user type stored value. |
| 293 | * |
Michal Vasko | d3dd15d | 2019-01-23 14:06:58 +0100 | [diff] [blame] | 294 | * @param[in] type Type of the value. |
Michal Vasko | c6cd3f0 | 2018-03-02 14:07:42 +0100 | [diff] [blame] | 295 | * @param[in] value Value union to free. |
Michal Vasko | d3dd15d | 2019-01-23 14:06:58 +0100 | [diff] [blame] | 296 | * @param[in] value_str String value of the value. |
Michal Vasko | c6cd3f0 | 2018-03-02 14:07:42 +0100 | [diff] [blame] | 297 | */ |
Michal Vasko | d3dd15d | 2019-01-23 14:06:58 +0100 | [diff] [blame] | 298 | void lytype_free(const struct lys_type *type, lyd_val value, const char *value_str); |
Michal Vasko | c6cd3f0 | 2018-03-02 14:07:42 +0100 | [diff] [blame] | 299 | |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 300 | #endif /* LY_PARSER_H_ */ |