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"
38 namespace mp = metaproxy_1;
40 static void handler(void *data)
42 mp::RouterFleXML *routerp = (mp::RouterFleXML*) data;
45 pack.router(*routerp).move();
48 int main(int argc, char **argv)
52 const char *fname = 0;
56 const char *pidfile = 0;
59 while ((ret = options("c{config}:Dh{help}l:p:u:V{version}w:X",
60 argv, argc, &arg)) != -2)
68 mode = YAZ_DAEMON_FORK|YAZ_DAEMON_KEEPALIVE;
71 std::cerr << "metaproxy\n"
73 " -V|--version version\n"
74 " -c|--config f config filename\n"
75 " -D daemon and keepalive operation\n"
78 " -u id change uid to id\n"
79 " -w dir changes working directory to dir\n"
80 " -X debug mode (no fork/daemon mode)\n"
84 yaz_log_init_file(arg);
93 std::cout << VERSION "\n";
99 std::cerr << "chdir " << arg << " failed" << std::endl;
103 mode = YAZ_DAEMON_DEBUG;
106 std::cerr << "bad option: " << arg << std::endl;
112 std::cerr << "No configuration given; use -h for help\n";
116 yaz_log(YLOG_LOG, "Metaproxy " VERSION " started");
117 xmlDocPtr doc = xmlReadFile(fname,
119 XML_PARSE_XINCLUDE + XML_PARSE_NOBLANKS
120 + XML_PARSE_NSCLEAN + XML_PARSE_NONET );
124 std::cerr << "XML parsing failed\n";
127 // and perform Xinclude then
128 if (xmlXIncludeProcess(doc) > 0) {
129 std::cerr << "processing XInclude directive\n";
131 mp::FactoryStatic factory;
132 mp::RouterFleXML router(doc, factory, false);
134 yaz_daemon("metaproxy", mode, handler, &router, pidfile, uid);
136 catch (std::logic_error &e) {
137 std::cerr << "std::logic error: " << e.what() << "\n";
140 catch (std::runtime_error &e) {
141 std::cerr << "std::runtime error: " << e.what() << "\n";
145 std::cerr << "Unknown Exception" << std::endl;
155 * indent-tabs-mode: nil
156 * c-file-style: "stroustrup"
158 * vim: shiftwidth=4 tabstop=8 expandtab