d6d2fe3baccf6449e97cbf771c8a05bbf1464616
[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
23 #include <daemon.h>
24 #include <config/child_cfg.h>
25
26 typedef struct private_ha_sync_plugin_t private_ha_sync_plugin_t;
27
28 /**
29 * private data of ha_sync plugin
30 */
31 struct private_ha_sync_plugin_t {
32
33 /**
34 * implements plugin interface
35 */
36 ha_sync_plugin_t public;
37
38 /**
39 * Communication socket
40 */
41 ha_sync_socket_t *socket;
42
43 /**
44 * IKE_SA synchronization
45 */
46 ha_sync_ike_t *ike;
47
48 /**
49 * CHILD_SA synchronization
50 */
51 ha_sync_child_t *child;
52 };
53
54 /**
55 * Implementation of plugin_t.destroy
56 */
57 static void destroy(private_ha_sync_plugin_t *this)
58 {
59 charon->bus->remove_listener(charon->bus, &this->ike->listener);
60 charon->bus->remove_listener(charon->bus, &this->child->listener);
61 this->ike->destroy(this->ike);
62 this->child->destroy(this->child);
63 this->socket->destroy(this->socket);
64 free(this);
65 }
66
67 /*
68 * see header file
69 */
70 plugin_t *plugin_create()
71 {
72 private_ha_sync_plugin_t *this = malloc_thing(private_ha_sync_plugin_t);
73
74 this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
75
76 this->socket = ha_sync_socket_create();
77 if (!this->socket)
78 {
79 free(this);
80 return NULL;
81 }
82 this->ike = ha_sync_ike_create(this->socket);
83 this->child = ha_sync_child_create(this->socket);
84 charon->bus->add_listener(charon->bus, &this->ike->listener);
85 charon->bus->add_listener(charon->bus, &this->child->listener);
86
87 return &this->public.plugin;
88 }
89