/[projects]/smsdaemon/Sms.cpp
ViewVC logotype

Diff of /smsdaemon/Sms.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 78 by torben, Sat Jun 14 08:39:40 2008 UTC revision 142 by torben, Sun Dec 7 15:51:02 2008 UTC
# Line 8  Line 8 
8    
9    
10    
11  std::string GetSmsCommand(SMS& sms)  std::string SMS::ExtractCommand()
12  {  {
13          unsigned int pos = sms.message.find(" ");          unsigned int pos = message.find(" ");
14    
15          std::string result;          std::string result;
16    
17          if (pos == std::string::npos)          if (pos == std::string::npos)
18                  result =  sms.message;                  result =  message;
19          else          else
20                  result = sms.message.substr(0, pos);                  result = message.substr(0, pos);
21    
22          return Util::str_trim(result);          return Util::str_trim(result);
23  }  }
24    
25  std::string GetSmsData(SMS& sms)  std::string SMS::ExtractParameters()
26  {  {
27          unsigned int pos = sms.message.find(" ");          unsigned int pos = message.find(" ");
28    
29          if (pos == std::string::npos)          if (pos == std::string::npos)
30                  return "";                  return "";
# Line 32  std::string GetSmsData(SMS& sms) Line 32  std::string GetSmsData(SMS& sms)
32          {          {
33                  pos++;                  pos++;
34                                    
35                  std::string data =  sms.message.substr(pos, sms.message.length()-pos );                  std::string data = message.substr(pos, message.length()-pos );
36    
37                  data = Util::str_trim(data);                  data = Util::str_trim(data);
38                  return data;                  return data;
# Line 43  SMS::SMS() Line 43  SMS::SMS()
43  {  {
44  }  }
45    
46  SMS::SMS(std::string _sender, std::string _message, std::string _timestamp)  SMS::SMS(std::string _index, std::string _sender, std::string _message, std::string _timestamp)
47   : sender(_sender), message(_message), timestamp(_timestamp)   : sms_index(_index), sender(_sender), message(_message), timestamp(_timestamp)
48  {  {
49  }  }
50    
 SMS SMS::FromRawString(const std::string& input)  
 {  
         std::string smsline = input.substr(7, input.length() -7); //strip "+CMGL: "      
   
         std::vector<std::string> lines = Util::str_split(smsline, "\r\n");  
         std::vector<std::string> fields = Util::str_split(lines[0],",");  
   
         std::string body;  
         for (unsigned i=1; i<lines.size(); ++i)  
         {  
                 std::string body_line = lines[i];  
   
   
                 if (body_line != "")  
                 {  
                         if (body.length() > 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<std::string> lines = Util::str_split(smsline, "\r\n");  
         std::vector<std::string> fields = Util::str_split(lines[0],",");  
   
         SMS newsms = SmsPdu::ParseSmsPdu(lines[1]);  
   
         newsms.sms_index = fields[0];  
   
         return newsms;  
 }  
   
   

Legend:
Removed from v.78  
changed lines
  Added in v.142

  ViewVC Help
Powered by ViewVC 1.1.20