Skip to content

Commit

Permalink
CHANGED: #238 Logon config parser error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
dfighter1985 committed Sep 8, 2012
1 parent 4cb60d7 commit 612ebb5
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
132 changes: 132 additions & 0 deletions src/arcemu-logonserver/LogonConfigParser.cpp
Expand Up @@ -2,24 +2,84 @@
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>

enum LogonConfigError
{
ERR_ALL_OK,
ERR_CANNOT_OPEN_FILE,
ERR_NOT_A_CONFIG_FILE,
ERR_NOT_LOGON_CONFIG,
ERR_WRONG_VERSION,
ERR_DB_NO_HOST,
ERR_DB_NO_USERNAME,
ERR_DB_NO_PASSWORD,
ERR_DB_NO_DB,
ERR_HOST_NO_LOGON_ADDR,
ERR_HOST_NO_LOGON_PORT,
ERR_HOST_NO_IS_ADDR,
ERR_HOST_NO_IS_PORT,
ERR_SEC_NO_PASSWORD,
ERR_SEC_NO_IP,
ERR_SEC_NO_MOD_IP,
ERR_NO_DB_SETTINGS,
ERR_NO_HOST_SETTINGS,
ERR_NO_SECURITY_SETTINGS,
MAX_ERROR
};

const char* errorString[] =
{
"No error.",
"Cannot open file",
"Not a config file",
"Not a logon config file",
"Logon database, hostname couldn't be loaded",
"Logon database, username couldn't be loaded",
"Logon database, password couldn't be loaded",
"Logon database, database name couldn't be loaded",
"Host, logon address couldn't be loaded",
"Host, logon port couldn't be loaded",
"Host, interserver address couldn't be loaded",
"Host, interserver port couldn't be loaded",
"Security, remote password couldn't be loaded",
"Security, allowed ip ranges couldn't be loaded",
"Security, allowed mod ip ranges couldn't be loaded",
"Database connection settings couldn't be loaded",
"Host settings couldn't be loaded",
"Security settings couldn't be loaded",
"Wrong version"
};

LogonConfigParser::LogonConfigParser()
{
lastError = ERR_ALL_OK;
dbPartDone = false;
hostPartDone = false;
securityPartDone = false;
}

LogonConfigParser::~LogonConfigParser()
{
}

const char* LogonConfigParser::getLastError() const
{
return errorString[ lastError ];
}

bool LogonConfigParser::parseFile( const std::string &name )
{
xmlDocPtr document = xmlParseFile( name.c_str() );
if( document == NULL )
{
lastError = ERR_CANNOT_OPEN_FILE;
return false;
}

xmlNodePtr root = xmlDocGetRootElement( document );
if( root == NULL )
{
xmlFreeDoc( document );
lastError = ERR_NOT_A_CONFIG_FILE;
return false;
}

Expand Down Expand Up @@ -56,6 +116,27 @@ bool LogonConfigParser::parseFile( const std::string &name )
}

xmlFreeDoc( document );

if( !ok )
return false;

if( !dbPartDone )
{
lastError = ERR_NO_DB_SETTINGS;
ok = false;
}
else
if( !hostPartDone )
{
lastError = ERR_NO_HOST_SETTINGS;
ok = false;
}
else
if( !securityPartDone )
{
lastError = ERR_NO_SECURITY_SETTINGS;
ok = false;
}

if( !ok )
return false;
Expand All @@ -66,21 +147,36 @@ bool LogonConfigParser::parseFile( const std::string &name )
bool LogonConfigParser::isConfig( _xmlNode *node )
{
if( xmlStrcmp( node->name, BAD_CAST "config" ) != 0 )
{
lastError = ERR_NOT_A_CONFIG_FILE;
return false;
}

xmlChar *prop = NULL;

prop = xmlGetProp( node, BAD_CAST "type" );
if( prop == NULL )
{
lastError = ERR_NOT_A_CONFIG_FILE;
return false;
}
if( xmlStrcmp( prop, BAD_CAST "logon" ) != 0 )
{
lastError = ERR_NOT_LOGON_CONFIG;
return false;
}

prop = xmlGetProp( node, BAD_CAST "version" );
if( prop == NULL )
{
lastError = ERR_NOT_A_CONFIG_FILE;
return false;
}
if( xmlStrcmp( prop, BAD_CAST requiredVersion.c_str() ) )
{
lastError = ERR_WRONG_VERSION;
return false;
}

return true;
}
Expand All @@ -91,22 +187,34 @@ bool LogonConfigParser::parseDBPart( _xmlNode *node )

prop = xmlGetProp( node, BAD_CAST "hostname" );
if( prop == NULL )
{
lastError = ERR_DB_NO_HOST;
return false;
}
data.logondb.host = reinterpret_cast< char* >( prop );

