blob: 0c3b489c51981be939deda72148cb24d8d477720 [file] [log] [blame]
/**
* @file tree_schema_internal.h
* @author Radek Krejci <rkrejci@cesnet.cz>
* @brief internal functions for YANG schema trees.
*
* Copyright (c) 2015 - 2018 CESNET, z.s.p.o.
*
* This source code is licensed under BSD 3-Clause License (the "License").
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*/
#ifndef LY_TREE_SCHEMA_INTERNAL_H_
#define LY_TREE_SCHEMA_INTERNAL_H_
/**
* @brief List of YANG statement groups - the (sub)module's substatements
*/
enum yang_module_stmt {
Y_MOD_MODULE_HEADER,
Y_MOD_LINKAGE,
Y_MOD_META,
Y_MOD_REVISION,
Y_MOD_BODY
};
/**
* @brief Types of arguments of YANG statements
*/
enum yang_arg {
Y_IDENTIF_ARG, /**< YANG "identifier-arg-str" rule */
Y_PREF_IDENTIF_ARG, /**< YANG "identifier-ref-arg-str" rule */
Y_STR_ARG, /**< YANG "string" rule */
Y_MAYBE_STR_ARG /**< optional YANG "string" rule */
};
/**
* @brief internal context for schema parsers
*/
struct ly_parser_ctx {
struct ly_ctx *ctx;
uint64_t line; /* line number */
uint64_t indent; /* current position on the line for YANG indentation */
};
/**
* @brief Check the currently present prefixes in the module for collision with the new one.
*
* @param[in] ctx yang parser context.
* @param[in] module Schema tree to check.
* @param[in] value Newly added prefix value (including its location to distinguish collision with itself).
* @return LY_EEXIST when prefix is already used in the module, LY_SUCCESS otherwise
*/
LY_ERR lysp_check_prefix(struct ly_parser_ctx *ctx, struct lysp_module *module, const char **value);
/**
* @brief Check date string (4DIGIT "-" 2DIGIT "-" 2DIGIT)
*
* @param[in] ctx Context to store log message.
* @param[in] date Date string to check (non-necessarily terminated by \0)
* @param[in] date_len Length of the date string, 10 expected.
* @param[in] stmt Statement name for error message.
* @return LY_ERR value.
*/
LY_ERR lysp_check_date(struct ly_ctx *ctx, const char *date, int date_len, const char *stmt);
/**
* @brief Just move the newest revision into the first position, does not sort the rest
* @param[in] revs Sized-array of the revisions in a printable schema tree.
*/
void lysp_sort_revisions(struct lysp_revision *revs);
/**
* @brief Free the schema structure. It just frees, it does not remove the schema from its context.
* @param[in,out] module Schema module structure to free.
* @param[in] private_destructor Function to remove private data from the compiled schema tree.
*/
void lys_module_free(struct lys_module *module, void (*private_destructor)(const struct lysc_node *node, void *priv));
/**
* @brief
*/
LY_ERR yang_parse(struct ly_ctx *ctx, const char *data, struct lysp_module **mod_p);
#endif /* LY_TREE_SCHEMA_INTERNAL_H_ */