|
|
|
1 |
#include "PluginManager.h" |
#include "PluginManager.h" |
2 |
|
|
3 |
#include "Logger.h" |
#include "Logger.h" |
4 |
|
#include "ConfigFile.h" |
5 |
|
#include "Common.h" |
6 |
|
#include "Util.h" |
7 |
|
|
8 |
#include "plugins/EchoPlugin.h" |
#include "plugins/EchoPlugin.h" |
9 |
#include "plugins/SpamPlugin.h" |
#include "plugins/SpamPlugin.h" |
50 |
} |
} |
51 |
} |
} |
52 |
|
|
53 |
void PluginManager::LoadPlugins() |
Plugin* PluginManager::CreatePlugin(const std::string& pluginName, const std::map<std::string,std::string>& args) |
54 |
{ |
{ |
55 |
static EchoPlugin echo; |
if (pluginName == "echo") |
56 |
|
return new EchoPlugin(); |
57 |
|
|
58 |
|
if (pluginName == "spam") |
59 |
|
return new SpamPlugin(); |
60 |
|
|
61 |
|
if (pluginName == "tog") |
62 |
|
return new TogPlugin(); |
63 |
|
|
64 |
static SpamPlugin spam; |
if (pluginName == "status") |
65 |
|
return new StatusPlugin(); |
66 |
|
|
67 |
static ShellExecPlugin wake("wake", "/home/torben/bin/wake", false, false); |
if (pluginName == "list") |
68 |
static ShellExecPlugin ping("ping", "nmap -sP 192.168.10.1-255 | grep appears | awk '{print $2}'", false,true); |
return new ListPlugin(); |
69 |
|
|
70 |
static TogPlugin tog; |
if (pluginName == "hoststatus") |
71 |
|
return new HostStatusPlugin(); |
72 |
|
|
73 |
static StatusPlugin status; |
if (pluginName == "weather") |
74 |
|
return new WeatherPlugin(); |
75 |
|
|
76 |
static ListPlugin list; |
if (pluginName == "shellexec") |
77 |
|
return new ShellExecPlugin(args); |
78 |
|
|
79 |
|
if (pluginName == "urltrigger") |
80 |
|
return new UrlTriggerPlugin(args); |
81 |
|
|
82 |
|
return 0; |
83 |
|
} |
84 |
|
|
|
static HostStatusPlugin hoststatus; |
|
85 |
|
|
86 |
static WeatherPlugin weather; |
void PluginManager::DestroyPlugins() |
87 |
|
{ |
88 |
|
for (std::map<std::string,Plugin*>::iterator it=_plugins.begin(); it!=_plugins.end(); ++it) |
89 |
|
{ |
90 |
|
delete it->second; |
91 |
|
} |
92 |
|
_plugins.clear(); |
93 |
|
} |
94 |
|
|
95 |
|
void PluginManager::LoadPlugins() |
96 |
|
{ |
97 |
|
Logger::logMessage("-------- PluginList --------"); |
98 |
|
std::vector<Value> pluginlist = Common::instance()->GetConfigfile()->GetValues("smsdaemon", "plugin"); |
99 |
|
|
100 |
|
for (unsigned i=0; i<pluginlist.size(); i++) |
101 |
|
{ |
102 |
|
std::string current = pluginlist[i]; |
103 |
|
|
104 |
|
std::string name; |
105 |
|
unsigned pos = current.find(' '); |
106 |
|
std::map<std::string,std::string> args; |
107 |
|
|
108 |
|
std::string argstr; |
109 |
|
|
110 |
|
if (pos == std::string::npos) |
111 |
|
{ |
112 |
|
name = current; |
113 |
|
} |
114 |
|
else |
115 |
|
{ |
116 |
|
name = Util::str_trim(current.substr(0,pos)); |
117 |
|
argstr = Util::str_trim(current.substr(pos+1,1024)); |
118 |
|
args = ConfigHelper::ParseArguments(argstr); |
119 |
|
} |
120 |
|
|
121 |
|
Plugin* pl = 0; |
122 |
|
try |
123 |
|
{ |
124 |
|
pl = CreatePlugin(name, args ); |
125 |
|
} |
126 |
|
catch (std::exception& e) |
127 |
|
{ |
128 |
|
Logger::logMessage(std::string("Failed to load plugin ") + name + " with args: " + argstr); |
129 |
|
Logger::logMessage(std::string("Reason: ") + e.what()); |
130 |
|
continue; |
131 |
|
} |
132 |
|
|
133 |
|
if (pl) |
134 |
|
AddPlugin(pl); |
135 |
|
else |
136 |
|
Logger::logMessage( std::string("Unknown plugin: ")+name); |
137 |
|
|
138 |
|
} |
139 |
|
|
|
static UrlTriggerPlugin urltrigger("tou", "http://t-hoerup.dk/test.php"); |
|
140 |
|
|
141 |
for (MapIterator it = _plugins.begin(); it != _plugins.end(); ++it) |
for (MapIterator it = _plugins.begin(); it != _plugins.end(); ++it) |
142 |
{ |
{ |
146 |
} |
} |
147 |
} |
} |
148 |
|
|
149 |
|
|
150 |
Plugin* PluginManager::GetPlugin(const std::string& pluginname) |
Plugin* PluginManager::GetPlugin(const std::string& pluginname) |
151 |
{ |
{ |
152 |
return _plugins[ pluginname ]; |
return _plugins[ pluginname ]; |