Skip to content
Snippets Groups Projects
Commit b1bb6c4e authored by Adrien Béraud's avatar Adrien Béraud Committed by Adrien Béraud
Browse files

libjami: use string utils for platform, arch

Change-Id: Idd06548d234f837b0f0cb35b75d052d6ebc95a7e
parent 8e1c4c95
No related branches found
No related tags found
No related merge requests found
......@@ -423,7 +423,7 @@ Account::getUserAgentName()
std::string
Account::getDefaultUserAgent()
{
return fmt::format("{:s} {:s} ({:s})", PACKAGE_NAME, libjami::version(), libjami::platform());
return fmt::format("{:s} {:s} ({:s})", PACKAGE_NAME, libjami::version(), jami::platform());
}
void
......
......@@ -23,6 +23,7 @@
#endif
#include "jami.h"
#include "string_utils.h"
#include <string>
#include <ciso646> // fix windows compiler bug
......@@ -49,25 +50,16 @@ version() noexcept
: (JAMI_REVISION[0] ? PACKAGE_VERSION "-" JAMI_REVISION : PACKAGE_VERSION);
}
const char*
std::string_view
platform() noexcept
{
#ifdef __linux__
#if defined(__ANDROID__)
return "android";
#else
return "linux";
#endif
#elif defined(_WIN32)
return "win32";
#elif defined(__APPLE__)
#ifdef TARGET_OS_IOS
return "iOS";
#else
return "macOS";
#endif
#else
#error "Unknown OS"
#endif
return jami::platform();
}
std::string_view
arch() noexcept
{
return jami::arch();
}
} // namespace libjami
......@@ -56,7 +56,12 @@ LIBJAMI_PUBLIC const char* version() noexcept;
/**
* Return the target platform (OS) as a string.
*/
LIBJAMI_PUBLIC const char* platform() noexcept;
LIBJAMI_PUBLIC std::string_view platform() noexcept;
/**
* Return the target architecture as a string.
*/
LIBJAMI_PUBLIC std::string_view arch() noexcept;
/**
* Initialize globals, create underlaying daemon.
......
......@@ -18,6 +18,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "string_utils.h"
......@@ -42,6 +45,13 @@
namespace jami {
std::string_view
userAgent()
{
static const std::string USER_AGENT = fmt::format("{:s} ({:s}/{:s})", PACKAGE_NAME, platform(), arch());
return USER_AGENT;
}
#ifdef _WIN32
std::wstring
to_wstring(const std::string& str, int codePage)
......
......@@ -29,10 +29,14 @@
#include <regex>
#include <iterator>
#include <charconv>
#include <string_view>
#ifdef _WIN32
#include <WTypes.h>
#endif
#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif
namespace jami {
......@@ -45,21 +49,25 @@ bool_to_str(bool b) noexcept
return b ? TRUE_STR : FALSE_STR;
}
std::string_view userAgent();
constexpr inline std::string_view
platform() {
using namespace std::literals;
#if defined(__ANDROID__)
return "android"sv;
#elif defined(__linux__)
return "linux"sv;
#elif defined(__APPLE__)
# if TARGET_OS_IPHONE
return "ios"sv;
# else
return "macos"sv;
# endif
#ifdef __linux__
#if defined(__ANDROID__)
return "Android"sv;
#else
return "Linux"sv;
#endif
#elif defined(_WIN32)
return "windows"sv;
return "Windows"sv;
#elif defined(__APPLE__)
#if TARGET_OS_IOS
return "iOS"sv;
#else
return "macOS"sv;
#endif
#else
return "unknown"sv;
#endif
......@@ -72,9 +80,9 @@ arch() {
return "x86_64"sv;
#elif defined(__i386__) || defined(_M_IX86)
return "x86"sv;
#elif defined(__aarch64__)
#elif defined(__aarch64__) || defined(_M_ARM64)
return "arm64"sv;
#elif defined(__arm__)
#elif defined(__arm__) || defined(_M_ARM)
return "arm"sv;
#else
return "unknown"sv;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment