blob: 7cfd46b98e9320bd153dc95cda19a6521bf565c4 [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 Vican1eeb1992016-02-09 11:10:45 +010026#define LY_ARRAY_SIZE 32
27#define LY_READ_ALL 1
28#define LY_READ_ONLY_SIZE 0
Pavol Vicanbe057c02016-02-11 19:08:08 +010029#define LYS_SYSTEMORDERED 0x40
30#define LYS_ORDERED_MASK 0xC0
Pavol Vican339d4ad2016-02-12 12:49:22 +010031#define LYS_MIN_ELEMENTS 0x01
32#define LYS_MAX_ELEMENTS 0x02
Pavol Vican52ed67d2016-03-02 17:46:15 +010033#define LYS_RPC_INPUT 0x01
34#define LYS_RPC_OUTPUT 0x02
Pavol Vican5de33492016-02-22 14:03:24 +010035#define LYS_DATADEF 0x04
Pavol Vican73e7c992016-02-24 12:18:05 +010036#define LYS_TYPE_DEF 0x08
Pavol Vican1ff0e222016-02-26 12:27:01 +010037#define LYS_TYPE_BASE 0x40
Pavol Vican1eeb1992016-02-09 11:10:45 +010038
39struct lys_node_array{
40 uint8_t if_features;
41 uint8_t must;
42 uint8_t unique;
43 uint8_t tpdf;
Pavol Vicana55cbb42016-03-21 20:15:26 +010044 union {
45 uint8_t uni;
46 uint8_t flags;
47 };
48 union {
49 uint8_t enm;
50 uint8_t pattern;
51 uint8_t bit;
52 uint8_t deviate;
53 };
Pavol Vican1eeb1992016-02-09 11:10:45 +010054 uint16_t refine;
55 uint16_t augment;
56
57};
58
59struct lys_array_size {
60 uint8_t rev;
61 uint8_t imp;
62 uint8_t inc;
63 uint32_t ident;
64 uint8_t features;
65 uint8_t augment;
66 uint8_t deviation;
Pavol Vican0df02b02016-03-01 10:28:50 +010067 uint8_t tpdf;
Pavol Vicane1354e92016-02-09 14:02:09 +010068 uint32_t size;
Pavol Vican1eeb1992016-02-09 11:10:45 +010069 uint32_t next;
70 struct lys_node_array *node;
71};
Pavol Vican021488a2016-01-25 23:56:12 +010072
Pavol Vican1f06ba82016-02-10 17:39:50 +010073struct type_choice {
74 char *s;
75 struct lys_node_choice *ptr_choice;
76};
77
Pavol Vican339d4ad2016-02-12 12:49:22 +010078struct type_leaflist {
79 struct lys_node_leaflist *ptr_leaflist;
80 uint8_t flag;
81};
82
Pavol Vican5de33492016-02-22 14:03:24 +010083struct type_list {
84 struct lys_node_list *ptr_list;
85 uint8_t flag;
Pavol Vican5de33492016-02-22 14:03:24 +010086};
87
Pavol Vican73e7c992016-02-24 12:18:05 +010088struct type_leaf {
89 struct lys_node_leaf *ptr_leaf;
90 uint8_t flag;
91};
92
Pavol Vican0df02b02016-03-01 10:28:50 +010093struct type_tpdf {
94 struct lys_tpdf *ptr_tpdf;
Pavol Vican0df02b02016-03-01 10:28:50 +010095 uint8_t flag;
96};
97
Pavol Vican92fa0dc2016-03-02 14:20:39 +010098struct type_augment {
99 struct lys_node_augment *ptr_augment;
100 uint8_t flag;
101};
102
Pavol Vican52ed67d2016-03-02 17:46:15 +0100103struct type_rpc {
104 struct lys_node_rpc *ptr_rpc;
105 uint8_t flag;
106};
107
Pavol Vican531a9132016-03-03 10:10:09 +0100108struct type_inout {
109 struct lys_node_rpc_inout *ptr_inout;
110 uint8_t flag;
111};
112
Pavol Vican220e5a12016-03-03 14:19:43 +0100113struct type_deviation {
114 struct lys_deviation *deviation;
115 struct lys_node *target;
116 struct lys_deviate *deviate;
Pavol Vican85f12022016-03-05 16:30:35 +0100117 struct lys_restr **trg_must;
118 uint8_t *trg_must_size;
Pavol Vican220e5a12016-03-03 14:19:43 +0100119};
120
Pavol Vican4fb66c92016-03-17 10:32:27 +0100121struct type_uses {
122 struct lys_node_uses *ptr_uses;
123 int config_inherit;
124};
125
Pavol Vican73e7c992016-02-24 12:18:05 +0100126struct yang_type {
127 char flags; /**< this is used to distinguish lyxml_elem * from a YANG temporary parsing structure */
128 char *name;
Pavol Vican73e7c992016-02-24 12:18:05 +0100129 struct lys_type *type;
Pavol Vican73e7c992016-02-24 12:18:05 +0100130};
131
Pavol Vican0adf01d2016-03-22 12:29:33 +0100132int yang_read_common(struct lys_module *module,char *value, int type);
Pavol Vican021488a2016-01-25 23:56:12 +0100133
Pavol Vican0adf01d2016-03-22 12:29:33 +0100134int yang_read_prefix(struct lys_module *module, void *save, char *value,int type);
Pavol Vicanbf805472016-01-26 14:24:56 +0100135
Pavol Vican6eb14e82016-02-03 12:27:13 +0100136/**
137 * @brief Get free member of array
138 *
139 * @param[in/out] ptr Pointer to the array.
140 * @param[in/out] act_size Pointer to the current size of array.
141 * @param[in] type Type of array.
142 * @param[in] sizeof_struct
143 * @return first free member of array, NULL on error.
144 */
145void *yang_elem_of_array(void **ptr, uint8_t *act_size, int type, int sizeof_struct);
146
Pavol Vican1eeb1992016-02-09 11:10:45 +0100147/**
148 * @brief Add node to the array
149 *
150 * @param[in/out] node Pointer to the array.
151 * @param[in/out] size Pointer to the current size of array.
152 * @return 1 on success, 0 on error.
153 */
Pavol Vicana1827962016-02-29 15:39:42 +0100154int yang_add_elem(struct lys_node_array **node, uint32_t *size);
Pavol Vican1eeb1992016-02-09 11:10:45 +0100155
Pavol Vican0adf01d2016-03-22 12:29:33 +0100156int yang_fill_import(struct lys_module *module, struct lys_import *imp, char *value);
Pavol Vican6eb14e82016-02-03 12:27:13 +0100157
Pavol Vican0adf01d2016-03-22 12:29:33 +0100158int yang_read_description(struct lys_module *module, void *node, char *value, char *where);
Pavol Vican1ca072c2016-02-03 13:03:56 +0100159
Pavol Vican0adf01d2016-03-22 12:29:33 +0100160int yang_read_reference(struct lys_module *module, void *node, char *value, char *where);
Pavol Vican1ca072c2016-02-03 13:03:56 +0100161
Pavol Vicanbedff692016-02-03 14:29:17 +0100162void *yang_read_revision(struct lys_module *module, char *value);
163
Pavol Vican0adf01d2016-03-22 12:29:33 +0100164void *yang_read_feature(struct lys_module *module, char *value);
Pavol Vicanbedff692016-02-03 14:29:17 +0100165
Pavol Vican0adf01d2016-03-22 12:29:33 +0100166int yang_read_if_feature(struct lys_module *module, void *ptr, char *value, struct unres_schema *unres, int type);
Pavol Vicane1354e92016-02-09 14:02:09 +0100167
Pavol Vicanbbdef532016-02-09 14:52:12 +0100168void *yang_read_identity(struct lys_module *module, char *value);
169
Pavol Vican0adf01d2016-03-22 12:29:33 +0100170int yang_read_base(struct lys_module *module, struct lys_ident *ident, char *value, struct unres_schema *unres);
Pavol Vicanbbdef532016-02-09 14:52:12 +0100171
Pavol Vican0adf01d2016-03-22 12:29:33 +0100172void *yang_read_must(struct lys_module *module, struct lys_node *node, char *value, int type);
Pavol Vicanf37eeaa2016-02-09 20:54:06 +0100173
Pavol Vican0adf01d2016-03-22 12:29:33 +0100174int yang_read_message(struct lys_module *module,struct lys_restr *save,char *value, char *what, int message);
Pavol Vicanf37eeaa2016-02-09 20:54:06 +0100175
Pavol Vican0adf01d2016-03-22 12:29:33 +0100176int yang_read_presence(struct lys_module *module, struct lys_node_container *cont, char *value);
Pavol Vicanb5687112016-02-09 22:35:59 +0100177
Pavol Vican0adf01d2016-03-22 12:29:33 +0100178int yang_read_config(void *node, int value, int type);
Pavol Vicanb5687112016-02-09 22:35:59 +0100179
Pavol Vican4fb66c92016-03-17 10:32:27 +0100180void store_flags(struct lys_node *node, uint8_t flags, int config_inherit);
181
Pavol Vican0adf01d2016-03-22 12:29:33 +0100182void *yang_read_when(struct lys_module *module, struct lys_node *node, int type, char *value);
Pavol Vican235dbd42016-02-10 10:34:19 +0100183
Pavol Vican7cadfe72016-02-11 12:33:34 +0100184/**
185 * @brief Allocate memory for node and add to the tree
186 *
187 * @param[in/out] node Pointer to the array.
188 * @param[in] parent Pointer to the parent.
189 * @param[in] value Name of node
190 * @param[in] nodetype Type of node
191 * @param[in] sizeof_struct Size of struct
192 * @return Pointer to the node, NULL on error.
193*/
194void * yang_read_node(struct lys_module *module, struct lys_node *parent, char *value, int nodetype, int sizeof_struct);
Pavol Vican12f53c32016-02-11 11:40:00 +0100195
Pavol Vican0adf01d2016-03-22 12:29:33 +0100196int yang_read_default(struct lys_module *module, void *node, char *value, int type);
Pavol Vican096c6db2016-02-11 15:08:10 +0100197
Pavol Vican0adf01d2016-03-22 12:29:33 +0100198int yang_read_units(struct lys_module *module, void *node, char *value, int type);
Pavol Vican096c6db2016-02-11 15:08:10 +0100199
Pavol Vican0adf01d2016-03-22 12:29:33 +0100200int yang_read_key(struct lys_module *module, struct lys_node_list *list, struct unres_schema *unres);
Pavol Vican5de33492016-02-22 14:03:24 +0100201
202int yang_read_unique(struct lys_module *module, struct lys_node_list *list, struct unres_schema *unres);
203
Pavol Vican0adf01d2016-03-22 12:29:33 +0100204void *yang_read_type(struct lys_module *module, void *parent, char *value, int type);
Pavol Vican73e7c992016-02-24 12:18:05 +0100205
Pavol Vican0adf01d2016-03-22 12:29:33 +0100206void *yang_read_length(struct lys_module *module, struct yang_type *typ, char *value);
Pavol Vican73e7c992016-02-24 12:18:05 +0100207
208int yang_check_type(struct lys_module *module, struct lys_node *parent, struct yang_type *typ, struct unres_schema *unres);
209
Pavol Vican0adf01d2016-03-22 12:29:33 +0100210void *yang_read_pattern(struct lys_module *module, struct yang_type *typ, char *value);
Pavol Vican1c203db2016-02-24 14:05:23 +0100211
Pavol Vican0adf01d2016-03-22 12:29:33 +0100212void *yang_read_range(struct lys_module *module, struct yang_type *typ, char *value);
Pavol Vicanaff5c802016-02-24 15:56:45 +0100213
Pavol Vican0adf01d2016-03-22 12:29:33 +0100214int yang_read_fraction(struct yang_type *typ, uint32_t value);
Pavol Vican07ea68d2016-02-25 12:01:37 +0100215
Pavol Vican0adf01d2016-03-22 12:29:33 +0100216void *yang_read_enum(struct lys_module *module, struct yang_type *typ, char *value);
Pavol Vican79a763d2016-02-25 15:41:27 +0100217
Pavol Vican0adf01d2016-03-22 12:29:33 +0100218int yang_check_enum(struct yang_type *typ, struct lys_type_enum *enm, int64_t *value, int assign);
Pavol Vican79a763d2016-02-25 15:41:27 +0100219
Pavol Vican0adf01d2016-03-22 12:29:33 +0100220void *yang_read_bit(struct lys_module *module, struct yang_type *typ, char *value);
Pavol Vican9887c682016-02-29 11:32:01 +0100221
Pavol Vican0adf01d2016-03-22 12:29:33 +0100222int yang_check_bit(struct yang_type *typ, struct lys_type_bit *bit, int64_t *value, int assign);
Pavol Vican9887c682016-02-29 11:32:01 +0100223
Pavol Vican0adf01d2016-03-22 12:29:33 +0100224void *yang_read_typedef(struct lys_module *module, struct lys_node *parent, char *value);
Pavol Vican0df02b02016-03-01 10:28:50 +0100225
Pavol Vican0adf01d2016-03-22 12:29:33 +0100226void *yang_read_refine(struct lys_module *module, struct lys_node_uses *uses, char *value);
Pavol Vican1003ead2016-03-02 12:24:52 +0100227
Pavol Vican0adf01d2016-03-22 12:29:33 +0100228void *yang_read_augment(struct lys_module *module, struct lys_node *parent, char *value);
Pavol Vican92fa0dc2016-03-02 14:20:39 +0100229
Pavol Vican0adf01d2016-03-22 12:29:33 +0100230void *yang_read_deviation(struct lys_module *module, char *value);
Pavol Vican220e5a12016-03-03 14:19:43 +0100231
Pavol Vican0adf01d2016-03-22 12:29:33 +0100232int yang_read_deviate_unsupported(struct type_deviation *dev);
Pavol Vican4c90c642016-03-03 15:06:47 +0100233
Pavol Vican0adf01d2016-03-22 12:29:33 +0100234int yang_read_deviate(struct type_deviation *dev, LYS_DEVIATE_TYPE mod);
Pavol Vican85f12022016-03-05 16:30:35 +0100235
Pavol Vican0adf01d2016-03-22 12:29:33 +0100236int yang_read_deviate_units(struct ly_ctx *ctx, struct type_deviation *dev, char *value);
Pavol Vican85f12022016-03-05 16:30:35 +0100237
Pavol Vican974377b2016-03-23 00:38:53 +0100238int yang_read_deviate_must(struct type_deviation *dev, uint8_t c_must);
Pavol Vican85f12022016-03-05 16:30:35 +0100239
Pavol Vican0adf01d2016-03-22 12:29:33 +0100240int 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 +0100241
Pavol Vican974377b2016-03-23 00:38:53 +0100242int yang_read_deviate_unique(struct type_deviation *dev, uint8_t c_uniq);
Pavol Vican85f12022016-03-05 16:30:35 +0100243
Pavol Vican0adf01d2016-03-22 12:29:33 +0100244int yang_read_deviate_default(struct ly_ctx *ctx, struct type_deviation *dev, char *value);
Pavol Vican85f12022016-03-05 16:30:35 +0100245
Pavol Vican0adf01d2016-03-22 12:29:33 +0100246int yang_read_deviate_config(struct type_deviation *dev, uint8_t value);
Pavol Vican85f12022016-03-05 16:30:35 +0100247
Pavol Vican0adf01d2016-03-22 12:29:33 +0100248int yang_read_deviate_mandatory(struct type_deviation *dev, uint8_t value);
Pavol Vican85f12022016-03-05 16:30:35 +0100249
250/*
251 * type: 0 - min, 1 - max
252 */
Pavol Vican0adf01d2016-03-22 12:29:33 +0100253int yang_read_deviate_minmax(struct type_deviation *dev, uint32_t value, int type);
Pavol Vican85f12022016-03-05 16:30:35 +0100254
Pavol Vican0adf01d2016-03-22 12:29:33 +0100255int yang_check_deviate_must(struct ly_ctx *ctx, struct type_deviation *dev);
Pavol Vicanc1f5a502016-03-06 16:51:26 +0100256
Pavol Vican0adf01d2016-03-22 12:29:33 +0100257int yang_check_deviate_unique(struct lys_module *module, struct type_deviation *dev, char *value);
Pavol Vicanc1f5a502016-03-06 16:51:26 +0100258
Pavol Vican0adf01d2016-03-22 12:29:33 +0100259int yang_check_deviation(struct lys_module *module, struct type_deviation *dev, struct unres_schema *unres);
Pavol Vicanc1f5a502016-03-06 16:51:26 +0100260
Pavol Vican9b89dda2016-03-09 15:36:55 +0100261int yang_fill_include(struct lys_module *module, struct lys_submodule *submodule, char *value,
Pavol Vican0adf01d2016-03-22 12:29:33 +0100262 char *rev, int inc_size, struct unres_schema *unres);
Pavol Vican9b89dda2016-03-09 15:36:55 +0100263
Pavol Vican0adf01d2016-03-22 12:29:33 +0100264int yang_use_extension(struct lys_module *module, struct lys_node *data_node, void *actual, char *value);
Pavol Vicanf4717e62016-03-16 11:30:01 +0100265
Pavol Vican0adf01d2016-03-22 12:29:33 +0100266int yang_check_flags(uint8_t *flags, uint8_t mask, char *what, char *where, int value);
Pavol Vican4fb66c92016-03-17 10:32:27 +0100267
Pavol Vican974377b2016-03-23 00:38:53 +0100268int yang_parse_mem(struct lys_module *module, struct lys_submodule *submodule, struct unres_schema *unres, const char *data, unsigned int size_data);
Pavol Vican8e7110b2016-03-22 17:00:26 +0100269
Pavol Vican974377b2016-03-23 00:38:53 +0100270struct 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 +0100271
Pavol Vican974377b2016-03-23 00:38:53 +0100272struct 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 +0100273
Pavol Vican021488a2016-01-25 23:56:12 +0100274#endif /* LY_PARSER_YANG_H_ */