projects
/
yaz-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' into sru_2_0
[yaz-moved-to-github.git]
/
src
/
record_render.c
diff --git
a/src/record_render.c
b/src/record_render.c
index
983667a
..
bcd4c39
100644
(file)
--- a/
src/record_render.c
+++ b/
src/record_render.c
@@
-1,5
+1,5
@@
/* This file is part of the YAZ toolkit.
/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2012 Index Data
+ * Copyright (C) 1995-2013 Index Data
* See the file LICENSE for details.
*/
/**
* See the file LICENSE for details.
*/
/**
@@
-34,14
+34,14
@@
static yaz_iconv_t iconv_create_charset(const char *record_charset,
yaz_iconv_t cd = 0;
char *from_set1 = 0;
char *from_set2 = 0;
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;
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';
strncpy(charset_buf, record_charset, sizeof(charset_buf)-1);
charset_buf[sizeof(charset_buf)-1] = '\0';
-
+
from_set1 = cp;
while (*cp && *cp != ',' && *cp != '/')
cp++;
from_set1 = cp;
while (*cp && *cp != ',' && *cp != '/')
cp++;
@@
-60,13
+60,13
@@
static yaz_iconv_t iconv_create_charset(const char *record_charset,
cp++;
}
}
cp++;
}
}
-
+
if (from_set1)
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)
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;
}
else
*cd2 = 0;
}
@@
-88,8
+88,7
@@
static const char *return_marc_record(WRBUF wrbuf,
yaz_marc_xml(mt, marc_type);
if (yaz_marc_decode_wrbuf(mt, buf, sz, wrbuf) > 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);
ret_string = wrbuf_cstr(wrbuf);
}
yaz_marc_destroy(mt);
@@
-116,15
+115,14
@@
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_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);
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);
}
return wrbuf_cstr(wrbuf);
}
@@
-144,8
+142,7
@@
static const char *return_string_record(WRBUF wrbuf,
sz = wrbuf_len(wrbuf);
yaz_iconv_close(cd);
}
sz = wrbuf_len(wrbuf);
yaz_iconv_close(cd);
}
- if (len)
- *len = sz;
+ *len = sz;
return buf;
}
return buf;
}
@@
-170,7
+167,10
@@
static const char *return_record_wrbuf(WRBUF wrbuf, int *len,
charset);
else if (r->which == Z_External_octet)
{
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,
{
const char *ret_buf = return_marc_record(
wrbuf, marctype, len,
@@
-179,8
+179,8
@@
static const char *return_record_wrbuf(WRBUF wrbuf, int *len,
charset);
if (ret_buf)
return ret_buf;
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;
}
return return_string_record(wrbuf, len,
@@
-198,7
+198,7
@@
static const char *return_record_wrbuf(WRBUF wrbuf, int *len,
}
return 0;
}
}
return 0;
}
-
+
static const char *get_record_format(WRBUF wrbuf, int *len,
Z_NamePlusRecord *npr,
int marctype, const char *charset,
static const char *get_record_format(WRBUF wrbuf, int *len,
Z_NamePlusRecord *npr,
int marctype, const char *charset,
@@
-206,7
+206,7
@@
static const char *get_record_format(WRBUF wrbuf, int *len,
{
const char *res = return_record_wrbuf(wrbuf, len, npr, marctype, charset);
#if YAZ_HAVE_XML2
{
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;
{
/* try to XML format res */
xmlDocPtr doc;
@@
-223,7
+223,7
@@
static const char *get_record_format(WRBUF wrbuf, int *len,
xmlFreeDoc(doc);
res = wrbuf_cstr(wrbuf);
*len = wrbuf_len(wrbuf);
xmlFreeDoc(doc);
res = wrbuf_cstr(wrbuf);
*len = wrbuf_len(wrbuf);
- }
+ }
}
#endif
return res;
}
#endif
return res;
@@
-346,6
+346,10
@@
const char *yaz_record_render(Z_NamePlusRecord *npr, const char *schema,
char charset[40];
char format[3];
const char *cp = type_spec;
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++)
for (i = 0; cp[i] && cp[i] != ';' && cp[i] != ' ' && i < sizeof(type)-1;
i++)
@@
-366,6
+370,8
@@
const char *yaz_record_render(Z_NamePlusRecord *npr, const char *schema,
{
size_t j = 0;
i = i + 8; /* skip charset= */
{
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)
for (j = 0; cp[i] && cp[i] != ';' && cp[i] != ' '; i++)
{
if (j < sizeof(charset)-1)
@@
-375,43
+381,44
@@
const char *yaz_record_render(Z_NamePlusRecord *npr, const char *schema,
}
else if (!strncmp(cp + i, "format=", 7))
{
}
else if (!strncmp(cp + i, "format=", 7))
{
- size_t j = 0;
+ size_t j = 0;
i = i + 7;
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';
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;
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);
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 (!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"))
{
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"))
{
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 (npr->which == Z_NamePlusRecord_databaseRecord)
{
Z_External *r = (Z_External *) npr->u.databaseRecord;
@@
-419,8
+426,7
@@
const char *yaz_record_render(Z_NamePlusRecord *npr, const char *schema,
}
if (!desc)
desc = "none";
}
if (!desc)
desc = "none";
- if (len)
- *len = strlen(desc);
+ *len = strlen(desc);
ret = desc;
}
if (npr->which != Z_NamePlusRecord_databaseRecord)
ret = desc;
}
if (npr->which != Z_NamePlusRecord_databaseRecord)
@@
-446,7
+452,7
@@
const char *yaz_record_render(Z_NamePlusRecord *npr, const char *schema,
}
else if (!strcmp(type, "ext"))
{
}
else if (!strcmp(type, "ext"))
{
- if (len) *len = -1;
+ *len = -1;
ret = (const char *) npr->u.databaseRecord;
}
else if (!strcmp(type, "opac"))
ret = (const char *) npr->u.databaseRecord;
}
else if (!strcmp(type, "opac"))
@@
-456,10
+462,10
@@
const char *yaz_record_render(Z_NamePlusRecord *npr, const char *schema,
format);
}
format);
}
- if (base64_xpath)
+ if (base64_xpath && *len != -1)
{
char *type_spec = nmem_malloc(nmem,
{
char *type_spec = nmem_malloc(nmem,
- strlen(format) + strlen(charset) + 11);
+ strlen(type) + strlen(charset) + 11);
strcpy(type_spec, type);
if (*charset)
{
strcpy(type_spec, type);
if (*charset)
{