blob: 40da58d6127836620fbaa268537801a05a8259a9 [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 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name of the Company nor the names of its contributors
18 * may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 */
21
22#ifndef LY_PARSER_YANG_H_
23#define LY_PARSER_YANG_H_
24
Pavol Vicanbf805472016-01-26 14:24:56 +010025#include <stdlib.h>
Pavol Vican6eb14e82016-02-03 12:27:13 +010026#include <string.h>
Pavol Vicanbf805472016-01-26 14:24:56 +010027
Pavol Vican021488a2016-01-25 23:56:12 +010028#include "tree_schema.h"
29#include "resolve.h"
Pavol Vicanbf805472016-01-26 14:24:56 +010030#include "common.h"
Pavol Vican6eb14e82016-02-03 12:27:13 +010031#include "context.h"
Pavol Vican021488a2016-01-25 23:56:12 +010032
Pavol Vican1eeb1992016-02-09 11:10:45 +010033#define LY_ARRAY_SIZE 32
34#define LY_READ_ALL 1
35#define LY_READ_ONLY_SIZE 0
Pavol Vicanbe057c02016-02-11 19:08:08 +010036#define LYS_SYSTEMORDERED 0x40
37#define LYS_ORDERED_MASK 0xC0
Pavol Vican339d4ad2016-02-12 12:49:22 +010038#define LYS_MIN_ELEMENTS 0x01
39#define LYS_MAX_ELEMENTS 0x02
Pavol Vican52ed67d2016-03-02 17:46:15 +010040#define LYS_RPC_INPUT 0x01
41#define LYS_RPC_OUTPUT 0x02
Pavol Vican5de33492016-02-22 14:03:24 +010042#define LYS_DATADEF 0x04
Pavol Vican73e7c992016-02-24 12:18:05 +010043#define LYS_TYPE_DEF 0x08
Pavol Vican1ff0e222016-02-26 12:27:01 +010044#define LYS_TYPE_BASE 0x40
Pavol Vican1eeb1992016-02-09 11:10:45 +010045
46struct lys_node_array{
47 uint8_t if_features;
48 uint8_t must;
49 uint8_t unique;
50 uint8_t tpdf;
51 uint8_t keys;
52 uint8_t expr_size;
53 uint16_t refine;
54 uint16_t augment;
55
56};
57
58struct lys_array_size {
59 uint8_t rev;
60 uint8_t imp;
61 uint8_t inc;
62 uint32_t ident;
63 uint8_t features;
64 uint8_t augment;
65 uint8_t deviation;
Pavol Vican0df02b02016-03-01 10:28:50 +010066 uint8_t tpdf;
Pavol Vicane1354e92016-02-09 14:02:09 +010067 uint32_t size;
Pavol Vican1eeb1992016-02-09 11:10:45 +010068 uint32_t next;
69 struct lys_node_array *node;
70};
Pavol Vican021488a2016-01-25 23:56:12 +010071
Pavol Vican1f06ba82016-02-10 17:39:50 +010072struct type_choice {
73 char *s;
74 struct lys_node_choice *ptr_choice;
75};
76
Pavol Vican339d4ad2016-02-12 12:49:22 +010077struct type_leaflist {
78 struct lys_node_leaflist *ptr_leaflist;
Pavol Vicana55992a2016-03-01 13:37:17 +010079 int line;
Pavol Vican339d4ad2016-02-12 12:49:22 +010080 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;
86 int line;
87};
88
Pavol Vican73e7c992016-02-24 12:18:05 +010089struct type_leaf {
90 struct lys_node_leaf *ptr_leaf;
Pavol Vican6295f122016-02-26 12:53:33 +010091 int line;
Pavol Vican73e7c992016-02-24 12:18:05 +010092 uint8_t flag;
93};
94
Pavol Vican0df02b02016-03-01 10:28:50 +010095struct type_tpdf {
96 struct lys_tpdf *ptr_tpdf;
97 int line;
98 uint8_t flag;
99};
100
Pavol Vican92fa0dc2016-03-02 14:20:39 +0100101struct type_augment {
102 struct lys_node_augment *ptr_augment;
103 uint8_t flag;
104};
105
Pavol Vican52ed67d2016-03-02 17:46:15 +0100106struct type_rpc {
107 struct lys_node_rpc *ptr_rpc;
108 uint8_t flag;
109};
110
Pavol Vican531a9132016-03-03 10:10:09 +0100111struct type_inout {
112 struct lys_node_rpc_inout *ptr_inout;
113 uint8_t flag;
114};
115
Pavol Vican220e5a12016-03-03 14:19:43 +0100116struct type_deviation {
117 struct lys_deviation *deviation;
118 struct lys_node *target;
119 struct lys_deviate *deviate;
120};
121
Pavol Vican5de33492016-02-22 14:03:24 +0100122struct type_ident {
123 int line;
124 char s[0];
125};
126
Pavol Vican73e7c992016-02-24 12:18:05 +0100127struct yang_type {
128 char flags; /**< this is used to distinguish lyxml_elem * from a YANG temporary parsing structure */
129 char *name;
Pavol Vican73e7c992016-02-24 12:18:05 +0100130 struct lys_type *type;
131 int line;
132};
133
134struct yang_schema {
135 struct yang_type type;
136 struct yang_schema *next;
137};
138
Pavol Vican021488a2016-01-25 23:56:12 +0100139int yang_read_common(struct lys_module *module,char *value, int type, int line);
140
Pavol Vicanbf805472016-01-26 14:24:56 +0100141int yang_read_prefix(struct lys_module *module, void *save, char *value,int type,int line);
142
Pavol Vican6eb14e82016-02-03 12:27:13 +0100143/**
144 * @brief Get free member of array
145 *
146 * @param[in/out] ptr Pointer to the array.
147 * @param[in/out] act_size Pointer to the current size of array.
148 * @param[in] type Type of array.
149 * @param[in] sizeof_struct
150 * @return first free member of array, NULL on error.
151 */
152void *yang_elem_of_array(void **ptr, uint8_t *act_size, int type, int sizeof_struct);
153
Pavol Vican1eeb1992016-02-09 11:10:45 +0100154/**
155 * @brief Add node to the array
156 *
157 * @param[in/out] node Pointer to the array.
158 * @param[in/out] size Pointer to the current size of array.
159 * @return 1 on success, 0 on error.
160 */
Pavol Vicana1827962016-02-29 15:39:42 +0100161int yang_add_elem(struct lys_node_array **node, uint32_t *size);
Pavol Vican1eeb1992016-02-09 11:10:45 +0100162
Pavol Vican6eb14e82016-02-03 12:27:13 +0100163int yang_fill_import(struct lys_module *module, struct lys_import *imp, char *value, int line);
164
Pavol Vican1ca072c2016-02-03 13:03:56 +0100165int yang_read_description(struct lys_module *module, void *node, char *value, int type, int line);
166
167int yang_read_reference(struct lys_module *module, void *node, char *value, int type, int line);
168
Pavol Vicanbedff692016-02-03 14:29:17 +0100169void *yang_read_revision(struct lys_module *module, char *value);
170
Pavol Vicane1354e92016-02-09 14:02:09 +0100171void *yang_read_feature(struct lys_module *module, char *value, int line);
Pavol Vicanbedff692016-02-03 14:29:17 +0100172
Pavol Vicanf37eeaa2016-02-09 20:54:06 +0100173int yang_read_if_feature(struct lys_module *module, void *ptr, char *value, struct unres_schema *unres, int type, int line);
Pavol Vicane1354e92016-02-09 14:02:09 +0100174
175int yang_read_status(void *node, int value, int type, int line);
Pavol Vican1ca072c2016-02-03 13:03:56 +0100176
Pavol Vicanbbdef532016-02-09 14:52:12 +0100177void *yang_read_identity(struct lys_module *module, char *value);
178
179int yang_read_base(struct lys_module *module, struct lys_ident *ident, char *value, struct unres_schema *unres, int line);
180
Pavol Vicanf37eeaa2016-02-09 20:54:06 +0100181void *yang_read_must(struct lys_module *module, struct lys_node *node, char *value, int type, int line);
182
183int yang_read_message(struct lys_module *module,struct lys_restr *save,char *value, int type, int message, int line);
184
Pavol Vicanb5687112016-02-09 22:35:59 +0100185int yang_read_presence(struct lys_module *module, struct lys_node_container *cont, char *value, int line);
186
187int yang_read_config(void *node, int value, int type, int line);
188
Pavol Vican235dbd42016-02-10 10:34:19 +0100189void *yang_read_when(struct lys_module *module, struct lys_node *node, int type, char *value, int line);
190
Pavol Vican8c82fa82016-02-10 13:13:24 +0100191int yang_read_mandatory(void *node, int value, int type, int line);
192
Pavol Vican7cadfe72016-02-11 12:33:34 +0100193/**
194 * @brief Allocate memory for node and add to the tree
195 *
196 * @param[in/out] node Pointer to the array.
197 * @param[in] parent Pointer to the parent.
198 * @param[in] value Name of node
199 * @param[in] nodetype Type of node
200 * @param[in] sizeof_struct Size of struct
201 * @return Pointer to the node, NULL on error.
202*/
203void * 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 +0100204
Pavol Vican096c6db2016-02-11 15:08:10 +0100205int yang_read_default(struct lys_module *module, void *node, char *value, int type, int line);
206
207int yang_read_units(struct lys_module *module, void *node, char *value, int type, int line);
208
Pavol Vican5de33492016-02-22 14:03:24 +0100209int yang_read_key(struct lys_module *module, struct lys_node_list *list, struct unres_schema *unres, int line);
210
211int yang_read_unique(struct lys_module *module, struct lys_node_list *list, struct unres_schema *unres);
212
Pavol Vicand01d8ae2016-03-01 10:45:59 +0100213void *yang_read_type(void *parent, char *value, int type, int line);
Pavol Vican73e7c992016-02-24 12:18:05 +0100214
215void *yang_read_length(struct lys_module *module, struct yang_type *typ, char *value, int line);
216
217int yang_check_type(struct lys_module *module, struct lys_node *parent, struct yang_type *typ, struct unres_schema *unres);
218
Pavol Vican1c203db2016-02-24 14:05:23 +0100219void *yang_read_pattern(struct lys_module *module, struct yang_type *typ, char *value, int line);
220
Pavol Vicanaff5c802016-02-24 15:56:45 +0100221void *yang_read_range(struct lys_module *module, struct yang_type *typ, char *value, int line);
222
Pavol Vican07ea68d2016-02-25 12:01:37 +0100223int yang_read_fraction(struct yang_type *typ, uint32_t value, int line);
224
Pavol Vican79a763d2016-02-25 15:41:27 +0100225void *yang_read_enum(struct lys_module *module, struct yang_type *typ, char *value, int line);
226
227int yang_check_enum(struct yang_type *typ, struct lys_type_enum *enm, int64_t *value, int assign, int line);
228
Pavol Vican9887c682016-02-29 11:32:01 +0100229void *yang_read_bit(struct lys_module *module, struct yang_type *typ, char *value, int line);
230
231int yang_check_bit(struct yang_type *typ, struct lys_type_bit *bit, int64_t *value, int assign, int line);
232
Pavol Vican0df02b02016-03-01 10:28:50 +0100233void *yang_read_typedef(struct lys_module *module, struct lys_node *parent, char *value, int line);
234
Pavol Vican1003ead2016-03-02 12:24:52 +0100235void *yang_read_refine(struct lys_module *module, struct lys_node_uses *uses, char *value, int line);
236
Pavol Vican92fa0dc2016-03-02 14:20:39 +0100237void *yang_read_augment(struct lys_module *module, struct lys_node *parent, char *value, int line);
238
Pavol Vican220e5a12016-03-03 14:19:43 +0100239void *yang_read_deviation(struct lys_module *module, char *value, int line);
240
Pavol Vican021488a2016-01-25 23:56:12 +0100241#endif /* LY_PARSER_YANG_H_ */