2004-06-03 03:38:44 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <asn1parser.h>
|
2004-08-18 04:50:37 +00:00
|
|
|
#include <asn1fix_export.h>
|
2004-08-18 05:41:05 +00:00
|
|
|
#include <asn1fix_crange.h>
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
#include "asn1print.h"
|
|
|
|
|
|
|
|
#define INDENT(fmt, args...) do { \
|
2005-02-15 07:06:05 +00:00
|
|
|
if(!(flags & APF_NOINDENT)) { \
|
|
|
|
int __i = level; \
|
|
|
|
while(__i--) printf(" "); \
|
|
|
|
} \
|
2004-06-03 03:38:44 +00:00
|
|
|
printf(fmt, ##args); \
|
|
|
|
} while(0)
|
|
|
|
|
2004-08-18 04:50:37 +00:00
|
|
|
static int asn1print_module(asn1p_t *asn, asn1p_module_t *mod, enum asn1print_flags flags);
|
2005-03-18 03:53:05 +00:00
|
|
|
static int asn1print_oid(int prior_len, asn1p_oid_t *oid, enum asn1print_flags flags);
|
2004-08-18 04:50:37 +00:00
|
|
|
static int asn1print_ref(asn1p_ref_t *ref, enum asn1print_flags flags);
|
|
|
|
static int asn1print_tag(asn1p_expr_t *tc, enum asn1print_flags flags);
|
|
|
|
static int asn1print_params(asn1p_paramlist_t *pl,enum asn1print_flags flags);
|
|
|
|
static int asn1print_with_syntax(asn1p_wsyntx_t *wx, enum asn1print_flags flags);
|
|
|
|
static int asn1print_constraint(asn1p_constraint_t *, enum asn1print_flags);
|
|
|
|
static int asn1print_value(asn1p_value_t *val, enum asn1print_flags flags);
|
2004-10-13 09:13:56 +00:00
|
|
|
static int asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1print_flags flags, int level);
|
|
|
|
static int asn1print_expr_dtd(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1print_flags flags, int level);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Print the contents of the parsed ASN tree.
|
|
|
|
*/
|
|
|
|
int
|
2004-08-18 04:50:37 +00:00
|
|
|
asn1print(asn1p_t *asn, enum asn1print_flags flags) {
|
2004-06-03 03:38:44 +00:00
|
|
|
asn1p_module_t *mod;
|
2004-09-30 06:38:21 +00:00
|
|
|
int modno = 0;
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
if(asn == NULL) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-10-13 09:13:56 +00:00
|
|
|
if(flags & APF_PRINT_XML_DTD)
|
|
|
|
printf("<!-- XML DTD generated by asn1c-" VERSION " -->\n\n");
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
TQ_FOR(mod, &(asn->modules), mod_next) {
|
2004-09-30 06:38:21 +00:00
|
|
|
if(modno++) printf("\n");
|
2004-08-18 04:50:37 +00:00
|
|
|
asn1print_module(asn, mod, flags);
|
2004-06-03 03:38:44 +00:00
|
|
|
}
|
|
|
|
|
2005-03-09 20:52:15 +00:00
|
|
|
if(flags & APF_PRINT_XML_DTD) {
|
|
|
|
/* Values for BOOLEAN */
|
|
|
|
printf("<!ELEMENT true EMPTY>\n");
|
|
|
|
printf("<!ELEMENT false EMPTY>\n");
|
|
|
|
}
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-08-18 04:50:37 +00:00
|
|
|
asn1print_module(asn1p_t *asn, asn1p_module_t *mod, enum asn1print_flags flags) {
|
2004-06-03 03:38:44 +00:00
|
|
|
asn1p_expr_t *tc;
|
|
|
|
|
2004-10-13 09:13:56 +00:00
|
|
|
if(flags & APF_PRINT_XML_DTD)
|
|
|
|
printf("<!-- ASN.1 module\n");
|
|
|
|
|
2005-08-12 10:09:10 +00:00
|
|
|
printf("%s ", mod->ModuleName);
|
2004-06-03 03:38:44 +00:00
|
|
|
if(mod->module_oid) {
|
2005-08-12 10:09:10 +00:00
|
|
|
asn1print_oid(strlen(mod->ModuleName), mod->module_oid, flags);
|
2004-06-03 03:38:44 +00:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2004-10-13 09:13:56 +00:00
|
|
|
if(flags & APF_PRINT_XML_DTD) {
|
|
|
|
if(mod->source_file_name
|
|
|
|
&& strcmp(mod->source_file_name, "-"))
|
|
|
|
printf("found in %s", mod->source_file_name);
|
|
|
|
printf(" -->\n\n");
|
|
|
|
|
|
|
|
TQ_FOR(tc, &(mod->members), next) {
|
|
|
|
asn1print_expr_dtd(asn, mod, tc, flags, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
printf("DEFINITIONS");
|
|
|
|
|
2004-08-18 04:50:37 +00:00
|
|
|
if(mod->module_flags & MSF_TAG_INSTRUCTIONS)
|
|
|
|
printf(" TAG INSTRUCTIONS");
|
|
|
|
if(mod->module_flags & MSF_XER_INSTRUCTIONS)
|
|
|
|
printf(" XER INSTRUCTIONS");
|
2004-06-03 03:38:44 +00:00
|
|
|
if(mod->module_flags & MSF_EXPLICIT_TAGS)
|
|
|
|
printf(" EXPLICIT TAGS");
|
|
|
|
if(mod->module_flags & MSF_IMPLICIT_TAGS)
|
|
|
|
printf(" IMPLICIT TAGS");
|
|
|
|
if(mod->module_flags & MSF_AUTOMATIC_TAGS)
|
|
|
|
printf(" AUTOMATIC TAGS");
|
|
|
|
if(mod->module_flags & MSF_EXTENSIBILITY_IMPLIED)
|
|
|
|
printf(" EXTENSIBILITY IMPLIED");
|
|
|
|
|
|
|
|
printf(" ::=\n");
|
|
|
|
printf("BEGIN\n\n");
|
|
|
|
|
|
|
|
TQ_FOR(tc, &(mod->members), next) {
|
2004-08-18 04:50:37 +00:00
|
|
|
asn1print_expr(asn, mod, tc, flags, 0);
|
2004-08-20 13:24:28 +00:00
|
|
|
if(flags & APF_DEBUG_CONSTRAINTS)
|
|
|
|
printf("\n");
|
|
|
|
else
|
|
|
|
printf("\n\n");
|
2004-06-03 03:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("END\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-03-18 03:53:05 +00:00
|
|
|
asn1print_oid(int prior_len, asn1p_oid_t *oid, enum asn1print_flags flags) {
|
|
|
|
size_t accum = prior_len;
|
2004-06-03 03:38:44 +00:00
|
|
|
int ac;
|
|
|
|
|
2004-06-05 08:17:50 +00:00
|
|
|
(void)flags; /* Unused argument */
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
printf("{");
|
|
|
|
for(ac = 0; ac < oid->arcs_count; ac++) {
|
2005-02-25 14:20:30 +00:00
|
|
|
const char *arcname = oid->arcs[ac].name;
|
|
|
|
|
2005-03-28 17:52:43 +00:00
|
|
|
if(accum + strlen(arcname ? arcname : "") > 72) {
|
2004-06-03 03:38:44 +00:00
|
|
|
printf("\n\t");
|
2005-03-28 17:52:43 +00:00
|
|
|
accum = 8;
|
2005-03-18 03:53:05 +00:00
|
|
|
} else {
|
|
|
|
accum += printf(" ");
|
2005-02-25 14:20:30 +00:00
|
|
|
}
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2005-02-25 14:20:30 +00:00
|
|
|
if(arcname) {
|
2005-03-18 03:53:05 +00:00
|
|
|
accum += printf("%s", arcname);
|
2004-09-05 10:38:50 +00:00
|
|
|
if(oid->arcs[ac].number >= 0) {
|
2005-03-18 03:53:05 +00:00
|
|
|
accum += printf("(%" PRIdASN ")",
|
|
|
|
oid->arcs[ac].number);
|
2004-09-05 10:38:50 +00:00
|
|
|
}
|
2004-06-03 03:38:44 +00:00
|
|
|
} else {
|
2005-03-18 03:53:05 +00:00
|
|
|
accum += printf("%" PRIdASN, oid->arcs[ac].number);
|
2004-06-03 03:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
printf(" }");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-08-18 04:50:37 +00:00
|
|
|
asn1print_ref(asn1p_ref_t *ref, enum asn1print_flags flags) {
|
2004-06-03 03:38:44 +00:00
|
|
|
int cc;
|
|
|
|
|
2004-06-05 08:17:50 +00:00
|
|
|
(void)flags; /* Unused argument */
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
for(cc = 0; cc < ref->comp_count; cc++) {
|
|
|
|
if(cc) printf(".");
|
|
|
|
printf("%s", ref->components[cc].name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-08-18 04:50:37 +00:00
|
|
|
asn1print_tag(asn1p_expr_t *tc, enum asn1print_flags flags) {
|
2004-06-03 03:38:44 +00:00
|
|
|
struct asn1p_type_tag_s *tag = &tc->tag;
|
|
|
|
|
2004-06-05 08:17:50 +00:00
|
|
|
(void)flags; /* Unused argument */
|
|
|
|
|
2005-06-02 05:21:53 +00:00
|
|
|
printf("%s", asn1p_tag2string(tag, 0));
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-08-18 04:50:37 +00:00
|
|
|
asn1print_value(asn1p_value_t *val, enum asn1print_flags flags) {
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
if(val == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch(val->type) {
|
|
|
|
case ATV_NOVALUE:
|
|
|
|
break;
|
2004-09-15 11:44:55 +00:00
|
|
|
case ATV_NULL:
|
|
|
|
printf("NULL");
|
|
|
|
return 0;
|
|
|
|
case ATV_REAL:
|
|
|
|
printf("%f", val->value.v_double);
|
|
|
|
return 0;
|
2004-06-03 03:38:44 +00:00
|
|
|
case ATV_INTEGER:
|
2004-09-24 21:01:43 +00:00
|
|
|
printf("%" PRIdASN, val->value.v_integer);
|
2004-06-03 03:38:44 +00:00
|
|
|
return 0;
|
|
|
|
case ATV_MIN: printf("MIN"); return 0;
|
|
|
|
case ATV_MAX: printf("MAX"); return 0;
|
|
|
|
case ATV_FALSE: printf("FALSE"); return 0;
|
|
|
|
case ATV_TRUE: printf("TRUE"); return 0;
|
2005-03-24 14:26:38 +00:00
|
|
|
case ATV_TUPLE:
|
|
|
|
printf("{%d, %d}",
|
|
|
|
(int)(val->value.v_integer >> 4),
|
|
|
|
(int)(val->value.v_integer & 0x0f));
|
|
|
|
return 0;
|
|
|
|
case ATV_QUADRUPLE:
|
|
|
|
printf("{%d, %d, %d, %d}",
|
|
|
|
(int)((val->value.v_integer >> 24) & 0xff),
|
|
|
|
(int)((val->value.v_integer >> 16) & 0xff),
|
|
|
|
(int)((val->value.v_integer >> 8) & 0xff),
|
|
|
|
(int)((val->value.v_integer >> 0) & 0xff)
|
|
|
|
);
|
|
|
|
return 0;
|
2004-06-03 03:38:44 +00:00
|
|
|
case ATV_STRING:
|
|
|
|
{
|
2005-06-15 18:41:50 +00:00
|
|
|
char *p = (char *)val->value.string.buf;
|
2004-06-03 03:38:44 +00:00
|
|
|
putchar('"');
|
|
|
|
if(strchr(p, '"')) {
|
|
|
|
/* Mask quotes */
|
|
|
|
for(; *p; p++) {
|
|
|
|
if(*p == '"')
|
|
|
|
putchar(*p);
|
|
|
|
putchar(*p);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fputs(p, stdout);
|
|
|
|
}
|
|
|
|
putchar('"');
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
case ATV_UNPARSED:
|
2005-06-15 18:41:50 +00:00
|
|
|
fputs((char *)val->value.string.buf, stdout);
|
2004-06-03 03:38:44 +00:00
|
|
|
return 0;
|
|
|
|
case ATV_BITVECTOR:
|
|
|
|
{
|
|
|
|
uint8_t *bitvector;
|
|
|
|
int bits;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
bitvector = val->value.binary_vector.bits;
|
|
|
|
bits = val->value.binary_vector.size_in_bits;
|
|
|
|
|
|
|
|
printf("'");
|
|
|
|
if(bits%8) {
|
|
|
|
for(i = 0; i < bits; i++) {
|
|
|
|
uint8_t uc;
|
|
|
|
uc = bitvector[i>>3];
|
|
|
|
putchar(((uc >> (7-(i%8)))&1)?'1':'0');
|
|
|
|
}
|
|
|
|
printf("'B");
|
|
|
|
} else {
|
|
|
|
char hextable[16] = "0123456789ABCDEF";
|
|
|
|
for(i = 0; i < (bits>>3); i++) {
|
|
|
|
putchar(hextable[bitvector[i] >> 4]);
|
|
|
|
putchar(hextable[bitvector[i] & 0x0f]);
|
|
|
|
}
|
|
|
|
printf("'H");
|
|
|
|
}
|
2005-02-24 21:07:35 +00:00
|
|
|
return 0;
|
2004-06-03 03:38:44 +00:00
|
|
|
}
|
2004-09-15 11:44:55 +00:00
|
|
|
case ATV_REFERENCED:
|
|
|
|
return asn1print_ref(val->value.reference, flags);
|
|
|
|
case ATV_CHOICE_IDENTIFIER:
|
|
|
|
printf("%s: ", val->value.choice_identifier.identifier);
|
|
|
|
return asn1print_value(val->value.choice_identifier.value, flags);
|
2004-06-03 03:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(val->type || !"Unknown");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-08-18 04:50:37 +00:00
|
|
|
asn1print_constraint(asn1p_constraint_t *ct, enum asn1print_flags flags) {
|
2004-06-03 03:38:44 +00:00
|
|
|
int symno = 0;
|
|
|
|
|
|
|
|
if(ct == 0) return 0;
|
|
|
|
|
|
|
|
if(ct->type == ACT_CA_SET)
|
|
|
|
printf("(");
|
|
|
|
|
|
|
|
switch(ct->type) {
|
2005-03-20 12:58:00 +00:00
|
|
|
case ACT_EL_TYPE:
|
|
|
|
asn1print_value(ct->value, flags);
|
|
|
|
break;
|
2004-06-03 03:38:44 +00:00
|
|
|
case ACT_EL_VALUE:
|
|
|
|
asn1print_value(ct->value, flags);
|
|
|
|
break;
|
|
|
|
case ACT_EL_RANGE:
|
|
|
|
case ACT_EL_LLRANGE:
|
|
|
|
case ACT_EL_RLRANGE:
|
|
|
|
case ACT_EL_ULRANGE:
|
|
|
|
asn1print_value(ct->range_start, flags);
|
|
|
|
switch(ct->type) {
|
|
|
|
case ACT_EL_RANGE: printf(".."); break;
|
|
|
|
case ACT_EL_LLRANGE: printf("<.."); break;
|
|
|
|
case ACT_EL_RLRANGE: printf("..<"); break;
|
|
|
|
case ACT_EL_ULRANGE: printf("<..<"); break;
|
|
|
|
default: printf("?..?"); break;
|
|
|
|
}
|
|
|
|
asn1print_value(ct->range_stop, flags);
|
|
|
|
break;
|
|
|
|
case ACT_EL_EXT:
|
|
|
|
printf("...");
|
|
|
|
break;
|
|
|
|
case ACT_CT_SIZE:
|
|
|
|
case ACT_CT_FROM:
|
|
|
|
switch(ct->type) {
|
2004-08-18 04:50:37 +00:00
|
|
|
case ACT_CT_SIZE: printf("SIZE("); break;
|
|
|
|
case ACT_CT_FROM: printf("FROM("); break;
|
2004-06-03 03:38:44 +00:00
|
|
|
default: printf("??? ("); break;
|
|
|
|
}
|
|
|
|
assert(ct->el_count != 0);
|
|
|
|
assert(ct->el_count == 1);
|
|
|
|
asn1print_constraint(ct->elements[0], flags);
|
|
|
|
printf(")");
|
|
|
|
break;
|
|
|
|
case ACT_CT_WCOMP:
|
2005-03-28 15:01:27 +00:00
|
|
|
assert(ct->el_count != 0);
|
|
|
|
assert(ct->el_count == 1);
|
|
|
|
printf("WITH COMPONENT (");
|
|
|
|
asn1print_constraint(ct->elements[0], flags);
|
|
|
|
printf(")");
|
2005-03-28 07:50:06 +00:00
|
|
|
break;
|
2005-03-28 15:01:27 +00:00
|
|
|
case ACT_CT_WCOMPS: {
|
|
|
|
unsigned int i;
|
|
|
|
printf("WITH COMPONENTS { ");
|
|
|
|
for(i = 0; i < ct->el_count; i++) {
|
|
|
|
asn1p_constraint_t *cel = ct->elements[i];
|
|
|
|
if(i) printf(", ");
|
|
|
|
fwrite(cel->value->value.string.buf,
|
|
|
|
1, cel->value->value.string.size,
|
|
|
|
stdout);
|
|
|
|
if(cel->el_count) {
|
|
|
|
assert(cel->el_count == 1);
|
|
|
|
printf(" ");
|
|
|
|
asn1print_constraint(cel->elements[0],
|
|
|
|
flags);
|
|
|
|
}
|
|
|
|
switch(cel->presence) {
|
|
|
|
case ACPRES_DEFAULT: break;
|
|
|
|
case ACPRES_PRESENT: printf(" PRESENT"); break;
|
|
|
|
case ACPRES_ABSENT: printf(" ABSENT"); break;
|
|
|
|
case ACPRES_OPTIONAL: printf(" OPTIONAL");break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf(" }");
|
|
|
|
}
|
2005-03-28 07:50:06 +00:00
|
|
|
break;
|
2005-03-20 14:28:32 +00:00
|
|
|
case ACT_CT_CTDBY:
|
|
|
|
printf("CONSTRAINED BY ");
|
|
|
|
assert(ct->value->type == ATV_UNPARSED);
|
|
|
|
fwrite(ct->value->value.string.buf,
|
|
|
|
1, ct->value->value.string.size, stdout);
|
2004-06-03 03:38:44 +00:00
|
|
|
break;
|
|
|
|
case ACT_CA_SET: symno++;
|
|
|
|
case ACT_CA_CRC: symno++;
|
|
|
|
case ACT_CA_CSV: symno++;
|
|
|
|
case ACT_CA_UNI: symno++;
|
|
|
|
case ACT_CA_INT: symno++;
|
|
|
|
case ACT_CA_EXC:
|
|
|
|
{
|
2004-08-18 04:50:37 +00:00
|
|
|
char *symtable[] = { " EXCEPT ", " ^ ", " | ", ",",
|
2004-06-03 03:38:44 +00:00
|
|
|
"", "(" };
|
2004-09-05 10:38:50 +00:00
|
|
|
unsigned int i;
|
2004-06-03 03:38:44 +00:00
|
|
|
for(i = 0; i < ct->el_count; i++) {
|
|
|
|
if(i) fputs(symtable[symno], stdout);
|
|
|
|
if(ct->type == ACT_CA_CRC) fputs("{", stdout);
|
2005-03-24 14:26:38 +00:00
|
|
|
asn1print_constraint(ct->elements[i], flags);
|
2004-06-03 03:38:44 +00:00
|
|
|
if(ct->type == ACT_CA_CRC) fputs("}", stdout);
|
|
|
|
if(i+1 < ct->el_count
|
|
|
|
&& ct->type == ACT_CA_SET)
|
|
|
|
fputs(")", stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2005-03-24 14:26:38 +00:00
|
|
|
case ACT_CA_AEX:
|
|
|
|
assert(ct->el_count == 1);
|
|
|
|
printf("ALL EXCEPT ");
|
|
|
|
asn1print_constraint(ct->elements[0], flags);
|
|
|
|
break;
|
2004-06-03 03:38:44 +00:00
|
|
|
case ACT_INVALID:
|
|
|
|
assert(ct->type != ACT_INVALID);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ct->type == ACT_CA_SET)
|
|
|
|
printf(")");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-08-18 04:50:37 +00:00
|
|
|
asn1print_params(asn1p_paramlist_t *pl, enum asn1print_flags flags) {
|
2004-06-03 03:38:44 +00:00
|
|
|
if(pl) {
|
|
|
|
int i;
|
|
|
|
printf("{");
|
|
|
|
for(i = 0; i < pl->params_count; i++) {
|
|
|
|
if(i) printf(", ");
|
|
|
|
if(pl->params[i].governor) {
|
|
|
|
asn1print_ref(pl->params[i].governor, flags);
|
|
|
|
printf(":");
|
|
|
|
}
|
|
|
|
printf("%s", pl->params[i].argument);
|
|
|
|
}
|
|
|
|
printf("}");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-08-18 04:50:37 +00:00
|
|
|
asn1print_with_syntax(asn1p_wsyntx_t *wx, enum asn1print_flags flags) {
|
2004-06-03 03:38:44 +00:00
|
|
|
if(wx) {
|
|
|
|
asn1p_wsyntx_chunk_t *wc;
|
|
|
|
printf(" WITH SYNTAX {");
|
|
|
|
TQ_FOR(wc, &(wx->chunks), next) {
|
|
|
|
if(wc->ref) {
|
|
|
|
asn1print_ref(wc->ref, flags);
|
|
|
|
} else {
|
|
|
|
fwrite(wc->buf, 1, wc->len, stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("}\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-08-18 04:50:37 +00:00
|
|
|
asn1print_crange_value(asn1cnst_edge_t *edge, int as_char) {
|
|
|
|
switch(edge->type) {
|
|
|
|
case ARE_MIN: printf("MIN"); break;
|
|
|
|
case ARE_MAX: printf("MAX"); break;
|
|
|
|
case ARE_VALUE:
|
|
|
|
if(as_char) {
|
|
|
|
printf("\"%c\"", (unsigned char)edge->value);
|
|
|
|
} else {
|
2004-09-24 21:01:43 +00:00
|
|
|
printf("%" PRIdASN, edge->value);
|
2004-08-18 04:50:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-08-25 02:00:03 +00:00
|
|
|
asn1print_constraint_explain_type(asn1p_expr_type_e expr_type, asn1p_constraint_t *ct, enum asn1p_constraint_type_e type, int strict_PER_visible) {
|
2004-08-18 04:50:37 +00:00
|
|
|
asn1cnst_range_t *range;
|
|
|
|
int as_char = (type==ACT_CT_FROM);
|
|
|
|
int i;
|
|
|
|
|
2004-08-25 02:00:03 +00:00
|
|
|
range = asn1constraint_compute_PER_range(expr_type, ct, type,
|
|
|
|
0, 0, strict_PER_visible);
|
2004-08-18 04:50:37 +00:00
|
|
|
if(!range) return -1;
|
|
|
|
|
2004-08-25 02:00:03 +00:00
|
|
|
if(range->incompatible
|
|
|
|
|| (strict_PER_visible && range->not_PER_visible)) {
|
|
|
|
asn1constraint_range_free(range);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-08-18 04:50:37 +00:00
|
|
|
switch(type) {
|
|
|
|
case ACT_CT_FROM: printf("(FROM("); break;
|
|
|
|
case ACT_CT_SIZE: printf("(SIZE("); break;
|
|
|
|
default: printf("("); break;
|
|
|
|
}
|
|
|
|
for(i = -1; i < range->el_count; i++) {
|
|
|
|
asn1cnst_range_t *r;
|
|
|
|
if(i == -1) {
|
|
|
|
if(range->el_count) continue;
|
|
|
|
r = range;
|
|
|
|
} else {
|
|
|
|
r = range->elements[i];
|
|
|
|
}
|
|
|
|
if(i > 0) {
|
|
|
|
printf(" | ");
|
|
|
|
}
|
|
|
|
asn1print_crange_value(&r->left, as_char);
|
|
|
|
if(r->left.type != r->right.type
|
|
|
|
|| r->left.value != r->right.value) {
|
|
|
|
printf("..");
|
|
|
|
asn1print_crange_value(&r->right, as_char);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(range->extensible)
|
|
|
|
printf(",...");
|
|
|
|
printf(type==ACT_EL_RANGE?")":"))");
|
|
|
|
|
|
|
|
if(range->empty_constraint)
|
|
|
|
printf(":Empty!");
|
|
|
|
|
|
|
|
asn1constraint_range_free(range);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
asn1print_constraint_explain(asn1p_expr_type_e expr_type,
|
2004-08-25 02:00:03 +00:00
|
|
|
asn1p_constraint_t *ct, int s_PV) {
|
2004-08-18 04:50:37 +00:00
|
|
|
|
2004-08-25 02:00:03 +00:00
|
|
|
asn1print_constraint_explain_type(expr_type, ct, ACT_EL_RANGE, s_PV);
|
2004-08-18 04:50:37 +00:00
|
|
|
printf(" ");
|
2004-08-25 02:00:03 +00:00
|
|
|
asn1print_constraint_explain_type(expr_type, ct, ACT_CT_SIZE, s_PV);
|
2004-08-18 04:50:37 +00:00
|
|
|
printf(" ");
|
2004-08-25 02:00:03 +00:00
|
|
|
asn1print_constraint_explain_type(expr_type, ct, ACT_CT_FROM, s_PV);
|
2004-08-18 04:50:37 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1print_flags flags, int level) {
|
2004-08-20 13:24:28 +00:00
|
|
|
int SEQ_OF = 0;
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2005-02-15 07:06:05 +00:00
|
|
|
if(flags & APF_LINE_COMMENTS && !(flags & APF_NOINDENT))
|
2004-10-13 09:13:56 +00:00
|
|
|
INDENT("-- #line %d\n", tc->_lineno);
|
2004-06-03 03:38:44 +00:00
|
|
|
if(tc->Identifier)
|
|
|
|
INDENT("%s", tc->Identifier);
|
|
|
|
|
|
|
|
if(tc->params) {
|
|
|
|
asn1print_params(tc->params, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tc->meta_type != AMT_VALUE
|
2004-08-25 02:27:47 +00:00
|
|
|
&& tc->meta_type != AMT_VALUESET
|
2004-06-03 03:38:44 +00:00
|
|
|
&& tc->expr_type != A1TC_EXTENSIBLE) {
|
|
|
|
if(level) {
|
2005-02-15 07:06:05 +00:00
|
|
|
if(tc->Identifier && !(flags & APF_NOINDENT))
|
2004-06-03 03:38:44 +00:00
|
|
|
printf("\t");
|
|
|
|
} else {
|
|
|
|
printf(" ::=");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tc->tag.tag_class) {
|
|
|
|
printf(" ");
|
|
|
|
asn1print_tag(tc, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(tc->expr_type) {
|
|
|
|
case A1TC_EXTENSIBLE:
|
|
|
|
if(tc->value) {
|
|
|
|
printf("!");
|
|
|
|
asn1print_value(tc->value, flags);
|
|
|
|
}
|
|
|
|
break;
|
2004-08-22 03:08:51 +00:00
|
|
|
case A1TC_COMPONENTS_OF:
|
|
|
|
SEQ_OF = 1; /* Equivalent to SET OF for printint purposes */
|
|
|
|
printf(" COMPONENTS OF");
|
|
|
|
break;
|
2005-02-15 07:06:05 +00:00
|
|
|
case A1TC_PARAMETRIZED:
|
|
|
|
flags |= APF_NOINDENT;
|
2004-06-03 03:38:44 +00:00
|
|
|
case A1TC_REFERENCE:
|
|
|
|
case A1TC_UNIVERVAL:
|
|
|
|
break;
|
|
|
|
case A1TC_CLASSDEF:
|
|
|
|
printf(" CLASS");
|
|
|
|
break;
|
|
|
|
case A1TC_CLASSFIELD:
|
|
|
|
/* Nothing to print here */
|
|
|
|
break;
|
2004-08-20 13:24:28 +00:00
|
|
|
case ASN_CONSTR_SET_OF:
|
|
|
|
case ASN_CONSTR_SEQUENCE_OF:
|
|
|
|
SEQ_OF = 1;
|
|
|
|
if(tc->expr_type == ASN_CONSTR_SET_OF)
|
|
|
|
printf(" SET");
|
|
|
|
else
|
|
|
|
printf(" SEQUENCE");
|
|
|
|
if(tc->constraints) {
|
|
|
|
printf(" ");
|
|
|
|
asn1print_constraint(tc->constraints, flags);
|
|
|
|
}
|
|
|
|
printf(" OF");
|
|
|
|
break;
|
2004-06-03 03:38:44 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
char *p = ASN_EXPR_TYPE2STR(tc->expr_type);
|
|
|
|
printf(" %s", p?p:"<unknown type!>");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-06-02 04:06:24 +00:00
|
|
|
/*
|
|
|
|
* Put the name of the referred type.
|
|
|
|
*/
|
2004-06-03 03:38:44 +00:00
|
|
|
if(tc->reference) {
|
2005-06-02 04:06:24 +00:00
|
|
|
printf(" ");
|
2004-06-03 03:38:44 +00:00
|
|
|
asn1print_ref(tc->reference, flags);
|
|
|
|
}
|
|
|
|
|
2004-08-25 02:27:47 +00:00
|
|
|
if(tc->meta_type == AMT_VALUESET)
|
|
|
|
printf(" ::=");
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
/*
|
|
|
|
* Display the descendants (children) of the current type.
|
|
|
|
*/
|
2004-08-25 02:27:47 +00:00
|
|
|
if(TQ_FIRST(&(tc->members))
|
|
|
|
|| (tc->expr_type & ASN_CONSTR_MASK)
|
|
|
|
|| tc->meta_type == AMT_VALUESET
|
|
|
|
|| tc->meta_type == AMT_OBJECT
|
|
|
|
|| tc->meta_type == AMT_OBJECTSET
|
|
|
|
) {
|
2004-06-03 03:38:44 +00:00
|
|
|
asn1p_expr_t *se; /* SubExpression */
|
2004-08-22 03:08:51 +00:00
|
|
|
int put_braces = !SEQ_OF; /* Don't need 'em, if SET OF... */
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2004-08-25 02:27:47 +00:00
|
|
|
if(put_braces) {
|
2005-02-15 07:06:05 +00:00
|
|
|
if(flags & APF_NOINDENT) {
|
|
|
|
printf("{");
|
|
|
|
if(!TQ_FIRST(&tc->members))
|
|
|
|
printf("}");
|
|
|
|
} else {
|
|
|
|
printf(" {");
|
|
|
|
if(TQ_FIRST(&tc->members))
|
|
|
|
printf("\n");
|
|
|
|
else
|
|
|
|
printf(" }");
|
|
|
|
}
|
2004-08-25 02:27:47 +00:00
|
|
|
}
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
TQ_FOR(se, &(tc->members), next) {
|
|
|
|
/*
|
2004-08-22 03:08:51 +00:00
|
|
|
* Print the expression as it were a stand-alone type.
|
2004-06-03 03:38:44 +00:00
|
|
|
*/
|
2004-10-13 09:13:56 +00:00
|
|
|
asn1print_expr(asn, mod, se, flags, level + 1);
|
2004-09-15 11:44:55 +00:00
|
|
|
if((se->marker.flags & EM_DEFAULT) == EM_DEFAULT) {
|
|
|
|
printf(" DEFAULT ");
|
|
|
|
asn1print_value(se->marker.default_value, flags);
|
|
|
|
} else if((se->marker.flags & EM_OPTIONAL)
|
|
|
|
== EM_OPTIONAL) {
|
2004-09-10 08:21:27 +00:00
|
|
|
printf(" OPTIONAL");
|
2004-09-15 11:44:55 +00:00
|
|
|
}
|
2004-06-03 03:38:44 +00:00
|
|
|
if(TQ_NEXT(se, next)) {
|
|
|
|
printf(",");
|
2005-02-15 07:06:05 +00:00
|
|
|
if(!(flags & APF_NOINDENT))
|
|
|
|
INDENT("\n");
|
2004-06-03 03:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-25 02:27:47 +00:00
|
|
|
if(put_braces && TQ_FIRST(&tc->members)) {
|
2005-02-15 07:06:05 +00:00
|
|
|
if(!(flags & APF_NOINDENT))
|
|
|
|
printf("\n");
|
2004-06-03 03:38:44 +00:00
|
|
|
INDENT("}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tc->with_syntax)
|
|
|
|
asn1print_with_syntax(tc->with_syntax, flags);
|
|
|
|
|
2004-08-20 13:24:28 +00:00
|
|
|
if(!SEQ_OF && tc->constraints) {
|
2004-06-03 03:38:44 +00:00
|
|
|
printf(" ");
|
|
|
|
asn1print_constraint(tc->constraints, flags);
|
|
|
|
}
|
2004-08-18 04:50:37 +00:00
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
if(tc->unique) {
|
|
|
|
printf(" UNIQUE");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tc->meta_type == AMT_VALUE
|
|
|
|
&& tc->expr_type != A1TC_EXTENSIBLE) {
|
2004-09-05 10:38:50 +00:00
|
|
|
if(tc->expr_type == A1TC_UNIVERVAL) {
|
2004-09-15 11:44:55 +00:00
|
|
|
if(tc->value) {
|
|
|
|
printf("(");
|
|
|
|
asn1print_value(tc->value, flags);
|
|
|
|
printf(")");
|
|
|
|
}
|
2004-09-05 10:38:50 +00:00
|
|
|
} else {
|
|
|
|
printf(" ::= ");
|
|
|
|
asn1print_value(tc->value, flags);
|
|
|
|
}
|
2004-06-03 03:38:44 +00:00
|
|
|
}
|
|
|
|
|
2004-08-22 03:08:51 +00:00
|
|
|
/*
|
2005-02-15 07:06:05 +00:00
|
|
|
* The following section exists entirely for debugging.
|
2004-08-22 03:08:51 +00:00
|
|
|
*/
|
2004-08-20 13:24:28 +00:00
|
|
|
if(flags & APF_DEBUG_CONSTRAINTS
|
|
|
|
&& tc->expr_type != A1TC_EXTENSIBLE) {
|
2004-08-18 04:50:37 +00:00
|
|
|
asn1p_expr_t *top_parent;
|
|
|
|
|
|
|
|
if(tc->combined_constraints) {
|
|
|
|
printf("\n-- Combined constraints: ");
|
|
|
|
asn1print_constraint(tc->combined_constraints, flags);
|
|
|
|
}
|
|
|
|
|
2004-09-22 16:05:13 +00:00
|
|
|
top_parent = asn1f_find_terminal_type_ex(asn, tc);
|
2004-08-18 04:50:37 +00:00
|
|
|
if(top_parent) {
|
2004-08-25 02:00:03 +00:00
|
|
|
printf("\n-- Practical constraints (%s): ",
|
|
|
|
top_parent->Identifier);
|
|
|
|
asn1print_constraint_explain(top_parent->expr_type,
|
|
|
|
tc->combined_constraints, 0);
|
2004-08-20 13:24:28 +00:00
|
|
|
printf("\n-- PER-visible constraints (%s): ",
|
|
|
|
top_parent->Identifier);
|
2004-08-18 04:50:37 +00:00
|
|
|
asn1print_constraint_explain(top_parent->expr_type,
|
2004-08-25 02:00:03 +00:00
|
|
|
tc->combined_constraints, 1);
|
2004-08-18 04:50:37 +00:00
|
|
|
}
|
2004-08-20 13:24:28 +00:00
|
|
|
printf("\n");
|
2004-08-18 04:50:37 +00:00
|
|
|
}
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-08-18 04:50:37 +00:00
|
|
|
|
2004-10-13 09:13:56 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
asn1print_expr_dtd(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *expr, enum asn1print_flags flags, int level) {
|
|
|
|
asn1p_expr_t *se;
|
|
|
|
int expr_unordered = 0;
|
2004-10-14 05:11:25 +00:00
|
|
|
int dont_involve_children = 0;
|
2004-10-13 09:13:56 +00:00
|
|
|
|
|
|
|
switch(expr->meta_type) {
|
|
|
|
case AMT_TYPE:
|
|
|
|
case AMT_TYPEREF:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if(expr->expr_type == A1TC_UNIVERVAL)
|
|
|
|
break;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!expr->Identifier) return 0;
|
|
|
|
|
|
|
|
if(flags & APF_LINE_COMMENTS)
|
|
|
|
INDENT("<!-- #line %d -->\n", expr->_lineno);
|
|
|
|
INDENT("<!ELEMENT %s", expr->Identifier);
|
|
|
|
|
|
|
|
if(expr->expr_type == A1TC_REFERENCE) {
|
|
|
|
se = asn1f_find_terminal_type_ex(asn, expr);
|
|
|
|
if(!se) {
|
2004-10-14 05:11:25 +00:00
|
|
|
printf(" (ANY)");
|
2004-10-13 09:13:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
expr = se;
|
2004-10-14 05:11:25 +00:00
|
|
|
dont_involve_children = 1;
|
2004-10-13 09:13:56 +00:00
|
|
|
}
|
|
|
|
|
2005-03-10 15:16:56 +00:00
|
|
|
if(expr->expr_type == ASN_CONSTR_CHOICE
|
|
|
|
|| expr->expr_type == ASN_CONSTR_SEQUENCE_OF
|
|
|
|
|| expr->expr_type == ASN_CONSTR_SET_OF
|
|
|
|
|| expr->expr_type == ASN_CONSTR_SET
|
2005-03-09 20:52:15 +00:00
|
|
|
|| expr->expr_type == ASN_BASIC_INTEGER
|
|
|
|
|| expr->expr_type == ASN_BASIC_ENUMERATED) {
|
|
|
|
expr_unordered = 1;
|
|
|
|
}
|
|
|
|
|
2004-10-13 09:13:56 +00:00
|
|
|
if(TQ_FIRST(&expr->members)) {
|
|
|
|
int extensible = 0;
|
|
|
|
printf(" (");
|
|
|
|
TQ_FOR(se, &(expr->members), next) {
|
|
|
|
if(se->expr_type == A1TC_EXTENSIBLE) {
|
|
|
|
extensible = 1;
|
|
|
|
continue;
|
|
|
|
} else if(!se->Identifier
|
|
|
|
&& se->expr_type == A1TC_REFERENCE) {
|
|
|
|
asn1print_ref(se->reference, flags);
|
|
|
|
} else if(se->Identifier) {
|
|
|
|
printf("%s", se->Identifier);
|
|
|
|
} else {
|
|
|
|
printf("ANY");
|
|
|
|
}
|
|
|
|
if(expr->expr_type != ASN_CONSTR_SET
|
|
|
|
&& expr->expr_type != ASN_CONSTR_CHOICE
|
|
|
|
&& expr->expr_type != ASN_BASIC_INTEGER
|
|
|
|
&& expr->expr_type != ASN_BASIC_ENUMERATED) {
|
|
|
|
if(expr_unordered)
|
|
|
|
printf("*");
|
|
|
|
else if(se->marker.flags)
|
|
|
|
printf("?");
|
|
|
|
}
|
|
|
|
if(TQ_NEXT(se, next)
|
|
|
|
&& TQ_NEXT(se, next)->expr_type != A1TC_EXTENSIBLE) {
|
|
|
|
printf(expr_unordered?"|":", ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(extensible) {
|
|
|
|
printf(expr_unordered?"|":", ");
|
|
|
|
printf("ANY");
|
|
|
|
if(expr->expr_type != ASN_CONSTR_SET
|
|
|
|
&& expr->expr_type != ASN_CONSTR_CHOICE
|
|
|
|
&& expr->expr_type != ASN_BASIC_INTEGER
|
|
|
|
&& expr->expr_type != ASN_BASIC_ENUMERATED)
|
|
|
|
printf("*");
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(")");
|
|
|
|
if(expr->expr_type == ASN_CONSTR_SET)
|
|
|
|
printf("*");
|
|
|
|
|
2004-10-14 05:11:25 +00:00
|
|
|
} else switch(expr->expr_type) {
|
|
|
|
case ASN_BASIC_BOOLEAN:
|
2005-03-09 20:52:15 +00:00
|
|
|
printf(" (true|false)");
|
2004-10-14 05:11:25 +00:00
|
|
|
break;
|
|
|
|
case ASN_CONSTR_CHOICE:
|
|
|
|
case ASN_CONSTR_SET:
|
|
|
|
case ASN_CONSTR_SET_OF:
|
|
|
|
case ASN_CONSTR_SEQUENCE:
|
|
|
|
case ASN_CONSTR_SEQUENCE_OF:
|
|
|
|
case ASN_BASIC_NULL:
|
|
|
|
case A1TC_UNIVERVAL:
|
2004-10-13 09:13:56 +00:00
|
|
|
printf(" EMPTY");
|
2004-10-14 05:11:25 +00:00
|
|
|
break;
|
|
|
|
case ASN_TYPE_ANY:
|
|
|
|
printf(" ANY");
|
|
|
|
break;
|
|
|
|
case ASN_BASIC_BIT_STRING:
|
|
|
|
case ASN_BASIC_OCTET_STRING:
|
|
|
|
case ASN_BASIC_OBJECT_IDENTIFIER:
|
|
|
|
case ASN_BASIC_RELATIVE_OID:
|
2004-10-15 06:01:54 +00:00
|
|
|
case ASN_BASIC_INTEGER:
|
2004-10-14 05:11:25 +00:00
|
|
|
case ASN_BASIC_UTCTime:
|
|
|
|
case ASN_BASIC_GeneralizedTime:
|
|
|
|
case ASN_STRING_NumericString:
|
|
|
|
case ASN_STRING_PrintableString:
|
2004-10-15 06:01:54 +00:00
|
|
|
printf(" (#PCDATA)");
|
2004-10-14 05:11:25 +00:00
|
|
|
break;
|
|
|
|
case ASN_STRING_VisibleString:
|
|
|
|
case ASN_STRING_ISO646String:
|
|
|
|
/* Entity references, but not XML elements may be present */
|
2004-10-13 09:13:56 +00:00
|
|
|
printf(" (#PCDATA)");
|
2004-10-14 05:11:25 +00:00
|
|
|
break;
|
|
|
|
case ASN_BASIC_REAL: /* e.g. <MINUS-INFINITY/> */
|
|
|
|
case ASN_BASIC_ENUMERATED: /* e.g. <enumIdentifier1/> */
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* XML elements are allowed.
|
|
|
|
* For example, a UTF8String may contain "<bel/>".
|
|
|
|
*/
|
|
|
|
printf(" ANY");
|
2004-10-13 09:13:56 +00:00
|
|
|
}
|
|
|
|
printf(">\n");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Display the descendants (children) of the current type.
|
|
|
|
*/
|
2004-10-14 05:11:25 +00:00
|
|
|
if(!dont_involve_children) {
|
|
|
|
TQ_FOR(se, &(expr->members), next) {
|
|
|
|
if(se->expr_type == A1TC_EXTENSIBLE) continue;
|
|
|
|
asn1print_expr_dtd(asn, mod, se, flags, level + 1);
|
|
|
|
}
|
2004-10-13 09:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|