Moving in e2sim originally from it/test/simulators
[sim/e2-interface.git] / e2sim / ASN1c / xer_decoder.h
1 /*****************************************************************************
2 #                                                                            *
3 # Copyright 2019 AT&T Intellectual Property                                  *
4 #                                                                            *
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                                    *
8 #                                                                            *
9 #      http://www.apache.org/licenses/LICENSE-2.0                            *
10 #                                                                            *
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.                                             *
16 #                                                                            *
17 ******************************************************************************/
18
19 /*-
20  * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
21  * Redistribution and modifications are permitted subject to BSD license.
22  */
23 #ifndef _XER_DECODER_H_
24 #define _XER_DECODER_H_
25
26 #include <asn_application.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 struct asn_TYPE_descriptor_s;   /* Forward declaration */
33
34 /*
35  * The XER decoder of any ASN.1 type. May be invoked by the application.
36  * Decodes CANONICAL-XER and BASIC-XER.
37  */
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 */
44 );
45
46 /*
47  * Type of the type-specific XER decoder function.
48  */
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);
54
55 /*******************************
56  * INTERNALLY USEFUL FUNCTIONS *
57  *******************************/
58
59 /*
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.
64  */
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,
72                                       size_t chunk_size),
73     ssize_t (*body_receiver)(void *struct_key, const void *chunk_buf,
74                              size_t chunk_size, int have_more));
75
76
77 /*
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.
82  */
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 */
88   } pxer_chunk_type_e;
89 ssize_t xer_next_token(int *stateContext,
90         const void *buffer, size_t size, pxer_chunk_type_e *_ch_type);
91
92 /*
93  * This function checks the buffer against the tag name is expected to occur.
94  */
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 */
104   } xer_check_tag_e;
105 xer_check_tag_e xer_check_tag(const void *buf_ptr, int size,
106                 const char *need_tag);
107
108 /*
109  * Get the number of bytes consisting entirely of XER whitespace characters.
110  * RETURN VALUES:
111  * >=0: Number of whitespace characters in the string.
112  */
113 size_t xer_whitespace_span(const void *chunk_buf, size_t chunk_size);
114
115 /*
116  * Skip the series of anticipated extensions.
117  */
118 int xer_skip_unknown(xer_check_tag_e tcv, ber_tlv_len_t *depth);
119
120 #ifdef __cplusplus
121 }
122 #endif
123
124 #endif  /* _XER_DECODER_H_ */