diff --git a/omim.pro b/omim.pro index 4d7cdc22ff..f204ad36ca 100644 --- a/omim.pro +++ b/omim.pro @@ -13,9 +13,9 @@ SUBDIRS = 3party \ geometry \ indexer \ geometry/geometry_tests \ + version \ platform platform/platform_tests \ yg \ - version \ storage storage/storage_tests \ map \ map/map_tests \ diff --git a/platform/platform.pro b/platform/platform.pro index 6bb1638d97..95b32f9458 100644 --- a/platform/platform.pro +++ b/platform/platform.pro @@ -5,7 +5,7 @@ TEMPLATE = lib CONFIG += staticlib ROOT_DIR = .. -DEPENDENCIES = base +DEPENDENCIES = base version include($$ROOT_DIR/common.pri) diff --git a/platform/qt_download.cpp b/platform/qt_download.cpp index 6cdabc011b..8cdf37cd18 100644 --- a/platform/qt_download.cpp +++ b/platform/qt_download.cpp @@ -4,9 +4,76 @@ #include "../base/logging.hpp" #include "../base/assert.hpp" +#include "../version/version.hpp" + +#include "../std/target_os.hpp" + +#include +#include +#include + // How many times we try to automatically reconnect in the case of network errors #define MAX_AUTOMATIC_RETRIES 2 +/// @return mac address of active interface without colons or empty string if not found +/// @note mac is converted to decimal from hex +static QString MacAddress() +{ + QList interfaces = QNetworkInterface::allInterfaces(); + for (int i = 0; i < interfaces.size(); ++i) + { + QNetworkInterface const & iface = interfaces.at(i); + QString hwAddr = iface.hardwareAddress(); + if (!iface.addressEntries().empty() + && (iface.flags() & (QNetworkInterface::IsUp | QNetworkInterface::IsRunning + | QNetworkInterface::CanBroadcast | QNetworkInterface::CanMulticast)) + == iface.flags() + && hwAddr.size() == 17) // mac length with semicolons + { + hwAddr.remove(':'); + bool success = false; + qulonglong numAddr = hwAddr.toULongLong(&success, 16); + if (success) + return QString("%1").arg(numAddr); + } + } + // no valid interface was found + return QString(); +} + +/// @return creation time of the root file system or empty string +static QString FsCreationTime() +{ + QFileInfoList drives = QFSFileEngine::drives(); + for (int i = 0; i < drives.size(); ++i) + { + QFileInfo const & info = drives.at(i); + QString const path = info.absolutePath(); + if (path == "/" || path.startsWith("C:")) + return QString("%1").arg(info.created().toTime_t()); + } + return QString(); +} + +static QString UniqueClientId() +{ + QString result = MacAddress(); + if (result.size() == 0) + { + result = FsCreationTime(); + if (result.size() == 0) + result = QString("------------"); + } + return result; +} + +static QString UserAgent() +{ + static QString userAgent = QString("MWM(" OMIM_OS_NAME ")/") + QString(VERSION_STRING) + + QString("/") + UniqueClientId(); + return userAgent; +} + QtDownload::QtDownload(QtDownloadManager & manager, char const * url, char const * fileName, TDownloadFinishedFunction & finish, TDownloadProgressFunction & progress, bool useResume) @@ -63,6 +130,8 @@ void QtDownload::StartDownload(QtDownloadManager & manager, char const * url, void QtDownload::StartRequest() { QNetworkRequest httpRequest(m_currentUrl); + // set user-agent with unique client id + httpRequest.setRawHeader("User-Agent", UserAgent().toAscii()); qint64 fileSize = m_file->size(); if (fileSize > 0) // need resume httpRequest.setRawHeader("Range", QString("bytes=%1-").arg(fileSize).toAscii()); diff --git a/std/target_os.hpp b/std/target_os.hpp index fec99a4eb7..b7b282c4f0 100644 --- a/std/target_os.hpp +++ b/std/target_os.hpp @@ -2,11 +2,13 @@ #if defined(_BADA_SIMULATOR) || defined(_BADA_DEVICE) #define OMIM_OS_BADA + #define OMIM_OS_NAME "Bada" #elif defined(__APPLE__) #include #if (TARGET_OS_IPHONE > 0) #define OMIM_OS_IPHONE + #define OMIM_OS_NAME "iOS" #if (TARGET_IPHONE_SIMULATOR > 0) #define OMIM_OS_IPHONE_SIMULATOR #else @@ -14,6 +16,7 @@ #endif #else #define OMIM_OS_MAC + #define OMIM_OS_NAME "MacOS" #endif #elif defined(_WIN32) @@ -21,9 +24,12 @@ #ifdef __MINGW32__ #define OMIM_OS_WINDOWS_MINGW + #define OMIM_OS_NAME "MinGW" #else #define OMIM_OS_WINDOWS_NATIVE + #define OMIM_OS_NAME "Win" #endif #else #define OMIM_OS_LINUX + #define OMIM_OS_NAME "Linux" #endif