You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-02 17:22:27 +03:00
Reformat all code to coding standard
This commit is contained in:
@ -34,7 +34,7 @@ using namespace std;
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/unordered_map.hpp>
|
||||
using namespace boost;
|
||||
namespace fs=boost::filesystem;
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@ -76,549 +76,609 @@ boost::mutex Config::fWriteXmlLock;
|
||||
|
||||
Config* Config::makeConfig(const string& cf)
|
||||
{
|
||||
return makeConfig(cf.c_str());
|
||||
return makeConfig(cf.c_str());
|
||||
}
|
||||
|
||||
Config* Config::makeConfig(const char* cf)
|
||||
{
|
||||
mutex::scoped_lock lk(fInstanceMapMutex);
|
||||
mutex::scoped_lock lk(fInstanceMapMutex);
|
||||
|
||||
static string installDir;
|
||||
|
||||
static string installDir;
|
||||
if (installDir.empty())
|
||||
installDir = startup::StartUp::installDir();
|
||||
|
||||
if (cf == 0)
|
||||
{
|
||||
if (cf == 0)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
string cfStr = IDBreadRegistry("ConfigFile");
|
||||
if (!cfStr.empty())
|
||||
cf = cfStr.c_str();
|
||||
string cfStr = IDBreadRegistry("ConfigFile");
|
||||
|
||||
if (!cfStr.empty())
|
||||
cf = cfStr.c_str();
|
||||
|
||||
#else
|
||||
cf = getenv("CALPONT_CONFIG_FILE");
|
||||
cf = getenv("CALPONT_CONFIG_FILE");
|
||||
#endif
|
||||
if (cf == 0 || *cf == 0)
|
||||
{
|
||||
|
||||
if (cf == 0 || *cf == 0)
|
||||
{
|
||||
static string defaultFilePath;
|
||||
|
||||
if (defaultFilePath.empty())
|
||||
{
|
||||
fs::path configFilePath;
|
||||
configFilePath = fs::path(installDir) / fs::path("etc") / defaultCalpontConfigFile;
|
||||
defaultFilePath = configFilePath.string();
|
||||
}
|
||||
|
||||
if (fInstanceMap.find(defaultFilePath) == fInstanceMap.end())
|
||||
{
|
||||
Config* instance = new Config(defaultFilePath, installDir);
|
||||
fInstanceMap[defaultFilePath] = instance;
|
||||
}
|
||||
{
|
||||
Config* instance = new Config(defaultFilePath, installDir);
|
||||
fInstanceMap[defaultFilePath] = instance;
|
||||
}
|
||||
|
||||
return fInstanceMap[defaultFilePath];
|
||||
}
|
||||
}
|
||||
string configFile(cf);
|
||||
}
|
||||
}
|
||||
|
||||
if (fInstanceMap.find(configFile) == fInstanceMap.end())
|
||||
{
|
||||
Config* instance = new Config(configFile, installDir);
|
||||
fInstanceMap[configFile] = instance;
|
||||
}
|
||||
string configFile(cf);
|
||||
|
||||
return fInstanceMap[configFile];
|
||||
if (fInstanceMap.find(configFile) == fInstanceMap.end())
|
||||
{
|
||||
Config* instance = new Config(configFile, installDir);
|
||||
fInstanceMap[configFile] = instance;
|
||||
}
|
||||
|
||||
return fInstanceMap[configFile];
|
||||
}
|
||||
|
||||
Config::Config(const string& configFile, const string& installDir) :
|
||||
fDoc(0), fConfigFile(configFile), fMtime(0), fInstallDir(installDir), fParser(fInstallDir)
|
||||
fDoc(0), fConfigFile(configFile), fMtime(0), fInstallDir(installDir), fParser(fInstallDir)
|
||||
{
|
||||
for ( int i = 0 ; i < 20 ; i++ )
|
||||
{
|
||||
if (access(fConfigFile.c_str(), R_OK) != 0) {
|
||||
if ( i >= 15 )
|
||||
throw runtime_error("Config::Config: error accessing config file " + fConfigFile);
|
||||
sleep (1);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
for ( int i = 0 ; i < 20 ; i++ )
|
||||
{
|
||||
if (access(fConfigFile.c_str(), R_OK) != 0)
|
||||
{
|
||||
if ( i >= 15 )
|
||||
throw runtime_error("Config::Config: error accessing config file " + fConfigFile);
|
||||
|
||||
struct stat statbuf;
|
||||
if (stat(configFile.c_str(), &statbuf) == 0)
|
||||
fMtime = statbuf.st_mtime;
|
||||
sleep (1);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
parseDoc();
|
||||
struct stat statbuf;
|
||||
|
||||
if (stat(configFile.c_str(), &statbuf) == 0)
|
||||
fMtime = statbuf.st_mtime;
|
||||
|
||||
parseDoc();
|
||||
}
|
||||
|
||||
Config::~Config()
|
||||
{
|
||||
if (fDoc != 0)
|
||||
closeConfig();
|
||||
if (fDoc != 0)
|
||||
closeConfig();
|
||||
}
|
||||
|
||||
void Config::parseDoc(void)
|
||||
{
|
||||
struct flock fl;
|
||||
int fd;
|
||||
struct flock fl;
|
||||
int fd;
|
||||
|
||||
memset(&fl, 0, sizeof(fl));
|
||||
fl.l_type = F_RDLCK; // read lock
|
||||
fl.l_whence = SEEK_SET;
|
||||
fl.l_start = 0;
|
||||
fl.l_len = 0; //lock whole file
|
||||
memset(&fl, 0, sizeof(fl));
|
||||
fl.l_type = F_RDLCK; // read lock
|
||||
fl.l_whence = SEEK_SET;
|
||||
fl.l_start = 0;
|
||||
fl.l_len = 0; //lock whole file
|
||||
|
||||
// lock file if exist
|
||||
if ((fd = open(fConfigFile.c_str(), O_RDONLY)) >= 0)
|
||||
{
|
||||
if (fcntl(fd, F_SETLKW, &fl) != 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Config::parseDoc: error locking file " <<
|
||||
fConfigFile <<
|
||||
": " <<
|
||||
strerror(errno) <<
|
||||
", proceding anyway.";
|
||||
cerr << oss.str() << endl;
|
||||
}
|
||||
// lock file if exist
|
||||
if ((fd = open(fConfigFile.c_str(), O_RDONLY)) >= 0)
|
||||
{
|
||||
if (fcntl(fd, F_SETLKW, &fl) != 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Config::parseDoc: error locking file " <<
|
||||
fConfigFile <<
|
||||
": " <<
|
||||
strerror(errno) <<
|
||||
", proceding anyway.";
|
||||
cerr << oss.str() << endl;
|
||||
}
|
||||
|
||||
fXmlLock.lock();
|
||||
fDoc = xmlParseFile(fConfigFile.c_str());
|
||||
fXmlLock.lock();
|
||||
fDoc = xmlParseFile(fConfigFile.c_str());
|
||||
fXmlLock.unlock();
|
||||
|
||||
fl.l_type = F_UNLCK; //unlock
|
||||
fcntl(fd, F_SETLK, &fl);
|
||||
fl.l_type = F_UNLCK; //unlock
|
||||
fcntl(fd, F_SETLK, &fl);
|
||||
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Config::parseDoc: error opening file " <<
|
||||
fConfigFile <<
|
||||
": " <<
|
||||
strerror(errno);
|
||||
throw runtime_error(oss.str());
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Config::parseDoc: error opening file " <<
|
||||
fConfigFile <<
|
||||
": " <<
|
||||
strerror(errno);
|
||||
throw runtime_error(oss.str());
|
||||
}
|
||||
|
||||
|
||||
if (fDoc == 0 ) {
|
||||
throw runtime_error("Config::parseDoc: error parsing config file " + fConfigFile);
|
||||
}
|
||||
if (fDoc == 0 )
|
||||
{
|
||||
throw runtime_error("Config::parseDoc: error parsing config file " + fConfigFile);
|
||||
}
|
||||
|
||||
xmlNodePtr cur = xmlDocGetRootElement(fDoc);
|
||||
xmlNodePtr cur = xmlDocGetRootElement(fDoc);
|
||||
|
||||
if (cur == NULL)
|
||||
{
|
||||
xmlFreeDoc(fDoc);
|
||||
fDoc = 0;
|
||||
throw runtime_error("Config::parseDoc: error parsing config file " + fConfigFile);
|
||||
}
|
||||
if (cur == NULL)
|
||||
{
|
||||
xmlFreeDoc(fDoc);
|
||||
fDoc = 0;
|
||||
throw runtime_error("Config::parseDoc: error parsing config file " + fConfigFile);
|
||||
}
|
||||
|
||||
if (xmlStrcmp(cur->name, (const xmlChar *)"Columnstore"))
|
||||
{
|
||||
xmlFreeDoc(fDoc);
|
||||
fDoc = 0;
|
||||
throw runtime_error("Config::parseDoc: error parsing config file " + fConfigFile);
|
||||
}
|
||||
if (xmlStrcmp(cur->name, (const xmlChar*)"Columnstore"))
|
||||
{
|
||||
xmlFreeDoc(fDoc);
|
||||
fDoc = 0;
|
||||
throw runtime_error("Config::parseDoc: error parsing config file " + fConfigFile);
|
||||
}
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
void Config::closeConfig(void)
|
||||
{
|
||||
xmlFreeDoc(fDoc);
|
||||
fDoc = 0;
|
||||
xmlFreeDoc(fDoc);
|
||||
fDoc = 0;
|
||||
}
|
||||
|
||||
const string Config::getConfig(const string& section, const string& name)
|
||||
{
|
||||
mutex::scoped_lock lk(fLock);
|
||||
mutex::scoped_lock lk(fLock);
|
||||
|
||||
if (section.length() == 0 || name.length() == 0)
|
||||
throw invalid_argument("Config::getConfig: both section and name must have a length");
|
||||
if (section.length() == 0 || name.length() == 0)
|
||||
throw invalid_argument("Config::getConfig: both section and name must have a length");
|
||||
|
||||
if (fDoc == 0){
|
||||
throw runtime_error("Config::getConfig: no XML document!");
|
||||
}
|
||||
if (fDoc == 0)
|
||||
{
|
||||
throw runtime_error("Config::getConfig: no XML document!");
|
||||
}
|
||||
|
||||
struct stat statbuf;
|
||||
if (stat(fConfigFile.c_str(), &statbuf) == 0)
|
||||
{
|
||||
if (statbuf.st_mtime != fMtime)
|
||||
{
|
||||
closeConfig();
|
||||
fMtime = statbuf.st_mtime;
|
||||
parseDoc();
|
||||
}
|
||||
}
|
||||
struct stat statbuf;
|
||||
|
||||
if (stat(fConfigFile.c_str(), &statbuf) == 0)
|
||||
{
|
||||
if (statbuf.st_mtime != fMtime)
|
||||
{
|
||||
closeConfig();
|
||||
fMtime = statbuf.st_mtime;
|
||||
parseDoc();
|
||||
}
|
||||
}
|
||||
|
||||
return fParser.getConfig(fDoc, section, name);
|
||||
}
|
||||
|
||||
void Config::getConfig(const string& section, const string& name, vector<string>& values)
|
||||
{
|
||||
mutex::scoped_lock lk(fLock);
|
||||
mutex::scoped_lock lk(fLock);
|
||||
|
||||
if (section.length() == 0)
|
||||
throw invalid_argument("Config::getConfig: section must have a length");
|
||||
if (section.length() == 0)
|
||||
throw invalid_argument("Config::getConfig: section must have a length");
|
||||
|
||||
if (fDoc == 0)
|
||||
throw runtime_error("Config::getConfig: no XML document!");
|
||||
if (fDoc == 0)
|
||||
throw runtime_error("Config::getConfig: no XML document!");
|
||||
|
||||
struct stat statbuf;
|
||||
if (stat(fConfigFile.c_str(), &statbuf) == 0)
|
||||
{
|
||||
if (statbuf.st_mtime != fMtime)
|
||||
{
|
||||
closeConfig();
|
||||
fMtime = statbuf.st_mtime;
|
||||
parseDoc();
|
||||
}
|
||||
}
|
||||
struct stat statbuf;
|
||||
|
||||
fParser.getConfig(fDoc, section, name, values);
|
||||
if (stat(fConfigFile.c_str(), &statbuf) == 0)
|
||||
{
|
||||
if (statbuf.st_mtime != fMtime)
|
||||
{
|
||||
closeConfig();
|
||||
fMtime = statbuf.st_mtime;
|
||||
parseDoc();
|
||||
}
|
||||
}
|
||||
|
||||
fParser.getConfig(fDoc, section, name, values);
|
||||
}
|
||||
|
||||
void Config::setConfig(const string& section, const string& name, const string& value)
|
||||
{
|
||||
mutex::scoped_lock lk(fLock);
|
||||
mutex::scoped_lock lk(fLock);
|
||||
|
||||
if (section.length() == 0 || name.length() == 0 )
|
||||
throw invalid_argument("Config::setConfig: all of section and name must have a length");
|
||||
if (section.length() == 0 || name.length() == 0 )
|
||||
throw invalid_argument("Config::setConfig: all of section and name must have a length");
|
||||
|
||||
if (fDoc == 0) {
|
||||
throw runtime_error("Config::setConfig: no XML document!");
|
||||
}
|
||||
if (fDoc == 0)
|
||||
{
|
||||
throw runtime_error("Config::setConfig: no XML document!");
|
||||
}
|
||||
|
||||
struct stat statbuf;
|
||||
memset(&statbuf, 0, sizeof(statbuf));
|
||||
if (stat(fConfigFile.c_str(), &statbuf) == 0)
|
||||
{
|
||||
if (statbuf.st_mtime != fMtime)
|
||||
{
|
||||
closeConfig();
|
||||
fMtime = statbuf.st_mtime;
|
||||
parseDoc();
|
||||
}
|
||||
}
|
||||
struct stat statbuf;
|
||||
|
||||
fParser.setConfig(fDoc, section, name, value);
|
||||
return;
|
||||
memset(&statbuf, 0, sizeof(statbuf));
|
||||
|
||||
if (stat(fConfigFile.c_str(), &statbuf) == 0)
|
||||
{
|
||||
if (statbuf.st_mtime != fMtime)
|
||||
{
|
||||
closeConfig();
|
||||
fMtime = statbuf.st_mtime;
|
||||
parseDoc();
|
||||
}
|
||||
}
|
||||
|
||||
fParser.setConfig(fDoc, section, name, value);
|
||||
return;
|
||||
}
|
||||
|
||||
void Config::delConfig(const string& section, const string& name)
|
||||
{
|
||||
mutex::scoped_lock lk(fLock);
|
||||
mutex::scoped_lock lk(fLock);
|
||||
|
||||
if (section.length() == 0 || name.length() == 0)
|
||||
throw invalid_argument("Config::delConfig: both section and name must have a length");
|
||||
if (section.length() == 0 || name.length() == 0)
|
||||
throw invalid_argument("Config::delConfig: both section and name must have a length");
|
||||
|
||||
if (fDoc == 0){
|
||||
throw runtime_error("Config::delConfig: no XML document!");
|
||||
}
|
||||
if (fDoc == 0)
|
||||
{
|
||||
throw runtime_error("Config::delConfig: no XML document!");
|
||||
}
|
||||
|
||||
struct stat statbuf;
|
||||
if (stat(fConfigFile.c_str(), &statbuf) == 0)
|
||||
{
|
||||
if (statbuf.st_mtime != fMtime)
|
||||
{
|
||||
closeConfig();
|
||||
fMtime = statbuf.st_mtime;
|
||||
parseDoc();
|
||||
}
|
||||
}
|
||||
struct stat statbuf;
|
||||
|
||||
fParser.delConfig(fDoc, section, name);
|
||||
return;
|
||||
if (stat(fConfigFile.c_str(), &statbuf) == 0)
|
||||
{
|
||||
if (statbuf.st_mtime != fMtime)
|
||||
{
|
||||
closeConfig();
|
||||
fMtime = statbuf.st_mtime;
|
||||
parseDoc();
|
||||
}
|
||||
}
|
||||
|
||||
fParser.delConfig(fDoc, section, name);
|
||||
return;
|
||||
}
|
||||
|
||||
void Config::writeConfig(const string& configFile) const
|
||||
{
|
||||
mutex::scoped_lock lk(fLock);
|
||||
FILE *fi;
|
||||
if (fDoc == 0)
|
||||
throw runtime_error("Config::writeConfig: no XML document!");
|
||||
mutex::scoped_lock lk(fLock);
|
||||
FILE* fi;
|
||||
|
||||
if (fDoc == 0)
|
||||
throw runtime_error("Config::writeConfig: no XML document!");
|
||||
|
||||
#ifdef _MSC_VER
|
||||
fs::path configFilePth(configFile);
|
||||
fs::path outFilePth(configFilePth);
|
||||
outFilePth.replace_extension("temp");
|
||||
if ((fi = fopen(outFilePth.string().c_str(), "wt")) == NULL)
|
||||
throw runtime_error("Config::writeConfig: error opening config file for write " + outFilePth.string());
|
||||
int rc = -1;
|
||||
rc = xmlDocDump(fi, fDoc);
|
||||
if (rc < 0) {
|
||||
throw runtime_error("Config::writeConfig: error writing config file " + outFilePth.string());
|
||||
}
|
||||
fclose(fi);
|
||||
if (fs::exists(configFilePth))
|
||||
fs::remove(configFilePth);
|
||||
fs::rename(outFilePth, configFilePth);
|
||||
fs::path configFilePth(configFile);
|
||||
fs::path outFilePth(configFilePth);
|
||||
outFilePth.replace_extension("temp");
|
||||
|
||||
if ((fi = fopen(outFilePth.string().c_str(), "wt")) == NULL)
|
||||
throw runtime_error("Config::writeConfig: error opening config file for write " + outFilePth.string());
|
||||
|
||||
int rc = -1;
|
||||
rc = xmlDocDump(fi, fDoc);
|
||||
|
||||
if (rc < 0)
|
||||
{
|
||||
throw runtime_error("Config::writeConfig: error writing config file " + outFilePth.string());
|
||||
}
|
||||
|
||||
fclose(fi);
|
||||
|
||||
if (fs::exists(configFilePth))
|
||||
fs::remove(configFilePth);
|
||||
|
||||
fs::rename(outFilePth, configFilePth);
|
||||
#else
|
||||
|
||||
const fs::path defaultCalpontConfigFileTemp("Columnstore.xml.temp");
|
||||
const fs::path saveCalpontConfigFileTemp("Columnstore.xml.columnstoreSave");
|
||||
const fs::path tmpCalpontConfigFileTemp("Columnstore.xml.temp1");
|
||||
const fs::path defaultCalpontConfigFileTemp("Columnstore.xml.temp");
|
||||
const fs::path saveCalpontConfigFileTemp("Columnstore.xml.columnstoreSave");
|
||||
const fs::path tmpCalpontConfigFileTemp("Columnstore.xml.temp1");
|
||||
|
||||
fs::path etcdir = fs::path(fInstallDir) / fs::path("etc");
|
||||
fs::path etcdir = fs::path(fInstallDir) / fs::path("etc");
|
||||
|
||||
fs::path dcf = etcdir / fs::path(defaultCalpontConfigFile);
|
||||
fs::path dcft = etcdir / fs::path(defaultCalpontConfigFileTemp);
|
||||
fs::path scft = etcdir / fs::path(saveCalpontConfigFileTemp);
|
||||
fs::path tcft = etcdir / fs::path(tmpCalpontConfigFileTemp);
|
||||
//perform a temp write first if Columnstore.xml file to prevent possible corruption
|
||||
if ( configFile == dcf ) {
|
||||
fs::path dcf = etcdir / fs::path(defaultCalpontConfigFile);
|
||||
fs::path dcft = etcdir / fs::path(defaultCalpontConfigFileTemp);
|
||||
fs::path scft = etcdir / fs::path(saveCalpontConfigFileTemp);
|
||||
fs::path tcft = etcdir / fs::path(tmpCalpontConfigFileTemp);
|
||||
|
||||
if (exists(dcft)) fs::remove(dcft);
|
||||
if ((fi = fopen(dcft.string().c_str(), "w+")) == NULL)
|
||||
throw runtime_error("Config::writeConfig: error writing config file " + configFile);
|
||||
//perform a temp write first if Columnstore.xml file to prevent possible corruption
|
||||
if ( configFile == dcf )
|
||||
{
|
||||
|
||||
int rc;
|
||||
rc = xmlDocDump(fi, fDoc);
|
||||
if ( rc < 0) {
|
||||
throw runtime_error("Config::writeConfig: error writing config file " + configFile);
|
||||
//cout << "xmlDocDump " << rc << " " << errno << endl;
|
||||
}
|
||||
if (exists(dcft)) fs::remove(dcft);
|
||||
|
||||
fclose(fi);
|
||||
if ((fi = fopen(dcft.string().c_str(), "w+")) == NULL)
|
||||
throw runtime_error("Config::writeConfig: error writing config file " + configFile);
|
||||
|
||||
//check temp file
|
||||
try {
|
||||
Config* c1 = makeConfig(dcft.string().c_str());
|
||||
int rc;
|
||||
rc = xmlDocDump(fi, fDoc);
|
||||
|
||||
string value;
|
||||
value = c1->getConfig("SystemConfig", "SystemName");
|
||||
if ( rc < 0)
|
||||
{
|
||||
throw runtime_error("Config::writeConfig: error writing config file " + configFile);
|
||||
//cout << "xmlDocDump " << rc << " " << errno << endl;
|
||||
}
|
||||
|
||||
//good read, save copy, copy temp file tp tmp then to Columnstore.xml
|
||||
//move to /tmp to get around a 'same file error' in mv command
|
||||
try {
|
||||
if (exists(scft)) fs::remove(scft);
|
||||
} catch (fs::filesystem_error&) { }
|
||||
fs::copy_file(dcf, scft, fs::copy_option::overwrite_if_exists);
|
||||
try {
|
||||
fs::permissions(scft, fs::add_perms | fs::owner_read | fs::owner_write |
|
||||
fs::group_read | fs::group_write |
|
||||
fs::others_read | fs::others_write);
|
||||
} catch (fs::filesystem_error&) { }
|
||||
fclose(fi);
|
||||
|
||||
if (exists(tcft)) fs::remove(tcft);
|
||||
fs::rename(dcft, tcft);
|
||||
//check temp file
|
||||
try
|
||||
{
|
||||
Config* c1 = makeConfig(dcft.string().c_str());
|
||||
|
||||
if (exists(dcf)) fs::remove(dcf);
|
||||
fs::rename(tcft, dcf);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
throw runtime_error("Config::writeConfig: error writing config file " + configFile);
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // non Columnstore.xml, perform update
|
||||
if ((fi = fopen(configFile.c_str(), "w")) == NULL)
|
||||
throw runtime_error("Config::writeConfig: error writing config file " + configFile);
|
||||
string value;
|
||||
value = c1->getConfig("SystemConfig", "SystemName");
|
||||
|
||||
xmlDocDump(fi, fDoc);
|
||||
//good read, save copy, copy temp file tp tmp then to Columnstore.xml
|
||||
//move to /tmp to get around a 'same file error' in mv command
|
||||
try
|
||||
{
|
||||
if (exists(scft)) fs::remove(scft);
|
||||
}
|
||||
catch (fs::filesystem_error&) { }
|
||||
|
||||
fs::copy_file(dcf, scft, fs::copy_option::overwrite_if_exists);
|
||||
|
||||
try
|
||||
{
|
||||
fs::permissions(scft, fs::add_perms | fs::owner_read | fs::owner_write |
|
||||
fs::group_read | fs::group_write |
|
||||
fs::others_read | fs::others_write);
|
||||
}
|
||||
catch (fs::filesystem_error&) { }
|
||||
|
||||
if (exists(tcft)) fs::remove(tcft);
|
||||
|
||||
fs::rename(dcft, tcft);
|
||||
|
||||
if (exists(dcf)) fs::remove(dcf);
|
||||
|
||||
fs::rename(tcft, dcf);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
throw runtime_error("Config::writeConfig: error writing config file " + configFile);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// non Columnstore.xml, perform update
|
||||
if ((fi = fopen(configFile.c_str(), "w")) == NULL)
|
||||
throw runtime_error("Config::writeConfig: error writing config file " + configFile);
|
||||
|
||||
xmlDocDump(fi, fDoc);
|
||||
|
||||
fclose(fi);
|
||||
}
|
||||
|
||||
fclose(fi);
|
||||
}
|
||||
#endif
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
void Config::write(void) const
|
||||
{
|
||||
mutex::scoped_lock lk(fWriteXmlLock);
|
||||
mutex::scoped_lock lk(fWriteXmlLock);
|
||||
#ifdef _MSC_VER
|
||||
writeConfig(fConfigFile);
|
||||
writeConfig(fConfigFile);
|
||||
#else
|
||||
write(fConfigFile);
|
||||
write(fConfigFile);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Config::write(const string& configFile) const
|
||||
{
|
||||
struct flock fl;
|
||||
int fd;
|
||||
struct flock fl;
|
||||
int fd;
|
||||
|
||||
fl.l_type = F_WRLCK; // write lock
|
||||
fl.l_whence = SEEK_SET;
|
||||
fl.l_start = 0;
|
||||
fl.l_len = 0;
|
||||
fl.l_pid = getpid();
|
||||
fl.l_type = F_WRLCK; // write lock
|
||||
fl.l_whence = SEEK_SET;
|
||||
fl.l_start = 0;
|
||||
fl.l_len = 0;
|
||||
fl.l_pid = getpid();
|
||||
|
||||
// lock file if it exists
|
||||
if ((fd = open(configFile.c_str(), O_WRONLY)) >= 0)
|
||||
{
|
||||
if (fcntl(fd, F_SETLKW, &fl) == -1)
|
||||
throw runtime_error("Config::write: file lock error " + configFile);
|
||||
// lock file if it exists
|
||||
if ((fd = open(configFile.c_str(), O_WRONLY)) >= 0)
|
||||
{
|
||||
if (fcntl(fd, F_SETLKW, &fl) == -1)
|
||||
throw runtime_error("Config::write: file lock error " + configFile);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
writeConfig(configFile);
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
fl.l_type = F_UNLCK; //unlock
|
||||
|
||||
if (fcntl(fd, F_SETLK, &fl) == -1)
|
||||
throw runtime_error("Config::write: file unlock error after exception in writeConfig " + configFile);
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
fl.l_type = F_UNLCK; //unlock
|
||||
if (fcntl(fd, F_SETLK, &fl) == -1)
|
||||
throw runtime_error("Config::write: file unlock error " + configFile);
|
||||
fl.l_type = F_UNLCK; //unlock
|
||||
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
writeConfig(configFile);
|
||||
}
|
||||
if (fcntl(fd, F_SETLK, &fl) == -1)
|
||||
throw runtime_error("Config::write: file unlock error " + configFile);
|
||||
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
writeConfig(configFile);
|
||||
}
|
||||
}
|
||||
|
||||
void Config::writeConfigFile(messageqcpp::ByteStream msg) const
|
||||
{
|
||||
struct flock fl;
|
||||
int fd;
|
||||
struct flock fl;
|
||||
int fd;
|
||||
|
||||
//get config file name being udated
|
||||
string fileName;
|
||||
msg >> fileName;
|
||||
//get config file name being udated
|
||||
string fileName;
|
||||
msg >> fileName;
|
||||
|
||||
fl.l_type = F_WRLCK; // write lock
|
||||
fl.l_whence = SEEK_SET;
|
||||
fl.l_start = 0;
|
||||
fl.l_len = 0;
|
||||
fl.l_pid = getpid();
|
||||
fl.l_type = F_WRLCK; // write lock
|
||||
fl.l_whence = SEEK_SET;
|
||||
fl.l_start = 0;
|
||||
fl.l_len = 0;
|
||||
fl.l_pid = getpid();
|
||||
|
||||
// lock file if it exists
|
||||
if ((fd = open(fileName.c_str(), O_WRONLY)) >= 0)
|
||||
{
|
||||
if (fcntl(fd, F_SETLKW, &fl) == -1)
|
||||
throw runtime_error("Config::write: file lock error " + fileName);
|
||||
// lock file if it exists
|
||||
if ((fd = open(fileName.c_str(), O_WRONLY)) >= 0)
|
||||
{
|
||||
if (fcntl(fd, F_SETLKW, &fl) == -1)
|
||||
throw runtime_error("Config::write: file lock error " + fileName);
|
||||
|
||||
ofstream out(fileName.c_str());
|
||||
out << msg;
|
||||
ofstream out(fileName.c_str());
|
||||
out << msg;
|
||||
|
||||
fl.l_type = F_UNLCK; //unlock
|
||||
if (fcntl(fd, F_SETLK, &fl) == -1)
|
||||
throw runtime_error("Config::write: file unlock error " + fileName);
|
||||
fl.l_type = F_UNLCK; //unlock
|
||||
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
ofstream out(fileName.c_str());
|
||||
out << msg;
|
||||
}
|
||||
if (fcntl(fd, F_SETLK, &fl) == -1)
|
||||
throw runtime_error("Config::write: file unlock error " + fileName);
|
||||
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
ofstream out(fileName.c_str());
|
||||
out << msg;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* static */
|
||||
void Config::deleteInstanceMap()
|
||||
{
|
||||
mutex::scoped_lock lk(fInstanceMapMutex);
|
||||
for (Config::configMap_t::iterator iter = fInstanceMap.begin();
|
||||
iter != fInstanceMap.end(); ++iter)
|
||||
{
|
||||
Config* instance = iter->second;
|
||||
delete instance;
|
||||
}
|
||||
fInstanceMap.clear();
|
||||
mutex::scoped_lock lk(fInstanceMapMutex);
|
||||
|
||||
for (Config::configMap_t::iterator iter = fInstanceMap.begin();
|
||||
iter != fInstanceMap.end(); ++iter)
|
||||
{
|
||||
Config* instance = iter->second;
|
||||
delete instance;
|
||||
}
|
||||
|
||||
fInstanceMap.clear();
|
||||
}
|
||||
|
||||
/* static */
|
||||
int64_t Config::fromText(const std::string& text)
|
||||
{
|
||||
if (text.length() == 0) return 0;
|
||||
if (text.length() == 0) return 0;
|
||||
|
||||
int64_t val = 0;
|
||||
char* ctext = static_cast<char*>(alloca(text.length() + 1));
|
||||
strcpy(ctext, text.c_str());
|
||||
char* cptr;
|
||||
int64_t val = 0;
|
||||
char* ctext = static_cast<char*>(alloca(text.length() + 1));
|
||||
strcpy(ctext, text.c_str());
|
||||
char* cptr;
|
||||
|
||||
val = strtoll(ctext, &cptr, 0);
|
||||
val = strtoll(ctext, &cptr, 0);
|
||||
|
||||
switch (*cptr)
|
||||
{
|
||||
case 'T':
|
||||
case 't':
|
||||
val *= 1024;
|
||||
/* fallthru */
|
||||
case 'G':
|
||||
case 'g':
|
||||
val *= 1024;
|
||||
/* fallthru */
|
||||
case 'M':
|
||||
case 'm':
|
||||
val *= 1024;
|
||||
/* fallthru */
|
||||
case 'K':
|
||||
case 'k':
|
||||
val *= 1024;
|
||||
/* fallthru */
|
||||
case '\0':
|
||||
break;
|
||||
default:
|
||||
ostringstream oss;
|
||||
oss << "Invalid character '" << *cptr << "' found in numeric parameter '" << text <<
|
||||
"'. Since this will not do what you want it is fatal." << endl;
|
||||
throw runtime_error(oss.str());
|
||||
break;
|
||||
}
|
||||
switch (*cptr)
|
||||
{
|
||||
case 'T':
|
||||
case 't':
|
||||
val *= 1024;
|
||||
|
||||
return val;
|
||||
/* fallthru */
|
||||
case 'G':
|
||||
case 'g':
|
||||
val *= 1024;
|
||||
|
||||
/* fallthru */
|
||||
case 'M':
|
||||
case 'm':
|
||||
val *= 1024;
|
||||
|
||||
/* fallthru */
|
||||
case 'K':
|
||||
case 'k':
|
||||
val *= 1024;
|
||||
|
||||
/* fallthru */
|
||||
case '\0':
|
||||
break;
|
||||
|
||||
default:
|
||||
ostringstream oss;
|
||||
oss << "Invalid character '" << *cptr << "' found in numeric parameter '" << text <<
|
||||
"'. Since this will not do what you want it is fatal." << endl;
|
||||
throw runtime_error(oss.str());
|
||||
break;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
time_t Config::getCurrentMTime()
|
||||
{
|
||||
mutex::scoped_lock lk(fLock);
|
||||
mutex::scoped_lock lk(fLock);
|
||||
|
||||
struct stat statbuf;
|
||||
if (stat(fConfigFile.c_str(), &statbuf) == 0)
|
||||
return statbuf.st_mtime;
|
||||
else
|
||||
return 0;
|
||||
struct stat statbuf;
|
||||
|
||||
if (stat(fConfigFile.c_str(), &statbuf) == 0)
|
||||
return statbuf.st_mtime;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
const vector<string> Config::enumConfig()
|
||||
{
|
||||
mutex::scoped_lock lk(fLock);
|
||||
mutex::scoped_lock lk(fLock);
|
||||
|
||||
if (fDoc == 0){
|
||||
throw runtime_error("Config::getConfig: no XML document!");
|
||||
}
|
||||
if (fDoc == 0)
|
||||
{
|
||||
throw runtime_error("Config::getConfig: no XML document!");
|
||||
}
|
||||
|
||||
struct stat statbuf;
|
||||
if (stat(fConfigFile.c_str(), &statbuf) == 0)
|
||||
{
|
||||
if (statbuf.st_mtime != fMtime)
|
||||
{
|
||||
closeConfig();
|
||||
fMtime = statbuf.st_mtime;
|
||||
parseDoc();
|
||||
}
|
||||
}
|
||||
struct stat statbuf;
|
||||
|
||||
return fParser.enumConfig(fDoc);
|
||||
if (stat(fConfigFile.c_str(), &statbuf) == 0)
|
||||
{
|
||||
if (statbuf.st_mtime != fMtime)
|
||||
{
|
||||
closeConfig();
|
||||
fMtime = statbuf.st_mtime;
|
||||
parseDoc();
|
||||
}
|
||||
}
|
||||
|
||||
return fParser.enumConfig(fDoc);
|
||||
}
|
||||
|
||||
const vector<string> Config::enumSection(const string& section)
|
||||
{
|
||||
mutex::scoped_lock lk(fLock);
|
||||
mutex::scoped_lock lk(fLock);
|
||||
|
||||
if (fDoc == 0){
|
||||
throw runtime_error("Config::getConfig: no XML document!");
|
||||
}
|
||||
if (fDoc == 0)
|
||||
{
|
||||
throw runtime_error("Config::getConfig: no XML document!");
|
||||
}
|
||||
|
||||
struct stat statbuf;
|
||||
if (stat(fConfigFile.c_str(), &statbuf) == 0)
|
||||
{
|
||||
if (statbuf.st_mtime != fMtime)
|
||||
{
|
||||
closeConfig();
|
||||
fMtime = statbuf.st_mtime;
|
||||
parseDoc();
|
||||
}
|
||||
}
|
||||
struct stat statbuf;
|
||||
|
||||
return fParser.enumSection(fDoc, section);
|
||||
if (stat(fConfigFile.c_str(), &statbuf) == 0)
|
||||
{
|
||||
if (statbuf.st_mtime != fMtime)
|
||||
{
|
||||
closeConfig();
|
||||
fMtime = statbuf.st_mtime;
|
||||
parseDoc();
|
||||
}
|
||||
}
|
||||
|
||||
return fParser.enumSection(fDoc, section);
|
||||
}
|
||||
|
||||
} //namespace config
|
||||
|
@ -50,7 +50,8 @@ class ByteStream;
|
||||
#define EXPORT
|
||||
#endif
|
||||
|
||||
namespace config {
|
||||
namespace config
|
||||
{
|
||||
|
||||
/** @brief a config file I/F class
|
||||
*
|
||||
@ -62,167 +63,176 @@ namespace config {
|
||||
class Config
|
||||
{
|
||||
public:
|
||||
/** @brief Config factory method
|
||||
*
|
||||
* Creates a singleton Config object
|
||||
*/
|
||||
EXPORT static Config* makeConfig(const char* cf=0);
|
||||
/** @brief Config factory method
|
||||
*
|
||||
* Creates a singleton Config object
|
||||
*/
|
||||
EXPORT static Config* makeConfig(const char* cf = 0);
|
||||
|
||||
/** @brief Config factory method
|
||||
*
|
||||
* Creates a singleton Config object
|
||||
*/
|
||||
EXPORT static Config* makeConfig(const std::string& cf);
|
||||
/** @brief Config factory method
|
||||
*
|
||||
* Creates a singleton Config object
|
||||
*/
|
||||
EXPORT static Config* makeConfig(const std::string& cf);
|
||||
|
||||
/** @brief dtor
|
||||
*/
|
||||
EXPORT virtual ~Config();
|
||||
/** @brief dtor
|
||||
*/
|
||||
EXPORT virtual ~Config();
|
||||
|
||||
/** @brief get name's value from section
|
||||
*
|
||||
* get name's value from section in the current config file.
|
||||
* @param section the name of the config file section to search
|
||||
* @param name the param name whose value is to be returned
|
||||
*/
|
||||
EXPORT const std::string getConfig(const std::string& section, const std::string& name);
|
||||
/** @brief get name's value from section
|
||||
*
|
||||
* get name's value from section in the current config file.
|
||||
* @param section the name of the config file section to search
|
||||
* @param name the param name whose value is to be returned
|
||||
*/
|
||||
EXPORT const std::string getConfig(const std::string& section, const std::string& name);
|
||||
|
||||
/** @brief get all name's values from a section
|
||||
*
|
||||
* get name's values from section in the current config file.
|
||||
* @param section the name of the config file section to search
|
||||
* @param name the param name whose value is to be returned
|
||||
* @param values the values in the section are returned in this vector
|
||||
*/
|
||||
EXPORT void getConfig(const std::string& section, const std::string& name,
|
||||
std::vector<std::string>& values);
|
||||
/** @brief get all name's values from a section
|
||||
*
|
||||
* get name's values from section in the current config file.
|
||||
* @param section the name of the config file section to search
|
||||
* @param name the param name whose value is to be returned
|
||||
* @param values the values in the section are returned in this vector
|
||||
*/
|
||||
EXPORT void getConfig(const std::string& section, const std::string& name,
|
||||
std::vector<std::string>& values);
|
||||
|
||||
/** @brief set name's value in section
|
||||
*
|
||||
* set name's value in section in the current config file.
|
||||
* @param section the name of the config file section to update
|
||||
* @param name the param name whose value is to be updated
|
||||
* @param value the param value
|
||||
*/
|
||||
EXPORT void setConfig(const std::string& section, const std::string& name, const std::string& value);
|
||||
/** @brief set name's value in section
|
||||
*
|
||||
* set name's value in section in the current config file.
|
||||
* @param section the name of the config file section to update
|
||||
* @param name the param name whose value is to be updated
|
||||
* @param value the param value
|
||||
*/
|
||||
EXPORT void setConfig(const std::string& section, const std::string& name, const std::string& value);
|
||||
|
||||
/** @brief delete name from section
|
||||
*
|
||||
* delete name from section in the current config file.
|
||||
* @param section the name of the config file section to search
|
||||
* @param name the param name whose entry is to be deleted
|
||||
* @note if you delete the last param from a section, the section will still remain
|
||||
*/
|
||||
EXPORT void delConfig(const std::string& section, const std::string& name);
|
||||
/** @brief delete name from section
|
||||
*
|
||||
* delete name from section in the current config file.
|
||||
* @param section the name of the config file section to search
|
||||
* @param name the param name whose entry is to be deleted
|
||||
* @note if you delete the last param from a section, the section will still remain
|
||||
*/
|
||||
EXPORT void delConfig(const std::string& section, const std::string& name);
|
||||
|
||||
/** @brief write the config file back out to disk
|
||||
*
|
||||
* write the config file back out to disk using the current filename.
|
||||
*/
|
||||
EXPORT void write(void) const;
|
||||
/** @brief write the config file back out to disk
|
||||
*
|
||||
* write the config file back out to disk using the current filename.
|
||||
*/
|
||||
EXPORT void write(void) const;
|
||||
|
||||
/** @brief write the config file back out to disk as fileName
|
||||
*
|
||||
* write the config file out to disk as a new file fileName. Does not affect the current
|
||||
* config filename.
|
||||
*/
|
||||
EXPORT void write(const std::string& fileName) const;
|
||||
/** @brief write the config file back out to disk as fileName
|
||||
*
|
||||
* write the config file out to disk as a new file fileName. Does not affect the current
|
||||
* config filename.
|
||||
*/
|
||||
EXPORT void write(const std::string& fileName) const;
|
||||
|
||||
/** @brief write a stream copy of config file to disk
|
||||
*
|
||||
* write a stream copy of config file to disk. used to distributed mass updates to system nodes
|
||||
*
|
||||
*/
|
||||
EXPORT void writeConfigFile(messageqcpp::ByteStream msg) const;
|
||||
/** @brief write a stream copy of config file to disk
|
||||
*
|
||||
* write a stream copy of config file to disk. used to distributed mass updates to system nodes
|
||||
*
|
||||
*/
|
||||
EXPORT void writeConfigFile(messageqcpp::ByteStream msg) const;
|
||||
|
||||
/** @brief return the name of this config file
|
||||
*
|
||||
* return the name of this config file.
|
||||
*/
|
||||
EXPORT inline const std::string& configFile() const { return fConfigFile; }
|
||||
/** @brief return the name of this config file
|
||||
*
|
||||
* return the name of this config file.
|
||||
*/
|
||||
EXPORT inline const std::string& configFile() const
|
||||
{
|
||||
return fConfigFile;
|
||||
}
|
||||
|
||||
/** @brief delete all config file instances
|
||||
*
|
||||
* deletes \b all config file maps
|
||||
*/
|
||||
EXPORT static void deleteInstanceMap();
|
||||
/** @brief delete all config file instances
|
||||
*
|
||||
* deletes \b all config file maps
|
||||
*/
|
||||
EXPORT static void deleteInstanceMap();
|
||||
|
||||
/** @brief parse config file numerics
|
||||
*
|
||||
* Convert human-friendly number formats to machine-friendly. Handle suffixes 'K', 'M', 'G'.
|
||||
* Handle decimal, hex and octal notation in the same way as the C compiler.
|
||||
* Ignore any 'B' following [KMG]. Ignore case in suffixes.
|
||||
* An empty string or an unparseable string returns 0.
|
||||
* Return a signed numeric value.
|
||||
*/
|
||||
EXPORT static int64_t fromText(const std::string& text);
|
||||
/** @brief parse config file numerics
|
||||
*
|
||||
* Convert human-friendly number formats to machine-friendly. Handle suffixes 'K', 'M', 'G'.
|
||||
* Handle decimal, hex and octal notation in the same way as the C compiler.
|
||||
* Ignore any 'B' following [KMG]. Ignore case in suffixes.
|
||||
* An empty string or an unparseable string returns 0.
|
||||
* Return a signed numeric value.
|
||||
*/
|
||||
EXPORT static int64_t fromText(const std::string& text);
|
||||
|
||||
/** @brief parse config file numerics
|
||||
*
|
||||
* Return an unsigned numeric value.
|
||||
*/
|
||||
EXPORT static inline uint64_t uFromText(const std::string& text) { return static_cast<uint64_t>(fromText(text)); }
|
||||
/** @brief parse config file numerics
|
||||
*
|
||||
* Return an unsigned numeric value.
|
||||
*/
|
||||
EXPORT static inline uint64_t uFromText(const std::string& text)
|
||||
{
|
||||
return static_cast<uint64_t>(fromText(text));
|
||||
}
|
||||
|
||||
/** @brief Used externally to check whether there has been a config change without loading everything
|
||||
*
|
||||
*/
|
||||
inline time_t getLastMTime() const { return fMtime; }
|
||||
/** @brief Used externally to check whether there has been a config change without loading everything
|
||||
*
|
||||
*/
|
||||
inline time_t getLastMTime() const
|
||||
{
|
||||
return fMtime;
|
||||
}
|
||||
|
||||
/** @brief Used externally to check whether there has been a config change without loading everything
|
||||
*
|
||||
*/
|
||||
EXPORT time_t getCurrentMTime();
|
||||
/** @brief Used externally to check whether there has been a config change without loading everything
|
||||
*
|
||||
*/
|
||||
EXPORT time_t getCurrentMTime();
|
||||
|
||||
/** @brief Enumerate all the sections in the config file
|
||||
*
|
||||
*/
|
||||
EXPORT const std::vector<std::string> enumConfig();
|
||||
/** @brief Enumerate all the sections in the config file
|
||||
*
|
||||
*/
|
||||
EXPORT const std::vector<std::string> enumConfig();
|
||||
|
||||
/** @brief Enumerate all the names in a section in the config file
|
||||
*
|
||||
*/
|
||||
EXPORT const std::vector<std::string> enumSection(const std::string& section);
|
||||
/** @brief Enumerate all the names in a section in the config file
|
||||
*
|
||||
*/
|
||||
EXPORT const std::vector<std::string> enumSection(const std::string& section);
|
||||
|
||||
protected:
|
||||
/** @brief parse the XML file
|
||||
*
|
||||
*/
|
||||
void parseDoc(void);
|
||||
/** @brief parse the XML file
|
||||
*
|
||||
*/
|
||||
void parseDoc(void);
|
||||
|
||||
/** @brief write the XML tree to disk
|
||||
*
|
||||
*/
|
||||
EXPORT void writeConfig(const std::string& fileName) const;
|
||||
/** @brief write the XML tree to disk
|
||||
*
|
||||
*/
|
||||
EXPORT void writeConfig(const std::string& fileName) const;
|
||||
|
||||
/** @brief stop processing this XML file
|
||||
*
|
||||
*/
|
||||
void closeConfig(void);
|
||||
/** @brief stop processing this XML file
|
||||
*
|
||||
*/
|
||||
void closeConfig(void);
|
||||
|
||||
private:
|
||||
typedef std::map<std::string, Config*> configMap_t;
|
||||
typedef std::map<std::string, Config*> configMap_t;
|
||||
|
||||
/*
|
||||
*/
|
||||
Config(const Config& rhs);
|
||||
/*
|
||||
*/
|
||||
Config& operator=(const Config& rhs);
|
||||
/*
|
||||
*/
|
||||
Config(const Config& rhs);
|
||||
/*
|
||||
*/
|
||||
Config& operator=(const Config& rhs);
|
||||
|
||||
/** @brief ctor with config file specified
|
||||
*/
|
||||
Config(const std::string& configFile, const std::string& installDir);
|
||||
/** @brief ctor with config file specified
|
||||
*/
|
||||
Config(const std::string& configFile, const std::string& installDir);
|
||||
|
||||
static configMap_t fInstanceMap;
|
||||
static boost::mutex fInstanceMapMutex;
|
||||
static boost::mutex fXmlLock;
|
||||
static boost::mutex fWriteXmlLock;
|
||||
static configMap_t fInstanceMap;
|
||||
static boost::mutex fInstanceMapMutex;
|
||||
static boost::mutex fXmlLock;
|
||||
static boost::mutex fWriteXmlLock;
|
||||
|
||||
xmlDocPtr fDoc;
|
||||
const std::string fConfigFile;
|
||||
time_t fMtime;
|
||||
mutable boost::mutex fLock;
|
||||
const std::string fInstallDir;
|
||||
XMLParser fParser;
|
||||
xmlDocPtr fDoc;
|
||||
const std::string fConfigFile;
|
||||
time_t fMtime;
|
||||
mutable boost::mutex fLock;
|
||||
const std::string fInstallDir;
|
||||
XMLParser fParser;
|
||||
|
||||
};
|
||||
|
||||
|
@ -36,34 +36,35 @@ namespace config
|
||||
{
|
||||
|
||||
ConfigStream::ConfigStream(const ByteStream& bs, const string& installDir) :
|
||||
fParser(installDir)
|
||||
fParser(installDir)
|
||||
{
|
||||
init(reinterpret_cast<const xmlChar*>(bs.buf()));
|
||||
init(reinterpret_cast<const xmlChar*>(bs.buf()));
|
||||
}
|
||||
|
||||
ConfigStream::ConfigStream(const string& str, const string& installDir) :
|
||||
fParser(installDir)
|
||||
fParser(installDir)
|
||||
{
|
||||
init(reinterpret_cast<const xmlChar*>(str.c_str()));
|
||||
init(reinterpret_cast<const xmlChar*>(str.c_str()));
|
||||
}
|
||||
|
||||
ConfigStream::ConfigStream(const char* cptr, const string& installDir) :
|
||||
fParser(installDir)
|
||||
fParser(installDir)
|
||||
{
|
||||
init(reinterpret_cast<const xmlChar*>(cptr));
|
||||
init(reinterpret_cast<const xmlChar*>(cptr));
|
||||
}
|
||||
|
||||
ConfigStream::~ConfigStream()
|
||||
{
|
||||
if (fDoc != NULL)
|
||||
xmlFreeDoc(fDoc);
|
||||
if (fDoc != NULL)
|
||||
xmlFreeDoc(fDoc);
|
||||
}
|
||||
|
||||
void ConfigStream::init(const xmlChar* xp)
|
||||
{
|
||||
fDoc = xmlParseDoc(xp);
|
||||
if (fDoc == NULL)
|
||||
throw runtime_error("ConfigStream::ConfigStream: bad XML stream");
|
||||
fDoc = xmlParseDoc(xp);
|
||||
|
||||
if (fDoc == NULL)
|
||||
throw runtime_error("ConfigStream::ConfigStream: bad XML stream");
|
||||
}
|
||||
|
||||
} //namespace
|
||||
|
@ -41,22 +41,24 @@ namespace config
|
||||
class ConfigStream
|
||||
{
|
||||
public:
|
||||
ConfigStream(const messageqcpp::ByteStream& bs, const std::string& installDir);
|
||||
ConfigStream(const std::string& str, const std::string& installDir);
|
||||
ConfigStream(const char* cptr, const std::string& installDir);
|
||||
~ConfigStream();
|
||||
ConfigStream(const messageqcpp::ByteStream& bs, const std::string& installDir);
|
||||
ConfigStream(const std::string& str, const std::string& installDir);
|
||||
ConfigStream(const char* cptr, const std::string& installDir);
|
||||
~ConfigStream();
|
||||
|
||||
const std::string getConfig(const std::string& section, const std::string& name) const
|
||||
{ return fParser.getConfig(fDoc, section, name); }
|
||||
const std::string getConfig(const std::string& section, const std::string& name) const
|
||||
{
|
||||
return fParser.getConfig(fDoc, section, name);
|
||||
}
|
||||
|
||||
private:
|
||||
ConfigStream(const ConfigStream& rhs);
|
||||
ConfigStream& operator=(const ConfigStream& rhs);
|
||||
ConfigStream(const ConfigStream& rhs);
|
||||
ConfigStream& operator=(const ConfigStream& rhs);
|
||||
|
||||
void init(const xmlChar* xp);
|
||||
void init(const xmlChar* xp);
|
||||
|
||||
XMLParser fParser;
|
||||
xmlDocPtr fDoc;
|
||||
XMLParser fParser;
|
||||
xmlDocPtr fDoc;
|
||||
};
|
||||
|
||||
} //namespace
|
||||
|
@ -7,7 +7,7 @@
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
@ -148,18 +148,18 @@
|
||||
# if defined(__POWERPC__)
|
||||
# define ROTATE(a,n) __rlwinm(a,n,0,31)
|
||||
# elif defined(__MC68K__)
|
||||
/* Motorola specific tweak. <appro@fy.chalmers.se> */
|
||||
/* Motorola specific tweak. <appro@fy.chalmers.se> */
|
||||
# define ROTATE(a,n) ( n<24 ? __rol(a,n) : __ror(a,32-n) )
|
||||
# else
|
||||
# define ROTATE(a,n) __rol(a,n)
|
||||
# endif
|
||||
# elif defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
|
||||
/*
|
||||
* Some GNU C inline assembler templates. Note that these are
|
||||
* rotates by *constant* number of bits! But that's exactly
|
||||
* what we need here...
|
||||
* <appro@fy.chalmers.se>
|
||||
*/
|
||||
/*
|
||||
* Some GNU C inline assembler templates. Note that these are
|
||||
* rotates by *constant* number of bits! But that's exactly
|
||||
* what we need here...
|
||||
* <appro@fy.chalmers.se>
|
||||
*/
|
||||
# if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
|
||||
# define ROTATE(a,n) ({ register unsigned int ret; \
|
||||
asm ( \
|
||||
@ -200,12 +200,12 @@
|
||||
# if ((defined(__i386) || defined(__i386__)) && !defined(I386_ONLY)) || \
|
||||
(defined(__x86_64) || defined(__x86_64__))
|
||||
# if !defined(B_ENDIAN)
|
||||
/*
|
||||
* This gives ~30-40% performance improvement in SHA-256 compiled
|
||||
* with gcc [on P4]. Well, first macro to be frank. We can pull
|
||||
* this trick on x86* platforms only, because these CPUs can fetch
|
||||
* unaligned data without raising an exception.
|
||||
*/
|
||||
/*
|
||||
* This gives ~30-40% performance improvement in SHA-256 compiled
|
||||
* with gcc [on P4]. Well, first macro to be frank. We can pull
|
||||
* this trick on x86* platforms only, because these CPUs can fetch
|
||||
* unaligned data without raising an exception.
|
||||
*/
|
||||
# define HOST_c2l(c,l) ({ unsigned int r=*((const unsigned int *)(c)); \
|
||||
asm ("bswapl %0":"=r"(r):"0"(r)); \
|
||||
(c)+=4; (l)=r; })
|
||||
@ -252,7 +252,7 @@
|
||||
#endif
|
||||
#if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
|
||||
# ifndef B_ENDIAN
|
||||
/* See comment in DATA_ORDER_IS_BIG_ENDIAN section. */
|
||||
/* See comment in DATA_ORDER_IS_BIG_ENDIAN section. */
|
||||
# define HOST_c2l(c,l) ((l)=*((const unsigned int *)(c)), (c)+=4, l)
|
||||
# define HOST_l2c(l,c) (*((unsigned int *)(c))=(l), (c)+=4, l)
|
||||
# endif
|
||||
@ -279,108 +279,114 @@
|
||||
* Time for some action:-)
|
||||
*/
|
||||
|
||||
int HASH_UPDATE (HASH_CTX *c, const void *data_, size_t len)
|
||||
{
|
||||
const unsigned char *data=data_;
|
||||
unsigned char *p;
|
||||
HASH_LONG l;
|
||||
size_t n;
|
||||
int HASH_UPDATE (HASH_CTX* c, const void* data_, size_t len)
|
||||
{
|
||||
const unsigned char* data = data_;
|
||||
unsigned char* p;
|
||||
HASH_LONG l;
|
||||
size_t n;
|
||||
|
||||
if (len==0) return 1;
|
||||
if (len == 0) return 1;
|
||||
|
||||
l=(c->Nl+(((HASH_LONG)len)<<3))&0xffffffffUL;
|
||||
/* 95-05-24 eay Fixed a bug with the overflow handling, thanks to
|
||||
* Wei Dai <weidai@eskimo.com> for pointing it out. */
|
||||
if (l < c->Nl) /* overflow */
|
||||
c->Nh++;
|
||||
c->Nh+=(HASH_LONG)(len>>29); /* might cause compiler warning on 16-bit */
|
||||
c->Nl=l;
|
||||
l = (c->Nl + (((HASH_LONG)len) << 3)) & 0xffffffffUL;
|
||||
|
||||
n = c->num;
|
||||
if (n != 0)
|
||||
{
|
||||
p=(unsigned char *)c->data;
|
||||
/* 95-05-24 eay Fixed a bug with the overflow handling, thanks to
|
||||
* Wei Dai <weidai@eskimo.com> for pointing it out. */
|
||||
if (l < c->Nl) /* overflow */
|
||||
c->Nh++;
|
||||
|
||||
if (len >= HASH_CBLOCK || len+n >= HASH_CBLOCK)
|
||||
{
|
||||
memcpy (p+n,data,HASH_CBLOCK-n);
|
||||
HASH_BLOCK_DATA_ORDER (c,p,1);
|
||||
n = HASH_CBLOCK-n;
|
||||
data += n;
|
||||
len -= n;
|
||||
c->num = 0;
|
||||
memset (p,0,HASH_CBLOCK); /* keep it zeroed */
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy (p+n,data,len);
|
||||
c->num += (unsigned int)len;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
c->Nh += (HASH_LONG)(len >> 29); /* might cause compiler warning on 16-bit */
|
||||
c->Nl = l;
|
||||
|
||||
n = len/HASH_CBLOCK;
|
||||
if (n > 0)
|
||||
{
|
||||
HASH_BLOCK_DATA_ORDER (c,data,n);
|
||||
n *= HASH_CBLOCK;
|
||||
data += n;
|
||||
len -= n;
|
||||
}
|
||||
n = c->num;
|
||||
|
||||
if (len != 0)
|
||||
{
|
||||
p = (unsigned char *)c->data;
|
||||
c->num = (unsigned int)len;
|
||||
memcpy (p,data,len);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (n != 0)
|
||||
{
|
||||
p = (unsigned char*)c->data;
|
||||
|
||||
if (len >= HASH_CBLOCK || len + n >= HASH_CBLOCK)
|
||||
{
|
||||
memcpy (p + n, data, HASH_CBLOCK - n);
|
||||
HASH_BLOCK_DATA_ORDER (c, p, 1);
|
||||
n = HASH_CBLOCK - n;
|
||||
data += n;
|
||||
len -= n;
|
||||
c->num = 0;
|
||||
memset (p, 0, HASH_CBLOCK); /* keep it zeroed */
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy (p + n, data, len);
|
||||
c->num += (unsigned int)len;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
n = len / HASH_CBLOCK;
|
||||
|
||||
if (n > 0)
|
||||
{
|
||||
HASH_BLOCK_DATA_ORDER (c, data, n);
|
||||
n *= HASH_CBLOCK;
|
||||
data += n;
|
||||
len -= n;
|
||||
}
|
||||
|
||||
if (len != 0)
|
||||
{
|
||||
p = (unsigned char*)c->data;
|
||||
c->num = (unsigned int)len;
|
||||
memcpy (p, data, len);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void HASH_TRANSFORM (HASH_CTX *c, const unsigned char *data)
|
||||
{
|
||||
HASH_BLOCK_DATA_ORDER (c,data,1);
|
||||
}
|
||||
void HASH_TRANSFORM (HASH_CTX* c, const unsigned char* data)
|
||||
{
|
||||
HASH_BLOCK_DATA_ORDER (c, data, 1);
|
||||
}
|
||||
|
||||
|
||||
int HASH_FINAL (unsigned char *md, HASH_CTX *c)
|
||||
{
|
||||
unsigned char *p = (unsigned char *)c->data;
|
||||
size_t n = c->num;
|
||||
int HASH_FINAL (unsigned char* md, HASH_CTX* c)
|
||||
{
|
||||
unsigned char* p = (unsigned char*)c->data;
|
||||
size_t n = c->num;
|
||||
|
||||
p[n] = 0x80; /* there is always room for one */
|
||||
n++;
|
||||
p[n] = 0x80; /* there is always room for one */
|
||||
n++;
|
||||
|
||||
if (n > (HASH_CBLOCK-8))
|
||||
{
|
||||
memset (p+n,0,HASH_CBLOCK-n);
|
||||
n=0;
|
||||
HASH_BLOCK_DATA_ORDER (c,p,1);
|
||||
}
|
||||
memset (p+n,0,HASH_CBLOCK-8-n);
|
||||
if (n > (HASH_CBLOCK - 8))
|
||||
{
|
||||
memset (p + n, 0, HASH_CBLOCK - n);
|
||||
n = 0;
|
||||
HASH_BLOCK_DATA_ORDER (c, p, 1);
|
||||
}
|
||||
|
||||
p += HASH_CBLOCK-8;
|
||||
memset (p + n, 0, HASH_CBLOCK - 8 - n);
|
||||
|
||||
p += HASH_CBLOCK - 8;
|
||||
#if defined(DATA_ORDER_IS_BIG_ENDIAN)
|
||||
(void)HOST_l2c(c->Nh,p);
|
||||
(void)HOST_l2c(c->Nl,p);
|
||||
(void)HOST_l2c(c->Nh, p);
|
||||
(void)HOST_l2c(c->Nl, p);
|
||||
#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
|
||||
(void)HOST_l2c(c->Nl,p);
|
||||
(void)HOST_l2c(c->Nh,p);
|
||||
(void)HOST_l2c(c->Nl, p);
|
||||
(void)HOST_l2c(c->Nh, p);
|
||||
#endif
|
||||
p -= HASH_CBLOCK;
|
||||
HASH_BLOCK_DATA_ORDER (c,p,1);
|
||||
c->num=0;
|
||||
memset (p,0,HASH_CBLOCK);
|
||||
p -= HASH_CBLOCK;
|
||||
HASH_BLOCK_DATA_ORDER (c, p, 1);
|
||||
c->num = 0;
|
||||
memset (p, 0, HASH_CBLOCK);
|
||||
|
||||
#ifndef HASH_MAKE_STRING
|
||||
#error "HASH_MAKE_STRING must be defined!"
|
||||
#else
|
||||
HASH_MAKE_STRING(c,md);
|
||||
HASH_MAKE_STRING(c, md);
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifndef MD32_REG_T
|
||||
#if defined(__alpha) || defined(__sparcv9) || defined(__mips)
|
||||
@ -398,7 +404,7 @@ int HASH_FINAL (unsigned char *md, HASH_CTX *c)
|
||||
* *either* case. Now declaring 'em long excuses the compiler
|
||||
* from keeping 32 MSBs zeroed resulting in 13% performance
|
||||
* improvement under SPARC Solaris7/64 and 5% under AlphaLinux.
|
||||
* Well, to be honest it should say that this *prevents*
|
||||
* Well, to be honest it should say that this *prevents*
|
||||
* performance degradation.
|
||||
* <appro@fy.chalmers.se>
|
||||
*/
|
||||
|
@ -5,21 +5,21 @@
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
@ -34,10 +34,10 @@
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
@ -49,7 +49,7 @@
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
@ -97,18 +97,18 @@ extern "C" {
|
||||
#define MD5_DIGEST_LENGTH 16
|
||||
|
||||
typedef struct MD5state_st
|
||||
{
|
||||
MD5_LONG A,B,C,D;
|
||||
MD5_LONG Nl,Nh;
|
||||
MD5_LONG data[MD5_LBLOCK];
|
||||
unsigned int num;
|
||||
} MD5_CTX;
|
||||
{
|
||||
MD5_LONG A, B, C, D;
|
||||
MD5_LONG Nl, Nh;
|
||||
MD5_LONG data[MD5_LBLOCK];
|
||||
unsigned int num;
|
||||
} MD5_CTX;
|
||||
|
||||
int MD5_Init(MD5_CTX *c);
|
||||
int MD5_Update(MD5_CTX *c, const void *data, size_t len);
|
||||
int MD5_Final(unsigned char *md, MD5_CTX *c);
|
||||
unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md);
|
||||
void MD5_Transform(MD5_CTX *c, const unsigned char *b);
|
||||
int MD5_Init(MD5_CTX* c);
|
||||
int MD5_Update(MD5_CTX* c, const void* data, size_t len);
|
||||
int MD5_Final(unsigned char* md, MD5_CTX* c);
|
||||
unsigned char* MD5(const unsigned char* d, size_t n, unsigned char* md);
|
||||
void MD5_Transform(MD5_CTX* c, const unsigned char* b);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -5,21 +5,21 @@
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
@ -34,10 +34,10 @@
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
@ -49,7 +49,7 @@
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
@ -76,7 +76,7 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
void md5_block_data_order (MD5_CTX *c, const void *p,size_t num);
|
||||
void md5_block_data_order (MD5_CTX* c, const void* p, size_t num);
|
||||
|
||||
#define DATA_ORDER_IS_LITTLE_ENDIAN
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by libconfigcpp.rc
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 101
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by libconfigcpp.rc
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 101
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
|
@ -37,322 +37,341 @@ using namespace messageqcpp;
|
||||
#include "configstream.h"
|
||||
using namespace config;
|
||||
|
||||
class ConfigFileTest : public CppUnit::TestFixture {
|
||||
class ConfigFileTest : public CppUnit::TestFixture
|
||||
{
|
||||
|
||||
CPPUNIT_TEST_SUITE( ConfigFileTest );
|
||||
CPPUNIT_TEST_SUITE( ConfigFileTest );
|
||||
|
||||
CPPUNIT_TEST( test1 );
|
||||
CPPUNIT_TEST( test1 );
|
||||
|
||||
CPPUNIT_TEST_EXCEPTION( test2, std::runtime_error );
|
||||
CPPUNIT_TEST( test3 );
|
||||
CPPUNIT_TEST( test4 );
|
||||
CPPUNIT_TEST_EXCEPTION( test5, std::runtime_error );
|
||||
CPPUNIT_TEST_EXCEPTION( test6, std::runtime_error );
|
||||
CPPUNIT_TEST_EXCEPTION( test7, std::invalid_argument );
|
||||
CPPUNIT_TEST_EXCEPTION( test8, std::invalid_argument );
|
||||
CPPUNIT_TEST( test9 );
|
||||
CPPUNIT_TEST( test10 );
|
||||
CPPUNIT_TEST( test11 );
|
||||
CPPUNIT_TEST( test12 );
|
||||
CPPUNIT_TEST_EXCEPTION( test13_1, std::runtime_error );
|
||||
CPPUNIT_TEST_EXCEPTION( test13_2, std::runtime_error );
|
||||
CPPUNIT_TEST( test14 );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
CPPUNIT_TEST_EXCEPTION( test2, std::runtime_error );
|
||||
CPPUNIT_TEST( test3 );
|
||||
CPPUNIT_TEST( test4 );
|
||||
CPPUNIT_TEST_EXCEPTION( test5, std::runtime_error );
|
||||
CPPUNIT_TEST_EXCEPTION( test6, std::runtime_error );
|
||||
CPPUNIT_TEST_EXCEPTION( test7, std::invalid_argument );
|
||||
CPPUNIT_TEST_EXCEPTION( test8, std::invalid_argument );
|
||||
CPPUNIT_TEST( test9 );
|
||||
CPPUNIT_TEST( test10 );
|
||||
CPPUNIT_TEST( test11 );
|
||||
CPPUNIT_TEST( test12 );
|
||||
CPPUNIT_TEST_EXCEPTION( test13_1, std::runtime_error );
|
||||
CPPUNIT_TEST_EXCEPTION( test13_2, std::runtime_error );
|
||||
CPPUNIT_TEST( test14 );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
private:
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
void setUp()
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown() {
|
||||
}
|
||||
void tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
void test1() {
|
||||
Config* c1 = Config::makeConfig("./Columnstore.xml");
|
||||
string value;
|
||||
value = c1->getConfig("Message", "Name");
|
||||
CPPUNIT_ASSERT(value == "Message");
|
||||
void test1()
|
||||
{
|
||||
Config* c1 = Config::makeConfig("./Columnstore.xml");
|
||||
string value;
|
||||
value = c1->getConfig("Message", "Name");
|
||||
CPPUNIT_ASSERT(value == "Message");
|
||||
|
||||
value = c1->getConfig("Message", "xName");
|
||||
CPPUNIT_ASSERT(value.size() == 0);
|
||||
Config::deleteInstanceMap();
|
||||
}
|
||||
value = c1->getConfig("Message", "xName");
|
||||
CPPUNIT_ASSERT(value.size() == 0);
|
||||
Config::deleteInstanceMap();
|
||||
}
|
||||
|
||||
void test2() {
|
||||
Config* c1 = Config::makeConfig("./yadayada.xml");
|
||||
string value;
|
||||
void test2()
|
||||
{
|
||||
Config* c1 = Config::makeConfig("./yadayada.xml");
|
||||
string value;
|
||||
|
||||
value = c1->getConfig("Message", "Name");
|
||||
CPPUNIT_ASSERT(value.size() == 0);
|
||||
value = c1->getConfig("Message", "Name");
|
||||
CPPUNIT_ASSERT(value.size() == 0);
|
||||
|
||||
value = c1->getConfig("Message", "xName");
|
||||
CPPUNIT_ASSERT(value.size() == 0);
|
||||
value = c1->getConfig("Message", "xName");
|
||||
CPPUNIT_ASSERT(value.size() == 0);
|
||||
|
||||
Config::deleteInstanceMap();
|
||||
}
|
||||
Config::deleteInstanceMap();
|
||||
}
|
||||
|
||||
void test3() {
|
||||
Config* c1;
|
||||
string value;
|
||||
void test3()
|
||||
{
|
||||
Config* c1;
|
||||
string value;
|
||||
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
c1 = Config::makeConfig("./Columnstore.xml");
|
||||
value = c1->getConfig("Message", "Name");
|
||||
assert(value == "Message");
|
||||
}
|
||||
Config::deleteInstanceMap();
|
||||
}
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
c1 = Config::makeConfig("./Columnstore.xml");
|
||||
value = c1->getConfig("Message", "Name");
|
||||
assert(value == "Message");
|
||||
}
|
||||
|
||||
void test4() {
|
||||
Config* c1 = Config::makeConfig("./Columnstore.xml");
|
||||
string value;
|
||||
Config::deleteInstanceMap();
|
||||
}
|
||||
|
||||
value = c1->getConfig("SystemConfig", "SystemVersion");
|
||||
c1->setConfig("SystemConfig", "SystemVersion", "2.2.versionversionversion");
|
||||
value = c1->getConfig("SystemConfig", "SystemVersion");
|
||||
CPPUNIT_ASSERT(value == "2.2.versionversionversion");
|
||||
void test4()
|
||||
{
|
||||
Config* c1 = Config::makeConfig("./Columnstore.xml");
|
||||
string value;
|
||||
|
||||
::unlink("./Columnstore.xml.new");
|
||||
c1->write("./Columnstore.xml.new");
|
||||
value = c1->getConfig("SystemConfig", "SystemVersion");
|
||||
c1->setConfig("SystemConfig", "SystemVersion", "2.2.versionversionversion");
|
||||
value = c1->getConfig("SystemConfig", "SystemVersion");
|
||||
CPPUNIT_ASSERT(value == "2.2.versionversionversion");
|
||||
|
||||
value = c1->getConfig("SystemConfig", "SystemVersion");
|
||||
CPPUNIT_ASSERT(value == "2.2.versionversionversion");
|
||||
::unlink("./Columnstore.xml.new");
|
||||
c1->write("./Columnstore.xml.new");
|
||||
|
||||
c1->setConfig("SystemConfig", "SystemVersion1", "V1.x");
|
||||
value = c1->getConfig("SystemConfig", "SystemVersion1");
|
||||
CPPUNIT_ASSERT(value == "V1.x");
|
||||
value = c1->getConfig("SystemConfig", "SystemVersion");
|
||||
CPPUNIT_ASSERT(value == "2.2.versionversionversion");
|
||||
|
||||
c1->setConfig("SystemConfig1", "SystemVersion1", "Vx.x");
|
||||
value = c1->getConfig("SystemConfig1", "SystemVersion1");
|
||||
CPPUNIT_ASSERT(value == "Vx.x");
|
||||
c1->setConfig("SystemConfig", "SystemVersion1", "V1.x");
|
||||
value = c1->getConfig("SystemConfig", "SystemVersion1");
|
||||
CPPUNIT_ASSERT(value == "V1.x");
|
||||
|
||||
c1->write("./Columnstore.xml.new");
|
||||
Config* c2 = Config::makeConfig("./Columnstore.xml.new");
|
||||
value = c2->getConfig("SystemConfig1", "SystemVersion1");
|
||||
CPPUNIT_ASSERT(value == "Vx.x");
|
||||
c2->setConfig("SystemConfig", "SystemVersion1", "V1.1");
|
||||
value = c2->getConfig("SystemConfig", "SystemVersion1");
|
||||
CPPUNIT_ASSERT(value == "V1.1");
|
||||
c2->write();
|
||||
Config::deleteInstanceMap();
|
||||
}
|
||||
c1->setConfig("SystemConfig1", "SystemVersion1", "Vx.x");
|
||||
value = c1->getConfig("SystemConfig1", "SystemVersion1");
|
||||
CPPUNIT_ASSERT(value == "Vx.x");
|
||||
|
||||
void test5() {
|
||||
Config* c1 = Config::makeConfig("./Columnstore.xml");
|
||||
c1->write("/cantwritethis");
|
||||
Config::deleteInstanceMap();
|
||||
}
|
||||
c1->write("./Columnstore.xml.new");
|
||||
Config* c2 = Config::makeConfig("./Columnstore.xml.new");
|
||||
value = c2->getConfig("SystemConfig1", "SystemVersion1");
|
||||
CPPUNIT_ASSERT(value == "Vx.x");
|
||||
c2->setConfig("SystemConfig", "SystemVersion1", "V1.1");
|
||||
value = c2->getConfig("SystemConfig", "SystemVersion1");
|
||||
CPPUNIT_ASSERT(value == "V1.1");
|
||||
c2->write();
|
||||
Config::deleteInstanceMap();
|
||||
}
|
||||
|
||||
void test6() {
|
||||
Config* c1 = Config::makeConfig("./XColumnstore.xml");
|
||||
// compiler warning...we won't actually get here
|
||||
c1 = 0;
|
||||
}
|
||||
void test5()
|
||||
{
|
||||
Config* c1 = Config::makeConfig("./Columnstore.xml");
|
||||
c1->write("/cantwritethis");
|
||||
Config::deleteInstanceMap();
|
||||
}
|
||||
|
||||
void test7() {
|
||||
Config* c1 = Config::makeConfig("./Columnstore.xml");
|
||||
string s;
|
||||
string n;
|
||||
string v;
|
||||
c1->setConfig(s, n, v);
|
||||
Config::deleteInstanceMap();
|
||||
}
|
||||
void test6()
|
||||
{
|
||||
Config* c1 = Config::makeConfig("./XColumnstore.xml");
|
||||
// compiler warning...we won't actually get here
|
||||
c1 = 0;
|
||||
}
|
||||
|
||||
void test8() {
|
||||
Config* c1 = Config::makeConfig("./Columnstore.xml");
|
||||
string s;
|
||||
string n;
|
||||
string v;
|
||||
v = c1->getConfig(s, n);
|
||||
Config::deleteInstanceMap();
|
||||
}
|
||||
void test7()
|
||||
{
|
||||
Config* c1 = Config::makeConfig("./Columnstore.xml");
|
||||
string s;
|
||||
string n;
|
||||
string v;
|
||||
c1->setConfig(s, n, v);
|
||||
Config::deleteInstanceMap();
|
||||
}
|
||||
|
||||
void test9() {
|
||||
string value;
|
||||
void test8()
|
||||
{
|
||||
Config* c1 = Config::makeConfig("./Columnstore.xml");
|
||||
string s;
|
||||
string n;
|
||||
string v;
|
||||
v = c1->getConfig(s, n);
|
||||
Config::deleteInstanceMap();
|
||||
}
|
||||
|
||||
Config* c1 = Config::makeConfig("./Columnstore.xml");
|
||||
Config* c2 = Config::makeConfig("./Columnstore.xml.new");
|
||||
void test9()
|
||||
{
|
||||
string value;
|
||||
|
||||
value = c1->getConfig("Message", "Name");
|
||||
CPPUNIT_ASSERT(value == "Message");
|
||||
Config* c1 = Config::makeConfig("./Columnstore.xml");
|
||||
Config* c2 = Config::makeConfig("./Columnstore.xml.new");
|
||||
|
||||
value = c2->getConfig("SystemConfig", "SystemVersion1");
|
||||
CPPUNIT_ASSERT(value == "V1.1");
|
||||
Config::deleteInstanceMap();
|
||||
}
|
||||
value = c1->getConfig("Message", "Name");
|
||||
CPPUNIT_ASSERT(value == "Message");
|
||||
|
||||
void test10() {
|
||||
string value;
|
||||
value = c2->getConfig("SystemConfig", "SystemVersion1");
|
||||
CPPUNIT_ASSERT(value == "V1.1");
|
||||
Config::deleteInstanceMap();
|
||||
}
|
||||
|
||||
setenv("CALPONT_CONFIG_FILE", "./Columnstore.xml", 1);
|
||||
Config* c1 = Config::makeConfig();
|
||||
void test10()
|
||||
{
|
||||
string value;
|
||||
|
||||
value = c1->getConfig("Message", "Name");
|
||||
CPPUNIT_ASSERT(value == "Message");
|
||||
Config::deleteInstanceMap();
|
||||
setenv("CALPONT_CONFIG_FILE", "./Columnstore.xml", 1);
|
||||
Config* c1 = Config::makeConfig();
|
||||
|
||||
}
|
||||
value = c1->getConfig("Message", "Name");
|
||||
CPPUNIT_ASSERT(value == "Message");
|
||||
Config::deleteInstanceMap();
|
||||
|
||||
void test11() {
|
||||
string value;
|
||||
struct stat stat_buf;
|
||||
struct utimbuf utime_buf;
|
||||
}
|
||||
|
||||
CPPUNIT_ASSERT(stat("./Columnstore.xml.new", &stat_buf) == 0);
|
||||
void test11()
|
||||
{
|
||||
string value;
|
||||
struct stat stat_buf;
|
||||
struct utimbuf utime_buf;
|
||||
|
||||
Config* c1 = Config::makeConfig("./Columnstore.xml.new");
|
||||
CPPUNIT_ASSERT(stat("./Columnstore.xml.new", &stat_buf) == 0);
|
||||
|
||||
value = c1->getConfig("Message", "Name");
|
||||
CPPUNIT_ASSERT(value == "Message");
|
||||
Config* c1 = Config::makeConfig("./Columnstore.xml.new");
|
||||
|
||||
utime_buf.actime = utime_buf.modtime = stat_buf.st_mtime + 1;
|
||||
CPPUNIT_ASSERT(utime("./Columnstore.xml.new", &utime_buf) == 0);
|
||||
value = c1->getConfig("Message", "Name");
|
||||
CPPUNIT_ASSERT(value == "Message");
|
||||
|
||||
value = c1->getConfig("Message", "Name");
|
||||
CPPUNIT_ASSERT(value == "Message");
|
||||
Config::deleteInstanceMap();
|
||||
}
|
||||
utime_buf.actime = utime_buf.modtime = stat_buf.st_mtime + 1;
|
||||
CPPUNIT_ASSERT(utime("./Columnstore.xml.new", &utime_buf) == 0);
|
||||
|
||||
void test12() {
|
||||
string value;
|
||||
int64_t ival;
|
||||
uint64_t uval;
|
||||
value = c1->getConfig("Message", "Name");
|
||||
CPPUNIT_ASSERT(value == "Message");
|
||||
Config::deleteInstanceMap();
|
||||
}
|
||||
|
||||
value = "10";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == 10);
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == 10);
|
||||
void test12()
|
||||
{
|
||||
string value;
|
||||
int64_t ival;
|
||||
uint64_t uval;
|
||||
|
||||
value = "0x10";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == 0x10);
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == 0x10);
|
||||
value = "10";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == 10);
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == 10);
|
||||
|
||||
value = "010";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == 010);
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == 010);
|
||||
value = "0x10";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == 0x10);
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == 0x10);
|
||||
|
||||
value = "-10";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == -10);
|
||||
value = "010";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == 010);
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == 010);
|
||||
|
||||
value = "10K";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == (10 * 1024));
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == (10 * 1024));
|
||||
value = "-10";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == -10);
|
||||
|
||||
value = "10k";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == (10 * 1024));
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == (10 * 1024));
|
||||
value = "10K";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == (10 * 1024));
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == (10 * 1024));
|
||||
|
||||
value = "10M";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == (10 * 1024 * 1024));
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == (10 * 1024 * 1024));
|
||||
value = "10k";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == (10 * 1024));
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == (10 * 1024));
|
||||
|
||||
value = "10m";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == (10 * 1024 * 1024));
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == (10 * 1024 * 1024));
|
||||
value = "10M";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == (10 * 1024 * 1024));
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == (10 * 1024 * 1024));
|
||||
|
||||
value = "10G";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == (10 * 1024 * 1024 * 1024LL));
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == (10 * 1024 * 1024 * 1024ULL));
|
||||
value = "10m";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == (10 * 1024 * 1024));
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == (10 * 1024 * 1024));
|
||||
|
||||
value = "10g";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == (10 * 1024 * 1024 * 1024LL));
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == (10 * 1024 * 1024 * 1024ULL));
|
||||
value = "10G";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == (10 * 1024 * 1024 * 1024LL));
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == (10 * 1024 * 1024 * 1024ULL));
|
||||
|
||||
value = "10MB";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == (10 * 1024 * 1024));
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == (10 * 1024 * 1024));
|
||||
value = "10g";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == (10 * 1024 * 1024 * 1024LL));
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == (10 * 1024 * 1024 * 1024ULL));
|
||||
|
||||
value = "0x7afafafafafafafa";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == 0x7afafafafafafafaLL);
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == 0x7afafafafafafafaULL);
|
||||
value = "10MB";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == (10 * 1024 * 1024));
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == (10 * 1024 * 1024));
|
||||
|
||||
value = "-0x7afafafafafafafa";
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == 0x8505050505050506ULL);
|
||||
value = "0x7afafafafafafafa";
|
||||
ival = Config::fromText(value);
|
||||
CPPUNIT_ASSERT(ival == 0x7afafafafafafafaLL);
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == 0x7afafafafafafafaULL);
|
||||
|
||||
value = "-1";
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == 0xffffffffffffffffULL);
|
||||
value = "-0x7afafafafafafafa";
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == 0x8505050505050506ULL);
|
||||
|
||||
}
|
||||
value = "-1";
|
||||
uval = Config::uFromText(value);
|
||||
CPPUNIT_ASSERT(uval == 0xffffffffffffffffULL);
|
||||
|
||||
void test13_1() {
|
||||
string value;
|
||||
int64_t ival;
|
||||
}
|
||||
|
||||
value = "2.2MB"; //invalid char causes throw
|
||||
ival = Config::fromText(value);
|
||||
}
|
||||
void test13_1()
|
||||
{
|
||||
string value;
|
||||
int64_t ival;
|
||||
|
||||
void test13_2() {
|
||||
string value;
|
||||
int64_t ival;
|
||||
value = "2.2MB"; //invalid char causes throw
|
||||
ival = Config::fromText(value);
|
||||
}
|
||||
|
||||
value = "10,000"; //invalid char causes throw
|
||||
ival = Config::fromText(value);
|
||||
}
|
||||
void test13_2()
|
||||
{
|
||||
string value;
|
||||
int64_t ival;
|
||||
|
||||
void test14() {
|
||||
ByteStream bs;
|
||||
ifstream ifs("./Columnstore.xml");
|
||||
ifs >> bs;
|
||||
string id(".");
|
||||
string value;
|
||||
{
|
||||
ConfigStream cs(bs, id);
|
||||
value = cs.getConfig("Message", "Name");
|
||||
CPPUNIT_ASSERT(value == "Message");
|
||||
}
|
||||
string bss(reinterpret_cast<const char*>(bs.buf()), bs.length());
|
||||
{
|
||||
ConfigStream cs(bss, id);
|
||||
value = cs.getConfig("Message", "Name");
|
||||
CPPUNIT_ASSERT(value == "Message");
|
||||
}
|
||||
{
|
||||
ConfigStream cs(bss.c_str(), id);
|
||||
value = cs.getConfig("Message", "Name");
|
||||
CPPUNIT_ASSERT(value == "Message");
|
||||
}
|
||||
}
|
||||
value = "10,000"; //invalid char causes throw
|
||||
ival = Config::fromText(value);
|
||||
}
|
||||
|
||||
};
|
||||
void test14()
|
||||
{
|
||||
ByteStream bs;
|
||||
ifstream ifs("./Columnstore.xml");
|
||||
ifs >> bs;
|
||||
string id(".");
|
||||
string value;
|
||||
{
|
||||
ConfigStream cs(bs, id);
|
||||
value = cs.getConfig("Message", "Name");
|
||||
CPPUNIT_ASSERT(value == "Message");
|
||||
}
|
||||
string bss(reinterpret_cast<const char*>(bs.buf()), bs.length());
|
||||
{
|
||||
ConfigStream cs(bss, id);
|
||||
value = cs.getConfig("Message", "Name");
|
||||
CPPUNIT_ASSERT(value == "Message");
|
||||
}
|
||||
{
|
||||
ConfigStream cs(bss.c_str(), id);
|
||||
value = cs.getConfig("Message", "Name");
|
||||
CPPUNIT_ASSERT(value == "Message");
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( ConfigFileTest );
|
||||
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
|
||||
int main( int argc, char **argv)
|
||||
int main( int argc, char** argv)
|
||||
{
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry();
|
||||
runner.addTest( registry.makeTest() );
|
||||
bool wasSuccessful = runner.run( "", false );
|
||||
return (wasSuccessful ? 0 : 1);
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
|
||||
runner.addTest( registry.makeTest() );
|
||||
bool wasSuccessful = runner.run( "", false );
|
||||
return (wasSuccessful ? 0 : 1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -38,86 +38,94 @@ namespace
|
||||
const string cf("./woparms.dat");
|
||||
}
|
||||
|
||||
class WOConfigFileTest : public CppUnit::TestFixture {
|
||||
class WOConfigFileTest : public CppUnit::TestFixture
|
||||
{
|
||||
|
||||
CPPUNIT_TEST_SUITE( WOConfigFileTest );
|
||||
CPPUNIT_TEST_SUITE( WOConfigFileTest );
|
||||
|
||||
CPPUNIT_TEST( test1 );
|
||||
CPPUNIT_TEST_EXCEPTION( test2, std::runtime_error );
|
||||
CPPUNIT_TEST_EXCEPTION( test3, std::runtime_error );
|
||||
CPPUNIT_TEST_EXCEPTION( test4, std::runtime_error );
|
||||
CPPUNIT_TEST( test5 );
|
||||
CPPUNIT_TEST( test1 );
|
||||
CPPUNIT_TEST_EXCEPTION( test2, std::runtime_error );
|
||||
CPPUNIT_TEST_EXCEPTION( test3, std::runtime_error );
|
||||
CPPUNIT_TEST_EXCEPTION( test4, std::runtime_error );
|
||||
CPPUNIT_TEST( test5 );
|
||||
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
unlink(cf.c_str());
|
||||
}
|
||||
void setUp()
|
||||
{
|
||||
unlink(cf.c_str());
|
||||
}
|
||||
|
||||
void tearDown() {
|
||||
unlink(cf.c_str());
|
||||
}
|
||||
void tearDown()
|
||||
{
|
||||
unlink(cf.c_str());
|
||||
}
|
||||
|
||||
void test1() {
|
||||
WriteOnceConfig woc(cf);
|
||||
CPPUNIT_ASSERT(woc.owns("PrimitiveServers", "LBID_Shift"));
|
||||
CPPUNIT_ASSERT(woc.owns("SystemConfig", "DBRootCount"));
|
||||
CPPUNIT_ASSERT(woc.owns("SystemConfig", "DBRMRoot"));
|
||||
void test1()
|
||||
{
|
||||
WriteOnceConfig woc(cf);
|
||||
CPPUNIT_ASSERT(woc.owns("PrimitiveServers", "LBID_Shift"));
|
||||
CPPUNIT_ASSERT(woc.owns("SystemConfig", "DBRootCount"));
|
||||
CPPUNIT_ASSERT(woc.owns("SystemConfig", "DBRMRoot"));
|
||||
|
||||
CPPUNIT_ASSERT(!woc.owns("dummy", "dummy"));
|
||||
CPPUNIT_ASSERT(!woc.owns("dummy", "dummy"));
|
||||
|
||||
int vali;
|
||||
int vali;
|
||||
|
||||
vali = Config::fromText(woc.getConfig("PrimitiveServers", "LBID_Shift"));
|
||||
CPPUNIT_ASSERT(vali == 13);
|
||||
vali = Config::fromText(woc.getConfig("PrimitiveServers", "LBID_Shift"));
|
||||
CPPUNIT_ASSERT(vali == 13);
|
||||
|
||||
woc.setConfig("SystemConfig", "DBRootCount", "10");
|
||||
vali = Config::fromText(woc.getConfig("SystemConfig", "DBRootCount"));
|
||||
CPPUNIT_ASSERT(vali == 10);
|
||||
woc.setConfig("SystemConfig", "DBRootCount", "10");
|
||||
vali = Config::fromText(woc.getConfig("SystemConfig", "DBRootCount"));
|
||||
CPPUNIT_ASSERT(vali == 10);
|
||||
|
||||
WriteOnceConfig woc2(cf.c_str());
|
||||
vali = Config::fromText(woc2.getConfig("SystemConfig", "DBRootCount"));
|
||||
CPPUNIT_ASSERT(vali == 10);
|
||||
}
|
||||
WriteOnceConfig woc2(cf.c_str());
|
||||
vali = Config::fromText(woc2.getConfig("SystemConfig", "DBRootCount"));
|
||||
CPPUNIT_ASSERT(vali == 10);
|
||||
}
|
||||
|
||||
void test2() {
|
||||
WriteOnceConfig woc(cf);
|
||||
woc.getConfig("dummy", "dummy");
|
||||
}
|
||||
void test2()
|
||||
{
|
||||
WriteOnceConfig woc(cf);
|
||||
woc.getConfig("dummy", "dummy");
|
||||
}
|
||||
|
||||
void test3() {
|
||||
WriteOnceConfig woc(cf);
|
||||
woc.setConfig("dummy", "dummy", "100");
|
||||
}
|
||||
void test3()
|
||||
{
|
||||
WriteOnceConfig woc(cf);
|
||||
woc.setConfig("dummy", "dummy", "100");
|
||||
}
|
||||
|
||||
void test4() {
|
||||
WriteOnceConfig woc(cf);
|
||||
woc.setConfig("SystemConfig", "DBRootCount", "10");
|
||||
woc.setConfig("SystemConfig", "DBRootCount", "11");
|
||||
}
|
||||
void test4()
|
||||
{
|
||||
WriteOnceConfig woc(cf);
|
||||
woc.setConfig("SystemConfig", "DBRootCount", "10");
|
||||
woc.setConfig("SystemConfig", "DBRootCount", "11");
|
||||
}
|
||||
|
||||
void test5() {
|
||||
WriteOnceConfig woc(cf);
|
||||
woc.setConfig("SystemConfig", "DBRootCount", "10");
|
||||
woc.setConfig("SystemConfig", "DBRootCount", "11", true);
|
||||
}
|
||||
void test5()
|
||||
{
|
||||
WriteOnceConfig woc(cf);
|
||||
woc.setConfig("SystemConfig", "DBRootCount", "10");
|
||||
woc.setConfig("SystemConfig", "DBRootCount", "11", true);
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( WOConfigFileTest );
|
||||
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
|
||||
int main( int argc, char **argv)
|
||||
int main( int argc, char** argv)
|
||||
{
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry();
|
||||
runner.addTest( registry.makeTest() );
|
||||
bool wasSuccessful = runner.run( "", false );
|
||||
return (wasSuccessful ? 0 : 1);
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
|
||||
runner.addTest( registry.makeTest() );
|
||||
bool wasSuccessful = runner.run( "", false );
|
||||
return (wasSuccessful ? 0 : 1);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
|
||||
#ifndef VERSIONNUMBER_H_
|
||||
#define VERSIONNUMBER_H_
|
||||
#include <string>
|
||||
const std::string idb_version("4.6");
|
||||
const std::string idb_release("0");
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef VERSIONNUMBER_H_
|
||||
#define VERSIONNUMBER_H_
|
||||
#include <string>
|
||||
const std::string idb_version("4.6");
|
||||
const std::string idb_release("0");
|
||||
#endif
|
||||
|
||||
|
@ -50,68 +50,75 @@ namespace config
|
||||
|
||||
void WriteOnceConfig::initializeDefaults()
|
||||
{
|
||||
fLBID_Shift = make_pair("13", false);
|
||||
fDBRootCount = make_pair("1", false);
|
||||
fDBRMRoot = make_pair("/mnt/OAM/dbrm/BRM_saves", false);
|
||||
fSharedMemoryTmpFile1 = make_pair("/tmp/CalpontShm,", false);
|
||||
fTxnIDFile = make_pair("/mnt/OAM/dbrm/SMTxnID", false);
|
||||
fSharedMemoryTmpFile2 = make_pair("/tmp/CalpontSessionMonitorShm", false);
|
||||
fLBID_Shift = make_pair("13", false);
|
||||
fDBRootCount = make_pair("1", false);
|
||||
fDBRMRoot = make_pair("/mnt/OAM/dbrm/BRM_saves", false);
|
||||
fSharedMemoryTmpFile1 = make_pair("/tmp/CalpontShm,", false);
|
||||
fTxnIDFile = make_pair("/mnt/OAM/dbrm/SMTxnID", false);
|
||||
fSharedMemoryTmpFile2 = make_pair("/tmp/CalpontSessionMonitorShm", false);
|
||||
}
|
||||
|
||||
void WriteOnceConfig::setup()
|
||||
{
|
||||
typedef EntryMap_t::value_type VT;
|
||||
typedef EntryMap_t::value_type VT;
|
||||
|
||||
fEntryMap.insert(VT("PrimitiveServers.LBID_Shift", &fLBID_Shift));
|
||||
fEntryMap.insert(VT("SystemConfig.DBRootCount", &fDBRootCount));
|
||||
fEntryMap.insert(VT("SystemConfig.DBRMRoot", &fDBRMRoot));
|
||||
fEntryMap.insert(VT("SessionManager.SharedMemoryTmpFile", &fSharedMemoryTmpFile1));
|
||||
fEntryMap.insert(VT("SessionManager.TxnIDFile", &fTxnIDFile));
|
||||
fEntryMap.insert(VT("SessionMonitor.SharedMemoryTmpFile", &fSharedMemoryTmpFile2));
|
||||
fEntryMap.insert(VT("PrimitiveServers.LBID_Shift", &fLBID_Shift));
|
||||
fEntryMap.insert(VT("SystemConfig.DBRootCount", &fDBRootCount));
|
||||
fEntryMap.insert(VT("SystemConfig.DBRMRoot", &fDBRMRoot));
|
||||
fEntryMap.insert(VT("SessionManager.SharedMemoryTmpFile", &fSharedMemoryTmpFile1));
|
||||
fEntryMap.insert(VT("SessionManager.TxnIDFile", &fTxnIDFile));
|
||||
fEntryMap.insert(VT("SessionMonitor.SharedMemoryTmpFile", &fSharedMemoryTmpFile2));
|
||||
|
||||
ByteStream ibs = load();
|
||||
if (ibs.length() > 0)
|
||||
unserialize(ibs);
|
||||
else
|
||||
initializeDefaults();
|
||||
ByteStream ibs = load();
|
||||
|
||||
if (ibs.length() > 0)
|
||||
unserialize(ibs);
|
||||
else
|
||||
initializeDefaults();
|
||||
}
|
||||
|
||||
void WriteOnceConfig::serialize(ByteStream& obs) const
|
||||
{
|
||||
obs << WriteOnceConfigVersion;
|
||||
obs << WriteOnceConfigVersion;
|
||||
|
||||
obs << fLBID_Shift.first;
|
||||
obs << fDBRootCount.first;
|
||||
obs << fDBRMRoot.first;
|
||||
obs << fSharedMemoryTmpFile1.first;
|
||||
obs << fTxnIDFile.first;
|
||||
obs << fSharedMemoryTmpFile2.first;
|
||||
obs << fLBID_Shift.first;
|
||||
obs << fDBRootCount.first;
|
||||
obs << fDBRMRoot.first;
|
||||
obs << fSharedMemoryTmpFile1.first;
|
||||
obs << fTxnIDFile.first;
|
||||
obs << fSharedMemoryTmpFile2.first;
|
||||
}
|
||||
|
||||
void WriteOnceConfig::unserialize(ByteStream& ibs)
|
||||
{
|
||||
uint32_t version;
|
||||
ibs >> version;
|
||||
uint32_t version;
|
||||
ibs >> version;
|
||||
|
||||
if (version < WriteOnceConfigVersion)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Invalid version found in WriteOnceConfig file: " << version;
|
||||
throw runtime_error(oss.str().c_str());
|
||||
}
|
||||
else if (version > WriteOnceConfigVersion)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Invalid version found in WriteOnceConfig file: " << version;
|
||||
throw runtime_error(oss.str().c_str());
|
||||
}
|
||||
if (version < WriteOnceConfigVersion)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Invalid version found in WriteOnceConfig file: " << version;
|
||||
throw runtime_error(oss.str().c_str());
|
||||
}
|
||||
else if (version > WriteOnceConfigVersion)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Invalid version found in WriteOnceConfig file: " << version;
|
||||
throw runtime_error(oss.str().c_str());
|
||||
}
|
||||
|
||||
ibs >> fLBID_Shift.first; fLBID_Shift.second = true;
|
||||
ibs >> fDBRootCount.first; fDBRootCount.second = true;
|
||||
ibs >> fDBRMRoot.first; fDBRMRoot.second = true;
|
||||
ibs >> fSharedMemoryTmpFile1.first; fSharedMemoryTmpFile1.second = true;
|
||||
ibs >> fTxnIDFile.first; fTxnIDFile.second = true;
|
||||
ibs >> fSharedMemoryTmpFile2.first; fSharedMemoryTmpFile2.second = true;
|
||||
ibs >> fLBID_Shift.first;
|
||||
fLBID_Shift.second = true;
|
||||
ibs >> fDBRootCount.first;
|
||||
fDBRootCount.second = true;
|
||||
ibs >> fDBRMRoot.first;
|
||||
fDBRMRoot.second = true;
|
||||
ibs >> fSharedMemoryTmpFile1.first;
|
||||
fSharedMemoryTmpFile1.second = true;
|
||||
ibs >> fTxnIDFile.first;
|
||||
fTxnIDFile.second = true;
|
||||
ibs >> fSharedMemoryTmpFile2.first;
|
||||
fSharedMemoryTmpFile2.second = true;
|
||||
}
|
||||
|
||||
|
||||
@ -119,95 +126,102 @@ void WriteOnceConfig::unserialize(ByteStream& ibs)
|
||||
|
||||
ByteStream WriteOnceConfig::load()
|
||||
{
|
||||
ByteStream bs;
|
||||
if (access(fConfigFileName.c_str(), F_OK) != 0)
|
||||
{
|
||||
initializeDefaults();
|
||||
return bs;
|
||||
}
|
||||
ByteStream bs;
|
||||
|
||||
idbassert(access(fConfigFileName.c_str(), F_OK) == 0);
|
||||
if (access(fConfigFileName.c_str(), F_OK) != 0)
|
||||
{
|
||||
initializeDefaults();
|
||||
return bs;
|
||||
}
|
||||
|
||||
ifstream ifs(fConfigFileName.c_str());
|
||||
int e = errno;
|
||||
if (!ifs.good())
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Error opening WriteOnceConfig file " << fConfigFileName << ": " << strerror(e);
|
||||
throw runtime_error(oss.str().c_str());
|
||||
}
|
||||
ifs >> bs;
|
||||
return bs;
|
||||
idbassert(access(fConfigFileName.c_str(), F_OK) == 0);
|
||||
|
||||
ifstream ifs(fConfigFileName.c_str());
|
||||
int e = errno;
|
||||
|
||||
if (!ifs.good())
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Error opening WriteOnceConfig file " << fConfigFileName << ": " << strerror(e);
|
||||
throw runtime_error(oss.str().c_str());
|
||||
}
|
||||
|
||||
ifs >> bs;
|
||||
return bs;
|
||||
}
|
||||
|
||||
void WriteOnceConfig::save(ByteStream& ibs) const
|
||||
{
|
||||
ofstream ofs(fConfigFileName.c_str());
|
||||
int e = errno;
|
||||
if (!ofs.good())
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Error opening WriteOnceConfig file " << fConfigFileName << ": " << strerror(e);
|
||||
throw runtime_error(oss.str().c_str());
|
||||
}
|
||||
ofs << ibs;
|
||||
ofstream ofs(fConfigFileName.c_str());
|
||||
int e = errno;
|
||||
|
||||
if (!ofs.good())
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Error opening WriteOnceConfig file " << fConfigFileName << ": " << strerror(e);
|
||||
throw runtime_error(oss.str().c_str());
|
||||
}
|
||||
|
||||
ofs << ibs;
|
||||
}
|
||||
|
||||
WriteOnceConfig::WriteOnceConfig(const char* cf)
|
||||
{
|
||||
string cfs;
|
||||
string cfs;
|
||||
|
||||
if (cf != 0)
|
||||
cfs = cf;
|
||||
else
|
||||
cfs = startup::StartUp::installDir() + "/etc/" + DefaultWriteOnceConfigFilename;
|
||||
if (cf != 0)
|
||||
cfs = cf;
|
||||
else
|
||||
cfs = startup::StartUp::installDir() + "/etc/" + DefaultWriteOnceConfigFilename;
|
||||
|
||||
fConfigFileName = cfs;
|
||||
fConfigFileName = cfs;
|
||||
|
||||
setup();
|
||||
setup();
|
||||
}
|
||||
|
||||
void WriteOnceConfig::setConfig(const string& section, const string& name, const string& value, bool force)
|
||||
{
|
||||
EntryMap_t::iterator iter;
|
||||
iter = fEntryMap.find(string(section + "." + name));
|
||||
if (iter == fEntryMap.end())
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Invalid request for " << section << '.' << name;
|
||||
throw runtime_error(oss.str().c_str());
|
||||
}
|
||||
EntryMap_t::iterator iter;
|
||||
iter = fEntryMap.find(string(section + "." + name));
|
||||
|
||||
if ((*iter->second).second && !force)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Invalid attempt to write read-only " << section << '.' << name;
|
||||
throw runtime_error(oss.str().c_str());
|
||||
}
|
||||
if (iter == fEntryMap.end())
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Invalid request for " << section << '.' << name;
|
||||
throw runtime_error(oss.str().c_str());
|
||||
}
|
||||
|
||||
(*iter->second).first = value;
|
||||
(*iter->second).second = true;
|
||||
if ((*iter->second).second && !force)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Invalid attempt to write read-only " << section << '.' << name;
|
||||
throw runtime_error(oss.str().c_str());
|
||||
}
|
||||
|
||||
ByteStream obs;
|
||||
serialize(obs);
|
||||
save(obs);
|
||||
(*iter->second).first = value;
|
||||
(*iter->second).second = true;
|
||||
|
||||
ByteStream obs;
|
||||
serialize(obs);
|
||||
save(obs);
|
||||
}
|
||||
|
||||
const string WriteOnceConfig::getConfig(const string& section, const string& name) const
|
||||
{
|
||||
string val;
|
||||
EntryMap_t::const_iterator iter;
|
||||
iter = fEntryMap.find(string(section + "." + name));
|
||||
if (iter == fEntryMap.end())
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Invalid request for " << section << '.' << name;
|
||||
throw runtime_error(oss.str().c_str());
|
||||
}
|
||||
string val;
|
||||
EntryMap_t::const_iterator iter;
|
||||
iter = fEntryMap.find(string(section + "." + name));
|
||||
|
||||
val = (*iter->second).first;
|
||||
if (iter == fEntryMap.end())
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Invalid request for " << section << '.' << name;
|
||||
throw runtime_error(oss.str().c_str());
|
||||
}
|
||||
|
||||
return val;
|
||||
val = (*iter->second).first;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,7 +36,8 @@
|
||||
|
||||
#include "bytestream.h"
|
||||
|
||||
namespace config {
|
||||
namespace config
|
||||
{
|
||||
|
||||
/** @brief a write-once config file I/F class
|
||||
*
|
||||
@ -45,94 +46,95 @@ namespace config {
|
||||
class WriteOnceConfig
|
||||
{
|
||||
public:
|
||||
/** @brief ctor
|
||||
*
|
||||
*/
|
||||
explicit WriteOnceConfig(const char* cf=0);
|
||||
/** @brief ctor
|
||||
*
|
||||
*/
|
||||
explicit WriteOnceConfig(const char* cf = 0);
|
||||
|
||||
/** @brief ctor
|
||||
*
|
||||
*/
|
||||
explicit WriteOnceConfig(const std::string& cf) :
|
||||
fConfigFileName(cf)
|
||||
{
|
||||
setup();
|
||||
}
|
||||
/** @brief ctor
|
||||
*
|
||||
*/
|
||||
explicit WriteOnceConfig(const std::string& cf) :
|
||||
fConfigFileName(cf)
|
||||
{
|
||||
setup();
|
||||
}
|
||||
|
||||
/** @brief dtor
|
||||
*
|
||||
*/
|
||||
virtual ~WriteOnceConfig() {}
|
||||
/** @brief dtor
|
||||
*
|
||||
*/
|
||||
virtual ~WriteOnceConfig() {}
|
||||
|
||||
/** @brief check if this class owns parm
|
||||
*
|
||||
*/
|
||||
bool owns(const std::string& section, const std::string& name) const {
|
||||
return (fEntryMap.find(std::string(section + "." + name)) != fEntryMap.end());
|
||||
}
|
||||
/** @brief check if this class owns parm
|
||||
*
|
||||
*/
|
||||
bool owns(const std::string& section, const std::string& name) const
|
||||
{
|
||||
return (fEntryMap.find(std::string(section + "." + name)) != fEntryMap.end());
|
||||
}
|
||||
|
||||
/** @brief set parm to value
|
||||
*
|
||||
* If you attempt to set a value more than once, and force is false, this will throw a runtime_error.
|
||||
*/
|
||||
void setConfig(const std::string& section, const std::string& name, const std::string& value, bool force=false);
|
||||
/** @brief set parm to value
|
||||
*
|
||||
* If you attempt to set a value more than once, and force is false, this will throw a runtime_error.
|
||||
*/
|
||||
void setConfig(const std::string& section, const std::string& name, const std::string& value, bool force = false);
|
||||
|
||||
/** @brief get value of parm
|
||||
*
|
||||
*/
|
||||
const std::string getConfig(const std::string& section, const std::string& name) const;
|
||||
/** @brief get value of parm
|
||||
*
|
||||
*/
|
||||
const std::string getConfig(const std::string& section, const std::string& name) const;
|
||||
|
||||
protected:
|
||||
/** @brief load from file
|
||||
*
|
||||
*/
|
||||
messageqcpp::ByteStream load();
|
||||
/** @brief load from file
|
||||
*
|
||||
*/
|
||||
messageqcpp::ByteStream load();
|
||||
|
||||
/** @brief save to file
|
||||
*
|
||||
*/
|
||||
void save(messageqcpp::ByteStream& ibs) const;
|
||||
/** @brief save to file
|
||||
*
|
||||
*/
|
||||
void save(messageqcpp::ByteStream& ibs) const;
|
||||
|
||||
/** @brief serialize to ByteStream
|
||||
*
|
||||
*/
|
||||
virtual void serialize(messageqcpp::ByteStream& obs) const;
|
||||
/** @brief serialize to ByteStream
|
||||
*
|
||||
*/
|
||||
virtual void serialize(messageqcpp::ByteStream& obs) const;
|
||||
|
||||
/** @brief load from ByteStream
|
||||
*
|
||||
*/
|
||||
virtual void unserialize(messageqcpp::ByteStream& ibs);
|
||||
/** @brief load from ByteStream
|
||||
*
|
||||
*/
|
||||
virtual void unserialize(messageqcpp::ByteStream& ibs);
|
||||
|
||||
private:
|
||||
typedef std::pair<std::string, bool> ConfigItem_t;
|
||||
typedef std::tr1::unordered_map<std::string, ConfigItem_t*> EntryMap_t;
|
||||
typedef std::pair<std::string, bool> ConfigItem_t;
|
||||
typedef std::tr1::unordered_map<std::string, ConfigItem_t*> EntryMap_t;
|
||||
|
||||
static const uint32_t WriteOnceConfigVersion = 1;
|
||||
static const uint32_t WriteOnceConfigVersion = 1;
|
||||
|
||||
//defaults okay
|
||||
//WriteOnceConfig(const WriteOnceConfig& rhs);
|
||||
//WriteOnceConfig& operator=(const WriteOnceConfig& rhs);
|
||||
//defaults okay
|
||||
//WriteOnceConfig(const WriteOnceConfig& rhs);
|
||||
//WriteOnceConfig& operator=(const WriteOnceConfig& rhs);
|
||||
|
||||
/** @brief ctor helper
|
||||
*
|
||||
*/
|
||||
void setup();
|
||||
/** @brief ctor helper
|
||||
*
|
||||
*/
|
||||
void setup();
|
||||
|
||||
/** @brief setup defaults when file doesn't exist
|
||||
*
|
||||
*/
|
||||
void initializeDefaults();
|
||||
/** @brief setup defaults when file doesn't exist
|
||||
*
|
||||
*/
|
||||
void initializeDefaults();
|
||||
|
||||
EntryMap_t fEntryMap;
|
||||
EntryMap_t fEntryMap;
|
||||
|
||||
std::string fConfigFileName;
|
||||
std::string fConfigFileName;
|
||||
|
||||
ConfigItem_t fLBID_Shift;
|
||||
ConfigItem_t fDBRootCount;
|
||||
ConfigItem_t fDBRMRoot;
|
||||
ConfigItem_t fSharedMemoryTmpFile1;
|
||||
ConfigItem_t fTxnIDFile;
|
||||
ConfigItem_t fSharedMemoryTmpFile2;
|
||||
ConfigItem_t fLBID_Shift;
|
||||
ConfigItem_t fDBRootCount;
|
||||
ConfigItem_t fDBRMRoot;
|
||||
ConfigItem_t fSharedMemoryTmpFile1;
|
||||
ConfigItem_t fTxnIDFile;
|
||||
ConfigItem_t fSharedMemoryTmpFile2;
|
||||
|
||||
};
|
||||
|
||||
|
@ -35,213 +35,254 @@ namespace config
|
||||
|
||||
const string XMLParser::getConfig(const xmlDocPtr doc, const string& section, const string& name) const
|
||||
{
|
||||
string res;
|
||||
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
|
||||
if (cur1 == NULL)
|
||||
throw runtime_error("XMLParser::getConfig: error accessing XML root");
|
||||
string res;
|
||||
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
|
||||
|
||||
cur1 = cur1->xmlChildrenNode;
|
||||
while (cur1 != NULL)
|
||||
{
|
||||
if ((!xmlStrcmp(cur1->name, (const xmlChar *)section.c_str())))
|
||||
{
|
||||
xmlNodePtr cur2 = cur1->xmlChildrenNode;
|
||||
while (cur2 != NULL)
|
||||
{
|
||||
if ((!xmlStrcmp(cur2->name, (const xmlChar*)name.c_str())))
|
||||
{
|
||||
xmlNodePtr cur3 = cur2->xmlChildrenNode;
|
||||
if (cur3)
|
||||
res = (const char*)cur3->content;
|
||||
return expand(res);
|
||||
}
|
||||
cur2 = cur2->next;
|
||||
}
|
||||
}
|
||||
cur1 = cur1->next;
|
||||
}
|
||||
// maybe nullstr if not found
|
||||
return expand(res);
|
||||
if (cur1 == NULL)
|
||||
throw runtime_error("XMLParser::getConfig: error accessing XML root");
|
||||
|
||||
cur1 = cur1->xmlChildrenNode;
|
||||
|
||||
while (cur1 != NULL)
|
||||
{
|
||||
if ((!xmlStrcmp(cur1->name, (const xmlChar*)section.c_str())))
|
||||
{
|
||||
xmlNodePtr cur2 = cur1->xmlChildrenNode;
|
||||
|
||||
while (cur2 != NULL)
|
||||
{
|
||||
if ((!xmlStrcmp(cur2->name, (const xmlChar*)name.c_str())))
|
||||
{
|
||||
xmlNodePtr cur3 = cur2->xmlChildrenNode;
|
||||
|
||||
if (cur3)
|
||||
res = (const char*)cur3->content;
|
||||
|
||||
return expand(res);
|
||||
}
|
||||
|
||||
cur2 = cur2->next;
|
||||
}
|
||||
}
|
||||
|
||||
cur1 = cur1->next;
|
||||
}
|
||||
|
||||
// maybe nullstr if not found
|
||||
return expand(res);
|
||||
}
|
||||
|
||||
void XMLParser::getConfig(const xmlDocPtr doc, const string& section, const string& name, vector<string>& values) const
|
||||
{
|
||||
string res;
|
||||
string res;
|
||||
|
||||
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
|
||||
if (cur1 == NULL)
|
||||
throw runtime_error("XMLParser::getConfig: error accessing XML root");
|
||||
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
|
||||
|
||||
cur1 = cur1->xmlChildrenNode;
|
||||
while (cur1 != NULL)
|
||||
{
|
||||
if ((!xmlStrcmp(cur1->name, (const xmlChar *)section.c_str())))
|
||||
{
|
||||
xmlNodePtr cur2 = cur1->xmlChildrenNode;
|
||||
while (cur2 != NULL)
|
||||
{
|
||||
if ((!xmlStrcmp(cur2->name, (const xmlChar*)name.c_str())))
|
||||
{
|
||||
res.clear();
|
||||
xmlNodePtr cur3 = cur2->xmlChildrenNode;
|
||||
if (cur3)
|
||||
res = (const char*)cur3->content;
|
||||
values.push_back(expand(res));
|
||||
}
|
||||
cur2 = cur2->next;
|
||||
}
|
||||
}
|
||||
cur1 = cur1->next;
|
||||
}
|
||||
if (cur1 == NULL)
|
||||
throw runtime_error("XMLParser::getConfig: error accessing XML root");
|
||||
|
||||
cur1 = cur1->xmlChildrenNode;
|
||||
|
||||
while (cur1 != NULL)
|
||||
{
|
||||
if ((!xmlStrcmp(cur1->name, (const xmlChar*)section.c_str())))
|
||||
{
|
||||
xmlNodePtr cur2 = cur1->xmlChildrenNode;
|
||||
|
||||
while (cur2 != NULL)
|
||||
{
|
||||
if ((!xmlStrcmp(cur2->name, (const xmlChar*)name.c_str())))
|
||||
{
|
||||
res.clear();
|
||||
xmlNodePtr cur3 = cur2->xmlChildrenNode;
|
||||
|
||||
if (cur3)
|
||||
res = (const char*)cur3->content;
|
||||
|
||||
values.push_back(expand(res));
|
||||
}
|
||||
|
||||
cur2 = cur2->next;
|
||||
}
|
||||
}
|
||||
|
||||
cur1 = cur1->next;
|
||||
}
|
||||
}
|
||||
|
||||
void XMLParser::setConfig(xmlDocPtr doc, const string& section, const string& name, const string& value)
|
||||
{
|
||||
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
|
||||
if (cur1 == NULL)
|
||||
throw runtime_error("XMLParser::setConfig: error accessing XML root");
|
||||
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
|
||||
|
||||
xmlNodePtr cur2;
|
||||
if (cur1 == NULL)
|
||||
throw runtime_error("XMLParser::setConfig: error accessing XML root");
|
||||
|
||||
cur1 = cur1->xmlChildrenNode;
|
||||
while (cur1 != NULL)
|
||||
{
|
||||
if (xmlStrcmp(cur1->name, (const xmlChar *)section.c_str()) == 0)
|
||||
{
|
||||
cur2 = cur1->xmlChildrenNode;
|
||||
while (cur2 != NULL)
|
||||
{
|
||||
if (xmlStrcmp(cur2->name, (const xmlChar*)name.c_str()) == 0)
|
||||
{
|
||||
xmlNodePtr cur3 = cur2->xmlChildrenNode;
|
||||
if (cur3 == NULL)
|
||||
{
|
||||
xmlAddChild(cur2, xmlNewText((const xmlChar*)"\t"));
|
||||
cur3 = cur2->xmlChildrenNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlFree(cur3->content);
|
||||
}
|
||||
cur3->content = xmlStrdup((const xmlChar*)value.c_str());
|
||||
return;
|
||||
}
|
||||
cur2 = cur2->next;
|
||||
}
|
||||
// We found the section, but not the name, so we need to add a new node here
|
||||
xmlAddChild(cur1, xmlNewText((const xmlChar*)"\t"));
|
||||
xmlNewTextChild(cur1, NULL, (const xmlChar*)name.c_str(), (const xmlChar*)value.c_str());
|
||||
xmlAddChild(cur1, xmlNewText((const xmlChar*)"\n\t"));
|
||||
return;
|
||||
}
|
||||
cur1 = cur1->next;
|
||||
}
|
||||
xmlNodePtr cur2;
|
||||
|
||||
// We did not find the section, so we need to add it and the name here
|
||||
cur1 = xmlDocGetRootElement(doc);
|
||||
xmlAddChild(cur1, xmlNewText((const xmlChar*)"\t"));
|
||||
cur2 = xmlNewChild(cur1, NULL, (const xmlChar*)section.c_str(), NULL);
|
||||
xmlAddChild(cur2, xmlNewText((const xmlChar*)"\n\t\t"));
|
||||
xmlNewTextChild(cur2, NULL, (const xmlChar*)name.c_str(), (const xmlChar*)value.c_str());
|
||||
xmlAddChild(cur2, xmlNewText((const xmlChar*)"\n\t"));
|
||||
xmlAddChild(cur1, xmlNewText((const xmlChar*)"\n"));
|
||||
cur1 = cur1->xmlChildrenNode;
|
||||
|
||||
return;
|
||||
while (cur1 != NULL)
|
||||
{
|
||||
if (xmlStrcmp(cur1->name, (const xmlChar*)section.c_str()) == 0)
|
||||
{
|
||||
cur2 = cur1->xmlChildrenNode;
|
||||
|
||||
while (cur2 != NULL)
|
||||
{
|
||||
if (xmlStrcmp(cur2->name, (const xmlChar*)name.c_str()) == 0)
|
||||
{
|
||||
xmlNodePtr cur3 = cur2->xmlChildrenNode;
|
||||
|
||||
if (cur3 == NULL)
|
||||
{
|
||||
xmlAddChild(cur2, xmlNewText((const xmlChar*)"\t"));
|
||||
cur3 = cur2->xmlChildrenNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlFree(cur3->content);
|
||||
}
|
||||
|
||||
cur3->content = xmlStrdup((const xmlChar*)value.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
cur2 = cur2->next;
|
||||
}
|
||||
|
||||
// We found the section, but not the name, so we need to add a new node here
|
||||
xmlAddChild(cur1, xmlNewText((const xmlChar*)"\t"));
|
||||
xmlNewTextChild(cur1, NULL, (const xmlChar*)name.c_str(), (const xmlChar*)value.c_str());
|
||||
xmlAddChild(cur1, xmlNewText((const xmlChar*)"\n\t"));
|
||||
return;
|
||||
}
|
||||
|
||||
cur1 = cur1->next;
|
||||
}
|
||||
|
||||
// We did not find the section, so we need to add it and the name here
|
||||
cur1 = xmlDocGetRootElement(doc);
|
||||
xmlAddChild(cur1, xmlNewText((const xmlChar*)"\t"));
|
||||
cur2 = xmlNewChild(cur1, NULL, (const xmlChar*)section.c_str(), NULL);
|
||||
xmlAddChild(cur2, xmlNewText((const xmlChar*)"\n\t\t"));
|
||||
xmlNewTextChild(cur2, NULL, (const xmlChar*)name.c_str(), (const xmlChar*)value.c_str());
|
||||
xmlAddChild(cur2, xmlNewText((const xmlChar*)"\n\t"));
|
||||
xmlAddChild(cur1, xmlNewText((const xmlChar*)"\n"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void XMLParser::delConfig(xmlDocPtr doc, const string& section, const string& name)
|
||||
{
|
||||
string res;
|
||||
string res;
|
||||
|
||||
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
|
||||
if (cur1 == NULL)
|
||||
throw runtime_error("XMLParser::delConfig: error accessing XML root");
|
||||
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
|
||||
|
||||
cur1 = cur1->xmlChildrenNode;
|
||||
while (cur1 != NULL)
|
||||
{
|
||||
if ((!xmlStrcmp(cur1->name, (const xmlChar *)section.c_str())))
|
||||
{
|
||||
xmlNodePtr cur2 = cur1->xmlChildrenNode;
|
||||
while (cur2 != NULL)
|
||||
{
|
||||
xmlNodePtr tmp = cur2;
|
||||
cur2 = cur2->next;
|
||||
if ((!xmlStrcmp(tmp->name, (const xmlChar*)name.c_str())))
|
||||
{
|
||||
xmlUnlinkNode(tmp);
|
||||
xmlFreeNode(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
cur1 = cur1->next;
|
||||
}
|
||||
if (cur1 == NULL)
|
||||
throw runtime_error("XMLParser::delConfig: error accessing XML root");
|
||||
|
||||
return;
|
||||
cur1 = cur1->xmlChildrenNode;
|
||||
|
||||
while (cur1 != NULL)
|
||||
{
|
||||
if ((!xmlStrcmp(cur1->name, (const xmlChar*)section.c_str())))
|
||||
{
|
||||
xmlNodePtr cur2 = cur1->xmlChildrenNode;
|
||||
|
||||
while (cur2 != NULL)
|
||||
{
|
||||
xmlNodePtr tmp = cur2;
|
||||
cur2 = cur2->next;
|
||||
|
||||
if ((!xmlStrcmp(tmp->name, (const xmlChar*)name.c_str())))
|
||||
{
|
||||
xmlUnlinkNode(tmp);
|
||||
xmlFreeNode(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cur1 = cur1->next;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const string XMLParser::expand(const std::string& in) const
|
||||
{
|
||||
string out(in);
|
||||
string::size_type pos;
|
||||
const string::size_type len=11;
|
||||
string out(in);
|
||||
string::size_type pos;
|
||||
const string::size_type len = 11;
|
||||
|
||||
pos = out.find("$INSTALLDIR");
|
||||
while (pos != string::npos)
|
||||
{
|
||||
out.replace(pos, len, fInstallDir);
|
||||
pos = out.find("$INSTALLDIR");
|
||||
}
|
||||
pos = out.find("$INSTALLDIR");
|
||||
|
||||
return out;
|
||||
while (pos != string::npos)
|
||||
{
|
||||
out.replace(pos, len, fInstallDir);
|
||||
pos = out.find("$INSTALLDIR");
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
const vector<string> XMLParser::enumConfig(const xmlDocPtr doc) const
|
||||
{
|
||||
vector<string> resv;
|
||||
string res;
|
||||
vector<string> resv;
|
||||
string res;
|
||||
|
||||
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
|
||||
if (cur1 == NULL)
|
||||
throw runtime_error("XMLParser::getConfig: error accessing XML root");
|
||||
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
|
||||
|
||||
cur1 = cur1->xmlChildrenNode;
|
||||
while (cur1 != NULL)
|
||||
{
|
||||
res = reinterpret_cast<const char*>(cur1->name);
|
||||
if (res != "text" && res != "comment")
|
||||
resv.push_back(res);
|
||||
cur1 = cur1->next;
|
||||
}
|
||||
return resv;
|
||||
if (cur1 == NULL)
|
||||
throw runtime_error("XMLParser::getConfig: error accessing XML root");
|
||||
|
||||
cur1 = cur1->xmlChildrenNode;
|
||||
|
||||
while (cur1 != NULL)
|
||||
{
|
||||
res = reinterpret_cast<const char*>(cur1->name);
|
||||
|
||||
if (res != "text" && res != "comment")
|
||||
resv.push_back(res);
|
||||
|
||||
cur1 = cur1->next;
|
||||
}
|
||||
|
||||
return resv;
|
||||
}
|
||||
|
||||
const vector<string> XMLParser::enumSection(const xmlDocPtr doc, const string& section) const
|
||||
{
|
||||
vector<string> resv;
|
||||
string res;
|
||||
vector<string> resv;
|
||||
string res;
|
||||
|
||||
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
|
||||
if (cur1 == NULL)
|
||||
throw runtime_error("XMLParser::getConfig: error accessing XML root");
|
||||
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
|
||||
|
||||
cur1 = cur1->xmlChildrenNode;
|
||||
while (cur1 != NULL)
|
||||
{
|
||||
if ((!xmlStrcmp(cur1->name, (const xmlChar *)section.c_str())))
|
||||
{
|
||||
xmlNodePtr cur2 = cur1->xmlChildrenNode;
|
||||
while (cur2 != NULL)
|
||||
{
|
||||
res = reinterpret_cast<const char*>(cur2->name);
|
||||
if (res != "text" && res != "comment")
|
||||
resv.push_back(expand(res));
|
||||
cur2 = cur2->next;
|
||||
}
|
||||
}
|
||||
cur1 = cur1->next;
|
||||
}
|
||||
return resv;
|
||||
if (cur1 == NULL)
|
||||
throw runtime_error("XMLParser::getConfig: error accessing XML root");
|
||||
|
||||
cur1 = cur1->xmlChildrenNode;
|
||||
|
||||
while (cur1 != NULL)
|
||||
{
|
||||
if ((!xmlStrcmp(cur1->name, (const xmlChar*)section.c_str())))
|
||||
{
|
||||
xmlNodePtr cur2 = cur1->xmlChildrenNode;
|
||||
|
||||
while (cur2 != NULL)
|
||||
{
|
||||
res = reinterpret_cast<const char*>(cur2->name);
|
||||
|
||||
if (res != "text" && res != "comment")
|
||||
resv.push_back(expand(res));
|
||||
|
||||
cur2 = cur2->next;
|
||||
}
|
||||
}
|
||||
|
||||
cur1 = cur1->next;
|
||||
}
|
||||
|
||||
return resv;
|
||||
}
|
||||
|
||||
} //namespace
|
||||
|
@ -36,33 +36,33 @@ namespace config
|
||||
class XMLParser
|
||||
{
|
||||
public:
|
||||
XMLParser(const std::string& installDir) : fInstallDir(installDir) { }
|
||||
~XMLParser() { }
|
||||
XMLParser(const std::string& installDir) : fInstallDir(installDir) { }
|
||||
~XMLParser() { }
|
||||
|
||||
const std::string getConfig(const xmlDocPtr doc, const std::string& section, const std::string& name) const;
|
||||
const std::string getConfig(const xmlDocPtr doc, const std::string& section, const std::string& name) const;
|
||||
|
||||
void getConfig(const xmlDocPtr doc, const std::string& section, const std::string& name,
|
||||
std::vector<std::string>& values) const;
|
||||
void getConfig(const xmlDocPtr doc, const std::string& section, const std::string& name,
|
||||
std::vector<std::string>& values) const;
|
||||
|
||||
void setConfig(xmlDocPtr doc, const std::string& section, const std::string& name,
|
||||
const std::string& value);
|
||||
void setConfig(xmlDocPtr doc, const std::string& section, const std::string& name,
|
||||
const std::string& value);
|
||||
|
||||
void delConfig(xmlDocPtr doc, const std::string& section, const std::string& name);
|
||||
void delConfig(xmlDocPtr doc, const std::string& section, const std::string& name);
|
||||
|
||||
const std::vector<std::string> enumConfig(const xmlDocPtr doc) const;
|
||||
const std::vector<std::string> enumConfig(const xmlDocPtr doc) const;
|
||||
|
||||
const std::vector<std::string> enumSection(const xmlDocPtr doc, const std::string& section) const;
|
||||
const std::vector<std::string> enumSection(const xmlDocPtr doc, const std::string& section) const;
|
||||
|
||||
private:
|
||||
//defaults okay
|
||||
//XMLParser(const XMLParser& rhs);
|
||||
//XMLParser& operator=(const XMLParser& rhs);
|
||||
//defaults okay
|
||||
//XMLParser(const XMLParser& rhs);
|
||||
//XMLParser& operator=(const XMLParser& rhs);
|
||||
|
||||
/** @brief expand macros in config file to actual values
|
||||
*/
|
||||
const std::string expand(const std::string& in) const;
|
||||
/** @brief expand macros in config file to actual values
|
||||
*/
|
||||
const std::string expand(const std::string& in) const;
|
||||
|
||||
const std::string fInstallDir;
|
||||
const std::string fInstallDir;
|
||||
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user