Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 2 | * Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 3 | * Redistribution and modifications are permitted subject to BSD license. |
| 4 | */ |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 5 | #include <asn_internal.h> |
Lev Walkin | b8ec15d | 2004-10-22 08:20:32 +0000 | [diff] [blame] | 6 | #include <asn_codecs_prim.h> |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 7 | #include <NULL.h> |
| 8 | #include <BOOLEAN.h> /* Implemented in terms of BOOLEAN type */ |
| 9 | |
| 10 | /* |
| 11 | * NULL basic type description. |
| 12 | */ |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 13 | static ber_tlv_tag_t asn_DEF_NULL_tags[] = { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 14 | (ASN_TAG_CLASS_UNIVERSAL | (5 << 2)) |
| 15 | }; |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 16 | asn_TYPE_descriptor_t asn_DEF_NULL = { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 17 | "NULL", |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 18 | "NULL", |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 19 | BOOLEAN_free, |
| 20 | NULL_print, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 21 | asn_generic_no_constraint, |
| 22 | BOOLEAN_decode_ber, /* Implemented in terms of BOOLEAN */ |
| 23 | NULL_encode_der, /* Special handling of DER encoding */ |
Lev Walkin | b8ec15d | 2004-10-22 08:20:32 +0000 | [diff] [blame] | 24 | NULL_decode_xer, |
| 25 | NULL_encode_xer, |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 26 | NULL_decode_uper, /* Unaligned PER decoder */ |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 27 | NULL_encode_uper, /* Unaligned PER encoder */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 28 | 0, /* Use generic outmost tag fetcher */ |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 29 | 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 Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 33 | 0, /* No PER visible constraints */ |
Lev Walkin | 449f832 | 2004-08-20 13:23:42 +0000 | [diff] [blame] | 34 | 0, 0, /* No members */ |
Lev Walkin | d9bd775 | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 35 | 0 /* No specifics */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 38 | asn_enc_rval_t |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 39 | NULL_encode_der(asn_TYPE_descriptor_t *td, void *ptr, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 40 | int tag_mode, ber_tlv_tag_t tag, |
| 41 | asn_app_consume_bytes_f *cb, void *app_key) { |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 42 | asn_enc_rval_t erval; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 43 | |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 44 | erval.encoded = der_write_tags(td, 0, tag_mode, 0, tag, cb, app_key); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 45 | if(erval.encoded == -1) { |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 46 | erval.failed_type = td; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 47 | erval.structure_ptr = ptr; |
| 48 | } |
| 49 | |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 50 | _ASN_ENCODED_OK(erval); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 53 | asn_enc_rval_t |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 54 | NULL_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 55 | 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 Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 68 | _ASN_ENCODED_OK(er); |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Lev Walkin | b8ec15d | 2004-10-22 08:20:32 +0000 | [diff] [blame] | 71 | |
Lev Walkin | 0fab1a6 | 2005-03-09 22:19:25 +0000 | [diff] [blame] | 72 | static enum xer_pbd_rval |
| 73 | NULL__xer_body_decode(asn_TYPE_descriptor_t *td, void *sptr, const void *chunk_buf, size_t chunk_size) { |
Lev Walkin | e0b56e0 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 74 | (void)td; |
Lev Walkin | b8ec15d | 2004-10-22 08:20:32 +0000 | [diff] [blame] | 75 | (void)sptr; |
Lev Walkin | 0fab1a6 | 2005-03-09 22:19:25 +0000 | [diff] [blame] | 76 | |
Lev Walkin | b8ec15d | 2004-10-22 08:20:32 +0000 | [diff] [blame] | 77 | if(xer_is_whitespace(chunk_buf, chunk_size)) |
Lev Walkin | 0fab1a6 | 2005-03-09 22:19:25 +0000 | [diff] [blame] | 78 | return XPBD_BODY_CONSUMED; |
| 79 | else |
| 80 | return XPBD_BROKEN_ENCODING; |
Lev Walkin | b8ec15d | 2004-10-22 08:20:32 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | asn_dec_rval_t |
| 84 | NULL_decode_xer(asn_codec_ctx_t *opt_codec_ctx, |
| 85 | asn_TYPE_descriptor_t *td, void **sptr, const char *opt_mname, |
Lev Walkin | 8c3b854 | 2005-03-10 18:52:02 +0000 | [diff] [blame] | 86 | const void *buf_ptr, size_t size) { |
Lev Walkin | b8ec15d | 2004-10-22 08:20:32 +0000 | [diff] [blame] | 87 | |
| 88 | return xer_decode_primitive(opt_codec_ctx, td, |
| 89 | sptr, sizeof(NULL_t), opt_mname, buf_ptr, size, |
| 90 | NULL__xer_body_decode); |
| 91 | } |
| 92 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 93 | int |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 94 | NULL_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 95 | asn_app_consume_bytes_f *cb, void *app_key) { |
Lev Walkin | d9bd775 | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 96 | |
| 97 | (void)td; /* Unused argument */ |
| 98 | (void)ilevel; /* Unused argument */ |
| 99 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 100 | if(sptr) { |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 101 | return (cb("<present>", 9, app_key) < 0) ? -1 : 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 102 | } else { |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 103 | return (cb("<absent>", 8, app_key) < 0) ? -1 : 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 104 | } |
| 105 | } |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 106 | |
| 107 | asn_dec_rval_t |
| 108 | NULL_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, |
| 109 | asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) { |
| 110 | asn_dec_rval_t rv; |
| 111 | |
| 112 | (void)opt_codec_ctx; |
| 113 | (void)td; |
| 114 | (void)constraints; |
| 115 | (void)pd; |
| 116 | |
| 117 | if(!*sptr) { |
| 118 | *sptr = MALLOC(sizeof(NULL_t)); |
| 119 | if(*sptr) { |
| 120 | *(NULL_t *)*sptr = 0; |
| 121 | } else { |
| 122 | _ASN_DECODE_FAILED; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * NULL type does not have content octets. |
| 128 | */ |
| 129 | |
| 130 | rv.code = RC_OK; |
| 131 | rv.consumed = 0; |
| 132 | return rv; |
| 133 | } |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 134 | |
| 135 | asn_enc_rval_t |
| 136 | NULL_encode_uper(asn_TYPE_descriptor_t *td, asn_per_constraints_t *constraints, |
| 137 | void *sptr, asn_per_outp_t *po) { |
| 138 | asn_enc_rval_t er; |
| 139 | |
| 140 | (void)td; |
| 141 | (void)constraints; |
| 142 | (void)sptr; |
| 143 | (void)po; |
| 144 | |
| 145 | er.encoded = 0; |
| 146 | _ASN_ENCODED_OK(er); |
| 147 | } |