20dec9d37292aa1b0ef0814c1c969204d16223a2
[strongswan.git] / src / medsrv / main.c
1 /*
2 * Copyright (C) 2008 Martin Willi
3 * Copyright (C) 2008 Philip Boetschi, Adrian Doerig
4 * Hochschule fuer Technik Rapperswil
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 <stdio.h>
18
19 #include <dispatcher.h>
20 #include <debug.h>
21 #include <database/database.h>
22
23 #include "filter/auth_filter.h"
24 #include "controller/user_controller.h"
25 #include "controller/peer_controller.h"
26
27 int main(int arc, char *argv[])
28 {
29 dispatcher_t *dispatcher;
30 database_t *db;
31 char *socket;
32 bool debug;
33 char *uri;
34 int timeout, threads;
35
36 library_init(STRONGSWAN_CONF);
37 lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR,
38 lib->settings->get_str(lib->settings, "medsrv.load", PLUGINS));
39
40 socket = lib->settings->get_str(lib->settings, "medsrv.socket", NULL);
41 debug = lib->settings->get_bool(lib->settings, "medsrv.debug", FALSE);
42 timeout = lib->settings->get_time(lib->settings, "medsrv.timeout", 900);
43 threads = lib->settings->get_int(lib->settings, "medsrv.threads", 5);
44 uri = lib->settings->get_str(lib->settings, "medsrv.database", NULL);
45 if (uri == NULL)
46 {
47 fprintf(stderr, "database URI medsrv.database not defined.\n");
48 return 1;
49 }
50
51 db = lib->db->create(lib->db, uri);
52 if (db == NULL)
53 {
54 fprintf(stderr, "opening database failed.\n");
55 return 1;
56 }
57
58 dispatcher = dispatcher_create(socket, debug, timeout,
59 (context_constructor_t)user_create, db);
60 dispatcher->add_filter(dispatcher,
61 (filter_constructor_t)auth_filter_create, db);
62 dispatcher->add_controller(dispatcher,
63 (controller_constructor_t)user_controller_create, db);
64 dispatcher->add_controller(dispatcher,
65 (controller_constructor_t)peer_controller_create, db);
66
67 dispatcher->run(dispatcher, threads);
68
69 dispatcher->waitsignal(dispatcher);
70 dispatcher->destroy(dispatcher);
71 db->destroy(db);
72
73 library_deinit();
74 return 0;
75 }
76