/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2013 Index Data
+ * Copyright (C) Index Data
* See the file LICENSE for details.
*/
/**
#endif
static yaz_iconv_t iconv_create_charset(const char *record_charset,
- yaz_iconv_t *cd2)
+ yaz_iconv_t *cd2,
+ const char *marc_buf,
+ int sz)
{
char charset_buf[40];
yaz_iconv_t cd = 0;
}
if (from_set1)
+ {
+ if (yaz_marc_check_marc21_coding(from_set1, marc_buf, sz))
+ from_set1 = "utf-8";
cd = yaz_iconv_open(to_set, from_set1);
+ }
if (cd2)
{
if (from_set2)
const char *buf, int sz,
const char *record_charset)
{
- yaz_iconv_t cd = iconv_create_charset(record_charset, 0);
+ yaz_iconv_t cd = iconv_create_charset(record_charset, 0, buf, sz);
yaz_marc_t mt = yaz_marc_create();
const char *ret_string = 0;
Z_OPACRecord *opac_rec,
const char *record_charset)
{
- yaz_iconv_t cd2;
- yaz_iconv_t cd = iconv_create_charset(record_charset, &cd2);
+ yaz_iconv_t cd, cd2;
+ const char *marc_buf = 0;
+ int marc_sz = 0;
yaz_marc_t mt = yaz_marc_create();
+ if (opac_rec->bibliographicRecord)
+ {
+ Z_External *ext = opac_rec->bibliographicRecord;
+ if (ext->which == Z_External_octet)
+ {
+ marc_buf = (const char *) ext->u.octet_aligned->buf;
+ marc_sz = ext->u.octet_aligned->len;
+ }
+ }
+ cd = iconv_create_charset(record_charset, &cd2, marc_buf, marc_sz);
+
if (cd)
yaz_marc_iconv(mt, cd);
yaz_marc_xml(mt, marc_type);
const char *buf, int sz,
const char *record_charset)
{
- yaz_iconv_t cd = iconv_create_charset(record_charset, 0);
+ yaz_iconv_t cd = iconv_create_charset(record_charset, 0, 0, 0);
if (cd)
{
charset);
else if (r->which == Z_External_octet)
{
- const char *ret_buf = return_marc_record(
- wrbuf, marctype, len,
- (const char *) r->u.octet_aligned->buf,
- r->u.octet_aligned->len,
- charset);
- if (ret_buf)
- return ret_buf;
- /* not ISO2709. Return fail unless raw (ISO2709) is wanted */
- if (yaz_oid_is_iso2709(oid) && marctype != YAZ_MARC_ISO2709)
- return 0;
+ 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,
+ (const char *) r->u.octet_aligned->buf,
+ r->u.octet_aligned->len,
+ charset);
+ if (ret_buf)
+ return ret_buf;
+ /* 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,
(const char *) r->u.octet_aligned->buf,
r->u.octet_aligned->len,
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,