3 * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
4 * Redistribution and modifications are permitted subject to BSD license.
6 #ifndef _XER_DECODER_H_
7 #define _XER_DECODER_H_
9 #include <asn_application.h>
15 struct asn_TYPE_descriptor_s; /* Forward declaration */
18 * The XER decoder of any ASN.1 type. May be invoked by the application.
19 * Decodes CANONICAL-XER and BASIC-XER.
21 asn_dec_rval_t xer_decode(
22 const struct asn_codec_ctx_s *opt_codec_ctx,
23 const struct asn_TYPE_descriptor_s *type_descriptor,
24 void **struct_ptr, /* Pointer to a target structure's pointer */
25 const void *buffer, /* Data to be decoded */
26 size_t size /* Size of data buffer */
30 * Type of the type-specific XER decoder function.
32 typedef asn_dec_rval_t(xer_type_decoder_f)(
33 const asn_codec_ctx_t *opt_codec_ctx,
34 const struct asn_TYPE_descriptor_s *type_descriptor, void **struct_ptr,
35 const char *opt_mname, /* Member name */
36 const void *buf_ptr, size_t size);
38 /*******************************
39 * INTERNALLY USEFUL FUNCTIONS *
40 *******************************/
43 * Generalized function for decoding the primitive values.
44 * Used by more specialized functions, such as OCTET_STRING_decode_xer_utf8
45 * and others. This function should not be used by applications, as its API
46 * is subject to changes.
48 asn_dec_rval_t xer_decode_general(
49 const asn_codec_ctx_t *opt_codec_ctx,
50 asn_struct_ctx_t *ctx, /* Type decoder context */
51 void *struct_key, /* Treated as opaque pointer */
52 const char *xml_tag, /* Expected XML tag name */
53 const void *buf_ptr, size_t size,
54 int (*opt_unexpected_tag_decoder)(void *struct_key, const void *chunk_buf,
56 ssize_t (*body_receiver)(void *struct_key, const void *chunk_buf,
57 size_t chunk_size, int have_more));
61 * Fetch the next XER (XML) token from the stream.
62 * The function returns the number of bytes occupied by the chunk type,
63 * returned in the _ch_type. The _ch_type is only set (and valid) when
64 * the return value is >= 0.
66 typedef enum pxer_chunk_type {
67 PXER_WMORE, /* Chunk type is not clear, more data expected. */
68 PXER_TAG, /* Complete XER tag */
69 PXER_TEXT, /* Plain text between XER tags */
70 PXER_COMMENT /* A comment, may be part of */
72 ssize_t xer_next_token(int *stateContext,
73 const void *buffer, size_t size, pxer_chunk_type_e *_ch_type);
76 * This function checks the buffer against the tag name is expected to occur.
78 typedef enum xer_check_tag {
79 XCT_BROKEN = 0, /* The tag is broken */
80 XCT_OPENING = 1, /* This is the <opening> tag */
81 XCT_CLOSING = 2, /* This is the </closing> tag */
82 XCT_BOTH = 3, /* This is the <modified/> tag */
83 XCT__UNK__MASK = 4, /* Mask of everything unexpected */
84 XCT_UNKNOWN_OP = 5, /* Unexpected <opening> tag */
85 XCT_UNKNOWN_CL = 6, /* Unexpected </closing> tag */
86 XCT_UNKNOWN_BO = 7 /* Unexpected <modified/> tag */
88 xer_check_tag_e xer_check_tag(const void *buf_ptr, int size,
89 const char *need_tag);
92 * Get the number of bytes consisting entirely of XER whitespace characters.
94 * >=0: Number of whitespace characters in the string.
96 size_t xer_whitespace_span(const void *chunk_buf, size_t chunk_size);
99 * Skip the series of anticipated extensions.
101 int xer_skip_unknown(xer_check_tag_e tcv, ber_tlv_len_t *depth);
107 #endif /* _XER_DECODER_H_ */