3 |
#include "Logger.h" |
#include "Logger.h" |
4 |
#include "Util.h" |
#include "Util.h" |
5 |
#include "Common.h" |
#include "Common.h" |
6 |
|
#include "ConfigFile.h" |
7 |
|
|
8 |
#include <stdexcept> |
#include <stdexcept> |
9 |
#include <iostream> |
#include <iostream> |
20 |
|
|
21 |
using namespace std; |
using namespace std; |
22 |
|
|
23 |
|
string appendSlash(string& str) |
24 |
|
{ |
25 |
|
if (str.at(str.length()-1) != '/'); |
26 |
|
str += "/"; |
27 |
|
return str; |
28 |
|
} |
29 |
|
|
30 |
|
SmsToolTransceiver::SmsToolTransceiver() |
31 |
|
{ |
32 |
|
Common* cmn = Common::instance(); |
33 |
|
|
34 |
|
try |
35 |
|
{ |
36 |
|
inboxdir = cmn->GetConfigfile()->GetValue("smstools","inboxdir").StringValue(); |
37 |
|
} catch (...) { |
38 |
|
Logger::logMessage("Config error> smstools::inboxdir not specified"); |
39 |
|
exit(1); |
40 |
|
} |
41 |
|
try |
42 |
|
{ |
43 |
|
outgoingdir = cmn->GetConfigfile()->GetValue("smstools","outgoingdir").StringValue(); |
44 |
|
} catch (...) { |
45 |
|
Logger::logMessage("Config error> smstools::outgoingdir not specified"); |
46 |
|
exit(1); |
47 |
|
} |
48 |
|
|
49 |
|
inboxdir = appendSlash(inboxdir); |
50 |
|
outgoingdir = appendSlash(outgoingdir); |
51 |
|
|
52 |
|
} |
53 |
|
|
54 |
|
|
55 |
void SmsToolTransceiver::SendSms(std::string to, std::string message, bool allowMultipart) |
void SmsToolTransceiver::SendSms(std::string to, std::string message, bool allowMultipart) |
56 |
{ |
{ |
57 |
std::string filename = CreateFilename(); |
std::string filename = CreateFilename(); |
58 |
Logger::logMessage( std::string("Sending sms to: ") + to); |
Logger::logMessage( std::string("Sending sms to: ") + to); |
59 |
|
|
60 |
string tempfile = "/var/spool/sms/"; |
string tempfile = outgoingdir + filename + ".LOCK"; |
|
tempfile += filename; |
|
61 |
|
|
62 |
string destfile = "/var/spool/sms/outgoing/"; |
string destfile = outgoingdir + filename; |
|
destfile += filename; |
|
63 |
|
|
64 |
ofstream out( tempfile.c_str() ); |
ofstream out( tempfile.c_str() ); |
65 |
if (!out ) |
if (!out ) |
90 |
|
|
91 |
std::vector<SMS> SmsToolTransceiver::ReadSms(bool readAll) |
std::vector<SMS> SmsToolTransceiver::ReadSms(bool readAll) |
92 |
{ |
{ |
|
const std::string incoming = "/var/spool/sms/incoming/"; |
|
93 |
std::vector<SMS> vec; |
std::vector<SMS> vec; |
94 |
DIR* dir = opendir( incoming.c_str() ); |
DIR* dir = opendir( inboxdir.c_str() ); |
95 |
|
|
96 |
if (dir != 0) |
if (dir != 0) |
97 |
{ |
{ |
104 |
|
|
105 |
try |
try |
106 |
{ |
{ |
107 |
SMS sms = ParseFile( incoming + entry->d_name); |
SMS sms = ParseFile( inboxdir + entry->d_name); |
108 |
vec.push_back(sms); |
vec.push_back(sms); |
109 |
} |
} |
110 |
catch (std::exception& e) |
catch (std::exception& e) |
118 |
} |
} |
119 |
else |
else |
120 |
{ |
{ |
121 |
Logger::logMessage( string("SmsToolTransceiver could open incoming dir ") + strerror(errno) ); |
Logger::logMessage( string("SmsToolTransceiver could open inbox dir ") + strerror(errno) ); |
122 |
} |
} |
123 |
closedir(dir); |
closedir(dir); |
124 |
|
|