03a9f5807c19199a9628c7fc22d33276871f3d09
[strongswan.git] / src / manager / main.c
1 /*
2 * Copyright (C) 2007 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * $Id$
16 */
17
18 #include <dispatcher.h>
19 #include <debug.h>
20 #include <stdio.h>
21
22 #include "manager.h"
23 #include "storage.h"
24 #include "controller/auth_controller.h"
25 #include "controller/ikesa_controller.h"
26 #include "controller/gateway_controller.h"
27 #include "controller/control_controller.h"
28 #include "controller/config_controller.h"
29
30 int main (int arc, char *argv[])
31 {
32 dispatcher_t *dispatcher;
33 storage_t *storage;
34 char *socket;
35 char *database;
36 bool debug;
37 int threads, timeout;
38
39 library_init(STRONGSWAN_CONF);
40 lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR, "libstrongswan-");
41
42 socket = lib->settings->get_str(lib->settings, "manager.socket", NULL);
43 debug = lib->settings->get_bool(lib->settings, "manager.debug", FALSE);
44 timeout = lib->settings->get_int(lib->settings, "manager.timeout", 900);
45 threads = lib->settings->get_int(lib->settings, "manager.threads", 10);
46 database = lib->settings->get_str(lib->settings, "manager.database", NULL);
47 if (!database)
48 {
49 DBG1("database URI undefined, set manager.database in strongswan.conf");
50 return 1;
51 }
52
53 storage = storage_create(database);
54 if (storage == NULL)
55 {
56 return 1;
57 }
58
59 dispatcher = dispatcher_create(socket, debug, timeout,
60 (context_constructor_t)manager_create, storage);
61 dispatcher->add_controller(dispatcher, ikesa_controller_create, NULL);
62 dispatcher->add_controller(dispatcher, gateway_controller_create, NULL);
63 dispatcher->add_controller(dispatcher, auth_controller_create, NULL);
64 dispatcher->add_controller(dispatcher, control_controller_create, NULL);
65 dispatcher->add_controller(dispatcher, config_controller_create, NULL);
66
67 dispatcher->run(dispatcher, threads);
68
69 dispatcher->waitsignal(dispatcher);
70
71 dispatcher->destroy(dispatcher);
72 storage->destroy(storage);
73
74 library_deinit();
75
76 return 0;
77 }
78