2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
22 TdeExceptionCode DBGMinCode
= TDEINFO
;
24 void DBGOcts
PARAMS ((v
),
28 for (i
= 0; i
< v
->octetLen
; i
++)
29 fprintf (stdout
, "%c", isprint(v
->octs
[i
])?v
->octs
[i
]:'.');
33 Class2ClassStr
PARAMS ((class),
61 Form2FormStr
PARAMS ((form
),
81 Code2UnivCodeStr
PARAMS ((code
),
86 case BOOLEAN_TAG_CODE
:
90 case INTEGER_TAG_CODE
:
94 case BITSTRING_TAG_CODE
:
98 case OCTETSTRING_TAG_CODE
:
99 return "OCTET STRING";
102 case NULLTYPE_TAG_CODE
:
107 return "OBJECT IDENTIFIER";
114 case EXTERNAL_TAG_CODE
:
134 case NUMERICSTRING_TAG_CODE
:
135 return "NUMERICSTRING";
138 case PRINTABLESTRING_TAG_CODE
:
139 return "PRINTABLESTRING";
142 case TELETEXSTRING_TAG_CODE
:
143 return "TELETEXSTRING";
146 case VIDEOTEXSTRING_TAG_CODE
:
147 return "VIDEOTEXSTRING";
150 case IA5STRING_TAG_CODE
:
154 case UTCTIME_TAG_CODE
:
158 case GENERALIZEDTIME_TAG_CODE
:
159 return "GENERALIZEDTIME";
162 case GRAPHICSTRING_TAG_CODE
:
163 return "GRAPHICSTRING";
166 case VISIBLESTRING_TAG_CODE
:
167 return "VISIBLESTRING";
170 case GENERALSTRING_TAG_CODE
:
171 return "GENERALSTRING";
187 void DBGIndent
PARAMS ((mode
),
190 static int indent
= 0;
191 static int withinline
= 0;
199 if (mode
==SOTSPC
&& withinline
)
203 if ((mode
==SOT
|| mode
==DECSOTEOL
|| mode
==SOTSPC
) && !withinline
)
205 for (i
=0; i
<indent
; i
++)
211 if (mode
==EOLIF
&& withinline
)
212 fprintf(stdout
,"\n");
215 if (mode
==EOL
|| mode
==EOLINC
|| mode
==DECSOTEOL
|| mode
==EOLIF
)
223 int DBGSimple
PARAMS ((tag
, v
, begin
),
228 BER_CLASS tclass
= TAG_ID_CLASS(tag
);
229 BER_FORM form
= TAG_ID_FORM(tag
);
230 unsigned long int code
= tag
& 0x1FFFFFFF;
237 codename
= Code2UnivCodeStr(bcode
);
241 bcode
= OCTETSTRING_TAG_CODE
;
242 codename
= "NOT_UNIV";
247 fprintf (stdout
, "%s", codename
);
248 if (TAG_IS_CONS(tag
))
252 fprintf(stdout
, " {\n");
258 fprintf(stdout
,": ");
259 PrintAsnOcts(stdout
,v
,0);
260 fprintf(stdout
,"\n");
266 if (TAG_IS_CONS(tag
) && tclass
==UNIV
)
268 DBGIndent(DECSOTEOL
);
269 fprintf(stdout
, "}\n");
275 void DBGNamedValue
PARAMS ((tnnl
, val
, mode
),
276 TBLNamedNumberList
* tnnl _AND_
280 /* mode 0: Don't print if no named value. postfix print with -- */
281 /* mode 0|1: prefix with -- */
282 /* mode >1: prefix with , */
285 FOR_EACH_LIST_ELMT (tnn
, tnnl
)
286 if (tnn
->value
== val
)
288 name
= tnn
->name
.octs
;
294 fprintf(stdout
," -- ");
296 fprintf(stdout
,", ");
298 fprintf(stdout
,"%s",name
);
299 fprintf(stdout
,"(%d)",val
);
301 fprintf(stdout
," --");
305 DBGPrintType
PARAMS ((type
),
308 static char* TIN
[] = { "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING",
309 "NULL", "OBJECT IDENTIFIER", "REAL", "ENUMERATED", "SEQUENCE", "SET",
310 "SEQUENCE OF", "SET OF", "CHOICE", NULL
};
312 if (type
->typeId
== TBL_TYPEREF
)
313 DBGOcts(&type
->content
->a
.typeRef
->typeDefPtr
->typeName
);
315 fprintf(stdout
,TIN
[type
->typeId
]);
316 if (type
->fieldName
.octetLen
)
319 DBGOcts(&type
->fieldName
);
323 typedef int (*Proc
) PROTO (());
326 DBGType
PARAMS ((type
, val
, begin
),
331 static Proc printproc
[] = {PrintAsnBool
, PrintAsnInt
, PrintAsnBits
,
333 PrintAsnNull
, PrintAsnOid
, PrintAsnReal
, PrintAsnInt
, NULL
, NULL
,
341 if (type
->typeId
>= TBL_SEQUENCE
&& type
->typeId
<= TBL_CHOICE
)
343 fprintf(stdout
," {\n");
349 if (printproc
[type
->typeId
])
352 fprintf(stdout
,": ");
353 (*printproc
[type
->typeId
])(stdout
,val
,0);
354 switch (type
->typeId
)
359 AsnBits
* b
= (AsnBits
*)val
;
361 for (i
=0; i
<b
->bitLen
;i
++)
363 DBGNamedValue(type
->values
,i
,mode
++);
365 fprintf(stdout
," --");
369 DBGNamedValue(type
->values
,*(AsnInt
*)val
,0);
374 fprintf(stdout
,"\n");
377 if (type
->typeId
>= TBL_SEQUENCE
&& type
->typeId
<= TBL_CHOICE
)
379 DBGIndent(DECSOTEOL
);
380 fprintf(stdout
,"}\n");
386 int DBGExc
PARAMS ((code
, p1
, p2
, p3
),
387 TdeExceptionCode code _AND_
398 fprintf(stdout
,"[EOC]");
402 fprintf(stdout
,"[%08X]",*(AsnTag
*)p1
);
406 fprintf(stdout
,"[%08X/%d(%d)]",*(AsnTag
*)p1
,*(int*)p2
,*(int*)p3
);
411 fprintf(stdout
,"WARNING: Unexpected type encountered");
413 fprintf(stdout
," when expecting ");
414 DBGPrintType((TBLType
*)p2
);
416 fprintf(stdout
," while decoding ");
417 DBGPrintType((TBLType
*)p1
);
418 fprintf(stdout
,", decoding it in simple mode.\n");
424 fprintf(stdout
,"WARNING: Non-optional element ");
425 DBGPrintType((TBLType
*)p2
);
426 fprintf(stdout
," missing in ");
427 DBGPrintType((TBLType
*)p1
);
428 fprintf(stdout
,".\n");
434 fprintf(stdout
,"WARNING: Mandatory elements missing in ");
435 DBGPrintType((TBLType
*)p1
);
436 fprintf(stdout
,".\n");
442 fprintf(stdout
,"WARNING: Value %d not in SIZE(%d..%d) in ",
443 *(AsnInt
*)p3
,((TBLRange
*)p2
)->from
,((TBLRange
*)p2
)->to
);
444 DBGPrintType((TBLType
*)p1
);
445 fprintf(stdout
,".\n");
451 fprintf(stdout
,"WARNING: Tag [%08X] does not match tag [%08X] of type ",
452 *(AsnTag
*)p3
,*(AsnTag
*)p2
);
453 DBGPrintType((TBLType
*)p1
);
454 fprintf(stdout
,".\n");
460 fprintf(stdout
,"ERROR: %s.\n",(char*)p1
);