From 83784d91a2132d98a3f3d81c0fdbfa9e6778b847 Mon Sep 17 00:00:00 2001 From: Marc Cromme Date: Wed, 13 Sep 2006 14:56:07 +0000 Subject: [PATCH] added more code to do protocol detection, experimented with different SRU and SRW decondings from YAZ. Much needs to be done .. --- src/filter_sru_to_z3950.cpp | 138 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 127 insertions(+), 11 deletions(-) diff --git a/src/filter_sru_to_z3950.cpp b/src/filter_sru_to_z3950.cpp index 260efeb..0718b94 100644 --- a/src/filter_sru_to_z3950.cpp +++ b/src/filter_sru_to_z3950.cpp @@ -1,28 +1,46 @@ -/* $Id: filter_sru_to_z3950.cpp,v 1.1 2006-09-13 10:43:24 marc Exp $ +/* $Id: filter_sru_to_z3950.cpp,v 1.2 2006-09-13 14:56:07 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details */ #include "config.hpp" - #include "filter.hpp" #include "package.hpp" - -#include - #include "util.hpp" #include "filter_sru_to_z3950.hpp" #include +#include + +#include + +#include +#include +#include + namespace mp = metaproxy_1; namespace yf = mp::filter; +namespace metaproxy_1 +{ + + template + std::string stringify(const T& x) + { + std::ostringstream o; + o << x; + return o.str(); + } +} + + namespace metaproxy_1 { namespace filter { class SRUtoZ3950::Rep { friend class SRUtoZ3950; + void process(metaproxy_1::Package & package) const; //int dummy; }; } @@ -39,6 +57,13 @@ yf::SRUtoZ3950::~SRUtoZ3950() void yf::SRUtoZ3950::process(mp::Package &package) const { + //std::cout << m_p->protocol_type(package) << "\n"; + //m_p->debug_http_headers(package); + m_p->process(package); +} + +void yf::SRUtoZ3950::Rep::process(mp::Package &package) const +{ Z_GDU *zgdu_req = package.request().get(); // ignoring all non HTTP_Request packages @@ -51,6 +76,94 @@ void yf::SRUtoZ3950::process(mp::Package &package) const Z_HTTP_Request* http_req = zgdu_req->u.HTTP_Request; // TODO: SRU package checking and translation to Z3950 package + + + +// int ret_code = 2; /* 2=NOT TAKEN, 1=TAKEN, 0=SOAP TAKEN */ +// Z_SRW_PDU *sru_res = 0; +// Z_SOAP *soap_package = 0; +// char *charset = 0; +// Z_SRW_diagnostic *diagnostic = 0; +// int num_diagnostic = 0; +// mp::odr odr; + +// if (!(ret_code = yaz_sru_decode(http_req, &sru_res, +// &soap_package, odr, &charset, +// &diagnostic, &num_diagnostic))) +// { +// protocol = "SRU GET/POST"; +// } +// else if (!(ret_code = yaz_srw_decode(http_req, &sru_res, +// &soap_package, odr, &charset))) +// { +// protocol = "SRU SOAP"; +// } +// else +// { +// protocol = "HTTP"; +// } + + std::string protocol("HTTP"); + + const std::string mime_text_xml("text/xml"); + const std::string mime_soap_xml("application/soap+xml"); + const std::string mime_urlencoded("application/x-www-form-urlencoded"); + + const std::string http_method(http_req->method); + const std::string http_type(z_HTTP_header_lookup(http_req->headers, + "Content-Type")); + + + if (http_method == "GET") + protocol = "SRU GET"; + else if ( http_method == "POST" + && http_type == mime_urlencoded) + protocol = "SRU POST"; + else if ( http_method == "POST" + && (http_type == mime_text_xml + || http_type == mime_soap_xml)) + protocol = "SRU SOAP"; + + std::cout << "SRUtoZ3950 " << protocol << "\n"; + + package.move(); + return; + + + + std::string message("\n\n

" + "Metaproxy SRUtoZ3950 filter" + "

\n"); + + message += "

HTTP Info


\n"; + message += "

\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:" + + std::string(z_HTTP_header_lookup(http_req->headers, "Content-Type")) + + "
\n"; + message += "Content-Length:" + + std::string(z_HTTP_header_lookup(http_req->headers, + "Content-Length")) + + "
\n"; + message += "

\n"; + + message += "

Headers


\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 += "

\n"; + message += "\n\n"; + + //std::cout << message << "\n"; + + // sending Z3950 package through pipeline package.move(); @@ -61,24 +174,27 @@ void yf::SRUtoZ3950::process(mp::Package &package) const Z_GDU *zgdu_res = 0; - metaproxy_1::odr odr; + mp::odr odr; zgdu_res = odr.create_HTTP_Response(package.session(), zgdu_req->u.HTTP_Request, 200); - //zgdu_res->u.HTTP_Response->content_len = message.str().size(); - //zgdu_res->u.HTTP_Response->content_buf - // = (char*) odr_malloc(odr, zgdu_res->u.HTTP_Response->content_len); + +// zgdu_res->u.HTTP_Response->content_len = message.size(); +// zgdu_res->u.HTTP_Response->content_buf +// = (char*) odr_malloc(odr, zgdu_res->u.HTTP_Response->content_len); - //strncpy(zgdu_res->u.HTTP_Response->content_buf, - // message.str().c_str(), zgdu_res->u.HTTP_Response->content_len); +// strncpy(zgdu_res->u.HTTP_Response->content_buf, +// message.c_str(), zgdu_res->u.HTTP_Response->content_len); // z_HTTP_header_add(o, &hres->headers, // "Content-Type", content_type.c_str()); + package.response() = zgdu_res; } + static mp::filter::Base* filter_creator() { return new mp::filter::SRUtoZ3950; -- 1.7.10.4