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 | |
| 10 | struct asn_TYPE_descriptor_s; /* Forward declaration */ |
| 11 | |
| 12 | /* |
| 13 | * The XER decoder of any type. May be invoked by the application. |
| 14 | */ |
| 15 | asn_dec_rval_t xer_decode(struct asn_codec_ctx_s *opt_codec_ctx, |
| 16 | struct asn_TYPE_descriptor_s *type_descriptor, |
| 17 | void **struct_ptr, /* Pointer to a target structure's pointer */ |
| 18 | void *buffer, /* Data to be decoded */ |
| 19 | size_t size /* Size of that buffer */ |
| 20 | ); |
| 21 | |
| 22 | /* |
| 23 | * Type of the type-specific XER decoder function. |
| 24 | */ |
| 25 | typedef asn_dec_rval_t (xer_type_decoder_f)(asn_codec_ctx_t *opt_codec_ctx, |
| 26 | struct asn_TYPE_descriptor_s *type_descriptor, |
| 27 | void **struct_ptr, |
| 28 | const char *opt_mname, /* Member name */ |
| 29 | void *buf_ptr, size_t size |
| 30 | ); |
| 31 | |
| 32 | /******************************* |
| 33 | * INTERNALLY USEFUL FUNCTIONS * |
| 34 | *******************************/ |
| 35 | |
| 36 | /* |
| 37 | * Generalized function for decoding the primitive values. |
| 38 | * Used by more specialized functions, such as OCTET_STRING_decode_xer_utf8 |
| 39 | * and others. This function should not be used by applications, as its API |
| 40 | * is subject to changes. |
| 41 | */ |
| 42 | asn_dec_rval_t xer_decode_general(asn_codec_ctx_t *opt_codec_ctx, |
| 43 | asn_struct_ctx_t *ctx, /* Type decoder context */ |
Lev Walkin | 3256d6f | 2004-10-21 11:22:12 +0000 | [diff] [blame] | 44 | void *struct_key, /* Treated as opaque pointer */ |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 45 | const char *xml_tag, /* Expected XML tag name */ |
Lev Walkin | 0fab1a6 | 2005-03-09 22:19:25 +0000 | [diff] [blame] | 46 | const void *buf_ptr, size_t size, |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 47 | int (*opt_unexpected_tag_decoder) |
Lev Walkin | 0fab1a6 | 2005-03-09 22:19:25 +0000 | [diff] [blame] | 48 | (void *struct_key, const void *chunk_buf, size_t chunk_size), |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 49 | ssize_t (*body_receiver) |
Lev Walkin | 0fab1a6 | 2005-03-09 22:19:25 +0000 | [diff] [blame] | 50 | (void *struct_key, const void *chunk_buf, size_t chunk_size, |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 51 | int have_more) |
| 52 | ); |
| 53 | |
| 54 | |
| 55 | /* |
| 56 | * Fetch the next XER (XML) token from the stream. |
| 57 | * The function returns the number of bytes occupied by the chunk type, |
| 58 | * returned in the _ch_type. The _ch_type is only set (and valid) when |
| 59 | * the return value is greater than 0. |
| 60 | */ |
| 61 | typedef enum pxer_chunk_type { |
| 62 | PXER_TAG, /* Complete XER tag */ |
| 63 | PXER_TEXT, /* Plain text between XER tags */ |
| 64 | PXER_COMMENT, /* A comment, may be part of */ |
| 65 | } pxer_chunk_type_e; |
Lev Walkin | 1e44396 | 2005-02-18 18:06:36 +0000 | [diff] [blame] | 66 | ssize_t xer_next_token(int *stateContext, |
Lev Walkin | 0fab1a6 | 2005-03-09 22:19:25 +0000 | [diff] [blame] | 67 | const void *buffer, size_t size, pxer_chunk_type_e *_ch_type); |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 68 | |
| 69 | /* |
| 70 | * This function checks the buffer against the tag name is expected to occur. |
| 71 | */ |
| 72 | typedef enum xer_check_tag { |
Lev Walkin | 904e65b | 2005-02-18 14:23:48 +0000 | [diff] [blame] | 73 | XCT_BROKEN = 0, /* The tag is broken */ |
| 74 | XCT_OPENING = 1, /* This is the <opening> tag */ |
| 75 | XCT_CLOSING = 2, /* This is the </closing> tag */ |
| 76 | XCT_BOTH = 3, /* This is the <modified/> tag */ |
| 77 | XCT__UNK__MASK = 4, /* Mask of everything unexpected */ |
| 78 | XCT_UNKNOWN_OP = 5, /* Unexpected <opening> tag */ |
| 79 | XCT_UNKNOWN_CL = 6, /* Unexpected </closing> tag */ |
| 80 | XCT_UNKNOWN_BO = 7, /* Unexpected <modified/> tag */ |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 81 | } xer_check_tag_e; |
| 82 | xer_check_tag_e xer_check_tag(const void *buf_ptr, int size, |
| 83 | const char *need_tag); |
| 84 | |
Lev Walkin | dde25b3 | 2004-10-22 08:17:16 +0000 | [diff] [blame] | 85 | /* |
| 86 | * Check whether this buffer consists of entirely XER whitespace characters. |
| 87 | * RETURN VALUES: |
| 88 | * 1: Whitespace or empty string |
| 89 | * 0: Non-whitespace |
| 90 | */ |
Lev Walkin | 0fab1a6 | 2005-03-09 22:19:25 +0000 | [diff] [blame] | 91 | int xer_is_whitespace(const void *chunk_buf, size_t chunk_size); |
Lev Walkin | dde25b3 | 2004-10-22 08:17:16 +0000 | [diff] [blame] | 92 | |
Lev Walkin | 2eeeedc | 2005-02-18 16:10:40 +0000 | [diff] [blame] | 93 | /* |
| 94 | * Skip the series of anticipated extensions. |
| 95 | */ |
| 96 | int xer_skip_unknown(xer_check_tag_e tcv, ber_tlv_len_t *depth); |
| 97 | |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 98 | #endif /* _XER_DECODER_H_ */ |