fb016acd975c46e71b31fe1e37415c0bf854b314
[strongswan.git] / src / libcharon / plugins / vici / vici_plugin.c
1 /*
2 * Copyright (C) 2014 Martin Willi
3 * Copyright (C) 2014 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 "vici_plugin.h"
17 #include "vici_dispatcher.h"
18 #include "vici_query.h"
19
20 #include <library.h>
21 #include <daemon.h>
22
23 typedef struct private_vici_plugin_t private_vici_plugin_t;
24
25 /**
26 * Private members of vici_plugin_t
27 */
28 struct private_vici_plugin_t {
29
30 /**
31 * public functions
32 */
33 vici_plugin_t public;
34
35 /**
36 * Dispatcher, creating socket
37 */
38 vici_dispatcher_t *dispatcher;
39
40 /**
41 * Query commands
42 */
43 vici_query_t *query;
44 };
45
46 METHOD(plugin_t, get_name, char*,
47 private_vici_plugin_t *this)
48 {
49 return "vici";
50 }
51
52 /**
53 * Register vici plugin features
54 */
55 static bool register_vici(private_vici_plugin_t *this,
56 plugin_feature_t *feature, bool reg, void *data)
57 {
58 if (reg)
59 {
60 char *uri;
61
62 uri = lib->settings->get_str(lib->settings, "%s.plugins.vici.socket",
63 VICI_DEFAULT_URI, lib->ns);
64 this->dispatcher = vici_dispatcher_create(uri);
65 if (this->dispatcher)
66 {
67 this->query = vici_query_create(this->dispatcher);
68 return TRUE;
69 }
70 return FALSE;
71 }
72 else
73 {
74 this->query->destroy(this->query);
75 this->dispatcher->destroy(this->dispatcher);
76 }
77 return TRUE;
78 }
79
80 METHOD(plugin_t, get_features, int,
81 private_vici_plugin_t *this, plugin_feature_t *features[])
82 {
83 static plugin_feature_t f[] = {
84 PLUGIN_CALLBACK((plugin_feature_callback_t)register_vici, NULL),
85 PLUGIN_PROVIDE(CUSTOM, "vici"),
86 };
87 *features = f;
88 return countof(f);
89 }
90
91 METHOD(plugin_t, destroy, void,
92 private_vici_plugin_t *this)
93 {
94 free(this);
95 }
96
97 /*
98 * see header file
99 */
100 plugin_t *vici_plugin_create()
101 {
102 private_vici_plugin_t *this;
103
104 INIT(this,
105 .public = {
106 .plugin = {
107 .get_name = _get_name,
108 .reload = (void*)return_false,
109 .get_features = _get_features,
110 .destroy = _destroy,
111 },
112 },
113 );
114
115 return &this->public.plugin;
116 }