summaryrefslogtreecommitdiffstats
path: root/crypto/heimdal/lib/asn1/gen.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/heimdal/lib/asn1/gen.c')
-rw-r--r--crypto/heimdal/lib/asn1/gen.c663
1 files changed, 500 insertions, 163 deletions
diff --git a/crypto/heimdal/lib/asn1/gen.c b/crypto/heimdal/lib/asn1/gen.c
index 8580360..499f8ea 100644
--- a/crypto/heimdal/lib/asn1/gen.c
+++ b/crypto/heimdal/lib/asn1/gen.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997 - 2002 Kungliga Tekniska Högskolan
+ * Copyright (c) 1997 - 2005 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
@@ -33,7 +33,7 @@
#include "gen_locl.h"
-RCSID("$Id: gen.c,v 1.50 2003/04/17 07:09:18 lha Exp $");
+RCSID("$Id: gen.c 22429 2008-01-13 10:25:50Z lha $");
FILE *headerfile, *codefile, *logfile;
@@ -41,7 +41,7 @@ FILE *headerfile, *codefile, *logfile;
static const char *orig_filename;
static char *header;
-static char *headerbase = STEM;
+static const char *headerbase = STEM;
/*
* list of all IMPORTs
@@ -62,10 +62,12 @@ add_import (const char *module)
tmp->module = module;
tmp->next = imports;
imports = tmp;
+
+ fprintf (headerfile, "#include <%s_asn1.h>\n", module);
}
const char *
-filename (void)
+get_filename (void)
{
return orig_filename;
}
@@ -73,10 +75,17 @@ filename (void)
void
init_generate (const char *filename, const char *base)
{
+ char *fn;
+
orig_filename = filename;
- if(base)
- asprintf(&headerbase, "%s", base);
+ if (base != NULL) {
+ headerbase = strdup(base);
+ if (headerbase == NULL)
+ errx(1, "strdup");
+ }
asprintf(&header, "%s.h", headerbase);
+ if (header == NULL)
+ errx(1, "malloc");
headerfile = fopen (header, "w");
if (headerfile == NULL)
err (1, "open %s", header);
@@ -90,25 +99,58 @@ init_generate (const char *filename, const char *base)
fprintf (headerfile,
"#include <stddef.h>\n"
"#include <time.h>\n\n");
-#ifndef HAVE_TIMEGM
- fprintf (headerfile, "time_t timegm (struct tm*);\n\n");
-#endif
fprintf (headerfile,
"#ifndef __asn1_common_definitions__\n"
"#define __asn1_common_definitions__\n\n");
fprintf (headerfile,
- "typedef struct octet_string {\n"
+ "typedef struct heim_integer {\n"
+ " size_t length;\n"
+ " void *data;\n"
+ " int negative;\n"
+ "} heim_integer;\n\n");
+ fprintf (headerfile,
+ "typedef struct heim_octet_string {\n"
" size_t length;\n"
" void *data;\n"
- "} octet_string;\n\n");
+ "} heim_octet_string;\n\n");
+ fprintf (headerfile,
+ "typedef char *heim_general_string;\n\n"
+ );
fprintf (headerfile,
- "typedef char *general_string;\n\n"
+ "typedef char *heim_utf8_string;\n\n"
);
fprintf (headerfile,
- "typedef struct oid {\n"
+ "typedef char *heim_printable_string;\n\n"
+ );
+ fprintf (headerfile,
+ "typedef char *heim_ia5_string;\n\n"
+ );
+ fprintf (headerfile,
+ "typedef struct heim_bmp_string {\n"
+ " size_t length;\n"
+ " uint16_t *data;\n"
+ "} heim_bmp_string;\n\n");
+ fprintf (headerfile,
+ "typedef struct heim_universal_string {\n"
+ " size_t length;\n"
+ " uint32_t *data;\n"
+ "} heim_universal_string;\n\n");
+ fprintf (headerfile,
+ "typedef char *heim_visible_string;\n\n"
+ );
+ fprintf (headerfile,
+ "typedef struct heim_oid {\n"
" size_t length;\n"
" unsigned *components;\n"
- "} oid;\n\n");
+ "} heim_oid;\n\n");
+ fprintf (headerfile,
+ "typedef struct heim_bit_string {\n"
+ " size_t length;\n"
+ " void *data;\n"
+ "} heim_bit_string;\n\n");
+ fprintf (headerfile,
+ "typedef struct heim_octet_string heim_any;\n"
+ "typedef struct heim_octet_string heim_any_set;\n\n");
fputs("#define ASN1_MALLOC_ENCODE(T, B, BL, S, L, R) \\\n"
" do { \\\n"
" (BL) = length_##T((S)); \\\n"
@@ -125,10 +167,14 @@ init_generate (const char *filename, const char *base)
" } \\\n"
" } while (0)\n\n",
headerfile);
+ fprintf (headerfile, "struct units;\n\n");
fprintf (headerfile, "#endif\n\n");
- logfile = fopen(STEM "_files", "w");
+ asprintf(&fn, "%s_files", base);
+ if (fn == NULL)
+ errx(1, "malloc");
+ logfile = fopen(fn, "w");
if (logfile == NULL)
- err (1, "open " STEM "_files");
+ err (1, "open %s", fn);
}
void
@@ -142,10 +188,160 @@ close_generate (void)
}
void
+gen_assign_defval(const char *var, struct value *val)
+{
+ switch(val->type) {
+ case stringvalue:
+ fprintf(codefile, "if((%s = strdup(\"%s\")) == NULL)\nreturn ENOMEM;\n", var, val->u.stringvalue);
+ break;
+ case integervalue:
+ fprintf(codefile, "%s = %d;\n", var, val->u.integervalue);
+ break;
+ case booleanvalue:
+ if(val->u.booleanvalue)
+ fprintf(codefile, "%s = TRUE;\n", var);
+ else
+ fprintf(codefile, "%s = FALSE;\n", var);
+ break;
+ default:
+ abort();
+ }
+}
+
+void
+gen_compare_defval(const char *var, struct value *val)
+{
+ switch(val->type) {
+ case stringvalue:
+ fprintf(codefile, "if(strcmp(%s, \"%s\") != 0)\n", var, val->u.stringvalue);
+ break;
+ case integervalue:
+ fprintf(codefile, "if(%s != %d)\n", var, val->u.integervalue);
+ break;
+ case booleanvalue:
+ if(val->u.booleanvalue)
+ fprintf(codefile, "if(!%s)\n", var);
+ else
+ fprintf(codefile, "if(%s)\n", var);
+ break;
+ default:
+ abort();
+ }
+}
+
+static void
+generate_header_of_codefile(const char *name)
+{
+ char *filename;
+
+ if (codefile != NULL)
+ abort();
+
+ asprintf (&filename, "%s_%s.x", STEM, name);
+ if (filename == NULL)
+ errx(1, "malloc");
+ codefile = fopen (filename, "w");
+ if (codefile == NULL)
+ err (1, "fopen %s", filename);
+ fprintf(logfile, "%s ", filename);
+ free(filename);
+ fprintf (codefile,
+ "/* Generated from %s */\n"
+ "/* Do not edit */\n\n"
+ "#include <stdio.h>\n"
+ "#include <stdlib.h>\n"
+ "#include <time.h>\n"
+ "#include <string.h>\n"
+ "#include <errno.h>\n"
+ "#include <limits.h>\n"
+ "#include <krb5-types.h>\n",
+ orig_filename);
+
+ fprintf (codefile,
+ "#include <%s.h>\n",
+ headerbase);
+ fprintf (codefile,
+ "#include <asn1_err.h>\n"
+ "#include <der.h>\n"
+ "#include <parse_units.h>\n\n");
+
+}
+
+static void
+close_codefile(void)
+{
+ if (codefile == NULL)
+ abort();
+
+ fclose(codefile);
+ codefile = NULL;
+}
+
+
+void
generate_constant (const Symbol *s)
{
- fprintf (headerfile, "enum { %s = %d };\n\n",
- s->gen_name, s->constant);
+ switch(s->value->type) {
+ case booleanvalue:
+ break;
+ case integervalue:
+ fprintf (headerfile, "enum { %s = %d };\n\n",
+ s->gen_name, s->value->u.integervalue);
+ break;
+ case nullvalue:
+ break;
+ case stringvalue:
+ break;
+ case objectidentifiervalue: {
+ struct objid *o, **list;
+ int i, len;
+
+ generate_header_of_codefile(s->gen_name);
+
+ len = 0;
+ for (o = s->value->u.objectidentifiervalue; o != NULL; o = o->next)
+ len++;
+ list = emalloc(sizeof(*list) * len);
+
+ i = 0;
+ for (o = s->value->u.objectidentifiervalue; o != NULL; o = o->next)
+ list[i++] = o;
+
+ fprintf (headerfile, "/* OBJECT IDENTIFIER %s ::= { ", s->name);
+ for (i = len - 1 ; i >= 0; i--) {
+ o = list[i];
+ fprintf(headerfile, "%s(%d) ",
+ o->label ? o->label : "label-less", o->value);
+ }
+
+ fprintf (headerfile, "} */\n");
+ fprintf (headerfile, "const heim_oid *oid_%s(void);\n\n",
+ s->gen_name);
+
+ fprintf (codefile, "static unsigned oid_%s_variable_num[%d] = {",
+ s->gen_name, len);
+ for (i = len - 1 ; i >= 0; i--) {
+ fprintf(codefile, "%d%s ", list[i]->value, i > 0 ? "," : "");
+ }
+ fprintf(codefile, "};\n");
+
+ fprintf (codefile, "static const heim_oid oid_%s_variable = "
+ "{ %d, oid_%s_variable_num };\n\n",
+ s->gen_name, len, s->gen_name);
+
+ fprintf (codefile, "const heim_oid *oid_%s(void)\n"
+ "{\n"
+ "return &oid_%s_variable;\n"
+ "}\n\n",
+ s->gen_name, s->gen_name);
+
+ close_codefile();
+
+ break;
+ }
+ default:
+ abort();
+ }
}
static void
@@ -155,93 +351,108 @@ space(int level)
fprintf(headerfile, " ");
}
+static const char *
+last_member_p(struct member *m)
+{
+ struct member *n = ASN1_TAILQ_NEXT(m, members);
+ if (n == NULL)
+ return "";
+ if (n->ellipsis && ASN1_TAILQ_NEXT(n, members) == NULL)
+ return "";
+ return ",";
+}
+
+static struct member *
+have_ellipsis(Type *t)
+{
+ struct member *m;
+ ASN1_TAILQ_FOREACH(m, t->members, members) {
+ if (m->ellipsis)
+ return m;
+ }
+ return NULL;
+}
+
static void
define_asn1 (int level, Type *t)
{
switch (t->type) {
case TType:
- space(level);
fprintf (headerfile, "%s", t->symbol->name);
break;
case TInteger:
- space(level);
- fprintf (headerfile, "INTEGER");
+ if(t->members == NULL) {
+ fprintf (headerfile, "INTEGER");
+ if (t->range)
+ fprintf (headerfile, " (%d..%d)",
+ t->range->min, t->range->max);
+ } else {
+ Member *m;
+ fprintf (headerfile, "INTEGER {\n");
+ ASN1_TAILQ_FOREACH(m, t->members, members) {
+ space (level + 1);
+ fprintf(headerfile, "%s(%d)%s\n", m->gen_name, m->val,
+ last_member_p(m));
+ }
+ space(level);
+ fprintf (headerfile, "}");
+ }
break;
- case TUInteger:
- space(level);
- fprintf (headerfile, "UNSIGNED INTEGER");
+ case TBoolean:
+ fprintf (headerfile, "BOOLEAN");
break;
case TOctetString:
- space(level);
fprintf (headerfile, "OCTET STRING");
break;
- case TOID :
- space(level);
- fprintf(headerfile, "OBJECT IDENTIFIER");
- break;
+ case TEnumerated :
case TBitString: {
Member *m;
- int tag = -1;
space(level);
- fprintf (headerfile, "BIT STRING {\n");
- for (m = t->members; m && m->val != tag; m = m->next) {
- if (tag == -1)
- tag = m->val;
+ if(t->type == TBitString)
+ fprintf (headerfile, "BIT STRING {\n");
+ else
+ fprintf (headerfile, "ENUMERATED {\n");
+ ASN1_TAILQ_FOREACH(m, t->members, members) {
space(level + 1);
fprintf (headerfile, "%s(%d)%s\n", m->name, m->val,
- m->next->val == tag?"":",");
-
- }
- space(level);
- fprintf (headerfile, "}");
- break;
- }
- case TEnumerated : {
- Member *m;
- int tag = -1;
-
- space(level);
- fprintf (headerfile, "ENUMERATED {\n");
- for (m = t->members; m && m->val != tag; m = m->next) {
- if (tag == -1)
- tag = m->val;
- space(level + 1);
- fprintf (headerfile, "%s(%d)%s\n", m->name, m->val,
- m->next->val == tag?"":",");
-
+ last_member_p(m));
}
space(level);
fprintf (headerfile, "}");
break;
}
+ case TChoice:
+ case TSet:
case TSequence: {
Member *m;
- int tag;
int max_width = 0;
- space(level);
- fprintf (headerfile, "SEQUENCE {\n");
- for (m = t->members, tag = -1; m && m->val != tag; m = m->next) {
- if (tag == -1)
- tag = m->val;
- if(strlen(m->name) + (m->val > 9) > max_width)
- max_width = strlen(m->name) + (m->val > 9);
+ if(t->type == TChoice)
+ fprintf(headerfile, "CHOICE {\n");
+ else if(t->type == TSet)
+ fprintf(headerfile, "SET {\n");
+ else
+ fprintf(headerfile, "SEQUENCE {\n");
+ ASN1_TAILQ_FOREACH(m, t->members, members) {
+ if(strlen(m->name) > max_width)
+ max_width = strlen(m->name);
}
- max_width += 3 + 2;
+ max_width += 3;
if(max_width < 16) max_width = 16;
- for (m = t->members, tag = -1 ; m && m->val != tag; m = m->next) {
- int width;
- if (tag == -1)
- tag = m->val;
+ ASN1_TAILQ_FOREACH(m, t->members, members) {
+ int width = max_width;
space(level + 1);
- fprintf(headerfile, "%s[%d]", m->name, m->val);
- width = max_width - strlen(m->name) - 3 - (m->val > 9) - 2;
- fprintf(headerfile, "%*s", width, "");
- define_asn1(level + 1, m->type);
- if(m->optional)
- fprintf(headerfile, " OPTIONAL");
- if(m->next->val != tag)
+ if (m->ellipsis) {
+ fprintf (headerfile, "...");
+ } else {
+ width -= fprintf(headerfile, "%s", m->name);
+ fprintf(headerfile, "%*s", width, "");
+ define_asn1(level + 1, m->type);
+ if(m->optional)
+ fprintf(headerfile, " OPTIONAL");
+ }
+ if(last_member_p(m))
fprintf (headerfile, ",");
fprintf (headerfile, "\n");
}
@@ -249,31 +460,74 @@ define_asn1 (int level, Type *t)
fprintf (headerfile, "}");
break;
}
- case TSequenceOf: {
- space(level);
+ case TSequenceOf:
fprintf (headerfile, "SEQUENCE OF ");
define_asn1 (0, t->subtype);
break;
- }
+ case TSetOf:
+ fprintf (headerfile, "SET OF ");
+ define_asn1 (0, t->subtype);
+ break;
case TGeneralizedTime:
- space(level);
fprintf (headerfile, "GeneralizedTime");
break;
case TGeneralString:
- space(level);
fprintf (headerfile, "GeneralString");
break;
- case TApplication:
- fprintf (headerfile, "[APPLICATION %d] ", t->application);
+ case TTag: {
+ const char *classnames[] = { "UNIVERSAL ", "APPLICATION ",
+ "" /* CONTEXT */, "PRIVATE " };
+ if(t->tag.tagclass != ASN1_C_UNIV)
+ fprintf (headerfile, "[%s%d] ",
+ classnames[t->tag.tagclass],
+ t->tag.tagvalue);
+ if(t->tag.tagenv == TE_IMPLICIT)
+ fprintf (headerfile, "IMPLICIT ");
define_asn1 (level, t->subtype);
break;
+ }
+ case TUTCTime:
+ fprintf (headerfile, "UTCTime");
+ break;
+ case TUTF8String:
+ space(level);
+ fprintf (headerfile, "UTF8String");
+ break;
+ case TPrintableString:
+ space(level);
+ fprintf (headerfile, "PrintableString");
+ break;
+ case TIA5String:
+ space(level);
+ fprintf (headerfile, "IA5String");
+ break;
+ case TBMPString:
+ space(level);
+ fprintf (headerfile, "BMPString");
+ break;
+ case TUniversalString:
+ space(level);
+ fprintf (headerfile, "UniversalString");
+ break;
+ case TVisibleString:
+ space(level);
+ fprintf (headerfile, "VisibleString");
+ break;
+ case TOID :
+ space(level);
+ fprintf(headerfile, "OBJECT IDENTIFIER");
+ break;
+ case TNull:
+ space(level);
+ fprintf (headerfile, "NULL");
+ break;
default:
abort ();
}
}
static void
-define_type (int level, char *name, Type *t, int typedefp)
+define_type (int level, const char *name, Type *t, int typedefp, int preservep)
{
switch (t->type) {
case TType:
@@ -282,104 +536,123 @@ define_type (int level, char *name, Type *t, int typedefp)
break;
case TInteger:
space(level);
- if(t->members == NULL) {
- fprintf (headerfile, "int %s;\n", name);
- } else {
+ if(t->members) {
Member *m;
- int tag = -1;
fprintf (headerfile, "enum %s {\n", typedefp ? name : "");
- for (m = t->members; m && m->val != tag; m = m->next) {
- if(tag == -1)
- tag = m->val;
+ ASN1_TAILQ_FOREACH(m, t->members, members) {
space (level + 1);
fprintf(headerfile, "%s = %d%s\n", m->gen_name, m->val,
- m->next->val == tag ? "" : ",");
+ last_member_p(m));
}
fprintf (headerfile, "} %s;\n", name);
- }
+ } else if (t->range == NULL) {
+ fprintf (headerfile, "heim_integer %s;\n", name);
+ } else if (t->range->min == INT_MIN && t->range->max == INT_MAX) {
+ fprintf (headerfile, "int %s;\n", name);
+ } else if (t->range->min == 0 && t->range->max == UINT_MAX) {
+ fprintf (headerfile, "unsigned int %s;\n", name);
+ } else if (t->range->min == 0 && t->range->max == INT_MAX) {
+ fprintf (headerfile, "unsigned int %s;\n", name);
+ } else
+ errx(1, "%s: unsupported range %d -> %d",
+ name, t->range->min, t->range->max);
break;
- case TUInteger:
+ case TBoolean:
space(level);
- fprintf (headerfile, "unsigned int %s;\n", name);
+ fprintf (headerfile, "int %s;\n", name);
break;
case TOctetString:
space(level);
- fprintf (headerfile, "octet_string %s;\n", name);
- break;
- case TOID :
- space(level);
- fprintf (headerfile, "oid %s;\n", name);
+ fprintf (headerfile, "heim_octet_string %s;\n", name);
break;
case TBitString: {
Member *m;
Type i;
- int tag = -1;
+ struct range range = { 0, INT_MAX };
+
+ i.type = TInteger;
+ i.range = &range;
+ i.members = NULL;
+ i.constraint = NULL;
- i.type = TUInteger;
space(level);
- fprintf (headerfile, "struct %s {\n", typedefp ? name : "");
- for (m = t->members; m && m->val != tag; m = m->next) {
- char *n;
-
- asprintf (&n, "%s:1", m->gen_name);
- define_type (level + 1, n, &i, FALSE);
- free (n);
- if (tag == -1)
- tag = m->val;
+ if(ASN1_TAILQ_EMPTY(t->members))
+ fprintf (headerfile, "heim_bit_string %s;\n", name);
+ else {
+ fprintf (headerfile, "struct %s {\n", typedefp ? name : "");
+ ASN1_TAILQ_FOREACH(m, t->members, members) {
+ char *n;
+
+ asprintf (&n, "%s:1", m->gen_name);
+ if (n == NULL)
+ errx(1, "malloc");
+ define_type (level + 1, n, &i, FALSE, FALSE);
+ free (n);
+ }
+ space(level);
+ fprintf (headerfile, "} %s;\n\n", name);
}
- space(level);
- fprintf (headerfile, "} %s;\n\n", name);
break;
}
case TEnumerated: {
Member *m;
- int tag = -1;
space(level);
fprintf (headerfile, "enum %s {\n", typedefp ? name : "");
- for (m = t->members; m && m->val != tag; m = m->next) {
- if (tag == -1)
- tag = m->val;
+ ASN1_TAILQ_FOREACH(m, t->members, members) {
space(level + 1);
- fprintf (headerfile, "%s = %d%s\n", m->gen_name, m->val,
- m->next->val == tag ? "" : ",");
+ if (m->ellipsis)
+ fprintf (headerfile, "/* ... */\n");
+ else
+ fprintf (headerfile, "%s = %d%s\n", m->gen_name, m->val,
+ last_member_p(m));
}
space(level);
fprintf (headerfile, "} %s;\n\n", name);
break;
}
+ case TSet:
case TSequence: {
Member *m;
- int tag = -1;
space(level);
fprintf (headerfile, "struct %s {\n", typedefp ? name : "");
- for (m = t->members; m && m->val != tag; m = m->next) {
- if (m->optional) {
+ if (t->type == TSequence && preservep) {
+ space(level + 1);
+ fprintf(headerfile, "heim_octet_string _save;\n");
+ }
+ ASN1_TAILQ_FOREACH(m, t->members, members) {
+ if (m->ellipsis) {
+ ;
+ } else if (m->optional) {
char *n;
asprintf (&n, "*%s", m->gen_name);
- define_type (level + 1, n, m->type, FALSE);
+ if (n == NULL)
+ errx(1, "malloc");
+ define_type (level + 1, n, m->type, FALSE, FALSE);
free (n);
} else
- define_type (level + 1, m->gen_name, m->type, FALSE);
- if (tag == -1)
- tag = m->val;
+ define_type (level + 1, m->gen_name, m->type, FALSE, FALSE);
}
space(level);
fprintf (headerfile, "} %s;\n", name);
break;
}
+ case TSetOf:
case TSequenceOf: {
Type i;
+ struct range range = { 0, INT_MAX };
- i.type = TUInteger;
- i.application = 0;
+ i.type = TInteger;
+ i.range = &range;
+ i.members = NULL;
+ i.constraint = NULL;
space(level);
fprintf (headerfile, "struct %s {\n", typedefp ? name : "");
- define_type (level + 1, "len", &i, FALSE);
- define_type (level + 1, "*val", t->subtype, FALSE);
+ define_type (level + 1, "len", &i, FALSE, FALSE);
+ define_type (level + 1, "*val", t->subtype, FALSE, FALSE);
space(level);
fprintf (headerfile, "} %s;\n", name);
break;
@@ -390,10 +663,99 @@ define_type (int level, char *name, Type *t, int typedefp)
break;
case TGeneralString:
space(level);
- fprintf (headerfile, "general_string %s;\n", name);
+ fprintf (headerfile, "heim_general_string %s;\n", name);
break;
- case TApplication:
- define_type (level, name, t->subtype, FALSE);
+ case TTag:
+ define_type (level, name, t->subtype, typedefp, preservep);
+ break;
+ case TChoice: {
+ int first = 1;
+ Member *m;
+
+ space(level);
+ fprintf (headerfile, "struct %s {\n", typedefp ? name : "");
+ if (preservep) {
+ space(level + 1);
+ fprintf(headerfile, "heim_octet_string _save;\n");
+ }
+ space(level + 1);
+ fprintf (headerfile, "enum {\n");
+ m = have_ellipsis(t);
+ if (m) {
+ space(level + 2);
+ fprintf (headerfile, "%s = 0,\n", m->label);
+ first = 0;
+ }
+ ASN1_TAILQ_FOREACH(m, t->members, members) {
+ space(level + 2);
+ if (m->ellipsis)
+ fprintf (headerfile, "/* ... */\n");
+ else
+ fprintf (headerfile, "%s%s%s\n", m->label,
+ first ? " = 1" : "",
+ last_member_p(m));
+ first = 0;
+ }
+ space(level + 1);
+ fprintf (headerfile, "} element;\n");
+ space(level + 1);
+ fprintf (headerfile, "union {\n");
+ ASN1_TAILQ_FOREACH(m, t->members, members) {
+ if (m->ellipsis) {
+ space(level + 2);
+ fprintf(headerfile, "heim_octet_string asn1_ellipsis;\n");
+ } else if (m->optional) {
+ char *n;
+
+ asprintf (&n, "*%s", m->gen_name);
+ if (n == NULL)
+ errx(1, "malloc");
+ define_type (level + 2, n, m->type, FALSE, FALSE);
+ free (n);
+ } else
+ define_type (level + 2, m->gen_name, m->type, FALSE, FALSE);
+ }
+ space(level + 1);
+ fprintf (headerfile, "} u;\n");
+ space(level);
+ fprintf (headerfile, "} %s;\n", name);
+ break;
+ }
+ case TUTCTime:
+ space(level);
+ fprintf (headerfile, "time_t %s;\n", name);
+ break;
+ case TUTF8String:
+ space(level);
+ fprintf (headerfile, "heim_utf8_string %s;\n", name);
+ break;
+ case TPrintableString:
+ space(level);
+ fprintf (headerfile, "heim_printable_string %s;\n", name);
+ break;
+ case TIA5String:
+ space(level);
+ fprintf (headerfile, "heim_ia5_string %s;\n", name);
+ break;
+ case TBMPString:
+ space(level);
+ fprintf (headerfile, "heim_bmp_string %s;\n", name);
+ break;
+ case TUniversalString:
+ space(level);
+ fprintf (headerfile, "heim_universal_string %s;\n", name);
+ break;
+ case TVisibleString:
+ space(level);
+ fprintf (headerfile, "heim_visible_string %s;\n", name);
+ break;
+ case TOID :
+ space(level);
+ fprintf (headerfile, "heim_oid %s;\n", name);
+ break;
+ case TNull:
+ space(level);
+ fprintf (headerfile, "int %s;\n", name);
break;
default:
abort ();
@@ -403,13 +765,15 @@ define_type (int level, char *name, Type *t, int typedefp)
static void
generate_type_header (const Symbol *s)
{
+ int preservep = preserve_type(s->name) ? TRUE : FALSE;
+
fprintf (headerfile, "/*\n");
fprintf (headerfile, "%s ::= ", s->name);
define_asn1 (0, s->type);
fprintf (headerfile, "\n*/\n\n");
fprintf (headerfile, "typedef ");
- define_type (0, s->gen_name, s->type, TRUE);
+ define_type (0, s->gen_name, s->type, TRUE, preservep);
fprintf (headerfile, "\n");
}
@@ -418,43 +782,16 @@ generate_type_header (const Symbol *s)
void
generate_type (const Symbol *s)
{
- struct import *i;
- char *filename;
-
- asprintf (&filename, "%s_%s.x", STEM, s->gen_name);
- codefile = fopen (filename, "w");
- if (codefile == NULL)
- err (1, "fopen %s", filename);
- fprintf(logfile, "%s ", filename);
- free(filename);
- fprintf (codefile,
- "/* Generated from %s */\n"
- "/* Do not edit */\n\n"
- "#include <stdio.h>\n"
- "#include <stdlib.h>\n"
- "#include <time.h>\n"
- "#include <string.h>\n"
- "#include <errno.h>\n",
- orig_filename);
+ generate_header_of_codefile(s->gen_name);
- for (i = imports; i != NULL; i = i->next)
- fprintf (codefile,
- "#include <%s_asn1.h>\n",
- i->module);
- fprintf (codefile,
- "#include <%s.h>\n",
- headerbase);
- fprintf (codefile,
- "#include <asn1_err.h>\n"
- "#include <der.h>\n"
- "#include <parse_units.h>\n\n");
generate_type_header (s);
generate_type_encode (s);
generate_type_decode (s);
generate_type_free (s);
generate_type_length (s);
generate_type_copy (s);
- generate_glue (s);
+ generate_type_seq (s);
+ generate_glue (s->type, s->gen_name);
fprintf(headerfile, "\n\n");
- fclose(codefile);
+ close_codefile();
}
OpenPOWER on IntegriCloud