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