PROG = convertor
SRCS = ./main.cpp \
- ./settings.cpp
+ ./settings_impl.cpp
STGLIBS = -lstg_logger \
-lstg_common \
#include "common.h"
#include "store.h"
-#include "settings.h"
+#include "settings_impl.h"
#include "conffiles.h"
#include "user_stat.h"
#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;
STORE * fromStore = NULL;
STORE * toStore = NULL;
-SETTINGS * settings = NULL;
+SETTINGS_IMPL * settings = NULL;
string modulePath;
CORP_CONF cc;
SERVICE_CONF sc;
vector<STG_MSG_HDR> hdrs;
-vector<STG_MSG_HDR>::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();
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());
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());
vector<string> entities;
vector<string> ready;
-vector<string>::const_iterator it;
fromStore->SetSettings(fromStoreSettings);
fromStore->ParseSettings();
toStore->SetSettings(toStoreSettings);
delete settings;
return -1;
}
+
+vector<string>::const_iterator it;
for (it = entities.begin(); it != entities.end(); ++it)
{
printfd(__FILE__, "\t - %s\n", it->c_str());
delete settings;
return -1;
}
+
for (it = entities.begin(); it != entities.end(); ++it)
{
printfd(__FILE__, "\t - %s\n", it->c_str());
delete settings;
return -1;
}
+
for (it = entities.begin(); it != entities.end(); ++it)
{
printfd(__FILE__, "\t - %s\n", it->c_str());
delete settings;
return -1;
}
+
for (it = entities.begin(); it != entities.end(); ++it)
{
printfd(__FILE__, "\t - %s\n", it->c_str());
delete settings;
return -1;
}
+
sort(ready.begin(), ready.end());
for (it = entities.begin(); it != entities.end(); ++it)
{
delete settings;
return -1;
}
+ vector<STG_MSG_HDR>::iterator mit;
for (mit = hdrs.begin(); mit != hdrs.end(); ++mit)
{
if (fromStore->GetMessage(mit->id, &msg, *it))
return -1;
}
}
-
}
dlclose(src_lh);
+++ /dev/null
-/*
- * 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 <stg34@stargazer.dp.ua>
- */
-
-/*
-$Revision: 1.6 $
-$Date: 2009/06/22 16:26:54 $
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <string>
-
-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<PARAM_VALUE> * 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;
-}
-//-----------------------------------------------------------------------------
-
+++ /dev/null
- /*
- $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 <stg34@stargazer.dp.ua>
- */
-
-#ifndef settingsh_h
-#define settingsh_h 1
-
-#include <sys/types.h>
-#include <vector>
-#include <dotconfpp.h>
-
-#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<PARAM_VALUE> * params);
-
- string strError;
- //////////settings
- string modulesPath;
- string confFile;
-
- MODULE_SETTINGS sourceStoreModuleSettings;
- MODULE_SETTINGS destStoreModuleSettings;
-};
-//-----------------------------------------------------------------------------
-#endif
-
--- /dev/null
+/*
+ * 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 <stg34@stargazer.dp.ua>
+ */
+
+/*
+$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<PARAM_VALUE> * 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;
+}
+//-----------------------------------------------------------------------------
--- /dev/null
+ /*
+ $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 <stg34@stargazer.dp.ua>
+ */
+
+#ifndef SETTINGS_IMPL_H
+#define SETTINGS_IMPL_H
+
+#include <string>
+#include <vector>
+
+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<PARAM_VALUE> * params);
+
+ std::string strError;
+ std::string modulesPath;
+ std::string confFile;
+
+ MODULE_SETTINGS sourceStoreModuleSettings;
+ MODULE_SETTINGS destStoreModuleSettings;
+};
+
+#endif