f4f0647fb9487bef535e1c5533b48667fdb11584
[strongswan.git] / src / libcharon / plugins / error_notify / error_notify_plugin.c
1 /*
2 * Copyright (C) 2012 Martin Willi
3 * Copyright (C) 2012 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 "error_notify_plugin.h"
17
18 #include "error_notify_listener.h"
19 #include "error_notify_socket.h"
20
21 #include <daemon.h>
22
23 typedef struct private_error_notify_plugin_t private_error_notify_plugin_t;
24
25 /**
26 * private data of error_notify plugin
27 */
28 struct private_error_notify_plugin_t {
29
30 /**
31 * Implements plugin interface
32 */
33 error_notify_plugin_t public;
34
35 /**
36 * Listener catching error alerts
37 */
38 error_notify_listener_t *listener;
39
40 /**
41 * Socket sending notifications
42 */
43 error_notify_socket_t *socket;
44 };
45
46 METHOD(plugin_t, get_name, char*,
47 private_error_notify_plugin_t *this)
48 {
49 return "error-notify";
50 }
51
52 METHOD(plugin_t, destroy, void,
53 private_error_notify_plugin_t *this)
54 {
55 charon->bus->remove_listener(charon->bus, &this->listener->listener);
56 this->listener->destroy(this->listener);
57 this->socket->destroy(this->socket);
58 free(this);
59 }
60
61 /**
62 * Plugin constructor
63 */
64 plugin_t *error_notify_plugin_create()
65 {
66 private_error_notify_plugin_t *this;
67
68 INIT(this,
69 .public = {
70 .plugin = {
71 .get_name = _get_name,
72 .reload = (void*)return_false,
73 .destroy = _destroy,
74 },
75 },
76 .socket = error_notify_socket_create(),
77 );
78
79 this->listener = error_notify_listener_create(this->socket);
80 charon->bus->add_listener(charon->bus, &this->listener->listener);
81
82 return &this->public.plugin;
83 }