/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2012 Index Data
+ * Copyright (C) Index Data
* See the file LICENSE for details.
*/
/**
yaz_iconv_t cd = 0;
char *from_set1 = 0;
char *from_set2 = 0;
- char *to_set = 0;
+ char *to_set = "utf-8";
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++;
cp++;
}
}
-
+
if (from_set1)
- cd = yaz_iconv_open(to_set ? to_set : "UTF-8", from_set1);
+ cd = yaz_iconv_open(to_set, from_set1);
if (cd2)
{
if (from_set2)
- *cd2 = yaz_iconv_open(to_set ? to_set : "UTF-8", from_set2);
+ *cd2 = yaz_iconv_open(to_set, from_set2);
else
*cd2 = 0;
}
yaz_marc_xml(mt, marc_type);
if (yaz_marc_decode_wrbuf(mt, buf, sz, wrbuf) > 0)
{
- if (len)
- *len = wrbuf_len(wrbuf);
+ *len = wrbuf_len(wrbuf);
ret_string = wrbuf_cstr(wrbuf);
}
yaz_marc_destroy(mt);
yaz_opac_decode_wrbuf2(mt, opac_rec, wrbuf, cd2);
else
yaz_opac_decode_wrbuf(mt, opac_rec, wrbuf);
-
+
yaz_marc_destroy(mt);
if (cd)
yaz_iconv_close(cd);
if (cd2)
yaz_iconv_close(cd2);
- if (len)
- *len = wrbuf_len(wrbuf);
+ *len = wrbuf_len(wrbuf);
return wrbuf_cstr(wrbuf);
}
sz = wrbuf_len(wrbuf);
yaz_iconv_close(cd);
}
- if (len)
- *len = sz;
+ *len = sz;
return buf;
}
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,
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,
}
return 0;
}
-
+
static const char *get_record_format(WRBUF wrbuf, int *len,
Z_NamePlusRecord *npr,
int marctype, const char *charset,
{
const char *res = return_record_wrbuf(wrbuf, len, npr, marctype, charset);
#if YAZ_HAVE_XML2
- if (*format == '1' && len)
+ if (*format == '1')
{
/* try to XML format res */
xmlDocPtr doc;
xmlFreeDoc(doc);
res = wrbuf_cstr(wrbuf);
*len = wrbuf_len(wrbuf);
- }
+ }
}
#endif
return res;
char charset[40];
char format[3];
const char *cp = type_spec;
+ int len0;
+
+ if (!len)
+ len = &len0;
for (i = 0; cp[i] && cp[i] != ';' && cp[i] != ' ' && i < sizeof(type)-1;
i++)
{
size_t j = 0;
i = i + 8; /* skip charset= */
+ while (cp[i] == ' ')
+ i++;
for (j = 0; cp[i] && cp[i] != ';' && cp[i] != ' '; i++)
{
if (j < sizeof(charset)-1)
}
else if (!strncmp(cp + i, "format=", 7))
{
- size_t j = 0;
+ size_t j = 0;
i = i + 7;
+ while (cp[i] == ' ')
+ i++;
for (j = 0; cp[i] && cp[i] != ';' && cp[i] != ' '; i++)
{
if (j < sizeof(format)-1)
format[j++] = cp[i];
}
format[j] = '\0';
- }
+ }
else if (!strncmp(cp + i, "base64=", 7))
{
size_t i0;
i = i + 7;
-
+ while (cp[i] == ' ')
+ i++;
i0 = i;
while (cp[i] && cp[i] != ';')
i++;
nmem = nmem_create();
base64_xpath = nmem_strdupn(nmem, cp + i0, i - i0);
- }
+ }
}
if (!strcmp(type, "database"))
{
- if (len)
- *len = (npr->databaseName ? strlen(npr->databaseName) : 0);
+ *len = (npr->databaseName ? strlen(npr->databaseName) : 0);
ret = npr->databaseName;
}
else if (!strcmp(type, "schema"))
{
- if (len)
- *len = schema ? strlen(schema) : 0;
+ *len = schema ? strlen(schema) : 0;
ret = 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;
}
if (!desc)
desc = "none";
- if (len)
- *len = strlen(desc);
+ *len = strlen(desc);
ret = desc;
}
if (npr->which != Z_NamePlusRecord_databaseRecord)
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,
}
else if (!strcmp(type, "ext"))
{
- if (len) *len = -1;
+ *len = -1;
ret = (const char *) npr->u.databaseRecord;
}
else if (!strcmp(type, "opac"))
format);
}
- if (base64_xpath)
+ if (base64_xpath && *len != -1)
{
char *type_spec = nmem_malloc(nmem,
- strlen(format) + strlen(charset) + 11);
+ strlen(type) + strlen(charset) + 11);
strcpy(type_spec, type);
if (*charset)
{