26 #include <metaproxy/package.hpp>
27 #include <metaproxy/util.hpp>
35 namespace yf = mp::filter;
47 yf::Bounce::Bounce() : m_p(new
Rep)
58 static void http_echo(mp::odr &odr, Z_GDU *zgdu, Z_GDU *zgdu_res)
61 ODR enc = odr_createmem(ODR_ENCODE);
63 (void) z_GDU(enc, &zgdu, 0, 0);
64 char *buf = odr_getbuf(enc, &len, 0);
66 Z_HTTP_Response *hres = zgdu_res->u.HTTP_Response;
69 z_HTTP_header_set(odr, &hres->headers,
70 "Content-Type",
"text/plain");
72 hres->content_buf = (
char*) odr_malloc(odr, len);
73 memcpy(hres->content_buf, buf, len);
74 hres->content_len = len;
81 void yf::Bounce::process(mp::Package &package)
const
83 package.session().close();
85 Z_GDU *zgdu = package.request().get();
91 std::ostringstream message;
92 message <<
"BOUNCE " << *zgdu;
96 if (zgdu->which == Z_GDU_Z3950)
99 apdu_res = odr.create_close(zgdu->u.z3950,
100 Z_Close_systemProblem,
101 message.str().c_str());
104 package.response() = apdu_res;
106 else if (zgdu->which == Z_GDU_HTTP_Request)
110 = odr.create_HTTP_Response(package.session(),
111 zgdu->u.HTTP_Request, 400);
116 package.response() = zgdu_res;
118 else if (zgdu->which == Z_GDU_HTTP_Response)
126 void mp::filter::Bounce::configure(
const xmlNode * ptr,
bool test_only,
129 for (ptr = ptr->children; ptr; ptr = ptr->next)
131 if (ptr->type != XML_ELEMENT_NODE)
133 else if (!strcmp((
const char *) ptr->name,
"echo"))
135 m_p->echo = mp::xml::get_bool(ptr, 0);
139 throw mp::filter::FilterException
141 + std::string((
const char *) ptr->name)
142 +
"' in bounce filter");
150 return new mp::filter::Bounce;
struct metaproxy_1_filter_struct metaproxy_1_filter_bounce
static mp::filter::Base * filter_creator()
static void http_echo(mp::odr &odr, Z_GDU *zgdu, Z_GDU *zgdu_res)