Harald Welte | d523a69 | 2015-08-30 23:11:19 +0200 | [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 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif |
| 13 | |
| 14 | struct asn_TYPE_descriptor_s; /* Forward declaration */ |
| 15 | |
| 16 | /* |
| 17 | * The XER decoder of any ASN.1 type. May be invoked by the application. |
| 18 | */ |
| 19 | asn_dec_rval_t xer_decode(struct asn_codec_ctx_s *opt_codec_ctx, |
| 20 | struct asn_TYPE_descriptor_s *type_descriptor, |
| 21 | void **struct_ptr, /* Pointer to a target structure's pointer */ |
| 22 | const void *buffer, /* Data to be decoded */ |
| 23 | size_t size /* Size of data buffer */ |
| 24 | ); |
| 25 | |
| 26 | /* |
| 27 | * Type of the type-specific XER decoder function. |
| 28 | */ |
| 29 | typedef asn_dec_rval_t (xer_type_decoder_f)(asn_codec_ctx_t *opt_codec_ctx, |
| 30 | struct asn_TYPE_descriptor_s *type_descriptor, |
| 31 | void **struct_ptr, |
| 32 | const char *opt_mname, /* Member name */ |
| 33 | const void *buf_ptr, size_t size |
| 34 | ); |
| 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 | */ |
| 46 | asn_dec_rval_t xer_decode_general(asn_codec_ctx_t *opt_codec_ctx, |
| 47 | asn_struct_ctx_t *ctx, /* Type decoder context */ |
| 48 | void *struct_key, /* Treated as opaque pointer */ |
| 49 | const char *xml_tag, /* Expected XML tag name */ |
| 50 | const void *buf_ptr, size_t size, |
| 51 | int (*opt_unexpected_tag_decoder) |
| 52 | (void *struct_key, const void *chunk_buf, size_t chunk_size), |
| 53 | ssize_t (*body_receiver) |
| 54 | (void *struct_key, const void *chunk_buf, size_t chunk_size, |
| 55 | int have_more) |
| 56 | ); |
| 57 | |
| 58 | |
| 59 | /* |
| 60 | * Fetch the next XER (XML) token from the stream. |
| 61 | * The function returns the number of bytes occupied by the chunk type, |
| 62 | * returned in the _ch_type. The _ch_type is only set (and valid) when |
| 63 | * the return value is greater than 0. |
| 64 | */ |
| 65 | typedef enum pxer_chunk_type { |
| 66 | PXER_TAG, /* Complete XER tag */ |
| 67 | PXER_TEXT, /* Plain text between XER tags */ |
| 68 | PXER_COMMENT /* A comment, may be part of */ |
| 69 | } pxer_chunk_type_e; |
| 70 | ssize_t xer_next_token(int *stateContext, |
| 71 | const void *buffer, size_t size, pxer_chunk_type_e *_ch_type); |
| 72 | |
| 73 | /* |
| 74 | * This function checks the buffer against the tag name is expected to occur. |
| 75 | */ |
| 76 | typedef enum xer_check_tag { |
| 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 */ |
| 84 | XCT_UNKNOWN_BO = 7 /* Unexpected <modified/> tag */ |
| 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 | |
| 89 | /* |
| 90 | * Get the number of bytes consisting entirely of XER whitespace characters. |
| 91 | * RETURN VALUES: |
| 92 | * >=0: Number of whitespace characters in the string. |
| 93 | */ |
| 94 | size_t xer_whitespace_span(const void *chunk_buf, size_t chunk_size); |
| 95 | |
| 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 | |
| 101 | #ifdef __cplusplus |
| 102 | } |
| 103 | #endif |
| 104 | |
| 105 | #endif /* _XER_DECODER_H_ */ |