1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2010 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>
28 #include <libxml/xinclude.h>
30 #include <metaproxy/filter.hpp>
31 #include <metaproxy/package.hpp>
32 #include "router_flexml.hpp"
33 #include "factory_static.hpp"
44 namespace mp = metaproxy_1;
46 static void handler(void *data)
48 mp::RouterFleXML *routerp = (mp::RouterFleXML*) data;
51 pack.router(*routerp).move();
56 int argc, char **argv)
60 const char *fname = 0;
64 const char *pidfile = 0;
67 while ((ret = options("c{config}:Dh{help}l:p:u:V{version}w:X",
68 argv, argc, &arg)) != -2)
76 mode = YAZ_DAEMON_FORK|YAZ_DAEMON_KEEPALIVE;
79 std::cerr << "metaproxy\n"
81 " -V|--version version\n"
82 " -c|--config f config filename\n"
83 " -D daemon and keepalive operation\n"
86 " -u id change uid to id\n"
87 " -w dir changes working directory to dir\n"
88 " -X debug mode (no fork/daemon mode)\n"
90 " -install install windows service\n"
91 " -remove remove windows service\n"
97 yaz_log_init_file(arg);
106 std::cout << VERSION "\n";
118 std::cerr << "chdir " << arg << " failed" << std::endl;
122 mode = YAZ_DAEMON_DEBUG;
125 std::cerr << "bad option: " << arg << std::endl;
131 std::cerr << "No configuration given; use -h for help\n";
135 yaz_log(YLOG_LOG, "Metaproxy " VERSION " started");
136 xmlDocPtr doc = xmlReadFile(fname,
138 XML_PARSE_XINCLUDE + XML_PARSE_NOBLANKS
139 + XML_PARSE_NSCLEAN + XML_PARSE_NONET );
143 yaz_log (YLOG_FATAL,"XML parsing failed");
146 // and perform Xinclude then
147 int r = xmlXIncludeProcess(doc);
150 yaz_log(YLOG_FATAL, "XInclude processing failed");
153 mp::FactoryStatic factory;
154 mp::RouterFleXML router(doc, factory, false);
158 yaz_daemon("metaproxy", mode, handler, &router, pidfile, uid);
160 catch (std::logic_error &e) {
161 yaz_log (YLOG_FATAL,"std::logic error: %s" , e.what() );
164 catch (std::runtime_error &e) {
165 yaz_log(YLOG_FATAL, "std::runtime error: %s" , e.what() );
169 yaz_log(YLOG_FATAL, "Unknown Exception");
175 static void sc_stop(yaz_sc_t s)
180 int main(int argc, char **argv)
183 yaz_sc_t s = yaz_sc_create("metaproxy", "metaproxy");
185 ret = yaz_sc_program(s, argc, argv, sc_main, sc_stop);
196 * c-file-style: "Stroustrup"
197 * indent-tabs-mode: nil
199 * vim: shiftwidth=4 tabstop=8 expandtab