X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;ds=sidebyside;f=src%2Fyaz-proxy.cpp;h=83fae8ac89616d5a12d67bcd746b657d06845cfd;hb=3cbb17ba89f52d01d20df67073fdbc8bbda4ae0d;hp=cd82f0abf779fb258c5a66891ee960ddbf932fc8;hpb=7d8da71f9935837bc4c8dc86266c9b29fd0d35c4;p=yazpp-moved-to-github.git diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index cd82f0a..83fae8a 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2004, Index Data. * See the file LICENSE for details. * - * $Id: yaz-proxy.cpp,v 1.94 2004-01-30 11:45:26 adam Exp $ + * $Id: yaz-proxy.cpp,v 1.100 2004-02-12 20:40:22 adam Exp $ */ #include @@ -100,9 +100,12 @@ Yaz_Proxy::Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable, m_config_fname = 0; m_request_no = 0; m_invalid_session = 0; + m_referenceId = 0; + m_referenceId_mem = nmem_create(); m_config = 0; m_marcxml_flag = 0; m_stylesheet_xsp = 0; + m_stylesheet_nprl = 0; m_s2z_stylesheet = 0; m_s2z_database = 0; m_schema = 0; @@ -131,6 +134,8 @@ Yaz_Proxy::~Yaz_Proxy() m_bytes_sent, m_bytes_recv); nmem_destroy(m_initRequest_mem); nmem_destroy(m_mem_invalid_session); + nmem_destroy(m_referenceId_mem); + xfree (m_proxyTarget); xfree (m_default_target); xfree (m_proxy_authentication); @@ -628,13 +633,12 @@ void Yaz_Proxy::convert_xsl_delay() m_stylesheet_offset++; if (m_stylesheet_offset == m_stylesheet_nprl->num_records) { + m_stylesheet_nprl = 0; if (m_stylesheet_xsp) xsltFreeStylesheet(m_stylesheet_xsp); m_stylesheet_xsp = 0; timeout(m_client_idletime); - int r = send_PDU_convert(m_stylesheet_apdu); - if (r) - return; + send_PDU_convert(m_stylesheet_apdu); } else timeout(0); @@ -978,6 +982,11 @@ int Yaz_Proxy::send_PDU_convert(Z_APDU *apdu) int Yaz_Proxy::send_to_client(Z_APDU *apdu) { int kill_session = 0; + Z_ReferenceId **new_id = get_referenceIdP(apdu); + + if (new_id && m_referenceId) + *new_id = m_referenceId; + if (apdu->which == Z_APDU_searchResponse) { Z_SearchResponse *sr = apdu->u.searchResponse; @@ -1911,13 +1920,27 @@ void Yaz_Proxy::handle_incoming_HTTP(Z_HTTP_Request *hreq) void Yaz_Proxy::handle_incoming_Z_PDU(Z_APDU *apdu) { + Z_ReferenceId **refid = get_referenceIdP(apdu); + nmem_reset(m_referenceId_mem); + if (refid && *refid) + { + m_referenceId = (Z_ReferenceId *) + nmem_malloc(m_referenceId_mem, sizeof(*m_referenceId)); + m_referenceId->len = m_referenceId->size = (*refid)->len; + m_referenceId->buf = (unsigned char *) + nmem_malloc(m_referenceId_mem, (*refid)->len); + memcpy(m_referenceId->buf, (*refid)->buf, (*refid)->len); + } + else + m_referenceId = 0; + if (!m_client && m_invalid_session) { m_apdu_invalid_session = apdu; m_mem_invalid_session = odr_extract_mem(odr_decode()); apdu = m_initRequest_apdu; } - + // Determine our client. Z_OtherInformation **oi; get_otherInfoAPDU(apdu, &oi); @@ -1974,19 +1997,22 @@ void Yaz_Proxy::handle_incoming_Z_PDU(Z_APDU *apdu) { if (handle_init_response_for_invalid_session(apdu)) return; - Z_APDU *apdu2 = m_client->m_initResponse; - apdu2->u.initResponse->otherInfo = 0; - if (m_client->m_cookie && *m_client->m_cookie) - set_otherInformationString(apdu2, VAL_COOKIE, 1, - m_client->m_cookie); - apdu2->u.initResponse->referenceId = - apdu->u.initRequest->referenceId; - apdu2->u.initResponse->options = m_client->m_initResponse_options; - apdu2->u.initResponse->protocolVersion = - m_client->m_initResponse_version; - - send_to_client(apdu2); - return; + if (m_client->m_initResponse) + { + Z_APDU *apdu2 = m_client->m_initResponse; + apdu2->u.initResponse->otherInfo = 0; + if (m_client->m_cookie && *m_client->m_cookie) + set_otherInformationString(apdu2, VAL_COOKIE, 1, + m_client->m_cookie); + apdu2->u.initResponse->referenceId = + apdu->u.initRequest->referenceId; + apdu2->u.initResponse->options = m_client->m_initResponse_options; + apdu2->u.initResponse->protocolVersion = + m_client->m_initResponse_version; + + send_to_client(apdu2); + return; + } } m_client->m_init_flag = 1; } @@ -2383,7 +2409,6 @@ int Yaz_Proxy::handle_init_response_for_invalid_session(Z_APDU *apdu) void Yaz_ProxyClient::recv_Z_PDU(Z_APDU *apdu, int len) { m_bytes_recv += len; - yaz_log(LOG_LOG, "m_bytes_recv += %d (now %d)", len, m_bytes_recv); m_pdu_recv++; m_waiting = 0;