-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIRC_Plugin.cpp
More file actions
92 lines (71 loc) · 1.56 KB
/
IRC_Plugin.cpp
File metadata and controls
92 lines (71 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "IRC_Plugin.h"
IRC_Plugin::IRC_Plugin(std::string path, IRC_Server* link, bool isService)
: Plugin(path)
{
if (!is_valid())
return;
this->link = link;
void* handle = get_plugin_handle();
void* init_handle = dlsym(handle, "init");
if (init_handle != NULL)
{
init = (init_function)init_handle;
if (!isService)
init(link);
}
else
init = NULL;
void* dealloc_handle = dlsym(handle, "dealloc");
if (dealloc_handle != NULL)
dealloc = (dealloc_function)dealloc_handle;
else
dealloc = NULL;
void* nop_handle = dlsym(handle, "name_of_plugin");
if (nop_handle == NULL)
{
valid = false;
return;
}
nop = (name_of_plugin_function)nop_handle;
if (isService)
return;
void* spf_handle = dlsym(handle, "get_supported_calls");
if (spf_handle == NULL)
{
valid = false;
return;
}
scf = (supported_calls_function)spf_handle;
void* pcf_handle = dlsym(handle, "plugin_call");
if (pcf_handle == NULL)
{
valid = false;
return;
}
pcf = (plugin_call_function)pcf_handle;
}
IRC_Plugin::~IRC_Plugin()
{
if (dealloc)
dealloc();
}
std::vector<IRC_Plugin::Call_Type> IRC_Plugin::get_supported_calls()
{
if (!valid)
return std::vector<Call_Type>();
return scf();
}
IRC_Plugin::Result_Of_Call IRC_Plugin::plugin_call(Call_Type type, IRC_Server::User* user, std::vector<std::string> &parts)
{
if (!valid)
return FAILURE;
return pcf(type, user, parts, link);
}
std::string IRC_Plugin::get_name_of_plugin(bool absolute)
{
if (!valid)
return "FAILURE";
if (absolute)
return nop();
return "Plugin (" + nop() + ")";
}