X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=odr%2Fdumpber.c;h=7acc3aa1f013a25b27126be5ebf96c79317bb9bd;hp=253e1609d6bdedcfeaa8ed932ada67e52fc43ab3;hb=3111fa3db35d0d3b76ba0f70a2c9ed83d5114c11;hpb=42d3d8a6486c495357574e5db0fc736834d8ba40 diff --git a/odr/dumpber.c b/odr/dumpber.c index 253e160..7acc3aa 100644 --- a/odr/dumpber.c +++ b/odr/dumpber.c @@ -4,7 +4,25 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: dumpber.c,v $ - * Revision 1.1 1995-06-19 12:38:45 quinn + * 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 + * 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. * * @@ -13,7 +31,7 @@ #include #include -static int do_dumpBER(FILE *f, char *buf, int len, int level) +static int do_dumpBER(FILE *f, char *buf, int len, int level, int offset) { int res, ll, class, tag, cons; char *b = buf; @@ -22,19 +40,19 @@ static int do_dumpBER(FILE *f, char *buf, int len, int level) return 0; if (!buf[0] && !buf[1]) return 0; - if ((res = ber_dectag(b, &class, &tag, &cons)) <= 0) + if ((res = ber_dectag((unsigned char*)b, &class, &tag, &cons)) <= 0) return 0; if (res > len) { fprintf(stderr, "Unexpected end of buffer\n"); return 0; } - fprintf(stderr, "%*s", level * 4, ""); + fprintf(f, "%5d: %*s", offset, level * 4, ""); if (class == 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", @@ -43,37 +61,37 @@ 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); + fprintf(f, "[%d]", tag); else - fprintf(stderr, "[%d:%d]", class, tag); + fprintf(f, "[%d:%d]", class, tag); b += res; len -= res; - if ((res = ber_declen(b, &ll)) <= 0) + 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; } b += res; len -= res; if (ll >= 0) - fprintf(stderr, " len=%d\n", ll); + fprintf(f, " len=%d\n", ll); else - fprintf(stderr, " len=?\n"); + fprintf(f, " len=?\n"); 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); @@ -85,9 +103,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; @@ -97,7 +115,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; @@ -107,5 +125,5 @@ static int do_dumpBER(FILE *f, char *buf, int len, int level) int odr_dumpBER(FILE *f, char *buf, int len) { - return do_dumpBER(f, buf, len, 0); + return do_dumpBER(f, buf, len, 0, 0); }