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; |
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 |
|
|
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 |
{ |
{ |
274 |
} |
} |
275 |
|
|
276 |
|
|
277 |
|
|
278 |
SMS ParseSmsPdu(std::string pdu_str) |
SMS ParseSmsPdu(std::string pdu_str) |
279 |
{ |
{ |
280 |
|
SmsPart part = ParseSmsPduWorker(pdu_str); |
281 |
|
|
282 |
|
|
283 |
|
SMS sms; |
284 |
|
sms.SetMessage(part.message); |
285 |
|
sms.SetSender(part.sender); |
286 |
|
return sms; |
287 |
|
} |
288 |
|
|
289 |
|
void ParseUdh(vector<unsigned char>& udh, SmsPart& part) |
290 |
|
{ |
291 |
|
if (udh.size() == 0) { |
292 |
|
Logger::logMessage("ParseUdh(): empty udh"); |
293 |
|
return; |
294 |
|
} |
295 |
|
|
296 |
|
if (udh[0] != 0) { |
297 |
|
Logger::logMessage("unknown UDH type"); |
298 |
|
return; |
299 |
|
} |
300 |
|
|
301 |
|
part.group = udh[2]; |
302 |
|
part.count = udh[3]; |
303 |
|
part.id = udh[4]; |
304 |
|
} |
305 |
|
|
306 |
|
|
307 |
|
SmsPart ParseSmsPduWorker(std::string pdu_str) |
308 |
|
{ |
309 |
|
|
310 |
vector<unsigned char> pdu = HexDecodeString(pdu_str); |
vector<unsigned char> pdu = HexDecodeString(pdu_str); |
311 |
|
|
335 |
|
|
336 |
unsigned char data_len = (*it++); |
unsigned char data_len = (*it++); |
337 |
|
|
338 |
|
|
339 |
|
SmsPart part; |
340 |
|
part.group = -1; |
341 |
|
|
342 |
int shift_start = 0; |
int shift_start = 0; |
343 |
|
|
344 |
if (UDHI) |
if (UDHI) |
345 |
{ |
{ |
346 |
int udh_len = (*it++); |
int udh_len = (*it++); |
347 |
it += udh_len; //just ignore the User Data Header |
|
348 |
|
vector<unsigned char> udh; |
349 |
|
for (int i=0; i<udh_len; i++) |
350 |
|
{ |
351 |
|
udh.push_back (*it++); |
352 |
|
} |
353 |
|
ParseUdh(udh,part); |
354 |
|
|
355 |
data_len -= udh_len; |
data_len -= udh_len; |
356 |
|
|
357 |
shift_start = udh_len+1; //make the 8to7bit decode start with the right shift level |
shift_start = udh_len+1; //make the 8to7bit decode start with the right shift level |
364 |
string message = Decode8to7bit(user_data, shift_start).substr(0,data_len); |
string message = Decode8to7bit(user_data, shift_start).substr(0,data_len); |
365 |
|
|
366 |
message = Util::str_trim(message); |
message = Util::str_trim(message); |
367 |
|
|
368 |
|
|
369 |
SMS result; |
part.message = message; |
370 |
result.SetMessage(message); |
part.sender = sender; |
|
result.SetSender(sender); |
|
371 |
|
|
372 |
return result; |
return part; |
373 |
} |
} |
374 |
|
|
375 |
} |
} |