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

Annotation of /smsdaemon/plugins/UrlTriggerPlugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 205 - (hide annotations) (download)
Fri Dec 19 22:29:25 2008 UTC (15 years, 5 months ago) by torben
File size: 1225 byte(s)
Enable selection and configuration of loaded plugins to be specified in the configuration file

1 torben 193 #include "UrlTriggerPlugin.h"
2    
3     #include "ISmsTransceiver.h"
4     #include "Sms.h"
5     #include "Util.h"
6    
7     #include "Logger.h"
8     #include "Exceptions.h"
9     #include "HttpClient.h"
10     #include <sstream>
11 torben 205 #include <stdexcept>
12 torben 193
13     using namespace std;
14    
15 torben 205 UrlTriggerPlugin::UrlTriggerPlugin(map<string,string> args)
16     : Plugin("", "" )
17 torben 193 {
18 torben 205
19     _command = args["trigger"];
20     _URL = args["url"];;
21     _description = string("UrlTrigger(") + _command + ") > " + _URL;
22    
23    
24     if (_command == "" || _URL == "")
25     throw std::runtime_error("UrlTriggerPlugin usage: plugin = urltrigger trigger=<triggerword> url=<url>");
26    
27 torben 193 }
28    
29     void UrlTriggerPlugin::Execute(ISmsTransceiver& modem, SMS& sms)
30     {
31     ostringstream request;
32 torben 205 request << _URL << "?";
33 torben 193 request << "sender=" << sms.GetSender() << "&";
34     request << "data=" << HttpClient::UrlEncode(sms.ExtractParameters());
35    
36     string reply;
37 torben 196 try
38     {
39 torben 193 reply = HttpClient::GetString( request.str() );
40     reply = Util::str_replace(reply, "\r"); //remove carriage return
41     if (reply == "")
42     reply = "Empty reply from server !?!";
43 torben 196 }
44     catch (httpexception& e)
45     {
46 torben 193 reply = "Error: Could not execute command";
47 torben 205 Logger::logMessage(string("UrlTrigger failed: ") + _command + ">" + e.what() );
48 torben 193 }
49    
50     modem.SendSms(sms.GetSender(), reply, true);
51     }

  ViewVC Help
Powered by ViewVC 1.1.20