blob: 02c0de0676c8f966f6c097aae0fec066b9c484d8 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
Lev Walkin59b176e2005-11-26 11:25:14 +00002 * Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
Lev Walkinf15320b2004-06-03 03:38:44 +00003 * Redistribution and modifications are permitted subject to BSD license.
4 */
Lev Walkina9cc46e2004-09-22 16:06:28 +00005#include <asn_internal.h>
Lev Walkinb8ec15d2004-10-22 08:20:32 +00006#include <asn_codecs_prim.h>
Lev Walkinf15320b2004-06-03 03:38:44 +00007#include <NULL.h>
8#include <BOOLEAN.h> /* Implemented in terms of BOOLEAN type */
9
10/*
11 * NULL basic type description.
12 */
Lev Walkin5e033762004-09-29 13:26:15 +000013static ber_tlv_tag_t asn_DEF_NULL_tags[] = {
Lev Walkinf15320b2004-06-03 03:38:44 +000014 (ASN_TAG_CLASS_UNIVERSAL | (5 << 2))
15};
Lev Walkin5e033762004-09-29 13:26:15 +000016asn_TYPE_descriptor_t asn_DEF_NULL = {
Lev Walkinf15320b2004-06-03 03:38:44 +000017 "NULL",
Lev Walkindc06f6b2004-10-20 15:50:55 +000018 "NULL",
Lev Walkina9cc46e2004-09-22 16:06:28 +000019 BOOLEAN_free,
20 NULL_print,
Lev Walkinf15320b2004-06-03 03:38:44 +000021 asn_generic_no_constraint,
22 BOOLEAN_decode_ber, /* Implemented in terms of BOOLEAN */
23 NULL_encode_der, /* Special handling of DER encoding */
Lev Walkinb8ec15d2004-10-22 08:20:32 +000024 NULL_decode_xer,
25 NULL_encode_xer,
Lev Walkin59b176e2005-11-26 11:25:14 +000026 NULL_decode_uper, /* Unaligned PER decoder */
Lev Walkin523de9e2006-08-18 01:34:18 +000027 NULL_encode_uper, /* Unaligned PER encoder */
Lev Walkinf15320b2004-06-03 03:38:44 +000028 0, /* Use generic outmost tag fetcher */
Lev Walkin5e033762004-09-29 13:26:15 +000029 asn_DEF_NULL_tags,
30 sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]),
31 asn_DEF_NULL_tags, /* Same as above */
32 sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]),
Lev Walkin59b176e2005-11-26 11:25:14 +000033 0, /* No PER visible constraints */
Lev Walkin449f8322004-08-20 13:23:42 +000034 0, 0, /* No members */
Lev Walkind9bd7752004-06-05 08:17:50 +000035 0 /* No specifics */
Lev Walkinf15320b2004-06-03 03:38:44 +000036};
37
Lev Walkina9cc46e2004-09-22 16:06:28 +000038asn_enc_rval_t
Lev Walkin5e033762004-09-29 13:26:15 +000039NULL_encode_der(asn_TYPE_descriptor_t *td, void *ptr,
Lev Walkinf15320b2004-06-03 03:38:44 +000040 int tag_mode, ber_tlv_tag_t tag,
41 asn_app_consume_bytes_f *cb, void *app_key) {
Lev Walkina9cc46e2004-09-22 16:06:28 +000042 asn_enc_rval_t erval;
Lev Walkinf15320b2004-06-03 03:38:44 +000043
Lev Walkin8e8078a2004-09-26 13:10:40 +000044 erval.encoded = der_write_tags(td, 0, tag_mode, 0, tag, cb, app_key);
Lev Walkinf15320b2004-06-03 03:38:44 +000045 if(erval.encoded == -1) {
Lev Walkina9cc46e2004-09-22 16:06:28 +000046 erval.failed_type = td;
Lev Walkinf15320b2004-06-03 03:38:44 +000047 erval.structure_ptr = ptr;
48 }
49
Lev Walkin59b176e2005-11-26 11:25:14 +000050 _ASN_ENCODED_OK(erval);
Lev Walkinf15320b2004-06-03 03:38:44 +000051}
52
Lev Walkina9cc46e2004-09-22 16:06:28 +000053asn_enc_rval_t
Lev Walkin5e033762004-09-29 13:26:15 +000054NULL_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
Lev Walkina9cc46e2004-09-22 16:06:28 +000055 int ilevel, enum xer_encoder_flags_e flags,
56 asn_app_consume_bytes_f *cb, void *app_key) {
57 asn_enc_rval_t er;
58
59 (void)td;
60 (void)sptr;
61 (void)ilevel;
62 (void)flags;
63 (void)cb;
64 (void)app_key;
65
66 /* XMLNullValue is empty */
67 er.encoded = 0;
Lev Walkin59b176e2005-11-26 11:25:14 +000068 _ASN_ENCODED_OK(er);
Lev Walkina9cc46e2004-09-22 16:06:28 +000069}
70
Lev Walkinb8ec15d2004-10-22 08:20:32 +000071
Lev Walkin0fab1a62005-03-09 22:19:25 +000072static enum xer_pbd_rval
73NULL__xer_body_decode(asn_TYPE_descriptor_t *td, void *sptr, const void *chunk_buf, size_t chunk_size) {
Lev Walkine0b56e02005-02-25 12:10:27 +000074 (void)td;
Lev Walkinb8ec15d2004-10-22 08:20:32 +000075 (void)sptr;
Lev Walkinbfc76e82014-01-14 02:44:54 -080076 (void)chunk_buf; /* Going to be empty according to the rules below. */
Lev Walkin0fab1a62005-03-09 22:19:25 +000077
Lev Walkinf7982282013-03-16 07:01:42 -070078 /*
79 * There must be no content in self-terminating <NULL/> tag.
80 */
81 if(chunk_size)
Lev Walkin0fab1a62005-03-09 22:19:25 +000082 return XPBD_BROKEN_ENCODING;
Lev Walkinf7982282013-03-16 07:01:42 -070083 else
84 return XPBD_BODY_CONSUMED;
Lev Walkinb8ec15d2004-10-22 08:20:32 +000085}
86
87asn_dec_rval_t
88NULL_decode_xer(asn_codec_ctx_t *opt_codec_ctx,
89 asn_TYPE_descriptor_t *td, void **sptr, const char *opt_mname,
Lev Walkin8c3b8542005-03-10 18:52:02 +000090 const void *buf_ptr, size_t size) {
Lev Walkinb8ec15d2004-10-22 08:20:32 +000091
92 return xer_decode_primitive(opt_codec_ctx, td,
93 sptr, sizeof(NULL_t), opt_mname, buf_ptr, size,
94 NULL__xer_body_decode);
95}
96
Lev Walkinf15320b2004-06-03 03:38:44 +000097int
Lev Walkin5e033762004-09-29 13:26:15 +000098NULL_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
Lev Walkinf15320b2004-06-03 03:38:44 +000099 asn_app_consume_bytes_f *cb, void *app_key) {
Lev Walkind9bd7752004-06-05 08:17:50 +0000100
101 (void)td; /* Unused argument */
102 (void)ilevel; /* Unused argument */
103
Lev Walkinf15320b2004-06-03 03:38:44 +0000104 if(sptr) {
Lev Walkin8e8078a2004-09-26 13:10:40 +0000105 return (cb("<present>", 9, app_key) < 0) ? -1 : 0;
Lev Walkinf15320b2004-06-03 03:38:44 +0000106 } else {
Lev Walkin8e8078a2004-09-26 13:10:40 +0000107 return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
Lev Walkinf15320b2004-06-03 03:38:44 +0000108 }
109}
Lev Walkin59b176e2005-11-26 11:25:14 +0000110
111asn_dec_rval_t
112NULL_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
113 asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
114 asn_dec_rval_t rv;
115
116 (void)opt_codec_ctx;
117 (void)td;
118 (void)constraints;
119 (void)pd;
120
121 if(!*sptr) {
122 *sptr = MALLOC(sizeof(NULL_t));
123 if(*sptr) {
124 *(NULL_t *)*sptr = 0;
125 } else {
126 _ASN_DECODE_FAILED;
127 }
128 }
129
130 /*
131 * NULL type does not have content octets.
132 */
133
134 rv.code = RC_OK;
135 rv.consumed = 0;
136 return rv;
137}
Lev Walkin523de9e2006-08-18 01:34:18 +0000138
139asn_enc_rval_t
140NULL_encode_uper(asn_TYPE_descriptor_t *td, asn_per_constraints_t *constraints,
141 void *sptr, asn_per_outp_t *po) {
142 asn_enc_rval_t er;
143
144 (void)td;
145 (void)constraints;
146 (void)sptr;
147 (void)po;
148
149 er.encoded = 0;
150 _ASN_ENCODED_OK(er);
151}