From 8b9fdaa0cb6edda7f445ae8155e07ecb6f4dbe43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 2 Oct 2018 13:55:51 +0300 Subject: [PATCH] Remove HTTP functionality It wasn't used so it can be removed. --- BUILD/install_build_deps.sh | 6 +- CMakeLists.txt | 1 - .../Building-MaxScale-from-Source-Code.md | 1 - include/maxscale/monitor.hh | 11 ---- include/maxscale/utils.hh | 22 ------- server/core/CMakeLists.txt | 1 - server/core/monitor.cc | 60 ------------------- server/core/test/test_utils.cc | 15 ----- server/core/utils.cc | 47 --------------- 9 files changed, 3 insertions(+), 161 deletions(-) diff --git a/BUILD/install_build_deps.sh b/BUILD/install_build_deps.sh index 810bbf718..64d54048e 100755 --- a/BUILD/install_build_deps.sh +++ b/BUILD/install_build_deps.sh @@ -16,7 +16,7 @@ then build-essential libssl-dev ncurses-dev bison flex \ perl libtool libpcre3-dev tcl tcl-dev uuid \ uuid-dev libsqlite3-dev liblzma-dev libpam0g-dev pkg-config \ - libedit-dev libcurl4-openssl-dev + libedit-dev ## separatelibgnutls installation process for Ubuntu Trusty cat /etc/*release | grep -E "Trusty|wheezy" @@ -49,7 +49,7 @@ else make libtool libopenssl-devel libaio libaio-devel flex \ pcre-devel git wget tcl libuuid-devel \ xz-devel sqlite3 sqlite3-devel pkg-config lua lua-devel \ - gnutls-devel libgcrypt-devel pam-devel libcurl-devel + gnutls-devel libgcrypt-devel pam-devel sudo zypper -n install rpm-build cat /etc/*-release | grep "SUSE Linux Enterprise Server 11" @@ -66,7 +66,7 @@ else libedit-devel systemtap-sdt-devel rpm-sign wget \ gnupg pcre-devel flex rpmdevtools git wget tcl openssl libuuid-devel xz-devel \ sqlite sqlite-devel pkgconfig lua lua-devel rpm-build createrepo yum-utils \ - gnutls-devel libgcrypt-devel pam-devel libcurl-devel + gnutls-devel libgcrypt-devel pam-devel # Attempt to install libasan, it'll only work on CentOS 7 sudo yum install -y --nogpgcheck libasan diff --git a/CMakeLists.txt b/CMakeLists.txt index fa233f6ed..71ee749c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,6 @@ find_package(GSSAPI) find_package(SQLite) find_package(ASAN) find_package(TSAN) -find_package(CURL) # Build PCRE2 so we always know the version # Read BuildPCRE2 for details about how to add pcre2 as a dependency to a target diff --git a/Documentation/Getting-Started/Building-MaxScale-from-Source-Code.md b/Documentation/Getting-Started/Building-MaxScale-from-Source-Code.md index c40021e94..be7621fab 100644 --- a/Documentation/Getting-Started/Building-MaxScale-from-Source-Code.md +++ b/Documentation/Getting-Started/Building-MaxScale-from-Source-Code.md @@ -11,7 +11,6 @@ requirements are as follows: * Flex 2.5.35 or later * libuuid * GNUTLS -* libcurl This is the minimum set of requirements that must be met to build the MaxScale core package. diff --git a/include/maxscale/monitor.hh b/include/maxscale/monitor.hh index 81822f436..5908ce7c2 100644 --- a/include/maxscale/monitor.hh +++ b/include/maxscale/monitor.hh @@ -338,15 +338,4 @@ MXS_MONITOR_API MonitorApi::s_api = &MonitorApi::diagnostics_json, }; -/** - * Get the master server of the remote monitor - * - * The `peer_hosts`, `peer_user` and `peer_password` parameters must have been defined for this - * to work. - * - * @param name The name of the remote monitor - * - * @return The host and port of the monitor or an empty string and 0 if an error occurred - */ -std::pair mon_get_external_master(const std::string& name); } diff --git a/include/maxscale/utils.hh b/include/maxscale/utils.hh index 014e2280d..72150e0d1 100644 --- a/include/maxscale/utils.hh +++ b/include/maxscale/utils.hh @@ -655,26 +655,4 @@ uint64_t get_byteN(const uint8_t* ptr, int bytes); */ uint8_t* set_byteN(uint8_t* ptr, uint64_t value, int bytes); -namespace http -{ - -struct Result -{ - int code; // HTTP response code - std::string raw_body; // Raw response body - std::unique_ptr body; // JSON form of the body if it was valid JSON - std::unordered_map headers; // Headers attached to the response -}; - -/** - * Do a HTTP GET - * - * @param url URL to use - * @param user Username to use, optional - * @param passwor Password for the user, optional - * - * @return A Result - */ -Result get(const std::string& url, const std::string& user = "", const std::string& password = ""); -} } diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index 43338d0c8..aef9ac2c7 100644 --- a/server/core/CMakeLists.txt +++ b/server/core/CMakeLists.txt @@ -67,7 +67,6 @@ target_link_libraries(maxscale-common gnutls gcrypt ${MICROHTTPD_LIBRARIES} - ${CURL_LIBRARIES} ) if(WITH_ASAN AND ASAN_FOUND) diff --git a/server/core/monitor.cc b/server/core/monitor.cc index 51130467d..a5b892637 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -2929,64 +2929,4 @@ void MonitorInstance::run_one_tick() store_server_journal(m_monitor, m_master); } -static bool remote_server_is_master(const std::string& url, std::string* host, int* port) -{ - bool rval = false; - auto res = mxs::http::get(url, - config_get_global_options()->peer_user, - config_get_global_options()->peer_password); - json_t* state = mxs_json_pointer(res.body.get(), "data/attributes/state"); - json_t* json_host = mxs_json_pointer(res.body.get(), "data/attributes/parameters/address"); - json_t* json_port = mxs_json_pointer(res.body.get(), "data/attributes/parameters/port"); - - if (json_is_string(json_host) && json_is_integer(json_port) && json_is_string(state)) - { - const std::set master_states {"Master, Running", "Master, Synced, Running"}; - - if (master_states.count(json_string_value(state))) - { - *host = json_string_value(json_host); - *port = json_integer_value(json_port); - rval = true; - } - } - - return rval; -} - -std::pair mon_get_external_master(const std::string& name) -{ - std::string host; - int port = 0; - std::string url = config_get_global_options()->peer_hosts; - - auto res = mxs::http::get(url + "/v1/monitors/" + name, - config_get_global_options()->peer_user, - config_get_global_options()->peer_password); - - json_t* remote = mxs_json_pointer(res.body.get(), "data/relationships/servers/links/self"); - json_t* arr = mxs_json_pointer(res.body.get(), "data/relationships/servers/data"); - - if (json_is_string(remote) && json_is_array(arr)) - { - std::string remote_host = json_string_value(remote); - size_t i; - json_t* value; - - json_array_foreach(arr, i, value) - { - json_t* id = mxs_json_pointer(value, "id"); - - if (json_is_string(id)) - { - if (remote_server_is_master(remote_host + json_string_value(id), &host, &port)) - { - break; - } - } - } - } - - return {host, port}; -} } diff --git a/server/core/test/test_utils.cc b/server/core/test/test_utils.cc index 1349f5bb7..daa118ff4 100644 --- a/server/core/test/test_utils.cc +++ b/server/core/test/test_utils.cc @@ -169,25 +169,10 @@ int test_checksums() return 0; } -void test_http() -{ - auto res = mxs::http::get("https://mariadb.com/"); - std::cout << "https://mariadb.com/ responded with: " << res.code << std::endl; - if (res.code == 200) - { - if (res.headers.count("Date")) - { - std::cout << "The date is: " << res.headers["Date"] << std::endl; - } - } -} - int main(int argc, char* argv[]) { int rv = 0; - test_http(); // Just to see that it works - rv += test_trim(); rv += test_trim_leading(); rv += test_trim_trailing(); diff --git a/server/core/utils.cc b/server/core/utils.cc index f25ed6690..bcb4892d1 100644 --- a/server/core/utils.cc +++ b/server/core/utils.cc @@ -1294,51 +1294,4 @@ size_t header_callback(char* ptr, size_t size, size_t nmemb, void* userdata) } } -namespace http -{ - -Result get(const std::string& url, const std::string& user, const std::string& password) -{ - Result res; - char errbuf[CURL_ERROR_SIZE + 1] = ""; - CURL* curl = curl_easy_init(); - - curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10); // For connection phase - curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10); // For data transfer phase - curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &res.raw_body); - curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); - curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback); - curl_easy_setopt(curl, CURLOPT_HEADERDATA, &res.headers); - - if (!user.empty() && !password.empty()) - { - curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_easy_setopt(curl, CURLOPT_USERPWD, (user + ":" + password).c_str()); - } - - long code = 0; // needs to be a long - - if (curl_easy_perform(curl) == CURLE_OK) - { - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code); - res.code = code; - } - else - { - res.code = -1; - res.raw_body = errbuf; - } - - // Even the errors are valid JSON so this should be OK - json_error_t err; - res.body.reset(json_loads(res.raw_body.c_str(), 0, &err)); - - curl_easy_cleanup(curl); - - return std::move(res); -} -} }