X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Fyaz-proxy.cpp;h=f319d5d0711b18d4bab976f079c7c47af7d37be6;hb=a2d288bc0361884aa6e2fa953ef2766e3e1a90e7;hp=1362144777ea193ea45ca6096f9e9fece660b0bb;hpb=3f57a94d4bb1753d013d5bf450af407d6a32d36d;p=yazproxy-moved-to-github.git diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index 1362144..f319d5d 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -1,20 +1,20 @@ -/* $Id: yaz-proxy.cpp,v 1.2 2004-04-11 11:58:35 adam Exp $ +/* $Id: yaz-proxy.cpp,v 1.5 2004-08-10 09:02:16 adam Exp $ Copyright (c) 1998-2004, Index Data. This file is part of the yaz-proxy. -Zebra is free software; you can redistribute it and/or modify it under +YAZ proxy 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. -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +YAZ proxy 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 Zebra; see the file LICENSE.proxy. If not, write to the +along with YAZ proxy; see the file LICENSE. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -24,6 +24,10 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #endif +#if HAVE_GETTIMEOFDAY +#include +#endif + #include #include #include @@ -37,6 +41,13 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include +#if HAVE_XSLT +#include +#include +#include +#include +#endif + static const char *apdu_name(Z_APDU *apdu) { switch (apdu->which) @@ -130,6 +141,8 @@ Yaz_Proxy::Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable, m_s2z_stylesheet = 0; m_s2z_database = 0; m_schema = 0; + m_backend_type = 0; + m_frontend_type = 0; m_initRequest_apdu = 0; m_initRequest_mem = 0; m_initRequest_preferredMessageSize = 0; @@ -148,8 +161,12 @@ Yaz_Proxy::Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable, m_soap_ns = 0; m_s2z_packing = Z_SRW_recordPacking_string; #if HAVE_GETTIMEOFDAY - m_time_tv.tv_sec = 0; - m_time_tv.tv_usec = 0; + m_time_tv = xmalloc(sizeof(struct timeval)); + struct timeval *tv = (struct timeval *) m_time_tv; + tv->tv_sec = 0; + tv->tv_usec = 0; +#else + m_time_tv = 0; #endif if (!m_parent) low_socket_open(); @@ -170,9 +187,12 @@ Yaz_Proxy::~Yaz_Proxy() #if HAVE_XSLT if (m_stylesheet_xsp) - xsltFreeStylesheet(m_stylesheet_xsp); + xsltFreeStylesheet((xsltStylesheetPtr) m_stylesheet_xsp); #endif + xfree (m_time_tv); + xfree (m_schema); + xfree (m_backend_type); if (m_s2z_odr_init) odr_destroy(m_s2z_odr_init); if (m_s2z_odr_search) @@ -671,7 +691,8 @@ void Yaz_Proxy::convert_xsl_delay() yaz_log(LOG_LOG, "%sXSLT convert %d", m_session_str, m_stylesheet_offset); - res = xsltApplyStylesheet(m_stylesheet_xsp, doc, 0); + res = xsltApplyStylesheet((xsltStylesheetPtr) m_stylesheet_xsp, + doc, 0); if (res) { @@ -697,7 +718,7 @@ void Yaz_Proxy::convert_xsl_delay() m_stylesheet_nprl = 0; #if HAVE_XSLT if (m_stylesheet_xsp) - xsltFreeStylesheet(m_stylesheet_xsp); + xsltFreeStylesheet((xsltStylesheetPtr) m_stylesheet_xsp); #endif m_stylesheet_xsp = 0; timeout(m_client_idletime); @@ -707,6 +728,30 @@ void Yaz_Proxy::convert_xsl_delay() timeout(0); } +void Yaz_Proxy::convert_to_frontend_type(Z_NamePlusRecordList *p) +{ + if (m_frontend_type != VAL_NONE) + { + int i; + for (i = 0; i < p->num_records; i++) + { + Z_NamePlusRecord *npr = p->records[i]; + if (npr->which == Z_NamePlusRecord_databaseRecord) + { + Z_External *r = npr->u.databaseRecord; + if (r->which == Z_External_octet) + { + npr->u.databaseRecord = + z_ext_record(odr_encode(), + m_frontend_type, + (char*) r->u.octet_aligned->buf, + r->u.octet_aligned->len); + } + } + } + } +} + void Yaz_Proxy::convert_to_marcxml(Z_NamePlusRecordList *p) { int i; @@ -744,18 +789,19 @@ void Yaz_Proxy::convert_to_marcxml(Z_NamePlusRecordList *p) void Yaz_Proxy::logtime() { #if HAVE_GETTIMEOFDAY - if (m_time_tv.tv_sec) + struct timeval *tv = (struct timeval*) m_time_tv; + if (tv->tv_sec) { - struct timeval tv; - gettimeofday(&tv, 0); - long diff = (tv.tv_sec - m_time_tv.tv_sec)*1000000 + - (tv.tv_usec - m_time_tv.tv_usec); + struct timeval tv1; + gettimeofday(&tv1, 0); + long diff = (tv1.tv_sec - tv->tv_sec)*1000000 + + (tv1.tv_usec - tv->tv_usec); if (diff >= 0) yaz_log(LOG_LOG, "%sElapsed %ld.%03ld", m_session_str, diff/1000000, (diff/1000)%1000); } - m_time_tv.tv_sec = 0; - m_time_tv.tv_usec = 0; + tv->tv_sec = 0; + tv->tv_usec = 0; #endif } @@ -1043,6 +1089,8 @@ int Yaz_Proxy::send_to_client(Z_APDU *apdu) { if (p && p->which == Z_Records_DBOSD) { + if (m_backend_type) + convert_to_frontend_type(p->u.databaseOrSurDiagnostics); if (m_marcxml_flag) convert_to_marcxml(p->u.databaseOrSurDiagnostics); if (convert_xsl(p->u.databaseOrSurDiagnostics, apdu)) @@ -1081,6 +1129,8 @@ int Yaz_Proxy::send_to_client(Z_APDU *apdu) } if (p && p->which == Z_Records_DBOSD) { + if (m_backend_type) + convert_to_frontend_type(p->u.databaseOrSurDiagnostics); if (m_marcxml_flag) convert_to_marcxml(p->u.databaseOrSurDiagnostics); if (convert_xsl(p->u.databaseOrSurDiagnostics, apdu)) @@ -1189,6 +1239,12 @@ Z_APDU *Yaz_Proxy::result_set_optimize(Z_APDU *apdu) return 0; } Z_NamePlusRecordList *npr; + int oclass = 0; +#if 0 + yaz_log(LOG_LOG, "%sCache lookup %d+%d syntax=%s", + m_session_str, start, toget, yaz_z3950oid_to_str( + pr->preferredRecordSyntax, &oclass)); +#endif if (m_client->m_cache.lookup (odr_encode(), &npr, start, toget, pr->preferredRecordSyntax, pr->recordComposition)) @@ -1408,7 +1464,7 @@ void Yaz_Proxy::recv_GDU(Z_GDU *apdu, int len) m_pdu_stat.add_bytes(1); #if HAVE_GETTIMEOFDAY - gettimeofday(&m_time_tv, 0); + gettimeofday((struct timeval *) m_time_tv, 0); #endif int bw_total = m_bw_stat.get_total(); @@ -1574,19 +1630,29 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) rc = &rc_temp; } + if (sr->preferredRecordSyntax) + { + struct oident *ent; + ent = oid_getentbyoid(sr->preferredRecordSyntax); + m_frontend_type = ent->value; + } + else + m_frontend_type = VAL_NONE; + char *stylesheet_name = 0; if (cfg) err = cfg->check_syntax(odr_encode(), m_default_target, sr->preferredRecordSyntax, rc, - &addinfo, &stylesheet_name, &m_schema); + &addinfo, &stylesheet_name, &m_schema, + &m_backend_type); if (stylesheet_name) { m_parent->low_socket_close(); #if HAVE_XSLT if (m_stylesheet_xsp) - xsltFreeStylesheet(m_stylesheet_xsp); + xsltFreeStylesheet((xsltStylesheetPtr) m_stylesheet_xsp); m_stylesheet_xsp = xsltParseStylesheetFile((const xmlChar*) stylesheet_name); #endif @@ -1597,8 +1663,19 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) } if (err == -1) { - sr->preferredRecordSyntax = - yaz_oidval_to_z3950oid(odr_encode(), CLASS_RECSYN, VAL_USMARC); + sr->smallSetElementSetNames = 0; + sr->mediumSetElementSetNames = 0; + if (m_backend_type) + { + + sr->preferredRecordSyntax = + yaz_str_to_z3950oid(odr_encode(), CLASS_RECSYN, + m_backend_type); + } + else + sr->preferredRecordSyntax = + yaz_oidval_to_z3950oid(odr_encode(), CLASS_RECSYN, + VAL_USMARC); m_marcxml_flag = 1; } else if (err) @@ -1614,6 +1691,11 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) return 0; } + else if (m_backend_type) + { + sr->preferredRecordSyntax = + yaz_str_to_z3950oid(odr_encode(), CLASS_RECSYN, m_backend_type); + } } else if (apdu->which == Z_APDU_presentRequest) { @@ -1622,20 +1704,29 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) char *addinfo = 0; Yaz_ProxyConfig *cfg = check_reconfigure(); + if (pr->preferredRecordSyntax) + { + struct oident *ent; + ent = oid_getentbyoid(pr->preferredRecordSyntax); + m_frontend_type = ent->value; + } + else + m_frontend_type = VAL_NONE; + char *stylesheet_name = 0; if (cfg) err = cfg->check_syntax(odr_encode(), m_default_target, pr->preferredRecordSyntax, pr->recordComposition, - &addinfo, &stylesheet_name, &m_schema); + &addinfo, &stylesheet_name, &m_schema, + &m_backend_type); if (stylesheet_name) { m_parent->low_socket_close(); #if HAVE_XSLT if (m_stylesheet_xsp) - xsltFreeStylesheet(m_stylesheet_xsp); - + xsltFreeStylesheet((xsltStylesheetPtr) m_stylesheet_xsp); m_stylesheet_xsp = xsltParseStylesheetFile((const xmlChar*) stylesheet_name); #endif @@ -1646,8 +1737,18 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) } if (err == -1) { - pr->preferredRecordSyntax = - yaz_oidval_to_z3950oid(odr_decode(), CLASS_RECSYN, VAL_USMARC); + pr->recordComposition = 0; + if (m_backend_type) + { + + pr->preferredRecordSyntax = + yaz_str_to_z3950oid(odr_encode(), CLASS_RECSYN, + m_backend_type); + } + else + pr->preferredRecordSyntax = + yaz_oidval_to_z3950oid(odr_encode(), CLASS_RECSYN, + VAL_USMARC); m_marcxml_flag = 1; } else if (err) @@ -1664,6 +1765,11 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) return 0; } + else if (m_backend_type) + { + pr->preferredRecordSyntax = + yaz_str_to_z3950oid(odr_encode(), CLASS_RECSYN, m_backend_type); + } } return apdu; }