blob: 5ceefb4438b69b1e5b49184e038c5cdebee6d926 [file] [log] [blame]
Radek Krejcida04f4a2015-05-21 12:54:09 +02001/**
Radek Krejciefdd0ce2015-05-26 16:48:29 +02002 * @file parser.h
Radek Krejcida04f4a2015-05-21 12:54:09 +02003 * @author Radek Krejci <rkrejci@cesnet.cz>
Radek Krejciefdd0ce2015-05-26 16:48:29 +02004 * @brief Parsers for libyang
Radek Krejcida04f4a2015-05-21 12:54:09 +02005 *
6 * Copyright (c) 2015 CESNET, z.s.p.o.
7 *
Radek Krejci54f6fb32016-02-24 12:56:39 +01008 * 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
Michal Vasko8de098c2016-02-26 10:00:25 +010011 *
Radek Krejci54f6fb32016-02-24 12:56:39 +010012 * https://opensource.org/licenses/BSD-3-Clause
Radek Krejcida04f4a2015-05-21 12:54:09 +020013 */
14
Radek Krejciefdd0ce2015-05-26 16:48:29 +020015#ifndef LY_PARSER_H_
16#define LY_PARSER_H_
Radek Krejcida04f4a2015-05-21 12:54:09 +020017
Michal Vasko0aee5c12016-06-17 14:27:26 +020018#include <pcre.h>
19
Radek Krejci3045cf32015-05-28 10:58:52 +020020#include "libyang.h"
Michal Vasko2d162e12015-09-24 14:33:29 +020021#include "tree_schema.h"
Michal Vaskoc3d9f8c2015-07-31 14:37:24 +020022#include "tree_internal.h"
Radek Krejcida04f4a2015-05-21 12:54:09 +020023
24/**
25 * @defgroup yin YIN format support
26 * @{
27 */
Radek Krejciff4874d2016-03-07 12:30:50 +010028struct lys_module *yin_read_module(struct ly_ctx *ctx, const char *data, const char *revision, int implement);
29struct lys_submodule *yin_read_submodule(struct lys_module *module, const char *data,struct unres_schema *unres);
Radek Krejci3045cf32015-05-28 10:58:52 +020030
31/**@} yin */
Radek Krejcida04f4a2015-05-21 12:54:09 +020032
Radek Krejcib20c62d2015-07-07 17:07:14 +020033/**
34 * @defgroup xmldata XML data format support
35 * @{
36 */
Radek Krejci25b9fd32015-08-10 15:06:07 +020037struct lyd_node *xml_read_data(struct ly_ctx *ctx, const char *data, int options);
Radek Krejcib20c62d2015-07-07 17:07:14 +020038
39/**@} xmldata */
40
Radek Krejci5449d472015-10-26 14:35:56 +010041/**
42 * @defgroup jsondata JSON data format support
43 * @{
44 */
Michal Vasko945b96b2016-10-18 11:49:12 +020045struct lyd_node *lyd_parse_json(struct ly_ctx *ctx, const char *data, int options, const struct lyd_node *rpc_act,
46 const struct lyd_node *data_tree);
Radek Krejci5449d472015-10-26 14:35:56 +010047
48/**@} jsondata */
49
Radek Krejcic6556022016-01-27 15:16:45 +010050enum LY_IDENT {
51 LY_IDENT_SIMPLE, /* only syntax rules */
52 LY_IDENT_FEATURE,
53 LY_IDENT_IDENTITY,
54 LY_IDENT_TYPE,
55 LY_IDENT_NODE,
56 LY_IDENT_NAME, /* uniqueness across the siblings */
57 LY_IDENT_PREFIX
58};
Radek Krejci63a91a92015-07-29 13:31:04 +020059
Michal Vasko5a721fd2016-02-16 12:16:48 +010060struct lys_module *lyp_search_file(struct ly_ctx *ctx, struct lys_module *module, const char *name,
Michal Vasko58e5f3e2016-07-28 11:06:34 +020061 const char *revision, int implement, struct unres_schema *unres);
Michal Vasko8ea2b7f2015-09-29 14:30:53 +020062
Michal Vasko8ea2b7f2015-09-29 14:30:53 +020063struct lys_type *lyp_get_next_union_type(struct lys_type *type, struct lys_type *prev_type, int *found);
64
Radek Krejci1899d6a2016-11-03 13:48:07 +010065struct lys_type *lyp_parse_value(struct lys_type *type, const char **value_, struct lyxml_elem *xml,
Michal Vaskoe3886bb2017-01-02 11:33:28 +010066 struct lyd_node_leaf_list *leaf, int store, int dflt);
Radek Krejci6dc53a22015-08-17 13:27:59 +020067
68int lyp_check_length_range(const char *expr, struct lys_type *type);
69
Michal Vasko0aee5c12016-06-17 14:27:26 +020070int lyp_check_pattern(const char *pattern, pcre **pcre_precomp);
71
Michal Vasko88c29542015-11-27 14:57:53 +010072int fill_yin_type(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_type *type,
Radek Krejci3a5501d2016-07-18 22:03:34 +020073 int tpdftype, struct unres_schema *unres);
Michal Vasko88c29542015-11-27 14:57:53 +010074
Radek Krejci4372b4e2016-04-14 17:42:16 +020075int lyp_check_status(uint16_t flags1, struct lys_module *mod1, const char *name1,
76 uint16_t flags2, struct lys_module *mod2, const char *name2,
Radek Krejci48464ed2016-03-17 15:44:09 +010077 const struct lys_node *node);
Radek Krejcicf509982015-12-15 09:22:44 +010078
Michal Vasko7b460e52017-02-10 14:50:26 +010079void lyp_del_includedup(struct lys_module *mod);
80
Pavol Vican810892e2016-07-12 16:55:34 +020081int dup_typedef_check(const char *type, struct lys_tpdf *tpdf, int size);
Pavol Vicand6cda452016-07-13 15:08:29 +020082
83int dup_identities_check(const char *id, struct lys_module *module);
84
Radek Krejci5449d472015-10-26 14:35:56 +010085/**
Michal Vaskob1b19442016-07-13 12:26:01 +020086 * @brief Get know if the node is part of the RPC/action's input/output
Radek Krejci4a49bdf2016-01-12 17:17:01 +010087 *
88 * @param node Schema node to be examined.
89 * @return 1 for true, 0 for false
90 */
Michal Vaskob1b19442016-07-13 12:26:01 +020091int lyp_is_rpc_action(struct lys_node *node);
Radek Krejci4a49bdf2016-01-12 17:17:01 +010092
93/**
94 * @brief Check validity of parser options.
95 *
96 * @param options Parser options to be checked.
Michal Vaskoa55d96b2016-12-07 12:20:42 +010097 * @return 0 for ok, 1 when multiple data types bits are set, or incompatible options are used together.
Radek Krejci4a49bdf2016-01-12 17:17:01 +010098 */
99int lyp_check_options(int options);
100
Radek Krejci48464ed2016-03-17 15:44:09 +0100101int lyp_check_identifier(const char *id, enum LY_IDENT type, struct lys_module *module, struct lys_node *parent);
102int lyp_check_date(const char *date);
Radek Krejcidf24cbe2016-11-08 11:55:51 +0100103int lyp_check_mandatory_augment(struct lys_node_augment *node, const struct lys_node *target);
Radek Krejcie00d2312016-08-12 15:27:49 +0200104int lyp_check_mandatory_choice(struct lys_node *node);
Radek Krejcic6556022016-01-27 15:16:45 +0100105
Radek Krejcid4c1d0f2017-01-19 16:11:38 +0100106int lyp_check_include(struct lys_module *module, const char *value,
Pavol Vican0adf01d2016-03-22 12:29:33 +0100107 struct lys_include *inc, struct unres_schema *unres);
Radek Krejcid4c1d0f2017-01-19 16:11:38 +0100108int lyp_check_include_missing(struct lys_module *main_module);
Pavol Vican58d2d4c2016-03-08 15:26:10 +0100109
Pavol Vican0adf01d2016-03-22 12:29:33 +0100110int lyp_check_import(struct lys_module *module, const char *value, struct lys_import *imp);
Pavol Vican0da132e2016-03-21 12:03:03 +0100111
Radek Krejci4a49bdf2016-01-12 17:17:01 +0100112/**
Pavol Vicanaa1eba92016-03-09 12:27:11 +0100113 * @brief Propagate imports and includes into the main module
114 *
115 * @param module Main module
Radek Krejcib8f98c12016-06-24 10:30:46 +0200116 * @param inc Filled include structure
Pavol Vicanaa1eba92016-03-09 12:27:11 +0100117 * @return 0 for success, 1 for failure
118 */
Radek Krejcib8f98c12016-06-24 10:30:46 +0200119int lyp_propagate_submodule(struct lys_module *module, struct lys_include *inc);
Pavol Vicanaa1eba92016-03-09 12:27:11 +0100120
PavolVican9e81c6a2017-02-09 13:09:07 +0100121/* return: -1 = error, 0 = succes, 1 = already there */
122int lyp_ctx_check_module(struct lys_module *module);
123
124int lyp_ctx_add_module(struct lys_module *module);
Pavol Vicanc99b59e2016-03-22 15:46:39 +0100125
Pavol Vicanaa1eba92016-03-09 12:27:11 +0100126/**
Radek Krejci0fb11502017-01-31 16:45:42 +0100127 * @brief mmap() wrapper for parsers. To unmap, use lyp_munmap().
128 *
129 * @param[in] prot The desired memory protection as in case of mmap().
130 * @param[in] fd File descriptor for getting data.
131 * @param[in] addsize Number of additional bytes to be allocated (and zeroed) after the implicitly added
132 * string-terminating NULL byte.
133 * @param[out] length length of the allocated memory.
134 * @return On success, the pointer to the memory where the file data resists is returned. On error, the value MAP_FAILED
135 * is returned and #ly_errno value is set.
136 */
137void *
138lyp_mmap(int fd, size_t addsize, size_t *length);
139
140/**
141 * @brief Unmap function for the data mapped by lyp_mmap()
142 */
143int lyp_munmap(void *addr, size_t length);
144
145/**
Radek Krejci5449d472015-10-26 14:35:56 +0100146 * Store UTF-8 character specified as 4byte integer into the dst buffer.
147 * Returns number of written bytes (4 max), expects that dst has enough space.
148 *
149 * UTF-8 mapping:
150 * 00000000 -- 0000007F: 0xxxxxxx
151 * 00000080 -- 000007FF: 110xxxxx 10xxxxxx
152 * 00000800 -- 0000FFFF: 1110xxxx 10xxxxxx 10xxxxxx
153 * 00010000 -- 001FFFFF: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
154 *
155 */
Radek Krejci48464ed2016-03-17 15:44:09 +0100156unsigned int pututf8(char *dst, int32_t value);
Radek Krejcideee60e2016-09-23 15:21:14 +0200157unsigned int copyutf8(char *dst, const char *src);
Radek Krejci5449d472015-10-26 14:35:56 +0100158
Radek Krejciefdd0ce2015-05-26 16:48:29 +0200159#endif /* LY_PARSER_H_ */