1 /* $Id: ex_filter_frontend_net.cpp,v 1.30 2007-05-09 21:23:09 adam Exp $
2 Copyright (c) 2005-2007, Index Data.
4 This file is part of Metaproxy.
6 Metaproxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with Metaproxy; see the file LICENSE. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
28 #include <boost/program_options.hpp>
29 namespace po = boost::program_options;
33 #include "filter_frontend_net.hpp"
34 #include "filter_z3950_client.hpp"
35 #include "filter_virt_db.hpp"
36 #include "filter_session_shared.hpp"
37 #include "filter_log.hpp"
39 #include "router_chain.hpp"
40 #include "session.hpp"
41 #include "package.hpp"
43 namespace mp = metaproxy_1;
45 class HTTPFilter: public mp::filter::Base {
47 void process(mp::Package & package) const {
48 if (package.session().is_closed())
50 // std::cout << "Got Close.\n";
53 Z_GDU *gdu = package.request().get();
54 if (gdu && gdu->which == Z_GDU_HTTP_Request)
57 Z_GDU *gdu = z_get_HTTP_Response(odr, 200);
58 Z_HTTP_Response *http_res = gdu->u.HTTP_Response;
60 z_HTTP_header_add(odr, &http_res->headers,
61 "Content-Type", "text/plain");
63 http_res->content_buf =
64 odr_strdup(odr, "Welcome to YP2");
65 http_res->content_len = strlen(http_res->content_buf);
67 package.response() = gdu;
69 return package.move();
73 int main(int argc, char **argv)
77 po::options_description desc("Allowed options");
79 ("help", "produce help message")
80 ("duration", po::value<int>(),
81 "number of seconds for server to exist")
82 ("port", po::value< std::vector<std::string> >(), "listener port")
85 po::positional_options_description p;
89 po::store(po::command_line_parser(argc, argv).
90 options(desc).positional(p).run(), vm);
93 if (vm.count("help")) {
94 std::cout << desc << "\n";
100 std::vector<std::string> ports =
101 vm["port"].as< std::vector<std::string> >();
103 for (size_t i = 0; i<ports.size(); i++)
104 std::cout << "port " << i << " " << ports[i] << "\n";
106 mp::RouterChain router;
108 // put frontend filter in router
109 mp::filter::FrontendNet filter_front;
110 filter_front.ports() = ports;
112 // 0=no time, >0 timeout in seconds
113 if (vm.count("duration")) {
114 filter_front.listen_duration() = vm["duration"].as<int>();
116 router.append(filter_front);
118 // put log filter in router
119 mp::filter::Log filter_log_front("FRONT");
120 router.append(filter_log_front);
122 // put Virt db filter in router
123 mp::filter::VirtualDB filter_virt_db;
124 filter_virt_db.add_map_db2target("gils", "indexdata.dk/gils",
126 filter_virt_db.add_map_db2target("Default", "localhost:9999/Default",
128 filter_virt_db.add_map_db2target("2", "localhost:9999/Slow", "");
129 router.append(filter_virt_db);
131 mp::filter::SessionShared filter_session_shared;
132 //router.append(filter_session_shared);
134 mp::filter::Log filter_log_back("BACK");
135 router.append(filter_log_back);
137 // put HTTP backend filter in router
138 HTTPFilter filter_init;
139 router.append(filter_init);
141 // put Z39.50 backend filter in router
142 mp::filter::Z3950Client z3950_client;
143 router.append(z3950_client);
147 mp::Package pack(session, origin);
149 pack.router(router).move();
153 std::cerr << "unknown exception\n";
162 * indent-tabs-mode: nil
163 * c-file-style: "stroustrup"
165 * vim: shiftwidth=4 tabstop=8 expandtab