From 8903c68460d79aeac6b1c5074003743f98371339 Mon Sep 17 00:00:00 2001 From: proller Date: Tue, 5 Nov 2013 16:57:43 +0400 Subject: [PATCH] Correct useragent in http queries Net struct init --- src/client.cpp | 2 ++ src/convert_json.cpp | 2 ++ src/guiEngine.cpp | 2 +- src/serverlist.cpp | 2 +- src/socket.cpp | 9 +++++++-- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 98c9af97..5e8f2062 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -48,6 +48,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/serialize.h" #include "config.h" #include "util/directiontables.h" +#include "version.h" #if USE_CURL #include @@ -245,6 +246,7 @@ void * MediaFetchThread::Thread() std::ostringstream stream; curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream); + curl_easy_setopt(curl, CURLOPT_USERAGENT, (std::string("Minetest ")+minetest_version_hash).c_str()); res = curl_easy_perform(curl); if (res == CURLE_OK) { std::string data = stream.str(); diff --git a/src/convert_json.cpp b/src/convert_json.cpp index edb37024..e8eede0b 100644 --- a/src/convert_json.cpp +++ b/src/convert_json.cpp @@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "log.h" #include "main.h" // for g_settings #include "settings.h" +#include "version.h" #if USE_CURL #include @@ -56,6 +57,7 @@ Json::Value fetchJsonValue(const std::string url, curl_easy_setopt(curl, CURLOPT_WRITEDATA, &liststring); curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, g_settings->getS32("curl_timeout")); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, g_settings->getS32("curl_timeout")); + curl_easy_setopt(curl, CURLOPT_USERAGENT, (std::string("Minetest ")+minetest_version_hash).c_str()); if (chunk != 0) curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk); diff --git a/src/guiEngine.cpp b/src/guiEngine.cpp index a96a832c..d5f528f3 100644 --- a/src/guiEngine.cpp +++ b/src/guiEngine.cpp @@ -532,7 +532,7 @@ bool GUIEngine::downloadFile(std::string url,std::string target) { curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, targetfile); - + curl_easy_setopt(curl, CURLOPT_USERAGENT, (std::string("Minetest ")+minetest_version_hash).c_str()); res = curl_easy_perform(curl); if (res != CURLE_OK) { errorstream << "File at url \"" << url diff --git a/src/serverlist.cpp b/src/serverlist.cpp index fa2ddad1..f9e3c673 100644 --- a/src/serverlist.cpp +++ b/src/serverlist.cpp @@ -241,7 +241,7 @@ void sendAnnounce(std::string action, const std::vector & clients_n CURLcode res; curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(curl, CURLOPT_URL, (g_settings->get("serverlist_url")+std::string("/announce?json=")+curl_easy_escape(curl, writer.write( server ).c_str(), 0)).c_str()); - //curl_easy_setopt(curl, CURLOPT_USERAGENT, "minetest"); + curl_easy_setopt(curl, CURLOPT_USERAGENT, (std::string("Minetest ")+minetest_version_hash).c_str()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ServerList::ServerAnnounceCallback); //curl_easy_setopt(curl, CURLOPT_WRITEDATA, &liststring); curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1); diff --git a/src/socket.cpp b/src/socket.cpp index 1c07c44d..c3873dab 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -345,6 +345,8 @@ void UDPSocket::Bind(u16 port) if(m_addr_family == AF_INET6) { struct sockaddr_in6 address; + memset(&address, 0, sizeof(address)); + address.sin6_family = AF_INET6; address.sin6_addr = in6addr_any; address.sin6_port = htons(port); @@ -360,6 +362,8 @@ void UDPSocket::Bind(u16 port) else { struct sockaddr_in address; + memset(&address, 0, sizeof(address)); + address.sin_family = AF_INET; address.sin_addr.s_addr = INADDR_ANY; address.sin_port = htons(port); @@ -454,6 +458,7 @@ int UDPSocket::Receive(Address & sender, void * data, int size) if(m_addr_family == AF_INET6) { struct sockaddr_in6 address; + memset(&address, 0, sizeof(address)); socklen_t address_len = sizeof(address); received = recvfrom(m_handle, (char *) data, @@ -470,6 +475,8 @@ int UDPSocket::Receive(Address & sender, void * data, int size) else { struct sockaddr_in address; + memset(&address, 0, sizeof(address)); + socklen_t address_len = sizeof(address); received = recvfrom(m_handle, (char *) data, @@ -568,5 +575,3 @@ bool UDPSocket::WaitData(int timeout_ms) // There is data return true; } - - -- 2.30.2