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

Diff of /smsdaemon/SmsToolTransceiver.cpp

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

revision 180 by torben, Fri Dec 12 12:54:27 2008 UTC revision 196 by torben, Thu Dec 18 06:53:29 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    
# Line 71  void SmsToolTransceiver::SendSms(std::st Line 75  void SmsToolTransceiver::SendSms(std::st
75          out.close();          out.close();
76    
77          Common::instance()->smsCounter.outgoing++;          Common::instance()->smsCounter.outgoing++;
78            
79          int result = rename(tempfile.c_str(), destfile.c_str());          int result = rename(tempfile.c_str(), destfile.c_str());
80    
81          if (result)          if (result)
# Line 93  std::vector<SMS> SmsToolTransceiver::Rea Line 97  std::vector<SMS> SmsToolTransceiver::Rea
97          std::vector<SMS> vec;          std::vector<SMS> vec;
98          DIR* dir = opendir( inboxdir.c_str() );          DIR* dir = opendir( inboxdir.c_str() );
99    
100          if (dir != 0)          if (dir != 0)
101          {          {
102                  dirent* entry;                  dirent* entry;
103                  while ( (entry = readdir(dir)) != 0)                  while ( (entry = readdir(dir)) != 0)
# Line 106  std::vector<SMS> SmsToolTransceiver::Rea Line 110  std::vector<SMS> SmsToolTransceiver::Rea
110                          {                          {
111                                  SMS sms = ParseFile( inboxdir + entry->d_name);                                  SMS sms = ParseFile( inboxdir + entry->d_name);
112                                  vec.push_back(sms);                                  vec.push_back(sms);
113                          }                          }
114                          catch (std::exception& e)                          catch (std::exception& e)
115                          {                          {
116                                  Logger::logMessage(e.what());                                  Logger::logMessage(e.what());
117                          }                          }
# Line 129  std::vector<SMS> SmsToolTransceiver::Rea Line 133  std::vector<SMS> SmsToolTransceiver::Rea
133  SMS SmsToolTransceiver::ParseFile(std::string path)  SMS SmsToolTransceiver::ParseFile(std::string path)
134  {  {
135          SMS sms;          SMS sms;
136            
137          string file = Util::readfile(path);          string file = Util::readfile(path);
138          int result = ::unlink(path.c_str());          int result = ::unlink(path.c_str());
139          if (result)          if (result)
140          {          {
141                  string message = "SmsTool> unlink ";                  string message = "SmsTool> unlink ";
142                  message += path;                  message += path;
143                  message += " failed: ";                  message += " failed: ";
144                  message += strerror(errno);                  message += strerror(errno);
145                  throw std::runtime_error( message );                  throw std::runtime_error( message );
# Line 144  SMS SmsToolTransceiver::ParseFile(std::s Line 148  SMS SmsToolTransceiver::ParseFile(std::s
148    
149          unsigned int pos = file.find("\n\n");          unsigned int pos = file.find("\n\n");
150    
151          if (pos != string::npos) {          if (pos != string::npos)
152            {
153                  string header = file.substr(0,pos);                  string header = file.substr(0,pos);
154                  string body = file.substr(pos+2,1024);                  string body = file.substr(pos+2,1024);
155    
# Line 153  SMS SmsToolTransceiver::ParseFile(std::s Line 158  SMS SmsToolTransceiver::ParseFile(std::s
158    
159                  ParseHeaders(header, sms);                  ParseHeaders(header, sms);
160    
161          } else {          }
162            else
163            {
164                  throw std::runtime_error("SmsTool: invalid incomming file");                  throw std::runtime_error("SmsTool: invalid incomming file");
165          }          }
166    
# Line 164  void SmsToolTransceiver::ParseHeaders(st Line 171  void SmsToolTransceiver::ParseHeaders(st
171  {  {
172          std::vector<std::string> headers = Util::str_split(headerstring, "\n");          std::vector<std::string> headers = Util::str_split(headerstring, "\n");
173    
174          for (unsigned int i=0; i<headers.size(); i++)          for (unsigned int i=0; i<headers.size(); i++)
175          {          {
176                  unsigned int  pos = headers[i].find(":");                  unsigned int  pos = headers[i].find(":");
177                  if (pos != string::npos)                  if (pos != string::npos)

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

  ViewVC Help
Powered by ViewVC 1.1.20