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

Diff of /smsdaemon/SmsToolTransceiver.cpp

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

revision 168 by torben, Tue Dec 9 21:44:15 2008 UTC revision 210 by torben, Sun Dec 21 21:14:40 2008 UTC
# Line 23  using namespace std; Line 23  using namespace std;
23  string appendSlash(string& str)  string appendSlash(string& str)
24  {  {
25          if (str.at(str.length()-1) != '/');          if (str.at(str.length()-1) != '/');
26                  str += "/";          str += "/";
27          return str;          return str;
28  }  }
29    
# Line 34  SmsToolTransceiver::SmsToolTransceiver() Line 34  SmsToolTransceiver::SmsToolTransceiver()
34          try          try
35          {          {
36                  inboxdir = cmn->GetConfigfile()->GetValue("smstools","inboxdir").StringValue();                  inboxdir = cmn->GetConfigfile()->GetValue("smstools","inboxdir").StringValue();
37          } catch (...) {          }
38            catch (...)
39            {
40                  Logger::logMessage("Config error> smstools::inboxdir not specified");                  Logger::logMessage("Config error> smstools::inboxdir not specified");
41                  exit(1);                  exit(1);
42          }          }
43          try          try
44          {          {
45                  outgoingdir = cmn->GetConfigfile()->GetValue("smstools","outgoingdir").StringValue();                  outgoingdir = cmn->GetConfigfile()->GetValue("smstools","outgoingdir").StringValue();
46          } catch (...) {          }
47            catch (...)
48            {
49                  Logger::logMessage("Config error> smstools::outgoingdir not specified");                  Logger::logMessage("Config error> smstools::outgoingdir not specified");
50                  exit(1);                  exit(1);
51          }          }
52    
53          inboxdir = appendSlash(inboxdir);          inboxdir = appendSlash(inboxdir);
54          outgoingdir = appendSlash(outgoingdir);          outgoingdir = appendSlash(outgoingdir);
55            
56  }  }
57    
58    
59  void SmsToolTransceiver::SendSms(std::string to, std::string message, bool allowMultipart)  void SmsToolTransceiver::SendSms(std::string to, std::string message, bool allowMultipart)
60  {  {
61            if (allowMultipart == false && message.size() > 160)
62                    message = message.substr(0,160);
63            
64    
65          std::string filename = CreateFilename();          std::string filename = CreateFilename();
66          Logger::logMessage( std::string("Sending sms to: ") + to);          Logger::logMessage( std::string("Sending sms to: ") + to);
67    
# Line 71  void SmsToolTransceiver::SendSms(std::st Line 79  void SmsToolTransceiver::SendSms(std::st
79          out.close();          out.close();
80    
81          Common::instance()->smsCounter.outgoing++;          Common::instance()->smsCounter.outgoing++;
82            
83          int result = rename(tempfile.c_str(), destfile.c_str());          int result = rename(tempfile.c_str(), destfile.c_str());
84    
85          if (result)          if (result)
# Line 93  std::vector<SMS> SmsToolTransceiver::Rea Line 101  std::vector<SMS> SmsToolTransceiver::Rea
101          std::vector<SMS> vec;          std::vector<SMS> vec;
102          DIR* dir = opendir( inboxdir.c_str() );          DIR* dir = opendir( inboxdir.c_str() );
103    
104          if (dir != 0)          if (dir != 0)
105          {          {
106                  dirent* entry;                  dirent* entry;
107                  while ( (entry = readdir(dir)) != 0)                  while ( (entry = readdir(dir)) != 0)
# Line 106  std::vector<SMS> SmsToolTransceiver::Rea Line 114  std::vector<SMS> SmsToolTransceiver::Rea
114                          {                          {
115                                  SMS sms = ParseFile( inboxdir + entry->d_name);                                  SMS sms = ParseFile( inboxdir + entry->d_name);
116                                  vec.push_back(sms);                                  vec.push_back(sms);
117                          }                          }
118                          catch (std::exception& e)                          catch (std::exception& e)
119                          {                          {
120                                  Logger::logMessage(e.what());                                  Logger::logMessage(e.what());
121                          }                          }
# Line 125  std::vector<SMS> SmsToolTransceiver::Rea Line 133  std::vector<SMS> SmsToolTransceiver::Rea
133          return vec;          return vec;
134  }  }
135    
 void SmsToolTransceiver::DeleteSms(std::string smsIndex)  
 {  
 }  
136    
137  SMS SmsToolTransceiver::ParseFile(std::string path)  SMS SmsToolTransceiver::ParseFile(std::string path)
138  {  {
139          SMS sms;          SMS sms;
140            
141          string file = Util::readfile(path);          string file = Util::readfile(path);
142          int result = ::unlink(path.c_str());          int result = ::unlink(path.c_str());
143          if (result)          if (result)
144          {          {
145                  string message = "SmsTool> unlink ";                  string message = "SmsTool> unlink ";
146                  message += path;                  message += path;
147                  message += " failed: ";                  message += " failed: ";
148                  message += strerror(errno);                  message += strerror(errno);
149                  throw std::runtime_error( message );                  throw std::runtime_error( message );
# Line 147  SMS SmsToolTransceiver::ParseFile(std::s Line 152  SMS SmsToolTransceiver::ParseFile(std::s
152    
153          unsigned int pos = file.find("\n\n");          unsigned int pos = file.find("\n\n");
154    
155          if (pos != string::npos) {          if (pos != string::npos)
156            {
157                  string header = file.substr(0,pos);                  string header = file.substr(0,pos);
158                  string body = file.substr(pos+2,1024);                  string body = file.substr(pos+2,1024);
159    
# Line 156  SMS SmsToolTransceiver::ParseFile(std::s Line 162  SMS SmsToolTransceiver::ParseFile(std::s
162    
163                  ParseHeaders(header, sms);                  ParseHeaders(header, sms);
164    
165          } else {          }
166            else
167            {
168                  throw std::runtime_error("SmsTool: invalid incomming file");                  throw std::runtime_error("SmsTool: invalid incomming file");
169          }          }
170    
# Line 167  void SmsToolTransceiver::ParseHeaders(st Line 175  void SmsToolTransceiver::ParseHeaders(st
175  {  {
176          std::vector<std::string> headers = Util::str_split(headerstring, "\n");          std::vector<std::string> headers = Util::str_split(headerstring, "\n");
177    
178          for (unsigned int i=0; i<headers.size(); i++)          for (unsigned int i=0; i<headers.size(); i++)
179          {          {
180                  unsigned int  pos = headers[i].find(":");                  unsigned int  pos = headers[i].find(":");
181                  if (pos != string::npos)                  if (pos != string::npos)
# Line 189  void SmsToolTransceiver::ParseHeaders(st Line 197  void SmsToolTransceiver::ParseHeaders(st
197    
198  }  }
199    
 int SmsToolTransceiver::DeleteAllSms()  
 {  
         return 0;  
 }  
200    
201    

Legend:
Removed from v.168  
changed lines
  Added in v.210

  ViewVC Help
Powered by ViewVC 1.1.20