X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fex_filter_frontend_net.cpp;h=a124e6a10ce5e7183a5093244496d4545fa95a55;hb=f1de0d00348a888657fa7940421de0a62e0c1957;hp=4ae21fa50a0778cc1be4ea1acef8828ec4b75fb7;hpb=fb02f5d8ceb8c0062dd976626c8517f7d78280ea;p=metaproxy-moved-to-github.git diff --git a/src/ex_filter_frontend_net.cpp b/src/ex_filter_frontend_net.cpp index 4ae21fa..a124e6a 100644 --- a/src/ex_filter_frontend_net.cpp +++ b/src/ex_filter_frontend_net.cpp @@ -1,3 +1,8 @@ +/* $Id: ex_filter_frontend_net.cpp,v 1.18 2005-11-14 23:35:22 adam Exp $ + Copyright (c) 2005, Index Data. + +%LICENSE% + */ #include #include @@ -8,52 +13,40 @@ namespace po = boost::program_options; #include "config.hpp" +#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 { +class HTTPFilter: public yp2::filter::Base { public: void process(yp2::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); + yp2::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(); }; @@ -68,10 +61,15 @@ int main(int argc, char **argv) ("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::parse_command_line(argc, argv, desc), vm); + po::store(po::command_line_parser(argc, argv). + options(desc).positional(p).run(), vm); po::notify(vm); if (vm.count("help")) { @@ -79,23 +77,49 @@ int main(int argc, char **argv) return 1; } + if (vm.count("port")) { + 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(); + filter_front.listen_duration() = vm["duration"].as(); } - router.rule(filter_front); + router.append(filter_front); + + // put log filter in router + yp2::filter::Log filter_log_front("FRONT"); + router.append(filter_log_front); + + // put Virt db filter in router + yp2::filter::Virt_db filter_virt_db; + filter_virt_db.add_map_db2vhost("gils", "indexdata.dk/gils"); + filter_virt_db.add_map_db2vhost("Default", "localhost:9100/Default"); +// router.append(filter_virt_db); + + yp2::filter::Session_shared filter_session_shared; + router.append(filter_session_shared); + + yp2::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 in a backend - FilterInit filter_init; - router.rule(filter_init); + // put Z39.50 backend filter in router + yp2::filter::Z3950Client z3950_client; + router.append(z3950_client); yp2::Session session; yp2::Origin origin; @@ -115,6 +139,7 @@ int main(int argc, char **argv) * Local variables: * c-basic-offset: 4 * indent-tabs-mode: nil + * c-file-style: "stroustrup" * End: * vim: shiftwidth=4 tabstop=8 expandtab */