X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Fsru_util.cpp;h=ef6a13e68de1ed551d27420324907dc83a52e164;hb=04b73acd94679a3230324eec3ece7a1e4138d8fe;hp=e1165922ce289591416fa33114fad348b5e544ed;hpb=30c0a93ac5646f497d4f1eabd3ddb5132ea1c37a;p=metaproxy-moved-to-github.git diff --git a/src/sru_util.cpp b/src/sru_util.cpp index e116592..ef6a13e 100644 --- a/src/sru_util.cpp +++ b/src/sru_util.cpp @@ -1,5 +1,5 @@ -/* $Id: sru_util.cpp,v 1.5 2007-01-07 00:41:18 marc Exp $ - Copyright (c) 2005-2006, Index Data. +/* $Id: sru_util.cpp,v 1.9 2007-03-20 07:20:16 adam Exp $ + Copyright (c) 2005-2007, Index Data. See the LICENSE file for details */ @@ -36,14 +36,9 @@ bool mp_util::build_sru_debug_package(mp::Package &package) } mp_util::SRUServerInfo mp_util::get_sru_server_info(mp::Package &package) - //Z_SRW_explainRequest const *er_req) { mp_util::SRUServerInfo sruinfo; - // getting database info - //if (er_req && er_req->database) - // sruinfo.database = er_req->database; - // getting host and port info sruinfo.host = package.origin().listen_host(); sruinfo.port = mp_util::to_string(package.origin().listen_port()); @@ -55,21 +50,26 @@ mp_util::SRUServerInfo mp_util::get_sru_server_info(mp::Package &package) Z_HTTP_Request* http_req = zgdu_req->u.HTTP_Request; if (http_req) { - - //std::string http_method = http_req->method; - //std::string http_version = http_req->version; std::string http_path = http_req->path; - if (http_path.size() > 1) + + // taking out GET parameters + std::string::size_type ipath = http_path.rfind("?"); + if (ipath != std::string::npos) + http_path.assign(http_path, 0, ipath); + + // assign to database name + 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"); - std::string::size_type i = http_host_address.rfind(":"); - if (i != std::string::npos) + std::string::size_type iaddress = http_host_address.rfind(":"); + if (iaddress != std::string::npos) { - sruinfo.host.assign(http_host_address, 0, i); - sruinfo.port.assign(http_host_address, i + 1, + sruinfo.host.assign(http_host_address, 0, iaddress); + sruinfo.port.assign(http_host_address, iaddress + 1, std::string::npos); } } @@ -83,51 +83,6 @@ mp_util::SRUServerInfo mp_util::get_sru_server_info(mp::Package &package) } -// bool mp_util::build_simple_explain(mp::Package &package, -// mp::odr &odr_en, -// Z_SRW_PDU *sru_pdu_res, -// SRUServerInfo sruinfo, -// Z_SRW_explainRequest const *er_req) -// { -// // z3950'fy recordPacking -// int record_packing = Z_SRW_recordPacking_XML; -// if (er_req && er_req->recordPacking && 's' == *(er_req->recordPacking)) -// record_packing = Z_SRW_recordPacking_string; - -// // building SRU explain record -// std::string explain_xml -// = mp_util::to_string( -// "\n" -// " \n" -// " ") -// + sruinfo.host -// + mp_util::to_string("\n" -// " ") -// + sruinfo.port -// + mp_util::to_string("\n" -// " ") -// + sruinfo.database -// + mp_util::to_string("\n" -// " \n" -// "\n"); - - -// // preparing explain record insert -// Z_SRW_explainResponse *sru_res = sru_pdu_res->u.explain_response; - -// // inserting one and only explain record - -// sru_res->record.recordPosition = odr_intdup(odr_en, 1); -// sru_res->record.recordPacking = record_packing; -// sru_res->record.recordSchema = (char *)xmlns_explain.c_str(); -// sru_res->record.recordData_len = 1 + explain_xml.size(); -// sru_res->record.recordData_buf -// = odr_strdupn(odr_en, (const char *)explain_xml.c_str(), -// 1 + explain_xml.size()); - -// return true; -// }; - bool mp_util::build_sru_explain(metaproxy_1::Package &package, metaproxy_1::odr &odr_en, @@ -158,7 +113,15 @@ bool mp_util::build_sru_explain(metaproxy_1::Package &package, "\n"); } else { - explain_xml = ""; + // make new XML DOC with given explain node + xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); + xmlDocSetRootElement(doc, (xmlNode*)explain); + + xmlChar *xmlbuff; + int xmlbuffsz; + xmlDocDumpFormatMemory(doc, &xmlbuff, &xmlbuffsz, 1); + + explain_xml.assign((const char*)xmlbuff, 0, xmlbuffsz); } @@ -258,7 +221,7 @@ bool mp_util::build_sru_response(mp::Package &package, mp::odr &odr_de, mp::odr &odr_en, Z_SRW_PDU *sru_pdu_res, - Z_SOAP *&soap, + Z_SOAP **soap, char *charset, char *stylesheet) { @@ -278,7 +241,7 @@ bool mp_util::build_sru_response(mp::Package &package, // checking if we got a SRU GET/POST/SOAP HTTP package // closing connection if we did not ... - if (0 == yaz_sru_decode(http_req, &sru_pdu_req, &soap, + if (0 == yaz_sru_decode(http_req, &sru_pdu_req, soap, odr_de, &charset, &(sru_pdu_res->u.response->diagnostics), &(sru_pdu_res->u.response->num_diagnostics))) @@ -291,7 +254,7 @@ bool mp_util::build_sru_response(mp::Package &package, } return sru_pdu_req; } - else if (0 == yaz_srw_decode(http_req, &sru_pdu_req, &soap, + else if (0 == yaz_srw_decode(http_req, &sru_pdu_req, soap, odr_de, &charset)) return sru_pdu_req; else