mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 02:31:48 +00:00
Include OS in User Agent.
This commit is contained in:
parent
98e3822c88
commit
f364c2cef3
@ -7,14 +7,81 @@
|
||||
#include "../server/TracyVersion.hpp"
|
||||
#include "HttpRequest.hpp"
|
||||
|
||||
#if defined _WIN32 || defined __CYGWIN__
|
||||
# include <windows.h>
|
||||
extern "C" typedef LONG (WINAPI *t_RtlGetVersion)( PRTL_OSVERSIONINFOW );
|
||||
#elif defined __linux__
|
||||
# include <sys/utsname.h>
|
||||
#elif defined __APPLE__
|
||||
# include "TargetConditionals.h"
|
||||
#endif
|
||||
|
||||
static constexpr char CRLF[2] = { '\r', '\n' };
|
||||
|
||||
static const char* GetOsInfo()
|
||||
{
|
||||
static char buf[1024];
|
||||
#if defined _WIN32 || defined __CYGWIN__
|
||||
t_RtlGetVersion RtlGetVersion = (t_RtlGetVersion)GetProcAddress( GetModuleHandleA( "ntdll.dll" ), "RtlGetVersion" );
|
||||
if( !RtlGetVersion )
|
||||
{
|
||||
# ifdef __CYGWIN__
|
||||
sprintf( buf, "Windows (Cygwin)" );
|
||||
# elif defined __MINGW32__
|
||||
sprintf( buf, "Windows (MingW)" );
|
||||
# else
|
||||
sprintf( buf, "Windows" );
|
||||
# endif
|
||||
}
|
||||
else
|
||||
{
|
||||
RTL_OSVERSIONINFOW ver = { sizeof( RTL_OSVERSIONINFOW ) };
|
||||
RtlGetVersion( &ver );
|
||||
|
||||
# ifdef __CYGWIN__
|
||||
sprintf( buf, "Windows %i.%i.%i (Cygwin)", ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber );
|
||||
# elif defined __MINGW32__
|
||||
sprintf( buf, "Windows %i.%i.%i (MingW)", (int)ver.dwMajorVersion, (int)ver.dwMinorVersion, (int)ver.dwBuildNumber );
|
||||
# else
|
||||
sprintf( buf, "Windows %i.%i.%i", ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber );
|
||||
# endif
|
||||
}
|
||||
#elif defined __linux__
|
||||
struct utsname utsName;
|
||||
uname( &utsName );
|
||||
# if defined __ANDROID__
|
||||
sprintf( buf, "Linux %s (Android)", utsName.release );
|
||||
# else
|
||||
sprintf( buf, "Linux %s", utsName.release );
|
||||
# endif
|
||||
#elif defined __APPLE__
|
||||
# if TARGET_OS_IPHONE == 1
|
||||
sprintf( buf, "Darwin (iOS)" );
|
||||
# elif TARGET_OS_MAC == 1
|
||||
sprintf( buf, "Darwin (OSX)" );
|
||||
# else
|
||||
sprintf( buf, "Darwin (unknown)" );
|
||||
# endif
|
||||
#elif defined __DragonFly__
|
||||
sprintf( buf, "BSD (DragonFly)" );
|
||||
#elif defined __FreeBSD__
|
||||
sprintf( buf, "BSD (FreeBSD)" );
|
||||
#elif defined __NetBSD__
|
||||
sprintf( buf, "BSD (NetBSD)" );
|
||||
#elif defined __OpenBSD__
|
||||
sprintf( buf, "BSD (OpenBSD)" );
|
||||
#else
|
||||
sprintf( buf, "unknown" );
|
||||
#endif
|
||||
return buf;
|
||||
}
|
||||
|
||||
void HttpRequest( const char* server, const char* resource, int port, std::function<void(int, char*)> cb )
|
||||
{
|
||||
tracy::Socket sock;
|
||||
if( !sock.ConnectBlocking( server, port ) ) return;
|
||||
char request[4096];
|
||||
const auto len = sprintf( request, "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: Tracy Profiler %i.%i.%i\r\nConnection: close\r\nCache-Control: no-cache, no-store, must-revalidate\r\n\r\n", resource, server, tracy::Version::Major, tracy::Version::Minor, tracy::Version::Patch );
|
||||
const auto len = sprintf( request, "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: Tracy Profiler %i.%i.%i (%s)\r\nConnection: close\r\nCache-Control: no-cache, no-store, must-revalidate\r\n\r\n", resource, server, tracy::Version::Major, tracy::Version::Minor, tracy::Version::Patch, GetOsInfo() );
|
||||
sock.Send( request, len );
|
||||
char response[4096];
|
||||
const auto sz = sock.ReadUpTo( response, 4096, 15 );
|
||||
|
Loading…
Reference in New Issue
Block a user