1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2008 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
22 #include <yaz/options.h>
23 #include <yaz/daemon.h>
27 #include <libxml/xinclude.h>
30 #include "package.hpp"
31 #include "router_flexml.hpp"
32 #include "factory_static.hpp"
41 namespace mp = metaproxy_1;
43 static void handler(void *data)
45 mp::RouterFleXML *routerp = (mp::RouterFleXML*) data;
48 pack.router(*routerp).move();
51 int main(int argc, char **argv)
55 const char *fname = 0;
59 const char *pidfile = 0;
62 while ((ret = options("c{config}:Dh{help}l:p:u:V{version}w:X",
63 argv, argc, &arg)) != -2)
71 mode = YAZ_DAEMON_FORK|YAZ_DAEMON_KEEPALIVE;
74 std::cerr << "metaproxy\n"
76 " -V|--version version\n"
77 " -c|--config f config filename\n"
78 " -D daemon and keepalive operation\n"
81 " -u id change uid to id\n"
82 " -w dir changes working directory to dir\n"
83 " -X debug mode (no fork/daemon mode)\n"
87 yaz_log_init_file(arg);
96 std::cout << VERSION "\n";
102 std::cerr << "chdir " << arg << " failed" << std::endl;
106 mode = YAZ_DAEMON_DEBUG;
109 std::cerr << "bad option: " << arg << std::endl;
115 std::cerr << "No configuration given; use -h for help\n";
119 yaz_log(YLOG_LOG, "Metaproxy " VERSION " started");
120 xmlDocPtr doc = xmlReadFile(fname,
122 XML_PARSE_XINCLUDE + XML_PARSE_NOBLANKS
123 + XML_PARSE_NSCLEAN + XML_PARSE_NONET );
127 std::cerr << "XML parsing failed\n";
130 // and perform Xinclude then
131 if (xmlXIncludeProcess(doc) > 0) {
132 std::cerr << "processing XInclude directive\n";
134 mp::FactoryStatic factory;
135 mp::RouterFleXML router(doc, factory, false);
137 yaz_daemon("metaproxy", mode, handler, &router, pidfile, uid);
139 catch (std::logic_error &e) {
140 std::cerr << "std::logic error: " << e.what() << "\n";
143 catch (std::runtime_error &e) {
144 std::cerr << "std::runtime error: " << e.what() << "\n";
148 std::cerr << "Unknown Exception" << std::endl;
158 * indent-tabs-mode: nil
159 * c-file-style: "stroustrup"
161 * vim: shiftwidth=4 tabstop=8 expandtab