X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=odr%2Fdumpber.c;h=fa3734f025d240b8dbffbb2ad43eb56346cc791d;hp=b52cabdb3e391feb32084f82da6a0fceea1cb5e2;hb=d9ee01635f03f9095a66f71b73580560d48798e8;hpb=3d0077a6eb90bf1cf4d2ecc3acd1afaf7c829bd0 diff --git a/odr/dumpber.c b/odr/dumpber.c index b52cabd..fa3734f 100644 --- a/odr/dumpber.c +++ b/odr/dumpber.c @@ -1,10 +1,28 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-1999, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: dumpber.c,v $ - * Revision 1.5 1995-10-18 16:12:55 quinn + * Revision 1.11 1999-11-30 13:47:11 adam + * Improved installation. Moved header files to include/yaz. + * + * Revision 1.10 1999/01/08 11:23:26 adam + * Added const modifier to some of the BER/ODR encoding routines. + * + * Revision 1.9 1998/01/14 09:53:26 quinn + * Added a bit more info to dump. + * + * Revision 1.8 1997/05/14 06:53:57 adam + * C++ support. + * + * Revision 1.7 1996/03/08 14:38:41 quinn + * Fixed output. + * + * Revision 1.6 1996/01/19 15:41:34 quinn + * dumpber was ignoring the file argument. + * + * Revision 1.5 1995/10/18 16:12:55 quinn * Better diagnostics. Added special case in NULL to handle WAIS server. * * Revision 1.4 1995/09/29 17:12:21 quinn @@ -22,31 +40,31 @@ * */ -#include #include +#include -static int do_dumpBER(FILE *f, char *buf, int len, int level, int offset) +static int do_dumpBER(FILE *f, const char *buf, int len, int level, int offset) { - int res, ll, class, tag, cons; - char *b = buf; + int res, ll, zclass, tag, cons, lenlen, taglen; + const char *b = buf, *bp = buf; if (!len) return 0; if (!buf[0] && !buf[1]) return 0; - if ((res = ber_dectag((unsigned char*)b, &class, &tag, &cons)) <= 0) + if ((res = ber_dectag((unsigned char*)b, &zclass, &tag, &cons)) <= 0) return 0; if (res > len) { fprintf(stderr, "Unexpected end of buffer\n"); return 0; } - fprintf(stderr, "%5d: %*s", offset, level * 4, ""); - if (class == ODR_UNIVERSAL) + fprintf(f, "%5d: %*s", offset, level * 4, ""); + if (zclass == ODR_UNIVERSAL) { static char *nl[] = { - "Ugh", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", + "[Univ 0]", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", "NULL", "OID", "OBJECT DESCIPTOR", "EXTERNAL", "REAL", "ENUM", "[UNIV 11]", "[UNIV 12]", "[UNIV 13]", "[UNIV 14]", "[UNIV 15]", "SEQUENCE", "SET", "NUMERICSTRING", "PRINTABLESTRING", @@ -55,37 +73,41 @@ static int do_dumpBER(FILE *f, char *buf, int len, int level, int offset) }; if (tag < 28) - fprintf(stderr, "%s", nl[tag]); + fprintf(f, "%s", nl[tag]); else - fprintf(stderr, "[UNIV %d]", tag); + fprintf(f, "[UNIV %d]", tag); } - else if (class == ODR_CONTEXT) - fprintf(stderr, "[%d]", tag); + else if (zclass == ODR_CONTEXT) + fprintf(f, "[%d]", tag); else - fprintf(stderr, "[%d:%d]", class, tag); + fprintf(f, "[%d:%d]", zclass, tag); b += res; + taglen = res; len -= res; + bp = b; if ((res = ber_declen((unsigned char*)b, &ll)) <= 0) { - fprintf(stderr, "bad length\n"); + fprintf(f, "bad length\n"); return 0; } if (res > len) { - fprintf(stderr, "Unexpected end of buffer\n"); + fprintf(f, "Unexpected end of buffer\n"); return 0; } + lenlen = res; b += res; len -= res; if (ll >= 0) - fprintf(stderr, " len=%d\n", ll); + fprintf(f, " len=%d", ll); else - fprintf(stderr, " len=?\n"); + fprintf(f, " len=?"); + fprintf(f, " tl=%d, ll=%d\n", taglen, lenlen); if (!cons) { if (ll < 0) { - fprintf(stderr, "Bad length on primitive type.\n"); + fprintf(f, "Bad length on primitive type.\n"); return 0; } return ll + (b - buf); @@ -99,7 +121,7 @@ static int do_dumpBER(FILE *f, char *buf, int len, int level, int offset) break; if (!(res = do_dumpBER(f, b, len, level + 1, offset + (b - buf)))) { - fprintf(stderr, "Dump of content element failed.\n"); + fprintf(f, "Dump of content element failed.\n"); return 0; } b += res; @@ -109,7 +131,7 @@ static int do_dumpBER(FILE *f, char *buf, int len, int level, int offset) { if (len < 2) { - fprintf(stderr, "Buffer too short in indefinite lenght.\n"); + fprintf(f, "Buffer too short in indefinite lenght.\n"); return 0; } return (b - buf) + 2; @@ -117,7 +139,7 @@ static int do_dumpBER(FILE *f, char *buf, int len, int level, int offset) return b - buf; } -int odr_dumpBER(FILE *f, char *buf, int len) +int odr_dumpBER(FILE *f, const char *buf, int len) { return do_dumpBER(f, buf, len, 0, 0); }