Moving charon to libcharon.
[strongswan.git] / src / libcharon / plugins / socket_dynamic / socket_dynamic_plugin.c
1 /*
2 * Copyright (C) 2010 Martin Willi
3 * Copyright (C) 2010 revosec AG
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
16 #include "socket_dynamic_plugin.h"
17
18 #include "socket_dynamic_socket.h"
19
20 #include <daemon.h>
21
22 typedef struct private_socket_dynamic_plugin_t private_socket_dynamic_plugin_t;
23
24 /**
25 * Private data of socket plugin
26 */
27 struct private_socket_dynamic_plugin_t {
28
29 /**
30 * Implements plugin interface
31 */
32 socket_dynamic_plugin_t public;
33
34 /**
35 * Socket instance.
36 */
37 socket_dynamic_socket_t *socket;
38 };
39
40 METHOD(plugin_t, destroy, void,
41 private_socket_dynamic_plugin_t *this)
42 {
43 charon->socket->remove_socket(charon->socket, &this->socket->socket);
44 this->socket->destroy(this->socket);
45 free(this);
46 }
47
48 /*
49 * see header file
50 */
51 plugin_t *socket_dynamic_plugin_create()
52 {
53 private_socket_dynamic_plugin_t *this;
54
55 INIT(this,
56 .public.plugin.destroy = _destroy,
57 .socket = socket_dynamic_socket_create(),
58 );
59
60 if (!this->socket)
61 {
62 free(this);
63 return NULL;
64 }
65 charon->socket->add_socket(charon->socket, &this->socket->socket);
66
67 return &this->public.plugin;
68 }
69