Skip to content

Commit

Permalink
Correct useragent in http queries
Browse files Browse the repository at this point in the history
Net struct init
  • Loading branch information
proller committed Nov 5, 2013
1 parent 6f44492 commit 8903c68
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/client.cpp
Expand Up @@ -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 <curl/curl.h>
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/convert_json.cpp
Expand Up @@ -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 <curl/curl.h>
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/guiEngine.cpp
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/serverlist.cpp
Expand Up @@ -241,7 +241,7 @@ void sendAnnounce(std::string action, const std::vector<std::string> & 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);
Expand Down
9 changes: 7 additions & 2 deletions src/socket.cpp
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -568,5 +575,3 @@ bool UDPSocket::WaitData(int timeout_ms)
// There is data
return true;
}


0 comments on commit 8903c68

Please sign in to comment.