given SERVER_NAME populate SERVER_ID and vice versa
This commit is contained in:
parent
ca9a391d62
commit
3481368574
|
@ -91,17 +91,82 @@ void zmLoadConfig()
|
|||
staticConfig.DB_PASS = std::string(val_ptr);
|
||||
else if ( strcasecmp( name_ptr, "ZM_PATH_WEB" ) == 0 )
|
||||
staticConfig.PATH_WEB = std::string(val_ptr);
|
||||
else if ( strcasecmp( name_ptr, "ZM_SERVER_HOST" ) == 0 )
|
||||
staticConfig.SERVER_NAME = std::string(val_ptr);
|
||||
else if ( strcasecmp( name_ptr, "ZM_SERVER_NAME" ) == 0 )
|
||||
staticConfig.SERVER_NAME = std::string(val_ptr);
|
||||
else if ( strcasecmp( name_ptr, "ZM_SERVER_ID" ) == 0 )
|
||||
staticConfig.SERVER_ID = atoi(val_ptr);
|
||||
else
|
||||
{
|
||||
// We ignore this now as there may be more parameters than the
|
||||
// c/c++ binaries are bothered about
|
||||
// Warning( "Invalid parameter '%s' in %s", name_ptr, ZM_CONFIG );
|
||||
}
|
||||
}
|
||||
fclose( cfg);
|
||||
} // end foreach line of the config
|
||||
fclose( cfg );
|
||||
zmDbConnect();
|
||||
config.Load();
|
||||
config.Assign();
|
||||
|
||||
// Populate the server config entries
|
||||
if ( ! staticConfig.SERVER_ID ) {
|
||||
if ( staticConfig.SERVER_NAME && ! staticConfig.SERVER_NAME.empty() ) {
|
||||
|
||||
std::string sql = stringtf("SELECT Id FROM Servers WHERE Name='%s'", staticConfig.SERVER_NAME );
|
||||
if ( mysql_query( &dbconn, sql.c_str() ) )
|
||||
{
|
||||
Error( "Can't run query: %s", mysql_error( &dbconn ) );
|
||||
Fatal("Can't get ServerId for Server %s", staticConfig.SERVER_NAME );
|
||||
}
|
||||
MYSQL_RES *result = mysql_store_result( &dbconn );
|
||||
if ( !result )
|
||||
{
|
||||
Error( "Can't use query result: %s", mysql_error( &dbconn ) );
|
||||
Fatal("Can't get ServerId for Server %s", staticConfig.SERVER_NAME );
|
||||
}
|
||||
int n_rows = mysql_num_rows( result );
|
||||
if ( n_rows != 1 )
|
||||
{
|
||||
Error( "Bogus number of lines return from Server lookup, %d, returned. Can't reload", n_rows );
|
||||
Fatal("Can't get ServerId for Server %s", staticConfig.SERVER_NAME );
|
||||
}
|
||||
|
||||
if ( MYSQL_ROW dbrow = mysql_fetch_row( result ) )
|
||||
{
|
||||
staticConfig.SERVER_ID = atoi(dbrow[0]);
|
||||
}
|
||||
mysql_free_result( result );
|
||||
|
||||
} // end if has SERVER_NAME
|
||||
} else if ( ! staticConfig.SERVER_NAME ) {
|
||||
std::string sql = stringtf("SELECT Name FROM Servers WHERE Id='%d'", staticConfig.SERVER_ID );
|
||||
if ( mysql_query( &dbconn, sql.c_str() ) )
|
||||
{
|
||||
Error( "Can't run query: %s", mysql_error( &dbconn ) );
|
||||
Fatal("Can't get ServerName for Server ID %d", staticConfig.SERVER_ID );
|
||||
}
|
||||
|
||||
MYSQL_RES *result = mysql_store_result( &dbconn );
|
||||
if ( !result )
|
||||
{
|
||||
Error( "Can't use query result: %s", mysql_error( &dbconn ) );
|
||||
Fatal("Can't get ServerName for Server ID %d", staticConfig.SERVER_ID );
|
||||
}
|
||||
int n_rows = mysql_num_rows( result );
|
||||
if ( n_rows != 1 )
|
||||
{
|
||||
Error( "Bogus number of lines return from Server lookup, %d, returned. Can't reload", n_rows );
|
||||
Fatal("Can't get ServerName for Server ID %d", staticConfig.SERVER_ID );
|
||||
}
|
||||
|
||||
if ( MYSQL_ROW dbrow = mysql_fetch_row( result ) )
|
||||
{
|
||||
staticConfig.SERVER_NAME = std::string(dbrow[0]);
|
||||
}
|
||||
mysql_free_result( result );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
StaticConfig staticConfig;
|
||||
|
|
Loading…
Reference in New Issue