#include "UrlTriggerPlugin.h" #include "ISmsTransceiver.h" #include "Sms.h" #include "Util.h" #include "Logger.h" #include "Exceptions.h" #include "HttpClient.h" #include #include using namespace std; UrlTriggerPlugin::UrlTriggerPlugin(map args) : Plugin("", "" ) { _command = args["trigger"]; _URL = args["url"];; _description = string("UrlTrigger(") + _command + ") > " + _URL; if (_command == "" || _URL == "") throw std::runtime_error("UrlTriggerPlugin usage: plugin = urltrigger trigger= url="); } void UrlTriggerPlugin::Execute(ISmsTransceiver& modem, SMS& sms) { ostringstream request; request << _URL << "?"; request << "sender=" << sms.GetSender() << "&"; request << "data=" << HttpClient::UrlEncode(sms.ExtractParameters()); string reply; try { reply = HttpClient::GetString( request.str() ); reply = Util::str_replace(reply, "\r"); //remove carriage return if (reply == "") reply = "Empty reply from server !?!"; } catch (httpexception& e) { reply = "Error: Could not execute command"; Logger::logMessage(string("UrlTrigger failed: ") + _command + ">" + e.what() ); } modem.SendSms(sms.GetSender(), reply, true); }