#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) result = sms.message; else result = sms.message.substr(0, pos); return Util::str_trim(result); } std::string GetSmsData(SMS& sms) { unsigned int pos = sms.message.find(" "); if (pos == std::string::npos) return ""; else { pos++; std::string data = sms.message.substr(pos, sms.message.length()-pos ); data = Util::str_trim(data); return data; } } SMS::SMS() { } SMS::SMS(std::string _sender, std::string _message, std::string _timestamp) : 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; } 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; }