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"
34 namespace mp = metaproxy_1;
36 static void handler(void *data)
38 mp::RouterFleXML *routerp = (mp::RouterFleXML*) data;
41 pack.router(*routerp).move();
44 int main(int argc, char **argv)
48 const char *fname = 0;
52 const char *pidfile = 0;
55 while ((ret = options("c{config}:Dh{help}l:p:u:V{version}X",
56 argv, argc, &arg)) != -2)
64 mode = YAZ_DAEMON_FORK|YAZ_DAEMON_KEEPALIVE;
67 std::cerr << "metaproxy\n"
69 " -V|--version version\n"
70 " -c|--config f config filename\n"
71 " -D daemon and keepalive operation\n"
74 " -u id change uid to id\n"
75 " -X debug mode (no fork/daemon mode)\n"
79 yaz_log_init_file(arg);
88 std::cout << VERSION "\n";
92 mode = YAZ_DAEMON_DEBUG;
95 std::cerr << "bad option: " << arg << std::endl;
101 std::cerr << "No configuration given; use -h for help\n";
105 yaz_log(YLOG_LOG, "Metaproxy " VERSION " started");
106 xmlDocPtr doc = xmlReadFile(fname,
108 XML_PARSE_XINCLUDE + XML_PARSE_NOBLANKS
109 + XML_PARSE_NSCLEAN + XML_PARSE_NONET );
113 std::cerr << "XML parsing failed\n";
116 // and perform Xinclude then
117 if (xmlXIncludeProcess(doc) > 0) {
118 std::cerr << "processing XInclude directive\n";
120 mp::FactoryStatic factory;
121 mp::RouterFleXML router(doc, factory, false);
123 yaz_daemon("metaproxy", mode, handler, &router, pidfile, uid);
125 catch (std::logic_error &e) {
126 std::cerr << "std::logic error: " << e.what() << "\n";
129 catch (std::runtime_error &e) {
130 std::cerr << "std::runtime error: " << e.what() << "\n";
134 std::cerr << "Unknown Exception" << std::endl;
144 * indent-tabs-mode: nil
145 * c-file-style: "stroustrup"
147 * vim: shiftwidth=4 tabstop=8 expandtab