/[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 78 by torben, Sat Jun 14 08:39:40 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    
11  std::string GetSmsCommand(SMS& sms)  std::string GetSmsCommand(SMS& sms)
12  {  {
13          unsigned int pos = sms.message.find(" ");          unsigned int pos = sms.message.find(" ");
14    
15            std::string result;
16    
17          if (pos == std::string::npos)          if (pos == std::string::npos)
18                  return sms.message;                  result =  sms.message;
19          else          else
20                  return sms.message.substr(0, pos);                  result = sms.message.substr(0, pos);
21    
22            return Util::str_trim(result);
23  }  }
24    
25  std::string GetSmsData(SMS& sms)  std::string GetSmsData(SMS& sms)
# Line 29  std::string GetSmsData(SMS& sms) Line 34  std::string GetSmsData(SMS& sms)
34                                    
35                  std::string data =  sms.message.substr(pos, sms.message.length()-pos );                  std::string data =  sms.message.substr(pos, sms.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 65  SMS SMS::FromRawString(const std::string Line 69  SMS SMS::FromRawString(const std::string
69                  }                  }
70          }          }
71    
72          while(body.at(0) == ' ') //remove starting space from body          body = Util::str_trim(body);
                 body = body.substr( 1, body.length() -1);  
73    
74          SMS newsms;          SMS newsms;
75    
76          newsms.sms_index = fields[0];          newsms.sms_index = fields[0];
77    
78          newsms.sender = fields[2];          newsms.sender = fields[2];
79          Util::str_clean(&newsms.sender, "\"");          newsms.sender = Util::str_replace(newsms.sender, "\"");
80                    
81          newsms.timestamp = fields[4] + std::string(",") + fields[5];          newsms.timestamp = fields[4] + std::string(",") + fields[5];    
82          Util::str_clean(&newsms.timestamp, "\"");          newsms.timestamp = Util::str_replace(newsms.timestamp, "\"");
83    
84          newsms.message = body;          newsms.message = body;
85    
86          return newsms;          return newsms;
87  }  }
88    
89    SMS SMS::FromPduString(const std::string& input)
90    {
91            std::string smsline = input.substr(7, input.length() -7); //strip "+CMGL: "    
92    
93            std::vector<std::string> lines = Util::str_split(smsline, "\r\n");
94            std::vector<std::string> fields = Util::str_split(lines[0],",");
95    
96            SMS newsms = SmsPdu::ParseSmsPdu(lines[1]);
97    
98            newsms.sms_index = fields[0];
99    
100            return newsms;
101    }
102    
103    

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

  ViewVC Help
Powered by ViewVC 1.1.20