Change order of compilation to reflect Unix AM.
[yaz-moved-to-github.git] / odr / odr.c
index 7bd3fae..da919a5 100644 (file)
--- a/odr/odr.c
+++ b/odr/odr.c
@@ -2,7 +2,7 @@
  * Copyright (c) 1995-2003, Index Data
  * See the file LICENSE for details.
  *
- * $Id: odr.c,v 1.41 2003-03-11 11:03:31 adam Exp $
+ * $Id: odr.c,v 1.45 2003-06-19 21:09:25 adam Exp $
  *
  */
 #if HAVE_CONFIG_H
@@ -36,7 +36,7 @@ char *odr_errlist[] =
     "Stack overflow",
     "Length of constructed type different from sum of members",
     "Overflow writing definite length of constructed type",
-    "HTTP Bad Request"
+    "Bad HTTP Request"
 };
 
 char *odr_errmsg(int n)
@@ -46,7 +46,14 @@ char *odr_errmsg(int n)
 
 void odr_perror(ODR o, 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)
@@ -61,10 +68,25 @@ int odr_geterrorx(ODR o, int *x)
     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)
@@ -76,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 = yaz_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;
 }