IXWebSocket/ixwebsocket/IXUserAgent.cpp

86 lines
2.3 KiB
C++
Raw Normal View History

2019-08-30 21:48:18 +02:00
/*
* IXUserAgent.cpp
* Author: Benjamin Sergeant
* Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved.
*/
#include "IXUserAgent.h"
2019-09-23 19:25:23 +02:00
#include "IXWebSocketVersion.h"
2019-08-30 21:48:18 +02:00
#include <sstream>
#include <zlib.h>
// Platform name
#if defined(_WIN32)
2019-09-23 19:25:23 +02:00
#define PLATFORM_NAME "windows" // Windows
2019-08-30 21:48:18 +02:00
#elif defined(_WIN64)
2019-09-23 19:25:23 +02:00
#define PLATFORM_NAME "windows" // Windows
2019-08-30 21:48:18 +02:00
#elif defined(__CYGWIN__) && !defined(_WIN32)
2019-09-23 19:25:23 +02:00
#define PLATFORM_NAME "windows" // Windows (Cygwin POSIX under Microsoft Window)
2019-08-30 21:48:18 +02:00
#elif defined(__ANDROID__)
2019-09-23 19:25:23 +02:00
#define PLATFORM_NAME "android" // Android (implies Linux, so it must come first)
2019-08-30 21:48:18 +02:00
#elif defined(__linux__)
2019-09-23 19:25:23 +02:00
#define PLATFORM_NAME "linux" // Debian, Ubuntu, Gentoo, Fedora, openSUSE, RedHat, Centos and other
2019-08-30 21:48:18 +02:00
#elif defined(__unix__) || !defined(__APPLE__) && defined(__MACH__)
2019-09-23 19:25:23 +02:00
#include <sys/param.h>
#if defined(BSD)
#define PLATFORM_NAME "bsd" // FreeBSD, NetBSD, OpenBSD, DragonFly BSD
#endif
2019-08-30 21:48:18 +02:00
#elif defined(__hpux)
2019-09-23 19:25:23 +02:00
#define PLATFORM_NAME "hp-ux" // HP-UX
2019-08-30 21:48:18 +02:00
#elif defined(_AIX)
2019-09-23 19:25:23 +02:00
#define PLATFORM_NAME "aix" // IBM AIX
2019-08-30 21:48:18 +02:00
#elif defined(__APPLE__) && defined(__MACH__) // Apple OSX and iOS (Darwin)
2019-09-23 19:25:23 +02:00
#include <TargetConditionals.h>
#if TARGET_IPHONE_SIMULATOR == 1
#define PLATFORM_NAME "ios" // Apple iOS
#elif TARGET_OS_IPHONE == 1
#define PLATFORM_NAME "ios" // Apple iOS
#elif TARGET_OS_MAC == 1
#define PLATFORM_NAME "macos" // Apple OSX
#endif
2019-08-30 21:48:18 +02:00
#elif defined(__sun) && defined(__SVR4)
2019-09-23 19:25:23 +02:00
#define PLATFORM_NAME "solaris" // Oracle Solaris, Open Indiana
2019-08-30 21:48:18 +02:00
#else
2019-09-23 19:25:23 +02:00
#define PLATFORM_NAME "unknown platform"
2019-08-30 21:48:18 +02:00
#endif
// SSL
#ifdef IXWEBSOCKET_USE_MBED_TLS
#include <mbedtls/version.h>
#elif defined(IXWEBSOCKET_USE_OPEN_SSL)
2019-08-30 21:48:18 +02:00
#include <openssl/opensslv.h>
#endif
namespace ix
{
std::string userAgent()
{
std::stringstream ss;
// IXWebSocket Version
ss << "ixwebsocket/" << IX_WEBSOCKET_VERSION;
// Platform
ss << " " << PLATFORM_NAME;
// TLS
#ifdef IXWEBSOCKET_USE_TLS
#ifdef IXWEBSOCKET_USE_MBED_TLS
ss << " ssl/mbedtls " << MBEDTLS_VERSION_STRING;
2019-08-30 21:48:18 +02:00
#elif defined(IXWEBSOCKET_USE_OPEN_SSL)
ss << " ssl/OpenSSL " << OPENSSL_VERSION_TEXT;
#elif __APPLE__
ss << " ssl/SecureTransport";
2019-08-30 21:48:18 +02:00
#endif
#else
ss << " nossl";
#endif
// Zlib version
ss << " zlib " << ZLIB_VERSION;
return ss.str();
}
2019-09-23 19:25:23 +02:00
} // namespace ix