Using USEMARCON 3 API.
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 20 Mar 2008 10:58:19 +0000 (11:58 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 20 Mar 2008 10:58:19 +0000 (11:58 +0100)
Patch from Ere Maijala. Bug #2121.

src/proxyp.h
src/yaz-proxy.cpp
src/yaz-usemarcon.cpp

index 311062c..0296b87 100644 (file)
@@ -28,7 +28,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #endif
 
 #if HAVE_USEMARCON
-#include <objectlist.h>
+#include <usemarconlib.h>
 #endif
 
 #include <yazpp/record-cache.h>
@@ -46,8 +46,8 @@ class Yaz_usemarcon {
                 const char *input, int input_len,
                 char **output, int *output_len);
 #if HAVE_USEMARCON
-    CDetails *m_stage1;
-    CDetails *m_stage2;
+    Usemarcon *m_stage1;
+    Usemarcon *m_stage2;
 #else
     int dummy;
 #endif
index eb7ce68..926d5b4 100644 (file)
@@ -961,53 +961,30 @@ void Yaz_Proxy::convert_to_frontend_type(Z_NamePlusRecordList *p)
                 Z_External *r = npr->u.databaseRecord;
                 if (r->which == Z_External_octet)
                 {
-#if HAVE_USEMARCON
+#if !HAVE_USEMARCON
                     if (m_usemarcon_ini_stage1 && *m_usemarcon_ini_stage1)
+                        yaz_log (YLOG_LOG, "%sError: USEMARCON requested but not available",
+                            m_session_str);
+#endif
+#if HAVE_USEMARCON
+                    yaz_log (YLOG_DEBUG, "%sUSEMARCON stage1=%s stage2=%s",
+                        m_session_str,
+                        m_usemarcon_ini_stage1 ? m_usemarcon_ini_stage1 : "(none)",
+                        m_usemarcon_ini_stage2 ? m_usemarcon_ini_stage2 : "(none)");
+                    char *converted;
+                    int convlen;
+                    if (m_usemarcon->convert(m_usemarcon_ini_stage1, m_usemarcon_ini_stage2,
+                        (char*) r->u.octet_aligned->buf, r->u.octet_aligned->len,
+                        &converted, &convlen))
                     {
-                        if (!m_usemarcon->m_stage1)
-                        {
-                            m_usemarcon->m_stage1 = new CDetails();
-                        }
-                        m_usemarcon->m_stage1->SetIniFileName(m_usemarcon_ini_stage1);
-                        m_usemarcon->m_stage1->SetMarcRecord((char*) r->u.octet_aligned->buf, r->u.octet_aligned->len);
-                        int res = m_usemarcon->m_stage1->Start();
-                        if (res == 0)
-                        {
-                            char *converted;
-                            int convlen;
-                            m_usemarcon->m_stage1->GetMarcRecord(converted, convlen);
-                            if (m_usemarcon_ini_stage2 && *m_usemarcon_ini_stage2)
-                            {
-                                if (!m_usemarcon->m_stage2)
-                                {
-                                    m_usemarcon->m_stage2 = new CDetails();
-                                }
-                                m_usemarcon->m_stage2->SetIniFileName(m_usemarcon_ini_stage2);
-                                m_usemarcon->m_stage2->SetMarcRecord(converted, convlen);
-                                res = m_usemarcon->m_stage2->Start();
-                                if (res == 0)
-                                {
-                                    free(converted);
-                                    m_usemarcon->m_stage2->GetMarcRecord(converted, convlen);
-                                }
-                                else
-                                {
-                                    yaz_log(YLOG_LOG, "%sUSEMARCON stage 2 error %d", m_session_str, res);
-                                }
-                            }
-                            npr->u.databaseRecord =
-                                z_ext_record_oid(odr_encode(),
-                                                 m_frontend_type,
-                                                 converted,
-                                                 strlen(converted));
-                            free(converted);
-                        }
-                        else
-                        {
-                            yaz_log(YLOG_LOG, "%sUSEMARCON stage 1 error %d", m_session_str, res);
-                        }
-                        continue;
+                        npr->u.databaseRecord =
+                            z_ext_record_oid(odr_encode(),
+                                             m_frontend_type,
+                                             converted,
+                                             strlen(converted));
+                        free(converted);
                     }
+                    else
 #endif
 /* HAVE_USEMARCON */
                     npr->u.databaseRecord =
index 1e0e698..a815f7b 100644 (file)
@@ -19,6 +19,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 02111-1307, USA.
  */
 
+#include <yaz/log.h>
 #include "proxyp.h"
 
 Yaz_usemarcon::Yaz_usemarcon()
@@ -48,11 +49,11 @@ int Yaz_usemarcon::convert(const char *stage1, const char *stage2,
         int convlen;
         if (!m_stage1)
         {
-            m_stage1 = new CDetails();
+            m_stage1 = new Usemarcon();
         }
         m_stage1->SetIniFileName(stage1);
         m_stage1->SetMarcRecord((char*) input, input_len);
-        int res = m_stage1->Start();
+        int res = m_stage1->Convert();
         if (res == 0)
         {
             m_stage1->GetMarcRecord(converted, convlen);
@@ -60,23 +61,30 @@ int Yaz_usemarcon::convert(const char *stage1, const char *stage2,
             {
                 if (!m_stage2)
                 {
-                    m_stage2 = new CDetails();
+                    m_stage2 = new Usemarcon();
                 }
                 m_stage2->SetIniFileName(stage2);
                 m_stage2->SetMarcRecord(converted, convlen);
-                res = m_stage2->Start();
+                res = m_stage2->Convert();
                 if (res == 0)
                 {
                     free(converted);
                     m_stage2->GetMarcRecord(converted, convlen);
                 }
                 else
+                {
+                    yaz_log(YLOG_LOG, "USEMARCON stage 2 error %d", res);
                     return 0;
+                }
             }
             *output = converted;
             *output_len = convlen;
             return 1;
         }
+        else
+        {
+            yaz_log(YLOG_LOG, "USEMARCON stage 1 error %d", res);
+        }
     }
 #endif
     return 0;