X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fex_filter_frontend_net.cpp;h=f9a4ef41e0c6ac2568602c529efbc38bec7817c9;hb=d0123337d70b0fb97b578cc57467bb94980f1014;hp=f8cbf5ae40452510a92423beb5b74b2a1bc577c9;hpb=bb5caa9f44b4e94c814a214881d42bff4a2be027;p=metaproxy-moved-to-github.git diff --git a/src/ex_filter_frontend_net.cpp b/src/ex_filter_frontend_net.cpp index f8cbf5a..f9a4ef4 100644 --- a/src/ex_filter_frontend_net.cpp +++ b/src/ex_filter_frontend_net.cpp @@ -1,57 +1,65 @@ +/* This file is part of Metaproxy. + 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 +Software Foundation; either version 2, or (at your option) any later +version. + +Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "config.hpp" #include #include #include -#include "config.hpp" - +#include +#include "util.hpp" #include "filter_frontend_net.hpp" +#include "filter_z3950_client.hpp" +#include "filter_virt_db.hpp" +#include "filter_session_shared.hpp" +#include "filter_log.hpp" -#include "router.hpp" +#include "router_chain.hpp" #include "session.hpp" #include "package.hpp" -class FilterInit: public yp2::Filter { -public: - void process(yp2::Package & package) const { +namespace mp = metaproxy_1; +class HTTPFilter: public mp::filter::Base { +public: + void process(mp::Package & package) const { if (package.session().is_closed()) { // std::cout << "Got Close.\n"; } - + Z_GDU *gdu = package.request().get(); - if (gdu) + if (gdu && gdu->which == Z_GDU_HTTP_Request) { - ODR odr = odr_createmem(ODR_ENCODE); - switch(gdu->which) - { - case Z_GDU_Z3950: - // std::cout << "Got PDU. Sending init response\n"; - Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse); - - apdu->u.initResponse->implementationName = "YP2/YAZ"; - - package.response() = apdu; - break; - case Z_GDU_HTTP_Request: - Z_GDU *gdu = z_get_HTTP_Response(odr, 200); - Z_HTTP_Response *http_res = gdu->u.HTTP_Response; - - z_HTTP_header_add(odr, &http_res->headers, - "Content-Type", "text/plain"); - - http_res->content_buf = - odr_strdup(odr, "Welcome to YP2"); - http_res->content_len = strlen(http_res->content_buf); - - package.response() = gdu; - break; - default: - break; - } - odr_destroy(odr); - } + mp::odr odr; + Z_GDU *gdu = z_get_HTTP_Response(odr, 200); + Z_HTTP_Response *http_res = gdu->u.HTTP_Response; + + z_HTTP_header_add(odr, &http_res->headers, + "Content-Type", "text/plain"); + + http_res->content_buf = + odr_strdup(odr, "Welcome to YP2"); + http_res->content_len = strlen(http_res->content_buf); + + package.response() = gdu; + } return package.move(); }; }; @@ -60,24 +68,79 @@ int main(int argc, char **argv) { try { + std::vector ports; + int duration = -1; + int ret; + char *arg; + + while ((ret = options("h{help}d{duration}:p{port}:", + argv, argc, &arg)) != -2) + { + switch(ret) + { + case -1: + std::cerr << "bad option " << arg << std::endl; + case 'h': + std::cerr << "ex_filter_frontend_net\n" + " -h|--help help\n" + " -d|--duration n duration\n" + " -p|--port n port number\n" + << std::endl; + break; + case 'p': + ports.push_back(arg); + break; + case 'd': + duration = atoi(arg); + break; + } + } { - yp2::RouterChain router; + for (size_t i = 0; i0 timeout in seconds - filter_front.listen_duration() = 0; - router.rule(filter_front); + if (duration != -1) + filter_front.set_listen_duration(duration); - // put in a backend - FilterInit filter_init; - router.rule(filter_init); + router.append(filter_front); - yp2::Session session; - yp2::Origin origin; - yp2::Package pack(session, origin); + // put log filter in router + mp::filter::Log filter_log_front("FRONT"); + router.append(filter_log_front); + + // put Virt db filter in router + mp::filter::VirtualDB filter_virt_db; + filter_virt_db.add_map_db2target("gils", "indexdata.dk/gils", + ""); + filter_virt_db.add_map_db2target("Default", "localhost:9999/Default", + ""); + filter_virt_db.add_map_db2target("2", "localhost:9999/Slow", ""); + router.append(filter_virt_db); + + mp::filter::SessionShared filter_session_shared; + //router.append(filter_session_shared); + + mp::filter::Log filter_log_back("BACK"); + router.append(filter_log_back); + + // put HTTP backend filter in router + HTTPFilter filter_init; + router.append(filter_init); + + // put Z39.50 backend filter in router + mp::filter::Z3950Client z3950_client; + router.append(z3950_client); + + mp::Session session; + mp::Origin origin; + mp::Package pack(session, origin); pack.router(router).move(); } @@ -86,12 +149,15 @@ int main(int argc, char **argv) std::cerr << "unknown exception\n"; std::exit(1); } + std::exit(0); } /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab */ +