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

Diff of /smsdaemon/Sms.cpp

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

revision 75 by torben, Fri Jun 13 10:10:06 2008 UTC revision 196 by torben, Thu Dec 18 06:53:29 2008 UTC
# Line 3  Line 3 
3  #include <vector>  #include <vector>
4    
5  #include "Sms.h"  #include "Sms.h"
6  #include "util.h"  #include "Util.h"
7  #include "SmsPdu.h"  #include "SmsPdu.h"
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;
16    
17          if (pos == std::string::npos)          if (pos == std::string::npos)
18                  return sms.message;                  result =  message;
19          else          else
20                  return sms.message.substr(0, pos);                  result = message.substr(0, pos);
21    
22            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 "";
31          else          else
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 39  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)
 {  
 }  
   
 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)  
48  {  {
         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;  
49  }  }
50    
   

Legend:
Removed from v.75  
changed lines
  Added in v.196

  ViewVC Help
Powered by ViewVC 1.1.20