Change version after creation of r2 branch
[ric-plt/resource-status-manager.git] / RSM / 3rdparty / asn1codec / e2ap_engine / NULL.c
1
2 /*-
3  * Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
6 #include <asn_internal.h>
7 #include <asn_codecs_prim.h>
8 #include <NULL.h>
9 #include <BOOLEAN.h>    /* Implemented in terms of BOOLEAN type */
10
11 /*
12  * NULL basic type description.
13  */
14 static const ber_tlv_tag_t asn_DEF_NULL_tags[] = {
15         (ASN_TAG_CLASS_UNIVERSAL | (5 << 2))
16 };
17 asn_TYPE_operation_t asn_OP_NULL = {
18         BOOLEAN_free,
19         NULL_print,
20         NULL_compare,
21         BOOLEAN_decode_ber,     /* Implemented in terms of BOOLEAN */
22         NULL_encode_der,        /* Special handling of DER encoding */
23         NULL_decode_xer,
24         NULL_encode_xer,
25 #ifdef  ASN_DISABLE_OER_SUPPORT
26         0,
27         0,
28 #else
29         NULL_decode_oer,
30         NULL_encode_oer,
31 #endif  /* ASN_DISABLE_OER_SUPPORT */
32 #ifdef  ASN_DISABLE_PER_SUPPORT
33         0,
34         0,
35         0,
36         0,
37 #else
38         NULL_decode_uper,       /* Unaligned PER decoder */
39         NULL_encode_uper,       /* Unaligned PER encoder */
40         NULL_decode_aper,       /* Aligned PER decoder */
41         NULL_encode_aper,       /* Aligned PER encoder */
42 #endif  /* ASN_DISABLE_PER_SUPPORT */
43         NULL_random_fill,
44         0       /* Use generic outmost tag fetcher */
45 };
46 asn_TYPE_descriptor_t asn_DEF_NULL = {
47         "NULL",
48         "NULL",
49         &asn_OP_NULL,
50         asn_DEF_NULL_tags,
51         sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]),
52         asn_DEF_NULL_tags,      /* Same as above */
53         sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]),
54         { 0, 0, asn_generic_no_constraint },
55         0, 0,   /* No members */
56         0       /* No specifics */
57 };
58
59 asn_enc_rval_t
60 NULL_encode_der(const asn_TYPE_descriptor_t *td, const void *ptr, int tag_mode,
61                 ber_tlv_tag_t tag, asn_app_consume_bytes_f *cb, void *app_key) {
62         asn_enc_rval_t erval = {0,0,0};
63
64         erval.encoded = der_write_tags(td, 0, tag_mode, 0, tag, cb, app_key);
65         if(erval.encoded == -1) {
66                 erval.failed_type = td;
67                 erval.structure_ptr = ptr;
68         }
69
70         ASN__ENCODED_OK(erval);
71 }
72
73 asn_enc_rval_t
74 NULL_encode_xer(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
75                 enum xer_encoder_flags_e flags, asn_app_consume_bytes_f *cb,
76                 void *app_key) {
77         asn_enc_rval_t er = {0,0,0};
78
79         (void)td;
80         (void)sptr;
81         (void)ilevel;
82         (void)flags;
83         (void)cb;
84         (void)app_key;
85
86         /* XMLNullValue is empty */
87         er.encoded = 0;
88         ASN__ENCODED_OK(er);
89 }
90
91
92 static enum xer_pbd_rval
93 NULL__xer_body_decode(const asn_TYPE_descriptor_t *td, void *sptr,
94                       const void *chunk_buf, size_t chunk_size) {
95     (void)td;
96         (void)sptr;
97         (void)chunk_buf;    /* Going to be empty according to the rules below. */
98
99         /*
100          * There must be no content in self-terminating <NULL/> tag.
101          */
102         if(chunk_size)
103                 return XPBD_BROKEN_ENCODING;
104         else
105                 return XPBD_BODY_CONSUMED;
106 }
107
108 asn_dec_rval_t
109 NULL_decode_xer(const asn_codec_ctx_t *opt_codec_ctx,
110                 const asn_TYPE_descriptor_t *td, void **sptr,
111                 const char *opt_mname, const void *buf_ptr, size_t size) {
112     return xer_decode_primitive(opt_codec_ctx, td,
113                 sptr, sizeof(NULL_t), opt_mname, buf_ptr, size,
114                 NULL__xer_body_decode);
115 }
116
117 int
118 NULL_compare(const asn_TYPE_descriptor_t *td, const void *a, const void *b) {
119     (void)td;
120     (void)a;
121     (void)b;
122     return 0;
123 }
124
125 int
126 NULL_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
127            asn_app_consume_bytes_f *cb, void *app_key) {
128     (void)td;   /* Unused argument */
129         (void)ilevel;   /* Unused argument */
130
131         if(sptr) {
132                 return (cb("<present>", 9, app_key) < 0) ? -1 : 0;
133         } else {
134                 return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
135         }
136 }
137
138 #ifndef ASN_DISABLE_OER_SUPPORT
139
140 asn_dec_rval_t
141 NULL_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
142                 const asn_TYPE_descriptor_t *td,
143                 const asn_oer_constraints_t *constraints, void **sptr,
144                 const void *ptr, size_t size) {
145     asn_dec_rval_t rv = {RC_OK, 0};
146     (void)opt_codec_ctx;
147     (void)td;
148     (void)constraints;
149     (void)ptr;
150     (void)size;
151
152     if(!*sptr) {
153         *sptr = MALLOC(sizeof(NULL_t));
154         if(*sptr) {
155             *(NULL_t *)*sptr = 0;
156         } else {
157             ASN__DECODE_FAILED;
158         }
159     }
160
161     return rv;
162 }
163
164 asn_enc_rval_t
165 NULL_encode_oer(const asn_TYPE_descriptor_t *td,
166                 const asn_oer_constraints_t *constraints, const void *sptr,
167                 asn_app_consume_bytes_f *cb, void *app_key) {
168     asn_enc_rval_t er = {0,0,0};
169
170     (void)td;
171     (void)sptr;
172     (void)constraints;
173     (void)cb;
174     (void)app_key;
175
176     er.encoded = 0; /* Encoding in 0 bytes. */
177
178     ASN__ENCODED_OK(er);
179 }
180
181 #endif /* ASN_DISABLE_OER_SUPPORT */
182
183 #ifndef ASN_DISABLE_PER_SUPPORT
184
185 asn_dec_rval_t
186 NULL_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
187                  const asn_TYPE_descriptor_t *td,
188                  const asn_per_constraints_t *constraints, void **sptr,
189                  asn_per_data_t *pd) {
190     asn_dec_rval_t rv;
191
192         (void)opt_codec_ctx;
193         (void)td;
194         (void)constraints;
195         (void)pd;
196
197         if(!*sptr) {
198                 *sptr = MALLOC(sizeof(NULL_t));
199                 if(*sptr) {
200                         *(NULL_t *)*sptr = 0;
201                 } else {
202                         ASN__DECODE_FAILED;
203                 }
204         }
205
206         /*
207          * NULL type does not have content octets.
208          */
209
210         rv.code = RC_OK;
211         rv.consumed = 0;
212         return rv;
213 }
214
215 asn_enc_rval_t
216 NULL_encode_uper(const asn_TYPE_descriptor_t *td,
217                  const asn_per_constraints_t *constraints, const void *sptr,
218                  asn_per_outp_t *po) {
219         asn_enc_rval_t er = {0,0,0};
220
221         (void)td;
222         (void)constraints;
223         (void)sptr;
224         (void)po;
225
226         er.encoded = 0;
227         ASN__ENCODED_OK(er);
228 }
229
230 asn_dec_rval_t
231 NULL_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
232                  const asn_TYPE_descriptor_t *td,
233                  const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
234         asn_dec_rval_t rv = {RC_OK, 0};
235
236         (void)opt_codec_ctx;
237         (void)td;
238         (void)constraints;
239         (void)pd;
240
241         if(!*sptr) {
242                 *sptr = MALLOC(sizeof(NULL_t));
243                 if(*sptr) {
244                         *(NULL_t *)*sptr = 0;
245                 } else {
246                         ASN__DECODE_FAILED;
247                 }
248         }
249
250         /*
251          * NULL type does not have content octets.
252          */
253
254         rv.code = RC_OK;
255         rv.consumed = 0;
256         return rv;
257 }
258
259
260 asn_enc_rval_t
261 NULL_encode_aper(const asn_TYPE_descriptor_t *td,
262                  const asn_per_constraints_t *constraints,
263                  const void *sptr, asn_per_outp_t *po) {
264         asn_enc_rval_t er = {0,0,0};
265
266         (void)td;
267         (void)constraints;
268         (void)sptr;
269         (void)po;
270
271         er.encoded = 0;
272         ASN__ENCODED_OK(er);
273 }
274
275 #endif  /* ASN_DISABLE_PER_SUPPORT */
276
277 asn_random_fill_result_t
278 NULL_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
279                     const asn_encoding_constraints_t *constr,
280                     size_t max_length) {
281     asn_random_fill_result_t result_ok = {ARFILL_OK, 1};
282     asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0};
283     asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0};
284     NULL_t *st = *sptr;
285
286     (void)td;
287     (void)constr;
288
289     if(max_length == 0) return result_skipped;
290
291     if(st == NULL) {
292         st = (NULL_t *)(*sptr = CALLOC(1, sizeof(*st)));
293         if(st == NULL) {
294             return result_failed;
295         }
296     }
297
298     return result_ok;
299 }
300