X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Fsru_util.cpp;h=45e5823ccfb681832a20efaf392ce320d420d1c4;hb=0dcfd01a8fc058f1537af7bf16f29ca901a3e61b;hp=e72c05d13d7015e1dab12e6f0ce3ca2b44e50f98;hpb=e9530d6289df9b848e4901d7c73f5a2f27706d66;p=metaproxy-moved-to-github.git diff --git a/src/sru_util.cpp b/src/sru_util.cpp index e72c05d..45e5823 100644 --- a/src/sru_util.cpp +++ b/src/sru_util.cpp @@ -1,5 +1,5 @@ /* This file is part of Metaproxy. - Copyright (C) 2005-2008 Index Data + Copyright (C) 2005-2009 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 @@ -35,7 +35,7 @@ const std::string xmlns_explain("http://explain.z3950.org/dtd/2.0/"); bool mp_util::build_sru_debug_package(mp::Package &package) { Z_GDU *zgdu_req = package.request().get(); - if (zgdu_req && zgdu_req->which == Z_GDU_HTTP_Request) + if (zgdu_req && zgdu_req->which == Z_GDU_HTTP_Request) { Z_HTTP_Request* http_req = zgdu_req->u.HTTP_Request; std::string content = mp_util::http_headers_debug(*http_req); @@ -57,7 +57,7 @@ mp_util::SRUServerInfo mp_util::get_sru_server_info(mp::Package &package) // overwriting host and port info if set from HTTP Host header Z_GDU *zgdu_req = package.request().get(); - if (zgdu_req && zgdu_req->which == Z_GDU_HTTP_Request) + if (zgdu_req && zgdu_req->which == Z_GDU_HTTP_Request) { Z_HTTP_Request* http_req = zgdu_req->u.HTTP_Request; if (http_req) @@ -70,9 +70,8 @@ mp_util::SRUServerInfo mp_util::get_sru_server_info(mp::Package &package) http_path.assign(http_path, 0, ipath); // assign to database name - if (http_path.size() > 1){ + if (http_path.size() > 1) sruinfo.database.assign(http_path, 1, std::string::npos); - } std::string http_host_address = mp_util::http_header_value(http_req->headers, "Host"); @@ -95,7 +94,6 @@ mp_util::SRUServerInfo mp_util::get_sru_server_info(mp::Package &package) } - bool mp_util::build_sru_explain(metaproxy_1::Package &package, metaproxy_1::odr &odr_en, Z_SRW_PDU *sru_pdu_res, @@ -156,7 +154,7 @@ bool mp_util::build_sru_explain(metaproxy_1::Package &package, 1 + explain_xml.size()); return true; -}; +} bool mp_util::build_sru_response(mp::Package &package, @@ -204,7 +202,7 @@ bool mp_util::build_sru_response(mp::Package &package, {"http://www.loc.gov/zing/srw/update/", 0, (Z_SOAP_fun) yaz_ucp_codec}, {0, 0, 0} - }; + }; // empty stylesheet means NO stylesheet @@ -229,13 +227,13 @@ bool mp_util::build_sru_response(mp::Package &package, - Z_SRW_PDU * mp_util::decode_sru_request(mp::Package &package, - mp::odr &odr_de, - mp::odr &odr_en, - Z_SRW_PDU *sru_pdu_res, - Z_SOAP **soap, - char *charset, - char *stylesheet) +Z_SRW_PDU * mp_util::decode_sru_request(mp::Package &package, + mp::odr &odr_de, + mp::odr &odr_en, + Z_SRW_PDU *sru_pdu_res, + Z_SOAP **soap, + char *charset, + char *stylesheet) { Z_GDU *zgdu_req = package.request().get(); Z_SRW_PDU *sru_pdu_req = 0; @@ -243,7 +241,8 @@ bool mp_util::build_sru_response(mp::Package &package, //assert((zgdu_req->which == Z_GDU_HTTP_Request)); //ignoring all non HTTP_Request packages - if (!zgdu_req || !(zgdu_req->which == Z_GDU_HTTP_Request)){ + if (!zgdu_req || !(zgdu_req->which == Z_GDU_HTTP_Request)) + { return 0; } @@ -285,7 +284,7 @@ mp_util::check_sru_query_exists(mp::Package &package, Z_SRW_PDU *sru_pdu_res, Z_SRW_searchRetrieveRequest const *sr_req) { - if( (sr_req->query_type == Z_SRW_query_type_cql && !sr_req->query.cql) ) + if ((sr_req->query_type == Z_SRW_query_type_cql && !sr_req->query.cql)) { yaz_add_srw_diagnostic(odr_en, &(sru_pdu_res->u.response->diagnostics), @@ -297,15 +296,15 @@ mp_util::check_sru_query_exists(mp::Package &package, 10, "CQL query is empty"); return false; } - if( (sr_req->query_type == Z_SRW_query_type_xcql && !sr_req->query.xcql) ) + if ((sr_req->query_type == Z_SRW_query_type_xcql && !sr_req->query.xcql)) { yaz_add_srw_diagnostic(odr_en, &(sru_pdu_res->u.response->diagnostics), &(sru_pdu_res->u.response->num_diagnostics), - 10, "XCQL query is empty"); + 10, "XCQL query is empty"); return false; - } - if( (sr_req->query_type == Z_SRW_query_type_pqf && !sr_req->query.pqf) ) + } + if ((sr_req->query_type == Z_SRW_query_type_pqf && !sr_req->query.pqf)) { yaz_add_srw_diagnostic(odr_en, &(sru_pdu_res->u.response->diagnostics), @@ -314,18 +313,15 @@ mp_util::check_sru_query_exists(mp::Package &package, return false; } return true; -}; - - +} Z_ElementSetNames * -mp_util::build_esn_from_schema(mp::odr &odr_en, - const char *schema) +mp_util::build_esn_from_schema(mp::odr &odr_en, const char *schema) { - if (!schema) + if (!schema) return 0; - + Z_ElementSetNames *esn = (Z_ElementSetNames *) odr_malloc(odr_en, sizeof(Z_ElementSetNames)); esn->which = Z_ElementSetNames_generic; @@ -453,126 +449,12 @@ std::ostream& std::operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu) return os; } - - - -// mp_util::SRU::SRU_protocol_type -// mp_util::SRU::protocol(const Z_HTTP_Request &http_req) const -// { -// const std::string mime_urlencoded("application/x-www-form-urlencoded"); -// const std::string mime_text_xml("text/xml"); -// const std::string mime_soap_xml("application/soap+xml"); - -// const std::string http_method(http_req.method); -// const std::string http_type -// = mp_util::http_header_value(http_req.headers, "Content-Type"); - -// if (http_method == "GET") -// return SRU_GET; - -// if (http_method == "POST" -// && http_type == mime_urlencoded) -// return SRU_POST; - -// if ( http_method == "POST" -// && (http_type == mime_text_xml -// || http_type == mime_soap_xml)) -// return SRU_SOAP; - -// return SRU_NONE; -// } - -// std::string -// mp_util::sru_protocol(const Z_HTTP_Request &http_req) const -// { -// const std::string mime_urlencoded("application/x-www-form-urlencoded"); -// const std::string mime_text_xml("text/xml"); -// const std::string mime_soap_xml("application/soap+xml"); - -// const std::string http_method(http_req.method); -// const std::string http_type -// = mp_util::http_header_value(http_req.headers, "Content-Type"); - -// if (http_method == "GET") -// return "SRU GET"; - -// if (http_method == "POST" -// && http_type == mime_urlencoded) -// return "SRU POST"; - -// if ( http_method == "POST" -// && (http_type == mime_text_xml -// || http_type == mime_soap_xml)) -// return "SRU SOAP"; - -// return "HTTP"; -// } - -// std::string -// mp_util::debug_http(const Z_HTTP_Request &http_req) const -// { -// std::string message("\n
\n\n";
-// message += "Method: " + std::string(http_req.method) + "
\n";
-// message += "Version: " + std::string(http_req.version) + "
\n";
-// message += "Path: " + std::string(http_req.path) + "
\n";
-
-// message += "Content-Type:"
-// + mp_util::http_header_value(http_req.headers, "Content-Type")
-// + "
\n";
-// message += "Content-Length:"
-// + mp_util::http_header_value(http_req.headers, "Content-Length")
-// + "
\n";
-// message += "
\n";
-// Z_HTTP_Header* header = http_req.headers;
-// while (header){
-// message += "Header: "
-// + std::string(header->name) + ": "
-// + std::string(header->value) + "
\n";
-// header = header->next;
-// }
-// message += "