1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2011 Index Data
4 Metaproxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <yaz/options.h>
26 #include <metaproxy/util.hpp>
27 #include "filter_frontend_net.hpp"
28 #include "filter_z3950_client.hpp"
29 #include "filter_virt_db.hpp"
30 #include "filter_session_shared.hpp"
31 #include "filter_log.hpp"
33 #include "router_chain.hpp"
34 #include <metaproxy/package.hpp>
36 namespace mp = metaproxy_1;
38 class HTTPFilter: public mp::filter::Base {
40 void process(mp::Package & package) const {
41 if (package.session().is_closed())
43 // std::cout << "Got Close.\n";
46 Z_GDU *gdu = package.request().get();
47 if (gdu && gdu->which == Z_GDU_HTTP_Request)
50 Z_GDU *gdu = z_get_HTTP_Response(odr, 200);
51 Z_HTTP_Response *http_res = gdu->u.HTTP_Response;
53 z_HTTP_header_add(odr, &http_res->headers,
54 "Content-Type", "text/plain");
56 http_res->content_buf =
57 odr_strdup(odr, "Welcome to Metaproxy");
58 http_res->content_len = strlen(http_res->content_buf);
60 package.response() = gdu;
62 return package.move();
66 int main(int argc, char **argv)
70 std::vector<std::string> ports;
75 while ((ret = options("h{help}d{duration}:p{port}:",
76 argv, argc, &arg)) != -2)
81 std::cerr << "bad option " << arg << std::endl;
83 std::cerr << "ex_filter_frontend_net\n"
85 " -d|--duration n duration\n"
86 " -p|--port n port number\n"
98 for (size_t i = 0; i<ports.size(); i++)
99 std::cout << "port " << i << " " << ports[i] << "\n";
101 mp::RouterChain router;
103 // put frontend filter in router
104 mp::filter::FrontendNet filter_front;
105 filter_front.set_ports(ports);
107 // 0=no time, >0 timeout in seconds
109 filter_front.set_listen_duration(duration);
111 router.append(filter_front);
113 // put log filter in router
114 mp::filter::Log filter_log_front("FRONT");
115 router.append(filter_log_front);
117 // put Virt db filter in router
118 mp::filter::VirtualDB filter_virt_db;
119 filter_virt_db.add_map_db2target("gils", "indexdata.dk/gils",
121 filter_virt_db.add_map_db2target("Default", "localhost:9999/Default",
123 filter_virt_db.add_map_db2target("2", "localhost:9999/Slow", "");
124 router.append(filter_virt_db);
126 mp::filter::SessionShared filter_session_shared;
127 //router.append(filter_session_shared);
129 mp::filter::Log filter_log_back("BACK");
130 router.append(filter_log_back);
132 // put HTTP backend filter in router
133 HTTPFilter filter_init;
134 router.append(filter_init);
136 // put Z39.50 backend filter in router
137 mp::filter::Z3950Client z3950_client;
138 router.append(z3950_client);
142 mp::Package pack(session, origin);
144 pack.router(router).move();
148 std::cerr << "unknown exception\n";
157 * c-file-style: "Stroustrup"
158 * indent-tabs-mode: nil
160 * vim: shiftwidth=4 tabstop=8 expandtab