support for distinguished value integers
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8396 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -46,94 +46,103 @@ length_primitive (const char *typename,
|
||||
static void
|
||||
length_type (const char *name, const Type *t, const char *variable)
|
||||
{
|
||||
switch (t->type) {
|
||||
case TType:
|
||||
switch (t->type) {
|
||||
case TType:
|
||||
#if 0
|
||||
length_type (name, t->symbol->type);
|
||||
length_type (name, t->symbol->type);
|
||||
#endif
|
||||
fprintf (codefile, "%s += length_%s(%s);\n",
|
||||
variable, t->symbol->gen_name, name);
|
||||
break;
|
||||
case TInteger:
|
||||
length_primitive ("integer", name, variable);
|
||||
break;
|
||||
case TUInteger:
|
||||
length_primitive ("unsigned", name, variable);
|
||||
break;
|
||||
case TOctetString:
|
||||
length_primitive ("octet_string", name, variable);
|
||||
break;
|
||||
case TBitString: {
|
||||
/*
|
||||
* XXX - Hope this is correct
|
||||
* look at TBitString case in `encode_type'
|
||||
*/
|
||||
fprintf (codefile, "%s += 7;\n", variable);
|
||||
break;
|
||||
}
|
||||
case TSequence: {
|
||||
Member *m;
|
||||
int tag = -1;
|
||||
fprintf (codefile, "%s += length_%s(%s);\n",
|
||||
variable, t->symbol->gen_name, name);
|
||||
break;
|
||||
case TInteger:
|
||||
if(t->members == NULL)
|
||||
length_primitive ("integer", name, variable);
|
||||
else {
|
||||
char *s;
|
||||
asprintf(&s, "(const int*)%s", name);
|
||||
if(s == NULL)
|
||||
return ENOMEM;
|
||||
length_primitive ("integer", s, variable);
|
||||
free(s);
|
||||
}
|
||||
break;
|
||||
case TUInteger:
|
||||
length_primitive ("unsigned", name, variable);
|
||||
break;
|
||||
case TOctetString:
|
||||
length_primitive ("octet_string", name, variable);
|
||||
break;
|
||||
case TBitString: {
|
||||
/*
|
||||
* XXX - Hope this is correct
|
||||
* look at TBitString case in `encode_type'
|
||||
*/
|
||||
fprintf (codefile, "%s += 7;\n", variable);
|
||||
break;
|
||||
}
|
||||
case TSequence: {
|
||||
Member *m;
|
||||
int tag = -1;
|
||||
|
||||
if (t->members == NULL)
|
||||
break;
|
||||
if (t->members == NULL)
|
||||
break;
|
||||
|
||||
for (m = t->members; m && tag != m->val; m = m->next) {
|
||||
char *s;
|
||||
for (m = t->members; m && tag != m->val; m = m->next) {
|
||||
char *s;
|
||||
|
||||
asprintf (&s, "%s(%s)->%s",
|
||||
m->optional ? "" : "&", name, m->gen_name);
|
||||
if (m->optional)
|
||||
fprintf (codefile, "if(%s)", s);
|
||||
fprintf (codefile, "{\n"
|
||||
"int oldret = %s;\n"
|
||||
"%s = 0;\n", variable, variable);
|
||||
length_type (s, m->type, "ret");
|
||||
fprintf (codefile, "%s += 1 + length_len(%s) + oldret;\n",
|
||||
variable, variable);
|
||||
fprintf (codefile, "}\n");
|
||||
if (tag == -1)
|
||||
tag = m->val;
|
||||
free (s);
|
||||
}
|
||||
fprintf (codefile,
|
||||
"%s += 1 + length_len(%s);\n", variable, variable);
|
||||
break;
|
||||
}
|
||||
case TSequenceOf: {
|
||||
char *n;
|
||||
asprintf (&s, "%s(%s)->%s",
|
||||
m->optional ? "" : "&", name, m->gen_name);
|
||||
if (m->optional)
|
||||
fprintf (codefile, "if(%s)", s);
|
||||
fprintf (codefile, "{\n"
|
||||
"int oldret = %s;\n"
|
||||
"%s = 0;\n", variable, variable);
|
||||
length_type (s, m->type, "ret");
|
||||
fprintf (codefile, "%s += 1 + length_len(%s) + oldret;\n",
|
||||
variable, variable);
|
||||
fprintf (codefile, "}\n");
|
||||
if (tag == -1)
|
||||
tag = m->val;
|
||||
free (s);
|
||||
}
|
||||
fprintf (codefile,
|
||||
"%s += 1 + length_len(%s);\n", variable, variable);
|
||||
break;
|
||||
}
|
||||
case TSequenceOf: {
|
||||
char *n;
|
||||
|
||||
fprintf (codefile,
|
||||
"{\n"
|
||||
"int oldret = %s;\n"
|
||||
"int i;\n"
|
||||
"%s = 0;\n",
|
||||
variable, variable);
|
||||
fprintf (codefile,
|
||||
"{\n"
|
||||
"int oldret = %s;\n"
|
||||
"int i;\n"
|
||||
"%s = 0;\n",
|
||||
variable, variable);
|
||||
|
||||
fprintf (codefile, "for(i = (%s)->len - 1; i >= 0; --i){\n", name);
|
||||
asprintf (&n, "&(%s)->val[i]", name);
|
||||
length_type(n, t->subtype, variable);
|
||||
fprintf (codefile, "}\n");
|
||||
fprintf (codefile, "for(i = (%s)->len - 1; i >= 0; --i){\n", name);
|
||||
asprintf (&n, "&(%s)->val[i]", name);
|
||||
length_type(n, t->subtype, variable);
|
||||
fprintf (codefile, "}\n");
|
||||
|
||||
fprintf (codefile,
|
||||
"%s += 1 + length_len(%s) + oldret;\n"
|
||||
"}\n", variable, variable);
|
||||
free(n);
|
||||
break;
|
||||
}
|
||||
case TGeneralizedTime:
|
||||
length_primitive ("generalized_time", name, variable);
|
||||
break;
|
||||
case TGeneralString:
|
||||
length_primitive ("general_string", name, variable);
|
||||
break;
|
||||
case TApplication:
|
||||
length_type (name, t->subtype, variable);
|
||||
fprintf (codefile, "ret += 1 + length_len (ret);\n");
|
||||
break;
|
||||
default :
|
||||
abort ();
|
||||
}
|
||||
fprintf (codefile,
|
||||
"%s += 1 + length_len(%s) + oldret;\n"
|
||||
"}\n", variable, variable);
|
||||
free(n);
|
||||
break;
|
||||
}
|
||||
case TGeneralizedTime:
|
||||
length_primitive ("generalized_time", name, variable);
|
||||
break;
|
||||
case TGeneralString:
|
||||
length_primitive ("general_string", name, variable);
|
||||
break;
|
||||
case TApplication:
|
||||
length_type (name, t->subtype, variable);
|
||||
fprintf (codefile, "ret += 1 + length_len (ret);\n");
|
||||
break;
|
||||
default :
|
||||
abort ();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
Reference in New Issue
Block a user