From 64584e7fd77bb392f444986f0d0472cc66fd658b Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 15 Jan 2004 23:44:58 +0000 Subject: [PATCH] Multiple explain records may exist for one target. Proxy checks contents of database element in explain record to validate database. --- ChangeLog | 4 ++++ TODO | 2 -- etc/config.xml | 9 ++++++++- include/yaz++/proxy.h | 3 ++- src/yaz-proxy-config.cpp | 29 +++++++++++++++++++++++++---- src/yaz-proxy.cpp | 28 +++++++++++++++++++--------- 6 files changed, 58 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 03838ad..b2c5934 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ + +Multiple explain records may exist for one target. Proxy checks contents of +database element in explain record to validate database. + --- 0.7.5 2004/01/15 Internal release. Fixes for Z39.50 options / version. diff --git a/TODO b/TODO index af27210..d162913 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,6 @@ Per database config. -Explain always returned even though database/path is wrong. - Control the various optimizations with config.. Live status (via search, present). diff --git a/etc/config.xml b/etc/config.xml index 7cdca9d..9e71d4c 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -1,5 +1,5 @@ - + indexdata.dk @@ -65,6 +65,13 @@ Default + + + indexdata.dk + 9000 + gils + + diff --git a/include/yaz++/proxy.h b/include/yaz++/proxy.h index f033377..87286ff 100644 --- a/include/yaz++/proxy.h +++ b/include/yaz++/proxy.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2004, Index Data. * See the file LICENSE for details. * - * $Id: proxy.h,v 1.35 2004-01-15 15:47:52 adam Exp $ + * $Id: proxy.h,v 1.36 2004-01-15 23:44:58 adam Exp $ */ #include @@ -255,6 +255,7 @@ class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc { ODR m_s2z_odr_search; int m_s2z_hit_count; int m_s2z_packing; + char *m_s2z_database; Z_APDU *m_s2z_init_apdu; Z_APDU *m_s2z_search_apdu; Z_APDU *m_s2z_present_apdu; diff --git a/src/yaz-proxy-config.cpp b/src/yaz-proxy-config.cpp index 7a3134b..ef7b279 100644 --- a/src/yaz-proxy-config.cpp +++ b/src/yaz-proxy-config.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2004, Index Data. * See the file LICENSE for details. * - * $Id: yaz-proxy-config.cpp,v 1.23 2004-01-07 13:40:06 adam Exp $ + * $Id: yaz-proxy-config.cpp,v 1.24 2004-01-15 23:44:58 adam Exp $ */ #include @@ -693,6 +693,30 @@ char *Yaz_ProxyConfig::get_explain(ODR odr, const char *name, const char *db, if (ptr->type == XML_ELEMENT_NODE && !strcmp((const char *) ptr->name, "explain")) { + xmlNodePtr ptr1 = ptr->children; + if (db) + { + for (; ptr1; ptr1 = ptr1->next) + if (ptr1->type == XML_ELEMENT_NODE && + !strcmp((const char *) ptr1->name, "serverInfo")) + break; + if (!ptr1) + continue; + for (ptr1 = ptr1->children; ptr; ptr1 = ptr1->next) + if (ptr1->type == XML_ELEMENT_NODE && + !strcmp((const char *) ptr1->name, "database")) + break; + + if (!ptr1) + continue; + for (ptr1 = ptr1->children; ptr1; ptr1 = ptr1->next) + if (ptr1->type == XML_TEXT_NODE && + ptr1->content && + !strcmp((const char *) ptr1->content, db)) + break; + if (!ptr1) + continue; + } xmlNodePtr ptr2 = xmlCopyNode(ptr, 1); xmlDocPtr doc = xmlNewDoc((const xmlChar *) "1.0"); @@ -709,9 +733,6 @@ char *Yaz_ProxyConfig::get_explain(ODR odr, const char *name, const char *db, return content; } } - else - yaz_log(LOG_WARN, "No explain node 1"); - #endif yaz_log(LOG_WARN, "No explain node"); return 0; diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index 76489f2..97ec2de 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.90 2004-01-15 15:47:52 adam Exp $ + * $Id: yaz-proxy.cpp,v 1.91 2004-01-15 23:44:58 adam Exp $ */ #include @@ -108,6 +108,7 @@ Yaz_Proxy::Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable, m_marcxml_flag = 0; m_stylesheet_schema = 0; m_s2z_stylesheet = 0; + m_s2z_database = 0; m_schema = 0; m_initRequest_apdu = 0; m_initRequest_mem = 0; @@ -850,25 +851,27 @@ int Yaz_Proxy::send_to_srw_client_ok(int hits, Z_Records *records, int start) int Yaz_Proxy::send_srw_explain_response(Z_SRW_diagnostic *diagnostics, int num_diagnostics) { - Z_SRW_PDU *res = yaz_srw_get(odr_encode(), Z_SRW_explain_response); - Z_SRW_explainResponse *er = res->u.explain_response; - Yaz_ProxyConfig *cfg = check_reconfigure(); if (cfg) { int len; char *b = cfg->get_explain(odr_encode(), 0 /* target */, - 0 /* db */, &len); + m_s2z_database, &len); if (b) { + Z_SRW_PDU *res = yaz_srw_get(odr_encode(), Z_SRW_explain_response); + Z_SRW_explainResponse *er = res->u.explain_response; + er->record.recordData_buf = b; er->record.recordData_len = len; er->record.recordPacking = m_s2z_packing; + + er->diagnostics = diagnostics; + er->num_diagnostics = num_diagnostics; + return send_srw_response(res); } } - er->diagnostics = diagnostics; - er->num_diagnostics = num_diagnostics; - return send_srw_response(res); + return send_http_response(404); } int Yaz_Proxy::send_PDU_convert(Z_APDU *apdu, int *len) @@ -1565,7 +1568,6 @@ Z_ElementSetNames *Yaz_Proxy::mk_esn_from_schema(ODR o, const char *schema) void Yaz_Proxy::handle_incoming_HTTP(Z_HTTP_Request *hreq) { - if (m_s2z_odr_init) { odr_destroy(m_s2z_odr_init); @@ -1621,6 +1623,7 @@ void Yaz_Proxy::handle_incoming_HTTP(Z_HTTP_Request *hreq) { Z_SRW_searchRetrieveRequest *srw_req = srw_pdu->u.request; + m_s2z_database = odr_strdup(m_s2z_odr_init, srw_req->database); // recordXPath unsupported. if (srw_req->recordXPath) { @@ -1804,6 +1807,8 @@ void Yaz_Proxy::handle_incoming_HTTP(Z_HTTP_Request *hreq) { Z_SRW_explainRequest *srw_req = srw_pdu->u.explain_request; + m_s2z_database = odr_strdup(m_s2z_odr_init, srw_req->database); + // save stylesheet if (srw_req->stylesheet) m_s2z_stylesheet = @@ -1837,6 +1842,9 @@ void Yaz_Proxy::handle_incoming_HTTP(Z_HTTP_Request *hreq) } else if (srw_pdu->which == Z_SRW_scan_request) { + m_s2z_database = odr_strdup(m_s2z_odr_init, + srw_pdu->u.scan_request->database); + yaz_add_srw_diagnostic(odr_decode(), &diagnostic, &num_diagnostic, 4, "scan"); @@ -1852,6 +1860,8 @@ void Yaz_Proxy::handle_incoming_HTTP(Z_HTTP_Request *hreq) } else { + m_s2z_database = 0; + send_to_srw_client_error(4, 0); } } -- 1.7.10.4