From 243e40729c4ac5cbed92a22dd18182d7692dd6e8 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 20 Mar 2008 11:58:19 +0100 Subject: [PATCH] Using USEMARCON 3 API. Patch from Ere Maijala. Bug #2121. --- src/proxyp.h | 6 ++--- src/yaz-proxy.cpp | 65 ++++++++++++++++--------------------------------- src/yaz-usemarcon.cpp | 16 +++++++++--- 3 files changed, 36 insertions(+), 51 deletions(-) diff --git a/src/proxyp.h b/src/proxyp.h index 311062c..0296b87 100644 --- a/src/proxyp.h +++ b/src/proxyp.h @@ -28,7 +28,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #endif #if HAVE_USEMARCON -#include +#include #endif #include @@ -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 diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index eb7ce68..926d5b4 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -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 = diff --git a/src/yaz-usemarcon.cpp b/src/yaz-usemarcon.cpp index 1e0e698..a815f7b 100644 --- a/src/yaz-usemarcon.cpp +++ b/src/yaz-usemarcon.cpp @@ -19,6 +19,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include #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; -- 1.7.10.4