blob: d80dbf62151e7351c1e462f5dccb386b61b05ef5 [file] [log] [blame]
David Sedlákb1ce3f82019-06-05 14:37:26 +02001/**
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ák2b626ee2019-06-03 16:40:18 +020014
15#ifndef LY_PARSER_YIN_H_
16#define LY_PARSER_YIN_H_
17
18#include <stdio.h>
David Sedlákb1ce3f82019-06-05 14:37:26 +020019#include <stdlib.h>
20
David Sedlák2b626ee2019-06-03 16:40:18 +020021#include "log.h"
22#include "xml.h"
David Sedlák2b626ee2019-06-03 16:40:18 +020023
David Sedlákf6251182019-06-06 10:22:13 +020024/* list of yin attribute strings */
25extern const char *const yin_attr_list[];
26#define yin_attr2str(STMT) yin_attr_list[STMT]
27
David Sedlák2b214ac2019-06-06 16:11:03 +020028#define YIN_NS_URI "urn:ietf:params:xml:ns:yang:yin:1"
29
David Sedlák2b626ee2019-06-03 16:40:18 +020030enum YIN_ARGUMENT {
31 YIN_ARG_UNKNOWN = 0, /**< parsed argument can not be matched with any known yin argument keyword */
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ák7ff55a92019-06-17 11:11:41 +020042 YIN_ARG_NONE, /**< */
43};
44
45struct yin_arg_record {
46 const char *prefix;
47 size_t prefix_len;
48 const char *name;
49 size_t name_len;
50 char *content;
51 size_t content_len;
David Sedlák57715b12019-06-17 13:05:22 +020052 int dynamic_content;
David Sedlák2b626ee2019-06-03 16:40:18 +020053};
54
55/**
56 * @brief Match argument name.
57 *
58 * @param[in] name String representing name.
59 * @param[in] len Lenght of the name.
60 *
David Sedlákb1ce3f82019-06-05 14:37:26 +020061 * @return YIN_ARGUMENT value.
David Sedlák2b626ee2019-06-03 16:40:18 +020062 */
63enum YIN_ARGUMENT match_argument_name(const char *name, size_t len);
64
65/**
66 * @brief Parse content of whole element as text.
67 *
68 * @param[in] xml_ctx Xml context.
David Sedlákb666bcc2019-06-05 15:00:05 +020069 * @param[in,out] data Data to read from.
David Sedlák2b626ee2019-06-03 16:40:18 +020070 * @param[out] value Where content of element should be stored.
David Sedlákb1ce3f82019-06-05 14:37:26 +020071 *
David Sedlák2b214ac2019-06-06 16:11:03 +020072 * @return LY_ERR values.
David Sedlák2b626ee2019-06-03 16:40:18 +020073 */
74LY_ERR parse_text_element(struct lyxml_context *xml_ctx, const char **data, const char **value);
75
David Sedlákd9d3a312019-06-04 09:47:10 +020076/**
David Sedlák2b214ac2019-06-06 16:11:03 +020077 * @brief Parse import element.
David Sedlákda63c082019-06-04 13:52:23 +020078 *
79 * @param[in] xml_ctx Xml context.
80 * @param[in] module_prefix Prefix of the module to check prefix collisions.
David Sedlákb666bcc2019-06-05 15:00:05 +020081 * @param[in,out] data Dta to read from.
82 * @param[in,out] imports Parsed imports to add to.
David Sedlákda63c082019-06-04 13:52:23 +020083 *
David Sedlák2b214ac2019-06-06 16:11:03 +020084 * @return LY_ERR values.
David Sedlákda63c082019-06-04 13:52:23 +020085 */
86LY_ERR yin_parse_import(struct lyxml_context *xml_ctx, const char *module_prefix, const char **data, struct lysp_import **imports);
David Sedlák2b626ee2019-06-03 16:40:18 +020087
88#endif /* LY_PARSER_YIN_H_*/