1 /**
2  * @file yang_types.c
3  * @author Radek Krejci <rkrejci@cesnet.cz>
4  * @brief Static YANG built-in-types
5  *
6  * Copyright (c) 2015 CESNET, z.s.p.o.
7  *
8  * 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
13  */
14 
15 #include <stdlib.h>
16 
17 #include "tree_internal.h"
18 
19 struct lys_tpdf ly_type_binary = {
20     .name = "binary",
21     .module = NULL,
22     .dsc = "Any binary data",
23     .ref = "RFC 6020, section 4.2.4",
24     .flags = 0,
25     .type = {.base = LY_TYPE_BINARY}
26 };
27 
28 struct lys_tpdf ly_type_bits = {
29     .name = "bits",
30     .module = NULL,
31     .dsc = "A set of bits or flags",
32     .ref = "RFC 6020, section 4.2.4",
33     .flags = 0,
34     .type = {.base = LY_TYPE_BITS}
35 };
36 
37 struct lys_tpdf ly_type_bool = {
38     .name = "boolean",
39     .module = NULL,
40     .dsc = "true or false",
41     .ref = "RFC 6020, section 4.2.4",
42     .flags = 0,
43     .type = {.base = LY_TYPE_BOOL}
44 };
45 
46 struct lys_tpdf ly_type_dec64 = {
47     .name = "decimal64",
48     .module = NULL,
49     .dsc = "64-bit signed decimal number",
50     .ref = "RFC 6020, section 4.2.4",
51     .flags = 0,
52     .type = {.base = LY_TYPE_DEC64}
53 };
54 
55 struct lys_tpdf ly_type_empty = {
56     .name = "empty",
57     .module = NULL,
58     .dsc = "A leaf that does not have any value",
59     .ref = "RFC 6020, section 4.2.4",
60     .flags = 0,
61     .type = {.base = LY_TYPE_EMPTY}
62 };
63 
64 struct lys_tpdf ly_type_enum = {
65     .name = "enumeration",
66     .module = NULL,
67     .dsc = "Enumerated strings",
68     .ref = "RFC 6020, section 4.2.4",
69     .flags = 0,
70     .type = {.base = LY_TYPE_ENUM}
71 };
72 
73 struct lys_tpdf ly_type_ident = {
74     .name = "identityref",
75     .module = NULL,
76     .dsc = "A reference to an abstract identity",
77     .ref = "RFC 6020, section 4.2.4",
78     .flags = 0,
79     .type = {.base = LY_TYPE_IDENT}
80 };
81 
82 struct lys_tpdf ly_type_inst = {
83     .name = "instance-identifier",
84     .module = NULL,
85     .dsc = "References a data tree node",
86     .ref = "RFC 6020, section 4.2.4",
87     .flags = 0,
88     .type = {.base = LY_TYPE_INST}
89 };
90 
91 struct lys_tpdf ly_type_int8 = {
92     .name = "int8",
93     .module = NULL,
94     .dsc = "8-bit signed integer",
95     .ref = "RFC 6020, section 4.2.4",
96     .flags = 0,
97     .type = {.base = LY_TYPE_INT8}
98 };
99 
100 struct lys_tpdf ly_type_int16 = {
101     .name = "int16",
102     .module = NULL,
103     .dsc = "16-bit signed integer",
104     .ref = "RFC 6020, section 4.2.4",
105     .flags = 0,
106     .type = {.base = LY_TYPE_INT16}
107 };
108 
109 struct lys_tpdf ly_type_int32 = {
110     .name = "int32",
111     .module = NULL,
112     .dsc = "32-bit signed integer",
113     .ref = "RFC 6020, section 4.2.4",
114     .flags = 0,
115     .type = {.base = LY_TYPE_INT32}
116 };
117 
118 struct lys_tpdf ly_type_int64 = {
119     .name = "int64",
120     .module = NULL,
121     .dsc = "64-bit signed integer",
122     .ref = "RFC 6020, section 4.2.4",
123     .flags = 0,
124     .type = {.base = LY_TYPE_INT64}
125 };
126 
127 struct lys_tpdf ly_type_leafref = {
128     .name = "leafref",
129     .module = NULL,
130     .dsc = "A reference to a leaf instance",
131     .ref = "RFC 6020, section 4.2.4",
132     .flags = 0,
133     .type = {.base = LY_TYPE_LEAFREF}
134 };
135 
136 struct lys_tpdf ly_type_string = {
137     .name = "string",
138     .module = NULL,
139     .dsc = "Human-readable string",
140     .ref = "RFC 6020, section 4.2.4",
141     .flags = 0,
142     .type = {.base = LY_TYPE_STRING}
143 };
144 
145 struct lys_tpdf ly_type_uint8 = {
146     .name = "uint8",
147     .module = NULL,
148     .dsc = "8-bit unsigned integer",
149     .ref = "RFC 6020, section 4.2.4",
150     .flags = 0,
151     .type = {.base = LY_TYPE_UINT8}
152 };
153 
154 struct lys_tpdf ly_type_uint16 = {
155     .name = "uint16",
156     .module = NULL,
157     .dsc = "16-bit unsigned integer",
158     .ref = "RFC 6020, section 4.2.4",
159     .flags = 0,
160     .type = {.base = LY_TYPE_UINT16}
161 };
162 
163 struct lys_tpdf ly_type_uint32 = {
164     .name = "uint32",
165     .module = NULL,
166     .dsc = "32-bit unsigned integer",
167     .ref = "RFC 6020, section 4.2.4",
168     .flags = 0,
169     .type = {.base = LY_TYPE_UINT32}
170 };
171 
172 struct lys_tpdf ly_type_uint64 = {
173     .name = "uint64",
174     .module = NULL,
175     .dsc = "64-bit unsigned integer",
176     .ref = "RFC 6020, section 4.2.4",
177     .flags = 0,
178     .type = {.base = LY_TYPE_UINT64}
179 };
180 
181 struct lys_tpdf ly_type_union = {
182     .name = "union",
183     .module = NULL,
184     .dsc = "Choice of member types",
185     .ref = "RFC 6020, section 4.2.4",
186     .flags = 0,
187     .type = {.base = LY_TYPE_UNION}
188 };
189 
190 struct lys_tpdf *ly_types[LY_DATA_TYPE_COUNT] = {
191     [LY_TYPE_DER] = NULL,
192     [LY_TYPE_BINARY] = &ly_type_binary,
193     [LY_TYPE_BITS] = &ly_type_bits,
194     [LY_TYPE_BOOL] = &ly_type_bool,
195     [LY_TYPE_DEC64] = &ly_type_dec64,
196     [LY_TYPE_EMPTY] = &ly_type_empty,
197     [LY_TYPE_ENUM] = &ly_type_enum,
198     [LY_TYPE_IDENT] = &ly_type_ident,
199     [LY_TYPE_INST] = &ly_type_inst,
200     [LY_TYPE_INT8] = &ly_type_int8,
201     [LY_TYPE_INT16] = &ly_type_int16,
202     [LY_TYPE_INT32] = &ly_type_int32,
203     [LY_TYPE_INT64] = &ly_type_int64,
204     [LY_TYPE_LEAFREF] = &ly_type_leafref,
205     [LY_TYPE_STRING] = &ly_type_string,
206     [LY_TYPE_UINT8] = &ly_type_uint8,
207     [LY_TYPE_UINT16] = &ly_type_uint16,
208     [LY_TYPE_UINT32] = &ly_type_uint32,
209     [LY_TYPE_UINT64] = &ly_type_uint64,
210     [LY_TYPE_UNION] = &ly_type_union
211 };
212 
213