blob: 301b613cf4bdc62aa6e50953eb15e19c08d957c6 [file] [log] [blame]
Lev Walkindc06f6b2004-10-20 15:50:55 +00001/*-
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
Lev Walkin21b41ac2005-07-24 09:03:44 +000010#ifdef __cplusplus
11extern "C" {
12#endif
13
Lev Walkindc06f6b2004-10-20 15:50:55 +000014struct asn_TYPE_descriptor_s; /* Forward declaration */
15
16/*
Lev Walkin1d9e8dd2005-12-07 05:46:03 +000017 * The XER decoder of any ASN.1 type. May be invoked by the application.
Lev Walkindc06f6b2004-10-20 15:50:55 +000018 */
19asn_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 */
Lev Walkin8c3b8542005-03-10 18:52:02 +000022 const void *buffer, /* Data to be decoded */
Lev Walkin1d9e8dd2005-12-07 05:46:03 +000023 size_t size /* Size of data buffer */
Lev Walkindc06f6b2004-10-20 15:50:55 +000024 );
25
26/*
27 * Type of the type-specific XER decoder function.
28 */
29typedef 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 */
Lev Walkin8c3b8542005-03-10 18:52:02 +000033 const void *buf_ptr, size_t size
Lev Walkindc06f6b2004-10-20 15:50:55 +000034 );
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 */
46asn_dec_rval_t xer_decode_general(asn_codec_ctx_t *opt_codec_ctx,
47 asn_struct_ctx_t *ctx, /* Type decoder context */
Lev Walkin3256d6f2004-10-21 11:22:12 +000048 void *struct_key, /* Treated as opaque pointer */
Lev Walkindc06f6b2004-10-20 15:50:55 +000049 const char *xml_tag, /* Expected XML tag name */
Lev Walkin0fab1a62005-03-09 22:19:25 +000050 const void *buf_ptr, size_t size,
Lev Walkindc06f6b2004-10-20 15:50:55 +000051 int (*opt_unexpected_tag_decoder)
Lev Walkin0fab1a62005-03-09 22:19:25 +000052 (void *struct_key, const void *chunk_buf, size_t chunk_size),
Lev Walkindc06f6b2004-10-20 15:50:55 +000053 ssize_t (*body_receiver)
Lev Walkin0fab1a62005-03-09 22:19:25 +000054 (void *struct_key, const void *chunk_buf, size_t chunk_size,
Lev Walkindc06f6b2004-10-20 15:50:55 +000055 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
Lev Walkin97363482016-01-24 19:23:02 -080063 * the return value is >= 0.
Lev Walkindc06f6b2004-10-20 15:50:55 +000064 */
65 typedef enum pxer_chunk_type {
Lev Walkin97363482016-01-24 19:23:02 -080066 PXER_WMORE, /* Chunk type is not clear, more data expected. */
67 PXER_TAG, /* Complete XER tag */
68 PXER_TEXT, /* Plain text between XER tags */
Lev Walkin8c3b8542005-03-10 18:52:02 +000069 PXER_COMMENT /* A comment, may be part of */
Lev Walkindc06f6b2004-10-20 15:50:55 +000070 } pxer_chunk_type_e;
Lev Walkin1e443962005-02-18 18:06:36 +000071ssize_t xer_next_token(int *stateContext,
Lev Walkin0fab1a62005-03-09 22:19:25 +000072 const void *buffer, size_t size, pxer_chunk_type_e *_ch_type);
Lev Walkindc06f6b2004-10-20 15:50:55 +000073
74/*
75 * This function checks the buffer against the tag name is expected to occur.
76 */
77 typedef enum xer_check_tag {
Lev Walkin904e65b2005-02-18 14:23:48 +000078 XCT_BROKEN = 0, /* The tag is broken */
79 XCT_OPENING = 1, /* This is the <opening> tag */
80 XCT_CLOSING = 2, /* This is the </closing> tag */
81 XCT_BOTH = 3, /* This is the <modified/> tag */
82 XCT__UNK__MASK = 4, /* Mask of everything unexpected */
83 XCT_UNKNOWN_OP = 5, /* Unexpected <opening> tag */
84 XCT_UNKNOWN_CL = 6, /* Unexpected </closing> tag */
Lev Walkin8c3b8542005-03-10 18:52:02 +000085 XCT_UNKNOWN_BO = 7 /* Unexpected <modified/> tag */
Lev Walkindc06f6b2004-10-20 15:50:55 +000086 } xer_check_tag_e;
87xer_check_tag_e xer_check_tag(const void *buf_ptr, int size,
88 const char *need_tag);
89
Lev Walkindde25b32004-10-22 08:17:16 +000090/*
Lev Walkinf7982282013-03-16 07:01:42 -070091 * Get the number of bytes consisting entirely of XER whitespace characters.
Lev Walkindde25b32004-10-22 08:17:16 +000092 * RETURN VALUES:
Lev Walkinf7982282013-03-16 07:01:42 -070093 * >=0: Number of whitespace characters in the string.
Lev Walkindde25b32004-10-22 08:17:16 +000094 */
Lev Walkinf7982282013-03-16 07:01:42 -070095size_t xer_whitespace_span(const void *chunk_buf, size_t chunk_size);
Lev Walkindde25b32004-10-22 08:17:16 +000096
Lev Walkin2eeeedc2005-02-18 16:10:40 +000097/*
98 * Skip the series of anticipated extensions.
99 */
100int xer_skip_unknown(xer_check_tag_e tcv, ber_tlv_len_t *depth);
101
Lev Walkin21b41ac2005-07-24 09:03:44 +0000102#ifdef __cplusplus
103}
104#endif
105
Lev Walkindc06f6b2004-10-20 15:50:55 +0000106#endif /* _XER_DECODER_H_ */