1 /*
2 * uhub - A tiny ADC p2p connection hub
3 * Copyright (C) 2007-2014, Jan Vidar Krey
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20 #include "plugin_api/handle.h"
21 #include "plugin_api/command_api.h"
22 #include "util/memory.h"
23
24 struct example_plugin_data
25 {
26 struct plugin_command_handle* example;
27 };
28
example_command_handler(struct plugin_handle * plugin,struct plugin_user * user,struct plugin_command * cmd)29 static int example_command_handler(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd)
30 {
31 plugin->hub.send_message(plugin, user, "Hello from mod_example.");
32 return 0;
33 }
34
command_register(struct plugin_handle * plugin)35 static void command_register(struct plugin_handle* plugin)
36 {
37 struct example_plugin_data* data = (struct example_plugin_data*) hub_malloc(sizeof(struct example_plugin_data));
38 data->example = hub_malloc_zero(sizeof(struct plugin_command_handle));
39 PLUGIN_COMMAND_INITIALIZE(data->example, (void*) data, "example", "", auth_cred_guest, example_command_handler, "This is an example command that is added dynamically by loading the mod_example plug-in.");
40 plugin->hub.command_add(plugin, data->example);
41 plugin->ptr = data;
42 }
43
command_unregister(struct plugin_handle * plugin)44 static void command_unregister(struct plugin_handle* plugin)
45 {
46 struct example_plugin_data* data = (struct example_plugin_data*) plugin->ptr;
47
48 plugin->hub.command_del(plugin, data->example);
49 hub_free(data->example);
50
51 hub_free(data);
52 plugin->ptr = NULL;
53 }
54
plugin_register(struct plugin_handle * plugin,const char * config)55 int plugin_register(struct plugin_handle* plugin, const char* config)
56 {
57 PLUGIN_INITIALIZE(plugin, "Example plugin", "1.0", "A simple example plugin");
58 command_register(plugin);
59 return 0;
60 }
61
plugin_unregister(struct plugin_handle * plugin)62 int plugin_unregister(struct plugin_handle* plugin)
63 {
64 command_unregister(plugin);
65 return 0;
66 }
67
68