10 |
#include <time.h> |
#include <time.h> |
11 |
#include <stdlib.h> |
#include <stdlib.h> |
12 |
|
|
13 |
#include "common.h" |
#include "Logger.h" |
14 |
#include "util.h" |
#include "Util.h" |
15 |
|
|
16 |
|
|
17 |
using namespace std; |
using namespace std; |
144 |
|
|
145 |
const unsigned char UDHI = multipart ? 0x40 : 0; |
const unsigned char UDHI = multipart ? 0x40 : 0; |
146 |
|
|
|
srand(time(0)); |
|
147 |
unsigned char csms_ref = rand() % 128; |
unsigned char csms_ref = rand() % 128; |
148 |
|
|
149 |
int part_count; |
int part_count; |
154 |
{ |
{ |
155 |
if (message.length() > 800) |
if (message.length() > 800) |
156 |
{ |
{ |
157 |
Common::instance()->logMessage("Trying to send multipart sms > 800 bytes !!!"); |
Logger::logMessage("Trying to send multipart sms > 800 bytes !!!"); |
158 |
message = message.substr(0,800); |
message = message.substr(0,800); |
159 |
} |
} |
160 |
|
|
190 |
if (multipart) |
if (multipart) |
191 |
{ |
{ |
192 |
message_part = message.substr(0, PDU_LEN); |
message_part = message.substr(0, PDU_LEN); |
193 |
message.erase(0, PDU_LEN); |
message.erase(0, PDU_LEN-1); |
194 |
|
|
195 |
pdu.push_back( message_part.length()+ 7 ); //UserDataLength |
pdu.push_back( message_part.length()+ 7 ); //UserDataLength |
196 |
pdu.push_back( 0x06 ); // UDH Len |
pdu.push_back( 0x06 ); // UDH Len |
207 |
if (message.length() > 160) |
if (message.length() > 160) |
208 |
{ |
{ |
209 |
message_part = message.substr(0,160); //truncate to 160 |
message_part = message.substr(0,160); //truncate to 160 |
210 |
Common::instance()->logMessage("Truncated message"); |
Logger::logMessage("Truncated message"); |
211 |
} |
} |
212 |
else |
else |
213 |
{ |
{ |
276 |
|
|
277 |
SMS ParseSmsPdu(std::string pdu_str) |
SMS ParseSmsPdu(std::string pdu_str) |
278 |
{ |
{ |
|
SMS result; |
|
279 |
|
|
280 |
vector<unsigned char> pdu = HexDecodeString(pdu_str); |
vector<unsigned char> pdu = HexDecodeString(pdu_str); |
281 |
|
|
293 |
|
|
294 |
++it; //ignore Type-Of-Address |
++it; //ignore Type-Of-Address |
295 |
|
|
296 |
result.sender = DecodeRawPhonenr( it, it+(sender_len/2) ); |
string sender = DecodeRawPhonenr( it, it+(sender_len/2) ); |
297 |
|
|
298 |
it += (sender_len/2); |
it += (sender_len/2); |
299 |
++it; //protocol identifier |
++it; //protocol identifier |
300 |
++it; //Data encoding |
++it; //Data encoding |
301 |
|
|
302 |
result.timestamp = DecodeTimestamp(it, it+7); |
string timestamp = DecodeTimestamp(it, it+7); |
303 |
it += 7; |
it += 7; |
304 |
|
|
305 |
|
|
319 |
vector<unsigned char> user_data; |
vector<unsigned char> user_data; |
320 |
user_data.insert(user_data.end(), it, it+data_len); |
user_data.insert(user_data.end(), it, it+data_len); |
321 |
|
|
322 |
result.message = Decode8to7bit(user_data, shift_start).substr(0,data_len); |
string message = Decode8to7bit(user_data, shift_start).substr(0,data_len); |
323 |
|
|
324 |
result.message = Util::str_trim(result.message); |
message = Util::str_trim(message); |
325 |
|
|
326 |
|
SMS result; |
327 |
|
result.SetMessage(message); |
328 |
|
result.SetSender(sender); |
329 |
|
|
330 |
return result; |
return result; |
331 |
} |
} |