Send OS/version/unique id in http user agent for each download
This commit is contained in:
Alex Zolotarev 2011-01-27 05:49:11 +02:00 committed by Alex Zolotarev
parent cdc8e9d229
commit ac7721a6ff
4 changed files with 77 additions and 2 deletions

View file

@ -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 \

View file

@ -5,7 +5,7 @@ TEMPLATE = lib
CONFIG += staticlib
ROOT_DIR = ..
DEPENDENCIES = base
DEPENDENCIES = base version
include($$ROOT_DIR/common.pri)

View file

@ -4,9 +4,76 @@
#include "../base/logging.hpp"
#include "../base/assert.hpp"
#include "../version/version.hpp"
#include "../std/target_os.hpp"
#include <QNetworkInterface>
#include <QFSFileEngine>
#include <QDateTime>
// 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<QNetworkInterface> 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());

View file

@ -2,11 +2,13 @@
#if defined(_BADA_SIMULATOR) || defined(_BADA_DEVICE)
#define OMIM_OS_BADA
#define OMIM_OS_NAME "Bada"
#elif defined(__APPLE__)
#include <TargetConditionals.h>
#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