Pass parameters as const ref to server_alloc

This commit is contained in:
Markus Mäkelä 2019-05-08 16:33:38 +03:00
parent d203e7af83
commit 50b5fe76ef
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
7 changed files with 44 additions and 44 deletions

View File

@ -4018,7 +4018,7 @@ int create_new_server(CONFIG_CONTEXT* obj)
return 1;
}
if (Server* server = Server::server_alloc(obj->name(), &obj->m_parameters))
if (Server* server = Server::server_alloc(obj->name(), obj->m_parameters))
{
auto disk_space_threshold = obj->m_parameters.get_string(CN_DISK_SPACE_THRESHOLD);
if (!server->set_disk_space_threshold(disk_space_threshold))

View File

@ -359,7 +359,7 @@ bool runtime_create_server(const char* name,
parameters.set(CN_AUTHENTICATOR, authenticator);
}
Server* server = Server::server_alloc(name, &parameters);
Server* server = Server::server_alloc(name, parameters);
if (server && (!external || server->serialize()))
{

View File

@ -153,7 +153,7 @@ public:
*
* @return The newly created server or NULL if an error occurred
*/
static Server* server_alloc(const char* name, MXS_CONFIG_PARAMETER* params);
static Server* server_alloc(const char* name, const MXS_CONFIG_PARAMETER& params);
/**
* Creates a server without any configuration. This should be used in unit tests in place of
@ -374,9 +374,9 @@ private:
char m_version_str[MAX_VERSION_LEN + 1] = {'\0'};/**< Server version string */
};
const std::string m_name; /**< Server config name */
Settings m_settings; /**< Server settings */
VersionInfo m_info; /**< Server version and type information */
const std::string m_name; /**< Server config name */
Settings m_settings; /**< Server settings */
VersionInfo m_info; /**< Server version and type information */
void* m_auth_instance = nullptr; /**< Authenticator instance data */
void* m_auth_instance = nullptr; /**< Authenticator instance data */
};

View File

@ -154,10 +154,10 @@ void careful_strcpy(char* dest, size_t max_len, const std::string& source)
}
}
Server* Server::server_alloc(const char* name, MXS_CONFIG_PARAMETER* params)
Server* Server::server_alloc(const char* name, const MXS_CONFIG_PARAMETER& params)
{
auto monuser = params->get_string(CN_MONITORUSER);
auto monpw = params->get_string(CN_MONITORPW);
auto monuser = params.get_string(CN_MONITORUSER);
auto monpw = params.get_string(CN_MONITORPW);
const char one_defined_err[] = "'%s is defined for server '%s', '%s' must also be defined.";
if (!monuser.empty() && monpw.empty())
@ -171,8 +171,8 @@ Server* Server::server_alloc(const char* name, MXS_CONFIG_PARAMETER* params)
return NULL;
}
auto protocol = params->get_string(CN_PROTOCOL);
auto authenticator = params->get_string(CN_AUTHENTICATOR);
auto protocol = params.get_string(CN_PROTOCOL);
auto authenticator = params.get_string(CN_AUTHENTICATOR);
if (authenticator.empty())
{
@ -197,7 +197,7 @@ Server* Server::server_alloc(const char* name, MXS_CONFIG_PARAMETER* params)
SSL_LISTENER* ssl = NULL;
if (!config_create_ssl(name, *params, false, &ssl))
if (!config_create_ssl(name, params, false, &ssl))
{
MXS_ERROR("Unable to initialize SSL for server '%s'", name);
return NULL;
@ -214,8 +214,8 @@ Server* Server::server_alloc(const char* name, MXS_CONFIG_PARAMETER* params)
return NULL;
}
auto address = params->contains(CN_ADDRESS) ?
params->get_string(CN_ADDRESS) : params->get_string(CN_SOCKET);
auto address = params.contains(CN_ADDRESS) ?
params.get_string(CN_ADDRESS) : params.get_string(CN_SOCKET);
careful_strcpy(server->address, MAX_ADDRESS_LEN, address.c_str());
if (address.length() > MAX_ADDRESS_LEN)
@ -224,18 +224,18 @@ Server* Server::server_alloc(const char* name, MXS_CONFIG_PARAMETER* params)
address.c_str(), MAX_ADDRESS_LEN);
}
server->port = params->get_integer(CN_PORT);
server->extra_port = params->get_integer(CN_EXTRA_PORT);
server->m_settings.persistpoolmax = params->get_integer(CN_PERSISTPOOLMAX);
server->m_settings.persistmaxtime = params->get_duration<std::chrono::seconds>(CN_PERSISTMAXTIME).count();
server->proxy_protocol = params->get_bool(CN_PROXY_PROTOCOL);
server->port = params.get_integer(CN_PORT);
server->extra_port = params.get_integer(CN_EXTRA_PORT);
server->m_settings.persistpoolmax = params.get_integer(CN_PERSISTPOOLMAX);
server->m_settings.persistmaxtime = params.get_duration<std::chrono::seconds>(CN_PERSISTMAXTIME).count();
server->proxy_protocol = params.get_bool(CN_PROXY_PROTOCOL);
server->is_active = true;
server->m_auth_instance = auth_instance;
server->server_ssl = ssl;
server->persistent = persistent;
server->last_event = SERVER_UP_EVENT;
server->status = SERVER_RUNNING;
server->m_settings.rank = params->get_enum(CN_RANK, rank_values);
server->m_settings.rank = params.get_enum(CN_RANK, rank_values);
mxb_assert(server->m_settings.rank > 0);
if (!monuser.empty())
@ -245,8 +245,8 @@ Server* Server::server_alloc(const char* name, MXS_CONFIG_PARAMETER* params)
server->set_monitor_password(monpw);
}
server->m_settings.all_parameters = *params;
for (auto p : *params)
server->m_settings.all_parameters = params;
for (auto p : params)
{
const string& param_name = p.first;
const string& param_value = p.second;

View File

@ -55,7 +55,7 @@ static int test1()
/* Server tests */
fprintf(stderr, "testserver : creating server called MyServer");
Server* server = Server::server_alloc("uniquename", params);
Server* server = Server::server_alloc("uniquename", *params);
mxb_assert_message(server, "Allocating the server should not fail");
fprintf(stderr, "\t..done\nTest Parameter for Server.");
@ -109,7 +109,7 @@ bool test_load_config(const char* input, Server* server)
TEST(param->get_string("authenticator") == server->get_authenticator(),
"Server authenticators differ");
TEST(param->get_integer("port") == server->port, "Server ports differ");
TEST(Server::server_alloc(obj->name(), &obj->m_parameters),
TEST(Server::server_alloc(obj->name(), obj->m_parameters),
"Failed to create server from loaded config");
duplicate_context_finish(&dcontext);
config_context_free(obj);
@ -126,7 +126,7 @@ bool test_serialize()
char old_config_name[] = "serialized-server.cnf.old";
char* persist_dir = MXS_STRDUP_A("./");
set_config_persistdir(persist_dir);
Server* server = Server::server_alloc(name, params);
Server* server = Server::server_alloc(name, *params);
TEST(server, "Server allocation failed");
/** Make sure the files don't exist */
@ -169,11 +169,11 @@ int main(int argc, char** argv)
load_module("HTTPD", MODULE_PROTOCOL);
params->set_from_list({
{"address", "127.0.0.1"},
{"port", "9876"},
{"protocol", "HTTPD"},
{"authenticator", "NullAuthAllow"}
}, config_server_params);
{"address", "127.0.0.1"},
{"port", "9876"},
{"protocol", "HTTPD"},
{"authenticator", "NullAuthAllow"}
}, config_server_params);
int result = 0;
result += test1();

