Moved Updater to common ostproto lib, Updater sends UserAgent

This commit is contained in:
Srivats P 2016-05-31 20:23:54 +05:30
parent daba488d71
commit bdbbd8f0a1
4 changed files with 40 additions and 5 deletions

View File

@ -58,7 +58,6 @@ HEADERS += \
streamconfigdialog.h \
streamlistdelegate.h \
streammodel.h \
updater.h \
variablefieldswidget.h
FORMS += \
@ -100,7 +99,6 @@ SOURCES += \
streamconfigdialog.cpp \
streamlistdelegate.cpp \
streammodel.cpp \
updater.cpp \
variablefieldswidget.cpp

View File

@ -1,7 +1,7 @@
TEMPLATE = lib
CONFIG += qt staticlib
QT -= gui
QT += network script
QT += network script xml
LIBS += \
-lprotobuf
@ -47,6 +47,7 @@ HEADERS = \
protocollist.h \
protocollistiterator.h \
streambase.h \
updater.h \
HEADERS += \
mac.h \
@ -85,6 +86,7 @@ SOURCES = \
protocollist.cpp \
protocollistiterator.cpp \
streambase.cpp \
updater.cpp \
SOURCES += \
mac.cpp \

View File

@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "updater.h"
#include <QCoreApplication>
#include <QHttp>
#include <QTemporaryFile>
#include <QXmlStreamReader>
@ -47,9 +48,14 @@ Updater::~Updater()
void Updater::checkForNewVersion()
{
http_ = new QHttp("update.ostinato.org");
QString host("update.ostinato.org");
QHttpRequestHeader reqHdr("GET", "/update/pad.xml");
http_ = new QHttp(host);
file_ = new QTemporaryFile();
reqHdr.setValue("Host", host);
reqHdr.setValue("UserAgent", userAgent());
connect(http_, SIGNAL(responseHeaderReceived(QHttpResponseHeader)),
this, SLOT(responseReceived(QHttpResponseHeader)));
connect(http_, SIGNAL(requestFinished(int, bool)),
@ -60,7 +66,7 @@ void Updater::checkForNewVersion()
file_->open();
qDebug("Updater: PAD XML file - %s", qPrintable(file_->fileName()));
http_->get("/update/pad.xml", file_);
http_->request(reqHdr, NULL, file_);
qDebug("Updater: %s", qPrintable(http_->currentRequest().toString()
.replace("\r\n", "\nUpdater: ")));
}
@ -124,4 +130,30 @@ bool Updater::isVersionNewer(QString newVersion, QString curVersion)
return false;
}
QString Updater::userAgent()
{
QString ua = QString("Mozilla/5.0 (%1) %2/%3 (Qt/%6)")
.arg(sysInfo())
.arg(QCoreApplication::instance()->applicationName())
.arg(version)
.arg(qVersion());
return ua;
}
QString Updater::sysInfo()
{
#if defined(Q_OS_WIN32)
return QString("Windows/0x%1").arg(QSysInfo::WindowsVersion, 0, 16);
#elif defined(Q_OS_LINUX)
return QString("Linux");
#elif defined(Q_OS_MAC)
return QString("MacOSX/0x%1").arg(QSysInfo::MacintoshVersion, 0, 16);
#elif defined(Q_OS_BSD4)
return QString("BSD");
#elif defined(Q_OS_UNIX)
return QString("Unix");
#else
return QString("Unknown");
#endif
}

View File

@ -44,6 +44,9 @@ private slots:
void parseXml(int id, bool error);
private:
QString userAgent();
QString sysInfo();
QHttp *http_;
QTemporaryFile *file_;
};