--- smsdaemon/Sms.cpp 2008/06/09 18:15:53 26 +++ smsdaemon/Sms.cpp 2008/06/13 10:10:06 75 @@ -2,9 +2,10 @@ #include #include -#include #include "Sms.h" #include "util.h" +#include "SmsPdu.h" + std::string GetSmsCommand(SMS& sms) @@ -29,8 +30,7 @@ std::string data = sms.message.substr(pos, sms.message.length()-pos ); - while (data.at(0) == ' ') - data = data.substr(1, data.length() -1); + data = Util::str_trim(data); return data; } } @@ -65,21 +65,35 @@ } } - while(body.at(0) == ' ') //remove starting space from body - body = body.substr( 1, body.length() -1); + body = Util::str_trim(body); SMS newsms; newsms.sms_index = fields[0]; newsms.sender = fields[2]; - Util::str_clean(&newsms.sender, "\""); + newsms.sender = Util::str_replace(newsms.sender, "\""); - newsms.timestamp = fields[4] + std::string(",") + fields[5]; - Util::str_clean(&newsms.timestamp, "\""); + newsms.timestamp = fields[4] + std::string(",") + fields[5]; + newsms.timestamp = Util::str_replace(newsms.timestamp, "\""); newsms.message = body; return newsms; } +SMS SMS::FromPduString(const std::string& input) +{ + std::string smsline = input.substr(7, input.length() -7); //strip "+CMGL: " + + std::vector lines = Util::str_split(smsline, "\r\n"); + std::vector fields = Util::str_split(lines[0],","); + + SMS newsms = SmsPdu::ParseSmsPdu(lines[1]); + + newsms.sms_index = fields[0]; + + return newsms; +} + +