From: Sfan5 Date: Sun, 19 Jan 2014 13:32:03 +0000 (+0100) Subject: Include system info in the HTTP user agent on Windows X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=cd7e8372f3c83531afe5d5c2460ecb95540f9d0d;p=zefram%2Fminetest%2Fminetest_engine.git Include system info in the HTTP user agent on Windows --- diff --git a/src/httpfetch.cpp b/src/httpfetch.cpp index 59950756..2eca363d 100644 --- a/src/httpfetch.cpp +++ b/src/httpfetch.cpp @@ -18,16 +18,13 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "socket.h" // for select() -#include "porting.h" // for sleep_ms() +#include "porting.h" // for sleep_ms(), get_sysinfo() #include "httpfetch.h" #include #include #include #include #include -#ifndef _WIN32 -#include -#endif #include "jthread/jevent.h" #include "config.h" #include "exceptions.h" @@ -50,15 +47,7 @@ HTTPFetchRequest::HTTPFetchRequest() timeout = g_settings->getS32("curl_timeout"); connect_timeout = timeout * 5; - useragent = std::string("Minetest/") + minetest_version_hash + " "; -#ifdef _WIN32 - useragent += "(Windows)"; -#else - struct utsname osinfo; - uname(&osinfo); - useragent += std::string("(") + osinfo.sysname + "/" - + osinfo.release + " " + osinfo.machine + ")"; -#endif + useragent = std::string("Minetest/") + minetest_version_hash + " (" + porting::get_sysinfo() + ")"; } diff --git a/src/porting.cpp b/src/porting.cpp index a080a44e..b0a1843e 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -23,15 +23,18 @@ with this program; if not, write to the Free Software Foundation, Inc., See comments in porting.h */ -#if defined(linux) - #include -#elif defined(__APPLE__) - #include +#if defined(__APPLE__) #include + #include "CoreFoundation/CoreFoundation.h" #elif defined(__FreeBSD__) - #include #include #include +#elif defined(_WIN32) + #include +#endif +#if !defined(_WIN32) + #include + #include #endif #include "porting.h" @@ -42,10 +45,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/string.h" #include -#ifdef __APPLE__ - #include "CoreFoundation/CoreFoundation.h" -#endif - namespace porting { @@ -284,6 +283,42 @@ bool detectMSVCBuildDir(char *c_path) return (removeStringEnd(path, ends) != ""); } +std::string get_sysinfo() +{ +#ifdef _WIN32 + OSVERSIONINFO osvi; + std::ostringstream oss; + std::string tmp; + ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&osvi); + tmp = osvi.szCSDVersion; + std::replace(tmp.begin(), tmp.end(), ' ', '_'); + + oss << "Windows/" << osvi.dwMajorVersion << "." + << osvi.dwMinorVersion; + if(osvi.szCSDVersion[0]) + oss << "-" << tmp; + oss << " "; + #ifdef _WIN64 + oss << "x86_64"; + #else + BOOL is64 = FALSE; + if(IsWow64Process(GetCurrentProcess(), &is64) && is64) + oss << "x86_64"; // 32-bit app on 64-bit OS + else + oss << "x86"; + #endif + + return oss.str(); +#else + struct utsname osinfo; + uname(&osinfo); + return std::string(osinfo.sysname) + "/" + + osinfo.release + " " + osinfo.machine; +#endif +} + void initializePaths() { #if RUN_IN_PLACE diff --git a/src/porting.h b/src/porting.h index ea7f31b1..7cd4cf03 100644 --- a/src/porting.h +++ b/src/porting.h @@ -148,6 +148,12 @@ bool threadBindToProcessor(threadid_t tid, int pnumber); */ bool threadSetPriority(threadid_t tid, int prio); +/* + Return system information + e.g. "Linux/3.12.7 x86_64" +*/ +std::string get_sysinfo(); + /* Resolution is 10-20ms. Remember to check for overflows.