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