diff --git a/src/client/ring_signal.cpp b/src/client/ring_signal.cpp index b29ab291f6c8799d54e1666c7acb47ad696d6ee7..f3234a9daa232d5a6c4134ba26c58d4b2e74e41b 100644 --- a/src/client/ring_signal.cpp +++ b/src/client/ring_signal.cpp @@ -78,6 +78,7 @@ getSignalHandlers() #endif #if defined(__ANDROID__) || (defined(TARGET_OS_IOS) && TARGET_OS_IOS) || defined(RING_UWP) exported_callback<DRing::ConfigurationSignal::GetAppDataPath>(), + exported_callback<DRing::ConfigurationSignal::GetDeviceName>(), #endif /* Debug */ diff --git a/src/dring/configurationmanager_interface.h b/src/dring/configurationmanager_interface.h index 135aa7ea0afe4afb78c92f1599180b7dcba23c6b..013c1806bd9e6b571e0f1328c292bd9d0f8ae2eb 100644 --- a/src/dring/configurationmanager_interface.h +++ b/src/dring/configurationmanager_interface.h @@ -294,6 +294,10 @@ struct ConfigurationSignal { constexpr static const char* name = "GetAppDataPath"; using cb_type = void(const std::string& name, std::vector<std::string>* /* path_ret */); }; + struct GetDeviceName { + constexpr static const char* name = "GetDeviceName"; + using cb_type = void(std::vector<std::string>* /* path_ret */); + }; #endif }; diff --git a/src/ip_utils.cpp b/src/ip_utils.cpp index 0a2771364524cf70baaaa69a28f97d0633a8d0f1..c4d6d29cb95f5731b5405c39bff924800f988a64 100644 --- a/src/ip_utils.cpp +++ b/src/ip_utils.cpp @@ -30,6 +30,10 @@ #include <unistd.h> #include <limits.h> +#if defined(__ANDROID__) || defined(RING_UWP) || (defined(TARGET_OS_IOS) && TARGET_OS_IOS) +#include "client/ring_signal.h" +#endif + #ifdef _WIN32 #define InetPtonA inet_pton WINSOCK_API_LINKAGE INT WSAAPI InetPtonA(INT Family, LPCSTR pStringBuf, PVOID pAddr); @@ -55,6 +59,19 @@ ip_utils::getHostname() return hostname; } +std::string +ip_utils::getDeviceName() +{ +#if defined(__ANDROID__) || defined(RING_UWP) || (defined(TARGET_OS_IOS) && TARGET_OS_IOS) + std::vector<std::string> deviceNames; + emitSignal<DRing::ConfigurationSignal::GetDeviceName>(&deviceNames); + if (not deviceNames.empty()) { + return deviceNames[0]; + } +#endif + return getHostname(); +} + std::vector<IpAddr> ip_utils::getAddrList(const std::string &name, pj_uint16_t family) { diff --git a/src/ip_utils.h b/src/ip_utils.h index f20f91194a3bd386d3f222d71fbd8859da7b3640..e70b4363c8fa39134aca12aad2a8323810f0932c 100644 --- a/src/ip_utils.h +++ b/src/ip_utils.h @@ -237,6 +237,8 @@ static const char *const DEFAULT_INTERFACE = "default"; std::string getHostname(); +std::string getDeviceName(); + /** * Return the generic "any host" IP address of the specified family. * If family is unspecified, default to pj_AF_INET6() (IPv6). diff --git a/src/ringdht/ringaccount.cpp b/src/ringdht/ringaccount.cpp index 21c6b0fb1c3ae74b3d03095a29a50a888851f400..7b4ccdfdb085508e629b4ed05096d7a39d7a0297 100644 --- a/src/ringdht/ringaccount.cpp +++ b/src/ringdht/ringaccount.cpp @@ -753,7 +753,7 @@ void RingAccount::unserialize(const YAML::Node &node) try { parseValue(node, DRing::Account::VolatileProperties::REGISTERED_NAME, registeredName_); } catch (const std::exception& e) { - RING_WARN("can't read device name: %s", e.what()); + RING_WARN("can't read registered name: %s", e.what()); } } @@ -810,7 +810,7 @@ RingAccount::createRingDevice(const dht::crypto::Identity& id) accountTrust_ = dht::crypto::TrustList{}; accountTrust_.add(*id.second); ringDeviceId_ = dev_id.first->getPublicKey().getId().toString(); - ringDeviceName_ = ip_utils::getHostname(); + ringDeviceName_ = ip_utils::getDeviceName(); if (ringDeviceName_.empty()) ringDeviceName_ = ringDeviceId_.substr(8);