From 3d95738e1464a966faae513cbaff87e9f9ff2b47 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 29 Jan 2013 15:32:43 +0100 Subject: [PATCH] yaz_xml_to_opac: OID for embedded MARC may be given --- include/yaz/marcdisp.h | 5 +++-- src/seshigh.c | 2 +- src/xml_to_opac.c | 18 +++++++++++------- test/test_record_conv.c | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/include/yaz/marcdisp.h b/include/yaz/marcdisp.h index 752de41..f1eaae8 100644 --- a/include/yaz/marcdisp.h +++ b/include/yaz/marcdisp.h @@ -440,19 +440,20 @@ YAZ_EXPORT void yaz_opac_decode_wrbuf2(yaz_marc_t mt, Z_OPACRecord *r, #if YAZ_HAVE_XML2 /** \brief Converts XML to OPAC - \param mt marc handle + \param mt marc handle \param buf_in XML buffer \param size_in size of XML buffer \param dst Z39.50 OPAC result - allocated by NMEM on marc handle \param cd iconv handle for the OPAC content (not ISO2709 part) \param nmem memory for OPACRecord (if NULL, mt NMEM memory is used) + \param syntax OID for embedded MARC (if NULL, USMARC is used) \retval 1 conversion OK \retval 0 conversion NOT OK \*/ YAZ_EXPORT int yaz_xml_to_opac(yaz_marc_t mt, const char *buf_in, size_t size_in, Z_OPACRecord **dst, yaz_iconv_t cd, - NMEM nmem); + NMEM nmem, const Odr_oid *syntax); #endif /** \brief flushes records diff --git a/src/seshigh.c b/src/seshigh.c index 1154016..803f767 100644 --- a/src/seshigh.c +++ b/src/seshigh.c @@ -665,7 +665,7 @@ static int retrieve_fetch(association *assoc, bend_fetch_rr *rr) Z_OPACRecord *opac = 0; if (yaz_xml_to_opac(mt, wrbuf_buf(output_record), wrbuf_len(output_record), - &opac, 0 /* iconv */, rr->stream->mem) + &opac, 0 /* iconv */, rr->stream->mem, 0) && opac) { rr->len = -1; diff --git a/src/xml_to_opac.c b/src/xml_to_opac.c index e6735c9..ead47bd 100644 --- a/src/xml_to_opac.c +++ b/src/xml_to_opac.c @@ -95,7 +95,7 @@ static int match_v_next(xmlNode **ptr, const char *elem, NMEM nmem, } static int bibliographicRecord(yaz_marc_t mt, xmlNode *ptr, Z_External **ext, - yaz_iconv_t cd, NMEM nmem) + yaz_iconv_t cd, NMEM nmem, const Odr_oid *syntax) { int ret = 0; if (yaz_marc_read_xml(mt, ptr) == 0) @@ -103,8 +103,9 @@ static int bibliographicRecord(yaz_marc_t mt, xmlNode *ptr, Z_External **ext, WRBUF wr = wrbuf_alloc(); if (yaz_marc_write_iso2709(mt, wr) == 0) { - *ext = z_ext_record_oid_nmem(nmem, yaz_oid_recsyn_usmarc, - wrbuf_buf(wr), wrbuf_len(wr)); + *ext = z_ext_record_oid_nmem( + nmem, syntax ? syntax : yaz_oid_recsyn_usmarc, + wrbuf_buf(wr), wrbuf_len(wr)); ret = 1; } wrbuf_destroy(wr); @@ -260,7 +261,8 @@ static int holdingsRecord(xmlNode *ptr, Z_HoldingsRecord **r, NMEM nmem) static int yaz_xml_to_opac_ptr(yaz_marc_t mt, xmlNode *ptr, Z_OPACRecord **dst, - yaz_iconv_t cd, NMEM nmem) + yaz_iconv_t cd, NMEM nmem, + const Odr_oid *syntax) { int i; Z_External *ext = 0; @@ -276,7 +278,7 @@ static int yaz_xml_to_opac_ptr(yaz_marc_t mt, xmlNode *ptr, ptr = ptr->next; if (!match_element(ptr, "bibliographicRecord")) return 0; - if (!bibliographicRecord(mt, ptr->children, &ext, cd, nmem)) + if (!bibliographicRecord(mt, ptr->children, &ext, cd, nmem, syntax)) return 0; *dst = opac = (Z_OPACRecord *) nmem_malloc(nmem, sizeof(*opac)); opac->num_holdingsData = 0; @@ -322,13 +324,15 @@ static int yaz_xml_to_opac_ptr(yaz_marc_t mt, xmlNode *ptr, } int yaz_xml_to_opac(yaz_marc_t mt, const char *buf_in, size_t size_in, - Z_OPACRecord **dst, yaz_iconv_t cd, NMEM nmem) + Z_OPACRecord **dst, yaz_iconv_t cd, NMEM nmem, + const Odr_oid *syntax) { xmlDocPtr doc = xmlParseMemory(buf_in, size_in); int r = 0; if (doc) { - r = yaz_xml_to_opac_ptr(mt, xmlDocGetRootElement(doc), dst, cd, nmem); + r = yaz_xml_to_opac_ptr(mt, xmlDocGetRootElement(doc), dst, cd, nmem, + syntax); xmlFreeDoc(doc); } return r; diff --git a/test/test_record_conv.c b/test/test_record_conv.c index 3cb5bfd..dc9bb0c 100644 --- a/test/test_record_conv.c +++ b/test/test_record_conv.c @@ -504,7 +504,7 @@ static void tst_convert3(void) Z_OPACRecord *opac = 0; yaz_marc_t mt = yaz_marc_create(); ret = yaz_xml_to_opac(mt, opacxml_rec, strlen(opacxml_rec), - &opac, 0 /* iconv */, nmem); + &opac, 0 /* iconv */, nmem, 0); YAZ_CHECK(ret); YAZ_CHECK(opac); -- 1.7.10.4