David Sedlák | b1ce3f8 | 2019-06-05 14:37:26 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file parser_yin.h |
| 3 | * @author David Sedlák <xsedla1d@stud.fit.vutbr.cz> |
| 4 | * @brief YIN parser. |
| 5 | * |
| 6 | * Copyright (c) 2015 - 2019 CESNET, z.s.p.o. |
| 7 | * |
| 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 |
| 13 | */ |
David Sedlák | 2b626ee | 2019-06-03 16:40:18 +0200 | [diff] [blame] | 14 | |
| 15 | #ifndef LY_PARSER_YIN_H_ |
| 16 | #define LY_PARSER_YIN_H_ |
| 17 | |
| 18 | #include <stdio.h> |
David Sedlák | b1ce3f8 | 2019-06-05 14:37:26 +0200 | [diff] [blame] | 19 | #include <stdlib.h> |
| 20 | |
David Sedlák | 2b626ee | 2019-06-03 16:40:18 +0200 | [diff] [blame] | 21 | #include "log.h" |
| 22 | #include "xml.h" |
David Sedlák | 2b626ee | 2019-06-03 16:40:18 +0200 | [diff] [blame] | 23 | |
David Sedlák | f625118 | 2019-06-06 10:22:13 +0200 | [diff] [blame] | 24 | /* list of yin attribute strings */ |
| 25 | extern const char *const yin_attr_list[]; |
| 26 | #define yin_attr2str(STMT) yin_attr_list[STMT] |
| 27 | |
David Sedlák | 2b214ac | 2019-06-06 16:11:03 +0200 | [diff] [blame] | 28 | #define YIN_NS_URI "urn:ietf:params:xml:ns:yang:yin:1" |
David Sedlák | d6e5689 | 2019-07-01 15:40:24 +0200 | [diff] [blame] | 29 | #define name2fullname(name, prefix_len) (prefix_len != 0 ? name - (prefix_len + 1) : name) |
David Sedlák | f250ecf | 2019-07-01 11:02:05 +0200 | [diff] [blame] | 30 | #define namelen2fulllen(name_len, prefix_len) (prefix_len != 0 ? name_len + prefix_len + 1 : name_len) |
David Sedlák | 2b214ac | 2019-06-06 16:11:03 +0200 | [diff] [blame] | 31 | |
David Sedlák | 2b626ee | 2019-06-03 16:40:18 +0200 | [diff] [blame] | 32 | enum YIN_ARGUMENT { |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 33 | YIN_ARG_UNKNOWN = 0, /**< parsed argument can not be matched with any supported yin argument keyword */ |
David Sedlák | 2b626ee | 2019-06-03 16:40:18 +0200 | [diff] [blame] | 34 | YIN_ARG_NAME, /**< argument name */ |
| 35 | YIN_ARG_TARGET_NODE, /**< argument target-node */ |
| 36 | YIN_ARG_MODULE, /**< argument module */ |
| 37 | YIN_ARG_VALUE, /**< argument value */ |
| 38 | YIN_ARG_TEXT, /**< argument text */ |
| 39 | YIN_ARG_CONDITION, /**< argument condition */ |
| 40 | YIN_ARG_URI, /**< argument uri */ |
| 41 | YIN_ARG_DATE, /**< argument data */ |
| 42 | YIN_ARG_TAG, /**< argument tag */ |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 43 | YIN_ARG_NONE, /**< empty (special value) */ |
David Sedlák | 7ff55a9 | 2019-06-17 11:11:41 +0200 | [diff] [blame] | 44 | }; |
| 45 | |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 46 | /** |
| 47 | * @brief structure to store instance of xml attribute |
| 48 | */ |
David Sedlák | 7ff55a9 | 2019-06-17 11:11:41 +0200 | [diff] [blame] | 49 | struct yin_arg_record { |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 50 | const char *prefix; /**< start of prefix */ |
| 51 | size_t prefix_len; /**< length of prefix */ |
| 52 | const char *name; /**< start of name */ |
| 53 | size_t name_len; /**< length of name */ |
| 54 | char *content; /**< start of content */ |
| 55 | size_t content_len; /**< length of content */ |
| 56 | int dynamic_content; /**< is set to 1 iff content is dynamically allocated 0 otherwise */ |
David Sedlák | 2b626ee | 2019-06-03 16:40:18 +0200 | [diff] [blame] | 57 | }; |
| 58 | |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 59 | struct yin_parser_ctx { |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 60 | struct ly_set tpdfs_nodes; |
| 61 | struct ly_set grps_nodes; |
David Sedlák | bba38e5 | 2019-07-09 15:20:01 +0200 | [diff] [blame] | 62 | uint8_t mod_version; /**< module's version */ |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 63 | struct lyxml_context xml_ctx; /**< context for xml parser */ |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 64 | }; |
| 65 | |
David Sedlák | 3ffbc52 | 2019-07-02 17:49:28 +0200 | [diff] [blame] | 66 | /* flags to encode cardinality of subelement */ |
| 67 | #define YIN_SUBELEM_MANDATORY 0x01 /**< is set when subelement is mandatory */ |
| 68 | #define YIN_SUBELEM_UNIQUE 0x02 /**< is set when subelement is unique */ |
David Sedlák | e1a3030 | 2019-07-10 13:49:38 +0200 | [diff] [blame] | 69 | #define YIN_SUBELEM_FIRST 0x04 /**< is set when subelement is actually yang argument mapped to yin element */ |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 70 | #define YIN_SUBELEM_VER2 0x08 /**< subelemnt is allowed only in modules with version at least 2 (YANG 1.1) */ |
David Sedlák | 21f87cd | 2019-07-03 16:53:23 +0200 | [diff] [blame] | 71 | |
| 72 | #define YIN_SUBELEM_PARSED 0x80 /**< is set during parsing when given subelement is encountered for the first |
David Sedlák | 3ffbc52 | 2019-07-02 17:49:28 +0200 | [diff] [blame] | 73 | time to simply check validity of given constraints */ |
| 74 | |
| 75 | struct yin_subelement { |
| 76 | enum yang_keyword type; /**< type of keyword */ |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 77 | void *dest; /**< meta infromation passed to responsible function (mostly information about where parsed subelement should be stored) */ |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 78 | uint8_t flags; /**< describes cardianlity of subelement can be set to YIN_SUBELEM_MANDATORY and YIN_SUBELEM_UNIQUE and YIN_SUBELEM_FIRST */ |
David Sedlák | 3ffbc52 | 2019-07-02 17:49:28 +0200 | [diff] [blame] | 79 | }; |
| 80 | |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 81 | /* helper structure just to make code look simpler */ |
David Sedlák | 3ffbc52 | 2019-07-02 17:49:28 +0200 | [diff] [blame] | 82 | struct sized_string { |
| 83 | const char *value; |
| 84 | size_t len; |
| 85 | }; |
| 86 | |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 87 | /* Meta information passed to yin_parse_argument function, |
| 88 | holds information about where content of argument element will be stored. */ |
David Sedlák | 3ffbc52 | 2019-07-02 17:49:28 +0200 | [diff] [blame] | 89 | struct yin_argument_meta { |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 90 | uint16_t *flags; /**< Argument flags */ |
| 91 | const char **argument; /**< Argument value */ |
David Sedlák | 3ffbc52 | 2019-07-02 17:49:28 +0200 | [diff] [blame] | 92 | }; |
| 93 | |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 94 | /* Meta information passed to functions working with tree schema such as yin_parse_any */ |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 95 | struct tree_node_meta { |
| 96 | struct lysp_node *parent; /**< parent node */ |
| 97 | struct lysp_node **siblings; /**< linked list of siblings */ |
| 98 | }; |
| 99 | |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 100 | /* Meta information passed to yin_parse_typedef */ |
| 101 | struct typedef_meta { |
| 102 | struct lysp_node *parent; /**< parent node */ |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 103 | struct lysp_tpdf **typedefs; /**< [Sized array](@ref sizedarrays) of typedefs to add to */ |
| 104 | }; |
| 105 | |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 106 | /* Meta information passed to yin_parse_augment function */ |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 107 | struct augment_meta { |
| 108 | struct lysp_node *parent; /**< parent node */ |
| 109 | struct lysp_augment **augments; /**< [Sized array](@ref sizedarrays) of augments to add to */ |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 110 | }; |
| 111 | |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 112 | /* Meta information passed to yin_parse_include function */ |
| 113 | struct include_meta { |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 114 | const char *name; /**< Module/submodule name. */ |
| 115 | struct lysp_include **includes; /**< [Sized array](@ref sizedarrays) of parsed includes to add to. */ |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 116 | }; |
| 117 | |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 118 | /* Meta information passed to yin_parse_notification function */ |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 119 | struct notif_meta { |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 120 | struct lysp_node *parent; /**< Parent node. */ |
| 121 | struct lysp_notif **notifs; /**< [Sized array](@ref sizedarrays) of notifications to add to. */ |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 122 | }; |
| 123 | |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 124 | /* Meta information passed to yin_parse_grouping function */ |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 125 | struct grouping_meta { |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 126 | struct lysp_node *parent; /**< Parent node. */ |
| 127 | struct lysp_grp **groupings; /**< [Sized array](@ref sizedarrays) of groupings to add to. */ |
| 128 | }; |
| 129 | |
| 130 | /* Meta information passed to yin_parse_grouping function */ |
| 131 | struct inout_meta { |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 132 | struct lysp_node *parent; /**< Parent node. */ |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 133 | struct lysp_action_inout *inout_p; /**< inout_p Input/output pointer to write to. */ |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 134 | }; |
| 135 | |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame^] | 136 | /* Meta information passed to yin_parse_action function */ |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 137 | struct action_meta { |
| 138 | struct lysp_node *parent; /**< Parent node. */ |
| 139 | struct lysp_action **actions; /**< Actions to add to. */ |
| 140 | }; |
| 141 | |
David Sedlák | 2b626ee | 2019-06-03 16:40:18 +0200 | [diff] [blame] | 142 | /** |
| 143 | * @brief Match argument name. |
| 144 | * |
| 145 | * @param[in] name String representing name. |
| 146 | * @param[in] len Lenght of the name. |
| 147 | * |
David Sedlák | b1ce3f8 | 2019-06-05 14:37:26 +0200 | [diff] [blame] | 148 | * @return YIN_ARGUMENT value. |
David Sedlák | 2b626ee | 2019-06-03 16:40:18 +0200 | [diff] [blame] | 149 | */ |
David Sedlák | 060b00e | 2019-06-19 11:12:06 +0200 | [diff] [blame] | 150 | enum YIN_ARGUMENT yin_match_argument_name(const char *name, size_t len); |
David Sedlák | 2b626ee | 2019-06-03 16:40:18 +0200 | [diff] [blame] | 151 | |
| 152 | /** |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 153 | * @brief Generic function for content parsing |
David Sedlák | 2b626ee | 2019-06-03 16:40:18 +0200 | [diff] [blame] | 154 | * |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 155 | * @param[in,out] ctx Yin parser context for logging and to store current state. |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 156 | * @param[in] subelem_info array of valid subelement types and meta information, |
| 157 | * array must be ordered by subelem_info->type in ascending order. |
| 158 | * @param[in] subelem_info_size Size of subelem_info array. |
| 159 | * @param[in,out] data Data to read from, always moved to currently handled character. |
| 160 | * @param[in] current_element Type of current element. |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 161 | * @param[out] text_content Where the text content of element should be stored if any. Text content is ignored if set to NULL. |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 162 | * @param[in,out] exts Extension instance to add to. Can be se to null if element cannot have extension as subelements. |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 163 | |
David Sedlák | 2b214ac | 2019-06-06 16:11:03 +0200 | [diff] [blame] | 164 | * @return LY_ERR values. |
David Sedlák | 2b626ee | 2019-06-03 16:40:18 +0200 | [diff] [blame] | 165 | */ |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 166 | LY_ERR yin_parse_content(struct yin_parser_ctx *ctx, struct yin_subelement *subelem_info, signed char subelem_info_size, |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 167 | const char **data, enum yang_keyword current_element, const char **text_content, |
| 168 | struct lysp_ext_instance **exts); |
David Sedlák | 2b626ee | 2019-06-03 16:40:18 +0200 | [diff] [blame] | 169 | |
David Sedlák | d9d3a31 | 2019-06-04 09:47:10 +0200 | [diff] [blame] | 170 | /** |
David Sedlák | 92147b0 | 2019-07-09 14:01:01 +0200 | [diff] [blame] | 171 | * @brief Parse yang-version element. |
| 172 | * |
| 173 | * @param[in,out] ctx Yin parser context for logging and to store current state. |
David Sedlák | bba38e5 | 2019-07-09 15:20:01 +0200 | [diff] [blame] | 174 | * @param[in] attrs [Sized array](@ref sizedarrays) of attributes of yang-version element. |
David Sedlák | 92147b0 | 2019-07-09 14:01:01 +0200 | [diff] [blame] | 175 | * @param[in] data Data to read from, always moved to currently handled character. |
| 176 | * @param[out] version Storage for the parsed information. |
| 177 | * @param[in,out] exts Extension instance to add to. |
| 178 | * |
| 179 | * @return LY_ERR values. |
| 180 | */ |
| 181 | LY_ERR yin_parse_yangversion(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, const char **data, uint8_t *version, |
| 182 | struct lysp_ext_instance **exts); |
| 183 | |
| 184 | /** |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 185 | * @brief Check that val is valid UTF8 character sequence of val_type. |
| 186 | * Doesn't check empty string, only character validity. |
| 187 | * |
| 188 | * @param[in] ctx Yin parser context for logging. |
| 189 | * @param[in] val_type Type of the input string to select method of checking character validity. |
| 190 | * @param[in] val Input to validate. |
| 191 | * @param[in] len Length of input. |
| 192 | * |
| 193 | * @return LY_ERR values. |
| 194 | */ |
| 195 | LY_ERR yin_validate_value(struct yin_parser_ctx *ctx, enum yang_arg val_type, char *val, size_t len); |
| 196 | |
| 197 | /** |
David Sedlák | 2b214ac | 2019-06-06 16:11:03 +0200 | [diff] [blame] | 198 | * @brief Parse import element. |
David Sedlák | da63c08 | 2019-06-04 13:52:23 +0200 | [diff] [blame] | 199 | * |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 200 | * @param[in,out] ctx Yin parser context for logging and to store current state. |
David Sedlák | bba38e5 | 2019-07-09 15:20:01 +0200 | [diff] [blame] | 201 | * @param[in] attrs [Sized array](@ref sizedarrays) of attributes of import element. |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 202 | * @param[in,out] data Data to read from, always moved to currently handled character. |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 203 | * @param[in,out] mod Structure of module that is being parsed. |
David Sedlák | da63c08 | 2019-06-04 13:52:23 +0200 | [diff] [blame] | 204 | * |
David Sedlák | 2b214ac | 2019-06-06 16:11:03 +0200 | [diff] [blame] | 205 | * @return LY_ERR values. |
David Sedlák | da63c08 | 2019-06-04 13:52:23 +0200 | [diff] [blame] | 206 | */ |
David Sedlák | 1f90d25 | 2019-07-10 17:09:32 +0200 | [diff] [blame] | 207 | LY_ERR yin_parse_import(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, |
David Sedlák | 619db94 | 2019-07-03 14:47:30 +0200 | [diff] [blame] | 208 | const char **data, struct lysp_module *mod); |
David Sedlák | 2b626ee | 2019-06-03 16:40:18 +0200 | [diff] [blame] | 209 | |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 210 | /** |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 211 | * @brief Match yang keyword from yin data. |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 212 | * |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 213 | * @param[in,out] ctx Yin parser context for logging and to store current state. |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 214 | * @param[in] name Start of keyword name |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 215 | * @param[in] name_len Lenght of keyword name. |
| 216 | * @param[in] prefix Start of keyword prefix. |
| 217 | * @param[in] prefix_len lenght of prefix. |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 218 | * @param[in] parrent Identification of parrent element, use YANG_NONE for elements without parrent. |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 219 | * |
| 220 | * @return yang_keyword values. |
| 221 | */ |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 222 | enum yang_keyword yin_match_keyword(struct yin_parser_ctx *ctx, const char *name, size_t name_len, |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 223 | const char *prefix, size_t prefix_len, enum yang_keyword parrent); |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 224 | |
David Sedlák | b6e6597 | 2019-06-19 10:44:13 +0200 | [diff] [blame] | 225 | /** |
David Sedlák | 1fdb252 | 2019-07-09 16:22:57 +0200 | [diff] [blame] | 226 | * @brief Parse mandatory element. |
| 227 | * |
| 228 | * @param[in,out] ctx Yin parser context for logging and to store current state. |
| 229 | * @param[in] attrs [Sized array](@ref sizedarrays) of attributes of status element. |
| 230 | * @param[in,out] data Data to read from, always moved to currently handled character. |
| 231 | * @param[in,out] flags Flags to add to. |
| 232 | * @param[in,out] exts Extension instances to add to. |
| 233 | * |
| 234 | * @return LY_ERR values. |
| 235 | */ |
| 236 | LY_ERR yin_parse_mandatory(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, const char **data, |
| 237 | uint16_t *flags, struct lysp_ext_instance **exts); |
| 238 | |
| 239 | /** |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 240 | * @brief Parse status element. |
David Sedlák | b6e6597 | 2019-06-19 10:44:13 +0200 | [diff] [blame] | 241 | * |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 242 | * @param[in,out] ctx Yin parser context for logging and to store current state. |
David Sedlák | bba38e5 | 2019-07-09 15:20:01 +0200 | [diff] [blame] | 243 | * @param[in] attrs [Sized array](@ref sizedarrays) of attributes of status element. |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 244 | * @param[in,out] data Data to read from, always moved to currently handled character. |
David Sedlák | b6e6597 | 2019-06-19 10:44:13 +0200 | [diff] [blame] | 245 | * @param[in,out] flags Flags to add to. |
| 246 | * @param[in,out] exts Extension instances to add to. |
| 247 | * |
| 248 | * @return LY_ERR values. |
| 249 | */ |
David Sedlák | 1f90d25 | 2019-07-10 17:09:32 +0200 | [diff] [blame] | 250 | LY_ERR yin_parse_status(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, const char **data, |
David Sedlák | 554e36d | 2019-06-20 16:00:04 +0200 | [diff] [blame] | 251 | uint16_t *flags, struct lysp_ext_instance **exts); |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 252 | |
| 253 | /** |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 254 | * @brief Parse when element. |
| 255 | * |
| 256 | * @param[in,out] ctx Yin parser context for logging and to store current state. |
David Sedlák | bba38e5 | 2019-07-09 15:20:01 +0200 | [diff] [blame] | 257 | * @param[in] attrs [Sized array](@ref sizedarrays) of attributes of when element. |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 258 | * @param[in,out] data Data to read from, always moved to currently handled character. |
| 259 | * @param[out] when_p When pointer to parse to. |
| 260 | */ |
David Sedlák | bba38e5 | 2019-07-09 15:20:01 +0200 | [diff] [blame] | 261 | LY_ERR yin_parse_when(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, const char **data, |
| 262 | struct lysp_when **when_p); |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 263 | |
| 264 | /** |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 265 | * @brief Parse revision date element. |
David Sedlák | 3ffbc52 | 2019-07-02 17:49:28 +0200 | [diff] [blame] | 266 | * |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 267 | * @param[in,out] ctx Yin parser context for logging and to store current state. |
David Sedlák | bba38e5 | 2019-07-09 15:20:01 +0200 | [diff] [blame] | 268 | * @param[in] attrs [Sized array](@ref sizedarrays) of attributes of revision-date element. |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 269 | * @param[in,out] data Data to read from, always moved to currently handled character. |
David Sedlák | 3ffbc52 | 2019-07-02 17:49:28 +0200 | [diff] [blame] | 270 | * @param[in,out] rev Array to store the parsed value in. |
| 271 | * @param[in,out] exts Extension instances to add to. |
| 272 | * |
| 273 | * @return LY_ERR values. |
| 274 | */ |
David Sedlák | 1f90d25 | 2019-07-10 17:09:32 +0200 | [diff] [blame] | 275 | LY_ERR yin_parse_revision_date(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, const char **data, |
David Sedlák | 3ffbc52 | 2019-07-02 17:49:28 +0200 | [diff] [blame] | 276 | char *rev, struct lysp_ext_instance **exts); |
| 277 | |
| 278 | /** |
David Sedlák | bba38e5 | 2019-07-09 15:20:01 +0200 | [diff] [blame] | 279 | * @brief load all attributes of element into ([sized array](@ref sizedarrays)). Caller is suposed to free the array. |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 280 | * |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 281 | * @param[in,out] ctx Yin parser context for logging and to store current state. |
| 282 | * @param[in,out] data Data to read from, always moved to currently handled character. |
David Sedlák | bba38e5 | 2019-07-09 15:20:01 +0200 | [diff] [blame] | 283 | * @param[out] attrs ([Sized array](@ref sizedarrays)) of attributes. |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 284 | * |
| 285 | * @return LY_ERR values. |
| 286 | */ |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 287 | LY_ERR yin_load_attributes(struct yin_parser_ctx *ctx, const char **data, struct yin_arg_record **attrs); |
David Sedlák | b6e6597 | 2019-06-19 10:44:13 +0200 | [diff] [blame] | 288 | |
David Sedlák | 554e36d | 2019-06-20 16:00:04 +0200 | [diff] [blame] | 289 | /** |
David Sedlák | 2721d3d | 2019-06-21 15:37:41 +0200 | [diff] [blame] | 290 | * @brief Parse yin-elemenet element. |
| 291 | * |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 292 | * @param[in,out] ctx Yin parser context for logging and to store current state. |
David Sedlák | bba38e5 | 2019-07-09 15:20:01 +0200 | [diff] [blame] | 293 | * @param[in] attrs [Sized array](@ref sizedarrays) of attributes of yin-element element. |
David Sedlák | 2721d3d | 2019-06-21 15:37:41 +0200 | [diff] [blame] | 294 | * @param[in,out] data Data to read from, always moved to currently handled position. |
| 295 | * @param[in,out] flags Flags to add to. |
David Sedlák | 3ffbc52 | 2019-07-02 17:49:28 +0200 | [diff] [blame] | 296 | * @prama[in,out] exts Extension instance to add to. |
David Sedlák | 2721d3d | 2019-06-21 15:37:41 +0200 | [diff] [blame] | 297 | * |
| 298 | * @return LY_ERR values. |
| 299 | */ |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 300 | LY_ERR yin_parse_yin_element_element(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, const char **data, |
David Sedlák | 3ffbc52 | 2019-07-02 17:49:28 +0200 | [diff] [blame] | 301 | uint16_t *flags, struct lysp_ext_instance **exts); |
| 302 | |
| 303 | /** |
| 304 | * @brief Parse argument element. |
| 305 | * |
| 306 | * @param[in,out] xml_ctx Xml context. |
David Sedlák | bba38e5 | 2019-07-09 15:20:01 +0200 | [diff] [blame] | 307 | * @param[in] attrs [Sized array](@ref sizedarrays) of attributes of argument element. |
David Sedlák | 3ffbc52 | 2019-07-02 17:49:28 +0200 | [diff] [blame] | 308 | * @param[in,out] data Data to read from, always moved to currently handled character. |
| 309 | * @param[in,out] arg_meta Meta information about destionation af prased data. |
| 310 | * @param[in,out] exts Extension instance to add to. |
| 311 | * |
| 312 | * @return LY_ERR values. |
| 313 | */ |
David Sedlák | 1f90d25 | 2019-07-10 17:09:32 +0200 | [diff] [blame] | 314 | LY_ERR yin_parse_argument_element(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, const char **data, |
David Sedlák | 3ffbc52 | 2019-07-02 17:49:28 +0200 | [diff] [blame] | 315 | struct yin_argument_meta *arg_meta, struct lysp_ext_instance **exts); |
David Sedlák | 2721d3d | 2019-06-21 15:37:41 +0200 | [diff] [blame] | 316 | |
| 317 | /** |
David Sedlák | 554e36d | 2019-06-20 16:00:04 +0200 | [diff] [blame] | 318 | * @brief Parse the extension statement. |
| 319 | * |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 320 | * @param[in,out] ctx Yin parser context for logging and to store current state. |
David Sedlák | bba38e5 | 2019-07-09 15:20:01 +0200 | [diff] [blame] | 321 | * @param[in] attrs [Sized array](@ref sizedarrays) of attributes of extension element. |
David Sedlák | 554e36d | 2019-06-20 16:00:04 +0200 | [diff] [blame] | 322 | * @param[in,out] data Data to read from. |
| 323 | * @param[in,out] extensions Extensions to add to. |
| 324 | * |
| 325 | * @return LY_ERR values. |
| 326 | */ |
David Sedlák | 1f90d25 | 2019-07-10 17:09:32 +0200 | [diff] [blame] | 327 | LY_ERR yin_parse_extension(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, |
David Sedlák | 554e36d | 2019-06-20 16:00:04 +0200 | [diff] [blame] | 328 | const char **data, struct lysp_ext **extensions); |
| 329 | |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 330 | /** |
| 331 | * @brief Parse instance of extension. |
| 332 | * |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 333 | * @param[in,out] ctx Yin parser context for logging and to store current state. |
David Sedlák | bba38e5 | 2019-07-09 15:20:01 +0200 | [diff] [blame] | 334 | * @param[in] attrs [Sized array](@ref sizedarrays) of attributes of extension instance. |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 335 | * @param[in,out] data Data to read from, always moved to currently handled character. |
| 336 | * @param[in] ext_name Name of the extension element. |
| 337 | * @param[in] ext_name_len Length of extension name. |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 338 | * @param[in] subelem Type of the keyword this extension instance is a subelement of. |
| 339 | * @param[in] subelem_index Index of the keyword instance this extension instance is a subelement of |
| 340 | * @param[in,out] exts Extension instance to add to. |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 341 | * |
| 342 | * @return LY_ERR values. |
| 343 | */ |
David Sedlák | 1f90d25 | 2019-07-10 17:09:32 +0200 | [diff] [blame] | 344 | LY_ERR yin_parse_extension_instance(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, const char **data, |
David Sedlák | 619db94 | 2019-07-03 14:47:30 +0200 | [diff] [blame] | 345 | const char *ext_name, int ext_name_len, LYEXT_SUBSTMT subelem, |
| 346 | uint32_t subelem_index, struct lysp_ext_instance **exts); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 347 | |
| 348 | /** |
| 349 | * @brief Parse yin element into generic structure. |
| 350 | * |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 351 | * @param[in,out] ctx Yin parser context for logging and to store current state. |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 352 | * @param[in] name Name of element. |
| 353 | * @param[in] name_len Length of elements Name. |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 354 | * @param[in] prefix Element prefix. |
| 355 | * @param[in] prefix_len Length of element prefix. |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 356 | * @param[in,out] data Data to read from, always moved to currently handled character. |
| 357 | * @param[out] element Where the element structure should be stored. |
| 358 | * |
| 359 | * @return LY_ERR values. |
| 360 | */ |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 361 | LY_ERR yin_parse_element_generic(struct yin_parser_ctx *ctx, const char *name, size_t name_len, const char *prefix, |
| 362 | size_t prefix_len, const char **data, struct lysp_stmt **element); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 363 | |
David Sedlák | 2b626ee | 2019-06-03 16:40:18 +0200 | [diff] [blame] | 364 | #endif /* LY_PARSER_YIN_H_*/ |