From 633a6e2df9fbdfee6768c53784df441b7191a080 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 16 Jul 2015 16:53:30 -0400 Subject: [PATCH 1/2] use zmDbFetchOne more --- src/zm_config.cpp | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/src/zm_config.cpp b/src/zm_config.cpp index e9c54b943..5521b5a14 100644 --- a/src/zm_config.cpp +++ b/src/zm_config.cpp @@ -115,7 +115,6 @@ void zmLoadConfig() if ( ! staticConfig.SERVER_ID ) { if ( ! staticConfig.SERVER_NAME.empty() ) { - std::string sql = stringtf("SELECT Id FROM Servers WHERE Name='%s'", staticConfig.SERVER_NAME.c_str() ); if ( MYSQL_ROW dbrow = zmDbFetchOne( sql.c_str() ) ) { staticConfig.SERVER_ID = atoi(dbrow[0]); @@ -126,30 +125,12 @@ void zmLoadConfig() } // end if has SERVER_NAME } else if ( staticConfig.SERVER_NAME.empty() ) { 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 ) ) - { + if ( MYSQL_ROW dbrow = zmDbFetchOne( sql.c_str() ) ) { staticConfig.SERVER_NAME = std::string(dbrow[0]); + } else { + Fatal("Can't get ServerName for Server ID %d", staticConfig.SERVER_ID ); } - mysql_free_result( result ); } } From 441a82e611e73c4e5da899093a0fee1e85772550 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 17 Jul 2015 10:12:44 -0400 Subject: [PATCH 2/2] fixup loading SERVER_ID from SERVER_NAME --- web/includes/config.php.in | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/web/includes/config.php.in b/web/includes/config.php.in index 7fdba34a7..efe9d2bce 100644 --- a/web/includes/config.php.in +++ b/web/includes/config.php.in @@ -167,13 +167,22 @@ function loadConfig( $defineConsts=true ) } // For Human-readability, user ZM_SERVER in zm.conf, and convert it here to a ZM_SERVER_ID -if ( ! defined(ZM_SERVER_ID) and defined(ZM_SERVER) ) { - $server_id = dbFetchOne('SELECT Id FROM Servers WHERE Name=?', 'Id', array(ZM_SERVER_NAME)); - if ( ! $server_id ) { - Error("ZM_SERVER_NAME set in config, but not found in Servers table."); - } else { - define( ZM_SERVER_ID, $server_id ); - } +if ( ! defined('ZM_SERVER_ID') ) { + if ( defined('ZM_SERVER_NAME') ) { + $server_id = dbFetchOne('SELECT Id FROM Servers WHERE Name=?', 'Id', array(ZM_SERVER_NAME)); + if ( ! $server_id ) { + Error("ZM_SERVER_NAME set in config, but not found in Servers table."); + } else { + define( 'ZM_SERVER_ID', $server_id ); + } + } else if ( defined('ZM_SERVER_HOST') ) { + $server_id = dbFetchOne('SELECT Id FROM Servers WHERE Name=?', 'Id', array(ZM_SERVER_HOST)); + if ( ! $server_id ) { + Error("ZM_SERVER_HOST set in config, but not found in Servers table."); + } else { + define( 'ZM_SERVER_ID', $server_id ); + } + } }