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