Handle OPAC for record conversion module.
authorAdam Dickmeiss <adam@indexdata.dk>
Sun, 16 Dec 2007 11:08:50 +0000 (11:08 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Sun, 16 Dec 2007 11:08:50 +0000 (11:08 +0000)
Extend the record_conv system to handle Z39.50 OPAC records.
Function yaz_record_conv_opac_record was added.

include/yaz/marcdisp.h
include/yaz/proto.h
include/yaz/record_conv.h
src/record_conv.c

index 834e37f..dd92044 100644 (file)
@@ -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 <yaz/nmem.h>
 #include <yaz/xmltypes.h>
+#include <yaz/z-opac.h>
 
 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
index f928e79..7031804 100644 (file)
@@ -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);
index 919f76d..f60740d 100644 (file)
@@ -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 <yaz/wrbuf.h>
 #include <yaz/yconfig.h>
 #include <yaz/xmltypes.h>
+#include <yaz/z-opac.h>
 
 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
index 524171e..ab5f173 100644 (file)
@@ -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 <yaz/xmalloc.h>
 #include <yaz/nmem.h>
 #include <yaz/tpath.h>
+#include <yaz/z-opac.h>
 
 #if YAZ_HAVE_XML2
 #include <libxml/parser.h>
@@ -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);