X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ffilter_sru_to_z3950.cpp;h=17e5b55c1ef0a6581564779108ba96c092f14abe;hb=cdb9d2053fa54a0a2d7da1514164de3bbe52edb3;hp=935f8f91c003aeb2e62f33f66d832e0ee28d866d;hpb=c980063f75d50d0869ea15fc5385bb9dd7072d85;p=metaproxy-moved-to-github.git diff --git a/src/filter_sru_to_z3950.cpp b/src/filter_sru_to_z3950.cpp index 935f8f9..17e5b55 100644 --- a/src/filter_sru_to_z3950.cpp +++ b/src/filter_sru_to_z3950.cpp @@ -1,5 +1,5 @@ /* This file is part of Metaproxy. - Copyright (C) 2005-2010 Index Data + Copyright (C) 2005-2011 Index Data Metaproxy 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 @@ -62,11 +62,11 @@ namespace metaproxy_1 { ActiveUrlMap m_active_urls; private: void sru(metaproxy_1::Package &package, Z_GDU *zgdu_req); - bool z3950_build_query( + int z3950_build_query( mp::odr &odr_en, Z_Query *z_query, const Z_SRW_searchRetrieveRequest *req ) const; - + bool z3950_init_request( mp::Package &package, mp::odr &odr_en, @@ -116,7 +116,8 @@ yf::SRUtoZ3950::~SRUtoZ3950() { // must have a destructor because of boost::scoped_ptr } -void yf::SRUtoZ3950::configure(const xmlNode *xmlnode, bool test_only) +void yf::SRUtoZ3950::configure(const xmlNode *xmlnode, bool test_only, + const char *path) { m_p->configure(xmlnode); } @@ -156,7 +157,7 @@ void yf::SRUtoZ3950::Impl::configure(const xmlNode *confignode) } // assigning explain node to database name - no check yet m_database_explain.insert(std::make_pair(database, explainnode)); - } + } } } @@ -222,6 +223,10 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) { package.origin().set_max_sockets(atoi(arg->value)); } + else if (!strcmp(arg->name, "x-session-id")) + { + package.origin().set_custom_session(arg->value); + } assert(sru_pdu_req); @@ -254,7 +259,7 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) if (ok && sru_pdu_res->u.response->numberOfRecords && *(sru_pdu_res->u.response->numberOfRecords)) - + ok = z3950_present_request(package, odr_en, sru_pdu_res, sr_req); @@ -368,6 +373,9 @@ yf::SRUtoZ3950::Impl::z3950_init_request(mp::Package &package, } init_req->idAuthentication = auth; + + *init_req->preferredMessageSize = 10*1024*1024; + *init_req->maximumRecordSize = 10*1024*1024; ODR_MASK_SET(init_req->options, Z_Options_search); ODR_MASK_SET(init_req->options, Z_Options_present); @@ -407,7 +415,7 @@ yf::SRUtoZ3950::Impl::z3950_init_request(mp::Package &package, if (z3950_gdu && z3950_gdu->which == Z_GDU_Z3950 && z3950_gdu->u.z3950->which == Z_APDU_initResponse && *z3950_gdu->u.z3950->u.initResponse->result) - return true; + return true; yaz_add_srw_diagnostic(odr_en, &(sru_pdu_res->u.response->diagnostics), @@ -461,10 +469,13 @@ bool yf::SRUtoZ3950::Impl::z3950_search_request(mp::Package &package, Z_APDU *apdu = zget_APDU(odr_en, Z_APDU_searchRequest); Z_SearchRequest *z_searchRequest = apdu->u.searchRequest; + // RecordSyntax will always be XML + z_searchRequest->preferredRecordSyntax + = odr_oiddup(odr_en, yaz_oid_recsyn_xml); if (!mp_util::set_databases_from_zurl(odr_en, zurl, - &z_searchRequest->num_databaseNames, - &z_searchRequest->databaseNames)) + &z_searchRequest->num_databaseNames, + &z_searchRequest->databaseNames)) { z_searchRequest->num_databaseNames = 1; z_searchRequest->databaseNames = (char**) @@ -475,19 +486,21 @@ bool yf::SRUtoZ3950::Impl::z3950_search_request(mp::Package &package, = odr_strdup(odr_en, const_cast(sr_req->database)); else z_searchRequest->databaseNames[0] - = odr_strdup(odr_en, "Default"); + = odr_strdup(odr_en, "Default"); } // z3950'fy query Z_Query *z_query = (Z_Query *) odr_malloc(odr_en, sizeof(Z_Query)); z_searchRequest->query = z_query; - if (!z3950_build_query(odr_en, z_query, sr_req)) + int sru_diagnostic = z3950_build_query(odr_en, z_query, sr_req); + if (sru_diagnostic) { yaz_add_srw_diagnostic(odr_en, &(sru_pdu_res->u.response->diagnostics), &(sru_pdu_res->u.response->num_diagnostics), - 7, "query"); + sru_diagnostic, + "query"); return false; } @@ -512,7 +525,7 @@ bool yf::SRUtoZ3950::Impl::z3950_search_request(mp::Package &package, yaz_add_srw_diagnostic(odr_en, &(sru_pdu_res->u.response->diagnostics), &(sru_pdu_res->u.response->num_diagnostics), - 2, 0); + YAZ_SRW_SYSTEM_TEMPORARILY_UNAVAILABLE, 0); return false; } @@ -624,11 +637,8 @@ yf::SRUtoZ3950::Impl::z3950_present_request( max_recs = *sru_pdu_res->u.response->numberOfRecords - start + 1; Z_SRW_searchRetrieveResponse *sru_res = sru_pdu_res->u.response; - // srw'fy number of returned records - sru_res->num_records = max_recs; - sru_res->records = (Z_SRW_record *) odr_malloc(odr_en, - sru_res->num_records - * sizeof(Z_SRW_record)); + sru_res->records = (Z_SRW_record *) + odr_malloc(odr_en, max_recs * sizeof(Z_SRW_record)); int num = 0; while (num < max_recs) { @@ -744,8 +754,8 @@ yf::SRUtoZ3950::Impl::z3950_present_request( return true; } -bool yf::SRUtoZ3950::Impl::z3950_build_query(mp::odr &odr_en, Z_Query *z_query, - const Z_SRW_searchRetrieveRequest *req +int yf::SRUtoZ3950::Impl::z3950_build_query(mp::odr &odr_en, Z_Query *z_query, + const Z_SRW_searchRetrieveRequest *req ) const { if (req->query_type == Z_SRW_query_type_cql) @@ -761,7 +771,7 @@ bool yf::SRUtoZ3950::Impl::z3950_build_query(mp::odr &odr_en, Z_Query *z_query, z_query->which = Z_Query_type_104; z_query->u.type_104 = ext; - return true; + return 0; } if (req->query_type == Z_SRW_query_type_pqf) @@ -772,18 +782,18 @@ bool yf::SRUtoZ3950::Impl::z3950_build_query(mp::odr &odr_en, Z_Query *z_query, pqf_parser = yaz_pqf_create (); RPNquery = yaz_pqf_parse (pqf_parser, odr_en, req->query.pqf); + + yaz_pqf_destroy(pqf_parser); + if (!RPNquery) - { - std::cout << "TODO: Handeling of bad PQF\n"; - std::cout << "TODO: Diagnostic to be send\n"; - } + return YAZ_SRW_QUERY_SYNTAX_ERROR; + z_query->which = Z_Query_type_1; z_query->u.type_1 = RPNquery; - yaz_pqf_destroy(pqf_parser); - return true; + return 0; } - return false; + return YAZ_SRW_MANDATORY_PARAMETER_NOT_SUPPLIED; } @@ -808,8 +818,8 @@ yf::SRUtoZ3950::Impl::z3950_to_srw_diagnostics_ok(mp::odr &odr_en, int yf::SRUtoZ3950::Impl::z3950_to_srw_diag(mp::odr &odr_en, - Z_SRW_searchRetrieveResponse *sru_res, - Z_DefaultDiagFormat *ddf) const + Z_SRW_searchRetrieveResponse *sru_res, + Z_DefaultDiagFormat *ddf) const { int bib1_code = *ddf->condition; sru_res->num_diagnostics = 1;