blob: da8789c7be27e29258ab97101f660ab7a08a219f [file] [log] [blame]
Radek Krejci70853c52018-10-15 14:46:16 +02001/**
2 * @file tree_schema_internal.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief internal functions for YANG schema trees.
5 *
6 * Copyright (c) 2015 - 2018 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 */
14
15#ifndef LY_TREE_SCHEMA_INTERNAL_H_
16#define LY_TREE_SCHEMA_INTERNAL_H_
17
18/**
Radek Krejcie3846472018-10-15 15:24:51 +020019 * @brief List of YANG statement groups - the (sub)module's substatements
20 */
21enum yang_module_stmt {
22 Y_MOD_MODULE_HEADER,
23 Y_MOD_LINKAGE,
24 Y_MOD_META,
25 Y_MOD_REVISION,
26 Y_MOD_BODY
27};
28
29/**
30 * @brief Types of arguments of YANG statements
31 */
32enum yang_arg {
33 Y_IDENTIF_ARG, /**< YANG "identifier-arg-str" rule */
34 Y_PREF_IDENTIF_ARG, /**< YANG "identifier-ref-arg-str" rule */
35 Y_STR_ARG, /**< YANG "string" rule */
36 Y_MAYBE_STR_ARG /**< optional YANG "string" rule */
37};
38
39/**
Radek Krejci70853c52018-10-15 14:46:16 +020040 * @brief internal context for schema parsers
41 */
42struct ly_parser_ctx {
43 struct ly_ctx *ctx;
44 uint64_t line; /* line number */
45 uint64_t indent; /* current position on the line for YANG indentation */
46};
47
48/**
49 * @brief Check the currently present prefixes in the module for collision with the new one.
50 *
51 * @param[in] ctx yang parser context.
52 * @param[in] module Schema tree to check.
53 * @param[in] value Newly added prefix value (including its location to distinguish collision with itself).
54 * @return LY_EEXIST when prefix is already used in the module, LY_SUCCESS otherwise
55 */
56LY_ERR lysp_check_prefix(struct ly_parser_ctx *ctx, struct lysp_module *module, const char **value);
57
Radek Krejci86d106e2018-10-18 09:53:19 +020058/**
59 * @brief Check date string (4DIGIT "-" 2DIGIT "-" 2DIGIT)
60 *
61 * @param[in] ctx Context to store log message.
62 * @param[in] date Date string to check (non-necessarily terminated by \0)
63 * @param[in] date_len Length of the date string, 10 expected.
64 * @param[in] stmt Statement name for error message.
65 * @return LY_ERR value.
66 */
67LY_ERR lysp_check_date(struct ly_ctx *ctx, const char *date, int date_len, const char *stmt);
68
69/**
70 * @brief Just move the newest revision into the first position, does not sort the rest
71 * @param[in] revs Sized-array of the revisions in a printable schema tree.
72 */
73void lysp_sort_revisions(struct lysp_revision *revs);
74
75/**
Radek Krejci151a5b72018-10-19 14:21:44 +020076 * @brief Find the module referenced by prefix in the provided mod.
77 *
78 * @param[in] mod Schema module where the prefix was used.
79 * @param[in] prefix Prefix used to reference a module.
80 * @param[in] len Length of the prefix since it is not necessary NULL-terminated.
81 * @return Pointer to the module or NULL if the module is not found.
82 */
83struct lysc_module *lysc_module_find_prefix(struct lysc_module *mod, const char *prefix, size_t len);
84
85/**
Radek Krejci86d106e2018-10-18 09:53:19 +020086 * @brief Free the schema structure. It just frees, it does not remove the schema from its context.
87 * @param[in,out] module Schema module structure to free.
88 * @param[in] private_destructor Function to remove private data from the compiled schema tree.
89 */
90void lys_module_free(struct lys_module *module, void (*private_destructor)(const struct lysc_node *node, void *priv));
91
92/**
93 * @brief
94 */
95LY_ERR yang_parse(struct ly_ctx *ctx, const char *data, struct lysp_module **mod_p);
96
Radek Krejci70853c52018-10-15 14:46:16 +020097#endif /* LY_TREE_SCHEMA_INTERNAL_H_ */