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

Diff of /smsdaemon/Sms.cpp

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

revision 26 by torben, Mon Jun 9 18:15:53 2008 UTC revision 158 by torben, Mon Dec 8 21:49:49 2008 UTC
# Line 2  Line 2 
2  #include <string>  #include <string>
3  #include <vector>  #include <vector>
4    
 #include <iostream>  
5  #include "Sms.h"  #include "Sms.h"
6  #include "util.h"  #include "Util.h"
7    #include "SmsPdu.h"
8    
9    
10  std::string GetSmsCommand(SMS& sms)  
11    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 "";
# Line 27  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                  while (data.at(0) == ' ')                  data = Util::str_trim(data);
                         data = data.substr(1, data.length() -1);  
38                  return data;                  return data;
39          }          }
40  }  }
# 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)
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;  
                 }  
         }  
   
         while(body.at(0) == ' ') //remove starting space from body  
                 body = body.substr( 1, body.length() -1);  
   
         SMS newsms;  
   
         newsms.sms_index = fields[0];  
   
         newsms.sender = fields[2];  
         Util::str_clean(&newsms.sender, "\"");  
           
         newsms.timestamp = fields[4] + std::string(",") + fields[5];  
         Util::str_clean(&newsms.timestamp, "\"");  
   
         newsms.message = body;  
   
         return newsms;  
 }  
   

Legend:
Removed from v.26  
changed lines
  Added in v.158

  ViewVC Help
Powered by ViewVC 1.1.20