1 /*****************************************************************************
3 # Copyright 2019 AT&T Intellectual Property *
5 # Licensed under the Apache License, Version 2.0 (the "License"); *
6 # you may not use this file except in compliance with the License. *
7 # You may obtain a copy of the License at *
9 # http://www.apache.org/licenses/LICENSE-2.0 *
11 # Unless required by applicable law or agreed to in writing, software *
12 # distributed under the License is distributed on an "AS IS" BASIS, *
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14 # See the License for the specific language governing permissions and *
15 # limitations under the License. *
17 ******************************************************************************/
20 * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
21 * Redistribution and modifications are permitted subject to BSD license.
23 #ifndef _XER_DECODER_H_
24 #define _XER_DECODER_H_
26 #include <asn_application.h>
32 struct asn_TYPE_descriptor_s; /* Forward declaration */
35 * The XER decoder of any ASN.1 type. May be invoked by the application.
36 * Decodes CANONICAL-XER and BASIC-XER.
38 asn_dec_rval_t xer_decode(
39 const struct asn_codec_ctx_s *opt_codec_ctx,
40 const struct asn_TYPE_descriptor_s *type_descriptor,
41 void **struct_ptr, /* Pointer to a target structure's pointer */
42 const void *buffer, /* Data to be decoded */
43 size_t size /* Size of data buffer */
47 * Type of the type-specific XER decoder function.
49 typedef asn_dec_rval_t(xer_type_decoder_f)(
50 const asn_codec_ctx_t *opt_codec_ctx,
51 const struct asn_TYPE_descriptor_s *type_descriptor, void **struct_ptr,
52 const char *opt_mname, /* Member name */
53 const void *buf_ptr, size_t size);
55 /*******************************
56 * INTERNALLY USEFUL FUNCTIONS *
57 *******************************/
60 * Generalized function for decoding the primitive values.
61 * Used by more specialized functions, such as OCTET_STRING_decode_xer_utf8
62 * and others. This function should not be used by applications, as its API
63 * is subject to changes.
65 asn_dec_rval_t xer_decode_general(
66 const asn_codec_ctx_t *opt_codec_ctx,
67 asn_struct_ctx_t *ctx, /* Type decoder context */
68 void *struct_key, /* Treated as opaque pointer */
69 const char *xml_tag, /* Expected XML tag name */
70 const void *buf_ptr, size_t size,
71 int (*opt_unexpected_tag_decoder)(void *struct_key, const void *chunk_buf,
73 ssize_t (*body_receiver)(void *struct_key, const void *chunk_buf,
74 size_t chunk_size, int have_more));
78 * Fetch the next XER (XML) token from the stream.
79 * The function returns the number of bytes occupied by the chunk type,
80 * returned in the _ch_type. The _ch_type is only set (and valid) when
81 * the return value is >= 0.
83 typedef enum pxer_chunk_type {
84 PXER_WMORE, /* Chunk type is not clear, more data expected. */
85 PXER_TAG, /* Complete XER tag */
86 PXER_TEXT, /* Plain text between XER tags */
87 PXER_COMMENT /* A comment, may be part of */
89 ssize_t xer_next_token(int *stateContext,
90 const void *buffer, size_t size, pxer_chunk_type_e *_ch_type);
93 * This function checks the buffer against the tag name is expected to occur.
95 typedef enum xer_check_tag {
96 XCT_BROKEN = 0, /* The tag is broken */
97 XCT_OPENING = 1, /* This is the <opening> tag */
98 XCT_CLOSING = 2, /* This is the </closing> tag */
99 XCT_BOTH = 3, /* This is the <modified/> tag */
100 XCT__UNK__MASK = 4, /* Mask of everything unexpected */
101 XCT_UNKNOWN_OP = 5, /* Unexpected <opening> tag */
102 XCT_UNKNOWN_CL = 6, /* Unexpected </closing> tag */
103 XCT_UNKNOWN_BO = 7 /* Unexpected <modified/> tag */
105 xer_check_tag_e xer_check_tag(const void *buf_ptr, int size,
106 const char *need_tag);
109 * Get the number of bytes consisting entirely of XER whitespace characters.
111 * >=0: Number of whitespace characters in the string.
113 size_t xer_whitespace_span(const void *chunk_buf, size_t chunk_size);
116 * Skip the series of anticipated extensions.
118 int xer_skip_unknown(xer_check_tag_e tcv, ber_tlv_len_t *depth);
124 #endif /* _XER_DECODER_H_ */