1 |
#include "SmsToolTransceiver.h" |
#include "SmsToolTransceiver.h" |
2 |
|
|
3 |
#include "common.h" |
#include "Logger.h" |
4 |
#include "util.h" |
#include "Util.h" |
5 |
|
|
6 |
#include <stdexcept> |
#include <stdexcept> |
7 |
#include <iostream> |
#include <iostream> |
21 |
void SmsToolTransceiver::SendSms(std::string to, std::string message, bool allowMultipart) |
void SmsToolTransceiver::SendSms(std::string to, std::string message, bool allowMultipart) |
22 |
{ |
{ |
23 |
std::string filename = CreateFilename(); |
std::string filename = CreateFilename(); |
24 |
Common::instance()->logMessage( std::string("Sending sms to: ") + to); |
Logger::logMessage( std::string("Sending sms to: ") + to); |
25 |
|
|
26 |
string tempfile = "/var/spool/sms/"; |
string tempfile = "/var/spool/sms/"; |
27 |
tempfile += filename; |
tempfile += filename; |
32 |
ofstream out( tempfile.c_str() ); |
ofstream out( tempfile.c_str() ); |
33 |
if (!out ) |
if (!out ) |
34 |
{ |
{ |
35 |
Common::instance()->logMessage("SmsToolTransceiver:: could not create temp file"); |
Logger::logMessage("SmsToolTransceiver:: could not create temp file"); |
36 |
return; |
return; |
37 |
} |
} |
38 |
out << "To: " << to << "\n\n" << message ; |
out << "To: " << to << "\n\n" << message ; |
39 |
out.close(); |
out.close(); |
40 |
|
|
41 |
|
Common::instance()->smsCounter.outgoing++; |
42 |
|
|
43 |
int result = rename(tempfile.c_str(), destfile.c_str()); |
int result = rename(tempfile.c_str(), destfile.c_str()); |
44 |
|
|
45 |
if (result) |
if (result) |
46 |
Common::instance()->logMessage( string("SmsToolTransceiver could not spool file: ") + strerror(errno) ); |
Logger::logMessage( string("SmsToolTransceiver could not spool file: ") + strerror(errno) ); |
47 |
} |
} |
48 |
|
|
49 |
std::string SmsToolTransceiver::CreateFilename() |
std::string SmsToolTransceiver::CreateFilename() |
77 |
} |
} |
78 |
catch (std::exception& e) |
catch (std::exception& e) |
79 |
{ |
{ |
80 |
Common::instance()->logMessage(e.what()); |
Logger::logMessage(e.what()); |
81 |
} |
} |
82 |
|
|
83 |
if (!readAll) |
if (!readAll) |
86 |
} |
} |
87 |
else |
else |
88 |
{ |
{ |
89 |
Common::instance()->logMessage( string("SmsToolTransceiver could open incoming dir ") + strerror(errno) ); |
Logger::logMessage( string("SmsToolTransceiver could open incoming dir ") + strerror(errno) ); |
90 |
} |
} |
91 |
|
closedir(dir); |
92 |
|
|
93 |
return vec; |
return vec; |
94 |
} |
} |