blob: 15a67261de843681390a7f63cc60c446332196e4 [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 /*
vlm72425de2004-09-13 08:31:01 +000073 * Tags that are expected to occur.
vlmfa67ddc2004-06-03 03:38:44 +000074 */
vlm72425de2004-09-13 08:31:01 +000075 ber_tlv_tag_t *tags; /* Effective tags sequence for this type */
vlmfa67ddc2004-06-03 03:38:44 +000076 int tags_count; /* Number of tags which are expected */
vlm72425de2004-09-13 08:31:01 +000077 ber_tlv_tag_t *all_tags;/* Every tag for BER/containment */
78 int all_tags_count; /* Number of tags */
79
vlmfa67ddc2004-06-03 03:38:44 +000080 int last_tag_form; /* Acceptable form of the tag (prim, constr) */
81
82 /*
vlme413c122004-08-20 13:23:42 +000083 * An ASN.1 production type members (members of SEQUENCE, SET, CHOICE).
84 */
85 struct asn1_TYPE_member_s *elements;
86 int elements_count;
87
88 /*
vlmfa67ddc2004-06-03 03:38:44 +000089 * Additional information describing the type, used by appropriate
90 * functions above.
91 */
92 void *specifics;
93} asn1_TYPE_descriptor_t;
94
95/*
vlme413c122004-08-20 13:23:42 +000096 * An element of the constructed type, i.e. SEQUENCE, SET, CHOICE.
97 */
vlm72425de2004-09-13 08:31:01 +000098 enum asn1_TYPE_flags_e {
99 ATF_NOFLAGS,
100 ATF_POINTER = 0x01, /* Represented by the pointer */
101 ATF_OPEN_TYPE = 0x02, /* ANY type, without meaningful tag */
102 };
vlme413c122004-08-20 13:23:42 +0000103typedef struct asn1_TYPE_member_s {
vlm72425de2004-09-13 08:31:01 +0000104 enum asn1_TYPE_flags_e flags; /* Element's presentation flags */
vlmddd5a7d2004-09-10 09:18:20 +0000105 int optional; /* Following optional members, including current */
vlme413c122004-08-20 13:23:42 +0000106 int memb_offset; /* Offset of the element */
107 ber_tlv_tag_t tag; /* Outmost (most immediate) tag */
108 int tag_mode; /* IMPLICIT/no/EXPLICIT tag at current level */
109 asn1_TYPE_descriptor_t *type; /* Member type descriptor */
110 asn_constr_check_f *memb_constraints; /* Constraints validator */
111 char *name; /* ASN.1 identifier of the element */
112} asn1_TYPE_member_t;
113
114/*
vlm31473082004-06-06 07:20:02 +0000115 * BER tag to element number mapping.
116 */
117typedef struct asn1_TYPE_tag2member_s {
118 ber_tlv_tag_t el_tag; /* Outmost tag of the member */
119 int el_no; /* Index of the associated member, base 0 */
vlmc8aeab42004-06-14 13:09:45 +0000120 int toff_first; /* First occurence of the el_tag, relative */
121 int toff_last; /* Last occurence of the el_tag, relatvie */
vlm31473082004-06-06 07:20:02 +0000122} asn1_TYPE_tag2member_t;
123
124
vlm31473082004-06-06 07:20:02 +0000125/*
vlmfa67ddc2004-06-03 03:38:44 +0000126 * This function is a wrapper around (td)->print_struct, which prints out
127 * the contents of the target language's structure (struct_ptr) into the
128 * file pointer (stream) in human readable form.
129 * RETURN VALUES:
130 * 0: The structure is printed.
131 * -1: Problem dumping the structure.
132 */
133int asn_fprint(FILE *stream, /* Destination stream descriptor */
134 asn1_TYPE_descriptor_t *td, /* ASN.1 type descriptor */
135 const void *struct_ptr); /* Structure to be printed */
136
137#endif /* _CONSTR_TYPE_H_ */