User-defined retrieval records for yaz-ztest YAZ-714
[yaz-moved-to-github.git] / ztest / read-marc.c
index 487d9ab..7a54ddf 100644 (file)
 
 #include "ztest.h"
 
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#if HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#ifdef WIN32
+#include <sys/stat.h>
+#endif
+
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
 #define NO_MARC_RECORDS 24
 
 char *marc_records[NO_MARC_RECORDS] = {
@@ -1680,6 +1694,28 @@ char *dummy_xml_record(int num, ODR odr, const char *esn)
             return rec;
         }
     }
+    else
+    {
+        char *buf = 0;
+        const char *e = getenv("YAZ_ZTEST_XML_FETCH");
+        if (e)
+        {
+            WRBUF w = wrbuf_alloc();
+            struct stat sbuf;
+            FILE *file = 0;
+
+            wrbuf_printf(w, "%s%s.%d.xml", e, esn, num);
+            if (stat(wrbuf_cstr(w), &sbuf) == 0 &&
+                (file = fopen(wrbuf_cstr(w), "rb")))
+            {
+                buf = odr_malloc(odr, sbuf.st_size);
+                fread(buf, 1, sbuf.st_size, file);
+            }
+            if (file)
+                fclose(file);
+        }
+        return buf;
+    }
     return 0;
 }