Notify duplicate detections over a UNIX sockets to listening applications
[strongswan.git] / src / libcharon / plugins / duplicheck / duplicheck_plugin.c
1 /*
2 * Copyright (C) 2011 Martin Willi
3 * Copyright (C) 2011 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 "duplicheck_plugin.h"
17
18 #include "duplicheck_notify.h"
19 #include "duplicheck_listener.h"
20
21 #include <daemon.h>
22
23 typedef struct private_duplicheck_plugin_t private_duplicheck_plugin_t;
24
25 /**
26 * Private data of duplicheck plugin
27 */
28 struct private_duplicheck_plugin_t {
29
30 /**
31 * Implements plugin interface
32 */
33 duplicheck_plugin_t public;
34
35 /**
36 * Listener doing duplicate checks
37 */
38 duplicheck_listener_t *listener;
39
40 /**
41 * Notification sender facility
42 */
43 duplicheck_notify_t *notify;
44 };
45
46 METHOD(plugin_t, destroy, void,
47 private_duplicheck_plugin_t *this)
48 {
49 charon->bus->remove_listener(charon->bus, &this->listener->listener);
50 this->notify->destroy(this->notify);
51 this->listener->destroy(this->listener);
52 free(this);
53 }
54
55 /**
56 * Plugin constructor
57 */
58 plugin_t *duplicheck_plugin_create()
59 {
60 private_duplicheck_plugin_t *this;
61
62 INIT(this,
63 .public = {
64 .plugin = {
65 .destroy = _destroy,
66 },
67 },
68 .notify = duplicheck_notify_create(),
69 );
70
71 if (!this->notify)
72 {
73 free(this);
74 return NULL;
75 }
76 this->listener = duplicheck_listener_create(this->notify);
77 charon->bus->add_listener(charon->bus, &this->listener->listener);
78
79 return &this->public.plugin;
80 }