1 |
torben |
26 |
|
2 |
|
|
#include <string> |
3 |
|
|
#include <vector> |
4 |
|
|
|
5 |
|
|
#include <iostream> |
6 |
|
|
#include "Sms.h" |
7 |
|
|
#include "util.h" |
8 |
|
|
|
9 |
|
|
|
10 |
|
|
std::string GetSmsCommand(SMS& sms) |
11 |
|
|
{ |
12 |
|
|
unsigned int pos = sms.message.find(" "); |
13 |
|
|
|
14 |
|
|
if (pos == std::string::npos) |
15 |
|
|
return sms.message; |
16 |
|
|
else |
17 |
|
|
return sms.message.substr(0, pos); |
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
std::string GetSmsData(SMS& sms) |
21 |
|
|
{ |
22 |
|
|
unsigned int pos = sms.message.find(" "); |
23 |
|
|
|
24 |
|
|
if (pos == std::string::npos) |
25 |
|
|
return ""; |
26 |
|
|
else |
27 |
|
|
{ |
28 |
|
|
pos++; |
29 |
|
|
|
30 |
|
|
std::string data = sms.message.substr(pos, sms.message.length()-pos ); |
31 |
|
|
|
32 |
torben |
39 |
data = Util::str_trim(data); |
33 |
torben |
26 |
return data; |
34 |
|
|
} |
35 |
|
|
} |
36 |
|
|
|
37 |
|
|
SMS::SMS() |
38 |
|
|
{ |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
SMS::SMS(std::string _sender, std::string _message, std::string _timestamp) |
42 |
|
|
: sender(_sender), message(_message), timestamp(_timestamp) |
43 |
|
|
{ |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
SMS SMS::FromRawString(const std::string& input) |
47 |
|
|
{ |
48 |
|
|
std::string smsline = input.substr(7, input.length() -7); //strip "+CMGL: " |
49 |
|
|
|
50 |
|
|
std::vector<std::string> lines = Util::str_split(smsline, "\r\n"); |
51 |
|
|
std::vector<std::string> fields = Util::str_split(lines[0],","); |
52 |
|
|
|
53 |
|
|
std::string body; |
54 |
|
|
for (unsigned i=1; i<lines.size(); ++i) |
55 |
|
|
{ |
56 |
|
|
std::string body_line = lines[i]; |
57 |
|
|
|
58 |
|
|
|
59 |
|
|
if (body_line != "") |
60 |
|
|
{ |
61 |
|
|
if (body.length() > 0) |
62 |
|
|
body += "\r\n"; |
63 |
|
|
body += body_line; |
64 |
|
|
} |
65 |
|
|
} |
66 |
|
|
|
67 |
torben |
39 |
body = Util::str_trim(body); |
68 |
torben |
26 |
|
69 |
|
|
SMS newsms; |
70 |
|
|
|
71 |
|
|
newsms.sms_index = fields[0]; |
72 |
|
|
|
73 |
|
|
newsms.sender = fields[2]; |
74 |
torben |
38 |
newsms.sender = Util::str_replace(newsms.sender, "\""); |
75 |
torben |
26 |
|
76 |
torben |
38 |
newsms.timestamp = fields[4] + std::string(",") + fields[5]; |
77 |
|
|
newsms.timestamp = Util::str_replace(newsms.timestamp, "\""); |
78 |
torben |
26 |
|
79 |
|
|
newsms.message = body; |
80 |
|
|
|
81 |
|
|
return newsms; |
82 |
|
|
} |