diff options
author | nectar <nectar@FreeBSD.org> | 2002-02-19 15:46:56 +0000 |
---|---|---|
committer | nectar <nectar@FreeBSD.org> | 2002-02-19 15:46:56 +0000 |
commit | 69a91bec14ec3ad49d1c8a82c40a796755f9e4a3 (patch) | |
tree | 85ecf91fd00875cec4b93111d3a8ed9eec9cddfe /crypto/heimdal/lib/asn1/gen.c | |
parent | 8db4cdb3da4228a5d93635e43825e2e8a2f66db7 (diff) | |
download | FreeBSD-src-69a91bec14ec3ad49d1c8a82c40a796755f9e4a3.zip FreeBSD-src-69a91bec14ec3ad49d1c8a82c40a796755f9e4a3.tar.gz |
Import of Heimdal Kerberos from KTH repository circa 2002/02/17.
Diffstat (limited to 'crypto/heimdal/lib/asn1/gen.c')
-rw-r--r-- | crypto/heimdal/lib/asn1/gen.c | 93 |
1 files changed, 84 insertions, 9 deletions
diff --git a/crypto/heimdal/lib/asn1/gen.c b/crypto/heimdal/lib/asn1/gen.c index 54212d9..6f57ec0 100644 --- a/crypto/heimdal/lib/asn1/gen.c +++ b/crypto/heimdal/lib/asn1/gen.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997 - 2000 Kungliga Tekniska Högskolan + * Copyright (c) 1997 - 2001 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.44 2000/06/19 15:17:52 joda Exp $"); +RCSID("$Id: gen.c,v 1.47 2001/09/27 16:21:47 assar Exp $"); FILE *headerfile, *codefile, *logfile; @@ -43,6 +43,27 @@ static const char *orig_filename; static char header[1024]; static char headerbase[1024] = STEM; +/* + * list of all IMPORTs + */ + +struct import { + const char *module; + struct import *next; +}; + +static struct import *imports = NULL; + +void +add_import (const char *module) +{ + struct import *tmp = emalloc (sizeof(*tmp)); + + tmp->module = module; + tmp->next = imports; + imports = tmp; +} + const char * filename (void) { @@ -90,6 +111,11 @@ init_generate (const char *filename, const char *base) "typedef char *general_string;\n\n" #endif ); + fprintf (headerfile, + "typedef struct oid {\n" + " size_t length;\n" + " unsigned *components;\n" + "} oid;\n\n"); fprintf (headerfile, "#endif\n\n"); logfile = fopen(STEM "_files", "w"); if (logfile == NULL) @@ -140,12 +166,14 @@ define_asn1 (int level, Type *t) space(level); fprintf (headerfile, "OCTET STRING"); break; + case TOID : + space(level); + fprintf(headerfile, "OBJECT IDENTIFIER"); + break; case TBitString: { Member *m; - Type i; int tag = -1; - i.type = TInteger; space(level); fprintf (headerfile, "BIT STRING {\n"); for (m = t->members; m && m->val != tag; m = m->next) { @@ -160,6 +188,24 @@ define_asn1 (int level, Type *t) 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?"":","); + + } + space(level); + fprintf (headerfile, "}"); + break; + } case TSequence: { Member *m; int tag; @@ -251,6 +297,10 @@ define_type (int level, char *name, Type *t, int typedefp) space(level); fprintf (headerfile, "octet_string %s;\n", name); break; + case TOID : + space(level); + fprintf (headerfile, "oid %s;\n", name); + break; case TBitString: { Member *m; Type i; @@ -272,6 +322,23 @@ define_type (int level, char *name, Type *t, int typedefp) 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; + space(level + 1); + fprintf (headerfile, "%s = %d%s\n", m->gen_name, m->val, + m->next->val == tag ? "" : ","); + } + space(level); + fprintf (headerfile, "} %s;\n\n", name); + break; + } case TSequence: { Member *m; int tag = -1; @@ -342,6 +409,7 @@ 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); @@ -353,16 +421,23 @@ generate_type (const Symbol *s) fprintf (codefile, "/* Generated from %s */\n" "/* Do not edit */\n\n" - "#include \"libasn1.h\"\n\n" -#if 0 "#include <stdio.h>\n" "#include <stdlib.h>\n" "#include <time.h>\n" - "#include <" STEM ".h>\n\n" + "#include <errno.h>\n", + orig_filename); + + 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" -#endif - ,orig_filename); + "#include <parse_units.h>\n\n"); generate_type_header (s); generate_type_encode (s); generate_type_decode (s); |