blob: 02c10499e53ceb26661ca052fa4e33fa7a131cd2 [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 Vican8e5f1192016-08-15 10:25:44 +020034#define LYS_CHOICE_DEFAULT 0x10
Pavol Vicanb60a1d12016-12-03 01:56:55 +010035#define LYS_NO_ERASE_IDENTITY 0x20
PavolVican75af21d2016-12-29 20:04:07 +010036#define LY_YANG_ARRAY_SIZE 8
PavolVican22e88682017-02-14 22:38:18 +010037#define YANG_REMOVE_IMPORT 0x01
38#define YANG_EXIST_MODULE 0x02
39#define EXT_INSTANCE_SUBSTMT 0x04
Pavol Vican1eeb1992016-02-09 11:10:45 +010040
Pavol Vicand946c0d2016-03-23 12:53:08 +010041struct type_node {
42 union {
43 struct lys_node_leaflist *ptr_leaflist;
44 struct lys_node_list *ptr_list;
45 struct lys_node_leaf *ptr_leaf;
46 struct lys_tpdf *ptr_tpdf;
Pavol Vicandb7489e2016-08-23 17:23:39 +020047 struct lys_node_anydata *ptr_anydata;
Michal Vasko44fb6382016-06-29 11:12:27 +020048 struct lys_node_rpc_action *ptr_rpc;
Pavol Vican8e5f1192016-08-15 10:25:44 +020049 struct lys_node_choice *ptr_choice;
Pavol Vicand946c0d2016-03-23 12:53:08 +010050 };
Pavol Vicandb7489e2016-08-23 17:23:39 +020051 uint flag;
Pavol Vican531a9132016-03-03 10:10:09 +010052};
53
PavolVican196694c2017-01-27 10:33:09 +010054struct yang_parameter {
55 struct lys_module *module;
56 struct lys_submodule *submodule;
57 struct unres_schema *unres;
58 struct lys_node **node;
59 char **value;
PavolVican196694c2017-01-27 10:33:09 +010060 void **data_node;
61 void **actual_node;
PavolVican22e88682017-02-14 22:38:18 +010062 uint8_t flags;
PavolVican196694c2017-01-27 10:33:09 +010063};
64
PavolVicandb0e8172017-02-20 00:46:09 +010065struct yang_ext_substmt {
66 char *ext_substmt; /* pointer to string, which contains substmts without module statement */
67 char **ext_modules; /* array of char *, which contains module statements */
68};
69
Pavol Vican73e7c992016-02-24 12:18:05 +010070struct yang_type {
71 char flags; /**< this is used to distinguish lyxml_elem * from a YANG temporary parsing structure */
Pavol Vican6b072512016-04-04 10:50:21 +020072 LY_DATA_TYPE base;
Pavol Vican5f0316a2016-04-05 21:21:11 +020073 const char *name;
Pavol Vican73e7c992016-02-24 12:18:05 +010074 struct lys_type *type;
Pavol Vican73e7c992016-02-24 12:18:05 +010075};
76
Pavol Vican5f0316a2016-04-05 21:21:11 +020077#include "parser_yang_bis.h"
Pavol Vican021488a2016-01-25 23:56:12 +010078
PavolVican1bc22062017-01-19 15:09:04 +010079char *yang_read_string(const char *input, char *output, int size, int offset, int indent);
Pavol Vican8760bb72016-04-07 09:44:01 +020080
Pavol Vican5f0316a2016-04-05 21:21:11 +020081int yang_read_common(struct lys_module *module,char *value, enum yytokentype type);
Pavol Vican021488a2016-01-25 23:56:12 +010082
Pavol Vicane024ab72016-07-27 14:27:43 +020083int yang_read_prefix(struct lys_module *module, struct lys_import *imp, char *value);
Pavol Vican6eb14e82016-02-03 12:27:13 +010084
Pavol Vicand0b64c12016-07-15 09:56:19 +020085int yang_check_version(struct lys_module *module, struct lys_submodule *submodule, char *value, int repeat);
86
Pavol Vicanec423c92016-10-24 21:33:43 +020087int yang_check_imports(struct lys_module *module, struct unres_schema *unres);
Pavol Vican6eb14e82016-02-03 12:27:13 +010088
PavolVican196694c2017-01-27 10:33:09 +010089int yang_read_description(struct lys_module *module, void *node, char *value, char *where, enum yytokentype type);
Pavol Vican1ca072c2016-02-03 13:03:56 +010090
PavolVican196694c2017-01-27 10:33:09 +010091int yang_read_reference(struct lys_module *module, void *node, char *value, char *where, enum yytokentype type);
Pavol Vican1ca072c2016-02-03 13:03:56 +010092
Pavol Vican0adf01d2016-03-22 12:29:33 +010093int yang_read_message(struct lys_module *module,struct lys_restr *save,char *value, char *what, int message);
Pavol Vicanf37eeaa2016-02-09 20:54:06 +010094
Pavol Vican0adf01d2016-03-22 12:29:33 +010095int yang_read_presence(struct lys_module *module, struct lys_node_container *cont, char *value);
Pavol Vicanb5687112016-02-09 22:35:59 +010096
Pavol Vican5f0316a2016-04-05 21:21:11 +020097int yang_read_config(void *node, int value, enum yytokentype type);
Pavol Vicanb5687112016-02-09 22:35:59 +010098
Pavol Vican5f0316a2016-04-05 21:21:11 +020099void *yang_read_when(struct lys_module *module, struct lys_node *node, enum yytokentype type, char *value);
Pavol Vican235dbd42016-02-10 10:34:19 +0100100
Pavol Vican7cadfe72016-02-11 12:33:34 +0100101/**
102 * @brief Allocate memory for node and add to the tree
103 *
104 * @param[in/out] node Pointer to the array.
105 * @param[in] parent Pointer to the parent.
Pavol Vican05810b62016-11-23 14:07:22 +0100106 * @param[in] root Pointer to the root of schema tree.
Pavol Vican7cadfe72016-02-11 12:33:34 +0100107 * @param[in] value Name of node
108 * @param[in] nodetype Type of node
109 * @param[in] sizeof_struct Size of struct
110 * @return Pointer to the node, NULL on error.
111*/
Pavol Vican05810b62016-11-23 14:07:22 +0100112void *yang_read_node(struct lys_module *module, struct lys_node *parent, struct lys_node **root,
113 char *value, int nodetype, int sizeof_struct);
Pavol Vican12f53c32016-02-11 11:40:00 +0100114
Pavol Vican5f0316a2016-04-05 21:21:11 +0200115int yang_read_default(struct lys_module *module, void *node, char *value, enum yytokentype type);
Pavol Vican096c6db2016-02-11 15:08:10 +0100116
Pavol Vican5f0316a2016-04-05 21:21:11 +0200117int yang_read_units(struct lys_module *module, void *node, char *value, enum yytokentype type);
Pavol Vican096c6db2016-02-11 15:08:10 +0100118
Pavol Vican0adf01d2016-03-22 12:29:33 +0100119int yang_read_key(struct lys_module *module, struct lys_node_list *list, struct unres_schema *unres);
Pavol Vican5de33492016-02-22 14:03:24 +0100120
121int yang_read_unique(struct lys_module *module, struct lys_node_list *list, struct unres_schema *unres);
122
Pavol Vican5f0316a2016-04-05 21:21:11 +0200123void *yang_read_type(struct lys_module *module, void *parent, char *value, enum yytokentype type);
Pavol Vican73e7c992016-02-24 12:18:05 +0100124
PavolVicaneef1d912017-02-19 00:19:15 +0100125void *yang_read_length(struct lys_module *module, struct yang_type *stype, char *value, int is_ext_instance);
Pavol Vican73e7c992016-02-24 12:18:05 +0100126
Pavol Vican7313fc02016-11-14 01:10:31 +0100127int 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 +0100128
PavolVicana0fdbf32017-02-15 17:59:02 +0100129int yang_fill_type(struct lys_module *module, struct lys_type *type, struct yang_type *stype,
130 void *parent, struct unres_schema *unres);
131
Pavol Vicancf2af4d2016-12-21 14:13:06 +0100132void yang_free_type_union(struct ly_ctx *ctx, struct lys_type *type);
133
PavolVicana0fdbf32017-02-15 17:59:02 +0100134void yang_type_free(struct ly_ctx *ctx, struct lys_type *type);
135
Pavol Vican81344ac2016-09-02 14:23:06 +0200136int yang_read_leafref_path(struct lys_module *module, struct yang_type *stype, char *value);
137
138int yang_read_require_instance(struct yang_type *stype, int req);
139
Pavol Vican6eecf302016-08-10 11:09:05 +0200140int yang_read_pattern(struct lys_module *module, struct lys_restr *pattern, char *value, char modifier);
Pavol Vican1c203db2016-02-24 14:05:23 +0100141
PavolVicaneef1d912017-02-19 00:19:15 +0100142void *yang_read_range(struct lys_module *module, struct yang_type *stype, char *value, int is_ext_instance);
Pavol Vicanaff5c802016-02-24 15:56:45 +0100143
Pavol Vican0adf01d2016-03-22 12:29:33 +0100144int yang_read_fraction(struct yang_type *typ, uint32_t value);
Pavol Vican07ea68d2016-02-25 12:01:37 +0100145
Pavol Vican874715f2016-10-25 14:52:08 +0200146int 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 +0100147
Pavol Vican0adf01d2016-03-22 12:29:33 +0100148int yang_check_enum(struct yang_type *typ, struct lys_type_enum *enm, int64_t *value, int assign);
Pavol Vican79a763d2016-02-25 15:41:27 +0100149
Pavol Vican59e8dee2016-10-25 15:29:38 +0200150int 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 +0100151
Pavol Vican0adf01d2016-03-22 12:29:33 +0100152int yang_check_bit(struct yang_type *typ, struct lys_type_bit *bit, int64_t *value, int assign);
Pavol Vican9887c682016-02-29 11:32:01 +0100153
Pavol Vican0adf01d2016-03-22 12:29:33 +0100154void *yang_read_typedef(struct lys_module *module, struct lys_node *parent, char *value);
Pavol Vican0df02b02016-03-01 10:28:50 +0100155
Pavol Vican3ad50f82016-12-04 15:00:36 +0100156int 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 +0100157
PavolVican75af21d2016-12-29 20:04:07 +0100158void *yang_read_deviate(struct lys_deviation *dev, LYS_DEVIATE_TYPE mod);
Pavol Vican220e5a12016-03-03 14:19:43 +0100159
PavolVican6f000922017-02-10 12:56:59 +0100160void *yang_read_deviate_unsupported(struct lys_deviation *dev);
Pavol Vican85f12022016-03-05 16:30:35 +0100161
Pavol Vican0adf01d2016-03-22 12:29:33 +0100162int 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 +0100163
PavolVicandad50b32017-02-16 22:34:14 +0100164int yang_fill_iffeature(struct lys_module *module, struct lys_iffeature *iffeature, void *parent,
165 char *value, struct unres_schema *unres, int parent_is_feature);
166
PavolVicandb0e8172017-02-20 00:46:09 +0100167void yang_free_ext_data(struct yang_ext_substmt *substmt);
168
PavolVicanc1807262017-01-31 18:00:27 +0100169void *yang_read_ext(struct lys_module *module, void *actual, char *ext_name, char *ext_arg,
PavolVican22e88682017-02-14 22:38:18 +0100170 enum yytokentype actual_type, enum yytokentype backup_type, int is_ext_instance);
PavolVicanc1807262017-01-31 18:00:27 +0100171
172int yang_check_ext_instance(struct lys_module *module, struct lys_ext_instance ***ext, uint size,
173 void *parent, struct unres_schema *unres);
174
PavolVican22e88682017-02-14 22:38:18 +0100175int yang_read_extcomplex_str(struct lys_module *module, struct lys_ext_instance_complex *ext, const char *arg_name,
176 const char *parent_name, char *value, int parent_stmt, LY_STMT stmt);
177
PavolVicanfe83b152017-02-19 03:19:29 +0100178void **yang_getplace_for_extcomplex_struct(struct lys_ext_instance_complex *ext, int *index,
179 char *parent_name, char *node_name, LY_STMT stmt);
PavolVicana0fdbf32017-02-15 17:59:02 +0100180
PavolVicanf3091bf2017-02-19 18:27:01 +0100181int yang_extcomplex_node(struct lys_ext_instance_complex *ext, char *parent_name, char *node_name,
182 struct lys_node *node, LY_STMT stmt);
183
PavolVicanff0f7f42017-02-16 11:35:42 +0100184int yang_fill_extcomplex_flags(struct lys_ext_instance_complex *ext, char *parent_name, char *node_name,
185 LY_STMT stmt, uint16_t value, uint16_t mask);
186
PavolVican6a852a62017-02-16 15:36:01 +0100187int yang_fill_extcomplex_uint8(struct lys_ext_instance_complex *ext, char *parent_name, char *node_name,
188 LY_STMT stmt, uint8_t value);
PavolVican8e8dfd12017-02-16 13:51:41 +0100189
PavolVican22e88682017-02-14 22:38:18 +0100190int yang_parse_ext_substatement(struct lys_module *module, struct unres_schema *unres, const char *data,
191 char *ext_name, struct lys_ext_instance_complex *ext);
192
PavolVicandb0e8172017-02-20 00:46:09 +0100193int yang_fill_extcomplex_module(struct ly_ctx *ctx, struct lys_ext_instance_complex *ext,
194 char *parent_name, char **values, int implemented);
195
PavolVicanc1807262017-01-31 18:00:27 +0100196
Pavol Vican1d684102016-03-23 10:18:54 +0100197/* **
198 * @brief Parse YANG from in-memory string
199 *
200 * yang parser expected at the end of the input string 2 zero byte
201 *
202 * @param[in] module Pointer to the libyang module.
203 * @param[in] submodule Pointer to the libyang submodule.
204 * @param[in] unres Pointer to a unres_schema
205 * @param[in] data Pointer to a NULL-terminated string containing YANG data to parse.
Pavol Vican5f0316a2016-04-05 21:21:11 +0200206 * @param[in] size_data Size of input string
Pavol Vican9d50a772016-10-14 22:23:36 +0200207 * @param[in/out] node Pointer to node
PavolVican9e81c6a2017-02-09 13:09:07 +0100208 * @return 0 on success, -1 on error, 1 on module is already in context.
Pavol Vican1d684102016-03-23 10:18:54 +0100209 */
Pavol Vican9d50a772016-10-14 22:23:36 +0200210int yang_parse_mem(struct lys_module *module, struct lys_submodule *submodule, struct unres_schema *unres,
211 const char *data, unsigned int size_data, struct lys_node **node);
Pavol Vican8e7110b2016-03-22 17:00:26 +0100212
Pavol Vican974377b2016-03-23 00:38:53 +0100213struct 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 +0100214
Pavol Vican974377b2016-03-23 00:38:53 +0100215struct 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 +0100216
Pavol Vican021488a2016-01-25 23:56:12 +0100217#endif /* LY_PARSER_YANG_H_ */