/[projects]/smsdaemon/plugins/ShellExecPlugin.cpp
ViewVC logotype

Annotation of /smsdaemon/plugins/ShellExecPlugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 196 - (hide annotations) (download)
Thu Dec 18 06:53:29 2008 UTC (15 years, 5 months ago) by torben
File size: 1213 byte(s)
Make pretty

astyle -t -b -N

1 torben 35 #include "ShellExecPlugin.h"
2 torben 149 #include "ISmsTransceiver.h"
3 torben 90 #include "Sms.h"
4 torben 35
5 torben 158 #include "Util.h"
6 torben 35
7 torben 107 ShellExecPlugin::ShellExecPlugin(std::string pluginCommand, std::string exeCommand, bool allowParameters, bool returnOutput)
8 torben 196 : Plugin(pluginCommand, std::string("ShellExec: ")+exeCommand ),
9     _exeCommand(exeCommand),
10     _allowParameters(allowParameters),
11     _returnOutput(returnOutput)
12 torben 35 {
13     }
14    
15 torben 149 void ShellExecPlugin::Execute(ISmsTransceiver& modem, SMS& sms)
16 torben 35 {
17 torben 56 std::string command = _exeCommand;
18 torben 35
19 torben 56 if (_allowParameters)
20     {
21 torben 142 std::string parameters = sms.ExtractParameters();
22 torben 56
23     parameters = Util::str_replace(parameters, "||");
24     parameters = Util::str_replace(parameters, "&&");
25     parameters = Util::str_replace(parameters, ";");
26     parameters = Util::str_replace(parameters, "'");
27     parameters = Util::str_replace(parameters, "\"");
28    
29     command += " ";
30     command += parameters;
31     }
32 torben 107 std::string output;
33     std::string* out_p = 0;
34 torben 35
35 torben 107 if (_returnOutput)
36     out_p = &output;
37    
38     int retval = Util::my_system( command.c_str(), out_p );
39    
40 torben 35 std::string message;
41     if (retval == -1)
42     message = "Error";
43     else
44 torben 107 {
45     if (_returnOutput)
46     message = output;
47     else
48     message = "OK";
49     }
50 torben 196
51 torben 142 modem.SendSms(sms.GetSender(), message, false );
52 torben 35 }

  ViewVC Help
Powered by ViewVC 1.1.20