X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=odr%2Fdumpber.c;h=1fbdecfd756b0a2194d28d1786382020ccef5f72;hb=9287c96097c00d28310becb14ea3dd7cfb9f2ab0;hp=7ae685de6a38d56e1f7c8d5aa949e9c9ca00d588;hpb=63cafe41a93427118959a74201b3e331169a71d9;p=yaz-moved-to-github.git diff --git a/odr/dumpber.c b/odr/dumpber.c index 7ae685d..1fbdecf 100644 --- a/odr/dumpber.c +++ b/odr/dumpber.c @@ -1,49 +1,39 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-2002, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: dumpber.c,v $ - * Revision 1.4 1995-09-29 17:12:21 quinn - * Smallish - * - * Revision 1.3 1995/09/27 15:02:57 quinn - * Modified function heads & prototypes. - * - * Revision 1.2 1995/06/27 13:20:51 quinn - * Fixed sign-clash. Non-fatal warning - * - * Revision 1.1 1995/06/19 12:38:45 quinn - * Added BER dumper. - * - * + * $Id: dumpber.c,v 1.13 2002-07-25 12:51:08 adam Exp $ */ +#if HAVE_CONFIG_H +#include +#endif -#include #include +#include "odr-priv.h" -static int do_dumpBER(FILE *f, char *buf, int len, int level) +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, "%*s", 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", @@ -52,37 +42,41 @@ static int do_dumpBER(FILE *f, char *buf, int len, int level) }; 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); @@ -94,9 +88,9 @@ static int do_dumpBER(FILE *f, char *buf, int len, int level) { if (ll == -1 && *b == 0 && *(b + 1) == 0) break; - if (!(res = do_dumpBER(f, b, len, level + 1))) + 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; @@ -106,7 +100,7 @@ static int do_dumpBER(FILE *f, char *buf, int len, int level) { 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; @@ -114,7 +108,7 @@ static int do_dumpBER(FILE *f, char *buf, int len, int level) 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); + return do_dumpBER(f, buf, len, 0, 0); }