Skip to content

Commit 8903c68

Browse files
author
proller
committedNov 5, 2013
Correct useragent in http queries
Net struct init
1 parent 6f44492 commit 8903c68

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed
 

‎src/client.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
4848
#include "util/serialize.h"
4949
#include "config.h"
5050
#include "util/directiontables.h"
51+
#include "version.h"
5152

5253
#if USE_CURL
5354
#include <curl/curl.h>
@@ -245,6 +246,7 @@ void * MediaFetchThread::Thread()
245246
std::ostringstream stream;
246247
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write_data);
247248
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream);
249+
curl_easy_setopt(curl, CURLOPT_USERAGENT, (std::string("Minetest ")+minetest_version_hash).c_str());
248250
res = curl_easy_perform(curl);
249251
if (res == CURLE_OK) {
250252
std::string data = stream.str();

‎src/convert_json.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2727
#include "log.h"
2828
#include "main.h" // for g_settings
2929
#include "settings.h"
30+
#include "version.h"
3031

3132
#if USE_CURL
3233
#include <curl/curl.h>
@@ -56,6 +57,7 @@ Json::Value fetchJsonValue(const std::string url,
5657
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &liststring);
5758
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, g_settings->getS32("curl_timeout"));
5859
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, g_settings->getS32("curl_timeout"));
60+
curl_easy_setopt(curl, CURLOPT_USERAGENT, (std::string("Minetest ")+minetest_version_hash).c_str());
5961

6062
if (chunk != 0)
6163
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);

‎src/guiEngine.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ bool GUIEngine::downloadFile(std::string url,std::string target) {
532532
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
533533
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
534534
curl_easy_setopt(curl, CURLOPT_WRITEDATA, targetfile);
535-
535+
curl_easy_setopt(curl, CURLOPT_USERAGENT, (std::string("Minetest ")+minetest_version_hash).c_str());
536536
res = curl_easy_perform(curl);
537537
if (res != CURLE_OK) {
538538
errorstream << "File at url \"" << url

‎src/serverlist.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void sendAnnounce(std::string action, const std::vector<std::string> & clients_n
241241
CURLcode res;
242242
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
243243
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());
244-
//curl_easy_setopt(curl, CURLOPT_USERAGENT, "minetest");
244+
curl_easy_setopt(curl, CURLOPT_USERAGENT, (std::string("Minetest ")+minetest_version_hash).c_str());
245245
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ServerList::ServerAnnounceCallback);
246246
//curl_easy_setopt(curl, CURLOPT_WRITEDATA, &liststring);
247247
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1);

‎src/socket.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ void UDPSocket::Bind(u16 port)
345345
if(m_addr_family == AF_INET6)
346346
{
347347
struct sockaddr_in6 address;
348+
memset(&address, 0, sizeof(address));
349+
348350
address.sin6_family = AF_INET6;
349351
address.sin6_addr = in6addr_any;
350352
address.sin6_port = htons(port);
@@ -360,6 +362,8 @@ void UDPSocket::Bind(u16 port)
360362
else
361363
{
362364
struct sockaddr_in address;
365+
memset(&address, 0, sizeof(address));
366+
363367
address.sin_family = AF_INET;
364368
address.sin_addr.s_addr = INADDR_ANY;
365369
address.sin_port = htons(port);
@@ -454,6 +458,7 @@ int UDPSocket::Receive(Address & sender, void * data, int size)
454458
if(m_addr_family == AF_INET6)
455459
{
456460
struct sockaddr_in6 address;
461+
memset(&address, 0, sizeof(address));
457462
socklen_t address_len = sizeof(address);
458463

459464
received = recvfrom(m_handle, (char *) data,
@@ -470,6 +475,8 @@ int UDPSocket::Receive(Address & sender, void * data, int size)
470475
else
471476
{
472477
struct sockaddr_in address;
478+
memset(&address, 0, sizeof(address));
479+
473480
socklen_t address_len = sizeof(address);
474481

475482
received = recvfrom(m_handle, (char *) data,
@@ -568,5 +575,3 @@ bool UDPSocket::WaitData(int timeout_ms)
568575
// There is data
569576
return true;
570577
}
571-
572-

0 commit comments

Comments
 (0)
Please sign in to comment.