X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fex_filter_frontend_net.cpp;h=0b856e393b3c0f09b01d41e70392587a368a71af;hb=b35155fac04ac744e267e00a62d3db9cab23dcd7;hp=4478afb5183fd45d43dbb92fca7a1ecc95b4f93b;hpb=5058e9bd89a991caaa45b6988d1da399892c32e9;p=metaproxy-moved-to-github.git diff --git a/src/ex_filter_frontend_net.cpp b/src/ex_filter_frontend_net.cpp index 4478afb..0b856e3 100644 --- a/src/ex_filter_frontend_net.cpp +++ b/src/ex_filter_frontend_net.cpp @@ -1,36 +1,55 @@ +/* $Id: ex_filter_frontend_net.cpp,v 1.27 2006-06-10 14:29:11 adam Exp $ + Copyright (c) 2005-2006, Index Data. + + See the LICENSE file for details + */ + +#include "config.hpp" #include #include #include -#include "config.hpp" +#include +namespace po = boost::program_options; + +#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) { - // std::cout << "Got PDU. Sending init response\n"; - ODR odr = odr_createmem(ODR_ENCODE); - Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse); + 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"); - apdu->u.initResponse->implementationName = "YP2/YAZ"; + http_res->content_buf = + odr_strdup(odr, "Welcome to YP2"); + http_res->content_len = strlen(http_res->content_buf); - package.response() = apdu; - odr_destroy(odr); + package.response() = gdu; } return package.move(); }; @@ -40,22 +59,77 @@ int main(int argc, char **argv) { try { + po::options_description desc("Allowed options"); + desc.add_options() + ("help", "produce help message") + ("duration", po::value(), + "number of seconds for server to exist") + ("port", po::value< std::vector >(), "listener port") + ; + + po::positional_options_description p; + p.add("port", -1); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv). + options(desc).positional(p).run(), vm); + po::notify(vm); + + if (vm.count("help")) { + std::cout << desc << "\n"; + return 1; + } + + if (vm.count("port")) { - yp2::RouterChain router; + std::vector ports = + vm["port"].as< std::vector >(); + + for (size_t i = 0; i0 timeout in seconds + if (vm.count("duration")) { + filter_front.listen_duration() = vm["duration"].as(); + } + router.append(filter_front); + + // 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::Virt_db 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 in frontend first - yp2::FilterFrontendNet filter_front; - filter_front.listen_address() = "tcp:@:9999"; - //filter_front.listen_duration() = 1; // listen a short time only - router.rule(filter_front); + // put HTTP backend filter in router + HTTPFilter filter_init; + router.append(filter_init); - // put in a backend - FilterInit filter_init; - router.rule(filter_init); + // put Z39.50 backend filter in router + mp::filter::Z3950Client z3950_client; + router.append(z3950_client); - yp2::Session session; - yp2::Origin origin; - yp2::Package pack(session, origin); + mp::Session session; + mp::Origin origin; + mp::Package pack(session, origin); pack.router(router).move(); } @@ -64,12 +138,14 @@ int main(int argc, char **argv) std::cerr << "unknown exception\n"; std::exit(1); } + std::exit(0); } /* * Local variables: * c-basic-offset: 4 * indent-tabs-mode: nil + * c-file-style: "stroustrup" * End: * vim: shiftwidth=4 tabstop=8 expandtab */