prop = xmlGetProp( node, BAD_CAST "username" );
if( prop == NULL )
{
lastError = ERR_DB_NO_USERNAME;
return false;
}
data.logondb.username = reinterpret_cast< char* >( prop );

prop = xmlGetProp( node, BAD_CAST "password" );
if( prop == NULL )
{
lastError = ERR_DB_NO_PASSWORD;
return false;
}
data.logondb.password = reinterpret_cast< char* >( prop );

prop = xmlGetProp( node, BAD_CAST "database" );
if( prop == NULL )
{
lastError = ERR_DB_NO_DB;
return false;
}
data.logondb.database = reinterpret_cast< char* >( prop );

prop = xmlGetProp( node, BAD_CAST "port" );
Expand All @@ -115,6 +223,7 @@ bool LogonConfigParser::parseDBPart( _xmlNode *node )
else
data.logondb.port = static_cast< unsigned int >( atoi( reinterpret_cast< char* >( prop ) ) );

dbPartDone = true;
return true;
}

Expand All @@ -124,24 +233,37 @@ bool LogonConfigParser::parseHostPart( _xmlNode *node )

prop = xmlGetProp( node, BAD_CAST "logon_address" );
if( prop == NULL )
{
lastError = ERR_HOST_NO_LOGON_ADDR;
return false;
}
data.host.logon_address = reinterpret_cast< char* >( prop );

prop = xmlGetProp( node, BAD_CAST "logon_port" );
if( prop == NULL )
{
lastError = ERR_HOST_NO_LOGON_PORT;
return false;
}
data.host.logon_port = static_cast< unsigned int >( atoi( reinterpret_cast< char* >( prop ) ) );

prop = xmlGetProp( node, BAD_CAST "is_address" );
if( prop == NULL )
{
lastError = ERR_HOST_NO_IS_ADDR;
return false;
}
data.host.is_address = reinterpret_cast< char* >( prop );

prop = xmlGetProp( node, BAD_CAST "is_port" );
if( prop == NULL )
{
lastError = ERR_HOST_NO_IS_PORT;
return false;
}
data.host.is_port = static_cast< unsigned int >( atoi( reinterpret_cast< char* >( prop ) ) );

hostPartDone = false;
return true;
}

Expand Down Expand Up @@ -173,19 +295,29 @@ bool LogonConfigParser::parseSecurityPart( _xmlNode *node )

prop = xmlGetProp( node, BAD_CAST "remote_password" );
if( prop == NULL )
{
lastError = ERR_SEC_NO_PASSWORD;
return false;
}
data.security.remote_password = reinterpret_cast< char* >( prop );

prop = xmlGetProp( node, BAD_CAST "allowed_ip_ranges" );
if( prop == NULL )
{
lastError = ERR_SEC_NO_IP;
return false;
}
data.security.allowed_ip_ranges = reinterpret_cast< char* >( prop );

prop = xmlGetProp( node, BAD_CAST "allowed_mod_ip_ranges" );
if( prop == NULL )
{
lastError = ERR_SEC_NO_MOD_IP;
return false;
}
data.security.allowed_mod_ip_ranges = reinterpret_cast< char* >( prop );

securityPartDone = true;
return true;
}

6 changes: 6 additions & 0 deletions src/arcemu-logonserver/LogonConfigParser.h
Expand Up @@ -14,6 +14,7 @@ class LogonConfigParser
bool parseFile( const std::string &name );
const LogonConfigData& getData() const{ return data; }
void setRequiredVersion( const std::string &s ){ requiredVersion = s; }
const char* getLastError() const;

private:
bool isConfig( _xmlNode *node );
Expand All @@ -25,6 +26,11 @@ class LogonConfigParser

LogonConfigData data;
std::string requiredVersion;
unsigned long lastError;

bool dbPartDone;
bool hostPartDone;
bool securityPartDone;
};

#endif
Expand Down
4 changes: 4 additions & 0 deletions src/arcemu-logonserver/Main.cpp
Expand Up @@ -170,6 +170,7 @@ bool rehash2()
if( !configParser.parseFile( config_file ) )
{
LOG_ERROR("Config file could not be loaded.");
LOG_ERROR("ERROR: %s",configParser.getLastError() );
return false;
}
configFile = configParser.getData();
Expand Down Expand Up @@ -306,7 +307,10 @@ void LogonServer::Run(int argc, char** argv)
if( parser.parseFile( "configs/logon.conf.xml" ) )
LOG_BASIC(" Passed without errors.");
else
{
LOG_BASIC(" Encountered one or more errors.");
LOG_BASIC("ERROR: %s", parser.getLastError() );
}

sLog.Close();
return;
Expand Down

0 comments on commit 612ebb5

Please sign in to comment.