Added Support OPAC to XML conversion. Triggered by backendtype="opac"
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 22 Feb 2005 10:08:19 +0000 (10:08 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 22 Feb 2005 10:08:19 +0000 (10:08 +0000)
and marcxml="1" in syntax sections.

NEWS
etc/voyager.xml
include/yazproxy/proxy.h
src/yaz-proxy.cpp

diff --git a/NEWS b/NEWS
index 3d76936..a1c0932 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,6 @@
+Added Support OPAC to XML conversion. Triggered by backendtype="opac"
+and marcxml="1" in syntax sections. See etc/voyager.xml for example.
+
 Option -X now makes it possible to stop YAZ proxy by sending
 "stop" as PROXY target (in init). This used to be debug code in a
 #if 0 .. #endif section.
index f142b1f..aee91a6 100644 (file)
@@ -1,8 +1,8 @@
 <?xml version="1.0"?>
-<!-- $Id: voyager.xml,v 1.4 2004-08-10 11:45:00 adam Exp $ -->
-<proxy xmlns="http://indexdata.dk/yazproxy/schema/0.8/"
+<!-- $Id: voyager.xml,v 1.5 2005-02-22 10:08:19 adam Exp $ -->
+<proxy xmlns="http://indexdata.dk/yazproxy/schema/0.9/"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://indexdata.dk/yazproxy/schema/0.8/ yazproxy.xsd"
+ xsi:schemaLocation="http://indexdata.dk/yazproxy/schema/0.9/ yazproxy.xsd"
 >
   <!-- define default target and name it voyager -->
   <target default="1" name="voyager">
       <name>mods3</name>
       <name>mods</name>
     </syntax>
+    
+    <syntax type="xml" marcxml="1" backendtype="opac"
+      identifier="info:srw/schema/1/opacxml-v1.0"
+      >
+      <title>OPACXML</title>
+      <name>opacxml</name>
+    </syntax>
 
     <syntax type="*" error="238"/>
 
index 95dc385..b356d79 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: proxy.h,v 1.13 2005-02-21 14:27:32 adam Exp $
+/* $Id: proxy.h,v 1.14 2005-02-22 10:08:19 adam Exp $
    Copyright (c) 1998-2005, Index Data.
 
 This file is part of the yaz-proxy.
@@ -42,6 +42,11 @@ class Yaz_usemarcon;
 class Yaz_ProxyConfig;
 class Yaz_ProxyClient;
 
+enum YAZ_Proxy_MARCXML_mode {
+    none,
+    marcxml,
+};
+
 /// Information Retrieval Proxy Server.
 class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc {
  private:
@@ -103,7 +108,7 @@ class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc {
     Yaz_ProxyConfig *check_reconfigure();
     int m_request_no;
     int m_invalid_session;
-    int m_marcxml_flag;
+    YAZ_Proxy_MARCXML_mode m_marcxml_mode;
     void *m_stylesheet_xsp;  // Really libxslt's xsltStylesheetPtr 
     int m_stylesheet_offset;
     Z_APDU *m_stylesheet_apdu;
index 0e07078..2d418a1 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: yaz-proxy.cpp,v 1.23 2005-02-21 14:27:32 adam Exp $
+/* $Id: yaz-proxy.cpp,v 1.24 2005-02-22 10:08:20 adam Exp $
    Copyright (c) 1998-2005, Index Data.
 
 This file is part of the yaz-proxy.
@@ -140,7 +140,7 @@ Yaz_Proxy::Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable,
     m_referenceId = 0;
     m_referenceId_mem = nmem_create();
     m_config = 0;
-    m_marcxml_flag = 0;
+    m_marcxml_mode = none;
     m_stylesheet_xsp = 0;
     m_stylesheet_nprl = 0;
     m_s2z_stylesheet = 0;
@@ -853,7 +853,18 @@ void Yaz_Proxy::convert_to_marcxml(Z_NamePlusRecordList *p,
        if (npr->which == Z_NamePlusRecord_databaseRecord)
        {
            Z_External *r = npr->u.databaseRecord;
-           if (r->which == Z_External_octet)
+           if (r->which == Z_External_OPAC)
+           {
+               WRBUF w = wrbuf_alloc();
+
+               yaz_display_OPAC(w, r->u.opac, 0);
+               npr->u.databaseRecord = z_ext_record(
+                   odr_encode(), VAL_TEXT_XML,
+                   wrbuf_buf(w), wrbuf_len(w)
+                   );
+               wrbuf_free(w, 1);
+           }
+           else if (r->which == Z_External_octet)
            {
                int rlen;
                char *result;
@@ -861,9 +872,8 @@ void Yaz_Proxy::convert_to_marcxml(Z_NamePlusRecordList *p,
                                        r->u.octet_aligned->len,
                                        &result, &rlen))
                {
-                   npr->u.databaseRecord = z_ext_record(odr_encode(),
-                                                        VAL_TEXT_XML,
-                                                        result, rlen);
+                   npr->u.databaseRecord =
+                       z_ext_record(odr_encode(), VAL_TEXT_XML, result, rlen);
                }
            }
        }
@@ -1182,7 +1192,7 @@ int Yaz_Proxy::send_to_client(Z_APDU *apdu)
 #endif
                    )
                    convert_to_frontend_type(p->u.databaseOrSurDiagnostics);
-               if (m_marcxml_flag)
+               if (m_marcxml_mode == marcxml)
                    convert_to_marcxml(p->u.databaseOrSurDiagnostics,
                                       m_backend_charset);
                if (convert_xsl(p->u.databaseOrSurDiagnostics, apdu))
@@ -1227,7 +1237,7 @@ int Yaz_Proxy::send_to_client(Z_APDU *apdu)
 #endif
                )
                convert_to_frontend_type(p->u.databaseOrSurDiagnostics);
-           if (m_marcxml_flag)
+           if (m_marcxml_mode == marcxml)
                convert_to_marcxml(p->u.databaseOrSurDiagnostics,
                                   m_backend_charset);
            if (convert_xsl(p->u.databaseOrSurDiagnostics, apdu))
@@ -1859,7 +1869,7 @@ int Yaz_Proxy::handle_authentication(Z_APDU *apdu)
 
 Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu)
 {
-    m_marcxml_flag = 0;
+    m_marcxml_mode = none;
     if (apdu->which == Z_APDU_searchRequest)
     {
        Z_SearchRequest *sr = apdu->u.searchRequest;
@@ -1912,6 +1922,7 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu)
        {
            sr->smallSetElementSetNames = 0;
            sr->mediumSetElementSetNames = 0;
+           m_marcxml_mode = marcxml;
            if (m_backend_type)
            {
                
@@ -1923,7 +1934,6 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu)
                sr->preferredRecordSyntax =
                    yaz_oidval_to_z3950oid(odr_encode(), CLASS_RECSYN,
                                           VAL_USMARC);
-           m_marcxml_flag = 1;
        }
        else if (err)
        {
@@ -1988,6 +1998,7 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu)
        if (err == -1)
        {
            pr->recordComposition = 0;
+           m_marcxml_mode = marcxml;
            if (m_backend_type)
            {
                
@@ -1999,7 +2010,6 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu)
                pr->preferredRecordSyntax =
                    yaz_oidval_to_z3950oid(odr_encode(), CLASS_RECSYN,
                                           VAL_USMARC);
-           m_marcxml_flag = 1;
        }
        else if (err)
        {