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