Fix yaz_use_attribute_create (uninit memory)
[yaz-moved-to-github.git] / src / record_render.c
index 37fc9f5..1291858 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2012 Index Data
+ * Copyright (C) Index Data
  * See the file LICENSE for details.
  */
 /**
@@ -38,10 +38,10 @@ static yaz_iconv_t iconv_create_charset(const char *record_charset,
     if (record_charset && *record_charset)
     {
         char *cp = charset_buf;
-        
+
         strncpy(charset_buf, record_charset, sizeof(charset_buf)-1);
         charset_buf[sizeof(charset_buf)-1] = '\0';
-        
+
         from_set1 = cp;
         while (*cp && *cp != ',' && *cp != '/')
             cp++;
@@ -60,7 +60,7 @@ static yaz_iconv_t iconv_create_charset(const char *record_charset,
                 cp++;
         }
     }
-    
+
     if (from_set1)
         cd = yaz_iconv_open(to_set, from_set1);
     if (cd2)
@@ -115,7 +115,7 @@ static const char *return_opac_record(WRBUF wrbuf,
         yaz_opac_decode_wrbuf2(mt, opac_rec, wrbuf, cd2);
     else
         yaz_opac_decode_wrbuf(mt, opac_rec, wrbuf);
-        
+
     yaz_marc_destroy(mt);
 
     if (cd)
@@ -167,7 +167,10 @@ static const char *return_record_wrbuf(WRBUF wrbuf, int *len,
                                     charset);
     else if (r->which == Z_External_octet)
     {
-        if (yaz_oid_is_iso2709(oid))
+        if (oid_oidcmp(oid, yaz_oid_recsyn_xml)
+            && oid_oidcmp(oid, yaz_oid_recsyn_application_xml)
+            && oid_oidcmp(oid, yaz_oid_recsyn_mab)
+            && oid_oidcmp(oid, yaz_oid_recsyn_html))
         {
             const char *ret_buf = return_marc_record(
                 wrbuf, marctype, len,
@@ -176,8 +179,8 @@ static const char *return_record_wrbuf(WRBUF wrbuf, int *len,
                 charset);
             if (ret_buf)
                 return ret_buf;
-            /* bad ISO2709. Return fail unless raw (ISO2709) is wanted */
-            if (marctype != YAZ_MARC_ISO2709)
+            /* not ISO2709. Return fail unless raw (ISO2709) is wanted */
+            if (yaz_oid_is_iso2709(oid) && marctype != YAZ_MARC_ISO2709)
                 return 0;
         }
         return return_string_record(wrbuf, len,
@@ -195,7 +198,7 @@ static const char *return_record_wrbuf(WRBUF wrbuf, int *len,
     }
     return 0;
 }
-    
+
 static const char *get_record_format(WRBUF wrbuf, int *len,
                                      Z_NamePlusRecord *npr,
                                      int marctype, const char *charset,
@@ -220,7 +223,7 @@ static const char *get_record_format(WRBUF wrbuf, int *len,
             xmlFreeDoc(doc);
             res = wrbuf_cstr(wrbuf);
             *len = wrbuf_len(wrbuf);
-        } 
+        }
     }
 #endif
     return res;
@@ -378,7 +381,7 @@ const char *yaz_record_render(Z_NamePlusRecord *npr, const char *schema,
         }
         else if (!strncmp(cp + i, "format=", 7))
         {
-            size_t j = 0; 
+            size_t j = 0;
             i = i + 7;
             while (cp[i] == ' ')
                 i++;
@@ -388,7 +391,7 @@ const char *yaz_record_render(Z_NamePlusRecord *npr, const char *schema,
                     format[j++] = cp[i];
             }
             format[j] = '\0';
-        } 
+        }
         else if (!strncmp(cp + i, "base64=", 7))
         {
             size_t i0;
@@ -401,7 +404,7 @@ const char *yaz_record_render(Z_NamePlusRecord *npr, const char *schema,
 
             nmem = nmem_create();
             base64_xpath = nmem_strdupn(nmem, cp + i0, i - i0);
-        } 
+        }
     }
     if (!strcmp(type, "database"))
     {
@@ -415,7 +418,7 @@ const char *yaz_record_render(Z_NamePlusRecord *npr, const char *schema,
     }
     else if (!strcmp(type, "syntax"))
     {
-        const char *desc = 0;   
+        const char *desc = 0;
         if (npr->which == Z_NamePlusRecord_databaseRecord)
         {
             Z_External *r = (Z_External *) npr->u.databaseRecord;
@@ -442,6 +445,11 @@ const char *yaz_record_render(Z_NamePlusRecord *npr, const char *schema,
         ret = get_record_format(wrbuf, len, npr, YAZ_MARC_TURBOMARC, charset,
                                 format);
     }
+    else if (!strcmp(type, "json"))
+    {
+        ret = get_record_format(wrbuf, len, npr, YAZ_MARC_JSON, charset,
+                                format);
+    }
     else if (!strcmp(type, "raw"))
     {
         ret = get_record_format(wrbuf, len, npr, YAZ_MARC_ISO2709, charset,