23 |
string appendSlash(string& str) |
string appendSlash(string& str) |
24 |
{ |
{ |
25 |
if (str.at(str.length()-1) != '/'); |
if (str.at(str.length()-1) != '/'); |
26 |
str += "/"; |
str += "/"; |
27 |
return str; |
return str; |
28 |
} |
} |
29 |
|
|
34 |
try |
try |
35 |
{ |
{ |
36 |
inboxdir = cmn->GetConfigfile()->GetValue("smstools","inboxdir").StringValue(); |
inboxdir = cmn->GetConfigfile()->GetValue("smstools","inboxdir").StringValue(); |
37 |
} catch (...) { |
} |
38 |
|
catch (...) |
39 |
|
{ |
40 |
Logger::logMessage("Config error> smstools::inboxdir not specified"); |
Logger::logMessage("Config error> smstools::inboxdir not specified"); |
41 |
exit(1); |
exit(1); |
42 |
} |
} |
43 |
try |
try |
44 |
{ |
{ |
45 |
outgoingdir = cmn->GetConfigfile()->GetValue("smstools","outgoingdir").StringValue(); |
outgoingdir = cmn->GetConfigfile()->GetValue("smstools","outgoingdir").StringValue(); |
46 |
} catch (...) { |
} |
47 |
|
catch (...) |
48 |
|
{ |
49 |
Logger::logMessage("Config error> smstools::outgoingdir not specified"); |
Logger::logMessage("Config error> smstools::outgoingdir not specified"); |
50 |
exit(1); |
exit(1); |
51 |
} |
} |
52 |
|
|
53 |
inboxdir = appendSlash(inboxdir); |
inboxdir = appendSlash(inboxdir); |
54 |
outgoingdir = appendSlash(outgoingdir); |
outgoingdir = appendSlash(outgoingdir); |
55 |
|
|
56 |
} |
} |
57 |
|
|
58 |
|
|
75 |
out.close(); |
out.close(); |
76 |
|
|
77 |
Common::instance()->smsCounter.outgoing++; |
Common::instance()->smsCounter.outgoing++; |
78 |
|
|
79 |
int result = rename(tempfile.c_str(), destfile.c_str()); |
int result = rename(tempfile.c_str(), destfile.c_str()); |
80 |
|
|
81 |
if (result) |
if (result) |
97 |
std::vector<SMS> vec; |
std::vector<SMS> vec; |
98 |
DIR* dir = opendir( inboxdir.c_str() ); |
DIR* dir = opendir( inboxdir.c_str() ); |
99 |
|
|
100 |
if (dir != 0) |
if (dir != 0) |
101 |
{ |
{ |
102 |
dirent* entry; |
dirent* entry; |
103 |
while ( (entry = readdir(dir)) != 0) |
while ( (entry = readdir(dir)) != 0) |
110 |
{ |
{ |
111 |
SMS sms = ParseFile( inboxdir + entry->d_name); |
SMS sms = ParseFile( inboxdir + entry->d_name); |
112 |
vec.push_back(sms); |
vec.push_back(sms); |
113 |
} |
} |
114 |
catch (std::exception& e) |
catch (std::exception& e) |
115 |
{ |
{ |
116 |
Logger::logMessage(e.what()); |
Logger::logMessage(e.what()); |
117 |
} |
} |
129 |
return vec; |
return vec; |
130 |
} |
} |
131 |
|
|
|
void SmsToolTransceiver::DeleteSms(std::string smsIndex) |
|
|
{ |
|
|
} |
|
132 |
|
|
133 |
SMS SmsToolTransceiver::ParseFile(std::string path) |
SMS SmsToolTransceiver::ParseFile(std::string path) |
134 |
{ |
{ |
135 |
SMS sms; |
SMS sms; |
136 |
|
|
137 |
string file = Util::readfile(path); |
string file = Util::readfile(path); |
138 |
int result = ::unlink(path.c_str()); |
int result = ::unlink(path.c_str()); |
139 |
if (result) |
if (result) |
140 |
{ |
{ |
141 |
string message = "SmsTool> unlink "; |
string message = "SmsTool> unlink "; |
142 |
message += path; |
message += path; |
143 |
message += " failed: "; |
message += " failed: "; |
144 |
message += strerror(errno); |
message += strerror(errno); |
145 |
throw std::runtime_error( message ); |
throw std::runtime_error( message ); |
148 |
|
|
149 |
unsigned int pos = file.find("\n\n"); |
unsigned int pos = file.find("\n\n"); |
150 |
|
|
151 |
if (pos != string::npos) { |
if (pos != string::npos) |
152 |
|
{ |
153 |
string header = file.substr(0,pos); |
string header = file.substr(0,pos); |
154 |
string body = file.substr(pos+2,1024); |
string body = file.substr(pos+2,1024); |
155 |
|
|
158 |
|
|
159 |
ParseHeaders(header, sms); |
ParseHeaders(header, sms); |
160 |
|
|
161 |
} else { |
} |
162 |
|
else |
163 |
|
{ |
164 |
throw std::runtime_error("SmsTool: invalid incomming file"); |
throw std::runtime_error("SmsTool: invalid incomming file"); |
165 |
} |
} |
166 |
|
|
171 |
{ |
{ |
172 |
std::vector<std::string> headers = Util::str_split(headerstring, "\n"); |
std::vector<std::string> headers = Util::str_split(headerstring, "\n"); |
173 |
|
|
174 |
for (unsigned int i=0; i<headers.size(); i++) |
for (unsigned int i=0; i<headers.size(); i++) |
175 |
{ |
{ |
176 |
unsigned int pos = headers[i].find(":"); |
unsigned int pos = headers[i].find(":"); |
177 |
if (pos != string::npos) |
if (pos != string::npos) |