Bump year in copyright msg in source
[metaproxy-moved-to-github.git] / src / ex_filter_frontend_net.cpp
index 15e6b55..f9a4ef4 100644 (file)
@@ -1,8 +1,20 @@
-/* $Id: ex_filter_frontend_net.cpp,v 1.25 2006-01-16 15:51:56 adam Exp $
-   Copyright (c) 2005, Index Data.
+/* This file is part of Metaproxy.
+   Copyright (C) 2005-2009 Index Data
 
-%LICENSE%
- */
+Metaproxy is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
 
 #include "config.hpp"
 
 #include <iostream>
 #include <stdexcept>
 
-#include <boost/program_options.hpp>
-namespace po = boost::program_options;
-
-
+#include <yaz/options.h>
 #include "util.hpp"
 #include "filter_frontend_net.hpp"
 #include "filter_z3950_client.hpp"
@@ -25,9 +34,11 @@ namespace po = boost::program_options;
 #include "session.hpp"
 #include "package.hpp"
 
-class HTTPFilter: public yp2::filter::Base {
+namespace mp = metaproxy_1;
+
+class HTTPFilter: public mp::filter::Base {
 public:
-    void process(yp2::Package & package) const {
+    void process(mp::Package & package) const {
         if (package.session().is_closed())
         {
             // std::cout << "Got Close.\n";
@@ -36,7 +47,7 @@ public:
         Z_GDU *gdu = package.request().get();
         if (gdu && gdu->which == Z_GDU_HTTP_Request)
         {
-            yp2::odr odr;
+            mp::odr odr;
             Z_GDU *gdu = z_get_HTTP_Response(odr, 200);
             Z_HTTP_Response *http_res = gdu->u.HTTP_Response;
             
@@ -57,53 +68,55 @@ int main(int argc, char **argv)
 {
     try 
     {
-        po::options_description desc("Allowed options");
-        desc.add_options()
-            ("help", "produce help message")
-            ("duration", po::value<int>(),
-             "number of seconds for server to exist")
-            ("port", po::value< std::vector<std::string> >(), "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;
-        }
+        std::vector<std::string> ports;
+        int duration = -1;
+        int ret;
+        char *arg;
 
-        if (vm.count("port"))
+        while ((ret = options("h{help}d{duration}:p{port}:", 
+                              argv, argc, &arg)) != -2)
+        {
+            switch(ret)
+            {
+            case -1:
+                std::cerr << "bad option " << arg << std::endl;
+            case 'h':
+                std::cerr << "ex_filter_frontend_net\n"
+                    " -h|--help       help\n"
+                    " -d|--duration n duration\n"
+                    " -p|--port n     port number\n"
+                          << std::endl;
+                break;
+            case 'p':
+                ports.push_back(arg);
+                break;
+            case 'd':
+                duration = atoi(arg);
+                break;
+            }
+        }
         {
-            std::vector<std::string> ports = 
-                vm["port"].as< std::vector<std::string> >();
-
             for (size_t i = 0; i<ports.size(); i++)
                 std::cout << "port " << i << " " << ports[i] << "\n";
 
-           yp2::RouterChain router;
+           mp::RouterChain router;
 
             // put frontend filter in router
-            yp2::filter::FrontendNet filter_front;
-            filter_front.ports() = ports;
+            mp::filter::FrontendNet filter_front;
+            filter_front.set_ports(ports);
 
             // 0=no time, >0 timeout in seconds
-            if (vm.count("duration")) {
-                filter_front.listen_duration() = vm["duration"].as<int>();
-            }
+            if (duration != -1)
+                filter_front.set_listen_duration(duration);
+
            router.append(filter_front);
 
             // put log filter in router
-            yp2::filter::Log filter_log_front("FRONT");
+            mp::filter::Log filter_log_front("FRONT");
             router.append(filter_log_front);
 
             // put Virt db filter in router
-            yp2::filter::Virt_db filter_virt_db;
+            mp::filter::VirtualDB filter_virt_db;
             filter_virt_db.add_map_db2target("gils", "indexdata.dk/gils",
                                             "");
             filter_virt_db.add_map_db2target("Default", "localhost:9999/Default",
@@ -111,10 +124,10 @@ int main(int argc, char **argv)
             filter_virt_db.add_map_db2target("2", "localhost:9999/Slow", "");
            router.append(filter_virt_db);
 
-            yp2::filter::SessionShared filter_session_shared;
+            mp::filter::SessionShared filter_session_shared;
             //router.append(filter_session_shared);
 
-            yp2::filter::Log filter_log_back("BACK");
+            mp::filter::Log filter_log_back("BACK");
             router.append(filter_log_back);
 
             // put HTTP backend filter in router
@@ -122,12 +135,12 @@ int main(int argc, char **argv)
            router.append(filter_init);
 
             // put Z39.50 backend filter in router
-            yp2::filter::Z3950Client z3950_client;
+            mp::filter::Z3950Client z3950_client;
            router.append(z3950_client);
 
-            yp2::Session session;
-            yp2::Origin origin;
-           yp2::Package pack(session, origin);
+            mp::Session session;
+            mp::Origin origin;
+           mp::Package pack(session, origin);
            
            pack.router(router).move(); 
         }
@@ -142,8 +155,9 @@ int main(int argc, char **argv)
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
- * c-file-style: "stroustrup"
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab
  */
+