X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=odr%2Fodr.c;h=aaaec46904c56005d9ee20000f8b888fd84bd1ae;hb=29a22396d7d7b1219f5b83c35983c8fb1cd79e8f;hp=084b632919430929d8a0731345812b9c81fe2fe3;hpb=cf9f213fff1ae6b2471f8367114b93ae45ed8b75;p=yaz-moved-to-github.git diff --git a/odr/odr.c b/odr/odr.c index 084b632..aaaec46 100644 --- a/odr/odr.c +++ b/odr/odr.c @@ -1,8 +1,8 @@ /* - * Copyright (c) 1995-2002, Index Data + * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: odr.c,v 1.36 2002-08-28 07:53:51 adam Exp $ + * $Id: odr.c,v 1.46 2003-10-16 10:37:06 adam Exp $ * */ #if HAVE_CONFIG_H @@ -35,7 +35,8 @@ char *odr_errlist[] = "Malformed data", "Stack overflow", "Length of constructed type different from sum of members", - "Overflow writing definite length of constructed type" + "Overflow writing definite length of constructed type", + "Bad HTTP Request" }; char *odr_errmsg(int n) @@ -43,9 +44,16 @@ char *odr_errmsg(int n) return odr_errlist[n]; } -void odr_perror(ODR o, char *message) +void odr_perror(ODR o, const char *message) { - fprintf(stderr, "%s: %s\n", message, odr_errlist[o->error]); + const char *e = odr_getelement(o); + int err, x; + + err = odr_geterrorx(o, &x); + fprintf(stderr, "%s: %s (code %d:%d)", message, odr_errlist[err], err, x); + if (e && *e) + fprintf (stderr, " element %s", e); + fprintf(stderr, "\n"); } int odr_geterror(ODR o) @@ -53,6 +61,34 @@ int odr_geterror(ODR o) return o->error; } +int odr_geterrorx(ODR o, int *x) +{ + if (x) + *x = o->op->error_id; + return o->error; +} + +char *odr_getelement(ODR o) +{ + return o->op->element; +} + +void odr_seterror(ODR o, int error, int id) +{ + o->error = error; + o->op->error_id = id; + o->op->element[0] = '\0'; +} + +void odr_setelement(ODR o, const char *element) +{ + if (element) + { + strncpy(o->op->element, element, sizeof(o->op->element)-1); + o->op->element[sizeof(o->op->element)-1] = '\0'; + } +} + void odr_setprint(ODR o, FILE *file) { o->print = file; @@ -62,10 +98,13 @@ int odr_set_charset(ODR o, const char *to, const char *from) { if (o->op->iconv_handle) yaz_iconv_close (o->op->iconv_handle); - - o->op->iconv_handle = iconv_open (to, from); - if (o->op->iconv_handle == 0) - return -1; + o->op->iconv_handle = 0; + if (to && from) + { + o->op->iconv_handle = yaz_iconv_open (to, from); + if (o->op->iconv_handle == 0) + return -1; + } return 0; } @@ -84,7 +123,7 @@ ODR odr_createmem(int direction) r->can_grow = 1; r->mem = nmem_create(); r->enable_bias = 1; - r->op = xmalloc (sizeof(*r->op)); + r->op = (struct Odr_private *) xmalloc (sizeof(*r->op)); r->op->odr_ber_tag.lclass = -1; r->op->iconv_handle = 0; odr_reset(r); @@ -94,7 +133,7 @@ ODR odr_createmem(int direction) void odr_reset(ODR o) { - o->error = ONONE; + odr_seterror(o, ONONE, 0); o->bp = o->buf; odr_seek(o, ODR_S_SET, 0); o->top = 0; @@ -141,3 +180,4 @@ char *odr_getbuf(ODR o, int *len, int *size) *size = o->size; return (char*) o->buf; } +