Extend the record_conv system to handle Z39.50 OPAC records.
Function yaz_record_conv_opac_record was added.
* (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
#include <yaz/nmem.h>
#include <yaz/xmltypes.h>
+#include <yaz/z-opac.h>
YAZ_BEGIN_CDECL
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
* (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
/** \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);
* (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
#include <yaz/wrbuf.h>
#include <yaz/yconfig.h>
#include <yaz/xmltypes.h>
+#include <yaz/z-opac.h>
YAZ_BEGIN_CDECL
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
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
* 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
#include <yaz/xmalloc.h>
#include <yaz/nmem.h>
#include <yaz/tpath.h>
+#include <yaz/z-opac.h>
#if YAZ_HAVE_XML2
#include <libxml/parser.h>
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);