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

Contents of /smsdaemon/plugins/UrlTriggerPlugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 205 - (show 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 #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 #include <stdexcept>
12
13 using namespace std;
14
15 UrlTriggerPlugin::UrlTriggerPlugin(map<string,string> args)
16 : Plugin("", "" )
17 {
18
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 }
28
29 void UrlTriggerPlugin::Execute(ISmsTransceiver& modem, SMS& sms)
30 {
31 ostringstream request;
32 request << _URL << "?";
33 request << "sender=" << sms.GetSender() << "&";
34 request << "data=" << HttpClient::UrlEncode(sms.ExtractParameters());
35
36 string reply;
37 try
38 {
39 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 }
44 catch (httpexception& e)
45 {
46 reply = "Error: Could not execute command";
47 Logger::logMessage(string("UrlTrigger failed: ") + _command + ">" + e.what() );
48 }
49
50 modem.SendSms(sms.GetSender(), reply, true);
51 }

  ViewVC Help
Powered by ViewVC 1.1.20