blob: 3463c6c00e033212973efbb23985da685c9e6c02 [file] [log] [blame]
vlmfa67ddc2004-06-03 03:38:44 +00001/*-
2 * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
5#ifndef _CONSTR_TYPE_H_
6#define _CONSTR_TYPE_H_
7
8#include <asn_types.h> /* System-dependent types */
9#include <ber_tlv_length.h>
10#include <ber_tlv_tag.h>
11#include <ber_decoder.h>
12#include <der_encoder.h>
13#include <constraints.h>
14
15struct asn1_TYPE_descriptor_s; /* Forward declaration */
vlme413c122004-08-20 13:23:42 +000016struct asn1_TYPE_member_s; /* Forward declaration */
vlmfa67ddc2004-06-03 03:38:44 +000017
18/*
19 * Free the structure according to its specification.
20 * If (free_contents_only) is set, the wrapper structure itself (struct_ptr)
21 * will not be freed. (It may be useful in case the structure is allocated
22 * statically or arranged on the stack, yet its elements are allocated
23 * dynamically.)
24 */
25typedef void (asn_struct_free_f)(
26 struct asn1_TYPE_descriptor_s *type_descriptor,
27 void *struct_ptr, int free_contents_only);
28
29/*
30 * Print the structure according to its specification.
31 */
32typedef int (asn_struct_print_f)(
33 struct asn1_TYPE_descriptor_s *type_descriptor,
34 const void *struct_ptr,
35 int level, /* Indentation level */
36 asn_app_consume_bytes_f *callback, void *app_key);
37
38/*
39 * Return the outmost tag of the type.
40 * If the type is untagged CHOICE, the dynamic operation is performed.
41 * NOTE: This function pointer type is only useful internally.
42 * Do not use it in your application.
43 */
44typedef ber_tlv_tag_t (asn_outmost_tag_f)(
45 struct asn1_TYPE_descriptor_s *type_descriptor,
46 const void *struct_ptr, int tag_mode, ber_tlv_tag_t tag);
vlme413c122004-08-20 13:23:42 +000047/* The instance of the above function type; used internally. */
vlmfa67ddc2004-06-03 03:38:44 +000048asn_outmost_tag_f asn1_TYPE_outmost_tag;
49
50
51/*
52 * The definitive description of the destination language's structure.
53 */
54typedef struct asn1_TYPE_descriptor_s {
55 char *name; /* A name of the ASN.1 type */
56
57 /*
58 * Generalized functions for dealing with the specific type.
59 * May be directly invoked by applications.
60 */
61 asn_constr_check_f *check_constraints; /* Constraints validator */
62 ber_type_decoder_f *ber_decoder; /* Free-form BER decoder */
63 der_type_encoder_f *der_encoder; /* Canonical DER encoder */
64 asn_struct_print_f *print_struct; /* Human readable output */
65 asn_struct_free_f *free_struct; /* Free the structure */
66
67 /*
68 * Functions used internally. Should not be used by applications.
69 */
70 asn_outmost_tag_f *outmost_tag; /* <optional, internal> */
71
72 /*
73 * Tags that are expected, with some of their vital properties.
74 */
75 ber_tlv_tag_t *tags; /* At least one tag must be specified */
76 int tags_count; /* Number of tags which are expected */
77 int tags_impl_skip; /* Tags to skip in implicit mode */
78 int last_tag_form; /* Acceptable form of the tag (prim, constr) */
79
80 /*
vlme413c122004-08-20 13:23:42 +000081 * An ASN.1 production type members (members of SEQUENCE, SET, CHOICE).
82 */
83 struct asn1_TYPE_member_s *elements;
84 int elements_count;
85
86 /*
vlmfa67ddc2004-06-03 03:38:44 +000087 * Additional information describing the type, used by appropriate
88 * functions above.
89 */
90 void *specifics;
91} asn1_TYPE_descriptor_t;
92
93/*
vlme413c122004-08-20 13:23:42 +000094 * An element of the constructed type, i.e. SEQUENCE, SET, CHOICE.
95 */
96typedef struct asn1_TYPE_member_s {
vlmddd5a7d2004-09-10 09:18:20 +000097 enum asn1_TYPE_flags_e {
98 ATF_NOFLAGS,
99 ATF_POINTER = 0x01, /* Represented by the pointer */
100 } flags; /* Element's presentation flags */
101 int optional; /* Following optional members, including current */
vlme413c122004-08-20 13:23:42 +0000102 int memb_offset; /* Offset of the element */
103 ber_tlv_tag_t tag; /* Outmost (most immediate) tag */
104 int tag_mode; /* IMPLICIT/no/EXPLICIT tag at current level */
105 asn1_TYPE_descriptor_t *type; /* Member type descriptor */
106 asn_constr_check_f *memb_constraints; /* Constraints validator */
107 char *name; /* ASN.1 identifier of the element */
108} asn1_TYPE_member_t;
109
110/*
vlm31473082004-06-06 07:20:02 +0000111 * BER tag to element number mapping.
112 */
113typedef struct asn1_TYPE_tag2member_s {
114 ber_tlv_tag_t el_tag; /* Outmost tag of the member */
115 int el_no; /* Index of the associated member, base 0 */
vlmc8aeab42004-06-14 13:09:45 +0000116 int toff_first; /* First occurence of the el_tag, relative */
117 int toff_last; /* Last occurence of the el_tag, relatvie */
vlm31473082004-06-06 07:20:02 +0000118} asn1_TYPE_tag2member_t;
119
120
vlm31473082004-06-06 07:20:02 +0000121/*
vlmfa67ddc2004-06-03 03:38:44 +0000122 * This function is a wrapper around (td)->print_struct, which prints out
123 * the contents of the target language's structure (struct_ptr) into the
124 * file pointer (stream) in human readable form.
125 * RETURN VALUES:
126 * 0: The structure is printed.
127 * -1: Problem dumping the structure.
128 */
129int asn_fprint(FILE *stream, /* Destination stream descriptor */
130 asn1_TYPE_descriptor_t *td, /* ASN.1 type descriptor */
131 const void *struct_ptr); /* Structure to be printed */
132
133#endif /* _CONSTR_TYPE_H_ */