/* This file is part of Metaproxy.
- Copyright (C) 2005-2009 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
*/
#include "sru_util.hpp"
-#include "util.hpp"
-
-//#include <yaz/wrbuf.h>
-//#include <yaz/querytowrbuf.h>
+#include <metaproxy/util.hpp>
#include <iostream>
#include <string>
mp_util::SRUServerInfo sruinfo;
// getting host and port info
- sruinfo.host = package.origin().listen_host();
- sruinfo.port = mp_util::to_string(package.origin().listen_port());
+ sruinfo.host = "localhost";
+ sruinfo.port = "80";
// overwriting host and port info if set from HTTP Host header
Z_GDU *zgdu_req = package.request().get();
// building SRU explain record
std::string explain_xml;
- if (explain == 0){
+ if (explain == 0)
+ {
explain_xml
= mp_util::to_string(
"<explain xmlns=\"" + xmlns_explain + "\">\n"
" </serverInfo>\n"
"</explain>\n");
}
- else {
+ else
+ {
// make new XML DOC with given explain node
xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
xmlDocSetRootElement(doc, (xmlNode*)explain);
bool mp_util::build_sru_response(mp::Package &package,
- mp::odr &odr_en,
- Z_SOAP *soap,
- const Z_SRW_PDU *sru_pdu_res,
- char *charset,
- const char *stylesheet)
+ mp::odr &odr_en,
+ Z_SOAP *soap,
+ const Z_SRW_PDU *sru_pdu_res,
+ char *charset,
+ const char *stylesheet)
{
// SRU request package translation to Z3950 package
//http_res->code = http_code;
std::string ctype("text/xml");
- if (charset){
+ if (charset)
+ {
ctype += "; charset=";
ctype += charset;
}
z_HTTP_header_add(odr_en,
&http_res->headers, "Content-Type", ctype.c_str());
- // packaging Z_SOAP into HTML response
- static Z_SOAP_Handler soap_handlers[4] = {
- {"http://www.loc.gov/zing/srw/", 0,
- (Z_SOAP_fun) yaz_srw_codec},
- {"http://www.loc.gov/zing/srw/v1.0/", 0,
- (Z_SOAP_fun) yaz_srw_codec},
- {"http://www.loc.gov/zing/srw/update/", 0,
- (Z_SOAP_fun) yaz_ucp_codec},
- {0, 0, 0}
- };
-
-
- // empty stylesheet means NO stylesheet
- if (stylesheet && *stylesheet == '\0')
- stylesheet = 0;
+ // packaging Z_SOAP into HTML response
+ static Z_SOAP_Handler soap_handlers[4] = {
+ {(char *)YAZ_XMLNS_SRU_v1_1, 0, (Z_SOAP_fun) yaz_srw_codec},
+ {(char *)YAZ_XMLNS_SRU_v1_0, 0, (Z_SOAP_fun) yaz_srw_codec},
+ {(char *)YAZ_XMLNS_UPDATE_v0_9, 0, (Z_SOAP_fun) yaz_ucp_codec},
+ {0, 0, 0}
+ };
+
+
+ // empty stylesheet means NO stylesheet
+ if (stylesheet && *stylesheet == '\0')
+ stylesheet = 0;
- // encoding SRU package
+ // encoding SRU package
- soap->u.generic->p = (void*) sru_pdu_res;
- //int ret =
- z_soap_codec_enc_xsl(odr_en, &soap,
- &http_res->content_buf, &http_res->content_len,
- soap_handlers, charset, stylesheet);
+ soap->u.generic->p = (void*) sru_pdu_res;
+ //int ret =
+ z_soap_codec_enc_xsl(odr_en, &soap,
+ &http_res->content_buf, &http_res->content_len,
+ soap_handlers, charset, stylesheet);
- package.response() = zgdu_res;
- return true;
+ package.response() = zgdu_res;
+ return true;
}
package.session().close();
return false;
yaz_add_srw_diagnostic(odr_en,
&(sru_pdu_res->u.response->diagnostics),
&(sru_pdu_res->u.response->num_diagnostics),
- 7, "query");
+ YAZ_SRW_MANDATORY_PARAMETER_NOT_SUPPLIED,
+ "query");
yaz_add_srw_diagnostic(odr_en,
&(sru_pdu_res->u.response->diagnostics),
&(sru_pdu_res->u.response->num_diagnostics),
- 10, "CQL query is empty");
+ YAZ_SRW_QUERY_SYNTAX_ERROR,
+ "CQL query is empty");
return false;
}
if ((sr_req->query_type == Z_SRW_query_type_xcql && !sr_req->query.xcql))
{
- yaz_add_srw_diagnostic(odr_en,
+ yaz_add_srw_diagnostic(odr_en,
&(sru_pdu_res->u.response->diagnostics),
&(sru_pdu_res->u.response->num_diagnostics),
- 10, "XCQL query is empty");
- return false;
+ YAZ_SRW_QUERY_SYNTAX_ERROR,
+ "XCQL query is empty");
+ return false;
}
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),
&(sru_pdu_res->u.response->num_diagnostics),
- 10, "PQF query is empty");
+ YAZ_SRW_QUERY_SYNTAX_ERROR,
+ "PQF query is empty");
return false;
}
return true;
{
os << "SRU";
- switch(srw_pdu.which) {
+ switch (srw_pdu.which)
+ {
case Z_SRW_searchRetrieve_request:
os << " " << "searchRetrieveRequest";
{