Remove HTTP functionality
It wasn't used so it can be removed.
This commit is contained in:
@ -67,7 +67,6 @@ target_link_libraries(maxscale-common
|
||||
gnutls
|
||||
gcrypt
|
||||
${MICROHTTPD_LIBRARIES}
|
||||
${CURL_LIBRARIES}
|
||||
)
|
||||
|
||||
if(WITH_ASAN AND ASAN_FOUND)
|
||||
|
@ -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<std::string> 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<std::string, int> 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};
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user