Convert to using ACE for reading configurationfiles, and remove dependency on dotconfpp configuration library and related files
(patch by astellar - and a thankyou to vladimir for being a russian teddybear) --HG-- branch : trunk
This commit is contained in:
@@ -26,7 +26,7 @@
|
|||||||
#include "Database/DatabaseEnv.h"
|
#include "Database/DatabaseEnv.h"
|
||||||
#include "Database/PreparedStatements.h"
|
#include "Database/PreparedStatements.h"
|
||||||
|
|
||||||
#include "Configuration/ConfigEnv.h"
|
#include "Configuration/Config.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "SystemConfig.h"
|
#include "SystemConfig.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "Database/DatabaseEnv.h"
|
#include "Database/DatabaseEnv.h"
|
||||||
#include "ByteBuffer.h"
|
#include "ByteBuffer.h"
|
||||||
#include "Configuration/ConfigEnv.h"
|
#include "Configuration/Config.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "RealmList.h"
|
#include "RealmList.h"
|
||||||
#include "AuthSocket.h"
|
#include "AuthSocket.h"
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
###############################################
|
###############################################
|
||||||
# Trinity Core Auth Server configuration file #
|
# Trinity Core Auth Server configuration file #
|
||||||
###############################################
|
###############################################
|
||||||
|
[authserver]
|
||||||
|
|
||||||
# Note to devs, line breaks should be at column 80
|
# Note to devs, line breaks should be at column 80
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# AUTH SERVER SETTINGS
|
# AUTH SERVER SETTINGS
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
#define AUCTION_HOUSE_BOT_H
|
#define AUCTION_HOUSE_BOT_H
|
||||||
|
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
#include "ConfigEnv.h"
|
#include "Config.h"
|
||||||
#include "ItemPrototype.h"
|
#include "ItemPrototype.h"
|
||||||
|
|
||||||
#define AHB_GREY 0
|
#define AHB_GREY 0
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
#include "SkillDiscovery.h"
|
#include "SkillDiscovery.h"
|
||||||
#include "SkillExtraItems.h"
|
#include "SkillExtraItems.h"
|
||||||
#include "SystemConfig.h"
|
#include "SystemConfig.h"
|
||||||
#include "ConfigEnv.h"
|
#include "Config.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "ItemEnchantmentMgr.h"
|
#include "ItemEnchantmentMgr.h"
|
||||||
#include "BattleGroundMgr.h"
|
#include "BattleGroundMgr.h"
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "Language.h"
|
#include "Language.h"
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
#include "ConfigEnv.h"
|
#include "Config.h"
|
||||||
|
|
||||||
Guild::Guild()
|
Guild::Guild()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
#include "InstanceSaveMgr.h"
|
#include "InstanceSaveMgr.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
#include "GridNotifiersImpl.h"
|
#include "GridNotifiersImpl.h"
|
||||||
#include "ConfigEnv.h"
|
#include "Config.h"
|
||||||
#include "Transport.h"
|
#include "Transport.h"
|
||||||
#include "ObjectMgr.h"
|
#include "ObjectMgr.h"
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
#include "InstanceData.h"
|
#include "InstanceData.h"
|
||||||
#include "Map.h"
|
#include "Map.h"
|
||||||
#include "GridNotifiersImpl.h"
|
#include "GridNotifiersImpl.h"
|
||||||
#include "ConfigEnv.h"
|
#include "Config.h"
|
||||||
#include "Transport.h"
|
#include "Transport.h"
|
||||||
#include "ObjectAccessor.h"
|
#include "ObjectAccessor.h"
|
||||||
#include "ObjectMgr.h"
|
#include "ObjectMgr.h"
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
#include "MapInstanced.h"
|
#include "MapInstanced.h"
|
||||||
#include "InstanceData.h"
|
#include "InstanceData.h"
|
||||||
#include "DestinationHolderImp.h"
|
#include "DestinationHolderImp.h"
|
||||||
#include "ConfigEnv.h"
|
#include "Config.h"
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
#include "CellImpl.h"
|
#include "CellImpl.h"
|
||||||
#include "Corpse.h"
|
#include "Corpse.h"
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "CompilerDefs.h"
|
#include "CompilerDefs.h"
|
||||||
#include "DBCStructure.h"
|
#include "DBCStructure.h"
|
||||||
#include "ConfigEnv.h"
|
#include "Config.h"
|
||||||
#include "ObjectMgr.h"
|
#include "ObjectMgr.h"
|
||||||
|
|
||||||
class Player;
|
class Player;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __ADDONHANDLER_H
|
#define __ADDONHANDLER_H
|
||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "ConfigEnv.h"
|
#include "Config.h"
|
||||||
#include "ace/Singleton.h"
|
#include "ace/Singleton.h"
|
||||||
#include "WorldPacket.h"
|
#include "WorldPacket.h"
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "WorldLog.h"
|
#include "WorldLog.h"
|
||||||
#include "ConfigEnv.h"
|
#include "Config.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
|
||||||
WorldLog::WorldLog() : i_file(NULL)
|
WorldLog::WorldLog() : i_file(NULL)
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "ConfigEnv.h"
|
#include "Config.h"
|
||||||
#include "DatabaseEnv.h"
|
#include "DatabaseEnv.h"
|
||||||
#include "WorldSocket.h"
|
#include "WorldSocket.h"
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "DatabaseEnv.h"
|
#include "DatabaseEnv.h"
|
||||||
#include "ConfigEnv.h"
|
#include "Config.h"
|
||||||
#include "SystemConfig.h"
|
#include "SystemConfig.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Opcodes.h"
|
#include "Opcodes.h"
|
||||||
|
|||||||
@@ -67,8 +67,6 @@ endif()
|
|||||||
########### trinityconfig ###############
|
########### trinityconfig ###############
|
||||||
|
|
||||||
set(trinityconfig_STAT_SRCS
|
set(trinityconfig_STAT_SRCS
|
||||||
Configuration/dotconfpp/dotconfpp.cpp
|
|
||||||
Configuration/dotconfpp/mempool.cpp
|
|
||||||
Configuration/Config.cpp
|
Configuration/Config.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -18,9 +18,31 @@
|
|||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ConfigEnv.h"
|
#include "Config.h"
|
||||||
|
#include <ace/Configuration_Import_Export.h>
|
||||||
|
|
||||||
Config::Config() : mIgnoreCase(true), mConf(NULL)
|
static bool GetValueHelper(ACE_Configuration_Heap *mConf, const char *name, ACE_TString &result)
|
||||||
|
{
|
||||||
|
if (!mConf)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ACE_TString section_name;
|
||||||
|
ACE_Configuration_Section_Key section_key;
|
||||||
|
ACE_Configuration_Section_Key root_key = mConf->root_section();
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
while (mConf->enumerate_sections(root_key, i, section_name) == 0)
|
||||||
|
{
|
||||||
|
mConf->open_section(root_key, section_name.c_str(), 0, section_key);
|
||||||
|
if (mConf->get_string_value(section_key, name, result) == 0)
|
||||||
|
return true;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Config::Config() : mConf(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,50 +51,40 @@ Config::~Config()
|
|||||||
delete mConf;
|
delete mConf;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Config::SetSource(const char *file, bool ignorecase)
|
bool Config::SetSource(const char *file)
|
||||||
{
|
{
|
||||||
mIgnoreCase = ignorecase;
|
|
||||||
mFilename = file;
|
mFilename = file;
|
||||||
|
|
||||||
return Reload();
|
return Reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Config::Reload()
|
bool Config::Reload()
|
||||||
{
|
{
|
||||||
delete mConf;
|
delete mConf;
|
||||||
|
mConf = new ACE_Configuration_Heap;
|
||||||
mConf = new DOTCONFDocument(mIgnoreCase ?
|
if (mConf->open() == 0)
|
||||||
DOTCONFDocument::CASEINSENSETIVE :
|
|
||||||
DOTCONFDocument::CASESENSETIVE);
|
|
||||||
|
|
||||||
if (mConf->setContent(mFilename.c_str()) == -1)
|
|
||||||
{
|
{
|
||||||
delete mConf;
|
ACE_Ini_ImpExp config_importer(*mConf);
|
||||||
mConf = NULL;
|
if (config_importer.import_config(mFilename.c_str()) == 0)
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
delete mConf;
|
||||||
return true;
|
mConf = NULL;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Config::GetStringDefault(const char * name, std::string def)
|
std::string Config::GetStringDefault(const char * name, std::string def)
|
||||||
{
|
{
|
||||||
if(!mConf)
|
ACE_TString val;
|
||||||
return std::string(def);
|
return GetValueHelper(mConf, name, val) ? val.c_str() : def;
|
||||||
const DOTCONFDocumentNode * node = mConf->findNode(name);
|
|
||||||
if(!node || !node->getValue())
|
|
||||||
return std::string(def);
|
|
||||||
return std::string(node->getValue());
|
|
||||||
};
|
};
|
||||||
|
|
||||||
bool Config::GetBoolDefault(const char * name, const bool def)
|
bool Config::GetBoolDefault(const char * name, const bool def)
|
||||||
{
|
{
|
||||||
if(!mConf)
|
ACE_TString val;
|
||||||
return false;
|
if (!GetValueHelper(mConf, name, val))
|
||||||
const DOTCONFDocumentNode * node = mConf->findNode(name);
|
|
||||||
if(!node || !node->getValue())
|
|
||||||
return def;
|
return def;
|
||||||
const char * str = node->getValue();
|
const char* str = val.c_str();
|
||||||
|
|
||||||
if(strcmp(str, "true") == 0 || strcmp(str, "TRUE") == 0 ||
|
if(strcmp(str, "true") == 0 || strcmp(str, "TRUE") == 0 ||
|
||||||
strcmp(str, "yes") == 0 || strcmp(str, "YES") == 0 ||
|
strcmp(str, "yes") == 0 || strcmp(str, "YES") == 0 ||
|
||||||
strcmp(str, "1") == 0)
|
strcmp(str, "1") == 0)
|
||||||
@@ -83,20 +95,12 @@ bool Config::GetBoolDefault(const char * name, const bool def)
|
|||||||
|
|
||||||
int32 Config::GetIntDefault(const char * name, const int32 def)
|
int32 Config::GetIntDefault(const char * name, const int32 def)
|
||||||
{
|
{
|
||||||
if(!mConf)
|
ACE_TString val;
|
||||||
return def;
|
return GetValueHelper(mConf, name, val) ? atoi(val.c_str()) : def;
|
||||||
const DOTCONFDocumentNode * node = mConf->findNode(name);
|
|
||||||
if(!node || !node->getValue())
|
|
||||||
return def;
|
|
||||||
return atoi(node->getValue());
|
|
||||||
};
|
};
|
||||||
|
|
||||||
float Config::GetFloatDefault(const char * name, const float def)
|
float Config::GetFloatDefault(const char * name, const float def)
|
||||||
{
|
{
|
||||||
if(!mConf)
|
ACE_TString val;
|
||||||
return def;
|
return GetValueHelper(mConf, name, val) ? (float)atof(val.c_str()) : def;
|
||||||
const DOTCONFDocumentNode * node = mConf->findNode(name);
|
|
||||||
if(!node || !node->getValue())
|
|
||||||
return def;
|
|
||||||
return atof(node->getValue());
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,10 +21,11 @@
|
|||||||
#ifndef CONFIG_H
|
#ifndef CONFIG_H
|
||||||
#define CONFIG_H
|
#define CONFIG_H
|
||||||
|
|
||||||
|
#include "Common.h"
|
||||||
#include <ace/Singleton.h>
|
#include <ace/Singleton.h>
|
||||||
#include "Define.h"
|
#include "Define.h"
|
||||||
|
|
||||||
class DOTCONFDocument;
|
class ACE_Configuration_Heap;
|
||||||
|
|
||||||
class Config
|
class Config
|
||||||
{
|
{
|
||||||
@@ -33,7 +34,7 @@ class Config
|
|||||||
public:
|
public:
|
||||||
~Config();
|
~Config();
|
||||||
|
|
||||||
bool SetSource(const char *file, bool ignorecase = true);
|
bool SetSource(const char *file);
|
||||||
bool Reload();
|
bool Reload();
|
||||||
|
|
||||||
std::string GetStringDefault(const char * name, std::string def);
|
std::string GetStringDefault(const char * name, std::string def);
|
||||||
@@ -44,8 +45,7 @@ class Config
|
|||||||
std::string GetFilename() const { return mFilename; }
|
std::string GetFilename() const { return mFilename; }
|
||||||
private:
|
private:
|
||||||
std::string mFilename;
|
std::string mFilename;
|
||||||
bool mIgnoreCase;
|
ACE_Configuration_Heap *mConf;
|
||||||
DOTCONFDocument *mConf;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define sConfig (*ACE_Singleton<Config, ACE_Null_Mutex>::instance())
|
#define sConfig (*ACE_Singleton<Config, ACE_Null_Mutex>::instance())
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(CONFIGENVIRONMENT_H)
|
|
||||||
|
|
||||||
#define CONFIGENVIRONMENT_H
|
|
||||||
|
|
||||||
#include "Common.h"
|
|
||||||
#include "dotconfpp/dotconfpp.h"
|
|
||||||
#include "Config.h"
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,137 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="Windows-1252"?>
|
|
||||||
<VisualStudioProject
|
|
||||||
ProjectType="Visual C++"
|
|
||||||
Version="7.10"
|
|
||||||
Name="ConfigLibrary"
|
|
||||||
ProjectGUID="{C849D54F-32A6-4025-95BE-E64D1CF0686E}"
|
|
||||||
Keyword="Win32Proj">
|
|
||||||
<Platforms>
|
|
||||||
<Platform
|
|
||||||
Name="Win32"/>
|
|
||||||
</Platforms>
|
|
||||||
<Configurations>
|
|
||||||
<Configuration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
OutputDirectory="Debug"
|
|
||||||
IntermediateDirectory="Debug"
|
|
||||||
ConfigurationType="4"
|
|
||||||
CharacterSet="2">
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
Optimization="0"
|
|
||||||
AdditionalIncludeDirectories=""
|
|
||||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
|
|
||||||
MinimalRebuild="TRUE"
|
|
||||||
BasicRuntimeChecks="3"
|
|
||||||
RuntimeLibrary="1"
|
|
||||||
UsePrecompiledHeader="0"
|
|
||||||
WarningLevel="3"
|
|
||||||
Detect64BitPortabilityProblems="TRUE"
|
|
||||||
DebugInformationFormat="4"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCCustomBuildTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCLibrarianTool"
|
|
||||||
OutputFile="$(OutDir)/ConfigLibrary.lib"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCMIDLTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPostBuildEventTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreBuildEventTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreLinkEventTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCResourceCompilerTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCWebServiceProxyGeneratorTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCXMLDataGeneratorTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCManagedWrapperGeneratorTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
|
||||||
</Configuration>
|
|
||||||
<Configuration
|
|
||||||
Name="Release|Win32"
|
|
||||||
OutputDirectory="Release"
|
|
||||||
IntermediateDirectory="Release"
|
|
||||||
ConfigurationType="4"
|
|
||||||
CharacterSet="2">
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
AdditionalIncludeDirectories=""
|
|
||||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
|
|
||||||
RuntimeLibrary="0"
|
|
||||||
UsePrecompiledHeader="0"
|
|
||||||
WarningLevel="3"
|
|
||||||
Detect64BitPortabilityProblems="TRUE"
|
|
||||||
DebugInformationFormat="3"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCCustomBuildTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCLibrarianTool"
|
|
||||||
OutputFile="$(OutDir)/ConfigLibrary.lib"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCMIDLTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPostBuildEventTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreBuildEventTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreLinkEventTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCResourceCompilerTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCWebServiceProxyGeneratorTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCXMLDataGeneratorTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCManagedWrapperGeneratorTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
|
||||||
</Configuration>
|
|
||||||
</Configurations>
|
|
||||||
<References>
|
|
||||||
</References>
|
|
||||||
<Files>
|
|
||||||
<Filter
|
|
||||||
Name="Source Files"
|
|
||||||
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
|
||||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
|
|
||||||
<File
|
|
||||||
RelativePath=".\Config.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\dotconfpp\dotconfpp.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\dotconfpp\mempool.cpp">
|
|
||||||
</File>
|
|
||||||
</Filter>
|
|
||||||
<Filter
|
|
||||||
Name="Header Files"
|
|
||||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
|
||||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
|
|
||||||
<File
|
|
||||||
RelativePath=".\Config.h">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\ConfigEnv.h">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\dotconfpp\dotconfpp.h">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\dotconfpp\mempool.h">
|
|
||||||
</File>
|
|
||||||
</Filter>
|
|
||||||
<Filter
|
|
||||||
Name="Resource Files"
|
|
||||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
|
|
||||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
|
|
||||||
</Filter>
|
|
||||||
</Files>
|
|
||||||
<Globals>
|
|
||||||
</Globals>
|
|
||||||
</VisualStudioProject>
|
|
||||||
@@ -1,599 +0,0 @@
|
|||||||
|
|
||||||
#include "Common.h"
|
|
||||||
|
|
||||||
#include "dotconfpp.h"
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#define PATH_MAX _MAX_PATH
|
|
||||||
#define strcasecmp stricmp
|
|
||||||
#define realpath(path,resolved_path) _fullpath(resolved_path, path, _MAX_PATH)
|
|
||||||
#include <io.h>
|
|
||||||
#else
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <strings.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(R_OK)
|
|
||||||
#define R_OK 04
|
|
||||||
#endif
|
|
||||||
|
|
||||||
DOTCONFDocumentNode::DOTCONFDocumentNode():previousNode(NULL), nextNode(NULL), parentNode(NULL), childNode(NULL),
|
|
||||||
values(NULL), valuesCount(0),
|
|
||||||
name(NULL), lineNum(0), fileName(NULL), closed(true)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
DOTCONFDocumentNode::~DOTCONFDocumentNode()
|
|
||||||
{
|
|
||||||
free(name);
|
|
||||||
if(values != NULL){
|
|
||||||
for (int i = 0 ; i < valuesCount; i++){
|
|
||||||
free(values[i]);
|
|
||||||
}
|
|
||||||
free(values);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DOTCONFDocumentNode::pushValue(char * _value)
|
|
||||||
{
|
|
||||||
++valuesCount;
|
|
||||||
values = (char**)realloc(values, valuesCount*sizeof(char*));
|
|
||||||
values[valuesCount-1] = strdup(_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* DOTCONFDocumentNode::getValue(int index) const
|
|
||||||
{
|
|
||||||
if(index >= valuesCount){
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return values[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
DOTCONFDocument::DOTCONFDocument(DOTCONFDocument::CaseSensitive caseSensitivity):
|
|
||||||
mempool(NULL),
|
|
||||||
curParent(NULL), curPrev(NULL), curLine(0), file(NULL), fileName(NULL)
|
|
||||||
{
|
|
||||||
if(caseSensitivity == CASESENSETIVE){
|
|
||||||
cmp_func = strcmp;
|
|
||||||
} else {
|
|
||||||
cmp_func = strcasecmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
mempool = new AsyncDNSMemPool(1024);
|
|
||||||
mempool->initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
DOTCONFDocument::~DOTCONFDocument()
|
|
||||||
{
|
|
||||||
for (std::list<DOTCONFDocumentNode*>::iterator i = nodeTree.begin(); i != nodeTree.end(); ++i){
|
|
||||||
delete(*i);
|
|
||||||
}
|
|
||||||
for (std::list<char*>::iterator i = requiredOptions.begin(); i != requiredOptions.end(); ++i){
|
|
||||||
free(*i);
|
|
||||||
}
|
|
||||||
for (std::list<char*>::iterator i = processedFiles.begin(); i != processedFiles.end(); ++i){
|
|
||||||
free(*i);
|
|
||||||
}
|
|
||||||
free(fileName);
|
|
||||||
delete mempool;
|
|
||||||
}
|
|
||||||
|
|
||||||
int DOTCONFDocument::cleanupLine(char * line)
|
|
||||||
{
|
|
||||||
char * start = line;
|
|
||||||
char * bg = line;
|
|
||||||
bool multiline = false;
|
|
||||||
bool concat = false;
|
|
||||||
char * word = NULL;
|
|
||||||
|
|
||||||
if(!words.empty() && quoted)
|
|
||||||
concat = true;
|
|
||||||
|
|
||||||
while(*line){
|
|
||||||
if((*line == '#' || *line == ';') && !quoted){
|
|
||||||
*bg = 0;
|
|
||||||
if(strlen(start)){
|
|
||||||
|
|
||||||
if(concat){
|
|
||||||
word = (char*)mempool->alloc(strlen(words.back())+strlen(start)+1);
|
|
||||||
strcpy(word, words.back());
|
|
||||||
strcat(word, start);
|
|
||||||
words.pop_back();
|
|
||||||
concat = false;
|
|
||||||
} else {
|
|
||||||
word = mempool->strdup(start);
|
|
||||||
}
|
|
||||||
words.push_back(word);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(*line == '=' && !quoted){
|
|
||||||
*line = ' ';continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allowing \" in there causes problems with directory paths
|
|
||||||
// like "C:\TrinIty\"
|
|
||||||
//if(*line == '\\' && (*(line+1) == '"' || *(line+1) == '\'')){
|
|
||||||
if(*line == '\\' && (*(line+1) == '\'')) {
|
|
||||||
*bg++ = *(line+1);
|
|
||||||
line+=2; continue;
|
|
||||||
}
|
|
||||||
if(*line == '\\' && *(line+1) == 'n'){
|
|
||||||
*bg++ = '\n';
|
|
||||||
line+=2; continue;
|
|
||||||
}
|
|
||||||
if(*line == '\\' && *(line+1) == 'r'){
|
|
||||||
*bg++ = '\r';
|
|
||||||
line+=2; continue;
|
|
||||||
}
|
|
||||||
if(*line == '\\' && (*(line+1) == '\n' || *(line+1) == '\r')){
|
|
||||||
*bg = 0;
|
|
||||||
if(strlen(start)){
|
|
||||||
|
|
||||||
if(concat){
|
|
||||||
word = (char*)mempool->alloc(strlen(words.back())+strlen(start)+1);
|
|
||||||
strcpy(word, words.back());
|
|
||||||
strcat(word, start);
|
|
||||||
words.pop_back();
|
|
||||||
concat = false;
|
|
||||||
} else {
|
|
||||||
word = mempool->strdup(start);
|
|
||||||
}
|
|
||||||
words.push_back(word);
|
|
||||||
}
|
|
||||||
multiline = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(*line == '"' || *line == '\''){
|
|
||||||
quoted = !quoted;
|
|
||||||
++line; continue;
|
|
||||||
}
|
|
||||||
if(isspace((unsigned char)*line) && !quoted){
|
|
||||||
*bg++ = 0;
|
|
||||||
if(strlen(start)){
|
|
||||||
|
|
||||||
if(concat){
|
|
||||||
word = (char*)mempool->alloc(strlen(words.back())+strlen(start)+1);
|
|
||||||
strcpy(word, words.back());
|
|
||||||
strcat(word, start);
|
|
||||||
words.pop_back();
|
|
||||||
concat = false;
|
|
||||||
} else {
|
|
||||||
word = mempool->strdup(start);
|
|
||||||
}
|
|
||||||
words.push_back(word);
|
|
||||||
}
|
|
||||||
start = bg;
|
|
||||||
while(isspace((unsigned char)*++line)) {}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
*bg++ = *line++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(quoted && !multiline){
|
|
||||||
error(curLine, fileName, "unterminated quote");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return multiline?1:0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int DOTCONFDocument::parseLine()
|
|
||||||
{
|
|
||||||
char * word = NULL;
|
|
||||||
char * nodeName = NULL;
|
|
||||||
char * nodeValue = NULL;
|
|
||||||
DOTCONFDocumentNode * tagNode = NULL;
|
|
||||||
bool newNode = false;
|
|
||||||
|
|
||||||
for (std::list<char*>::iterator i = words.begin(); i != words.end(); ++i) {
|
|
||||||
word = *i;
|
|
||||||
|
|
||||||
if(*word == '<'){
|
|
||||||
newNode = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(newNode){
|
|
||||||
nodeValue = NULL;
|
|
||||||
nodeName = NULL;
|
|
||||||
newNode = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t wordLen = strlen(word);
|
|
||||||
if(word[wordLen-1] == '>'){
|
|
||||||
word[wordLen-1] = 0;
|
|
||||||
newNode = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(nodeName == NULL){
|
|
||||||
nodeName = word;
|
|
||||||
bool closed = true;
|
|
||||||
if(*nodeName == '<'){
|
|
||||||
if(*(nodeName+1) != '/'){
|
|
||||||
++nodeName;
|
|
||||||
closed = false;
|
|
||||||
} else {
|
|
||||||
nodeName+=2;
|
|
||||||
std::list<DOTCONFDocumentNode*>::reverse_iterator itr=nodeTree.rbegin();
|
|
||||||
for (; itr!=nodeTree.rend(); ++itr){
|
|
||||||
if(!cmp_func(nodeName, (*itr)->name) && !(*itr)->closed){
|
|
||||||
(*itr)->closed = true;
|
|
||||||
curParent = (*itr)->parentNode;
|
|
||||||
curPrev = *itr;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(itr==nodeTree.rend()){
|
|
||||||
error(curLine, fileName, "not matched closing tag </%s>", nodeName);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tagNode = new DOTCONFDocumentNode;
|
|
||||||
tagNode->name = strdup(nodeName);
|
|
||||||
tagNode->document = this;
|
|
||||||
tagNode->fileName = processedFiles.back();
|
|
||||||
tagNode->lineNum = curLine;
|
|
||||||
tagNode->closed = closed;
|
|
||||||
if(!nodeTree.empty()){
|
|
||||||
DOTCONFDocumentNode * prev = nodeTree.back();
|
|
||||||
if(prev->closed){
|
|
||||||
|
|
||||||
curPrev->nextNode = tagNode;
|
|
||||||
tagNode->previousNode = curPrev;
|
|
||||||
tagNode->parentNode = curParent;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
prev->childNode = tagNode;
|
|
||||||
tagNode->parentNode = prev;
|
|
||||||
curParent = prev;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
nodeTree.push_back(tagNode);
|
|
||||||
curPrev = tagNode;
|
|
||||||
} else {
|
|
||||||
nodeValue = word;
|
|
||||||
tagNode->pushValue(nodeValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int DOTCONFDocument::parseFile(DOTCONFDocumentNode * _parent)
|
|
||||||
{
|
|
||||||
char str[512];
|
|
||||||
int ret = 0;
|
|
||||||
curLine = 0;
|
|
||||||
curParent = _parent;
|
|
||||||
|
|
||||||
quoted = false;
|
|
||||||
size_t slen = 0;
|
|
||||||
|
|
||||||
while(fgets(str, 511, file)){
|
|
||||||
++curLine;
|
|
||||||
slen = strlen(str);
|
|
||||||
if( slen >= 510 ){
|
|
||||||
error(curLine, fileName, "warning: line too long");
|
|
||||||
}
|
|
||||||
if(str[slen-1] != '\n'){
|
|
||||||
str[slen] = '\n';
|
|
||||||
str[slen+1] = 0;
|
|
||||||
}
|
|
||||||
if((ret = cleanupLine(str)) == -1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(ret == 0){
|
|
||||||
if(!words.empty()){
|
|
||||||
ret = parseLine();
|
|
||||||
mempool->free();
|
|
||||||
words.clear();
|
|
||||||
if(ret == -1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int DOTCONFDocument::checkConfig(const std::list<DOTCONFDocumentNode*>::iterator & from)
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
DOTCONFDocumentNode * tagNode = NULL;
|
|
||||||
int vi = 0;
|
|
||||||
for (std::list<DOTCONFDocumentNode*>::iterator i = from; i != nodeTree.end(); ++i){
|
|
||||||
tagNode = *i;
|
|
||||||
if(!tagNode->closed){
|
|
||||||
error(tagNode->lineNum, tagNode->fileName, "unclosed tag %s", tagNode->name);
|
|
||||||
ret = -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
vi = 0;
|
|
||||||
while( vi < tagNode->valuesCount ){
|
|
||||||
|
|
||||||
if(strstr(tagNode->values[vi], "${") && strchr(tagNode->values[vi], '}') ){
|
|
||||||
ret = macroSubstitute(tagNode, vi );
|
|
||||||
mempool->free();
|
|
||||||
if(ret == -1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
++vi;
|
|
||||||
}
|
|
||||||
if(ret == -1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int DOTCONFDocument::setContent(const char * _fileName)
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
char realpathBuf[PATH_MAX];
|
|
||||||
|
|
||||||
if(realpath(_fileName, realpathBuf) == NULL){
|
|
||||||
error(0, NULL, "realpath(%s) failed: %s", _fileName, strerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
fileName = strdup(realpathBuf);
|
|
||||||
|
|
||||||
processedFiles.push_back(strdup(realpathBuf));
|
|
||||||
|
|
||||||
if(( file = fopen(fileName, "r")) == NULL){
|
|
||||||
error(0, NULL, "failed to open file '%s': %s", fileName, strerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
// Try read utf8 header and skip it if exist
|
|
||||||
uint32 utf8header = 0;
|
|
||||||
fgets((char*)&utf8header, 4, file); // Try read header
|
|
||||||
if (utf8header!=0x00BFBBEF) // If not exist
|
|
||||||
fseek(file, 0, SEEK_SET); // Reset read position
|
|
||||||
|
|
||||||
ret = parseFile();
|
|
||||||
|
|
||||||
(void) fclose(file);
|
|
||||||
|
|
||||||
if(!ret){
|
|
||||||
|
|
||||||
if( (ret = checkConfig(nodeTree.begin())) == -1){
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::list<DOTCONFDocumentNode*>::iterator from;
|
|
||||||
DOTCONFDocumentNode * tagNode = NULL;
|
|
||||||
int vi = 0;
|
|
||||||
for (std::list<DOTCONFDocumentNode*>::iterator i = nodeTree.begin(); i!=nodeTree.end(); ++i){
|
|
||||||
tagNode = *i;
|
|
||||||
if(!cmp_func("DOTCONFPPIncludeFile", tagNode->name)){
|
|
||||||
vi = 0;
|
|
||||||
while( vi < tagNode->valuesCount ){
|
|
||||||
if(access(tagNode->values[vi], R_OK) == -1){
|
|
||||||
error(tagNode->lineNum, tagNode->fileName, "%s: %s", tagNode->values[vi], strerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(realpath(tagNode->values[vi], realpathBuf) == NULL){
|
|
||||||
error(tagNode->lineNum, tagNode->fileName, "realpath(%s) failed: %s", tagNode->values[vi], strerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool processed = false;
|
|
||||||
for (std::list<char*>::const_iterator itInode = processedFiles.begin(); itInode != processedFiles.end(); ++itInode){
|
|
||||||
if(!strcmp(*itInode, realpathBuf)){
|
|
||||||
processed = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(processed){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
processedFiles.push_back(strdup(realpathBuf));
|
|
||||||
|
|
||||||
file = fopen(tagNode->values[vi], "r");
|
|
||||||
if(file == NULL){
|
|
||||||
error(tagNode->lineNum, fileName, "failed to open file '%s': %s", tagNode->values[vi], strerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
fileName = strdup(realpathBuf);
|
|
||||||
from = nodeTree.end(); --from;
|
|
||||||
|
|
||||||
ret = parseFile();
|
|
||||||
(void) fclose(file);
|
|
||||||
if(ret == -1)
|
|
||||||
return -1;
|
|
||||||
if(checkConfig(++from) == -1){
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
++vi;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!requiredOptions.empty())
|
|
||||||
ret = checkRequiredOptions();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int DOTCONFDocument::checkRequiredOptions()
|
|
||||||
{
|
|
||||||
for (std::list<char*>::const_iterator ci = requiredOptions.begin(); ci != requiredOptions.end(); ++ci){
|
|
||||||
bool matched = false;
|
|
||||||
for (std::list<DOTCONFDocumentNode*>::iterator i = nodeTree.begin(); i!=nodeTree.end(); ++i){
|
|
||||||
if(!cmp_func((*i)->name, *ci)){
|
|
||||||
matched = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!matched){
|
|
||||||
error(0, NULL, "required option '%s' not specified", *ci);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DOTCONFDocument::error(int lineNum, const char * fileName_, const char * fmt, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
|
|
||||||
size_t len = (lineNum!=0?strlen(fileName_):0) + strlen(fmt) + 50;
|
|
||||||
char * buf = (char*)mempool->alloc(len);
|
|
||||||
|
|
||||||
if(lineNum)
|
|
||||||
(void) snprintf(buf, len, "DOTCONF++: file '%s', line %d: %s\n", fileName_, lineNum, fmt);
|
|
||||||
else
|
|
||||||
(void) snprintf(buf, len, "DOTCONF++: %s\n", fmt);
|
|
||||||
|
|
||||||
(void) vfprintf(stderr, buf, args);
|
|
||||||
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
char * DOTCONFDocument::getSubstitution(char * macro, int lineNum)
|
|
||||||
{
|
|
||||||
char * buf = NULL;
|
|
||||||
char * variable = macro+2;
|
|
||||||
|
|
||||||
char * endBr = strchr(macro, '}');
|
|
||||||
|
|
||||||
if(!endBr){
|
|
||||||
error(lineNum, fileName, "unterminated '{'");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
*endBr = 0;
|
|
||||||
|
|
||||||
char * defaultValue = strchr(variable, ':');
|
|
||||||
|
|
||||||
if(defaultValue){
|
|
||||||
*defaultValue++ = 0;
|
|
||||||
if(*defaultValue != '-'){
|
|
||||||
error(lineNum, fileName, "incorrect macro substitution syntax");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
++defaultValue;
|
|
||||||
if(*defaultValue == '"' || *defaultValue == '\''){
|
|
||||||
++defaultValue;
|
|
||||||
defaultValue[strlen(defaultValue)-1] = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
defaultValue = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
char * subs = getenv(variable);
|
|
||||||
if( subs ){
|
|
||||||
buf = mempool->strdup(subs);
|
|
||||||
} else {
|
|
||||||
std::list<DOTCONFDocumentNode*>::iterator i = nodeTree.begin();
|
|
||||||
DOTCONFDocumentNode * tagNode = NULL;
|
|
||||||
for (; i!=nodeTree.end(); i++){
|
|
||||||
tagNode = *i;
|
|
||||||
if(!cmp_func(tagNode->name, variable)){
|
|
||||||
if(tagNode->valuesCount != 0){
|
|
||||||
buf = mempool->strdup(tagNode->values[0]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( i == nodeTree.end() ){
|
|
||||||
if( defaultValue ){
|
|
||||||
buf = mempool->strdup(defaultValue);
|
|
||||||
} else {
|
|
||||||
error(lineNum, fileName, "substitution not found and default value not given");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
int DOTCONFDocument::macroSubstitute(DOTCONFDocumentNode * tagNode, int valueIndex)
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
char * macro = tagNode->values[valueIndex];
|
|
||||||
size_t valueLen = strlen(tagNode->values[valueIndex])+1;
|
|
||||||
char * value = (char*)mempool->alloc(valueLen);
|
|
||||||
char * v = value;
|
|
||||||
char * subs = NULL;
|
|
||||||
|
|
||||||
while(*macro){
|
|
||||||
if(*macro == '$' && *(macro+1) == '{'){
|
|
||||||
char * m = strchr(macro, '}');
|
|
||||||
subs = getSubstitution(macro, tagNode->lineNum);
|
|
||||||
if(subs == NULL){
|
|
||||||
ret = -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
macro = m + 1;
|
|
||||||
*v = 0;
|
|
||||||
v = (char*)mempool->alloc(strlen(value)+strlen(subs)+valueLen);
|
|
||||||
strcpy(v, value);
|
|
||||||
value = strcat(v, subs);
|
|
||||||
v = value + strlen(value);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
*v++ = *macro++;
|
|
||||||
}
|
|
||||||
*v = 0;
|
|
||||||
|
|
||||||
free(tagNode->values[valueIndex]);
|
|
||||||
tagNode->values[valueIndex] = strdup(value);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
const DOTCONFDocumentNode * DOTCONFDocument::getFirstNode() const
|
|
||||||
{
|
|
||||||
if ( !nodeTree.empty() ) {
|
|
||||||
return *nodeTree.begin();
|
|
||||||
} else {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const DOTCONFDocumentNode * DOTCONFDocument::findNode(const char * nodeName, const DOTCONFDocumentNode * parentNode, const DOTCONFDocumentNode * startNode) const
|
|
||||||
{
|
|
||||||
|
|
||||||
std::list<DOTCONFDocumentNode*>::const_iterator i = nodeTree.begin();
|
|
||||||
|
|
||||||
if(startNode == NULL)
|
|
||||||
startNode = parentNode;
|
|
||||||
|
|
||||||
if(startNode != NULL){
|
|
||||||
while( i != nodeTree.end() && (*i) != startNode ){
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
if( i != nodeTree.end() ) ++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (; i!=nodeTree.end(); ++i){
|
|
||||||
|
|
||||||
if((*i)->parentNode != parentNode){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(!cmp_func(nodeName, (*i)->name)){
|
|
||||||
return *i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DOTCONFDocument::setRequiredOptionNames(const char ** requiredOptionNames)
|
|
||||||
{
|
|
||||||
while(*requiredOptionNames){
|
|
||||||
requiredOptions.push_back(strdup( *requiredOptionNames ));
|
|
||||||
++requiredOptionNames;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
#ifndef DOTCONFPP_H
|
|
||||||
#define DOTCONFPP_H
|
|
||||||
|
|
||||||
#include <list>
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#include "mempool.h"
|
|
||||||
|
|
||||||
class DOTCONFDocument;
|
|
||||||
|
|
||||||
class DOTCONFDocumentNode
|
|
||||||
{
|
|
||||||
friend class DOTCONFDocument;
|
|
||||||
private:
|
|
||||||
DOTCONFDocumentNode * previousNode;
|
|
||||||
DOTCONFDocumentNode * nextNode;
|
|
||||||
DOTCONFDocumentNode * parentNode;
|
|
||||||
DOTCONFDocumentNode * childNode;
|
|
||||||
char ** values;
|
|
||||||
int valuesCount;
|
|
||||||
char * name;
|
|
||||||
const DOTCONFDocument * document;
|
|
||||||
int lineNum;
|
|
||||||
char * fileName;
|
|
||||||
bool closed;
|
|
||||||
|
|
||||||
void pushValue(char * _value);
|
|
||||||
|
|
||||||
public:
|
|
||||||
DOTCONFDocumentNode();
|
|
||||||
~DOTCONFDocumentNode();
|
|
||||||
|
|
||||||
const char * getConfigurationFileName()const { return fileName; }
|
|
||||||
int getConfigurationLineNumber() const { return lineNum; }
|
|
||||||
|
|
||||||
const DOTCONFDocumentNode * getNextNode() const { return nextNode; }
|
|
||||||
const DOTCONFDocumentNode * getPreviuosNode() const { return previousNode; }
|
|
||||||
const DOTCONFDocumentNode * getParentNode() const { return parentNode; }
|
|
||||||
const DOTCONFDocumentNode * getChildNode() const { return childNode; }
|
|
||||||
const char* getValue(int index = 0) const;
|
|
||||||
const char * getName() const { return name; }
|
|
||||||
const DOTCONFDocument * getDocument() const { return document; }
|
|
||||||
};
|
|
||||||
|
|
||||||
class DOTCONFDocument
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum CaseSensitive { CASESENSETIVE, CASEINSENSETIVE };
|
|
||||||
protected:
|
|
||||||
AsyncDNSMemPool * mempool;
|
|
||||||
private:
|
|
||||||
DOTCONFDocumentNode * curParent;
|
|
||||||
DOTCONFDocumentNode * curPrev;
|
|
||||||
int curLine;
|
|
||||||
bool quoted;
|
|
||||||
std::list<DOTCONFDocumentNode*> nodeTree;
|
|
||||||
std::list<char*> requiredOptions;
|
|
||||||
std::list<char*> processedFiles;
|
|
||||||
FILE * file;
|
|
||||||
char * fileName;
|
|
||||||
std::list<char*> words;
|
|
||||||
int (*cmp_func)(const char *, const char *);
|
|
||||||
|
|
||||||
int checkRequiredOptions();
|
|
||||||
int parseLine();
|
|
||||||
int parseFile(DOTCONFDocumentNode * _parent = NULL);
|
|
||||||
int checkConfig(const std::list<DOTCONFDocumentNode*>::iterator & from);
|
|
||||||
int cleanupLine(char * line);
|
|
||||||
char * getSubstitution(char * macro, int lineNum);
|
|
||||||
int macroSubstitute(DOTCONFDocumentNode * tagNode, int valueIndex);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void error(int lineNum, const char * fileName, const char * fmt, ...) ATTR_PRINTF(4,5);
|
|
||||||
|
|
||||||
public:
|
|
||||||
DOTCONFDocument(CaseSensitive caseSensitivity = CASESENSETIVE);
|
|
||||||
virtual ~DOTCONFDocument();
|
|
||||||
|
|
||||||
int setContent(const char * _fileName);
|
|
||||||
|
|
||||||
void setRequiredOptionNames(const char ** requiredOptionNames);
|
|
||||||
const DOTCONFDocumentNode * getFirstNode() const;
|
|
||||||
const DOTCONFDocumentNode * findNode(const char * nodeName, const DOTCONFDocumentNode * parentNode = NULL, const DOTCONFDocumentNode * startNode = NULL) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "mempool.h"
|
|
||||||
|
|
||||||
AsyncDNSMemPool::PoolChunk::PoolChunk(size_t _size):
|
|
||||||
pool(NULL), pos(0), size(_size)
|
|
||||||
{
|
|
||||||
pool = ::malloc(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
AsyncDNSMemPool::PoolChunk::~PoolChunk()
|
|
||||||
{
|
|
||||||
::free(pool);
|
|
||||||
}
|
|
||||||
|
|
||||||
AsyncDNSMemPool::AsyncDNSMemPool(size_t _defaultSize):
|
|
||||||
chunks(NULL), chunksCount(0), defaultSize(_defaultSize),
|
|
||||||
poolUsage(0), poolUsageCounter(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
AsyncDNSMemPool::~AsyncDNSMemPool()
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i<chunksCount; ++i){
|
|
||||||
delete chunks[i];
|
|
||||||
}
|
|
||||||
::free(chunks);
|
|
||||||
}
|
|
||||||
|
|
||||||
int AsyncDNSMemPool::initialize()
|
|
||||||
{
|
|
||||||
chunksCount = 1;
|
|
||||||
chunks = (PoolChunk**)::malloc(sizeof(PoolChunk*));
|
|
||||||
if(chunks == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
chunks[chunksCount-1] = new PoolChunk(defaultSize);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AsyncDNSMemPool::addNewChunk(size_t size)
|
|
||||||
{
|
|
||||||
++chunksCount;
|
|
||||||
chunks = (PoolChunk**)::realloc(chunks, chunksCount*sizeof(PoolChunk*));
|
|
||||||
if(size <= defaultSize)
|
|
||||||
chunks[chunksCount-1] = new PoolChunk(defaultSize);
|
|
||||||
else
|
|
||||||
chunks[chunksCount-1] = new PoolChunk(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void * AsyncDNSMemPool::alloc(size_t size)
|
|
||||||
{
|
|
||||||
PoolChunk * chunk = NULL;
|
|
||||||
for (size_t i = 0; i<chunksCount; ++i){
|
|
||||||
chunk = chunks[i];
|
|
||||||
if((chunk->size - chunk->pos) >= size){
|
|
||||||
chunk->pos += size;
|
|
||||||
return ((char*)chunk->pool) + chunk->pos - size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addNewChunk(size);
|
|
||||||
chunks[chunksCount-1]->pos = size;
|
|
||||||
return chunks[chunksCount-1]->pool;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AsyncDNSMemPool::free()
|
|
||||||
{
|
|
||||||
size_t pu = 0;
|
|
||||||
size_t psz = 0;
|
|
||||||
++poolUsageCounter;
|
|
||||||
|
|
||||||
for (size_t i = 0; i<chunksCount; ++i){
|
|
||||||
pu += chunks[i]->pos;
|
|
||||||
psz += chunks[i]->size;
|
|
||||||
chunks[i]->pos = 0;
|
|
||||||
}
|
|
||||||
poolUsage=(poolUsage>pu)?poolUsage:pu;
|
|
||||||
|
|
||||||
if(poolUsageCounter >= 10 && chunksCount > 1){
|
|
||||||
psz -= chunks[chunksCount-1]->size;
|
|
||||||
if(poolUsage < psz){
|
|
||||||
--chunksCount;
|
|
||||||
delete chunks[chunksCount];
|
|
||||||
}
|
|
||||||
poolUsage = 0;
|
|
||||||
poolUsageCounter = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void * AsyncDNSMemPool::calloc(size_t size)
|
|
||||||
{
|
|
||||||
return ::memset(this->alloc(size), 0, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
char * AsyncDNSMemPool::strdup(const char *str)
|
|
||||||
{
|
|
||||||
return ::strcpy((char*)this->alloc(strlen(str)+1), str);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
#ifndef ASYNC_DNS_MEMPOOL_H
|
|
||||||
#define ASYNC_DNS_MEMPOOL_H
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#undef free
|
|
||||||
#undef calloc
|
|
||||||
#undef strdup
|
|
||||||
|
|
||||||
class AsyncDNSMemPool
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
struct PoolChunk {
|
|
||||||
void * pool;
|
|
||||||
size_t pos;
|
|
||||||
size_t size;
|
|
||||||
|
|
||||||
PoolChunk(size_t _size);
|
|
||||||
~PoolChunk();
|
|
||||||
};
|
|
||||||
PoolChunk ** chunks;
|
|
||||||
size_t chunksCount;
|
|
||||||
size_t defaultSize;
|
|
||||||
|
|
||||||
size_t poolUsage;
|
|
||||||
size_t poolUsageCounter;
|
|
||||||
|
|
||||||
void addNewChunk(size_t size);
|
|
||||||
|
|
||||||
public:
|
|
||||||
AsyncDNSMemPool(size_t _defaultSize = 4096);
|
|
||||||
virtual ~AsyncDNSMemPool();
|
|
||||||
|
|
||||||
int initialize();
|
|
||||||
void free();
|
|
||||||
void * alloc(size_t size);
|
|
||||||
void * calloc(size_t size);
|
|
||||||
char * strdup(const char *str);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "DatabaseEnv.h"
|
#include "DatabaseEnv.h"
|
||||||
#include "Configuration/ConfigEnv.h"
|
#include "Configuration/Config.h"
|
||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "Updates/UpdateFields.h"
|
#include "Updates/UpdateFields.h"
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Configuration/ConfigEnv.h"
|
#include "Configuration/Config.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
#include "ObjectMgr.h"
|
#include "ObjectMgr.h"
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
#include "WorldSession.h"
|
#include "WorldSession.h"
|
||||||
#include "Configuration/ConfigEnv.h"
|
#include "Configuration/Config.h"
|
||||||
|
|
||||||
#include "AccountMgr.h"
|
#include "AccountMgr.h"
|
||||||
#include "Chat.h"
|
#include "Chat.h"
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "Database/DatabaseEnv.h"
|
#include "Database/DatabaseEnv.h"
|
||||||
#include "Configuration/ConfigEnv.h"
|
#include "Configuration/Config.h"
|
||||||
|
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Master.h"
|
#include "Master.h"
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
#include "WorldRunnable.h"
|
#include "WorldRunnable.h"
|
||||||
#include "WorldSocket.h"
|
#include "WorldSocket.h"
|
||||||
#include "WorldSocketMgr.h"
|
#include "WorldSocketMgr.h"
|
||||||
#include "Configuration/ConfigEnv.h"
|
#include "Configuration/Config.h"
|
||||||
#include "Database/DatabaseEnv.h"
|
#include "Database/DatabaseEnv.h"
|
||||||
|
|
||||||
#include "CliRunnable.h"
|
#include "CliRunnable.h"
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "Configuration/ConfigEnv.h"
|
#include "Configuration/Config.h"
|
||||||
#include "Database/DatabaseEnv.h"
|
#include "Database/DatabaseEnv.h"
|
||||||
#include "AccountMgr.h"
|
#include "AccountMgr.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
################################################
|
################################################
|
||||||
# Trinity Core World Server configuration file #
|
# Trinity Core World Server configuration file #
|
||||||
################################################
|
################################################
|
||||||
|
[worldserver]
|
||||||
|
|
||||||
# Note to devs, line breaks should be at column 80
|
# Note to devs, line breaks should be at column 80
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# CONNECTIONS AND DIRECTORIES
|
# CONNECTIONS AND DIRECTORIES
|
||||||
|
|||||||
Reference in New Issue
Block a user