X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Fex_filter_frontend_net.cpp;h=76264f91657960edd06e930f090747a1a6e22522;hb=f82b19f2b93707657fee804bd1242f2548d51ada;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..76264f9 100644 --- a/src/ex_filter_frontend_net.cpp +++ b/src/ex_filter_frontend_net.cpp @@ -1,35 +1,64 @@ +/* $Id: ex_filter_frontend_net.cpp,v 1.7 2005-10-15 14:09:09 adam Exp $ + Copyright (c) 2005, Index Data. + +%LICENSE% + */ #include #include #include +#include +namespace po = boost::program_options; + #include "config.hpp" #include "filter_frontend_net.hpp" +#include "filter_log.hpp" #include "router.hpp" #include "session.hpp" #include "package.hpp" -class FilterInit: public yp2::Filter { +class FilterInit: 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) { - // std::cout << "Got PDU. Sending init response\n"; ODR odr = odr_createmem(ODR_ENCODE); - Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse); - - apdu->u.initResponse->implementationName = "YP2/YAZ"; - - package.response() = apdu; + 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); } return package.move(); @@ -40,16 +69,52 @@ 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")) { + 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.rule(filter_front); - // put in a backend + // put log filter in router + yp2::filter::Log filter_log; + router.rule(filter_log); + + // put backend init filter in router FilterInit filter_init; router.rule(filter_init); @@ -64,12 +129,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 */