ITS
constr_TYPE.h
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2003, 2004, 2005, 2006 Lev Walkin <vlm@lionet.info>.
3  * All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
6 /*
7  * This file contains the declaration structure called "ASN.1 Type Definition",
8  * which holds all information necessary for encoding and decoding routines.
9  * This structure even contains pointer to these encoding and decoding routines
10  * for each defined ASN.1 type.
11  */
12 #ifndef _CONSTR_TYPE_H_
13 #define _CONSTR_TYPE_H_
14 
15 #include <ber_tlv_length.h>
16 #include <ber_tlv_tag.h>
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 struct asn_TYPE_descriptor_s; /* Forward declaration */
23 struct asn_TYPE_member_s; /* Forward declaration */
24 
25 /*
26  * This type provides the context information for various ASN.1 routines,
27  * primarily ones doing decoding. A member _asn_ctx of this type must be
28  * included into certain target language's structures, such as compound types.
29  */
30 typedef struct asn_struct_ctx_s {
31  short phase; /* Decoding phase */
32  short step; /* Elementary step of a phase */
33  int context; /* Other context information */
34  void *ptr; /* Decoder-specific stuff (stack elements) */
35  ber_tlv_len_t left; /* Number of bytes left, -1 for indefinite */
37 
38 #include <ber_decoder.h> /* Basic Encoding Rules decoder */
39 #include <der_encoder.h> /* Distinguished Encoding Rules encoder */
40 #include <xer_decoder.h> /* Decoder of XER (XML, text) */
41 #include <xer_encoder.h> /* Encoder into XER (XML, text) */
42 #include <per_decoder.h> /* Packet Encoding Rules decoder */
43 #include <per_encoder.h> /* Packet Encoding Rules encoder */
44 #include <constraints.h> /* Subtype constraints support */
45 
46 /*
47  * Free the structure according to its specification.
48  * If (free_contents_only) is set, the wrapper structure itself (struct_ptr)
49  * will not be freed. (It may be useful in case the structure is allocated
50  * statically or arranged on the stack, yet its elements are allocated
51  * dynamically.)
52  */
53 typedef void (asn_struct_free_f)(
54  struct asn_TYPE_descriptor_s *type_descriptor,
55  void *struct_ptr, int free_contents_only);
56 #define ASN_STRUCT_FREE(asn_DEF, ptr) (asn_DEF).free_struct(&(asn_DEF),ptr,0)
57 #define ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF, ptr) \
58  (asn_DEF).free_struct(&(asn_DEF),ptr,1)
59 
60 /*
61  * Print the structure according to its specification.
62  */
63 typedef int (asn_struct_print_f)(
64  struct asn_TYPE_descriptor_s *type_descriptor,
65  const void *struct_ptr,
66  int level, /* Indentation level */
67  asn_app_consume_bytes_f *callback, void *app_key);
68 
69 /*
70  * Return the outmost tag of the type.
71  * If the type is untagged CHOICE, the dynamic operation is performed.
72  * NOTE: This function pointer type is only useful internally.
73  * Do not use it in your application.
74  */
76  struct asn_TYPE_descriptor_s *type_descriptor,
77  const void *struct_ptr, int tag_mode, ber_tlv_tag_t tag);
78 /* The instance of the above function type; used internally. */
80 
81 
82 /*
83  * The definitive description of the destination language's structure.
84  */
85 typedef struct asn_TYPE_descriptor_s {
86  char *name; /* A name of the ASN.1 type. "" in some cases. */
87  char *xml_tag; /* Name used in XML tag */
88 
89  /*
90  * Generalized functions for dealing with the specific type.
91  * May be directly invoked by applications.
92  */
93  asn_struct_free_f *free_struct; /* Free the structure */
94  asn_struct_print_f *print_struct; /* Human readable output */
95  asn_constr_check_f *check_constraints; /* Constraints validator */
96  ber_type_decoder_f *ber_decoder; /* Generic BER decoder */
97  der_type_encoder_f *der_encoder; /* Canonical DER encoder */
98  xer_type_decoder_f *xer_decoder; /* Generic XER decoder */
99  xer_type_encoder_f *xer_encoder; /* [Canonical] XER encoder */
100  per_type_decoder_f *uper_decoder; /* Unaligned PER decoder */
101  per_type_encoder_f *uper_encoder; /* Unaligned PER encoder */
102 
103  /***********************************************************************
104  * Internally useful members. Not to be used by applications directly. *
105  **********************************************************************/
106 
107  /*
108  * Tags that are expected to occur.
109  */
110  asn_outmost_tag_f *outmost_tag; /* <optional, internal> */
111  ber_tlv_tag_t *tags; /* Effective tags sequence for this type */
112  int tags_count; /* Number of tags which are expected */
113  ber_tlv_tag_t *all_tags;/* Every tag for BER/containment */
114  int all_tags_count; /* Number of tags */
115 
116  asn_per_constraints_t *per_constraints; /* PER compiled constraints */
117 
118  /*
119  * An ASN.1 production type members (members of SEQUENCE, SET, CHOICE).
120  */
123 
124  /*
125  * Additional information describing the type, used by appropriate
126  * functions above.
127  */
128  void *specifics;
130 
131 /*
132  * This type describes an element of the constructed type,
133  * i.e. SEQUENCE, SET, CHOICE, etc.
134  */
137  ATF_POINTER = 0x01, /* Represented by the pointer */
138  ATF_OPEN_TYPE = 0x02 /* ANY type, without meaningful tag */
139  };
140 typedef struct asn_TYPE_member_s {
141  enum asn_TYPE_flags_e flags; /* Element's presentation flags */
142  int optional; /* Following optional members, including current */
143  int memb_offset; /* Offset of the element */
144  ber_tlv_tag_t tag; /* Outmost (most immediate) tag */
145  int tag_mode; /* IMPLICIT/no/EXPLICIT tag at current level */
146  asn_TYPE_descriptor_t *type; /* Member type descriptor */
147  asn_constr_check_f *memb_constraints; /* Constraints validator */
148  asn_per_constraints_t *per_constraints; /* PER compiled constraints */
149  int (*default_value)(int setval, void **sptr); /* DEFAULT <value> */
150  char *name; /* ASN.1 identifier of the element */
152 
153 /*
154  * BER tag to element number mapping.
155  */
156 typedef struct asn_TYPE_tag2member_s {
157  ber_tlv_tag_t el_tag; /* Outmost tag of the member */
158  int el_no; /* Index of the associated member, base 0 */
159  int toff_first; /* First occurence of the el_tag, relative */
160  int toff_last; /* Last occurence of the el_tag, relatvie */
162 
163 /*
164  * This function is a wrapper around (td)->print_struct, which prints out
165  * the contents of the target language's structure (struct_ptr) into the
166  * file pointer (stream) in human readable form.
167  * RETURN VALUES:
168  * 0: The structure is printed.
169  * -1: Problem dumping the structure.
170  * (See also xer_fprint() in xer_encoder.h)
171  */
172 int asn_fprint(FILE *stream, /* Destination stream descriptor */
173  asn_TYPE_descriptor_t *td, /* ASN.1 type descriptor */
174  const void *struct_ptr); /* Structure to be printed */
175 
176 #ifdef __cplusplus
177 }
178 #endif
179 
180 #endif /* _CONSTR_TYPE_H_ */
struct asn_TYPE_descriptor_s asn_TYPE_descriptor_t
int(* default_value)(int setval, void **sptr)
Definition: constr_TYPE.h:149
asn_outmost_tag_f asn_TYPE_outmost_tag
Definition: constr_TYPE.h:79
enum asn_TYPE_flags_e flags
Definition: constr_TYPE.h:141
asn_dec_rval_t() ber_type_decoder_f(struct asn_codec_ctx_s *opt_codec_ctx, struct asn_TYPE_descriptor_s *type_descriptor, void **struct_ptr, const void *buf_ptr, size_t size, int tag_mode)
Definition: ber_decoder.h:32
ber_tlv_tag_t * all_tags
Definition: constr_TYPE.h:113
asn_TYPE_flags_e
Definition: constr_TYPE.h:135
struct asn_TYPE_member_s asn_TYPE_member_t
asn_enc_rval_t() per_type_encoder_f(struct asn_TYPE_descriptor_s *type_descriptor, asn_per_constraints_t *constraints, void *struct_ptr, asn_per_outp_t *per_output)
Definition: per_encoder.h:58
asn_enc_rval_t() xer_type_encoder_f(struct asn_TYPE_descriptor_s *type_descriptor, void *struct_ptr, int ilevel, enum xer_encoder_flags_e xer_flags, asn_app_consume_bytes_f *consume_bytes_cb, void *app_key)
Definition: xer_encoder.h:46
void() asn_struct_free_f(struct asn_TYPE_descriptor_s *type_descriptor, void *struct_ptr, int free_contents_only)
Definition: constr_TYPE.h:53
asn_outmost_tag_f * outmost_tag
Definition: constr_TYPE.h:110
asn_struct_free_f * free_struct
Definition: constr_TYPE.h:93
asn_constr_check_f * memb_constraints
Definition: constr_TYPE.h:147
ber_tlv_len_t left
Definition: constr_TYPE.h:35
ber_tlv_tag_t el_tag
Definition: constr_TYPE.h:157
ssize_t ber_tlv_len_t
asn_per_constraints_t * per_constraints
Definition: constr_TYPE.h:148
ber_tlv_tag_t * tags
Definition: constr_TYPE.h:111
int() asn_constr_check_f(struct asn_TYPE_descriptor_s *type_descriptor, const void *struct_ptr, asn_app_constraint_failed_f *optional_callback, void *optional_app_key)
Definition: constraints.h:40
asn_constr_check_f * check_constraints
Definition: constr_TYPE.h:95
asn_enc_rval_t() der_type_encoder_f(struct asn_TYPE_descriptor_s *type_descriptor, void *struct_ptr, int tag_mode, ber_tlv_tag_t tag, asn_app_consume_bytes_f *consume_bytes_cb, void *app_key)
Definition: der_encoder.h:37
asn_struct_print_f * print_struct
Definition: constr_TYPE.h:94
ber_tlv_tag_t() asn_outmost_tag_f(struct asn_TYPE_descriptor_s *type_descriptor, const void *struct_ptr, int tag_mode, ber_tlv_tag_t tag)
Definition: constr_TYPE.h:75
struct asn_TYPE_member_s * elements
Definition: constr_TYPE.h:121
asn_dec_rval_t() xer_type_decoder_f(asn_codec_ctx_t *opt_codec_ctx, struct asn_TYPE_descriptor_s *type_descriptor, void **struct_ptr, const char *opt_mname, const void *buf_ptr, size_t size)
Definition: xer_decoder.h:29
int() asn_app_consume_bytes_f(const void *buffer, size_t size, void *application_specific_key)
asn_dec_rval_t() per_type_decoder_f(asn_codec_ctx_t *opt_codec_ctx, struct asn_TYPE_descriptor_s *type_descriptor, asn_per_constraints_t *constraints, void **struct_ptr, asn_per_data_t *per_data)
Definition: per_decoder.h:45
xer_type_decoder_f * xer_decoder
Definition: constr_TYPE.h:98
der_type_encoder_f * der_encoder
Definition: constr_TYPE.h:97
int() asn_struct_print_f(struct asn_TYPE_descriptor_s *type_descriptor, const void *struct_ptr, int level, asn_app_consume_bytes_f *callback, void *app_key)
Definition: constr_TYPE.h:63
asn_TYPE_descriptor_t * type
Definition: constr_TYPE.h:146
int asn_fprint(FILE *stream, asn_TYPE_descriptor_t *td, const void *struct_ptr)
Definition: constr_TYPE.c:36
per_type_encoder_f * uper_encoder
Definition: constr_TYPE.h:101
struct asn_struct_ctx_s asn_struct_ctx_t
per_type_decoder_f * uper_decoder
Definition: constr_TYPE.h:100
ber_tlv_tag_t tag
Definition: constr_TYPE.h:144
asn_per_constraints_t * per_constraints
Definition: constr_TYPE.h:116
struct asn_TYPE_tag2member_s asn_TYPE_tag2member_t
ber_type_decoder_f * ber_decoder
Definition: constr_TYPE.h:96
unsigned ber_tlv_tag_t
Definition: ber_tlv_tag.h:18
xer_type_encoder_f * xer_encoder
Definition: constr_TYPE.h:99