Better User Agent for Subsurface

This one is less verbose and very easy to parse. It's guaranteed to have
five components, separated by ':' with no other ':' in the string:

Subsurface:<version>:<PrettyOSName>:<appCpuArch[/osCpuArch]>:<UILang>

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-08-08 11:13:05 -07:00
parent a9f59c0cb3
commit 827d4740c3
4 changed files with 19 additions and 2 deletions

View file

@ -223,7 +223,7 @@ WebServices::WebServices(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f
ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
timeout.setSingleShot(true); timeout.setSingleShot(true);
defaultApplyText = ui.buttonBox->button(QDialogButtonBox::Apply)->text(); defaultApplyText = ui.buttonBox->button(QDialogButtonBox::Apply)->text();
userAgent = UserSurvey::getVersion().replace("\n", " "); userAgent = UserSurvey::getUserAgent();
} }
void WebServices::hidePassword() void WebServices::hidePassword()

View file

@ -28,7 +28,7 @@ void UpdateManager::checkForUpdates()
QNetworkRequest request; QNetworkRequest request;
request.setUrl(url); request.setUrl(url);
request.setRawHeader("Accept", "text/xml"); request.setRawHeader("Accept", "text/xml");
QString userAgent = UserSurvey::getVersion().replace("\n", " "); QString userAgent = UserSurvey::getUserAgent();
request.setRawHeader("User-Agent", userAgent.toUtf8()); request.setRawHeader("User-Agent", userAgent.toUtf8());
connect(SubsurfaceWebServices::manager()->get(request), SIGNAL(finished()), this, SLOT(requestReceived())); connect(SubsurfaceWebServices::manager()->get(request), SIGNAL(finished()), this, SLOT(requestReceived()));
} }

View file

@ -47,6 +47,22 @@ QString UserSurvey::getVersion()
return sysInfo; return sysInfo;
} }
QString UserSurvey::getUserAgent()
{
QString arch;
// fill in the system data - use ':' as separator
// replace all other ':' with ' ' so that this is easy to parse
QString userAgent = QString("Subsurface:%1:").arg(VERSION_STRING);
userAgent.append(SubsurfaceSysInfo::prettyOsName().replace(':', ' ') + ":");
arch = SubsurfaceSysInfo::cpuArchitecture().replace(':', ' ');
userAgent.append(arch);
if (arch == "i386")
userAgent.append("/" + SubsurfaceSysInfo::osArch());
userAgent.append(":" + uiLanguage(NULL));
return userAgent;
}
UserSurvey::~UserSurvey() UserSurvey::~UserSurvey()
{ {
delete ui; delete ui;

View file

@ -16,6 +16,7 @@ public:
explicit UserSurvey(QWidget *parent = 0); explicit UserSurvey(QWidget *parent = 0);
~UserSurvey(); ~UserSurvey();
static QString getVersion(); static QString getVersion();
static QString getUserAgent();
private private
slots: slots: