1 /* $Id: ex_filter_frontend_net.cpp,v 1.32 2008-02-20 15:07:51 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 <yaz/options.h>
30 #include "filter_frontend_net.hpp"
31 #include "filter_z3950_client.hpp"
32 #include "filter_virt_db.hpp"
33 #include "filter_session_shared.hpp"
34 #include "filter_log.hpp"
36 #include "router_chain.hpp"
37 #include "session.hpp"
38 #include "package.hpp"
40 namespace mp = metaproxy_1;
42 class HTTPFilter: public mp::filter::Base {
44 void process(mp::Package & package) const {
45 if (package.session().is_closed())
47 // std::cout << "Got Close.\n";
50 Z_GDU *gdu = package.request().get();
51 if (gdu && gdu->which == Z_GDU_HTTP_Request)
54 Z_GDU *gdu = z_get_HTTP_Response(odr, 200);
55 Z_HTTP_Response *http_res = gdu->u.HTTP_Response;
57 z_HTTP_header_add(odr, &http_res->headers,
58 "Content-Type", "text/plain");
60 http_res->content_buf =
61 odr_strdup(odr, "Welcome to YP2");
62 http_res->content_len = strlen(http_res->content_buf);
64 package.response() = gdu;
66 return package.move();
70 int main(int argc, char **argv)
74 std::vector<std::string> ports;
79 while ((ret = options("h{help}d{duration}:p{port}:",
80 argv, argc, &arg)) != -2)
85 std::cerr << "bad option " << arg << std::endl;
87 std::cerr << "ex_filter_frontend_net\n"
89 " -d|--duration n duration\n"
90 " -p|--port n port number\n"
102 for (size_t i = 0; i<ports.size(); i++)
103 std::cout << "port " << i << " " << ports[i] << "\n";
105 mp::RouterChain router;
107 // put frontend filter in router
108 mp::filter::FrontendNet filter_front;
109 filter_front.set_ports(ports);
111 // 0=no time, >0 timeout in seconds
113 filter_front.set_listen_duration(duration);
115 router.append(filter_front);
117 // put log filter in router
118 mp::filter::Log filter_log_front("FRONT");
119 router.append(filter_log_front);
121 // put Virt db filter in router
122 mp::filter::VirtualDB filter_virt_db;
123 filter_virt_db.add_map_db2target("gils", "indexdata.dk/gils",
125 filter_virt_db.add_map_db2target("Default", "localhost:9999/Default",
127 filter_virt_db.add_map_db2target("2", "localhost:9999/Slow", "");
128 router.append(filter_virt_db);
130 mp::filter::SessionShared filter_session_shared;
131 //router.append(filter_session_shared);
133 mp::filter::Log filter_log_back("BACK");
134 router.append(filter_log_back);
136 // put HTTP backend filter in router
137 HTTPFilter filter_init;
138 router.append(filter_init);
140 // put Z39.50 backend filter in router
141 mp::filter::Z3950Client z3950_client;
142 router.append(z3950_client);
146 mp::Package pack(session, origin);
148 pack.router(router).move();
152 std::cerr << "unknown exception\n";
161 * indent-tabs-mode: nil
162 * c-file-style: "stroustrup"
164 * vim: shiftwidth=4 tabstop=8 expandtab