X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Ffilter_sru_to_z3950.cpp;h=8c18dabc126a1ec6af60c910fb5473b0a8293c71;hb=1cdd720a9a3ba872aa092c80b28413d8b2579eed;hp=ba1f6af3733c8d6269364e12c42c25b3a5bc1143;hpb=1439d0bf10a879e94e7edfdc813b514328d93070;p=metaproxy-moved-to-github.git diff --git a/src/filter_sru_to_z3950.cpp b/src/filter_sru_to_z3950.cpp index ba1f6af..8c18dab 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,7 +62,7 @@ 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; @@ -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); } @@ -222,7 +223,15 @@ 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); + } + else if (!strcmp(arg->name, "x-log-enable")) + { + if (*arg->value == '1') + package.log_enable(); + } assert(sru_pdu_req); // filter acts as sink for SRU explain requests @@ -284,6 +293,22 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) YAZ_SRW_UNSUPP_OPERATION, "unknown"); } + + std::string l; + package.log_reset(l); + if (l.length()) + { + WRBUF w = wrbuf_alloc(); + + wrbuf_puts(w, "\n"); + wrbuf_xmlputs(w, l.c_str()); + wrbuf_puts(w, ""); + + sru_pdu_res->extraResponseData_len = wrbuf_len(w); + sru_pdu_res->extraResponseData_buf = odr_strdup(odr_en, wrbuf_cstr(w)); + wrbuf_destroy(w); + } + // build and send SRU response mp_util::build_sru_response(package, odr_en, soap, sru_pdu_res, charset, stylesheet); @@ -368,6 +393,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); @@ -461,6 +489,9 @@ 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, @@ -482,12 +513,13 @@ bool yf::SRUtoZ3950::Impl::z3950_search_request(mp::Package &package, 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), - YAZ_SRW_MANDATORY_PARAMETER_NOT_SUPPLIED, + sru_diagnostic, "query"); return false; } @@ -742,8 +774,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) @@ -759,7 +791,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) @@ -770,18 +802,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; }