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" |
| 29 | |
David Sedlák | 2b626ee | 2019-06-03 16:40:18 +0200 | [diff] [blame] | 30 | enum YIN_ARGUMENT { |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 31 | 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] | 32 | YIN_ARG_NAME, /**< argument name */ |
| 33 | YIN_ARG_TARGET_NODE, /**< argument target-node */ |
| 34 | YIN_ARG_MODULE, /**< argument module */ |
| 35 | YIN_ARG_VALUE, /**< argument value */ |
| 36 | YIN_ARG_TEXT, /**< argument text */ |
| 37 | YIN_ARG_CONDITION, /**< argument condition */ |
| 38 | YIN_ARG_URI, /**< argument uri */ |
| 39 | YIN_ARG_DATE, /**< argument data */ |
| 40 | YIN_ARG_TAG, /**< argument tag */ |
| 41 | YIN_ARG_XMLNS, /**< argument xmlns */ |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 42 | YIN_ARG_NONE, /**< empty (special value) */ |
David Sedlák | 7ff55a9 | 2019-06-17 11:11:41 +0200 | [diff] [blame] | 43 | }; |
| 44 | |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 45 | /** |
| 46 | * @brief structure to store instance of xml attribute |
| 47 | */ |
David Sedlák | 7ff55a9 | 2019-06-17 11:11:41 +0200 | [diff] [blame] | 48 | struct yin_arg_record { |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 49 | const char *prefix; /**< start of prefix */ |
| 50 | size_t prefix_len; /**< length of prefix */ |
| 51 | const char *name; /**< start of name */ |
| 52 | size_t name_len; /**< length of name */ |
| 53 | char *content; /**< start of content */ |
| 54 | size_t content_len; /**< length of content */ |
| 55 | 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] | 56 | }; |
| 57 | |
| 58 | /** |
| 59 | * @brief Match argument name. |
| 60 | * |
| 61 | * @param[in] name String representing name. |
| 62 | * @param[in] len Lenght of the name. |
| 63 | * |
David Sedlák | b1ce3f8 | 2019-06-05 14:37:26 +0200 | [diff] [blame] | 64 | * @return YIN_ARGUMENT value. |
David Sedlák | 2b626ee | 2019-06-03 16:40:18 +0200 | [diff] [blame] | 65 | */ |
| 66 | enum YIN_ARGUMENT match_argument_name(const char *name, size_t len); |
| 67 | |
| 68 | /** |
| 69 | * @brief Parse content of whole element as text. |
| 70 | * |
| 71 | * @param[in] xml_ctx Xml context. |
David Sedlák | b666bcc | 2019-06-05 15:00:05 +0200 | [diff] [blame] | 72 | * @param[in,out] data Data to read from. |
David Sedlák | 2b626ee | 2019-06-03 16:40:18 +0200 | [diff] [blame] | 73 | * @param[out] value Where content of element should be stored. |
David Sedlák | b1ce3f8 | 2019-06-05 14:37:26 +0200 | [diff] [blame] | 74 | * |
David Sedlák | 2b214ac | 2019-06-06 16:11:03 +0200 | [diff] [blame] | 75 | * @return LY_ERR values. |
David Sedlák | 2b626ee | 2019-06-03 16:40:18 +0200 | [diff] [blame] | 76 | */ |
| 77 | LY_ERR parse_text_element(struct lyxml_context *xml_ctx, const char **data, const char **value); |
| 78 | |
David Sedlák | d9d3a31 | 2019-06-04 09:47:10 +0200 | [diff] [blame] | 79 | /** |
David Sedlák | 2b214ac | 2019-06-06 16:11:03 +0200 | [diff] [blame] | 80 | * @brief Parse import element. |
David Sedlák | da63c08 | 2019-06-04 13:52:23 +0200 | [diff] [blame] | 81 | * |
| 82 | * @param[in] xml_ctx Xml context. |
| 83 | * @param[in] module_prefix Prefix of the module to check prefix collisions. |
David Sedlák | b666bcc | 2019-06-05 15:00:05 +0200 | [diff] [blame] | 84 | * @param[in,out] data Dta to read from. |
| 85 | * @param[in,out] imports Parsed imports to add to. |
David Sedlák | da63c08 | 2019-06-04 13:52:23 +0200 | [diff] [blame] | 86 | * |
David Sedlák | 2b214ac | 2019-06-06 16:11:03 +0200 | [diff] [blame] | 87 | * @return LY_ERR values. |
David Sedlák | da63c08 | 2019-06-04 13:52:23 +0200 | [diff] [blame] | 88 | */ |
| 89 | LY_ERR yin_parse_import(struct lyxml_context *xml_ctx, const char *module_prefix, const char **data, struct lysp_import **imports); |
David Sedlák | 2b626ee | 2019-06-03 16:40:18 +0200 | [diff] [blame] | 90 | |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 91 | /** |
| 92 | * @brief match yang keyword from yin data |
| 93 | * |
| 94 | * param[in,out] data Data to read from. |
| 95 | * param[in] len lenght of keyword. |
| 96 | * param[in] prefix_len lenght of prefix. |
| 97 | * |
| 98 | * @return yang_keyword values. |
| 99 | */ |
| 100 | enum yang_keyword yin_match_keyword(const char *data, size_t len, size_t prefix_len); |
| 101 | |
David Sedlák | b6e6597 | 2019-06-19 10:44:13 +0200 | [diff] [blame] | 102 | /** |
| 103 | * @brief Parse status statement. |
| 104 | * |
| 105 | * @param[in] xml_ctx Xml context. |
| 106 | * @param[in,out] data Data to read from. |
| 107 | * @param[in,out] flags Flags to add to. |
| 108 | * @param[in,out] exts Extension instances to add to. |
| 109 | * |
| 110 | * @return LY_ERR values. |
| 111 | */ |
| 112 | LY_ERR yin_parse_status(struct lyxml_context *xml_ctx, const char **data, uint16_t *flags, struct lysp_ext_instance **exts); |
| 113 | |
David Sedlák | 2b626ee | 2019-06-03 16:40:18 +0200 | [diff] [blame] | 114 | #endif /* LY_PARSER_YIN_H_*/ |