Merge branch 'master' of ssh://git.indexdata.com:222/home/git/pub/yaz
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 16 Apr 2013 11:18:30 +0000 (13:18 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 16 Apr 2013 11:18:30 +0000 (13:18 +0200)
ztest/read-marc.c
ztest/ztest.c
ztest/ztest.h

index c31eab3..fdcc174 100644 (file)
@@ -1581,25 +1581,31 @@ char *dummy_marc_record(int num, ODR odr)
 }
 
 /* read MARC record and convert to XML */
-char *dummy_xml_record(int num, ODR odr)
+char *dummy_xml_record(int num, ODR odr, const char *esn)
 {
     char *rec = dummy_marc_record(num, odr);
 
     if (rec)
     {
-        const char *result;
-        size_t rlen;
-        int len;
+        WRBUF w = wrbuf_alloc();
         yaz_marc_t mt = yaz_marc_create();
+
         yaz_marc_xml(mt, YAZ_MARC_MARCXML);
-        len = yaz_marc_decode_buf(mt, rec, -1, &result, &rlen);
-        if (len > 1)
+        if (esn && !strcmp(esn, "OP"))
+        {
+            /* generate OPACXML (OPAC in XML) */
+            Z_OPACRecord *opac = dummy_opac(num, odr, rec);
+            yaz_opac_decode_wrbuf(mt, opac, w);
+        }
+        else
         {
-            rec = (char *) odr_malloc(odr, rlen+1);
-            memcpy(rec, result, rlen);
-            rec[rlen] = '\0';
+            /* generate MARCXML */
+            yaz_marc_decode_wrbuf(mt, rec, -1, w);
         }
+        rec = odr_strdup(odr, wrbuf_cstr(w));
         yaz_marc_destroy(mt);
+        wrbuf_destroy(w);
+
     }
     return rec;
 }
index 0fde809..b43b5bd 100644 (file)
@@ -835,6 +835,7 @@ int ztest_fetch(void *handle, bend_fetch_rr *r)
     char *cp;
     const Odr_oid *oid = r->request_format;
     struct result_set *set = get_set(sh, r->setname);
+    const char *esn = yaz_get_esn(r->comp);
 
     if (!set)
     {
@@ -935,7 +936,7 @@ int ztest_fetch(void *handle, bend_fetch_rr *r)
     }
     else if (!oid_oidcmp(oid, yaz_oid_recsyn_xml))
     {
-        if ((cp = dummy_xml_record(r->number, r->stream)))
+        if ((cp = dummy_xml_record(r->number, r->stream, esn)))
         {
             r->len = strlen(cp);
             r->record = cp;
index 231aa3f..f895df1 100644 (file)
@@ -33,7 +33,7 @@
 
 Z_GenericRecord *dummy_grs_record(int num, ODR o);
 char *dummy_marc_record(int num, ODR odr);
-char *dummy_xml_record(int num, ODR odr);
+char *dummy_xml_record(int num, ODR odr, const char *esn);
 Z_OPACRecord *dummy_opac(int num, ODR odr, const char *marc_input);
 
 /*