2 |
#include <string> |
#include <string> |
3 |
#include <vector> |
#include <vector> |
4 |
|
|
|
#include <iostream> |
|
5 |
#include "Sms.h" |
#include "Sms.h" |
6 |
#include "util.h" |
#include "Util.h" |
7 |
|
#include "SmsPdu.h" |
8 |
|
|
9 |
|
|
10 |
std::string GetSmsCommand(SMS& sms) |
|
11 |
|
std::string SMS::ExtractCommand() |
12 |
{ |
{ |
13 |
unsigned int pos = sms.message.find(" "); |
unsigned int pos = message.find(" "); |
14 |
|
|
15 |
|
std::string result; |
16 |
|
|
17 |
if (pos == std::string::npos) |
if (pos == std::string::npos) |
18 |
return sms.message; |
result = message; |
19 |
else |
else |
20 |
return sms.message.substr(0, pos); |
result = message.substr(0, pos); |
21 |
|
|
22 |
|
return Util::str_trim(result); |
23 |
} |
} |
24 |
|
|
25 |
std::string GetSmsData(SMS& sms) |
std::string SMS::ExtractParameters() |
26 |
{ |
{ |
27 |
unsigned int pos = sms.message.find(" "); |
unsigned int pos = message.find(" "); |
28 |
|
|
29 |
if (pos == std::string::npos) |
if (pos == std::string::npos) |
30 |
return ""; |
return ""; |
31 |
else |
else |
32 |
{ |
{ |
33 |
pos++; |
pos++; |
|
|
|
|
std::string data = sms.message.substr(pos, sms.message.length()-pos ); |
|
34 |
|
|
35 |
while (data.at(0) == ' ') |
std::string data = message.substr(pos, message.length()-pos ); |
36 |
data = data.substr(1, data.length() -1); |
|
37 |
|
data = Util::str_trim(data); |
38 |
return data; |
return data; |
39 |
} |
} |
40 |
} |
} |
43 |
{ |
{ |
44 |
} |
} |
45 |
|
|
46 |
SMS::SMS(std::string _sender, std::string _message, std::string _timestamp) |
SMS::SMS(std::string _index, std::string _sender, std::string _message, std::string _timestamp) |
47 |
: sender(_sender), message(_message), timestamp(_timestamp) |
: sms_index(_index), sender(_sender), message(_message), timestamp(_timestamp) |
|
{ |
|
|
} |
|
|
|
|
|
SMS SMS::FromRawString(const std::string& input) |
|
48 |
{ |
{ |
|
std::string smsline = input.substr(7, input.length() -7); //strip "+CMGL: " |
|
|
|
|
|
std::vector<std::string> lines = Util::str_split(smsline, "\r\n"); |
|
|
std::vector<std::string> fields = Util::str_split(lines[0],","); |
|
|
|
|
|
std::string body; |
|
|
for (unsigned i=1; i<lines.size(); ++i) |
|
|
{ |
|
|
std::string body_line = lines[i]; |
|
|
|
|
|
|
|
|
if (body_line != "") |
|
|
{ |
|
|
if (body.length() > 0) |
|
|
body += "\r\n"; |
|
|
body += body_line; |
|
|
} |
|
|
} |
|
|
|
|
|
while(body.at(0) == ' ') //remove starting space from body |
|
|
body = body.substr( 1, body.length() -1); |
|
|
|
|
|
SMS newsms; |
|
|
|
|
|
newsms.sms_index = fields[0]; |
|
|
|
|
|
newsms.sender = fields[2]; |
|
|
newsms.sender = Util::str_replace(newsms.sender, "\""); |
|
|
|
|
|
newsms.timestamp = fields[4] + std::string(",") + fields[5]; |
|
|
newsms.timestamp = Util::str_replace(newsms.timestamp, "\""); |
|
|
|
|
|
newsms.message = body; |
|
|
|
|
|
return newsms; |
|
49 |
} |
} |
50 |
|
|