--- smsdaemon/Sms.cpp 2008/06/10 20:25:15 38 +++ smsdaemon/Sms.cpp 2008/06/14 08:39:40 78 @@ -2,19 +2,24 @@ #include #include -#include #include "Sms.h" #include "util.h" +#include "SmsPdu.h" + std::string GetSmsCommand(SMS& sms) { unsigned int pos = sms.message.find(" "); + std::string result; + if (pos == std::string::npos) - return sms.message; + result = sms.message; else - return sms.message.substr(0, pos); + result = sms.message.substr(0, pos); + + return Util::str_trim(result); } std::string GetSmsData(SMS& sms) @@ -29,8 +34,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,8 +69,7 @@ } } - while(body.at(0) == ' ') //remove starting space from body - body = body.substr( 1, body.length() -1); + body = Util::str_trim(body); SMS newsms; @@ -83,3 +86,18 @@ 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; +} + +