2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.5 1995-10-18 16:12:55 quinn
8 * Better diagnostics. Added special case in NULL to handle WAIS server.
10 * Revision 1.4 1995/09/29 17:12:21 quinn
13 * Revision 1.3 1995/09/27 15:02:57 quinn
14 * Modified function heads & prototypes.
16 * Revision 1.2 1995/06/27 13:20:51 quinn
17 * Fixed sign-clash. Non-fatal warning
19 * Revision 1.1 1995/06/19 12:38:45 quinn
28 static int do_dumpBER(FILE *f, char *buf, int len, int level, int offset)
30 int res, ll, class, tag, cons;
35 if (!buf[0] && !buf[1])
37 if ((res = ber_dectag((unsigned char*)b, &class, &tag, &cons)) <= 0)
41 fprintf(stderr, "Unexpected end of buffer\n");
44 fprintf(stderr, "%5d: %*s", offset, level * 4, "");
45 if (class == ODR_UNIVERSAL)
49 "Ugh", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING",
50 "NULL", "OID", "OBJECT DESCIPTOR", "EXTERNAL", "REAL",
51 "ENUM", "[UNIV 11]", "[UNIV 12]", "[UNIV 13]", "[UNIV 14]",
52 "[UNIV 15]", "SEQUENCE", "SET", "NUMERICSTRING", "PRINTABLESTRING",
53 "[UNIV 20]", "[UNIV 21]", "[UNIV 22]", "[UNIV 23]", "[UNIV 24]",
54 "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", "[UNIV 28]"
58 fprintf(stderr, "%s", nl[tag]);
60 fprintf(stderr, "[UNIV %d]", tag);
62 else if (class == ODR_CONTEXT)
63 fprintf(stderr, "[%d]", tag);
65 fprintf(stderr, "[%d:%d]", class, tag);
68 if ((res = ber_declen((unsigned char*)b, &ll)) <= 0)
70 fprintf(stderr, "bad length\n");
75 fprintf(stderr, "Unexpected end of buffer\n");
81 fprintf(stderr, " len=%d\n", ll);
83 fprintf(stderr, " len=?\n");
88 fprintf(stderr, "Bad length on primitive type.\n");
91 return ll + (b - buf);
95 /* constructed - cycle through children */
96 while ((ll == -1 && len >= 2) || (ll >= 0 && len))
98 if (ll == -1 && *b == 0 && *(b + 1) == 0)
100 if (!(res = do_dumpBER(f, b, len, level + 1, offset + (b - buf))))
102 fprintf(stderr, "Dump of content element failed.\n");
112 fprintf(stderr, "Buffer too short in indefinite lenght.\n");
115 return (b - buf) + 2;
120 int odr_dumpBER(FILE *f, char *buf, int len)
122 return do_dumpBER(f, buf, len, 0, 0);