From 383f5304d92ea489bc44d77736c231f1ebfdbe26 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Wed, 12 Dec 2018 18:45:17 +0200 Subject: [PATCH] MXS-2220 Use private Server class in config_runtime Required for further changes. --- server/core/config_runtime.cc | 31 +++++++++++++------------- server/core/internal/config_runtime.hh | 12 +++++----- server/core/resource.cc | 4 ++-- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/server/core/config_runtime.cc b/server/core/config_runtime.cc index 6a705a7a5..b30147841 100644 --- a/server/core/config_runtime.cc +++ b/server/core/config_runtime.cc @@ -131,7 +131,7 @@ static std::pair load_defaults(const char* name, return {rval, params}; } -bool runtime_link_server(SERVER* server, const char* target) +bool runtime_link_server(Server* server, const char* target) { std::lock_guard guard(crt_lock); @@ -175,7 +175,7 @@ bool runtime_link_server(SERVER* server, const char* target) return rval; } -bool runtime_unlink_server(SERVER* server, const char* target) +bool runtime_unlink_server(Server* server, const char* target) { std::lock_guard guard(crt_lock); @@ -272,7 +272,7 @@ bool runtime_create_server(const char* name, return rval; } -bool runtime_destroy_server(SERVER* server) +bool runtime_destroy_server(Server* server) { std::lock_guard guard(crt_lock); bool rval = false; @@ -358,7 +358,7 @@ static SSL_LISTENER* create_ssl(const char* name, return rval; } -bool runtime_enable_server_ssl(SERVER* server, +bool runtime_enable_server_ssl(Server* server, const char* key, const char* cert, const char* ca, @@ -1626,7 +1626,7 @@ static bool service_to_filter_relation_is_valid(const std::string& type, const s return type == CN_FILTERS && filter_find(value.c_str()); } -static bool unlink_server_from_objects(SERVER* server, StringSet& relations) +static bool unlink_server_from_objects(Server* server, StringSet& relations) { bool rval = true; @@ -1641,7 +1641,7 @@ static bool unlink_server_from_objects(SERVER* server, StringSet& relations) return rval; } -static bool link_server_to_objects(SERVER* server, StringSet& relations) +static bool link_server_to_objects(Server* server, StringSet& relations) { bool rval = true; @@ -1735,7 +1735,7 @@ static bool validate_ssl_json(json_t* params, object_type type) return rval; } -static bool process_ssl_parameters(SERVER* server, json_t* params) +static bool process_ssl_parameters(Server* server, json_t* params) { mxb_assert(server->server_ssl == NULL); bool rval = true; @@ -1785,9 +1785,9 @@ static bool process_ssl_parameters(SERVER* server, json_t* params) return rval; } -SERVER* runtime_create_server_from_json(json_t* json) +Server* runtime_create_server_from_json(json_t* json) { - SERVER* rval = NULL; + Server* rval = NULL; if (is_valid_resource_body(json) && server_contains_required_fields(json)) @@ -1812,12 +1812,11 @@ SERVER* runtime_create_server_from_json(json_t* json) { if (runtime_create_server(name, address, port.c_str(), protocol, authenticator)) { - rval = server_find_by_unique_name(name); + rval = Server::find_by_unique_name(name); mxb_assert(rval); json_t* param = mxs_json_pointer(json, MXS_JSON_PTR_PARAMETERS); - if (!process_ssl_parameters(rval, param) - || !link_server_to_objects(rval, relations)) + if (!process_ssl_parameters(rval, param) || !link_server_to_objects(rval, relations)) { runtime_destroy_server(rval); rval = NULL; @@ -1833,7 +1832,7 @@ SERVER* runtime_create_server_from_json(json_t* json) return rval; } -bool server_to_object_relations(SERVER* server, json_t* old_json, json_t* new_json) +bool server_to_object_relations(Server* server, json_t* old_json, json_t* new_json) { if (mxs_json_pointer(new_json, MXS_JSON_PTR_RELATIONSHIPS_SERVICES) == NULL && mxs_json_pointer(new_json, MXS_JSON_PTR_RELATIONSHIPS_MONITORS) == NULL) @@ -1961,7 +1960,7 @@ static bool is_valid_relationship_body(json_t* json) return rval; } -bool runtime_alter_server_relationships_from_json(SERVER* server, const char* type, json_t* json) +bool runtime_alter_server_relationships_from_json(Server* server, const char* type, json_t* json) { bool rval = false; std::unique_ptr old_json(server_to_json(server, "")); @@ -2076,7 +2075,7 @@ static bool unlink_object_from_servers(const char* target, StringSet& relations) for (StringSet::iterator it = relations.begin(); it != relations.end(); it++) { - SERVER* server = server_find_by_unique_name(it->c_str()); + auto server = Server::find_by_unique_name(*it); if (!server || !runtime_unlink_server(server, target)) { @@ -2094,7 +2093,7 @@ static bool link_object_to_servers(const char* target, StringSet& relations) for (StringSet::iterator it = relations.begin(); it != relations.end(); it++) { - SERVER* server = server_find_by_unique_name(it->c_str()); + auto server = Server::find_by_unique_name(*it); if (!server || !runtime_link_server(server, target)) { diff --git a/server/core/internal/config_runtime.hh b/server/core/internal/config_runtime.hh index baec116a7..908bd6afe 100644 --- a/server/core/internal/config_runtime.hh +++ b/server/core/internal/config_runtime.hh @@ -68,7 +68,7 @@ bool runtime_create_server(const char* name, * @param server Server to destroy * @return True if server was destroyed */ -bool runtime_destroy_server(SERVER* server); +bool runtime_destroy_server(Server* server); /** * @brief Link a server to an object @@ -81,7 +81,7 @@ bool runtime_destroy_server(SERVER* server); * @return True if the object was found and the server was linked to it, false * if no object matching @c target was found */ -bool runtime_link_server(SERVER* server, const char* target); +bool runtime_link_server(Server* server, const char* target); /** * @brief Unlink a server from an object @@ -94,7 +94,7 @@ bool runtime_link_server(SERVER* server, const char* target); * @return True if the object was found and the server was unlinked from it, false * if no object matching @c target was found */ -bool runtime_unlink_server(SERVER* server, const char* target); +bool runtime_unlink_server(Server* server, const char* target); /** * @brief Alter server parameters @@ -124,7 +124,7 @@ bool runtime_alter_server(Server* server, const char* key, const char* value); * * @return True if SSL was successfully enabled */ -bool runtime_enable_server_ssl(SERVER* server, +bool runtime_enable_server_ssl(Server* server, const char* key, const char* cert, const char* ca, @@ -271,7 +271,7 @@ bool runtime_destroy_service(Service* service); * * @return Created server or NULL on error */ -SERVER* runtime_create_server_from_json(json_t* json); +Server* runtime_create_server_from_json(json_t* json); /** * @brief Alter a server using JSON @@ -292,7 +292,7 @@ bool runtime_alter_server_from_json(Server* server, json_t* new_json); * * @return True if the relationships were successfully modified */ -bool runtime_alter_server_relationships_from_json(SERVER* server, const char* type, json_t* json); +bool runtime_alter_server_relationships_from_json(Server* server, const char* type, json_t* json); /** * @brief Create a new monitor from JSON diff --git a/server/core/resource.cc b/server/core/resource.cc index 146a5b766..dbd48951d 100644 --- a/server/core/resource.cc +++ b/server/core/resource.cc @@ -312,7 +312,7 @@ HttpResponse cb_alter_server(const HttpRequest& request) HttpResponse do_alter_server_relationship(const HttpRequest& request, const char* type) { - SERVER* server = server_find_by_unique_name(request.uri_part(1).c_str()); + auto server = Server::find_by_unique_name(request.uri_part(1)); mxb_assert(server && request.get_json()); if (runtime_alter_server_relationships_from_json(server, type, request.get_json())) @@ -473,7 +473,7 @@ HttpResponse cb_alter_qc(const HttpRequest& request) HttpResponse cb_delete_server(const HttpRequest& request) { - SERVER* server = server_find_by_unique_name(request.uri_part(1).c_str()); + auto server = Server::find_by_unique_name(request.uri_part(1).c_str()); mxb_assert(server); if (runtime_destroy_server(server))