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 ; |
41 |
int result = rename(tempfile.c_str(), destfile.c_str()); |
int result = rename(tempfile.c_str(), destfile.c_str()); |
42 |
|
|
43 |
if (result) |
if (result) |
44 |
Common::instance()->logMessage( string("SmsToolTransceiver could not spool file: ") + strerror(errno) ); |
Logger::logMessage( string("SmsToolTransceiver could not spool file: ") + strerror(errno) ); |
45 |
} |
} |
46 |
|
|
47 |
std::string SmsToolTransceiver::CreateFilename() |
std::string SmsToolTransceiver::CreateFilename() |
75 |
} |
} |
76 |
catch (std::exception& e) |
catch (std::exception& e) |
77 |
{ |
{ |
78 |
Common::instance()->logMessage(e.what()); |
Logger::logMessage(e.what()); |
79 |
} |
} |
80 |
|
|
81 |
if (!readAll) |
if (!readAll) |
84 |
} |
} |
85 |
else |
else |
86 |
{ |
{ |
87 |
Common::instance()->logMessage( string("SmsToolTransceiver could open incoming dir ") + strerror(errno) ); |
Logger::logMessage( string("SmsToolTransceiver could open incoming dir ") + strerror(errno) ); |
88 |
} |
} |
89 |
closedir(dir); |
closedir(dir); |
90 |
|
|