2 * Copyright (c) 1997-2005 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #ifndef __GEN_LOCL_H__
37 #define __GEN_LOCL_H__
54 #include "asn1-common.h"
56 #include "der-private.h"
59 * XXX We need to move all module state out of globals and into a struct that
60 * we pass around when parsing and compiling a module, and also that we keep on
61 * a linked list of parsed modules.
65 * - implement IMPORTS correctly, because we need to know the type of a symbol
66 * in order to emit an extern declaration of it
67 * - implement value parsing
68 * - implement an ASN.1 library that does value parsing
70 * Value parsing, in particular, would be fantastic. We could then have
71 * options in hxtool(1) to load arbitrary ASN.1 modules and then parse SAN
72 * values given in ASN.1 value syntax on the command-line or in files. Eat
73 * your heart out OpenSSL if we do this!
75 * As well we'll need a `-I' option to the compiler so it knows where to find
76 * modules to IMPORT FROM.
78 typedef struct asn1_module
{
79 /* Name of ASN.1 module file: */
80 const char *orig_filename
;
81 /* Name of file to always include for common type definitions: */
82 const char *type_file_string
;
83 /* Name of public header file for module: */
85 /* Name of private header file for module: */
86 const char *privheader
;
87 /* Basename of module: */
88 const char *headerbase
;
89 /* Open stdio file handles for output: */
97 /* Module contents: */
98 struct sexport
*exports
;
99 struct import
*imports
;
100 Hashtab
*htab
; /* symbols */
101 /* Template state: */
102 struct templatehead
*template;
103 struct tlisthead
*tlistmaster
;
104 /* CLI options and flags needed everywhere: */
105 getarg_strings preserve
;
107 const char *enum_prefix
;
108 unsigned int one_code_file
:1;
109 unsigned int support_ber
:1;
110 unsigned int parse_units_flag
:1;
111 unsigned int prefix_enum
:1; /* Should be a getarg_strings of bitrsting types to do this for */
112 unsigned int rfc1510_bitstring
:1; /* Should be a getarg_strings of bitrsting types to do this for */
115 void generate_type (const Symbol
*);
116 void generate_type_header_forwards(const Symbol
*);
117 void generate_constant (const Symbol
*);
118 void generate_type_encode (const Symbol
*);
119 void generate_type_decode (const Symbol
*);
120 void generate_type_free (const Symbol
*);
121 void generate_type_length (const Symbol
*);
122 void generate_type_print_stub(const Symbol
*);
123 void generate_type_copy (const Symbol
*);
124 void generate_type_seq (const Symbol
*);
125 void generate_glue (const Type
*, const char*);
127 const char *classname(Der_class
);
128 const char *valuename(Der_class
, int);
130 void gen_compare_defval(const char *, struct value
*);
131 void gen_assign_defval(const char *, struct value
*);
133 int objid_cmp(struct objid
*, struct objid
*);
135 void init_generate (const char *, const char *);
136 const char *get_filename (void);
137 void close_generate(void);
138 void add_import(const char *);
139 void add_export(const char *);
140 int is_export(const char *);
142 int is_primitive_type(const Type
*);
143 int is_tagged_type(const Type
*);
145 int preserve_type(const char *);
146 int seq_type(const char *);
147 int decorate_type(const char *, char **, char **, int *);
149 void generate_header_of_codefile(const char *);
150 void close_codefile(void);
152 void get_open_type_defn_fields(const Type
*, Member
**, Member
**, Field
**,
154 void sort_object_set(IOSObjectSet
*, Field
*, IOSObject
***, size_t *);
155 int object_cmp(const void *, const void *);
157 int is_template_compat (const Symbol
*);
158 void generate_template(const Symbol
*);
159 void generate_template_type_forward(const char *);
160 void generate_template_objectset_forwards(const Symbol
*);
161 void gen_template_import(const Symbol
*);
163 struct objid
**objid2list(struct objid
*);
165 extern FILE *jsonfile
, *privheaderfile
, *headerfile
, *codefile
, *logfile
, *templatefile
;
166 extern const char *fuzzer_string
;
167 extern int support_ber
;
168 extern int template_flag
;
169 extern int rfc1510_bitstring
;
170 extern int one_code_file
;
171 extern int original_order
;
172 extern int parse_units_flag
;
173 extern char *type_file_string
;
175 extern int error_flag
;
177 #endif /* __GEN_LOCL_H__ */