X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Fex_filter_frontend_net.cpp;h=4ae21fa50a0778cc1be4ea1acef8828ec4b75fb7;hb=fb02f5d8ceb8c0062dd976626c8517f7d78280ea;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..4ae21fa 100644 --- a/src/ex_filter_frontend_net.cpp +++ b/src/ex_filter_frontend_net.cpp @@ -3,6 +3,9 @@ #include #include +#include +namespace po = boost::program_options; + #include "config.hpp" #include "filter_frontend_net.hpp" @@ -23,13 +26,33 @@ public: 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,13 +63,34 @@ 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") + ; + + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + + if (vm.count("help")) { + std::cout << desc << "\n"; + return 1; + } + { yp2::RouterChain router; // put in frontend first yp2::FilterFrontendNet filter_front; filter_front.listen_address() = "tcp:@:9999"; - //filter_front.listen_duration() = 1; // listen a short time only + + // 0=no time, >0 timeout in seconds + if (vm.count("duration")) { + filter_front.listen_duration() = + vm["duration"].as(); + } router.rule(filter_front); // put in a backend @@ -64,6 +108,7 @@ int main(int argc, char **argv) std::cerr << "unknown exception\n"; std::exit(1); } + std::exit(0); } /*