1/*
2 * IXUserAgent.cpp
3 * Author: Benjamin Sergeant
4 * Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved.
5 */
6
7#include "IXUserAgent.h"
8
9#include "IXWebSocketVersion.h"
10#include <sstream>
11#ifdef IXWEBSOCKET_USE_ZLIB
12#include <zlib.h>
13#endif
14
15// Platform name
16#if defined(_WIN32)
17#define PLATFORM_NAME "windows" // Windows
18#elif defined(_WIN64)
19#define PLATFORM_NAME "windows" // Windows
20#elif defined(__CYGWIN__) && !defined(_WIN32)
21#define PLATFORM_NAME "windows" // Windows (Cygwin POSIX under Microsoft Window)
22#elif defined(__ANDROID__)
23#define PLATFORM_NAME "android" // Android (implies Linux, so it must come first)
24#elif defined(__linux__)
25#define PLATFORM_NAME "linux" // Debian, Ubuntu, Gentoo, Fedora, openSUSE, RedHat, Centos and other
26#elif defined(__unix__) || !defined(__APPLE__) && defined(__MACH__)
27#include <sys/param.h>
28#if defined(BSD)
29#define PLATFORM_NAME "bsd" // FreeBSD, NetBSD, OpenBSD, DragonFly BSD
30#endif
31#elif defined(__hpux)
32#define PLATFORM_NAME "hp-ux" // HP-UX
33#elif defined(_AIX)
34#define PLATFORM_NAME "aix" // IBM AIX
35#elif defined(__APPLE__) && defined(__MACH__) // Apple OSX and iOS (Darwin)
36#include <TargetConditionals.h>
37#if TARGET_IPHONE_SIMULATOR == 1
38#define PLATFORM_NAME "ios" // Apple iOS
39#elif TARGET_OS_IPHONE == 1
40#define PLATFORM_NAME "ios" // Apple iOS
41#elif TARGET_OS_MAC == 1
42#define PLATFORM_NAME "macos" // Apple OSX
43#endif
44#elif defined(__sun) && defined(__SVR4)
45#define PLATFORM_NAME "solaris" // Oracle Solaris, Open Indiana
46#else
47#define PLATFORM_NAME "unknown platform"
48#endif
49
50// SSL
51#ifdef IXWEBSOCKET_USE_MBED_TLS
52#include <mbedtls/version.h>
53#elif defined(IXWEBSOCKET_USE_OPEN_SSL)
54#include <openssl/opensslv.h>
55#endif
56
57namespace ix
58{
59 std::string userAgent()
60 {
61 std::stringstream ss;
62
63 // IXWebSocket Version
64 ss << "ixwebsocket/" << IX_WEBSOCKET_VERSION;
65
66 // Platform
67 ss << " " << PLATFORM_NAME;
68
69 // TLS
70#ifdef IXWEBSOCKET_USE_TLS
71#ifdef IXWEBSOCKET_USE_MBED_TLS
72 ss << " ssl/mbedtls " << MBEDTLS_VERSION_STRING;
73#elif defined(IXWEBSOCKET_USE_OPEN_SSL)
74 ss << " ssl/OpenSSL " << OPENSSL_VERSION_TEXT;
75#elif __APPLE__
76 ss << " ssl/SecureTransport";
77#endif
78#else
79 ss << " nossl";
80#endif
81
82#ifdef IXWEBSOCKET_USE_ZLIB
83 // Zlib version
84 ss << " zlib " << ZLIB_VERSION;
85#endif
86
87 return ss.str();
88 }
89} // namespace ix
90