From 0b90ab9b0d18a47201ba1c5883593a14c1e5b148 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Sun, 16 Dec 2007 11:08:50 +0000 Subject: [PATCH] Handle OPAC for record conversion module. Extend the record_conv system to handle Z39.50 OPAC records. Function yaz_record_conv_opac_record was added. --- include/yaz/marcdisp.h | 10 +++++++++- include/yaz/proto.h | 8 +------- include/yaz/record_conv.h | 20 +++++++++++++++++-- src/record_conv.c | 47 +++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 73 insertions(+), 12 deletions(-) diff --git a/include/yaz/marcdisp.h b/include/yaz/marcdisp.h index 834e37f..dd92044 100644 --- a/include/yaz/marcdisp.h +++ b/include/yaz/marcdisp.h @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: marcdisp.h,v 1.28 2007-03-19 14:40:06 adam Exp $ */ +/* $Id: marcdisp.h,v 1.29 2007-12-16 11:08:50 adam Exp $ */ /** * \file marcdisp.h @@ -40,6 +40,7 @@ #include #include +#include YAZ_BEGIN_CDECL @@ -359,6 +360,13 @@ int yaz_marc_decode_formatstr(const char *arg); YAZ_EXPORT void yaz_marc_write_using_libxml2(yaz_marc_t mt, int enable); +/** \brief Performs "pretty" display of OPAC record to WRBUF */ +YAZ_EXPORT void yaz_display_OPAC(WRBUF wrbuf, Z_OPACRecord *r, int flags); + +/** \brief Performs "pretty" display of OPAC record to WRBUF using marc_t */ +YAZ_EXPORT void yaz_opac_decode_wrbuf(yaz_marc_t mt, Z_OPACRecord *r, WRBUF wrbuf); + + YAZ_END_CDECL #endif diff --git a/include/yaz/proto.h b/include/yaz/proto.h index f928e79..7031804 100644 --- a/include/yaz/proto.h +++ b/include/yaz/proto.h @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: proto.h,v 1.27 2007-04-12 13:52:57 adam Exp $ */ +/* $Id: proto.h,v 1.28 2007-12-16 11:08:50 adam Exp $ */ /** * \file proto.h @@ -133,12 +133,6 @@ YAZ_EXPORT Z_Close *zget_Close (ODR o); /** \brief Performs "pretty" display of GRS-1 record to WRBUF */ YAZ_EXPORT void yaz_display_grs1(WRBUF wrbuf, Z_GenericRecord *r, int flags); -/** \brief Performs "pretty" display of OPAC record to WRBUF */ -YAZ_EXPORT void yaz_display_OPAC(WRBUF wrbuf, Z_OPACRecord *r, int flags); - -/** \brief Performs "pretty" display of OPAC record to WRBUF using marc_t */ -YAZ_EXPORT void yaz_opac_decode_wrbuf(yaz_marc_t mt, Z_OPACRecord *r, WRBUF wrbuf); - /** \brief Encodes Z39.50 Init OPtions based on string mnemonics */ YAZ_EXPORT int yaz_init_opt_encode(Z_Options *opt, const char *opt_str, int *error_pos); diff --git a/include/yaz/record_conv.h b/include/yaz/record_conv.h index 919f76d..f60740d 100644 --- a/include/yaz/record_conv.h +++ b/include/yaz/record_conv.h @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: record_conv.h,v 1.8 2007-01-03 08:42:14 adam Exp $ */ +/* $Id: record_conv.h,v 1.9 2007-12-16 11:08:50 adam Exp $ */ /** * \file record_conv.h @@ -38,6 +38,7 @@ #include #include #include +#include YAZ_BEGIN_CDECL @@ -80,7 +81,7 @@ YAZ_EXPORT void yaz_record_conv_destroy(yaz_record_conv_t p); YAZ_EXPORT int yaz_record_conv_configure(yaz_record_conv_t p, const xmlNode *node); -/** performs record conversion +/** performs record conversion on record buffer (OCTET aligned) \param p record conversion handle \param input_record_buf input record buffer \param input_record_len length of input record buffer @@ -95,6 +96,21 @@ int yaz_record_conv_record(yaz_record_conv_t p, const char *input_record_buf, size_t input_record_len, WRBUF output_record); + +/** performs record conversion on OPAC record + \param p record conversion handle + \param input_record Z39.50 OPAC record + \param output_record resultint record (WRBUF string) + \retval 0 success + \retval -1 failure + + On failure, use yaz_record_conv_get_error to get error string. +*/ +YAZ_EXPORT +int yaz_record_conv_opac_record(yaz_record_conv_t p, + Z_OPACRecord *input_record, + WRBUF output_record); + /** returns error string (for last error) \param p record conversion handle \return error string diff --git a/src/record_conv.c b/src/record_conv.c index 524171e..ab5f173 100644 --- a/src/record_conv.c +++ b/src/record_conv.c @@ -2,7 +2,7 @@ * Copyright (C) 2005-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: record_conv.c,v 1.16 2007-05-06 20:12:20 adam Exp $ + * $Id: record_conv.c,v 1.17 2007-12-16 11:08:51 adam Exp $ */ /** * \file record_conv.c @@ -21,6 +21,7 @@ #include #include #include +#include #if YAZ_HAVE_XML2 #include @@ -370,14 +371,56 @@ int yaz_record_conv_configure(yaz_record_conv_t p, const xmlNode *ptr) return 0; } +static int yaz_record_conv_record_rule(yaz_record_conv_t p, + struct yaz_record_conv_rule *r, + const char *input_record_buf, + size_t input_record_len, + WRBUF output_record); + +int yaz_record_conv_opac_record(yaz_record_conv_t p, + Z_OPACRecord *input_record, + WRBUF output_record) +{ + int ret = 0; + struct yaz_record_conv_rule *r = p->rules; + WRBUF res = wrbuf_alloc(); + yaz_marc_t mt = yaz_marc_create(); + + wrbuf_rewind(p->wr_error); + yaz_marc_xml(mt, r->u.marc.output_format); + if (r->u.marc.iconv_t) + yaz_marc_iconv(mt, r->u.marc.iconv_t); + yaz_opac_decode_wrbuf(mt, input_record, res); + if (ret != -1) + { + ret = yaz_record_conv_record_rule(p, + r->next, + wrbuf_buf(res), wrbuf_len(res), + output_record); + } + yaz_marc_destroy(mt); + wrbuf_destroy(res); + return ret; +} + int yaz_record_conv_record(yaz_record_conv_t p, const char *input_record_buf, size_t input_record_len, WRBUF output_record) { + return yaz_record_conv_record_rule(p, p->rules, + input_record_buf, + input_record_len, output_record); +} + +static int yaz_record_conv_record_rule(yaz_record_conv_t p, + struct yaz_record_conv_rule *r, + const char *input_record_buf, + size_t input_record_len, + WRBUF output_record) +{ int ret = 0; WRBUF record = output_record; /* pointer transfer */ - struct yaz_record_conv_rule *r = p->rules; wrbuf_rewind(p->wr_error); wrbuf_write(record, input_record_buf, input_record_len); -- 1.7.10.4