2 * Copyright (c) 1997 - 2005 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Portions Copyright (c) 2009 - 2010 Apple Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 static const char *symbol_name(const char *, const Type
*);
39 static void generate_template_type(const char *, const char **, const char *, const char *, const char *,
40 Type
*, int, int, int);
43 ttype_symbol(const char *basename
, const Type
*t
)
45 return t
->symbol
->gen_name
;
49 integer_symbol(const char *basename
, const Type
*t
)
52 return "int"; /* XXX enum foo */
53 else if (t
->range
== NULL
)
54 return "heim_integer";
55 else if (t
->range
->min
< INT_MIN
&& t
->range
->max
<= INT64_MAX
)
57 else if (t
->range
->min
>= 0 && t
->range
->max
> UINT_MAX
)
59 else if (t
->range
->min
>= INT_MIN
&& t
->range
->max
<= INT_MAX
)
61 else if (t
->range
->min
>= 0 && t
->range
->max
<= UINT_MAX
)
65 UNREACHABLE(return NULL
);
70 boolean_symbol(const char *basename
, const Type
*t
)
77 octetstring_symbol(const char *basename
, const Type
*t
)
79 return "heim_octet_string";
83 sequence_symbol(const char *basename
, const Type
*t
)
89 time_symbol(const char *basename
, const Type
*t
)
95 tag_symbol(const char *basename
, const Type
*t
)
97 return symbol_name(basename
, t
->subtype
);
101 generalstring_symbol(const char *basename
, const Type
*t
)
103 return "heim_general_string";
107 printablestring_symbol(const char *basename
, const Type
*t
)
109 return "heim_printable_string";
113 ia5string_symbol(const char *basename
, const Type
*t
)
115 return "heim_ia5_string";
119 teletexstring_symbol(const char *basename
, const Type
*t
)
121 return "heim_teletex_string";
125 visiblestring_symbol(const char *basename
, const Type
*t
)
127 return "heim_visible_string";
131 utf8string_symbol(const char *basename
, const Type
*t
)
133 return "heim_utf8_string";
137 bmpstring_symbol(const char *basename
, const Type
*t
)
139 return "heim_bmp_string";
143 universalstring_symbol(const char *basename
, const Type
*t
)
145 return "heim_universal_string";
149 oid_symbol(const char *basename
, const Type
*t
)
155 bitstring_symbol(const char *basename
, const Type
*t
)
159 return "heim_bit_string";
166 const char *(*symbol_name
)(const char *, const Type
*);
169 { TBMPString
, bmpstring_symbol
, 0 },
170 { TBitString
, bitstring_symbol
, 0 },
171 { TBoolean
, boolean_symbol
, 0 },
172 { TGeneralString
, generalstring_symbol
, 0 },
173 { TGeneralizedTime
, time_symbol
, 0 },
174 { TIA5String
, ia5string_symbol
, 0 },
175 { TTeletexString
, generalstring_symbol
, 0 },
176 { TInteger
, integer_symbol
, 0 },
177 { TOID
, oid_symbol
, 0 },
178 { TOctetString
, octetstring_symbol
, 0 },
179 { TPrintableString
, printablestring_symbol
, 0 },
180 { TSequence
, sequence_symbol
, 1 },
181 { TSequenceOf
, tag_symbol
, 1 },
182 { TSetOf
, tag_symbol
, 1 },
183 { TTag
, tag_symbol
, 1 },
184 { TType
, ttype_symbol
, 1 },
185 { TUTCTime
, time_symbol
, 0 },
186 { TUniversalString
, universalstring_symbol
, 0 },
187 { TTeletexString
, teletexstring_symbol
, 0 },
188 { TVisibleString
, visiblestring_symbol
, 0 },
189 { TUTF8String
, utf8string_symbol
, 0 },
190 { TChoice
, sequence_symbol
, 1 },
191 { TNull
, integer_symbol
, 1 }
204 is_supported_type_p(const Type
*t
)
208 for (i
= 0; i
< sizeof(types
)/sizeof(types
[0]); i
++)
209 if (t
->type
== types
[i
].type
)
215 is_template_compat (const Symbol
*s
)
217 return is_supported_type_p(s
->type
);
221 symbol_name(const char *basename
, const Type
*t
)
225 for (i
= 0; i
< sizeof(types
)/sizeof(types
[0]); i
++)
226 if (t
->type
== types
[i
].type
)
227 return (types
[i
].symbol_name
)(basename
, t
);
228 printf("unknown der type: %d\n", t
->type
);
234 partial_offset(const char *basetype
, const char *name
, int need_offset
, int isstruct
)
237 if (name
== NULL
|| need_offset
== 0)
239 if (asprintf(&str
, "offsetof(%s%s, %s)", isstruct
? "struct " : "", basetype
, name
) < 0 || str
== NULL
)
249 ASN1_TAILQ_ENTRY(template) members
;
252 ASN1_TAILQ_HEAD(templatehead
, template);
257 struct templatehead
template;
258 ASN1_TAILQ_ENTRY(tlist
) tmembers
;
261 ASN1_TAILQ_HEAD(tlisthead
, tlist
);
263 static void tlist_header(struct tlist
*, const char *, ...) __attribute__((__format__(__printf__
, 2, 3)));
264 static struct template *
265 add_line(struct templatehead
*, const char *, ...) __attribute__((__format__(__printf__
, 2, 3)));
266 static int tlist_cmp(const struct tlist
*, const struct tlist
*);
268 static void add_line_pointer(struct templatehead
*, const char *, const char *, const char *, ...)
269 __attribute__((__format__(__printf__
, 4, 5)));
272 static struct tlisthead tlistmaster
= ASN1_TAILQ_HEAD_INITIALIZER(tlistmaster
);
273 static unsigned long numdups
= 0;
275 static struct tlist
*
276 tlist_new(const char *name
)
278 struct tlist
*tl
= calloc(1, sizeof(*tl
));
279 tl
->name
= strdup(name
);
280 ASN1_TAILQ_INIT(&tl
->template);
285 tlist_header(struct tlist
*t
, const char *fmt
, ...)
289 if (vasprintf(&t
->header
, fmt
, ap
) < 0 || t
->header
== NULL
)
295 tlist_count(struct tlist
*tl
)
297 unsigned int count
= 0;
300 ASN1_TAILQ_FOREACH(q
, &tl
->template, members
) {
307 tlist_add(struct tlist
*tl
)
309 ASN1_TAILQ_INSERT_TAIL(&tlistmaster
, tl
, tmembers
);
313 tlist_print(struct tlist
*tl
)
317 FILE *f
= get_code_file();
319 fprintf(f
, "const struct asn1_template asn1_%s[] = {\n", tl
->name
);
320 fprintf(f
, "/* 0 */ %s,\n", tl
->header
);
321 ASN1_TAILQ_FOREACH(q
, &tl
->template, members
) {
322 int last
= (ASN1_TAILQ_LAST(&tl
->template, templatehead
) == q
);
323 fprintf(f
, "/* %lu */ %s%s\n", (unsigned long)i
++, q
->line
, last
? "" : ",");
328 static struct tlist
*
329 tlist_find_by_name(const char *name
)
332 ASN1_TAILQ_FOREACH(ql
, &tlistmaster
, tmembers
) {
333 if (strcmp(ql
->name
, name
) == 0)
340 tlist_cmp_name(const char *tname
, const char *qname
)
342 struct tlist
*tl
= tlist_find_by_name(tname
);
343 struct tlist
*ql
= tlist_find_by_name(qname
);
348 return tlist_cmp(tl
, ql
);
352 tlist_cmp(const struct tlist
*tl
, const struct tlist
*ql
)
355 struct template *t
, *q
;
357 ret
= strcmp(tl
->header
, ql
->header
);
360 q
= ASN1_TAILQ_FIRST(&ql
->template);
361 ASN1_TAILQ_FOREACH(t
, &tl
->template, members
) {
362 if (q
== NULL
) return 1;
364 if (t
->ptr
== NULL
|| q
->ptr
== NULL
) {
365 ret
= strcmp(t
->line
, q
->line
);
368 ret
= strcmp(t
->tt
, q
->tt
);
371 ret
= strcmp(t
->offset
, q
->offset
);
374 if ((ret
= strcmp(t
->ptr
, q
->ptr
)) != 0 ||
375 (ret
= tlist_cmp_name(t
->ptr
, q
->ptr
)) != 0)
378 q
= ASN1_TAILQ_NEXT(q
, members
);
380 if (q
!= NULL
) return -1;
386 tlist_find_dup(const struct tlist
*tl
)
390 ASN1_TAILQ_FOREACH(ql
, &tlistmaster
, tmembers
) {
391 if (tlist_cmp(ql
, tl
) == 0) {
404 static struct template *
405 add_line(struct templatehead
*t
, const char *fmt
, ...)
407 struct template *q
= calloc(1, sizeof(*q
));
410 if (vasprintf(&q
->line
, fmt
, ap
) < 0 || q
->line
== NULL
)
413 ASN1_TAILQ_INSERT_TAIL(t
, q
, members
);
418 add_line_pointer(struct templatehead
*t
,
429 if (vasprintf(&tt
, ttfmt
, ap
) < 0 || tt
== NULL
)
433 q
= add_line(t
, "{ %s, %s, asn1_%s }", tt
, offset
, ptr
);
435 q
->offset
= strdup(offset
);
436 q
->ptr
= strdup(ptr
);
440 use_extern(const Symbol
*s
)
448 is_struct(const Type
*t
, int isstruct
)
452 if (t
->type
== TType
)
454 if (t
->type
== TSequence
|| t
->type
== TSet
|| t
->type
== TChoice
)
457 return is_struct(t
->subtype
, isstruct
);
459 for (i
= 0; i
< sizeof(types
)/sizeof(types
[0]); i
++) {
460 if (t
->type
== types
[i
].type
) {
461 if (types
[i
].is_struct
== 0)
472 compact_tag(const Type
*t
)
474 while (t
->type
== TTag
)
480 template_members(struct templatehead
*temp
, const char *basetype
, const char *name
, const Type
*t
, int optional
, int implicit
, int isstruct
, int need_offset
)
482 char *poffset
= NULL
;
484 if (optional
&& t
->type
!= TTag
&& t
->type
!= TType
)
485 errx(1, "%s...%s is optional and not a (TTag or TType)", basetype
, name
);
487 poffset
= partial_offset(basetype
, name
, need_offset
, isstruct
);
491 if (use_extern(t
->symbol
)) {
492 add_line(temp
, "{ A1_OP_TYPE_EXTERN %s%s, %s, &asn1_extern_%s}",
493 optional
? "|A1_FLAG_OPTIONAL" : "",
494 implicit
? "|A1_FLAG_IMPLICIT" : "",
495 poffset
, t
->symbol
->gen_name
);
497 add_line_pointer(temp
, t
->symbol
->gen_name
, poffset
,
499 optional
? "|A1_FLAG_OPTIONAL" : "",
500 implicit
? "|A1_FLAG_IMPLICIT" : "");
509 else if (t
->range
== NULL
)
510 itype
= "HEIM_INTEGER";
511 else if (t
->range
->min
< INT_MIN
&& t
->range
->max
<= INT64_MAX
)
513 else if (t
->range
->min
>= 0 && t
->range
->max
> UINT_MAX
)
514 itype
= "UNSIGNED64";
515 else if (t
->range
->min
>= INT_MIN
&& t
->range
->max
<= INT_MAX
)
517 else if (t
->range
->min
>= 0 && t
->range
->max
<= UINT_MAX
)
520 errx(1, "%s: unsupported range %lld -> %lld",
521 name
, (long long)t
->range
->min
, (long long)t
->range
->max
);
523 add_line(temp
, "{ A1_PARSE_T(A1T_%s), %s, NULL }", itype
, poffset
);
527 add_line(temp
, "{ A1_PARSE_T(A1T_GENERAL_STRING), %s, NULL }", poffset
);
530 add_line(temp
, "{ A1_PARSE_T(A1T_TELETEX_STRING), %s, NULL }", poffset
);
532 case TPrintableString
:
533 add_line(temp
, "{ A1_PARSE_T(A1T_PRINTABLE_STRING), %s, NULL }", poffset
);
536 add_line(temp
, "{ A1_PARSE_T(A1T_OCTET_STRING), %s, NULL }", poffset
);
539 add_line(temp
, "{ A1_PARSE_T(A1T_IA5_STRING), %s, NULL }", poffset
);
542 add_line(temp
, "{ A1_PARSE_T(A1T_BMP_STRING), %s, NULL }", poffset
);
544 case TUniversalString
:
545 add_line(temp
, "{ A1_PARSE_T(A1T_UNIVERSAL_STRING), %s, NULL }", poffset
);
548 add_line(temp
, "{ A1_PARSE_T(A1T_VISIBLE_STRING), %s, NULL }", poffset
);
551 add_line(temp
, "{ A1_PARSE_T(A1T_UTF8_STRING), %s, NULL }", poffset
);
553 case TGeneralizedTime
:
554 add_line(temp
, "{ A1_PARSE_T(A1T_GENERALIZED_TIME), %s, NULL }", poffset
);
557 add_line(temp
, "{ A1_PARSE_T(A1T_UTC_TIME), %s, NULL }", poffset
);
560 add_line(temp
, "{ A1_PARSE_T(A1T_BOOLEAN), %s, NULL }", poffset
);
563 add_line(temp
, "{ A1_PARSE_T(A1T_OID), %s, NULL }", poffset
);
568 struct templatehead
template;
573 FILE *f
= get_code_file();
574 static unsigned long bmember_counter
= 0;
576 ASN1_TAILQ_INIT(&template);
578 if (ASN1_TAILQ_EMPTY(t
->members
)) {
579 add_line(temp
, "{ A1_PARSE_T(A1T_HEIM_BIT_STRING), %s, NULL }", poffset
);
583 if (asprintf(&bname
, "bmember_%s_%lu", name
? name
: "", bmember_counter
++) < 0 || bname
== NULL
)
587 ASN1_TAILQ_FOREACH(m
, t
->members
, members
) {
588 add_line(&template, "{ 0, %d, 0 } /* %s */", m
->val
, m
->gen_name
);
591 ASN1_TAILQ_FOREACH(q
, &template, members
) {
595 fprintf(f
, "static const struct asn1_template asn1_%s_%s[] = {\n", basetype
, bname
);
596 fprintf(f
, "/* 0 */ { 0%s, sizeof(%s), ((void *)%lu) },\n",
597 rfc1510_bitstring
? "|A1_HBF_RFC1510" : "",
598 basetype
, (unsigned long)count
);
600 ASN1_TAILQ_FOREACH(q
, &template, members
) {
601 int last
= (ASN1_TAILQ_LAST(&template, templatehead
) == q
);
602 fprintf(f
, "/* %lu */ %s%s\n", (unsigned long)i
++, q
->line
, last
? "" : ",");
606 add_line(temp
, "{ A1_OP_BMEMBER, %s, asn1_%s_%s }", poffset
, basetype
, bname
);
615 fprintf(get_code_file(), "/* tsequence: members isstruct: %d */\n", isstruct
);
617 ASN1_TAILQ_FOREACH(m
, t
->members
, members
) {
618 char *newbasename
= NULL
;
624 if (asprintf(&newbasename
, "%s_%s", basetype
, name
) < 0)
627 newbasename
= strdup(basetype
);
628 if (newbasename
== NULL
)
631 template_members(temp
, newbasename
, m
->gen_name
, m
->type
, m
->optional
, 0, isstruct
, 1);
639 char *tname
= NULL
, *elname
= NULL
;
640 const char *sename
, *dupname
;
641 int subtype_is_struct
= is_struct(t
->subtype
, isstruct
);
642 static unsigned long tag_counter
= 0;
643 int tagimplicit
= (t
->tag
.tagenv
== TE_IMPLICIT
);
644 struct type
*subtype
;
646 fprintf(get_code_file(), "/* template_members: %s %s %s */\n", basetype
, implicit
? "imp" : "exp", tagimplicit
? "imp" : "exp");
650 struct type
*type
= t
->subtype
;
654 if (type
->type
== TTag
) {
655 fprintf(get_code_file(), "/* template_members: imp skip tag */\n");
656 type
= type
->subtype
;
658 } else if(type
->type
== TType
&& type
->symbol
&& type
->symbol
->type
) {
659 /* XXX really, we should stop here and find a
660 * pointer to where this is encoded instead of
661 * generated an new structure and hope that the
662 * optimizer catch it later.
664 subtype_is_struct
= is_struct(type
, isstruct
);
665 fprintf(get_code_file(), "/* template_members: imp skip type %s isstruct: %d */\n",
666 type
->symbol
->name
, subtype_is_struct
);
667 type
= type
->symbol
->type
;
674 subtype
= t
->subtype
;
677 if (subtype_is_struct
)
680 sename
= symbol_name(basetype
, subtype
);
682 if (asprintf(&tname
, "tag_%s_%lu", name
? name
: "", tag_counter
++) < 0 || tname
== NULL
)
686 if (asprintf(&elname
, "%s_%s", basetype
, tname
) < 0 || elname
== NULL
)
689 generate_template_type(elname
, &dupname
, NULL
, sename
, name
,
690 subtype
, 0, subtype_is_struct
, 0);
692 add_line_pointer(temp
, dupname
, poffset
,
693 "A1_TAG_T(%s,%s,%s)%s%s",
694 classname(t
->tag
.tagclass
),
695 is_primitive_type(subtype
->type
) ? "PRIM" : "CONS",
696 valuename(t
->tag
.tagclass
, t
->tag
.tagvalue
),
697 optional
? "|A1_FLAG_OPTIONAL" : "",
698 tagimplicit
? "|A1_FLAG_IMPLICIT" : "");
707 const char *type
= NULL
, *tname
, *dupname
;
708 char *sename
= NULL
, *elname
= NULL
;
709 int subtype_is_struct
= is_struct(t
->subtype
, 0);
710 static unsigned long seof_counter
= 0;
712 if (name
&& subtype_is_struct
) {
713 tname
= "seofTstruct";
714 if (asprintf(&sename
, "%s_%s_val", basetype
, name
) < 0)
716 } else if (subtype_is_struct
) {
717 tname
= "seofTstruct";
718 if (asprintf(&sename
, "%s_val", symbol_name(basetype
, t
->subtype
)) < 0)
724 tname
= "seofTstruct";
725 sename
= strdup(symbol_name(basetype
, t
->subtype
));
730 if (t
->type
== TSetOf
) type
= "A1_OP_SETOF";
731 else if (t
->type
== TSequenceOf
) type
= "A1_OP_SEQOF";
734 if (asprintf(&elname
, "%s_%s_%lu", basetype
, tname
, seof_counter
++) < 0 || elname
== NULL
)
737 generate_template_type(elname
, &dupname
, NULL
, sename
, NULL
, t
->subtype
,
738 0, subtype_is_struct
, need_offset
);
740 add_line(temp
, "{ %s, %s, asn1_%s }", type
, poffset
, dupname
);
745 struct templatehead
template;
749 FILE *f
= get_code_file();
753 static unsigned long choice_counter
= 0;
755 ASN1_TAILQ_INIT(&template);
757 if (asprintf(&tname
, "asn1_choice_%s_%s%lu",
758 basetype
, name
? name
: "", choice_counter
++) < 0 || tname
== NULL
)
761 ASN1_TAILQ_FOREACH(m
, t
->members
, members
) {
764 char *newbasename
= NULL
;
765 int subtype_is_struct
;
772 subtype_is_struct
= is_struct(m
->type
, 0);
774 if (asprintf(&elname
, "%s_choice_%s", basetype
, m
->gen_name
) < 0 || elname
== NULL
)
777 if (subtype_is_struct
) {
778 if (asprintf(&newbasename
, "%s_%s", basetype
, m
->gen_name
) < 0)
781 newbasename
= strdup(basetype
);
783 if (newbasename
== NULL
)
787 generate_template_type(elname
, &dupname
, NULL
,
788 symbol_name(newbasename
, m
->type
),
789 NULL
, m
->type
, 0, subtype_is_struct
, 1);
791 add_line(&template, "{ %s, offsetof(%s%s, u.%s), asn1_%s }",
792 m
->label
, isstruct
? "struct " : "",
793 basetype
, m
->gen_name
,
802 if (asprintf(&e
, "offsetof(%s%s, u.asn1_ellipsis)", isstruct
? "struct " : "", basetype
) < 0 || e
== NULL
)
806 ASN1_TAILQ_FOREACH(q
, &template, members
) {
810 fprintf(f
, "static const struct asn1_template %s[] = {\n", tname
);
811 fprintf(f
, "/* 0 */ { %s, offsetof(%s%s, element), ((void *)%lu) },\n",
812 e
? e
: "0", isstruct
? "struct " : "", basetype
, (unsigned long)count
);
814 ASN1_TAILQ_FOREACH(q
, &template, members
) {
815 int last
= (ASN1_TAILQ_LAST(&template, templatehead
) == q
);
816 fprintf(f
, "/* %lu */ %s%s\n", (unsigned long)i
++, q
->line
, last
? "" : ",");
820 add_line(temp
, "{ A1_OP_CHOICE, %s, %s }", poffset
, tname
);
834 gen_extern_stubs(FILE *f
, const char *name
)
837 "static const struct asn1_type_func asn1_extern_%s = {\n"
838 "\t(asn1_type_encode)encode_%s,\n"
839 "\t(asn1_type_decode)decode_%s,\n"
840 "\t(asn1_type_length)length_%s,\n"
841 "\t(asn1_type_copy)copy_%s,\n"
842 "\t(asn1_type_release)free_%s,\n"
845 name
, name
, name
, name
,
850 gen_template_import(const Symbol
*s
)
852 FILE *f
= get_code_file();
854 if (template_flag
== 0)
857 gen_extern_stubs(f
, s
->gen_name
);
861 generate_template_type(const char *varname
,
862 const char **dupname
,
864 const char *basetype
,
867 int optional
, int isstruct
, int need_offset
)
871 int have_ellipsis
= 0;
874 tl
= tlist_new(varname
);
876 if (type
->type
== TTag
)
877 implicit
= (type
->tag
.tagenv
== TE_IMPLICIT
);
879 fprintf(get_code_file(), "extern const struct asn1_template asn1_%s[];\n", tl
->name
);
881 template_members(&tl
->template, basetype
, name
, type
, optional
, implicit
, isstruct
, need_offset
);
883 /* if its a sequence or set type, check if there is a ellipsis */
884 if (type
->type
== TSequence
|| type
->type
== TSet
) {
886 ASN1_TAILQ_FOREACH(m
, type
->members
, members
) {
892 if (ASN1_TAILQ_EMPTY(&tl
->template) && compact_tag(type
)->type
!= TNull
)
893 errx(1, "Tag %s...%s with no content ?", basetype
, name
? name
: "");
895 fprintf(get_code_file(), "/* generate_template_type: %s */\n", tl
->name
);
897 tlist_header(tl
, "{ 0%s%s, sizeof(%s%s), ((void *)%lu) }",
898 (symname
&& preserve_type(symname
)) ? "|A1_HF_PRESERVE" : "",
899 have_ellipsis
? "|A1_HF_ELLIPSIS" : "",
900 isstruct
? "struct " : "", basetype
, tlist_count(tl
));
902 dup
= tlist_find_dup(tl
);
905 if (strcmp(dup
, tl
->name
) == 0)
906 errx(1, "found dup of ourself: %s", dup
);
918 generate_template(const Symbol
*s
)
920 FILE *f
= get_code_file();
924 gen_extern_stubs(f
, s
->gen_name
);
928 generate_template_type(s
->gen_name
, &dupname
, s
->name
, s
->gen_name
, NULL
, s
->type
, 0, 0, 1);
933 "decode_%s(const unsigned char *p, size_t len, %s *data, size_t *size)\n"
935 " return _asn1_decode_top(asn1_%s, 0|%s, p, len, data, size);\n"
941 support_ber
? "A1_PF_ALLOW_BER" : "0");
946 "encode_%s(unsigned char *p, size_t len, const %s *data, size_t *size)\n"
948 " return _asn1_encode%s(asn1_%s, p, len, data, size);\n"
959 "length_%s(const %s *data)\n"
961 " return _asn1_length%s(asn1_%s, data);\n"
973 "free_%s(%s *data)\n"
975 " _asn1_free_top(asn1_%s, data);\n"
985 "copy_%s(const %s *from, %s *to)\n"
987 " return _asn1_copy_top(asn1_%s, from, to);\n"