diff --git a/update/agent/include/agent/linux/datasid-agent.h b/update/agent/include/agent/linux/datasid-agent.h index 5dff862fd156d9945682fd1ff16ccd7bc37b8324..359b22382d9b2a9b4d5dc647f4b689a6964f1332 100644 --- a/update/agent/include/agent/linux/datasid-agent.h +++ b/update/agent/include/agent/linux/datasid-agent.h @@ -23,28 +23,26 @@ #include <iostream> #include <cstring> -using namespace std; - class Agent{ private: - string confDir; - string logFile; - string prefix; - string version; + std::string confDir; + std::string logFile; + std::string prefix; + std::string version; public: - void setConfDir(string); - void setLogFile(string, string); - void setPrefix(string, int); - void setVersion(string); + void setConfDir(std::string); + void setLogFile(std::string, std::string); + void setPrefix(std::string, int); + void setVersion(std::string); - string getConfDir() const; - string getLogFile() const; - string getPrefix() const; - string getVersion() const; + std::string getConfDir() const; + std::string getLogFile() const; + std::string getPrefix() const; + std::string getVersion() const; }; -string cutString( string str, int tot ); +std::string cutString( std::string str, int tot ); int datasid_agent(); -bool prefixIsSet( string prefix ); +bool prefixIsSet( std::string prefix ); #endif diff --git a/update/agent/include/agent/linux/datasid-common.h b/update/agent/include/agent/linux/datasid-common.h index d3c69227bfc29046dcf5deacafaaf5bc64668d32..ef0848462e6ce2cda0eef5745b05d981eacba826 100644 --- a/update/agent/include/agent/linux/datasid-common.h +++ b/update/agent/include/agent/linux/datasid-common.h @@ -5,20 +5,16 @@ #include "datasid-conf.h" #include "datasid-proxy.h" -using namespace std; - class Common{ private: - string defaultConf; + std::string defaultConf; public: - void setDefaultConf(string, string); + void setDefaultConf(std::string, std::string); - string getDefaultConf() const; + std::string getDefaultConf() const; }; -void checkVersionFileExist(Agent& agent); -void createDirectories(Agent agent, Conf conf); bool fileExist(const char * file); -bool datasid_common(Conf& conf, Proxy& proxy, Agent& agent, Common& Common); +bool datasid_common(Conf* conf, Proxy* proxy, Agent* agent, Common* Common); #endif diff --git a/update/agent/include/agent/linux/datasid-conf.h b/update/agent/include/agent/linux/datasid-conf.h index aeddb1ef6fd570218cb61c043e1d6954252a1662..b163d4fd1cae493ed9198dc9d9e0767b5d27a541 100644 --- a/update/agent/include/agent/linux/datasid-conf.h +++ b/update/agent/include/agent/linux/datasid-conf.h @@ -27,16 +27,15 @@ #include <sstream> #include <map> #include "datasid-agent.h" +#include "datasid-conf.h" #include "datasid-parse.h" -using namespace std; - class Conf{ private: - string dataDir; - string logDir; - string proxyConf; - string webService; + std::string dataDir; + std::string logDir; + std::string proxyConf; + std::string webService; int delay; int daysToExpireLog; @@ -44,20 +43,20 @@ class Conf{ int updateTimeOut; public: - void setDataDir(string); - void setLogDir(string); - void setProxyConf(string); - void setWebService(string); + void setDataDir(std::string); + void setLogDir(std::string); + void setProxyConf(std::string); + void setWebService(std::string); void setDelay(int); void setDaysToExpireLog(int); void setUpdateTries(int); void setUpdatTimeOut(int); - string getDataDir() const; - string getLogDir() const; - string getProxyConf() const; - string getWebService() const; + std::string getDataDir() const; + std::string getLogDir() const; + std::string getProxyConf() const; + std::string getWebService() const; int getDelay() const; int getDaysToExpireLog() const; @@ -66,6 +65,6 @@ class Conf{ }; -bool setConf(Conf& conf, Agent agent, map<string,string>& content); -Conf datasid_conf(Agent agent); +bool setConf(Conf* conf, Agent* agent, std::map<std::string, std::string>* content); +void datasid_conf(Agent* agent, Conf* conf); #endif \ No newline at end of file diff --git a/update/agent/include/agent/linux/datasid-parse.h b/update/agent/include/agent/linux/datasid-parse.h index 243fe5f0c5be50c9ad220ee014495751cc51cda2..6e695e4c60afd330493a460c9e39547b23a6ca59 100644 --- a/update/agent/include/agent/linux/datasid-parse.h +++ b/update/agent/include/agent/linux/datasid-parse.h @@ -27,12 +27,10 @@ #include <locale> #include <map> -using namespace std; - -bool isvalid (string & line); -void normalize (string & str); -void parse ( string& line, map<string, string>& content); -bool readfile (const string file, map<string,string>& content); -bool spaceonly (const string& line); -void trim (string& str); +bool isvalid(std::string * line); +void normalize(std::string * str); +void parse(std::string * line, std::map<std::string, std::string> * content); +bool readfile(const std::string file, std::map<std::string, std::string> * content); +bool spaceonly(const std::string * line); +void trim(std::string& str); #endif \ No newline at end of file diff --git a/update/agent/include/agent/linux/datasid-proxy.h b/update/agent/include/agent/linux/datasid-proxy.h index 7c4cd2888709eb0f7b30de764620ce719c15b198..3bfe4cc8d1d7fb878010957c0769885392f33c30 100644 --- a/update/agent/include/agent/linux/datasid-proxy.h +++ b/update/agent/include/agent/linux/datasid-proxy.h @@ -28,27 +28,25 @@ #include "datasid-parse.h" #include "datasid-proxy.h" -using namespace std; - class Proxy{ private: - string host; - string port; - string user; - string password; + std::string host; + std::string port; + std::string user; + std::string password; public: - void setHost(string); - void setPort(string); - void setUser(string); - void setPassword(string); + void setHost(std::string); + void setPort(std::string); + void setUser(std::string); + void setPassword(std::string); - string getHost() const; - string getPort() const; - string getUser() const; - string getPassword() const; + std::string getHost() const; + std::string getPort() const; + std::string getUser() const; + std::string getPassword() const; }; -bool setProxy(Proxy& proxy, map<string,string>& content); -Proxy datasid_proxy(Conf conf); +bool setProxy(Proxy* proxy, std::map<std::string, std::string>* content); +void datasid_proxy(Conf* conf, Proxy* proxy); #endif \ No newline at end of file diff --git a/update/agent/include/agent/main.h b/update/agent/include/agent/main.h index dc7552db6aeede44bbc8066f10289101095848a5..45dd1eb1ddb64275a30917d602805453106ca2f4 100644 --- a/update/agent/include/agent/main.h +++ b/update/agent/include/agent/main.h @@ -8,6 +8,6 @@ #include "linux/datasid-agent.h" #include "linux/datasid-conf.h" -bool fileExist(const string& file); +bool fileExist(const std::string& file); int main(); #endif diff --git a/update/agent/src/linux/datasid-agent.cpp b/update/agent/src/linux/datasid-agent.cpp index b59ad9a8835940844a594348ea22ad40645628bf..2fb5ae599491d2e48429d3bac1a206e6bb55eea1 100644 --- a/update/agent/src/linux/datasid-agent.cpp +++ b/update/agent/src/linux/datasid-agent.cpp @@ -18,27 +18,26 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. */ +#include <string> #include "../../include/agent/main.h" -using namespace std; - /* * set Functions */ -void Agent::setConfDir(string dir){ +void Agent::setConfDir(std::string dir) { this->confDir = this->prefix + dir; } -void Agent::setLogFile(string logDir, string file){ +void Agent::setLogFile(std::string logDir, std::string file) { this->logFile = logDir + file; } -void Agent::setPrefix(string p, int t){ - this->prefix = cutString(p,t); +void Agent::setPrefix(std::string p, int t) { + this->prefix = cutString(p, t); } -void Agent::setVersion(string v){ +void Agent::setVersion(std::string v) { this->version = v; } @@ -46,19 +45,19 @@ void Agent::setVersion(string v){ * get Functions */ -string Agent::getConfDir() const{ +std::string Agent::getConfDir() const { return this->confDir; } -string Agent::getLogFile() const{ +std::string Agent::getLogFile() const { return this->logFile; } -string Agent::getPrefix() const{ +std::string Agent::getPrefix() const { return this->prefix; } -string Agent::getVersion() const{ +std::string Agent::getVersion() const { return this->version; } @@ -67,22 +66,22 @@ string Agent::getVersion() const{ * get the absolute path of the agent */ -string cutString( string str, int tot){; - int i=str.size(), count=0; - while(i-->-1) - if(str[i] == '/') - if(++count == tot) +std::string cutString(std::string str, int tot) { + int i = str.size(), count = 0; + while (i-->-1) + if (str[i] == '/') + if (++count == tot) break; - return str.substr(0,i); + return str.substr(0, i); } -bool prefixIsSet(string prefix){ - if(prefix.size() == 0) +bool prefixIsSet(std::string prefix) { + if (prefix.size() == 0) throw " ERROR: Prefix not set. "; return true; } -int datasid_agent(){ +int datasid_agent() { Agent agent; Conf conf; Proxy proxy; @@ -92,7 +91,7 @@ int datasid_agent(){ agent.setPrefix(__FILE__, 3); /* Run datasid-common.cpp */ - if(!datasid_common(conf, proxy, agent, common)) + if (!datasid_common(&conf, &proxy, &agent, &common)) exit(1); return 1; diff --git a/update/agent/src/linux/datasid-common.cpp b/update/agent/src/linux/datasid-common.cpp index 55be7f5197cbb418d32789adee3c9e9120ea6d1e..4039c60422f87123dde4f8130399ce6a86673f25 100644 --- a/update/agent/src/linux/datasid-common.cpp +++ b/update/agent/src/linux/datasid-common.cpp @@ -18,18 +18,18 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. */ +#include "string" #include "../../include/agent/linux/datasid-conf.h" #include "../../include/agent/linux/datasid-proxy.h" #include "../../include/agent/linux/datasid-agent.h" #include "../../include/agent/linux/datasid-common.h" #include "../../include/agent/main.h" -using namespace std; /* * set Functions */ -void Common::setDefaultConf(string defaultConf, string prefix){ +void Common::setDefaultConf(std::string defaultConf, std::string prefix) { this->defaultConf = prefix + defaultConf; } @@ -37,7 +37,7 @@ void Common::setDefaultConf(string defaultConf, string prefix){ * get Functions */ -string Common::getDefaultConf() const{ +std::string Common::getDefaultConf() const { return this->defaultConf; } @@ -46,9 +46,9 @@ string Common::getDefaultConf() const{ * verify if a file exist */ -bool fileExist(const string& file){ - ifstream myFile (file.c_str(), ios::in); - if(myFile.is_open()){ +bool fileExist(const std::string& file) { + std::ifstream myFile(file.c_str(), std::ifstream::in); + if (myFile.is_open()) { myFile.close(); return true; } @@ -57,30 +57,30 @@ bool fileExist(const string& file){ } -bool datasid_common(Conf& conf, Proxy& proxy, Agent& agent, Common& common){ - - try{ - prefixIsSet(agent.getPrefix()); - }catch(const char* msg){ - cout << __DATE__ << msg << endl; +bool datasid_common(Conf* conf, Proxy* proxy, Agent* agent, Common* common) { + try { + prefixIsSet(agent->getPrefix()); + } catch (const char* msg) { + std::cout << __DATE__ << msg << std::endl; return false; } /* Read config file and declare only valid variables */ - common.setDefaultConf("/conf/datasid-conf.json", agent.getPrefix()); - if(!fileExist(common.getDefaultConf())){ - cout << __DATE__ << "- ERROR: Config file not found. " << endl; + common->setDefaultConf("/conf/datasid-conf.json", agent->getPrefix()); + if (!fileExist(common->getDefaultConf())) { + std::cout << __DATE__ << "- ERROR: Config file not found. " << std::endl; return false; - } else - conf = datasid_conf(agent); + } else { + datasid_conf(agent, conf); + } /* Read proxy file and declare only valid variables */ - if(!fileExist(conf.getProxyConf())) - cout << __DATE__ << "- WARNING: Proxy file not found. " << endl; + if (!fileExist(conf->getProxyConf())) + std::cout << __DATE__ << "- WARNING: Proxy file not found. " << std::endl; else - proxy = datasid_proxy(conf); + datasid_proxy(conf, proxy); return true; -} \ No newline at end of file +} diff --git a/update/agent/src/linux/datasid-conf.cpp b/update/agent/src/linux/datasid-conf.cpp index 1ea981761cde59e236b154efe4b2c43bf34b7c2a..007d5a93d070d724d0bfac5a884117e38fdcbe90 100644 --- a/update/agent/src/linux/datasid-conf.cpp +++ b/update/agent/src/linux/datasid-conf.cpp @@ -18,47 +18,45 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. */ -#include "../../include/agent/linux/datasid-conf.h" #include <map> +#include <string> +#include "../../include/agent/linux/datasid-conf.h" #include "../../include/agent/linux/datasid-agent.h" #include "../../include/agent/main.h" #include "../../include/agent/linux/datasid-parse.h" - -using namespace std; - /* * set Functions */ -void Conf::setDataDir(string data){ +void Conf::setDataDir(std::string data) { this->dataDir = data; } -void Conf::setLogDir(string log){ +void Conf::setLogDir(std::string log) { this->logDir = log; } -void Conf::setProxyConf(string p){ +void Conf::setProxyConf(std::string p) { this->proxyConf = p; } -void Conf::setWebService(string web){ +void Conf::setWebService(std::string web) { this->webService = web; } -void Conf::setDelay(int d){ +void Conf::setDelay(int d) { this->delay = d; } -void Conf::setDaysToExpireLog(int d){ +void Conf::setDaysToExpireLog(int d) { this->daysToExpireLog = d; } -void Conf::setUpdateTries(int u){ +void Conf::setUpdateTries(int u) { this->updateTries = u; } -void Conf::setUpdatTimeOut(int u){ +void Conf::setUpdatTimeOut(int u) { this->updateTimeOut = u; } @@ -66,35 +64,35 @@ void Conf::setUpdatTimeOut(int u){ * get Functions */ -string Conf::getDataDir() const{ +std::string Conf::getDataDir() const { return this->dataDir; } -string Conf::getLogDir() const{ +std::string Conf::getLogDir() const { return this->logDir; } -string Conf::getProxyConf() const{ +std::string Conf::getProxyConf() const { return this->proxyConf; } -string Conf::getWebService() const{ +std::string Conf::getWebService() const { return this->webService; } -int Conf::getDelay() const{ +int Conf::getDelay() const { return this->delay; } -int Conf::getDaysToExpireLog() const{ +int Conf::getDaysToExpireLog() const { return this->daysToExpireLog; } -int Conf::getUpdateTries() const{ +int Conf::getUpdateTries() const { return this->updateTries; } -int Conf::getUpdateTimeOut() const{ +int Conf::getUpdateTimeOut() const { return this->updateTimeOut; } @@ -104,58 +102,56 @@ int Conf::getUpdateTimeOut() const{ * then set the conf object */ -bool setConf(Conf& conf, Agent agent, map<string,string>& content){ - if(content.count("DATADIR") == 0 || - content.count("LOGDIR") == 0 || - content.count("PROXYCONF") == 0 || - content.count("WEBSERVICE") == 0|| - content.count("DELAY") == 0 || - content.count("DAYSTOEXPIRELOG") == 0 || - content.count("UPDATETRIES") == 0 || - content.count("UPDATETIMEOUT") == 0 ) +bool setConf(Conf* conf, Agent* agent, std::map<std::string, std::string>* content) { + if (content->count("DATADIR") == 0 || + content->count("LOGDIR") == 0 || + content->count("PROXYCONF") == 0 || + content->count("WEBSERVICE") == 0|| + content->count("DELAY") == 0 || + content->count("DAYSTOEXPIRELOG") == 0 || + content->count("UPDATETRIES") == 0 || + content->count("UPDATETIMEOUT") == 0 ) return false; /* * agent.getPrefix() contains the absolute path of the agent. */ - string dataDir = agent.getPrefix() + content["DATADIR"]; - string dataLog = agent.getPrefix() + content["LOGDIR"]; - string proxyConf = agent.getPrefix() + content["PROXYCONF"]; - string webService = content["WEBSERVICE"]; - - int delay = atoi(content["DELAY"].c_str()); /* 24 hours */ - int daysToExpireLog = atoi(content["DAYSTOEXPIRELOG"].c_str()); /* 1 month */ - int updateTries = atoi(content["UPDATETRIES"].c_str()); - int updateTimeOut = atoi(content["UPDATETIMEOUT"].c_str()); - - conf.setDataDir(dataDir); - conf.setLogDir(dataLog); - conf.setProxyConf(proxyConf); - conf.setWebService(webService); - - conf.setDelay(delay); - conf.setDaysToExpireLog(daysToExpireLog); - conf.setUpdateTries(updateTries); - conf.setUpdatTimeOut(updateTimeOut); + std::string dataDir = agent->getPrefix() + (*content)["DATADIR"]; + std::string dataLog = agent->getPrefix() + (*content)["LOGDIR"]; + std::string proxyConf = agent->getPrefix() + (*content)["PROXYCONF"]; + std::string webService = (*content)["WEBSERVICE"]; + + int delay = atoi((*content)["DELAY"].c_str()); + int daysToExpireLog = atoi((*content)["DAYSTOEXPIRELOG"].c_str()); + int updateTries = atoi((*content)["UPDATETRIES"].c_str()); + int updateTimeOut = atoi((*content)["UPDATETIMEOUT"].c_str()); + + conf->setDataDir(dataDir); + conf->setLogDir(dataLog); + conf->setProxyConf(proxyConf); + conf->setWebService(webService); + + conf->setDelay(delay); + conf->setDaysToExpireLog(daysToExpireLog); + conf->setUpdateTries(updateTries); + conf->setUpdatTimeOut(updateTimeOut); return true; } -Conf datasid_conf(Agent agent){ - map<string, string> content; - string confFile = agent.getPrefix() + "/conf/datasid-conf.json"; - Conf conf; +void datasid_conf(Agent* agent, Conf* conf) { + std::map<std::string, std::string> content; + std::string confFile = agent->getPrefix() + "/conf/datasid-conf.json"; - if(readfile(confFile, content)){ - if(!setConf(conf, agent, content)){ - cout << __DATE__ << " ERROR: to parse variables from config file." << endl; + if (readfile(confFile, &content)) { + if (!setConf(conf, agent, &content)) { + std::cout << __DATE__ << " ERROR: to parse variables " << + "from config file." << std::endl; exit(1); } - }else { - cout << __DATE__ << " ERROR: config file not found." << endl; + } else { + std::cout << __DATE__ << " ERROR: config file not found." << std::endl; exit(1); } - - return conf; -} \ No newline at end of file +} diff --git a/update/agent/src/linux/datasid-parse.cpp b/update/agent/src/linux/datasid-parse.cpp index df75d1fe87f9b6e33d268e00951bbf8a8c465490..aa7eafc19c22682593a0262162fd139656684b6d 100644 --- a/update/agent/src/linux/datasid-parse.cpp +++ b/update/agent/src/linux/datasid-parse.cpp @@ -18,53 +18,56 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. */ +#include <string> +#include <map> #include "../../include/agent/linux/datasid-parse.h" /* * Erases leading tabs, leading spaces; trailing tabs, trailing spaces. */ -void trim (string& str){ +void trim(std::string* str) { int i = 0; - while (i < (int) str.length() && (str[i] == ' ' || str[i] == '\t')) + while (i < static_cast<int>(str->length()) && ((*str)[i] == ' ' + || (*str)[i] == '\t')) ++i; if (i > 0) - str.erase (0, i); + str->erase(0, i); - int j = i = str.length(); + int j = i = str->length(); - while (i > 0 && (str[i - 1] == ' ' || str[i - 1] == '\t')) + while (i > 0 && ((*str)[i - 1] == ' ' || (*str)[i - 1] == '\t')) --i; if (i < j) - str.erase (i, j); + str->erase(i, j); } /* * Erases tabs and spaces between the variable's name and its value. */ -void normalize (string & str){ - trim (str); +void normalize(std::string* str) { + trim(str); size_t i, j; i = j = 0; - while (i < str.length()) { - if (str[i] == ' ' || str[i] == '\t') { + while (i < str->length()) { + if ((*str)[i] == ' ' || (*str)[i] == '\t') { j = i + 1; - while (j < str.length() && (str[j] == ' ' || str[j] == '\t')) + while (j < str->length() && ((*str)[j] == ' ' || (*str)[j] == '\t')) ++j; if (j == i) - str.erase (i, 1); + str->erase(i, 1); else - str.erase (i, j - i); - } - else + str->erase(i, j - i); + } else { ++i; + } } } @@ -72,9 +75,9 @@ void normalize (string & str){ * Check if a line consists only of spaces and tabs */ -bool spaceonly (const string& line){ - for (int i = 0, j = line.length(); i < j; ++i) - if (line[i] != ' ' && line[i] != '\t') +bool spaceonly(const std::string* line) { + for (int i = 0, j = line->length(); i < j; ++i) + if ((*line)[i] != ' ' && (*line)[i] != '\t') return false; return true; } @@ -83,70 +86,66 @@ bool spaceonly (const string& line){ * Check if a line is valid */ -bool isvalid (string& line) { - normalize (line); +bool isvalid(std::string* line) { + normalize(line); int i = 0; - if (line[i] == '[') { - int j = line.find_last_of (']'); + if ((*line)[i] == '[') { + int j = line->find_last_of(']'); if (j == std::string::npos) return false; if (j - i == 1) return false; - } - - else if (line[i] == ';' || line[i] == '#' || (line[i] == '/' && line[i + 1] == '/')) + } else if ((*line)[i] == ';' || (*line)[i] == '#' || + ((*line)[i] == '/' && (*line)[i + 1] == '/')) { return false; - - else if (line[i] == '=' || line[i] == ']' || line[i] == '{' || line[i] == '}') + } else if ((*line)[i] == '=' || (*line)[i] == ']' || + (*line)[i] == '{' || (*line)[i] == '}') { return false; - - else if (line[i] = '"'){ - int j = line.find_last_of (':'); + } else if ((*line)[i] = '"') { + int j = line->find_last_of(':'); if (j == i || j == -1) return false; - if (j == line.length()) + if (j == line->length()) return false; } return true; } -void parse ( string& line, map<string, string>& content){ - locale loc; +void parse(std::string* line, std::map<std::string, std::string>* content) { + std::locale loc; // if the line is a variable + value - if (line[0] == '"') { - - string name = line.substr (1, line.find (':')-2); - for(int i = 0; i < name.length(); i++) + if ((*line)[0] == '"') { + std::string name = line->substr(1, line->find(':')-2); + for (int i = 0; i < name.length(); i++) name[i] = toupper(name[i], loc); - string value = line.substr (line.find (':')+2); - value = value.substr(0,value.find ('"')); + std::string value = line->substr(line->find(':')+2); + value = value.substr(0, value.find('"')); - content[name] = value; + (*content)[name] = value; } } -bool readfile (const string file, map<string,string>& content) { - content.clear(); +bool readfile(const std::string file, std::map<std::string, std::string>* content) { + content->clear(); - ifstream config (file.c_str(), ios::in); + std::ifstream config(file.c_str(), std::ifstream::in); if (!config.is_open()) return false; - string section; - string buffer; + std::string buffer; - while (getline (config, buffer, '\n')){ - if (!spaceonly (buffer)) - if (isvalid (buffer)) - parse ( buffer, content); + while (getline(config, buffer, '\n')) { + if (!spaceonly(&buffer)) + if (isvalid(&buffer)) + parse(&buffer, content); } - + return true; -} \ No newline at end of file +} diff --git a/update/agent/src/linux/datasid-proxy.cpp b/update/agent/src/linux/datasid-proxy.cpp index 5a749db3cf9170180b3b77adc5c0226ffa60e6e8..e52fbe73fc553df1efe8d9de7534083989a41333 100644 --- a/update/agent/src/linux/datasid-proxy.cpp +++ b/update/agent/src/linux/datasid-proxy.cpp @@ -18,30 +18,30 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. */ +#include <string> +#include <map> #include "../../include/agent/linux/datasid-conf.h" #include "../../include/agent/linux/datasid-parse.h" #include "../../include/agent/linux/datasid-proxy.h" #include "../../include/agent/linux/datasid-agent.h" -using namespace std; - /* * set Functions */ -void Proxy::setHost(string h){ +void Proxy::setHost(std::string h) { this->host = h; } -void Proxy::setPort(string p){ +void Proxy::setPort(std::string p) { this->port = p; } -void Proxy::setUser(string u){ +void Proxy::setUser(std::string u) { this->user = u; } -void Proxy::setPassword(string p){ +void Proxy::setPassword(std::string p) { this->password = p; } @@ -49,34 +49,34 @@ void Proxy::setPassword(string p){ * get Functions */ -string Proxy::getHost() const{ +std::string Proxy::getHost() const { return this->host; } -string Proxy::getPort() const{ +std::string Proxy::getPort() const { return this->port; } -string Proxy::getUser() const{ +std::string Proxy::getUser() const { return this->user; } -string Proxy::getPassword() const{ +std::string Proxy::getPassword() const { return this->password; } -bool setProxy(Proxy& proxy, map<string,string>& content){ - if(content.count("PROXYHOST") == 0 || - content.count("PROXYPORT") == 0 || - content.count("PROXYUSER") == 0 || - content.count("PROXYPASSWORD") == 0) +bool setProxy(Proxy* proxy, std::map<std::string, std::string>* content) { + if (content->count("PROXYHOST") == 0 || + content->count("PROXYPORT") == 0 || + content->count("PROXYUSER") == 0 || + content->count("PROXYPASSWORD") == 0) return false; - proxy.setHost(content["PROXYHOST"] ); - proxy.setPort(content["PROXYPORT"]); - proxy.setUser(content["PROXYUSER"]); - proxy.setPassword(content["PROXYPASSWORD"]); + proxy->setHost((*content)["PROXYHOST"]); + proxy->setPort((*content)["PROXYPORT"]); + proxy->setUser((*content)["PROXYUSER"]); + proxy->setPassword((*content)["PROXYPASSWORD"]); return true; } @@ -86,18 +86,17 @@ bool setProxy(Proxy& proxy, map<string,string>& content){ * host, port, user and password variables. */ -Proxy datasid_proxy(Conf conf){ - Proxy proxy; - map<string,string> content; - string proxyFile = conf.getProxyConf(); +void datasid_proxy(Conf* conf, Proxy* proxy) { + std::map<std::string, std::string> content; + std::string proxyFile = conf->getProxyConf(); - if(readfile(proxyFile, content)){ - if(!setProxy(proxy, content)){ - cout << __DATE__ << " ERROR: to parse variables from proxy file." << endl; + if (readfile(proxyFile, &content)) { + if (!setProxy(proxy, &content)) { + std::cout << __DATE__ << " ERROR: to parse variables" << + " from proxy file." << std::endl; exit(1); } - } else - cout << __DATE__ << " WARNING: proxy file not found." << endl; - - return proxy; -} \ No newline at end of file + } else { + std::cout << __DATE__ << " WARNING: proxy file not found." << std::endl; + } +} diff --git a/update/agent/src/main.cpp b/update/agent/src/main.cpp index 1afa6e755ebe6dc8dea63c49b4dc0bf68ba5fd9e..b0ddb53f60037c83f68585a3314fc2b2be795c97 100644 --- a/update/agent/src/main.cpp +++ b/update/agent/src/main.cpp @@ -22,6 +22,5 @@ int main(){ datasid_agent(); - return 0; } \ No newline at end of file