added a dispatcher class to receive HA sync messages
[strongswan.git] / src / charon / plugins / ha_sync / ha_sync_plugin.c
1 /*
2 * Copyright (C) 2008 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 "ha_sync_plugin.h"
19 #include "ha_sync_ike.h"
20 #include "ha_sync_child.h"
21 #include "ha_sync_socket.h"
22 #include "ha_sync_dispatcher.h"
23
24 #include <daemon.h>
25 #include <config/child_cfg.h>
26
27 typedef struct private_ha_sync_plugin_t private_ha_sync_plugin_t;
28
29 /**
30 * private data of ha_sync plugin
31 */
32 struct private_ha_sync_plugin_t {
33
34 /**
35 * implements plugin interface
36 */
37 ha_sync_plugin_t public;
38
39 /**
40 * Communication socket
41 */
42 ha_sync_socket_t *socket;
43
44 /**
45 * IKE_SA synchronization
46 */
47 ha_sync_ike_t *ike;
48
49 /**
50 * CHILD_SA synchronization
51 */
52 ha_sync_child_t *child;
53
54 /**
55 * Dispatcher to process incoming messages
56 */
57 ha_sync_dispatcher_t *dispatcher;
58 };
59
60 /**
61 * Implementation of plugin_t.destroy
62 */
63 static void destroy(private_ha_sync_plugin_t *this)
64 {
65 charon->bus->remove_listener(charon->bus, &this->ike->listener);
66 charon->bus->remove_listener(charon->bus, &this->child->listener);
67 this->ike->destroy(this->ike);
68 this->child->destroy(this->child);
69 this->dispatcher->destroy(this->dispatcher);
70 this->socket->destroy(this->socket);
71 free(this);
72 }
73
74 /*
75 * see header file
76 */
77 plugin_t *plugin_create()
78 {
79 private_ha_sync_plugin_t *this = malloc_thing(private_ha_sync_plugin_t);
80
81 this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
82
83 this->socket = ha_sync_socket_create();
84 if (!this->socket)
85 {
86 free(this);
87 return NULL;
88 }
89 this->dispatcher = ha_sync_dispatcher_create(this->socket);
90 this->ike = ha_sync_ike_create(this->socket);
91 this->child = ha_sync_child_create(this->socket);
92 charon->bus->add_listener(charon->bus, &this->ike->listener);
93 charon->bus->add_listener(charon->bus, &this->child->listener);
94
95 return &this->public.plugin;
96 }
97