Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 1 | /*- |
| 2 | * Copyright (c) 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. |
| 3 | * Redistribution and modifications are permitted subject to BSD license. |
| 4 | */ |
| 5 | #ifndef _XER_DECODER_H_ |
| 6 | #define _XER_DECODER_H_ |
| 7 | |
| 8 | #include <asn_application.h> |
| 9 | |
Lev Walkin | 21b41ac | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 10 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif |
| 13 | |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 14 | struct asn_TYPE_descriptor_s; /* Forward declaration */ |
| 15 | |
| 16 | /* |
Lev Walkin | 1d9e8dd | 2005-12-07 05:46:03 +0000 | [diff] [blame] | 17 | * The XER decoder of any ASN.1 type. May be invoked by the application. |
Lev Walkin | 2864774 | 2017-09-12 11:07:06 -0700 | [diff] [blame] | 18 | * Decodes CANONICAL-XER and BASIC-XER. |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 19 | */ |
Lev Walkin | afbf2a9 | 2017-09-12 23:30:27 -0700 | [diff] [blame] | 20 | asn_dec_rval_t xer_decode(const struct asn_codec_ctx_s *opt_codec_ctx, |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 21 | struct asn_TYPE_descriptor_s *type_descriptor, |
| 22 | void **struct_ptr, /* Pointer to a target structure's pointer */ |
Lev Walkin | 8c3b854 | 2005-03-10 18:52:02 +0000 | [diff] [blame] | 23 | const void *buffer, /* Data to be decoded */ |
Lev Walkin | 1d9e8dd | 2005-12-07 05:46:03 +0000 | [diff] [blame] | 24 | size_t size /* Size of data buffer */ |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 25 | ); |
| 26 | |
| 27 | /* |
| 28 | * Type of the type-specific XER decoder function. |
| 29 | */ |
Lev Walkin | afbf2a9 | 2017-09-12 23:30:27 -0700 | [diff] [blame] | 30 | typedef asn_dec_rval_t(xer_type_decoder_f)( |
| 31 | const asn_codec_ctx_t *opt_codec_ctx, |
| 32 | struct asn_TYPE_descriptor_s *type_descriptor, void **struct_ptr, |
| 33 | const char *opt_mname, /* Member name */ |
| 34 | const void *buf_ptr, size_t size); |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 35 | |
| 36 | /******************************* |
| 37 | * INTERNALLY USEFUL FUNCTIONS * |
| 38 | *******************************/ |
| 39 | |
| 40 | /* |
| 41 | * Generalized function for decoding the primitive values. |
| 42 | * Used by more specialized functions, such as OCTET_STRING_decode_xer_utf8 |
| 43 | * and others. This function should not be used by applications, as its API |
| 44 | * is subject to changes. |
| 45 | */ |
Lev Walkin | afbf2a9 | 2017-09-12 23:30:27 -0700 | [diff] [blame] | 46 | asn_dec_rval_t xer_decode_general( |
| 47 | const asn_codec_ctx_t *opt_codec_ctx, |
| 48 | asn_struct_ctx_t *ctx, /* Type decoder context */ |
| 49 | void *struct_key, /* Treated as opaque pointer */ |
| 50 | const char *xml_tag, /* Expected XML tag name */ |
| 51 | const void *buf_ptr, size_t size, |
| 52 | int (*opt_unexpected_tag_decoder)(void *struct_key, const void *chunk_buf, |
| 53 | size_t chunk_size), |
| 54 | ssize_t (*body_receiver)(void *struct_key, const void *chunk_buf, |
| 55 | size_t chunk_size, int have_more)); |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 56 | |
| 57 | |
| 58 | /* |
| 59 | * Fetch the next XER (XML) token from the stream. |
| 60 | * The function returns the number of bytes occupied by the chunk type, |
| 61 | * returned in the _ch_type. The _ch_type is only set (and valid) when |
Lev Walkin | 9736348 | 2016-01-24 19:23:02 -0800 | [diff] [blame] | 62 | * the return value is >= 0. |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 63 | */ |
| 64 | typedef enum pxer_chunk_type { |
Lev Walkin | 9736348 | 2016-01-24 19:23:02 -0800 | [diff] [blame] | 65 | PXER_WMORE, /* Chunk type is not clear, more data expected. */ |
| 66 | PXER_TAG, /* Complete XER tag */ |
| 67 | PXER_TEXT, /* Plain text between XER tags */ |
Lev Walkin | 8c3b854 | 2005-03-10 18:52:02 +0000 | [diff] [blame] | 68 | PXER_COMMENT /* A comment, may be part of */ |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 69 | } pxer_chunk_type_e; |
Lev Walkin | 1e44396 | 2005-02-18 18:06:36 +0000 | [diff] [blame] | 70 | ssize_t xer_next_token(int *stateContext, |
Lev Walkin | 0fab1a6 | 2005-03-09 22:19:25 +0000 | [diff] [blame] | 71 | const void *buffer, size_t size, pxer_chunk_type_e *_ch_type); |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 72 | |
| 73 | /* |
| 74 | * This function checks the buffer against the tag name is expected to occur. |
| 75 | */ |
| 76 | typedef enum xer_check_tag { |
Lev Walkin | 904e65b | 2005-02-18 14:23:48 +0000 | [diff] [blame] | 77 | XCT_BROKEN = 0, /* The tag is broken */ |
| 78 | XCT_OPENING = 1, /* This is the <opening> tag */ |
| 79 | XCT_CLOSING = 2, /* This is the </closing> tag */ |
| 80 | XCT_BOTH = 3, /* This is the <modified/> tag */ |
| 81 | XCT__UNK__MASK = 4, /* Mask of everything unexpected */ |
| 82 | XCT_UNKNOWN_OP = 5, /* Unexpected <opening> tag */ |
| 83 | XCT_UNKNOWN_CL = 6, /* Unexpected </closing> tag */ |
Lev Walkin | 8c3b854 | 2005-03-10 18:52:02 +0000 | [diff] [blame] | 84 | XCT_UNKNOWN_BO = 7 /* Unexpected <modified/> tag */ |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 85 | } xer_check_tag_e; |
| 86 | xer_check_tag_e xer_check_tag(const void *buf_ptr, int size, |
| 87 | const char *need_tag); |
| 88 | |
Lev Walkin | dde25b3 | 2004-10-22 08:17:16 +0000 | [diff] [blame] | 89 | /* |
Lev Walkin | f798228 | 2013-03-16 07:01:42 -0700 | [diff] [blame] | 90 | * Get the number of bytes consisting entirely of XER whitespace characters. |
Lev Walkin | dde25b3 | 2004-10-22 08:17:16 +0000 | [diff] [blame] | 91 | * RETURN VALUES: |
Lev Walkin | f798228 | 2013-03-16 07:01:42 -0700 | [diff] [blame] | 92 | * >=0: Number of whitespace characters in the string. |
Lev Walkin | dde25b3 | 2004-10-22 08:17:16 +0000 | [diff] [blame] | 93 | */ |
Lev Walkin | f798228 | 2013-03-16 07:01:42 -0700 | [diff] [blame] | 94 | size_t xer_whitespace_span(const void *chunk_buf, size_t chunk_size); |
Lev Walkin | dde25b3 | 2004-10-22 08:17:16 +0000 | [diff] [blame] | 95 | |
Lev Walkin | 2eeeedc | 2005-02-18 16:10:40 +0000 | [diff] [blame] | 96 | /* |
| 97 | * Skip the series of anticipated extensions. |
| 98 | */ |
| 99 | int xer_skip_unknown(xer_check_tag_e tcv, ber_tlv_len_t *depth); |
| 100 | |
Lev Walkin | 21b41ac | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 101 | #ifdef __cplusplus |
| 102 | } |
| 103 | #endif |
| 104 | |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 105 | #endif /* _XER_DECODER_H_ */ |