Add path to configure method of filter.
[metaproxy-moved-to-github.git] / src / filter_record_transform.cpp
index 472ec9a..8e43e1e 100644 (file)
@@ -1,23 +1,31 @@
-/* $Id: filter_record_transform.cpp,v 1.9 2007-03-20 07:57:54 adam Exp $
-   Copyright (c) 2005-2007, Index Data.
+/* This file is part of Metaproxy.
+   Copyright (C) 2005-2011 Index Data
 
-   See the LICENSE file for details
- */
+Metaproxy is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
 
 #include "config.hpp"
-#include "filter.hpp"
 #include "filter_record_transform.hpp"
-#include "package.hpp"
-#include "util.hpp"
+#include <metaproxy/package.hpp>
+#include <metaproxy/util.hpp>
 #include "gduutil.hpp"
-#include "xmlutil.hpp"
 
 #include <yaz/diagbib1.h>
 #include <yaz/zgdu.h>
 #include <yaz/retrieval.h>
 
-//#include <boost/thread/mutex.hpp>
-
 #include <iostream>
 
 namespace mp = metaproxy_1;
@@ -48,7 +56,8 @@ yf::RecordTransform::~RecordTransform()
 {  // must have a destructor because of boost::scoped_ptr
 }
 
-void yf::RecordTransform::configure(const xmlNode *xmlnode)
+void yf::RecordTransform::configure(const xmlNode *xmlnode, bool test_only,
+                                    const char *path)
 {
     m_p->configure(xmlnode);
 }
@@ -141,7 +150,7 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const
     }
     
     const char *match_schema = 0;
-    int *match_syntax = 0;
+    Odr_oid *match_syntax = 0;
 
     const char *backend_schema = 0;
     Odr_oid *backend_syntax = 0;
@@ -178,7 +187,7 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const
         else if (ret_code == 2)
         {
             char oidbuf[OID_STR_MAX];
-            oid_to_dotstring(input_syntax, oidbuf);
+            oid_oid_to_dotstring(input_syntax, oidbuf);
             details = odr_strdup(odr_en, oidbuf);
             
             apdu = odr_en.create_presentResponse(
@@ -189,16 +198,12 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const
         return;
     }
 
-
-
     // now re-coding the z3950 backend present request
      
-    // z3950'fy record syntax
-    if (backend_syntax)  // TODO: this seems not to work - why ??
-        pr_req->preferredRecordSyntax = backend_syntax;
+    if (backend_syntax) 
+        pr_req->preferredRecordSyntax = odr_oiddup(odr_en, backend_syntax);
     else
-        pr_req->preferredRecordSyntax
-            = yaz_oidval_to_z3950oid(odr_en, CLASS_RECSYN, VAL_NONE);
+        pr_req->preferredRecordSyntax = 0;
     
 
     // z3950'fy record schema
@@ -229,7 +234,6 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const
         || !gdu_res->u.z3950->u.presentResponse)
 
     {
-        std::cout << "record-transform: error back present\n";
         package.session().close();
         return;
     }
@@ -271,36 +275,44 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const
                  = pr_res->records->u.databaseOrSurDiagnostics->records[i];
              if (npr->which == Z_NamePlusRecord_databaseRecord)
              {
+                 WRBUF output_record = wrbuf_alloc();
                  Z_External *r = npr->u.databaseRecord;
-                 //oident *ent = oid_getentbyoid(r->direct_reference);
-                 if (r->which == Z_External_octet) 
+                 int ret_trans = 0;
+                 if (r->which == Z_External_OPAC)
                  {
-                     WRBUF output_record = wrbuf_alloc();
-                     int ret_trans 
-                         =  yaz_record_conv_record(rc,
-                                                   (const char *)
-                                                   r->u.octet_aligned->buf, 
-                                                   r->u.octet_aligned->len,
-                                                   output_record);
-                     if (ret_trans == 0)
-                     {
-                         struct oident *ident = oid_getentbyoid(match_syntax);
-                         npr->u.databaseRecord =
-                             z_ext_record(odr_en, ident->value,
+#if YAZ_VERSIONL >= 0x030011
+                     ret_trans = 
+                         yaz_record_conv_opac_record(rc, r->u.opac,
+                                                     output_record);
+#else
+                     ;
+#endif
+                 }
+                 else if (r->which == Z_External_octet) 
+                 {
+                     ret_trans =
+                         yaz_record_conv_record(rc, (const char *)
+                                                r->u.octet_aligned->buf, 
+                                                r->u.octet_aligned->len,
+                                                output_record);
+                 }
+                 if (ret_trans == 0)
+                 {
+                     npr->u.databaseRecord =
+                         z_ext_record_oid(odr_en, match_syntax,
                                           wrbuf_buf(output_record),
                                           wrbuf_len(output_record));
-                     }
-                     else
-                     {
-                         pr_res->records->
-                             u.databaseOrSurDiagnostics->records[i] 
-                             =  zget_surrogateDiagRec(
-                                 odr_en, npr->databaseName,
-                                 YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS,
-                                 yaz_record_conv_get_error(rc));
-                     }
-                     wrbuf_destroy(output_record);
                  }
+                 else
+                 {
+                     pr_res->records->
+                         u.databaseOrSurDiagnostics->records[i] 
+                         =  zget_surrogateDiagRec(
+                             odr_en, npr->databaseName,
+                             YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS,
+                             yaz_record_conv_get_error(rc));
+                 }
+                 wrbuf_destroy(output_record);
              }
          }
     }
@@ -326,8 +338,9 @@ extern "C" {
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
- * c-file-style: "stroustrup"
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab
  */
+