1 |
#include "ProxyTransceiver.h" |
2 |
#include "ConfigFile.h" |
3 |
#include "Common.h" |
4 |
#include "Logger.h" |
5 |
|
6 |
ProxyTransceiver::ProxyTransceiver(ISmsTransceiver& realtransceiver) |
7 |
: _transceiver(realtransceiver), _hasCC(false) |
8 |
{ |
9 |
Common* cmn = Common::instance(); |
10 |
_countrycode = cmn->GetConfigfile()->GetValue("smsdaemon","countrycode","").StringValue(); |
11 |
if (_countrycode != "") |
12 |
{ |
13 |
try |
14 |
{ |
15 |
if (ConfigHelper::StringToInt(_countrycode) != 0) |
16 |
{ |
17 |
_hasCC = true; |
18 |
} |
19 |
} |
20 |
catch (...) |
21 |
{ |
22 |
Logger::logMessage( "Invalid country code:" + _countrycode); |
23 |
} |
24 |
} |
25 |
if (_hasCC) |
26 |
Logger::logMessage( "Enforcing country code: " + _countrycode); |
27 |
else |
28 |
Logger::logMessage( "No countrycode enforced"); |
29 |
} |
30 |
|
31 |
|
32 |
void ProxyTransceiver::SendSms(std::string to, std::string message, bool allowMultipart) |
33 |
{ |
34 |
unsigned maxLength = allowMultipart ? 900 : 160; |
35 |
|
36 |
if (message.size() > maxLength) |
37 |
message = message.substr(0,maxLength); |
38 |
|
39 |
if (to.at(0) == '+') //no leading + signs |
40 |
to.erase(0); |
41 |
|
42 |
if (_hasCC) |
43 |
{ |
44 |
if (to.substr(0,_countrycode.size()) != _countrycode) |
45 |
to.insert(0, _countrycode); |
46 |
} |
47 |
|
48 |
if ( Common::instance()->IsBlacklisted(to)) |
49 |
{ |
50 |
Logger::logMessage( "Will not send message to blacklisted phone: " + to); |
51 |
return; |
52 |
} |
53 |
|
54 |
_transceiver.SendSms(to,message,allowMultipart); |
55 |
} |
56 |
|
57 |
std::vector<SMS> ProxyTransceiver::ReadSms(bool readAll) |
58 |
{ |
59 |
return _transceiver.ReadSms(readAll); |
60 |
} |