View File

@ -69,11 +69,11 @@ static json_t* diagnostics_json(const MXS_ROUTER* instance);
static void clientReply(MXS_ROUTER* instance,
MXS_ROUTER_SESSION* router_session,
GWBUF* queue,
DCB* backend_dcb);
DCB* backend_dcb);
static void errorReply(MXS_ROUTER* instance,
MXS_ROUTER_SESSION* router_session,
GWBUF* message,
DCB* backend_dcb,
DCB* backend_dcb,
mxs_error_action_t action,
bool* succp);
@ -807,13 +807,13 @@ static MXS_ROUTER* createInstance(SERVICE* service, MXS_CONFIG_PARAMETER* params
extern const MXS_MODULE_PARAM config_server_params[];
MXS_CONFIG_PARAMETER params;
params.set_from_list({
{"address", "_none_"},
{"port", "3306"},
{"protocol", "mariadbbackend"},
{"authenticator", "MySQLBackendAuth"}
}, config_server_params);
{"address", "_none_"},
{"port", "3306"},
{"protocol", "mariadbbackend"},
{"authenticator", "MySQLBackendAuth"}
}, config_server_params);
Server* server = Server::server_alloc("binlog_router_master_host", &params);
Server* server = Server::server_alloc("binlog_router_master_host", params);
if (server == NULL)
{
@ -2326,7 +2326,7 @@ static json_t* diagnostics_json(const MXS_ROUTER* router)
static void clientReply(MXS_ROUTER* instance,
MXS_ROUTER_SESSION* router_session,
GWBUF* queue,
DCB* backend_dcb)
DCB* backend_dcb)
{
ROUTER_INSTANCE* router = (ROUTER_INSTANCE*)instance;
@ -2372,7 +2372,7 @@ static char* extract_message(GWBUF* errpkt)
static void errorReply(MXS_ROUTER* instance,
MXS_ROUTER_SESSION* router_session,
GWBUF* message,
DCB* backend_dcb,
DCB* backend_dcb,
mxs_error_action_t action,
bool* succp)
{
@ -2686,8 +2686,8 @@ int blr_ping(ROUTER_INSTANCE* router, ROUTER_SLAVE* slave, GWBUF* queue)
*
*/
int blr_send_custom_error(DCB* dcb,
int packet_number,
int affected_rows,
int packet_number,
int affected_rows,
const char* msg,
const char* statemsg,
unsigned int errcode)

View File

@ -146,7 +146,7 @@ int main(int argc, char** argv)
{"authenticator", "MySQLBackendAuth"}
}, config_server_params);
Server* server = Server::server_alloc("binlog_router_master_host", &params);
Server* server = Server::server_alloc("binlog_router_master_host", params);
if (server == NULL)
{
printf("Failed to allocate 'server' object\n");