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

Diff of /smsdaemon/plugins/ShellExecPlugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 90 by torben, Mon Jun 16 10:21:02 2008 UTC revision 205 by torben, Fri Dec 19 22:29:25 2008 UTC
# Line 1  Line 1 
1  #include "ShellExecPlugin.h"  #include "ShellExecPlugin.h"
2  #include "IGsmModem.h"  #include "ISmsTransceiver.h"
3  #include "Sms.h"  #include "Sms.h"
4    
5  #include "util.h"  #include "Util.h"
6    #include "ConfigFile.h"
7    
8  ShellExecPlugin::ShellExecPlugin(std::string pluginCommand, std::string exeCommand, bool allowParameters)  #include <stdexcept>
9    : Plugin(pluginCommand, std::string("ShellExec: ")+exeCommand ),  
10    _exeCommand(exeCommand),  ShellExecPlugin::ShellExecPlugin(std::map<std::string,std::string> args)
11    _allowParameters(allowParameters)                  : Plugin("", "")
12  {  {
13            _command = args["trigger"];
14            _exeCommand = args["cmd"];
15            _description = std::string("ShellExec: ")+_exeCommand;
16            std::string allowParms = args["allowparms"];
17            std::string returnOutput = args["returnoutput"];
18    
19            if (_command == "" || _exeCommand == "" || allowParms == "" || returnOutput == "")
20                    throw std::runtime_error("Usage: plugin = shellexec trigger=<trigger>; cmd=<command>; allowparms=<0|1>; returnoutput=<0|1>");
21    
22    
23            _allowParameters = ( ConfigHelper::StringToInt(allowParms) == 1);
24            _returnOutput = ( ConfigHelper::StringToInt(returnOutput) == 1);
25  }  }
26    
27  void ShellExecPlugin::Execute(IGsmModem& modem, SMS& sms)  void ShellExecPlugin::Execute(ISmsTransceiver& modem, SMS& sms)
28  {  {
29          std::string command = _exeCommand;          std::string command = _exeCommand;
30    
31          if (_allowParameters)          if (_allowParameters)
32          {          {
33                  std::string parameters = GetSmsData(sms);                  std::string parameters = sms.ExtractParameters();
34    
35                  parameters = Util::str_replace(parameters, "||");                  parameters = Util::str_replace(parameters, "||");
36                  parameters = Util::str_replace(parameters, "&&");                  parameters = Util::str_replace(parameters, "&&");
# Line 28  void ShellExecPlugin::Execute(IGsmModem& Line 41  void ShellExecPlugin::Execute(IGsmModem&
41                  command += " ";                  command += " ";
42                  command += parameters;                  command += parameters;
43          }          }
44          int retval = Util::my_system( command.c_str()  );          std::string output;
45            std::string* out_p = 0;
46    
47            if (_returnOutput)
48                    out_p = &output;
49    
50            int retval = Util::my_system( command.c_str(), out_p );
51    
52          std::string message;          std::string message;
53          if (retval == -1)          if (retval == -1)
54                  message = "Error";                  message = "Error";
55          else          else
56                  message = "OK";          {
57                            if (_returnOutput)
58          modem.SendSms(sms.sender, message, false );                          message = output;
59                    else
60                            message = "OK";
61            }
62    
63            modem.SendSms(sms.GetSender(), message, false );
64  }  }

Legend:
Removed from v.90  
changed lines
  Added in v.205

  ViewVC Help
Powered by ViewVC 1.1.20