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 |
|
|
|
12 |
|
|
using namespace std; |
13 |
|
|
|
14 |
|
|
UrlTriggerPlugin::UrlTriggerPlugin(string cmd, string url) |
15 |
|
|
: Plugin(cmd, string("URL Trigger:")+url ), |
16 |
|
|
command(cmd), URL(url) |
17 |
|
|
{ |
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
void UrlTriggerPlugin::Execute(ISmsTransceiver& modem, SMS& sms) |
21 |
|
|
{ |
22 |
|
|
ostringstream request; |
23 |
|
|
request << URL << "?"; |
24 |
|
|
request << "sender=" << sms.GetSender() << "&"; |
25 |
|
|
request << "data=" << HttpClient::UrlEncode(sms.ExtractParameters()); |
26 |
|
|
|
27 |
|
|
string reply; |
28 |
|
|
try { |
29 |
|
|
reply = HttpClient::GetString( request.str() ); |
30 |
|
|
reply = Util::str_replace(reply, "\r"); //remove carriage return |
31 |
|
|
if (reply == "") |
32 |
|
|
reply = "Empty reply from server !?!"; |
33 |
|
|
} catch (httpexception& e) { |
34 |
|
|
reply = "Error: Could not execute command"; |
35 |
|
|
Logger::logMessage(string("UrlTrigger failed: ") + command + ">" + e.what() ); |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
modem.SendSms(sms.GetSender(), reply, true); |
39 |
|
|
} |