From: Maxim Mamontov Date: Thu, 7 Apr 2011 11:34:51 +0000 (+0300) Subject: Fix compilation issues for convertor X-Git-Tag: 2.407-rc3~66 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/015efefb3fcbf0613cefc6826eb92c0f4aec25f0?ds=sidebyside Fix compilation issues for convertor --- diff --git a/projects/convertor/Makefile b/projects/convertor/Makefile index c07f698e..a143687c 100644 --- a/projects/convertor/Makefile +++ b/projects/convertor/Makefile @@ -7,7 +7,7 @@ include ../../Makefile.conf PROG = convertor SRCS = ./main.cpp \ - ./settings.cpp + ./settings_impl.cpp STGLIBS = -lstg_logger \ -lstg_common \ diff --git a/projects/convertor/main.cpp b/projects/convertor/main.cpp index 3d08ad2a..9308ed36 100644 --- a/projects/convertor/main.cpp +++ b/projects/convertor/main.cpp @@ -34,7 +34,7 @@ #include "common.h" #include "store.h" -#include "settings.h" +#include "settings_impl.h" #include "conffiles.h" #include "user_stat.h" @@ -43,7 +43,7 @@ #include "service_conf.h" #include "admin_conf.h" #include "tariff_conf.h" -#include "module_settings.h" +#include "settings.h" #include "stg_message.h" using namespace std; @@ -57,7 +57,7 @@ printfd(__FILE__, "Start\n"); STORE * fromStore = NULL; STORE * toStore = NULL; -SETTINGS * settings = NULL; +SETTINGS_IMPL * settings = NULL; string modulePath; @@ -72,22 +72,18 @@ TARIFF_DATA td; CORP_CONF cc; SERVICE_CONF sc; vector hdrs; -vector::iterator mit; - -void * src_lh; -void * dst_lh; if (argc == 2) - settings = new SETTINGS(argv[1]); + settings = new SETTINGS_IMPL(argv[1]); else - settings = new SETTINGS(); + settings = new SETTINGS_IMPL(); if (settings->ReadSettings()) -{ + { printfd(__FILE__, "Error reading settings\n"); delete settings; return -1; -} + } fromStoreSettings = settings->GetSourceStoreModuleSettings(); toStoreSettings = settings->GetDestStoreModuleSettings(); @@ -96,7 +92,7 @@ modulePath = settings->GetModulesPath(); string sourcePlugin(modulePath + "/mod_" + fromStoreSettings.moduleName + ".so"); string destPlugin(modulePath + "/mod_" + toStoreSettings.moduleName + ".so"); -src_lh = dlopen(sourcePlugin.c_str(), RTLD_NOW); +void * src_lh = dlopen(sourcePlugin.c_str(), RTLD_NOW); if (!src_lh) { printfd(__FILE__, "Source storage plugin loading failed: %s\n", dlerror()); @@ -104,7 +100,7 @@ if (!src_lh) return -1; } -dst_lh = dlopen(destPlugin.c_str(), RTLD_NOW); +void * dst_lh = dlopen(destPlugin.c_str(), RTLD_NOW); if (!dst_lh) { printfd(__FILE__, "Destination storage plugin loading failed: %s\n", dlerror()); @@ -134,7 +130,6 @@ toStore = GetDestStore(); vector entities; vector ready; -vector::const_iterator it; fromStore->SetSettings(fromStoreSettings); fromStore->ParseSettings(); toStore->SetSettings(toStoreSettings); @@ -159,6 +154,8 @@ if (toStore->GetAdminsList(&ready)) delete settings; return -1; } + +vector::const_iterator it; for (it = entities.begin(); it != entities.end(); ++it) { printfd(__FILE__, "\t - %s\n", it->c_str()); @@ -209,6 +206,7 @@ if (toStore->GetTariffsList(&ready)) delete settings; return -1; } + for (it = entities.begin(); it != entities.end(); ++it) { printfd(__FILE__, "\t - %s\n", it->c_str()); @@ -258,6 +256,7 @@ if (toStore->GetServicesList(&ready)) delete settings; return -1; } + for (it = entities.begin(); it != entities.end(); ++it) { printfd(__FILE__, "\t - %s\n", it->c_str()); @@ -307,6 +306,7 @@ if (toStore->GetCorpsList(&ready)) delete settings; return -1; } + for (it = entities.begin(); it != entities.end(); ++it) { printfd(__FILE__, "\t - %s\n", it->c_str()); @@ -356,6 +356,7 @@ if (toStore->GetUsersList(&ready)) delete settings; return -1; } + sort(ready.begin(), ready.end()); for (it = entities.begin(); it != entities.end(); ++it) { @@ -413,6 +414,7 @@ for (it = entities.begin(); it != entities.end(); ++it) delete settings; return -1; } + vector::iterator mit; for (mit = hdrs.begin(); mit != hdrs.end(); ++mit) { if (fromStore->GetMessage(mit->id, &msg, *it)) @@ -433,7 +435,6 @@ for (it = entities.begin(); it != entities.end(); ++it) return -1; } } - } dlclose(src_lh); diff --git a/projects/convertor/settings.cpp b/projects/convertor/settings.cpp deleted file mode 100644 index 33f4457e..00000000 --- a/projects/convertor/settings.cpp +++ /dev/null @@ -1,267 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Date: 27.10.2002 - */ - -/* - * Author : Boris Mikhailenko - */ - -/* -$Revision: 1.6 $ -$Date: 2009/06/22 16:26:54 $ -*/ - -#include -#include -#include -#include -#include - -using namespace std; - -#include "settings.h" -#include "common.h" - -//----------------------------------------------------------------------------- -SETTINGS::SETTINGS(const char * cf) -{ -confFile = string(cf); -} -//----------------------------------------------------------------------------- -SETTINGS::~SETTINGS() -{ - -} -//----------------------------------------------------------------------------- -/* -int SETTINGS::ParseYesNo(const string & value, bool * val) -{ -if (0 == strcasecmp(value.c_str(), "yes")) - { - *val = true; - return 0; - } -if (0 == strcasecmp(value.c_str(), "no")) - { - *val = false; - return 0; - } - -strError = "Incorrect value \'" + value + "\'."; -return -1; -} -//----------------------------------------------------------------------------- -int SETTINGS::ParseInt(const string & value, int * val) -{ -char *res; -*val = strtol(value.c_str(), &res, 10); -if (*res != 0) - { - strError = "Cannot convert \'" + value + "\' to integer."; - return -1; - } -return 0; -} -//----------------------------------------------------------------------------- -int SETTINGS::ParseIntInRange(const string & value, int min, int max, int * val) -{ -if (ParseInt(value, val) != 0) - return -1; - -if (*val < min || *val > max) - { - strError = "Value \'" + value + "\' out of range."; - return -1; - } - -return 0; -} -*/ -//----------------------------------------------------------------------------- -int SETTINGS::ParseModuleSettings(const DOTCONFDocumentNode * node, vector * params) -{ -/*if (!node) - return 0;*/ -const DOTCONFDocumentNode * childNode; -PARAM_VALUE pv; -const char * value; - -pv.param = node->getName(); - -if (node->getValue(1)) - { - strError = "Unexpected value \'" + string(node->getValue(1)) + "\'."; - return -1; - } - -value = node->getValue(0); - -if (!value) - { - strError = "Module name expected."; - return -1; - } - -childNode = node->getChildNode(); -while (childNode) - { - pv.param = childNode->getName(); - int i = 0; - while ((value = childNode->getValue(i)) != NULL) - { - //printfd(__FILE__, "--> param=\'%s\' value=\'%s\'\n", childNode->getName(), value); - pv.value.push_back(value); - i++; - } - params->push_back(pv); - pv.value.clear(); - childNode = childNode->getNextNode(); - } - -/*for (unsigned i = 0; i < params->size(); i++) - { - printfd(__FILE__, "param \'%s\'\n", (*params)[i].param.c_str()); - for (unsigned j = 0; j < (*params)[i].value.size(); j++) - { - printfd(__FILE__, "value \'%s\'\n", (*params)[i].value[j].c_str()); - } - }*/ - -return 0; -} -//----------------------------------------------------------------------------- -string SETTINGS::GetStrError() const -{ -return strError; -} -//----------------------------------------------------------------------------- -int SETTINGS::ReadSettings() -{ -const char * requiredOptions[] = { - "ModulesPath", - "SourceStoreModule", - "DestStoreModule", - NULL - }; -int sourceStoreModulesCount = 0; -int destStoreModulesCount = 0; - -DOTCONFDocument conf(DOTCONFDocument::CASEINSENSITIVE); -conf.setRequiredOptionNames(requiredOptions); - -//printfd(__FILE__, "Conffile: %s\n", confFile.c_str()); - -if(conf.setContent(confFile.c_str()) != 0) - { - strError = "Cannot read file " + confFile + "."; - return -1; - } - -const DOTCONFDocumentNode * node = conf.getFirstNode(); - -while (node) - { - if (strcasecmp(node->getName(), "ModulesPath") == 0) - { - modulesPath = node->getValue(0); - //printfd(__FILE__, "ModulesPath: %s\n", logFile.c_str()); - } - - if (strcasecmp(node->getName(), "SourceStoreModule") == 0) - { - // íÙ ×ÎÕÔÒÉ ÓÅËÃÉÉ StoreModule - //printfd(__FILE__, "StoreModule\n"); - - if (node->getValue(1)) - { - // StoreModule ÄÏÌÖÅÎ ÉÍÅÔØ 1 ÁÔÒÉÂÕÔ - strError = "Unexpected \'" + string(node->getValue(1)) + "\'."; - return -1; - } - - if (sourceStoreModulesCount) - { - // äÏÌÖÅÎ ÂÙÔØ ÔÏÌØËÏ ÏÄÉÎ ÍÏÄÕÌØ StoreModule! - strError = "Should be only one source StoreModule."; - return -1; - } - sourceStoreModulesCount++; - - //storeModuleSettings.clear(); //TODO To make constructor - //printfd(__FILE__, "StoreModule %s\n", node->getValue()); - sourceStoreModuleSettings.moduleName = node->getValue(0); - ParseModuleSettings(node, &sourceStoreModuleSettings.moduleParams); - } - - if (strcasecmp(node->getName(), "DestStoreModule") == 0) - { - // íÙ ×ÎÕÔÒÉ ÓÅËÃÉÉ StoreModule - //printfd(__FILE__, "StoreModule\n"); - - if (node->getValue(1)) - { - // StoreModule ÄÏÌÖÅÎ ÉÍÅÔØ 1 ÁÔÒÉÂÕÔ - strError = "Unexpected \'" + string(node->getValue(1)) + "\'."; - return -1; - } - - if (destStoreModulesCount) - { - // äÏÌÖÅÎ ÂÙÔØ ÔÏÌØËÏ ÏÄÉÎ ÍÏÄÕÌØ StoreModule! - strError = "Should be only one dest StoreModule."; - return -1; - } - destStoreModulesCount++; - - //storeModuleSettings.clear(); //TODO To make constructor - //printfd(__FILE__, "StoreModule %s\n", node->getValue()); - destStoreModuleSettings.moduleName = node->getValue(0); - ParseModuleSettings(node, &destStoreModuleSettings.moduleParams); - } - - node = node->getNextNode(); - } - -//sort(modulesSettings.begin(), modulesSettings.end()); -//modulesSettings.erase(unique(modulesSettings.begin(), modulesSettings.end()), modulesSettings.end()); - -return 0; -} -//----------------------------------------------------------------------------- -int SETTINGS::Reload () -{ -return ReadSettings(); -} -//----------------------------------------------------------------------------- -const MODULE_SETTINGS & SETTINGS::GetSourceStoreModuleSettings() const -{ -return sourceStoreModuleSettings; -} -//----------------------------------------------------------------------------- -const MODULE_SETTINGS & SETTINGS::GetDestStoreModuleSettings() const -{ -return destStoreModuleSettings; -} -//----------------------------------------------------------------------------- -const string & SETTINGS::GetModulesPath() const -{ -return modulesPath; -} -//----------------------------------------------------------------------------- - diff --git a/projects/convertor/settings.h b/projects/convertor/settings.h deleted file mode 100644 index 129e7f90..00000000 --- a/projects/convertor/settings.h +++ /dev/null @@ -1,78 +0,0 @@ - /* - $Revision: 1.6 $ - $Date: 2009/06/22 16:26:54 $ - */ - -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Date: 27.10.2002 - */ - -/* - * Author : Boris Mikhailenko - */ - -#ifndef settingsh_h -#define settingsh_h 1 - -#include -#include -#include - -#include "common.h" -#include "base_settings.h" -#include "stg_logger.h" - -using namespace std; - -//----------------------------------------------------------------------------- -class SETTINGS -{ -public: - SETTINGS(const char * cf = "./convertor.conf"); - ~SETTINGS(); - int Reload(); - int ReadSettings(); - - string GetStrError() const; - - const string & GetConfDir() const; - - const string & GetModulesPath() const; - const MODULE_SETTINGS & GetSourceStoreModuleSettings() const; - const MODULE_SETTINGS & GetDestStoreModuleSettings() const; - -private: - - //int ParseInt(const string & value, int * val); - //int ParseIntInRange(const string & value, int min, int max, int * val); - //int ParseYesNo(const string & value, bool * val); - - int ParseModuleSettings(const DOTCONFDocumentNode * dirNameNode, vector * params); - - string strError; - //////////settings - string modulesPath; - string confFile; - - MODULE_SETTINGS sourceStoreModuleSettings; - MODULE_SETTINGS destStoreModuleSettings; -}; -//----------------------------------------------------------------------------- -#endif - diff --git a/projects/convertor/settings_impl.cpp b/projects/convertor/settings_impl.cpp new file mode 100644 index 00000000..44206340 --- /dev/null +++ b/projects/convertor/settings_impl.cpp @@ -0,0 +1,155 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Date: 27.10.2002 + */ + +/* + * Author : Boris Mikhailenko + */ + +/* +$Revision: 1.6 $ +$Date: 2009/06/22 16:26:54 $ +*/ + +#include "dotconfpp.h" +#include "module_settings.h" +#include "settings_impl.h" +#include "common.h" + +int SETTINGS_IMPL::ParseModuleSettings(const DOTCONFDocumentNode * node, std::vector * params) +{ +if (!node) + return 0; + +PARAM_VALUE pv; + +pv.param = node->getName(); + +if (node->getValue(1)) + { + strError = "Unexpected value \'" + std::string(node->getValue(1)) + "\'."; + printfd(__FILE__, "SETTINGS_IMPL::ParseModuleSettings() - %s\n", strError.c_str()); + return -1; + } + +const char * value = node->getValue(0); + +if (!value) + { + strError = "Module name expected."; + printfd(__FILE__, "SETTINGS_IMPL::ParseModuleSettings() - %s\n", strError.c_str()); + return -1; + } + +const DOTCONFDocumentNode * childNode = node->getChildNode(); +while (childNode) + { + pv.param = childNode->getName(); + int i = 0; + while ((value = childNode->getValue(i)) != NULL) + { + pv.value.push_back(value); + ++i; + } + params->push_back(pv); + pv.value.clear(); + childNode = childNode->getNextNode(); + } + +return 0; +} +//----------------------------------------------------------------------------- +int SETTINGS_IMPL::ReadSettings() +{ +const char * requiredOptions[] = { + "ModulesPath", + "SourceStoreModule", + "DestStoreModule", + NULL + }; +int sourceStoreModulesCount = 0; +int destStoreModulesCount = 0; + +DOTCONFDocument conf(DOTCONFDocument::CASEINSENSITIVE); +conf.setRequiredOptionNames(requiredOptions); + +if(conf.setContent(confFile.c_str()) != 0) + { + strError = "Cannot read file " + confFile + "."; + printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str()); + return -1; + } + +const DOTCONFDocumentNode * node = conf.getFirstNode(); + +while (node) + { + if (strcasecmp(node->getName(), "ModulesPath") == 0) + { + modulesPath = node->getValue(0); + } + + if (strcasecmp(node->getName(), "SourceStoreModule") == 0) + { + if (node->getValue(1)) + { + strError = "Unexpected \'" + std::string(node->getValue(1)) + "\'."; + printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str()); + return -1; + } + + if (sourceStoreModulesCount) + { + strError = "Should be only one source StoreModule."; + printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str()); + return -1; + } + ++sourceStoreModulesCount; + + sourceStoreModuleSettings.moduleName = node->getValue(0); + ParseModuleSettings(node, &sourceStoreModuleSettings.moduleParams); + } + + if (strcasecmp(node->getName(), "DestStoreModule") == 0) + { + if (node->getValue(1)) + { + strError = "Unexpected \'" + std::string(node->getValue(1)) + "\'."; + printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str()); + return -1; + } + + if (destStoreModulesCount) + { + strError = "Should be only one dest StoreModule."; + printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str()); + return -1; + } + ++destStoreModulesCount; + + destStoreModuleSettings.moduleName = node->getValue(0); + ParseModuleSettings(node, &destStoreModuleSettings.moduleParams); + } + + node = node->getNextNode(); + } + +return 0; +} +//----------------------------------------------------------------------------- diff --git a/projects/convertor/settings_impl.h b/projects/convertor/settings_impl.h new file mode 100644 index 00000000..64d4b9fc --- /dev/null +++ b/projects/convertor/settings_impl.h @@ -0,0 +1,65 @@ + /* + $Revision: 1.6 $ + $Date: 2009/06/22 16:26:54 $ + */ + +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Date: 27.10.2002 + */ + +/* + * Author : Boris Mikhailenko + */ + +#ifndef SETTINGS_IMPL_H +#define SETTINGS_IMPL_H + +#include +#include + +class MODULE_SETTINGS; +class DOTCONFDocumentNode; + +class SETTINGS_IMPL { +public: + SETTINGS_IMPL() : confFile("./convertor.conf") {} + SETTINGS_IMPL(const std::string & cf) : confFile(cf) {} + ~SETTINGS_IMPL() {} + int ReadSettings(); + + std::string GetStrError() const { return strError; } + + const std::string & GetConfDir() const; + + const std::string & GetModulesPath() const { return modulesPath; } + const MODULE_SETTINGS & GetSourceStoreModuleSettings() const { return sourceStoreModuleSettings; } + const MODULE_SETTINGS & GetDestStoreModuleSettings() const { return destStoreModuleSettings; } + +private: + int ParseModuleSettings(const DOTCONFDocumentNode * dirNameNode, std::vector * params); + + std::string strError; + std::string modulesPath; + std::string confFile; + + MODULE_SETTINGS sourceStoreModuleSettings; + MODULE_SETTINGS destStoreModuleSettings; +}; + +#endif