blob: 33a2cee895fa2b9b07ef8c58104019fea1efbcb1 [file] [log] [blame]
Pavol Vican021488a2016-01-25 23:56:12 +01001/**
2 * @file parser_yang.h
3 * @author Pavol Vican
4 * @brief Parsers for libyang
5 *
6 * Copyright (c) 2015 CESNET, z.s.p.o.
7 *
Pavol Vican9a3a7212016-03-23 10:04:00 +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
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
Pavol Vican021488a2016-01-25 23:56:12 +010013 */
14
15#ifndef LY_PARSER_YANG_H_
16#define LY_PARSER_YANG_H_
17
Pavol Vicanbf805472016-01-26 14:24:56 +010018#include <stdlib.h>
Pavol Vican6eb14e82016-02-03 12:27:13 +010019#include <string.h>
Pavol Vicanbf805472016-01-26 14:24:56 +010020
Pavol Vican021488a2016-01-25 23:56:12 +010021#include "tree_schema.h"
22#include "resolve.h"
Pavol Vicanbf805472016-01-26 14:24:56 +010023#include "common.h"
Pavol Vican6eb14e82016-02-03 12:27:13 +010024#include "context.h"
Pavol Vican021488a2016-01-25 23:56:12 +010025
Pavol Vicanbe057c02016-02-11 19:08:08 +010026#define LYS_SYSTEMORDERED 0x40
27#define LYS_ORDERED_MASK 0xC0
Pavol Vican339d4ad2016-02-12 12:49:22 +010028#define LYS_MIN_ELEMENTS 0x01
29#define LYS_MAX_ELEMENTS 0x02
Pavol Vican52ed67d2016-03-02 17:46:15 +010030#define LYS_RPC_INPUT 0x01
31#define LYS_RPC_OUTPUT 0x02
Pavol Vican5de33492016-02-22 14:03:24 +010032#define LYS_DATADEF 0x04
Pavol Vican73e7c992016-02-24 12:18:05 +010033#define LYS_TYPE_DEF 0x08
Pavol Vican1dac40c2016-09-28 11:39:26 +020034#define CONFIG_INHERIT_DISABLE 0x00
35#define CONFIG_INHERIT_ENABLE 0x01
36#define CONFIG_IGNORE 0x02
Pavol Vicanab75ce02016-09-29 01:31:09 +020037#define CONFIG_MASK 0x03
Pavol Vican8e5f1192016-08-15 10:25:44 +020038#define LYS_CHOICE_DEFAULT 0x10
Pavol Vicanb60a1d12016-12-03 01:56:55 +010039#define LYS_NO_ERASE_IDENTITY 0x20
PavolVican75af21d2016-12-29 20:04:07 +010040#define LY_YANG_ARRAY_SIZE 8
Pavol Vican1eeb1992016-02-09 11:10:45 +010041
Pavol Vicand946c0d2016-03-23 12:53:08 +010042struct type_node {
43 union {
44 struct lys_node_leaflist *ptr_leaflist;
45 struct lys_node_list *ptr_list;
46 struct lys_node_leaf *ptr_leaf;
47 struct lys_tpdf *ptr_tpdf;
Pavol Vicandb7489e2016-08-23 17:23:39 +020048 struct lys_node_anydata *ptr_anydata;
Michal Vasko44fb6382016-06-29 11:12:27 +020049 struct lys_node_rpc_action *ptr_rpc;
Pavol Vican8e5f1192016-08-15 10:25:44 +020050 struct lys_node_choice *ptr_choice;
Pavol Vicand946c0d2016-03-23 12:53:08 +010051 };
Pavol Vicandb7489e2016-08-23 17:23:39 +020052 uint flag;
Pavol Vican531a9132016-03-03 10:10:09 +010053};
54
PavolVican196694c2017-01-27 10:33:09 +010055struct yang_parameter {
56 struct lys_module *module;
57 struct lys_submodule *submodule;
58 struct unres_schema *unres;
59 struct lys_node **node;
60 char **value;
PavolVican196694c2017-01-27 10:33:09 +010061 void **data_node;
62 void **actual_node;
PavolVican9e81c6a2017-02-09 13:09:07 +010063 uint8_t remove_import;
64 uint8_t exist_module;
PavolVican196694c2017-01-27 10:33:09 +010065};
66
Pavol Vican73e7c992016-02-24 12:18:05 +010067struct yang_type {
68 char flags; /**< this is used to distinguish lyxml_elem * from a YANG temporary parsing structure */
Pavol Vican6b072512016-04-04 10:50:21 +020069 LY_DATA_TYPE base;
Pavol Vican5f0316a2016-04-05 21:21:11 +020070 const char *name;
Pavol Vican73e7c992016-02-24 12:18:05 +010071 struct lys_type *type;
Pavol Vican73e7c992016-02-24 12:18:05 +010072};
73
Pavol Vican5f0316a2016-04-05 21:21:11 +020074#include "parser_yang_bis.h"
Pavol Vican021488a2016-01-25 23:56:12 +010075
PavolVican1bc22062017-01-19 15:09:04 +010076char *yang_read_string(const char *input, char *output, int size, int offset, int indent);
Pavol Vican8760bb72016-04-07 09:44:01 +020077
Pavol Vican5f0316a2016-04-05 21:21:11 +020078int yang_read_common(struct lys_module *module,char *value, enum yytokentype type);
Pavol Vican021488a2016-01-25 23:56:12 +010079
Pavol Vicane024ab72016-07-27 14:27:43 +020080int yang_read_prefix(struct lys_module *module, struct lys_import *imp, char *value);
Pavol Vican6eb14e82016-02-03 12:27:13 +010081
Pavol Vicand0b64c12016-07-15 09:56:19 +020082int yang_check_version(struct lys_module *module, struct lys_submodule *submodule, char *value, int repeat);
83
Pavol Vicanec423c92016-10-24 21:33:43 +020084int yang_check_imports(struct lys_module *module, struct unres_schema *unres);
Pavol Vican6eb14e82016-02-03 12:27:13 +010085
PavolVican196694c2017-01-27 10:33:09 +010086int yang_read_description(struct lys_module *module, void *node, char *value, char *where, enum yytokentype type);
Pavol Vican1ca072c2016-02-03 13:03:56 +010087
PavolVican196694c2017-01-27 10:33:09 +010088int yang_read_reference(struct lys_module *module, void *node, char *value, char *where, enum yytokentype type);
Pavol Vican1ca072c2016-02-03 13:03:56 +010089
PavolVican171717d2017-02-01 14:49:55 +010090void *yang_read_revision(struct lys_module *module, char *value, struct lys_revision *retval);
Pavol Vicanbedff692016-02-03 14:29:17 +010091
Pavol Vican0adf01d2016-03-22 12:29:33 +010092int yang_read_message(struct lys_module *module,struct lys_restr *save,char *value, char *what, int message);
Pavol Vicanf37eeaa2016-02-09 20:54:06 +010093
Pavol Vican0adf01d2016-03-22 12:29:33 +010094int yang_read_presence(struct lys_module *module, struct lys_node_container *cont, char *value);
Pavol Vicanb5687112016-02-09 22:35:59 +010095
Pavol Vican5f0316a2016-04-05 21:21:11 +020096int yang_read_config(void *node, int value, enum yytokentype type);
Pavol Vicanb5687112016-02-09 22:35:59 +010097
Pavol Vican1dac40c2016-09-28 11:39:26 +020098int store_flags(struct lys_node *node, uint8_t flags, int config_opt);
Pavol Vican4fb66c92016-03-17 10:32:27 +010099
Pavol Vican5f0316a2016-04-05 21:21:11 +0200100void *yang_read_when(struct lys_module *module, struct lys_node *node, enum yytokentype type, char *value);
Pavol Vican235dbd42016-02-10 10:34:19 +0100101
Pavol Vican7cadfe72016-02-11 12:33:34 +0100102/**
103 * @brief Allocate memory for node and add to the tree
104 *
105 * @param[in/out] node Pointer to the array.
106 * @param[in] parent Pointer to the parent.
Pavol Vican05810b62016-11-23 14:07:22 +0100107 * @param[in] root Pointer to the root of schema tree.
Pavol Vican7cadfe72016-02-11 12:33:34 +0100108 * @param[in] value Name of node
109 * @param[in] nodetype Type of node
110 * @param[in] sizeof_struct Size of struct
111 * @return Pointer to the node, NULL on error.
112*/
Pavol Vican05810b62016-11-23 14:07:22 +0100113void *yang_read_node(struct lys_module *module, struct lys_node *parent, struct lys_node **root,
114 char *value, int nodetype, int sizeof_struct);
Pavol Vican12f53c32016-02-11 11:40:00 +0100115
Pavol Vican5f0316a2016-04-05 21:21:11 +0200116int yang_read_default(struct lys_module *module, void *node, char *value, enum yytokentype type);
Pavol Vican096c6db2016-02-11 15:08:10 +0100117
Pavol Vican5f0316a2016-04-05 21:21:11 +0200118int yang_read_units(struct lys_module *module, void *node, char *value, enum yytokentype type);
Pavol Vican096c6db2016-02-11 15:08:10 +0100119
Pavol Vican0adf01d2016-03-22 12:29:33 +0100120int yang_read_key(struct lys_module *module, struct lys_node_list *list, struct unres_schema *unres);
Pavol Vican5de33492016-02-22 14:03:24 +0100121
122int yang_read_unique(struct lys_module *module, struct lys_node_list *list, struct unres_schema *unres);
123
Pavol Vican5f0316a2016-04-05 21:21:11 +0200124void *yang_read_type(struct lys_module *module, void *parent, char *value, enum yytokentype type);
Pavol Vican73e7c992016-02-24 12:18:05 +0100125
Pavol Vican0adf01d2016-03-22 12:29:33 +0100126void *yang_read_length(struct lys_module *module, struct yang_type *typ, char *value);
Pavol Vican73e7c992016-02-24 12:18:05 +0100127
Pavol Vican7313fc02016-11-14 01:10:31 +0100128int yang_check_type(struct lys_module *module, struct lys_node *parent, struct yang_type *typ, struct lys_type *type, int tpdftype, struct unres_schema *unres);
Pavol Vican73e7c992016-02-24 12:18:05 +0100129
Pavol Vicancf2af4d2016-12-21 14:13:06 +0100130void yang_free_type_union(struct ly_ctx *ctx, struct lys_type *type);
131
Pavol Vican81344ac2016-09-02 14:23:06 +0200132int yang_read_leafref_path(struct lys_module *module, struct yang_type *stype, char *value);
133
134int yang_read_require_instance(struct yang_type *stype, int req);
135
Pavol Vican6eecf302016-08-10 11:09:05 +0200136int yang_read_pattern(struct lys_module *module, struct lys_restr *pattern, char *value, char modifier);
Pavol Vican1c203db2016-02-24 14:05:23 +0100137
Pavol Vican0adf01d2016-03-22 12:29:33 +0100138void *yang_read_range(struct lys_module *module, struct yang_type *typ, char *value);
Pavol Vicanaff5c802016-02-24 15:56:45 +0100139
Pavol Vican0adf01d2016-03-22 12:29:33 +0100140int yang_read_fraction(struct yang_type *typ, uint32_t value);
Pavol Vican07ea68d2016-02-25 12:01:37 +0100141
Pavol Vican874715f2016-10-25 14:52:08 +0200142int yang_read_enum(struct lys_module *module, struct yang_type *typ, struct lys_type_enum *enm, char *value);
Pavol Vican79a763d2016-02-25 15:41:27 +0100143
Pavol Vican0adf01d2016-03-22 12:29:33 +0100144int yang_check_enum(struct yang_type *typ, struct lys_type_enum *enm, int64_t *value, int assign);
Pavol Vican79a763d2016-02-25 15:41:27 +0100145
Pavol Vican59e8dee2016-10-25 15:29:38 +0200146int yang_read_bit(struct lys_module *module, struct yang_type *typ, struct lys_type_bit *bit, char *value);
Pavol Vican9887c682016-02-29 11:32:01 +0100147
Pavol Vican0adf01d2016-03-22 12:29:33 +0100148int yang_check_bit(struct yang_type *typ, struct lys_type_bit *bit, int64_t *value, int assign);
Pavol Vican9887c682016-02-29 11:32:01 +0100149
Pavol Vican0adf01d2016-03-22 12:29:33 +0100150void *yang_read_typedef(struct lys_module *module, struct lys_node *parent, char *value);
Pavol Vican0df02b02016-03-01 10:28:50 +0100151
Pavol Vican3ad50f82016-12-04 15:00:36 +0100152int yang_read_augment(struct lys_module *module, struct lys_node *parent, struct lys_node_augment *aug, char *value);
Pavol Vican92fa0dc2016-03-02 14:20:39 +0100153
PavolVican75af21d2016-12-29 20:04:07 +0100154void *yang_read_deviate(struct lys_deviation *dev, LYS_DEVIATE_TYPE mod);
Pavol Vican220e5a12016-03-03 14:19:43 +0100155
PavolVican6f000922017-02-10 12:56:59 +0100156void *yang_read_deviate_unsupported(struct lys_deviation *dev);
Pavol Vican85f12022016-03-05 16:30:35 +0100157
Pavol Vican0adf01d2016-03-22 12:29:33 +0100158int yang_fill_unique(struct lys_module *module, struct lys_node_list *list, struct lys_unique *unique, char *value, struct unres_schema *unres);
Pavol Vican85f12022016-03-05 16:30:35 +0100159
Pavol Vican0adf01d2016-03-22 12:29:33 +0100160int yang_use_extension(struct lys_module *module, struct lys_node *data_node, void *actual, char *value);
Pavol Vicanf4717e62016-03-16 11:30:01 +0100161
Radek Krejci4372b4e2016-04-14 17:42:16 +0200162int yang_check_flags(uint16_t *flags, uint16_t mask, char *what, char *where, uint16_t value, int shortint);
Pavol Vican4fb66c92016-03-17 10:32:27 +0100163
PavolVicanc1807262017-01-31 18:00:27 +0100164void *yang_read_ext(struct lys_module *module, void *actual, char *ext_name, char *ext_arg,
165 enum yytokentype actual_type, enum yytokentype backup_type);
166
167int yang_check_ext_instance(struct lys_module *module, struct lys_ext_instance ***ext, uint size,
168 void *parent, struct unres_schema *unres);
169
170
Pavol Vican1d684102016-03-23 10:18:54 +0100171/* **
172 * @brief Parse YANG from in-memory string
173 *
174 * yang parser expected at the end of the input string 2 zero byte
175 *
176 * @param[in] module Pointer to the libyang module.
177 * @param[in] submodule Pointer to the libyang submodule.
178 * @param[in] unres Pointer to a unres_schema
179 * @param[in] data Pointer to a NULL-terminated string containing YANG data to parse.
Pavol Vican5f0316a2016-04-05 21:21:11 +0200180 * @param[in] size_data Size of input string
Pavol Vican9d50a772016-10-14 22:23:36 +0200181 * @param[in/out] node Pointer to node
PavolVican9e81c6a2017-02-09 13:09:07 +0100182 * @return 0 on success, -1 on error, 1 on module is already in context.
Pavol Vican1d684102016-03-23 10:18:54 +0100183 */
Pavol Vican9d50a772016-10-14 22:23:36 +0200184int yang_parse_mem(struct lys_module *module, struct lys_submodule *submodule, struct unres_schema *unres,
185 const char *data, unsigned int size_data, struct lys_node **node);
Pavol Vican8e7110b2016-03-22 17:00:26 +0100186
Pavol Vican974377b2016-03-23 00:38:53 +0100187struct lys_module *yang_read_module(struct ly_ctx *ctx, const char* data, unsigned int size, const char *revision, int implement);
Pavol Vican8e7110b2016-03-22 17:00:26 +0100188
Pavol Vican974377b2016-03-23 00:38:53 +0100189struct lys_submodule *yang_read_submodule(struct lys_module *module, const char *data, unsigned int size, struct unres_schema *unres);
Pavol Vican8e7110b2016-03-22 17:00:26 +0100190
Pavol Vican021488a2016-01-25 23:56:12 +0100191#endif /* LY_PARSER_YANG_H_ */