19static int do_dumpBER(FILE *f,
const char *buf,
int len,
int level,
int offset)
21 int res, ll, zclass, tag, cons, lenlen, taglen;
26 yaz_snprintf(level_str,
sizeof level_str,
"level=%-6d%*s", level, 18,
"");
28 yaz_snprintf(level_str,
sizeof level_str,
"%*s", level * 2,
"");
32 if (!buf[0] && !buf[1])
34 if ((res =
ber_dectag(b, &zclass, &tag, &cons, len)) <= 0)
38 fprintf(f,
"%5d: %s : Unexpected end of buffer\n", offset, level_str);
41 fprintf(f,
"%5d: %s", offset, level_str);
46 "[Univ 0]",
"BOOLEAN",
"INTEGER",
"BIT STRING",
"OCTET STRING",
47 "NULL",
"OID",
"OBJECT DESCRIPTOR",
"EXTERNAL",
"REAL",
48 "ENUM",
"[UNIV 11]",
"[UNIV 12]",
"[UNIV 13]",
"[UNIV 14]",
49 "[UNIV 15]",
"SEQUENCE",
"SET",
"NUMERICSTRING",
"PRINTABLESTRING",
50 "[UNIV 20]",
"[UNIV 21]",
"[UNIV 22]",
"[UNIV 23]",
"[UNIV 24]",
51 "GRAPHICSTRING",
"VISIBLESTRING",
"GENERALSTRING",
"[UNIV 28]"
54 if (tag >= 0 && tag < 28)
55 fprintf(f,
"%s", nl[tag]);
57 fprintf(f,
"[UNIV %d]", tag);
60 fprintf(f,
"[%d]", tag);
62 fprintf(f,
"[%d:%d]", zclass, tag);
68 fprintf(f,
"\n%sBad length\n", level_str);
75 fprintf(f,
" len=%d", ll);
78 fprintf(f,
" tl=%d, ll=%d cons=%d\n", taglen, lenlen, cons);
81 if (ll < 0 || ll > len)
83 fprintf(f,
"%sBad length on primitive type. ll=%d len=%d\n",
87 return ll + (b - buf);
93 fprintf(f,
"%sBad length of constructed type ll=%d len=%d\n",
100 while ((ll == -1 && len >= 2) || (ll >= 0 && len))
102 if (ll == -1 && *b == 0 && *(b + 1) == 0)
104 if (!(res =
do_dumpBER(f, b, len, level + 1, offset + (b - buf))))
106 fprintf(f,
"%s Dump of content element failed\n", level_str);
113 fprintf(f,
"%sBad length\n", level_str);
121 fprintf(f,
"%sBuffer too short in indefinite length\n",
125 return (b - buf) + 2;
int ber_declen(const char *buf, int *len, int max)
int ber_dectag(const char *cp, int *zclass, int *tag, int *constructed, int max)
Decodes BER identifier octets.
static int do_dumpBER(FILE *f, const char *buf, int len, int level, int offset)
int odr_dumpBER(FILE *f, const char *buf, int len)
Internal ODR definitions.
void yaz_snprintf(char *buf, size_t size, const char *fmt,...)
Header for config file reading utilities.