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

Diff of /smsdaemon/SmsToolTransceiver.cpp

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

revision 167 by torben, Tue Dec 9 19:42:45 2008 UTC revision 168 by torben, Tue Dec 9 21:44:15 2008 UTC
# Line 3  Line 3 
3  #include "Logger.h"  #include "Logger.h"
4  #include "Util.h"  #include "Util.h"
5  #include "Common.h"  #include "Common.h"
6    #include "ConfigFile.h"
7    
8  #include <stdexcept>  #include <stdexcept>
9  #include <iostream>  #include <iostream>
# Line 19  Line 20 
20    
21  using namespace std;  using namespace std;
22    
23    string appendSlash(string& str)
24    {
25            if (str.at(str.length()-1) != '/');
26                    str += "/";
27            return str;
28    }
29    
30    SmsToolTransceiver::SmsToolTransceiver()
31    {
32            Common* cmn = Common::instance();
33    
34            try
35            {
36                    inboxdir = cmn->GetConfigfile()->GetValue("smstools","inboxdir").StringValue();
37            } catch (...) {
38                    Logger::logMessage("Config error> smstools::inboxdir not specified");
39                    exit(1);
40            }
41            try
42            {
43                    outgoingdir = cmn->GetConfigfile()->GetValue("smstools","outgoingdir").StringValue();
44            } catch (...) {
45                    Logger::logMessage("Config error> smstools::outgoingdir not specified");
46                    exit(1);
47            }
48    
49            inboxdir = appendSlash(inboxdir);
50            outgoingdir = appendSlash(outgoingdir);
51            
52    }
53    
54    
55  void SmsToolTransceiver::SendSms(std::string to, std::string message, bool allowMultipart)  void SmsToolTransceiver::SendSms(std::string to, std::string message, bool allowMultipart)
56  {  {
57          std::string filename = CreateFilename();          std::string filename = CreateFilename();
58          Logger::logMessage( std::string("Sending sms to: ") + to);          Logger::logMessage( std::string("Sending sms to: ") + to);
59    
60          string tempfile = "/var/spool/sms/";          string tempfile = outgoingdir + filename + ".LOCK";
         tempfile += filename;  
61    
62          string destfile = "/var/spool/sms/outgoing/";          string destfile = outgoingdir + filename;
         destfile += filename;  
63    
64          ofstream out( tempfile.c_str() );          ofstream out( tempfile.c_str() );
65          if (!out )          if (!out )
# Line 59  std::string SmsToolTransceiver::CreateFi Line 90  std::string SmsToolTransceiver::CreateFi
90    
91  std::vector<SMS> SmsToolTransceiver::ReadSms(bool readAll)  std::vector<SMS> SmsToolTransceiver::ReadSms(bool readAll)
92  {  {
         const std::string inbox = "/var/spool/sms/inbox/";  
93          std::vector<SMS> vec;          std::vector<SMS> vec;
94          DIR* dir = opendir( inbox.c_str() );          DIR* dir = opendir( inboxdir.c_str() );
95    
96          if (dir != 0)          if (dir != 0)
97          {          {
# Line 74  std::vector<SMS> SmsToolTransceiver::Rea Line 104  std::vector<SMS> SmsToolTransceiver::Rea
104    
105                          try                          try
106                          {                          {
107                                  SMS sms = ParseFile( inbox + entry->d_name);                                  SMS sms = ParseFile( inboxdir + entry->d_name);
108                                  vec.push_back(sms);                                  vec.push_back(sms);
109                          }                          }
110                          catch (std::exception& e)                          catch (std::exception& e)

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

  ViewVC Help
Powered by ViewVC 1.1.20