MARC XML
[yaz-moved-to-github.git] / zutil / zoom-c.c
index 337fcdd..9ca55c1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: zoom-c.c,v 1.6 2002-10-28 10:53:09 adam Exp $
+ * $Id: zoom-c.c,v 1.9 2002-12-03 10:03:27 adam Exp $
  *
  * ZOOM layer for C, connections, result sets, queries.
  */
@@ -8,6 +8,7 @@
 #include <yaz/otherinfo.h>
 #include <yaz/log.h>
 #include <yaz/pquery.h>
+#include <yaz/marcdisp.h>
 #include <yaz/diagbib1.h>
 #include <yaz/charneg.h>
 #include <yaz/ill.h>
@@ -1119,8 +1120,8 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len)
         }
        return 0;
     }
-    else if (!strcmp (type, "xml") && 
-             npr->which == Z_NamePlusRecord_databaseRecord)
+    else if (npr->which == Z_NamePlusRecord_databaseRecord &&
+             (!strcmp (type, "xml") || !strcmp(type, "MarcXML")))
     {
         Z_External *r = (Z_External *) npr->u.databaseRecord;
         oident *ent = oid_getentbyoid(r->direct_reference);
@@ -1132,6 +1133,10 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len)
         }
         else if (r->which == Z_External_octet)
         {
+            int marc_decode_type = YAZ_MARC_OAIMARC;
+
+            if (!strcmp(type, "MarcXML"))
+                marc_decode_type = YAZ_MARC_MARCXML;
             switch (ent->value)
             {
             case VAL_SOIF:
@@ -1149,7 +1154,7 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len)
                                      r->u.octet_aligned->buf,
                                      rec->wrbuf_marc, 0,
                                      r->u.octet_aligned->len,
-                                     2) > 0)
+                                     marc_decode_type) > 0)
                 {
                     if (len) *len = wrbuf_len(rec->wrbuf_marc);
                     return wrbuf_buf(rec->wrbuf_marc);
@@ -2183,7 +2188,6 @@ static zoom_ret do_write_ex (ZOOM_connection c, char *buf_out, int len_out)
     }
     else
     {
-        // c->reconnect_ok = 0;
         c->mask = ZOOM_SELECT_READ|ZOOM_SELECT_EXCEPT;
         yaz_log (LOG_DEBUG, "do_write_ex 2 mask=%d", c->mask);
     }
@@ -2245,6 +2249,34 @@ ZOOM_connection_addinfo (ZOOM_connection c)
     return addinfo;
 }
 
+ZOOM_API(const char *)
+ZOOM_diag_str (int error)
+{
+    switch (error)
+    {
+    case ZOOM_ERROR_NONE:
+       return "No error";
+    case ZOOM_ERROR_CONNECT:
+       return "Connect failed";
+    case ZOOM_ERROR_MEMORY:
+       return "Out of memory";
+    case ZOOM_ERROR_ENCODE:
+       return "Encoding failed";
+    case ZOOM_ERROR_DECODE:
+       return "Decoding failed";
+    case ZOOM_ERROR_CONNECTION_LOST:
+       return "Connection lost";
+    case ZOOM_ERROR_INIT:
+       return "Init rejected";
+    case ZOOM_ERROR_INTERNAL:
+       return "Internal failure";
+    case ZOOM_ERROR_TIMEOUT:
+       return "Timeout";
+    default:
+       return diagbib1_str (error);
+    }
+}
+
 ZOOM_API(int)
 ZOOM_connection_error (ZOOM_connection c, const char **cp,
                            const char **addinfo)
@@ -2252,29 +2284,7 @@ ZOOM_connection_error (ZOOM_connection c, const char **cp,
     int error = c->error;
     if (cp)
     {
-       switch (error)
-       {
-       case ZOOM_ERROR_NONE:
-           *cp = "No error"; break;
-       case ZOOM_ERROR_CONNECT:
-           *cp = "Connect failed"; break;
-       case ZOOM_ERROR_MEMORY:
-           *cp = "Out of memory"; break;
-       case ZOOM_ERROR_ENCODE:
-           *cp = "Encoding failed"; break;
-       case ZOOM_ERROR_DECODE:
-           *cp = "Decoding failed"; break;
-       case ZOOM_ERROR_CONNECTION_LOST:
-           *cp = "Connection lost"; break;
-       case ZOOM_ERROR_INIT:
-           *cp = "Init rejected"; break;
-       case ZOOM_ERROR_INTERNAL:
-           *cp = "Internal failure"; break;
-       case ZOOM_ERROR_TIMEOUT:
-           *cp = "Timeout"; break;
-       default:
-           *cp = diagbib1_str (error);
-       }
+       *cp = ZOOM_diag_str(error);
     }
     if (addinfo)
     {