#include "ProxyTransceiver.h" #include "ConfigFile.h" #include "Common.h" #include "Logger.h" #include "AccessManager.h" ProxyTransceiver::ProxyTransceiver(ISmsTransceiver& realtransceiver) : _transceiver(realtransceiver), _hasCC(false) { Common* cmn = Common::instance(); _countrycode = cmn->GetConfigfile()->GetValue("smsdaemon","countrycode","").StringValue(); if (_countrycode != "") { try { if (ConfigHelper::StringToInt(_countrycode) != 0) { _hasCC = true; } } catch (...) { Logger::logMessage( "Invalid country code:" + _countrycode); } } if (_hasCC) Logger::logMessage( "Enforcing country code: " + _countrycode); else Logger::logMessage( "No countrycode enforced"); } void ProxyTransceiver::SendSms(std::string to, std::string message, bool allowMultipart) { unsigned maxLength = allowMultipart ? 900 : 160; if (message.size() > maxLength) message = message.substr(0,maxLength); if (to.at(0) == '+') //no leading + signs to.erase(0); if (_hasCC) { if (to.substr(0,_countrycode.size()) != _countrycode) to.insert(0, _countrycode); } if ( AccessManager::IsBlacklisted(to)) { Logger::logMessage( "Will not send message to blacklisted phone: " + to); return; } _transceiver.SendSms(to,message,allowMultipart); } std::vector ProxyTransceiver::ReadSms(bool readAll) { return _transceiver.ReadSms(readAll); }