e874abc01b909cb19f88b2a63bf56dd49908c4ed
[ric-plt/resource-status-manager.git] / RSM / asn1codec / e2ap_engine / xer_decoder.h
1
2 /*-
3  * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
6 #ifndef _XER_DECODER_H_
7 #define _XER_DECODER_H_
8
9 #include <asn_application.h>
10
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14
15 struct asn_TYPE_descriptor_s;   /* Forward declaration */
16
17 /*
18  * The XER decoder of any ASN.1 type. May be invoked by the application.
19  * Decodes CANONICAL-XER and BASIC-XER.
20  */
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 */
27 );
28
29 /*
30  * Type of the type-specific XER decoder function.
31  */
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);
37
38 /*******************************
39  * INTERNALLY USEFUL FUNCTIONS *
40  *******************************/
41
42 /*
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.
47  */
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,
55                                       size_t chunk_size),
56     ssize_t (*body_receiver)(void *struct_key, const void *chunk_buf,
57                              size_t chunk_size, int have_more));
58
59
60 /*
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.
65  */
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 */
71   } pxer_chunk_type_e;
72 ssize_t xer_next_token(int *stateContext,
73         const void *buffer, size_t size, pxer_chunk_type_e *_ch_type);
74
75 /*
76  * This function checks the buffer against the tag name is expected to occur.
77  */
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 */
87   } xer_check_tag_e;
88 xer_check_tag_e xer_check_tag(const void *buf_ptr, int size,
89                 const char *need_tag);
90
91 /*
92  * Get the number of bytes consisting entirely of XER whitespace characters.
93  * RETURN VALUES:
94  * >=0: Number of whitespace characters in the string.
95  */
96 size_t xer_whitespace_span(const void *chunk_buf, size_t chunk_size);
97
98 /*
99  * Skip the series of anticipated extensions.
100  */
101 int xer_skip_unknown(xer_check_tag_e tcv, ber_tlv_len_t *depth);
102
103 #ifdef __cplusplus
104 }
105 #endif
106
107 #endif  /* _XER_DECODER_H_ */