--- smsdaemon/Sms.cpp 2008/06/10 20:28:42 39 +++ smsdaemon/Sms.cpp 2008/12/07 15:51:02 142 @@ -2,24 +2,29 @@ #include #include -#include #include "Sms.h" #include "util.h" +#include "SmsPdu.h" -std::string GetSmsCommand(SMS& sms) + +std::string SMS::ExtractCommand() { - unsigned int pos = sms.message.find(" "); + unsigned int pos = message.find(" "); + + std::string result; if (pos == std::string::npos) - return sms.message; + result = message; else - return sms.message.substr(0, pos); + result = message.substr(0, pos); + + return Util::str_trim(result); } -std::string GetSmsData(SMS& sms) +std::string SMS::ExtractParameters() { - unsigned int pos = sms.message.find(" "); + unsigned int pos = message.find(" "); if (pos == std::string::npos) return ""; @@ -27,7 +32,7 @@ { pos++; - std::string data = sms.message.substr(pos, sms.message.length()-pos ); + std::string data = message.substr(pos, message.length()-pos ); data = Util::str_trim(data); return data; @@ -38,46 +43,8 @@ { } -SMS::SMS(std::string _sender, std::string _message, std::string _timestamp) - : sender(_sender), message(_message), timestamp(_timestamp) +SMS::SMS(std::string _index, std::string _sender, std::string _message, std::string _timestamp) + : sms_index(_index), sender(_sender), message(_message), timestamp(_timestamp) { } -SMS SMS::FromRawString(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],","); - - std::string body; - for (unsigned i=1; i 0) - body += "\r\n"; - body += body_line; - } - } - - body = Util::str_trim(body); - - SMS newsms; - - newsms.sms_index = fields[0]; - - newsms.sender = fields[2]; - newsms.sender = Util::str_replace(newsms.sender, "\""); - - newsms.timestamp = fields[4] + std::string(",") + fields[5]; - newsms.timestamp = Util::str_replace(newsms.timestamp, "\""); - - newsms.message = body; - - return newsms; -} -