aboutsummaryrefslogtreecommitdiff
path: root/lib/asn1/gen.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/asn1/gen.c')
-rw-r--r--lib/asn1/gen.c105
1 files changed, 60 insertions, 45 deletions
diff --git a/lib/asn1/gen.c b/lib/asn1/gen.c
index 2194b329ce1d..3773647c29d7 100644
--- a/lib/asn1/gen.c
+++ b/lib/asn1/gen.c
@@ -148,7 +148,7 @@ init_generate (const char *filename, const char *base)
fn = NULL;
/* template file */
- if (asprintf(&template, "%s-template.c", headerbase) < 0 || template == NULL)
+ if (asprintf(&template, "%s-template.x", headerbase) < 0 || template == NULL)
errx(1, "malloc");
fprintf (headerfile,
"/* Generated from %s */\n"
@@ -163,6 +163,15 @@ init_generate (const char *filename, const char *base)
fprintf (headerfile,
"#ifndef __asn1_common_definitions__\n"
"#define __asn1_common_definitions__\n\n");
+ fprintf (headerfile,
+ "#ifndef __HEIM_BASE_DATA__\n"
+ "#define __HEIM_BASE_DATA__ 1\n"
+ "struct heim_base_data {\n"
+ " size_t length;\n"
+ " void *data;\n"
+ "};\n"
+ "typedef struct heim_base_data heim_octet_string;\n"
+ "#endif\n\n");
fprintf (headerfile,
"typedef struct heim_integer {\n"
" size_t length;\n"
@@ -170,21 +179,16 @@ init_generate (const char *filename, const char *base)
" int negative;\n"
"} heim_integer;\n\n");
fprintf (headerfile,
- "typedef struct heim_octet_string {\n"
- " size_t length;\n"
- " void *data;\n"
- "} heim_octet_string;\n\n");
- fprintf (headerfile,
"typedef char *heim_general_string;\n\n"
);
fprintf (headerfile,
"typedef char *heim_utf8_string;\n\n"
);
fprintf (headerfile,
- "typedef struct heim_octet_string heim_printable_string;\n\n"
+ "typedef struct heim_base_data heim_printable_string;\n\n"
);
fprintf (headerfile,
- "typedef struct heim_octet_string heim_ia5_string;\n\n"
+ "typedef struct heim_base_data heim_ia5_string;\n\n"
);
fprintf (headerfile,
"typedef struct heim_bmp_string {\n"
@@ -210,8 +214,8 @@ init_generate (const char *filename, const char *base)
" 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");
+ "typedef struct heim_base_data heim_any;\n"
+ "typedef struct heim_base_data heim_any_set;\n\n");
fputs("#define ASN1_MALLOC_ENCODE(T, B, BL, S, L, R) \\\n"
" do { \\\n"
" (BL) = length_##T((S)); \\\n"
@@ -265,14 +269,14 @@ init_generate (const char *filename, const char *base)
"#include <string.h>\n"
"#include <errno.h>\n"
"#include <limits.h>\n"
- "#include <krb5-types.h>\n",
- filename);
+ "#include <%s>\n",
+ filename,
+ type_file_string);
fprintf (templatefile,
"#include <%s>\n"
"#include <%s>\n"
"#include <der.h>\n"
- "#include <der-private.h>\n"
"#include <asn1-template.h>\n",
header, privheader);
@@ -290,9 +294,10 @@ close_generate (void)
fclose (privheaderfile);
if (templatefile)
fclose (templatefile);
- if (logfile)
+ if (logfile) {
fprintf (logfile, "\n");
fclose (logfile);
+ }
}
void
@@ -303,7 +308,8 @@ gen_assign_defval(const char *var, struct value *val)
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);
+ fprintf(codefile, "%s = %lld;\n",
+ var, (long long)val->u.integervalue);
break;
case booleanvalue:
if(val->u.booleanvalue)
@@ -324,7 +330,8 @@ gen_compare_defval(const char *var, struct value *val)
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);
+ fprintf(codefile, "if(%s != %lld)\n",
+ var, (long long)val->u.integervalue);
break;
case booleanvalue:
if(val->u.booleanvalue)
@@ -350,7 +357,8 @@ generate_header_of_codefile(const char *name)
codefile = fopen (filename, "w");
if (codefile == NULL)
err (1, "fopen %s", filename);
- fprintf(logfile, "%s ", filename);
+ if (logfile)
+ fprintf(logfile, "%s ", filename);
free(filename);
filename = NULL;
fprintf (codefile,
@@ -363,19 +371,22 @@ generate_header_of_codefile(const char *name)
"#include <string.h>\n"
"#include <errno.h>\n"
"#include <limits.h>\n"
- "#include <krb5-types.h>\n",
- orig_filename);
+ "#include <%s>\n",
+ orig_filename,
+ type_file_string);
fprintf (codefile,
- "#include <%s>\n"
- "#include <%s>\n",
+ "#include \"%s\"\n"
+ "#include \"%s\"\n",
header, privheader);
fprintf (codefile,
"#include <asn1_err.h>\n"
"#include <der.h>\n"
- "#include <der-private.h>\n"
- "#include <asn1-template.h>\n"
- "#include <parse_units.h>\n\n");
+ "#include <asn1-template.h>\n\n");
+
+ if (parse_units_flag)
+ fprintf (codefile,
+ "#include <parse_units.h>\n\n");
}
@@ -397,8 +408,9 @@ generate_constant (const Symbol *s)
case booleanvalue:
break;
case integervalue:
- fprintf (headerfile, "enum { %s = %d };\n\n",
- s->gen_name, s->value->u.integervalue);
+ fprintf (headerfile, "enum { %s = %lld };\n\n",
+ s->gen_name,
+ (long long)s->value->u.integervalue);
break;
case nullvalue:
break;
@@ -406,7 +418,7 @@ generate_constant (const Symbol *s)
break;
case objectidentifiervalue: {
struct objid *o, **list;
- unsigned int i, len;
+ size_t i, len;
char *gen_upper;
if (!one_code_file)
@@ -433,16 +445,16 @@ generate_constant (const Symbol *s)
o->label ? o->label : "label-less", o->value);
}
- fprintf (codefile, "static unsigned oid_%s_variable_num[%d] = {",
- s->gen_name, len);
+ fprintf (codefile, "static unsigned oid_%s_variable_num[%lu] = {",
+ s->gen_name, (unsigned long)len);
for (i = len ; i > 0; i--) {
fprintf(codefile, "%d%s ", list[i - 1]->value, i > 1 ? "," : "");
}
fprintf(codefile, "};\n");
fprintf (codefile, "const heim_oid asn1_oid_%s = "
- "{ %d, oid_%s_variable_num };\n\n",
- s->gen_name, len, s->gen_name);
+ "{ %lu, oid_%s_variable_num };\n\n",
+ s->gen_name, (unsigned long)len, s->gen_name);
free(list);
@@ -540,8 +552,9 @@ define_asn1 (int level, Type *t)
if(t->members == NULL) {
fprintf (headerfile, "INTEGER");
if (t->range)
- fprintf (headerfile, " (%d..%d)",
- t->range->min, t->range->max);
+ fprintf (headerfile, " (%lld..%lld)",
+ (long long)t->range->min,
+ (long long)t->range->max);
} else {
Member *m;
fprintf (headerfile, "INTEGER {\n");
@@ -582,7 +595,7 @@ define_asn1 (int level, Type *t)
case TSet:
case TSequence: {
Member *m;
- int max_width = 0;
+ size_t max_width = 0;
if(t->type == TChoice)
fprintf(headerfile, "CHOICE {\n");
@@ -597,13 +610,13 @@ define_asn1 (int level, Type *t)
max_width += 3;
if(max_width < 16) max_width = 16;
ASN1_TAILQ_FOREACH(m, t->members, members) {
- int width = max_width;
+ size_t width = max_width;
space(level + 1);
if (m->ellipsis) {
fprintf (headerfile, "...");
} else {
width -= fprintf(headerfile, "%s", m->name);
- fprintf(headerfile, "%*s", width, "");
+ fprintf(headerfile, "%*s", (int)width, "");
define_asn1(level + 1, m->type);
if(m->optional)
fprintf(headerfile, " OPTIONAL");
@@ -723,15 +736,17 @@ define_type (int level, const char *name, const char *basename, Type *t, int typ
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) {
+ } else if (t->range->min < INT_MIN && t->range->max <= INT64_MAX) {
+ fprintf (headerfile, "int64_t %s;\n", name);
+ } else if (t->range->min >= 0 && t->range->max > UINT_MAX) {
+ fprintf (headerfile, "uint64_t %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) {
+ } else if (t->range->min >= 0 && t->range->max <= UINT_MAX) {
fprintf (headerfile, "unsigned int %s;\n", name);
} else
- errx(1, "%s: unsupported range %d -> %d",
- name, t->range->min, t->range->max);
+ errx(1, "%s: unsupported range %lld -> %lld",
+ name, (long long)t->range->min, (long long)t->range->max);
break;
case TBoolean:
space(level);
@@ -744,7 +759,7 @@ define_type (int level, const char *name, const char *basename, Type *t, int typ
case TBitString: {
Member *m;
Type i;
- struct range range = { 0, INT_MAX };
+ struct range range = { 0, UINT_MAX };
i.type = TInteger;
i.range = &range;
@@ -843,7 +858,7 @@ define_type (int level, const char *name, const char *basename, Type *t, int typ
case TSetOf:
case TSequenceOf: {
Type i;
- struct range range = { 0, INT_MAX };
+ struct range range = { 0, UINT_MAX };
getnewbasename(&newbasename, typedefp, basename, name);
@@ -888,7 +903,7 @@ define_type (int level, const char *name, const char *basename, Type *t, int typ
fprintf(headerfile, "heim_octet_string _save;\n");
}
space(level + 1);
- fprintf (headerfile, "enum {\n");
+ fprintf (headerfile, "enum %s_enum {\n", newbasename);
m = have_ellipsis(t);
if (m) {
space(level + 2);