vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
| 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 | |
| 15 | struct asn1_TYPE_descriptor_s; /* Forward declaration */ |
| 16 | |
| 17 | /* |
| 18 | * Free the structure according to its specification. |
| 19 | * If (free_contents_only) is set, the wrapper structure itself (struct_ptr) |
| 20 | * will not be freed. (It may be useful in case the structure is allocated |
| 21 | * statically or arranged on the stack, yet its elements are allocated |
| 22 | * dynamically.) |
| 23 | */ |
| 24 | typedef void (asn_struct_free_f)( |
| 25 | struct asn1_TYPE_descriptor_s *type_descriptor, |
| 26 | void *struct_ptr, int free_contents_only); |
| 27 | |
| 28 | /* |
| 29 | * Print the structure according to its specification. |
| 30 | */ |
| 31 | typedef int (asn_struct_print_f)( |
| 32 | struct asn1_TYPE_descriptor_s *type_descriptor, |
| 33 | const void *struct_ptr, |
| 34 | int level, /* Indentation level */ |
| 35 | asn_app_consume_bytes_f *callback, void *app_key); |
| 36 | |
| 37 | /* |
| 38 | * Return the outmost tag of the type. |
| 39 | * If the type is untagged CHOICE, the dynamic operation is performed. |
| 40 | * NOTE: This function pointer type is only useful internally. |
| 41 | * Do not use it in your application. |
| 42 | */ |
| 43 | typedef ber_tlv_tag_t (asn_outmost_tag_f)( |
| 44 | struct asn1_TYPE_descriptor_s *type_descriptor, |
| 45 | const void *struct_ptr, int tag_mode, ber_tlv_tag_t tag); |
| 46 | /* The instance of the above function type */ |
| 47 | asn_outmost_tag_f asn1_TYPE_outmost_tag; |
| 48 | |
| 49 | |
| 50 | /* |
| 51 | * The definitive description of the destination language's structure. |
| 52 | */ |
| 53 | typedef struct asn1_TYPE_descriptor_s { |
| 54 | char *name; /* A name of the ASN.1 type */ |
| 55 | |
| 56 | /* |
| 57 | * Generalized functions for dealing with the specific type. |
| 58 | * May be directly invoked by applications. |
| 59 | */ |
| 60 | asn_constr_check_f *check_constraints; /* Constraints validator */ |
| 61 | ber_type_decoder_f *ber_decoder; /* Free-form BER decoder */ |
| 62 | der_type_encoder_f *der_encoder; /* Canonical DER encoder */ |
| 63 | asn_struct_print_f *print_struct; /* Human readable output */ |
| 64 | asn_struct_free_f *free_struct; /* Free the structure */ |
| 65 | |
| 66 | /* |
| 67 | * Functions used internally. Should not be used by applications. |
| 68 | */ |
| 69 | asn_outmost_tag_f *outmost_tag; /* <optional, internal> */ |
| 70 | |
| 71 | /* |
| 72 | * Tags that are expected, with some of their vital properties. |
| 73 | */ |
| 74 | ber_tlv_tag_t *tags; /* At least one tag must be specified */ |
| 75 | int tags_count; /* Number of tags which are expected */ |
| 76 | int tags_impl_skip; /* Tags to skip in implicit mode */ |
| 77 | int last_tag_form; /* Acceptable form of the tag (prim, constr) */ |
| 78 | |
| 79 | /* |
| 80 | * Additional information describing the type, used by appropriate |
| 81 | * functions above. |
| 82 | */ |
| 83 | void *specifics; |
| 84 | } asn1_TYPE_descriptor_t; |
| 85 | |
| 86 | /* |
vlm | 3147308 | 2004-06-06 07:20:02 +0000 | [diff] [blame] | 87 | * BER tag to element number mapping. |
| 88 | */ |
| 89 | typedef struct asn1_TYPE_tag2member_s { |
| 90 | ber_tlv_tag_t el_tag; /* Outmost tag of the member */ |
| 91 | int el_no; /* Index of the associated member, base 0 */ |
vlm | c8aeab4 | 2004-06-14 13:09:45 +0000 | [diff] [blame] | 92 | int toff_first; /* First occurence of the el_tag, relative */ |
| 93 | int toff_last; /* Last occurence of the el_tag, relatvie */ |
vlm | 3147308 | 2004-06-06 07:20:02 +0000 | [diff] [blame] | 94 | } asn1_TYPE_tag2member_t; |
| 95 | |
| 96 | |
vlm | 3147308 | 2004-06-06 07:20:02 +0000 | [diff] [blame] | 97 | /* |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 98 | * This function is a wrapper around (td)->print_struct, which prints out |
| 99 | * the contents of the target language's structure (struct_ptr) into the |
| 100 | * file pointer (stream) in human readable form. |
| 101 | * RETURN VALUES: |
| 102 | * 0: The structure is printed. |
| 103 | * -1: Problem dumping the structure. |
| 104 | */ |
| 105 | int asn_fprint(FILE *stream, /* Destination stream descriptor */ |
| 106 | asn1_TYPE_descriptor_t *td, /* ASN.1 type descriptor */ |
| 107 | const void *struct_ptr); /* Structure to be printed */ |
| 108 | |
| 109 | #endif /* _CONSTR_TYPE_H_ */ |