diff options
author | Bjorn Sandell <biorn@cvs.openbsd.org> | 2005-10-16 18:56:36 +0000 |
---|---|---|
committer | Bjorn Sandell <biorn@cvs.openbsd.org> | 2005-10-16 18:56:36 +0000 |
commit | 9b65ff1ed6cf7a1e29a392de0ba9fe5d722eccef (patch) | |
tree | f82203bfbf633ffa333b45fecec06ff9cff005cf | |
parent | 14d3e879f4c504b87ea309e2ae1e198d1572aaa0 (diff) |
sync with heimdal 0.7
-rw-r--r-- | usr.bin/asn1_compile/gen.c | 82 | ||||
-rw-r--r-- | usr.bin/asn1_compile/gen_copy.c | 8 | ||||
-rw-r--r-- | usr.bin/asn1_compile/gen_decode.c | 29 | ||||
-rw-r--r-- | usr.bin/asn1_compile/gen_encode.c | 26 | ||||
-rw-r--r-- | usr.bin/asn1_compile/gen_free.c | 16 | ||||
-rw-r--r-- | usr.bin/asn1_compile/gen_glue.c | 14 | ||||
-rw-r--r-- | usr.bin/asn1_compile/gen_length.c | 15 | ||||
-rw-r--r-- | usr.bin/asn1_compile/getarg.c | 32 | ||||
-rw-r--r-- | usr.bin/asn1_compile/getarg.h | 27 | ||||
-rw-r--r-- | usr.bin/asn1_compile/hash.c | 6 | ||||
-rw-r--r-- | usr.bin/asn1_compile/lex.l | 74 | ||||
-rw-r--r-- | usr.bin/asn1_compile/main.c | 8 | ||||
-rw-r--r-- | usr.bin/asn1_compile/parse.y | 52 | ||||
-rw-r--r-- | usr.bin/asn1_compile/symbol.h | 24 |
14 files changed, 321 insertions, 92 deletions
diff --git a/usr.bin/asn1_compile/gen.c b/usr.bin/asn1_compile/gen.c index 929686bc838..6f43a9a1665 100644 --- a/usr.bin/asn1_compile/gen.c +++ b/usr.bin/asn1_compile/gen.c @@ -34,7 +34,7 @@ #include "gen_locl.h" /* -RCSID("$KTH: gen.c,v 1.50 2003/04/17 07:09:18 lha Exp $"); +RCSID("$KTH: gen.c,v 1.58 2005/03/31 00:08:58 lha Exp $"); */ FILE *headerfile, *codefile, *logfile; @@ -43,7 +43,7 @@ FILE *headerfile, *codefile, *logfile; static const char *orig_filename; static char *header; -static char *headerbase = STEM; +static char *headerbase; /* * list of all IMPORTs @@ -78,14 +78,16 @@ void init_generate (const char *filename, const char *base) { orig_filename = filename; - if(base) + if(base){ if((headerbase = strdup(base)) == NULL) - err(1, NULL); - + err(1, NULL); + }else{ + if((headerbase = strdup(STEM)) == NULL) + err(1, NULL); + } asprintf(&header, "%s.h", headerbase); if(header == NULL) - err(1, NULL); - + err(1, NULL); headerfile = fopen (header, "w"); if (headerfile == NULL) err (1, "open %s", header); @@ -106,18 +108,21 @@ init_generate (const char *filename, const char *base) "#ifndef __asn1_common_definitions__\n" "#define __asn1_common_definitions__\n\n"); fprintf (headerfile, - "typedef struct octet_string {\n" + "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 struct heim_oid {\n" " size_t length;\n" " unsigned *components;\n" - "} oid;\n\n"); + "} heim_oid;\n\n"); fputs("#define ASN1_MALLOC_ENCODE(T, B, BL, S, L, R) \\\n" " do { \\\n" " (BL) = length_##T((S)); \\\n" @@ -276,13 +281,25 @@ define_asn1 (int level, Type *t) fprintf (headerfile, "[APPLICATION %d] ", t->application); define_asn1 (level, t->subtype); break; + case TBoolean: + space(level); + fprintf (headerfile, "BOOLEAN"); + break; + case TUTF8String: + space(level); + fprintf (headerfile, "UTF8String"); + 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) { switch (t->type) { case TType: @@ -313,11 +330,11 @@ define_type (int level, char *name, Type *t, int typedefp) break; case TOctetString: space(level); - fprintf (headerfile, "octet_string %s;\n", name); + fprintf (headerfile, "heim_octet_string %s;\n", name); break; case TOID : space(level); - fprintf (headerfile, "oid %s;\n", name); + fprintf (headerfile, "heim_oid %s;\n", name); break; case TBitString: { Member *m; @@ -399,7 +416,19 @@ 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 TUTF8String: + space(level); + fprintf (headerfile, "heim_utf8_string %s;\n", name); + break; + case TBoolean: + space(level); + fprintf (headerfile, "int %s;\n", name); + break; + case TNull: + space(level); + fprintf (headerfile, "NULL %s;\n", name); break; case TApplication: define_type (level, name, t->subtype, FALSE); @@ -458,13 +487,20 @@ generate_type (const Symbol *s) "#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); + + if (s->stype == Stype && s->type->type == TChoice) { + fprintf(codefile, + "/* CHOICE */\n" + "int asn1_%s_dummy_holder = 1;\n", s->gen_name); + } else { + 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); + } fprintf(headerfile, "\n\n"); fclose(codefile); } diff --git a/usr.bin/asn1_compile/gen_copy.c b/usr.bin/asn1_compile/gen_copy.c index c52e5d8defc..bd311addac5 100644 --- a/usr.bin/asn1_compile/gen_copy.c +++ b/usr.bin/asn1_compile/gen_copy.c @@ -34,7 +34,7 @@ #include "gen_locl.h" /* -RCSID("$KTH: gen_copy.c,v 1.12 2001/09/25 13:39:26 assar Exp $"); +RCSID("$KTH: gen_copy.c,v 1.14 2003/10/03 00:27:36 lha Exp $"); */ static void @@ -57,6 +57,7 @@ copy_type (const char *from, const char *to, const Type *t) break; case TInteger: case TUInteger: + case TBoolean: case TEnumerated : fprintf(codefile, "*(%s) = *(%s);\n", to, from); break; @@ -127,6 +128,11 @@ copy_type (const char *from, const char *to, const Type *t) case TGeneralString: copy_primitive ("general_string", from, to); break; + case TUTF8String: + copy_primitive ("utf8string", from, to); + break; + case TNull: + break; case TApplication: copy_type (from, to, t->subtype); break; diff --git a/usr.bin/asn1_compile/gen_decode.c b/usr.bin/asn1_compile/gen_decode.c index 27881adc431..6032a974221 100644 --- a/usr.bin/asn1_compile/gen_decode.c +++ b/usr.bin/asn1_compile/gen_decode.c @@ -34,7 +34,7 @@ #include "gen_locl.h" /* -RCSID("$KTH: gen_decode.c,v 1.18 2002/08/09 15:37:34 joda Exp $"); +RCSID("$KTH: gen_decode.c,v 1.21 2005/05/29 14:23:01 lha Exp $"); */ static void @@ -90,7 +90,7 @@ decode_type (const char *name, const Type *t) int pos; fprintf (codefile, - "e = der_match_tag_and_length (p, len, UNIV, PRIM, UT_BitString," + "e = der_match_tag_and_length (p, len, ASN1_C_UNIV, PRIM, UT_BitString," "&reallen, &l);\n" "FORW;\n" "if(len < reallen)\n" @@ -124,7 +124,7 @@ decode_type (const char *name, const Type *t) break; fprintf (codefile, - "e = der_match_tag_and_length (p, len, UNIV, CONS, UT_Sequence," + "e = der_match_tag_and_length (p, len, ASN1_C_UNIV, CONS, UT_Sequence," "&reallen, &l);\n" "FORW;\n" "{\n" @@ -161,7 +161,7 @@ decode_type (const char *name, const Type *t) }else{ fprintf (codefile, "{\n" "size_t newlen, oldlen;\n\n" - "e = der_match_tag (p, len, CONTEXT, CONS, %d, &l);\n", + "e = der_match_tag (p, len, ASN1_C_CONTEXT, CONS, %d, &l);\n", m->val); fprintf (codefile, "if (e)\n"); @@ -221,7 +221,7 @@ decode_type (const char *name, const Type *t) char *n; fprintf (codefile, - "e = der_match_tag_and_length (p, len, UNIV, CONS, UT_Sequence," + "e = der_match_tag_and_length (p, len, ASN1_C_UNIV, CONS, UT_Sequence," "&reallen, &l);\n" "FORW;\n" "if(len < reallen)\n" @@ -255,9 +255,17 @@ decode_type (const char *name, const Type *t) case TGeneralString: decode_primitive ("general_string", name); break; + case TUTF8String: + decode_primitive ("utf8string", name); + break; + case TNull: + fprintf (codefile, + "e = decode_nulltype(p, len, &l);\n" + "FORW;\n"); + break; case TApplication: fprintf (codefile, - "e = der_match_tag_and_length (p, len, APPL, CONS, %d, " + "e = der_match_tag_and_length (p, len, ASN1_C_APPL, CONS, %d, " "&reallen, &l);\n" "FORW;\n" "{\n" @@ -275,6 +283,9 @@ decode_type (const char *name, const Type *t) "}\n"); break; + case TBoolean: + decode_primitive ("boolean", name); + break; default : abort (); } @@ -304,10 +315,14 @@ generate_type_decode (const Symbol *s) switch (s->type->type) { case TInteger: case TUInteger: + case TBoolean: case TOctetString: case TOID: case TGeneralizedTime: case TGeneralString: + case TUTF8String: + case TNull: + case TEnumerated: case TBitString: case TSequence: case TSequenceOf: @@ -357,7 +372,7 @@ generate_seq_type_decode (const Symbol *s) "int dce_fix;\n"); fprintf (codefile, - "e = der_match_tag(p, len, CONTEXT, CONS, tag, &l);\n" + "e = der_match_tag(p, len, ASN1_C_CONTEXT, CONS, tag, &l);\n" "if (e)\n" "return e;\n"); fprintf (codefile, diff --git a/usr.bin/asn1_compile/gen_encode.c b/usr.bin/asn1_compile/gen_encode.c index 8e27d5dba4a..fd60176b4da 100644 --- a/usr.bin/asn1_compile/gen_encode.c +++ b/usr.bin/asn1_compile/gen_encode.c @@ -34,7 +34,7 @@ #include "gen_locl.h" /* -RCSID("$KTH: gen_encode.c,v 1.12 2001/09/25 13:39:26 assar Exp $"); +RCSID("$KTH: gen_encode.c,v 1.15 2005/05/29 14:23:01 lha Exp $"); */ static void @@ -127,7 +127,7 @@ encode_type (const char *name, const Type *t) "len -= 2;\n" "ret += 2;\n" "}\n\n" - "e = der_put_length_and_tag (p, len, ret, UNIV, PRIM," + "e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, PRIM," "UT_BitString, &l);\n" "BACK;\n", rest); @@ -159,7 +159,7 @@ encode_type (const char *name, const Type *t) #endif encode_type (s, m->type); fprintf (codefile, - "e = der_put_length_and_tag (p, len, ret, CONTEXT, CONS, " + "e = der_put_length_and_tag (p, len, ret, ASN1_C_CONTEXT, CONS, " "%d, &l);\n" "BACK;\n", m->val); @@ -173,7 +173,7 @@ encode_type (const char *name, const Type *t) free (s); } fprintf (codefile, - "e = der_put_length_and_tag (p, len, ret, UNIV, CONS, UT_Sequence, &l);\n" + "e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);\n" "BACK;\n"); break; } @@ -196,7 +196,7 @@ encode_type (const char *name, const Type *t) "ret += oldret;\n" #endif "}\n" - "e = der_put_length_and_tag (p, len, ret, UNIV, CONS, UT_Sequence, &l);\n" + "e = der_put_length_and_tag (p, len, ret, ASN1_C_UNIV, CONS, UT_Sequence, &l);\n" "BACK;\n"); free (n); break; @@ -207,13 +207,24 @@ encode_type (const char *name, const Type *t) case TGeneralString: encode_primitive ("general_string", name); break; + case TUTF8String: + encode_primitive ("utf8string", name); + break; + case TNull: + fprintf (codefile, + "e = encode_nulltype(p, len, &l);\n" + "BACK;\n"); + break; case TApplication: encode_type (name, t->subtype); fprintf (codefile, - "e = der_put_length_and_tag (p, len, ret, APPL, CONS, %d, &l);\n" + "e = der_put_length_and_tag (p, len, ret, ASN1_C_APPL, CONS, %d, &l);\n" "BACK;\n", t->application); break; + case TBoolean: + encode_primitive ("boolean", name); + break; default: abort (); } @@ -239,9 +250,12 @@ generate_type_encode (const Symbol *s) switch (s->type->type) { case TInteger: case TUInteger: + case TBoolean: case TOctetString: case TGeneralizedTime: case TGeneralString: + case TUTF8String: + case TNull: case TBitString: case TEnumerated: case TOID: diff --git a/usr.bin/asn1_compile/gen_free.c b/usr.bin/asn1_compile/gen_free.c index 56612e6b9df..f47888680a1 100644 --- a/usr.bin/asn1_compile/gen_free.c +++ b/usr.bin/asn1_compile/gen_free.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997 - 2000 Kungliga Tekniska Högskolan + * Copyright (c) 1997 - 2003 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). * All rights reserved. * @@ -34,7 +34,7 @@ #include "gen_locl.h" /* -RCSID("$KTH: gen_free.c,v 1.9 2001/09/25 13:39:26 assar Exp $"); +RCSID("$KTH: gen_free.c,v 1.12 2003/10/03 00:28:08 lha Exp $"); */ static void @@ -55,6 +55,7 @@ free_type (const char *name, const Type *t) break; case TInteger: case TUInteger: + case TBoolean: case TEnumerated : break; case TOctetString: @@ -84,7 +85,8 @@ free_type (const char *name, const Type *t) if(m->optional) fprintf(codefile, "free(%s);\n" - "}\n",s); + "%s = NULL;\n" + "}\n", s, s); if (tag == -1) tag = m->val; free (s); @@ -102,7 +104,8 @@ free_type (const char *name, const Type *t) "}\n", name); fprintf(codefile, - "free((%s)->val);\n", name); + "free((%s)->val);\n" + "(%s)->val = NULL;\n", name, name); free(n); break; } @@ -111,6 +114,11 @@ free_type (const char *name, const Type *t) case TGeneralString: free_primitive ("general_string", name); break; + case TUTF8String: + free_primitive ("utf8string", name); + break; + case TNull: + break; case TApplication: free_type (name, t->subtype); break; diff --git a/usr.bin/asn1_compile/gen_glue.c b/usr.bin/asn1_compile/gen_glue.c index 84e964f27e8..cb83b3f23fd 100644 --- a/usr.bin/asn1_compile/gen_glue.c +++ b/usr.bin/asn1_compile/gen_glue.c @@ -34,7 +34,7 @@ #include "gen_locl.h" /* -RCSID("$KTH: gen_glue.c,v 1.7 1999/12/02 17:05:02 joda Exp $"); +RCSID("$KTH: gen_glue.c,v 1.8 2005/04/25 18:07:07 lha Exp $"); */ static void @@ -105,11 +105,11 @@ generate_units (const Symbol *s) int tag = -1; fprintf (headerfile, - "extern struct units %s_units[];", + "const struct units * asn1_%s_units(void);", s->gen_name); fprintf (codefile, - "struct units %s_units[] = {\n", + "static struct units %s_units[] = {\n", s->gen_name); if(t->members) @@ -124,6 +124,14 @@ generate_units (const Symbol *s) fprintf (codefile, "\t{NULL,\t0}\n" "};\n\n"); + + fprintf (codefile, + "const struct units * asn1_%s_units(void){\n" + "return %s_units;\n" + "}\n\n", + s->gen_name, s->gen_name); + + } void diff --git a/usr.bin/asn1_compile/gen_length.c b/usr.bin/asn1_compile/gen_length.c index 02cbefcc7b2..6016cc6c71e 100644 --- a/usr.bin/asn1_compile/gen_length.c +++ b/usr.bin/asn1_compile/gen_length.c @@ -34,7 +34,7 @@ #include "gen_locl.h" /* -RCSID("$KTH: gen_length.c,v 1.11 2001/09/25 13:39:26 assar Exp $"); +RCSID("$KTH: gen_length.c,v 1.14 2004/01/19 17:54:33 lha Exp $"); */ static void @@ -128,8 +128,12 @@ length_type (const char *name, const Type *t, const char *variable) variable, variable); fprintf (codefile, "for(i = (%s)->len - 1; i >= 0; --i){\n", name); + fprintf (codefile, "int oldret = %s;\n" + "%s = 0;\n", variable, variable); asprintf (&n, "&(%s)->val[i]", name); length_type(n, t->subtype, variable); + fprintf (codefile, "%s += oldret;\n", + variable); fprintf (codefile, "}\n"); fprintf (codefile, @@ -144,10 +148,19 @@ length_type (const char *name, const Type *t, const char *variable) case TGeneralString: length_primitive ("general_string", name, variable); break; + case TUTF8String: + length_primitive ("utf8string", name, variable); + break; + case TNull: + fprintf (codefile, "%s += length_nulltype();\n", variable); + break; case TApplication: length_type (name, t->subtype, variable); fprintf (codefile, "ret += 1 + length_len (ret);\n"); break; + case TBoolean: + length_primitive ("boolean", name, variable); + break; default : abort (); } diff --git a/usr.bin/asn1_compile/getarg.c b/usr.bin/asn1_compile/getarg.c index b7ebcf9ff0f..cb368ee88a6 100644 --- a/usr.bin/asn1_compile/getarg.c +++ b/usr.bin/asn1_compile/getarg.c @@ -33,13 +33,13 @@ #ifdef HAVE_CONFIG_H #include <config.h> -RCSID("$KTH: getarg.c,v 1.46 2002/08/20 16:23:07 joda Exp $"); +RCSID("$KTH: getarg.c,v 1.48 2005/04/12 11:28:43 lha Exp $"); #endif #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <err.h> +#include <errno.h> #include "getarg.h" #define ISFLAG(X) ((X).type == arg_flag || (X).type == arg_negative_flag) @@ -202,7 +202,7 @@ check_column(FILE *f, int col, int len, int columns) return col; } -void +void ROKEN_LIB_FUNCTION arg_printusage (struct getargs *args, size_t num_args, const char *progname, @@ -322,14 +322,22 @@ arg_printusage (struct getargs *args, } } -static void +static int add_string(getarg_strings *s, char *value) { - if ((s->strings = realloc(s->strings, (s->num_strings + 1) * - sizeof(*s->strings))) == NULL) - err(1, "realloc"); + char **strings; + + strings = realloc(s->strings, (s->num_strings + 1) * sizeof(*s->strings)); + if (strings == NULL) { + free(s->strings); + s->strings = NULL; + s->num_strings = 0; + return ENOMEM; + } + s->strings = strings; s->strings[s->num_strings] = value; s->num_strings++; + return 0; } static int @@ -407,8 +415,7 @@ arg_match_long(struct getargs *args, size_t num_args, } case arg_strings: { - add_string((getarg_strings*)current->value, goptarg + 1); - return 0; + return add_string((getarg_strings*)current->value, goptarg + 1); } case arg_flag: case arg_negative_flag: @@ -516,8 +523,7 @@ arg_match_short (struct getargs *args, size_t num_args, *(char**)args[k].value = goptarg; return 0; } else if(args[k].type == arg_strings) { - add_string((getarg_strings*)args[k].value, goptarg); - return 0; + return add_string((getarg_strings*)args[k].value, goptarg); } else if(args[k].type == arg_double) { double tmp; if(sscanf(goptarg, "%lf", &tmp) != 1) @@ -534,7 +540,7 @@ arg_match_short (struct getargs *args, size_t num_args, return 0; } -int +int ROKEN_LIB_FUNCTION getarg(struct getargs *args, size_t num_args, int argc, char **argv, int *goptind) { @@ -575,7 +581,7 @@ getarg(struct getargs *args, size_t num_args, return ret; } -void +void ROKEN_LIB_FUNCTION free_getarg_strings (getarg_strings *s) { free (s->strings); diff --git a/usr.bin/asn1_compile/getarg.h b/usr.bin/asn1_compile/getarg.h index 5224a1a4bee..ef3e92dd945 100644 --- a/usr.bin/asn1_compile/getarg.h +++ b/usr.bin/asn1_compile/getarg.h @@ -31,13 +31,21 @@ * SUCH DAMAGE. */ -/* $KTH: getarg.h,v 1.12 2002/04/18 08:50:08 joda Exp $ */ +/* $KTH: getarg.h,v 1.14 2005/04/13 05:52:27 lha Exp $ */ #ifndef __GETARG_H__ #define __GETARG_H__ #include <stddef.h> +#ifndef ROKEN_LIB_FUNCTION +#ifdef _WIN32 +#define ROKEN_LIB_FUNCTION _stdcall +#else +#define ROKEN_LIB_FUNCTION +#endif +#endif + struct getargs{ const char *long_name; char short_name; @@ -78,14 +86,17 @@ typedef struct getarg_collect_info { void *data; } getarg_collect_info; -int getarg(struct getargs *args, size_t num_args, - int argc, char **argv, int *goptind); +int ROKEN_LIB_FUNCTION +getarg(struct getargs *args, size_t num_args, + int argc, char **argv, int *goptind); -void arg_printusage (struct getargs *args, - size_t num_args, - const char *progname, - const char *extra_string); +void ROKEN_LIB_FUNCTION +arg_printusage (struct getargs *args, + size_t num_args, + const char *progname, + const char *extra_string); -void free_getarg_strings (getarg_strings *); +void ROKEN_LIB_FUNCTION +free_getarg_strings (getarg_strings *); #endif /* __GETARG_H__ */ diff --git a/usr.bin/asn1_compile/hash.c b/usr.bin/asn1_compile/hash.c index 8f954615e71..51d1fdb318c 100644 --- a/usr.bin/asn1_compile/hash.c +++ b/usr.bin/asn1_compile/hash.c @@ -38,7 +38,7 @@ #include "gen_locl.h" /* -RCSID("$KTH: hash.c,v 1.8 1999/12/02 17:05:02 joda Exp $"); +RCSID("$KTH: hash.c,v 1.9 2005/01/08 22:55:26 lha Exp $"); */ static Hashentry *_search(Hashtab * htab, /* The hash table */ @@ -60,7 +60,7 @@ hashtabnew(int sz, return NULL; } else { for (i = 0; i < sz; ++i) - htab->tab[i] = NULL; + htab->tab[i] = NULL; htab->cmp = cmp; htab->hash = hash; htab->sz = sz; @@ -185,7 +185,7 @@ hashcaseadd(const char *s) assert(s); for (i = 0; *s; ++s) - i += toupper(*s); + i += toupper((unsigned char)*s); return i; } diff --git a/usr.bin/asn1_compile/lex.l b/usr.bin/asn1_compile/lex.l index a21243ecf4a..59c4892a576 100644 --- a/usr.bin/asn1_compile/lex.l +++ b/usr.bin/asn1_compile/lex.l @@ -1,6 +1,6 @@ %{ /* - * Copyright (c) 1997 - 2001 Kungliga Tekniska Högskolan + * Copyright (c) 1997 - 2004 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). * All rights reserved. * @@ -32,7 +32,7 @@ * SUCH DAMAGE. */ -/* $KTH: lex.l,v 1.19 2001/09/25 23:28:03 assar Exp $ */ +/* $KTH: lex.l,v 1.24 2004/10/13 17:40:21 lha Exp $ */ #ifdef HAVE_CONFIG_H #include <config.h> @@ -56,35 +56,43 @@ static unsigned lineno = 1; #undef ECHO +static void handle_comment(int type); + %} %% INTEGER { return INTEGER; } +BOOLEAN { return BOOLEAN; } IMPORTS { return IMPORTS; } FROM { return FROM; } SEQUENCE { return SEQUENCE; } +CHOICE { return CHOICE; } OF { return OF; } OCTET { return OCTET; } STRING { return STRING; } GeneralizedTime { return GeneralizedTime; } GeneralString { return GeneralString; } +UTF8String { return UTF8String; } +NULL { return NULLTYPE; } BIT { return BIT; } APPLICATION { return APPLICATION; } OPTIONAL { return OPTIONAL; } BEGIN { return TBEGIN; } END { return END; } +DEFAULT { return DEFAULT; } DEFINITIONS { return DEFINITIONS; } ENUMERATED { return ENUMERATED; } EXTERNAL { return EXTERNAL; } OBJECT { return OBJECT; } IDENTIFIER { return IDENTIFIER; } -[,;{}()|] { return *yytext; } +[-,;{}()|\"] { return *yytext; } "[" { return *yytext; } "]" { return *yytext; } ::= { return EEQUAL; } ---[^\n]*\n { ++lineno; } --?(0x)?[0-9]+ { char *e, *y = yytext; +-- { handle_comment(0); } +\/\* { handle_comment(1); } +0x[0-9A-Fa-f]+|[0-9]+ { char *e, *y = yytext; yylval.constant = strtol((const char *)yytext, &e, 0); if(e == y) @@ -98,6 +106,7 @@ IDENTIFIER { return IDENTIFIER; } } [ \t] ; \n { ++lineno; } +\.\.\. { return DOTDOTDOT; } \.\. { return DOTDOT; } . { error_message("Ignoring char(%c)\n", *yytext); } %% @@ -120,3 +129,58 @@ error_message (const char *format, ...) vfprintf (stderr, format, args); va_end (args); } + +static void +handle_comment(int type) +{ + int c; + int start_lineno = lineno; + if(type == 0) { + int f = 0; + while((c = input()) != EOF) { + if(f && c == '-') + return; + if(c == '-') { + f = 1; + continue; + } + if(c == '\n') { + lineno++; + return; + } + f = 0; + } + } else { + int level = 1; + int seen_star = 0; + int seen_slash = 0; + while((c = input()) != EOF) { + if(c == '/') { + if(seen_star) { + if(--level == 0) + return; + seen_star = 0; + continue; + } + seen_slash = 1; + continue; + } + if(c == '*') { + if(seen_slash) { + level++; + seen_star = seen_slash = 0; + continue; + } + seen_star = 1; + continue; + } + seen_star = seen_slash = 0; + if(c == '\n') { + lineno++; + continue; + } + } + } + if(c == EOF) + error_message("unterminated comment, possibly started on line %d\n", start_lineno); +} diff --git a/usr.bin/asn1_compile/main.c b/usr.bin/asn1_compile/main.c index a000087ac28..16ea159fa96 100644 --- a/usr.bin/asn1_compile/main.c +++ b/usr.bin/asn1_compile/main.c @@ -35,7 +35,7 @@ #include <getarg.h> /* -RCSID("$KTH: main.c,v 1.11 2001/02/20 01:44:52 assar Exp $"); +RCSID("$KTH: main.c,v 1.12 2005/03/31 00:37:42 lha Exp $"); */ extern FILE *yyin; @@ -59,8 +59,8 @@ int main(int argc, char **argv) { int ret; - char *file; - char *name = NULL; + const char *file; + const char *name = NULL; int optind = 0; if(getarg(args, num_args, argc, argv, &optind)) @@ -71,7 +71,7 @@ main(int argc, char **argv) #if 0 print_version(NULL); #else - printf("asn1_compile from heimdal-0.6\n"); + printf("asn1_compile from heimdal-0.7\n"); #endif exit(0); } diff --git a/usr.bin/asn1_compile/parse.y b/usr.bin/asn1_compile/parse.y index 1d445cb22a3..7a4cb846bbb 100644 --- a/usr.bin/asn1_compile/parse.y +++ b/usr.bin/asn1_compile/parse.y @@ -31,7 +31,7 @@ * SUCH DAMAGE. */ -/* $KTH: parse.y,v 1.19 2001/09/27 16:21:47 assar Exp $ */ +/* $KTH: parse.y,v 1.23 2004/10/13 17:41:48 lha Exp $ */ %{ #ifdef HAVE_CONFIG_H @@ -45,7 +45,7 @@ #include "gen_locl.h" /* -RCSID("$KTH: parse.y,v 1.19 2001/09/27 16:21:47 assar Exp $"); +RCSID("$KTH: parse.y,v 1.23 2004/10/13 17:41:48 lha Exp $"); */ static Type *new_type (Typetype t); @@ -60,12 +60,15 @@ static void append (Member *l, Member *r); char *name; Type *type; Member *member; + char *defval; } -%token INTEGER SEQUENCE OF OCTET STRING GeneralizedTime GeneralString +%token INTEGER SEQUENCE CHOICE OF OCTET STRING GeneralizedTime GeneralString %token BIT APPLICATION OPTIONAL EEQUAL TBEGIN END DEFINITIONS ENUMERATED -%token EXTERNAL -%token DOTDOT +%token UTF8String NULLTYPE +%token EXTERNAL DEFAULT +%token DOTDOT DOTDOTDOT +%token BOOLEAN %token IMPORTS FROM %token OBJECT IDENTIFIER %token <name> IDENT @@ -73,7 +76,9 @@ static void append (Member *l, Member *r); %type <constant> constant optional2 %type <type> type -%type <member> memberdecls memberdecl bitdecls bitdecl +%type <member> memberdecls memberdecl memberdeclstart bitdecls bitdecl + +%type <defval> defvalue %start envelope @@ -147,6 +152,8 @@ type : INTEGER { $$ = new_type(TInteger); } } | OCTET STRING { $$ = new_type(TOctetString); } | GeneralString { $$ = new_type(TGeneralString); } + | UTF8String { $$ = new_type(TUTF8String); } + | NULLTYPE { $$ = new_type(TNull); } | GeneralizedTime { $$ = new_type(TGeneralizedTime); } | SEQUENCE OF type { @@ -158,6 +165,11 @@ type : INTEGER { $$ = new_type(TInteger); } $$ = new_type(TSequence); $$->members = $3; } + | CHOICE '{' memberdecls '}' + { + $$ = new_type(TChoice); + $$->members = $3; + } | BIT STRING '{' bitdecls '}' { $$ = new_type(TBitString); @@ -178,32 +190,51 @@ type : INTEGER { $$ = new_type(TInteger); } $$->subtype = $5; $$->application = $3; } + | BOOLEAN { $$ = new_type(TBoolean); } ; memberdecls : { $$ = NULL; } | memberdecl { $$ = $1; } + | memberdecls ',' DOTDOTDOT { $$ = $1; } | memberdecls ',' memberdecl { $$ = $1; append($$, $3); } ; -memberdecl : IDENT '[' constant ']' type optional2 +memberdeclstart : IDENT '[' constant ']' type { $$ = malloc(sizeof(*$$)); $$->name = $1; $$->gen_name = strdup($1); output_name ($$->gen_name); $$->val = $3; - $$->optional = $6; + $$->optional = 0; + $$->defval = NULL; $$->type = $5; $$->next = $$->prev = $$; } ; -optional2 : { $$ = 0; } - | OPTIONAL { $$ = 1; } + +memberdecl : memberdeclstart optional2 + { $1->optional = $2 ; $$ = $1; } + | memberdeclstart defvalue + { $1->defval = $2 ; $$ = $1; } + | memberdeclstart + { $$ = $1; } + ; + + +optional2 : OPTIONAL { $$ = 1; } + ; + +defvalue : DEFAULT constant + { asprintf(&$$, "%d", $2); } + | DEFAULT '"' IDENT '"' + { $$ = strdup ($3); } ; bitdecls : { $$ = NULL; } | bitdecl { $$ = $1; } + | bitdecls ',' DOTDOTDOT { $$ = $1; } | bitdecls ',' bitdecl { $$ = $1; append($$, $3); } ; @@ -221,6 +252,7 @@ bitdecl : IDENT '(' constant ')' ; constant : CONSTANT { $$ = $1; } + | '-' CONSTANT { $$ = -$2; } | IDENT { Symbol *s = addsym($1); if(s->stype != SConstant) diff --git a/usr.bin/asn1_compile/symbol.h b/usr.bin/asn1_compile/symbol.h index 9bc7e48603c..ceff7b23ad8 100644 --- a/usr.bin/asn1_compile/symbol.h +++ b/usr.bin/asn1_compile/symbol.h @@ -31,14 +31,29 @@ * SUCH DAMAGE. */ -/* $KTH: symbol.h,v 1.6 2001/09/25 13:39:27 assar Exp $ */ +/* $KTH: symbol.h,v 1.11 2003/10/03 00:28:29 lha Exp $ */ #ifndef _SYMBOL_H #define _SYMBOL_H -enum typetype { TInteger, TOctetString, TBitString, TSequence, TSequenceOf, - TGeneralizedTime, TGeneralString, TApplication, TType, - TUInteger, TEnumerated, TOID }; +enum typetype { + TApplication, + TBitString, + TBoolean, + TChoice, + TEnumerated, + TGeneralString, + TGeneralizedTime, + TInteger, + TNull, + TOID, + TOctetString, + TSequence, + TSequenceOf, + TType, + TUInteger, + TUTF8String +}; typedef enum typetype Typetype; @@ -51,6 +66,7 @@ struct member { int optional; struct type *type; struct member *next, *prev; + char *defval; }; typedef struct member Member; |