--- smsdaemon/SmsToolTransceiver.cpp 2008/12/08 22:11:01 160 +++ smsdaemon/SmsToolTransceiver.cpp 2008/12/09 21:44:15 168 @@ -2,6 +2,8 @@ #include "Logger.h" #include "Util.h" +#include "Common.h" +#include "ConfigFile.h" #include #include @@ -18,16 +20,46 @@ using namespace std; +string appendSlash(string& str) +{ + if (str.at(str.length()-1) != '/'); + str += "/"; + return str; +} + +SmsToolTransceiver::SmsToolTransceiver() +{ + Common* cmn = Common::instance(); + + try + { + inboxdir = cmn->GetConfigfile()->GetValue("smstools","inboxdir").StringValue(); + } catch (...) { + Logger::logMessage("Config error> smstools::inboxdir not specified"); + exit(1); + } + try + { + outgoingdir = cmn->GetConfigfile()->GetValue("smstools","outgoingdir").StringValue(); + } catch (...) { + Logger::logMessage("Config error> smstools::outgoingdir not specified"); + exit(1); + } + + inboxdir = appendSlash(inboxdir); + outgoingdir = appendSlash(outgoingdir); + +} + + void SmsToolTransceiver::SendSms(std::string to, std::string message, bool allowMultipart) { std::string filename = CreateFilename(); Logger::logMessage( std::string("Sending sms to: ") + to); - string tempfile = "/var/spool/sms/"; - tempfile += filename; + string tempfile = outgoingdir + filename + ".LOCK"; - string destfile = "/var/spool/sms/outgoing/"; - destfile += filename; + string destfile = outgoingdir + filename; ofstream out( tempfile.c_str() ); if (!out ) @@ -58,9 +90,8 @@ std::vector SmsToolTransceiver::ReadSms(bool readAll) { - const std::string incoming = "/var/spool/sms/incoming/"; std::vector vec; - DIR* dir = opendir( incoming.c_str() ); + DIR* dir = opendir( inboxdir.c_str() ); if (dir != 0) { @@ -69,10 +100,11 @@ { if (entry->d_name[0] == '.') continue; - + Logger::logMessage( string("SmsTool::ReadSms >") +entry->d_name); + try { - SMS sms = ParseFile( incoming + entry->d_name); + SMS sms = ParseFile( inboxdir + entry->d_name); vec.push_back(sms); } catch (std::exception& e) @@ -86,7 +118,7 @@ } else { - Logger::logMessage( string("SmsToolTransceiver could open incoming dir ") + strerror(errno) ); + Logger::logMessage( string("SmsToolTransceiver could open inbox dir ") + strerror(errno) ); } closedir(dir); @@ -137,15 +169,22 @@ for (unsigned int i=0; i ") + headers[i]); + } } }