2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.8 1997-05-14 06:53:57 adam
10 * Revision 1.7 1996/03/08 14:38:41 quinn
13 * Revision 1.6 1996/01/19 15:41:34 quinn
14 * dumpber was ignoring the file argument.
16 * Revision 1.5 1995/10/18 16:12:55 quinn
17 * Better diagnostics. Added special case in NULL to handle WAIS server.
19 * Revision 1.4 1995/09/29 17:12:21 quinn
22 * Revision 1.3 1995/09/27 15:02:57 quinn
23 * Modified function heads & prototypes.
25 * Revision 1.2 1995/06/27 13:20:51 quinn
26 * Fixed sign-clash. Non-fatal warning
28 * Revision 1.1 1995/06/19 12:38:45 quinn
37 static int do_dumpBER(FILE *f, char *buf, int len, int level, int offset)
39 int res, ll, zclass, tag, cons;
44 if (!buf[0] && !buf[1])
46 if ((res = ber_dectag((unsigned char*)b, &zclass, &tag, &cons)) <= 0)
50 fprintf(stderr, "Unexpected end of buffer\n");
53 fprintf(f, "%5d: %*s", offset, level * 4, "");
54 if (zclass == ODR_UNIVERSAL)
58 "[Univ 0]", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING",
59 "NULL", "OID", "OBJECT DESCIPTOR", "EXTERNAL", "REAL",
60 "ENUM", "[UNIV 11]", "[UNIV 12]", "[UNIV 13]", "[UNIV 14]",
61 "[UNIV 15]", "SEQUENCE", "SET", "NUMERICSTRING", "PRINTABLESTRING",
62 "[UNIV 20]", "[UNIV 21]", "[UNIV 22]", "[UNIV 23]", "[UNIV 24]",
63 "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", "[UNIV 28]"
67 fprintf(f, "%s", nl[tag]);
69 fprintf(f, "[UNIV %d]", tag);
71 else if (zclass == ODR_CONTEXT)
72 fprintf(f, "[%d]", tag);
74 fprintf(f, "[%d:%d]", zclass, tag);
77 if ((res = ber_declen((unsigned char*)b, &ll)) <= 0)
79 fprintf(f, "bad length\n");
84 fprintf(f, "Unexpected end of buffer\n");
90 fprintf(f, " len=%d\n", ll);
92 fprintf(f, " len=?\n");
97 fprintf(f, "Bad length on primitive type.\n");
100 return ll + (b - buf);
104 /* constructed - cycle through children */
105 while ((ll == -1 && len >= 2) || (ll >= 0 && len))
107 if (ll == -1 && *b == 0 && *(b + 1) == 0)
109 if (!(res = do_dumpBER(f, b, len, level + 1, offset + (b - buf))))
111 fprintf(f, "Dump of content element failed.\n");
121 fprintf(f, "Buffer too short in indefinite lenght.\n");
124 return (b - buf) + 2;
129 int odr_dumpBER(FILE *f, char *buf, int len)
131 return do_dumpBER(f, buf, len, 0, 0);