--- smsdaemon/SmsPdu.cpp 2008/06/13 07:56:57 70 +++ smsdaemon/SmsPdu.cpp 2008/12/08 21:49:49 158 @@ -10,14 +10,12 @@ #include #include -#include "common.h" -#include "util.h" +#include "Logger.h" +#include "Util.h" -#include using namespace std; - namespace SmsPdu { @@ -36,6 +34,9 @@ string EncodePhonenr(string input) { + if ( input.at(0) == '+' ) + input.erase(0,1); + if ( (input.length() % 2) == 1) input.append("F"); return SwitchChars(input); @@ -78,7 +79,7 @@ return vec; } - std::string Decode8to7bit(vector input, int shift_start = 0) + std::string Decode8to7bit(vector input, int shift_start) { string result; @@ -110,11 +111,11 @@ - vector Encode7to8bit(std::string str) + vector Encode7to8bit(std::string str, int shift_start) { vector buf; - int shift = 0; + int shift = shift_start; for (unsigned int i=0; i 800) { - Common::instance()->logMessage("Trying to send multipart sms > 800 bytes !!!"); + Logger::logMessage("Trying to send multipart sms > 800 bytes !!!"); message = message.substr(0,800); } @@ -178,18 +178,19 @@ pdu.push_back(to.length() ); //length of phone nr pdu.push_back(0x81); // type of address (international nr + ISDN/telephone range) - else try 0x81 - - string phone = EncodePhonenr(to); + + vector phone = HexDecodeString( EncodePhonenr(to )); pdu.insert( pdu.end(), phone.begin(), phone.end()); pdu.push_back(0x00); // Protocol identifier pdu.push_back(0x00); // Data coding scheme + int shift_start = 0; string message_part; if (multipart) { message_part = message.substr(0, PDU_LEN); - message.erase(0, PDU_LEN); + message.erase(0, PDU_LEN-1); pdu.push_back( message_part.length()+ 7 ); //UserDataLength pdu.push_back( 0x06 ); // UDH Len @@ -199,14 +200,14 @@ pdu.push_back( part_count ); pdu.push_back( partnr+1 ); pdu.push_back( 0x00); - + //shift_start = 6; } else { if (message.length() > 160) { message_part = message.substr(0,160); //truncate to 160 - Common::instance()->logMessage("Truncated message"); + Logger::logMessage("Truncated message"); } else { @@ -216,7 +217,7 @@ pdu.push_back( message_part.length() ); //UserDataLength } - vector userData = Encode7to8bit(message_part); + vector userData = Encode7to8bit(message_part, shift_start); pdu.insert( pdu.end(), userData.begin(), userData.end()); @@ -275,7 +276,6 @@ SMS ParseSmsPdu(std::string pdu_str) { - SMS result; vector pdu = HexDecodeString(pdu_str); @@ -293,13 +293,13 @@ ++it; //ignore Type-Of-Address - result.sender = DecodeRawPhonenr( it, it+(sender_len/2) ); + string sender = DecodeRawPhonenr( it, it+(sender_len/2) ); it += (sender_len/2); ++it; //protocol identifier ++it; //Data encoding - result.timestamp = DecodeTimestamp(it, it+7); + string timestamp = DecodeTimestamp(it, it+7); it += 7; @@ -309,20 +309,23 @@ if (UDHI) { int udh_len = (*it++); - cout << "UDH_LEN:" << udh_len << endl; it += udh_len; //just ignore the User Data Header data_len -= udh_len; shift_start = udh_len+1; //make the 8to7bit decode start with the right shift level } - cout << hex<< (int)(*it) << endl;; vector user_data; user_data.insert(user_data.end(), it, it+data_len); - result.message = Decode8to7bit(user_data, shift_start); + string message = Decode8to7bit(user_data, shift_start).substr(0,data_len); + + message = Util::str_trim(message); + SMS result; + result.SetMessage(message); + result.SetSender(sender); return result; }