This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goclient. commit d02396443b667e3c2217aebc257ca515bcf2e402 Author: Josh Lukens <jlukens@botch.com> Date: Mon Mar 3 11:45:19 2014 +0100 Switch to QNetworkAccessManager. --- debian/changelog | 4 ++ httpbrokerclient.cpp | 113 +++++++++++++++++++++++++------------------------- httpbrokerclient.h | 23 +++++----- 3 files changed, 74 insertions(+), 66 deletions(-) diff --git a/debian/changelog b/debian/changelog index 42c5799..896cde6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -13,6 +13,10 @@ x2goclient (4.0.2.0-0x2go1) UNRELEASED; urgency=low - Don't show GUI dialog for --version, --help, etc, if started from terminal on linux and mac. - If no user in session config, display system username in pass form. + + [ Josh Lukens ] + * New upstream version (4.0.2.0): + - Switch to QNetworkAccessManager. [ Mike Gabriel ] * debian/control: diff --git a/httpbrokerclient.cpp b/httpbrokerclient.cpp index 4ca8e5d..fca59b4 100644 --- a/httpbrokerclient.cpp +++ b/httpbrokerclient.cpp @@ -16,8 +16,11 @@ ***************************************************************************/ #include "httpbrokerclient.h" +#include <QNetworkAccessManager> #include <QUrl> -#include <QHttp> +#include <QNetworkRequest> +#include <QNetworkReply> +#include <QUuid> #include <QTextStream> #include <QFile> #include <QDir> @@ -34,6 +37,7 @@ #include <QTemporaryFile> #include <QInputDialog> + HttpBrokerClient::HttpBrokerClient ( ONMainWindow* wnd, ConfigFile* cfg ) { config=cfg; @@ -56,30 +60,19 @@ HttpBrokerClient::HttpBrokerClient ( ONMainWindow* wnd, ConfigFile* cfg ) { sshBroker=false; - http=new QHttp ( this ); + if ((config->brokerCaCertFile.length() >0) && (QFile::exists(config->brokerCaCertFile))) { + QSslSocket::addDefaultCaCertificates(config->brokerCaCertFile, QSsl::Pem); + x2goDebug<<"Custom CA certificate file loaded into HTTPS broker client: "<<config->brokerCaCertFile; + } - if ( config->brokerurl.indexOf ( "https://" ) ==0 ) { - if ((config->brokerCaCertFile.length() >0) && (QFile::exists(config->brokerCaCertFile))) { + http=new QNetworkAccessManager ( this ); + x2goDebug<<"Setting up connection to broker: "<<config->brokerurl; - sslSocket = new QSslSocket(this); - connect ( sslSocket, SIGNAL ( sslErrors ( const QList<QSslError>& ) ),this, - SLOT ( slotSslErrors ( const QList<QSslError>& ) ) ); - http->setSocket(sslSocket); - sslSocket->addCaCertificates(config->brokerCaCertFile, QSsl::Pem); - x2goDebug<<"Custom CA certificate file loaded into HTTPS broker client: "<<config->brokerCaCertFile; + connect ( http, SIGNAL ( sslErrors ( QNetworkReply*, const QList<QSslError>& ) ),this, + SLOT ( slotSslErrors ( QNetworkReply*, const QList<QSslError>& ) ) ); - } else { - connect ( http, SIGNAL ( sslErrors ( const QList<QSslError>& ) ),this, - SLOT ( slotSslErrors ( const QList<QSslError>& ) ) ); - } - http->setHost ( lurl.host(),QHttp::ConnectionModeHttps, - lurl.port ( 443 ) ); - } else { - http->setHost ( lurl.host(),QHttp::ConnectionModeHttp, - lurl.port ( 80 ) ); - } - connect ( http,SIGNAL ( requestFinished ( int,bool ) ),this, - SLOT ( slotRequestFinished ( int,bool ) ) ); + connect ( http,SIGNAL ( finished (QNetworkReply*) ),this, + SLOT ( slotRequestFinished (QNetworkReply*) ) ); } } @@ -248,6 +241,7 @@ void HttpBrokerClient::slotSshUserAuthError(QString error) void HttpBrokerClient::getUserSessions() { QString brokerUser=config->brokerUser; + x2goDebug<<"called getUserSessions: brokeruser: "<<brokerUser<<" authid: "<<config->brokerUserId; if(mainWindow->getUsePGPCard()) brokerUser=mainWindow->getCardLogin(); config->sessiondata=QString::null; @@ -259,10 +253,11 @@ void HttpBrokerClient::getUserSessions() "user="<<brokerUser<<"&"<< "password="<<config->brokerPass<<"&"<< "authid="<<config->brokerUserId; - QUrl lurl ( config->brokerurl ); - httpSessionAnswer.close(); - httpSessionAnswer.setData ( 0,0 ); - sessionsRequest=http->post ( lurl.path(),req.toUtf8(),&httpSessionAnswer ); + + x2goDebug << "sending request: "<< req.toUtf8(); + QNetworkRequest request(QUrl(config->brokerurl)); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); + sessionsRequest=http->post (request, req.toUtf8() ); } else { @@ -283,6 +278,7 @@ void HttpBrokerClient::getUserSessions() void HttpBrokerClient::selectUserSession(const QString& session) { + x2goDebug<<"called selectUserSessions"; QString brokerUser=config->brokerUser; if(mainWindow->getUsePGPCard()) brokerUser=mainWindow->getCardLogin(); @@ -296,10 +292,11 @@ void HttpBrokerClient::selectUserSession(const QString& session) "user="<<brokerUser<<"&"<< "password="<<config->brokerPass<<"&"<< "authid="<<config->brokerUserId; - QUrl lurl ( config->brokerurl ); - httpSessionAnswer.close(); - httpSessionAnswer.setData ( 0,0 ); - selSessRequest=http->post ( lurl.path(),req.toUtf8(),&httpSessionAnswer ); + x2goDebug << "sending request: "<< req.toUtf8(); + QNetworkRequest request(QUrl(config->brokerurl)); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); + sessionsRequest=http->post (request, req.toUtf8() ); + } else { @@ -330,10 +327,10 @@ void HttpBrokerClient::changePassword(QString newPass) "user="<<brokerUser<<"&"<< "password="<<config->brokerPass<<"&"<< "authid="<<config->brokerUserId; - QUrl lurl ( config->brokerurl ); - httpSessionAnswer.close(); - httpSessionAnswer.setData ( 0,0 ); - chPassRequest=http->post ( lurl.path(),req.toUtf8(),&httpSessionAnswer ); + x2goDebug << "sending request: "<< req.toUtf8(); + QNetworkRequest request(QUrl(config->brokerurl)); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); + sessionsRequest=http->post (request, req.toUtf8() ); } else { @@ -349,16 +346,16 @@ void HttpBrokerClient::changePassword(QString newPass) void HttpBrokerClient::testConnection() { + x2goDebug<<"called testConnection"; if(!sshBroker) { QString req; QTextStream ( &req ) << "task=testcon"; - QUrl lurl ( config->brokerurl ); - httpSessionAnswer.close(); - httpSessionAnswer.setData ( 0,0 ); - requestTime.start(); - testConRequest=http->post ( lurl.path(),req.toUtf8(),&httpSessionAnswer ); + x2goDebug << "sending request: "<< req.toUtf8(); + QNetworkRequest request(QUrl(config->brokerurl)); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); + sessionsRequest=http->post (request, req.toUtf8() ); } else { @@ -392,6 +389,7 @@ void HttpBrokerClient::createIniFile(const QString& raw_content) bool HttpBrokerClient::checkAccess(QString answer ) { + x2goDebug<<"called checkAccess - answer was: "<<answer; if (answer.indexOf("Access granted")==-1) { QMessageBox::critical ( @@ -408,6 +406,7 @@ bool HttpBrokerClient::checkAccess(QString answer ) void HttpBrokerClient::slotConnectionTest(bool success, QString answer, int) { + x2goDebug<<"called slotConnectionTest"; if(!success) { x2goDebug<<answer; @@ -419,8 +418,8 @@ void HttpBrokerClient::slotConnectionTest(bool success, QString answer, int) return; if(!sshBroker) { - x2goDebug<<"elapsed: "<<requestTime.elapsed()<<"received:"<<httpSessionAnswer.size()<<endl; - emit connectionTime(requestTime.elapsed(),httpSessionAnswer.size()); + x2goDebug<<"elapsed: "<<requestTime.elapsed()<<"received:"<<answer.size()<<endl; + emit connectionTime(requestTime.elapsed(),answer.size()); } return; @@ -471,36 +470,38 @@ void HttpBrokerClient::slotSelectSession(bool success, QString answer, int) } -void HttpBrokerClient::slotRequestFinished ( int id, bool error ) +void HttpBrokerClient::slotRequestFinished ( QNetworkReply* reply ) { -// x2goDebug<<"http request "<<id<<", finished with: "<<error; - - if ( error ) + if(reply->error() != QNetworkReply::NoError) { - x2goDebug<<http->errorString(); - QMessageBox::critical(0,tr("Error"),http->errorString()); + x2goDebug<<"Broker HTTP request failed with error: "<<reply->errorString(); + QMessageBox::critical(0,tr("Error"),reply->errorString()); emit fatalHttpError(); return; } - QString answer ( httpSessionAnswer.data() ); - x2goDebug<<"cmd request answer: "<<answer; - if (id==testConRequest) + QString answer ( reply->readAll() ); + x2goDebug<<"A http request returned. Result was: "<<answer; + if (reply == testConRequest) { slotConnectionTest(true,answer,0); } - if (id == sessionsRequest) + if (reply == sessionsRequest) { slotListSessions(true, answer,0); } - if (id == selSessRequest) + if (reply == selSessRequest) { slotSelectSession(true,answer,0); } - if ( id == chPassRequest) + if (reply == chPassRequest) { slotPassChanged(true,answer,0); } + + // We receive ownership of the reply object + // and therefore need to handle deletion. + reply->deleteLater(); } void HttpBrokerClient::parseSession(QString sinfo) @@ -537,7 +538,7 @@ void HttpBrokerClient::parseSession(QString sinfo) } -void HttpBrokerClient::slotSslErrors ( const QList<QSslError> & errors ) +void HttpBrokerClient::slotSslErrors ( QNetworkReply* netReply, const QList<QSslError> & errors ) { QStringList err; QSslCertificate cert; @@ -564,7 +565,7 @@ void HttpBrokerClient::slotSslErrors ( const QList<QSslError> & errors ) QSslCertificate mcert ( &fl ); if ( mcert==cert ) { - http->ignoreSslErrors(); + netReply->ignoreSslErrors(); requestTime.restart(); return; } @@ -635,7 +636,7 @@ void HttpBrokerClient::slotSslErrors ( const QList<QSslError> & errors ) fl.open ( QIODevice::WriteOnly | QIODevice::Text ); QTextStream ( &fl ) <<cert.toPem(); fl.close(); - http->ignoreSslErrors(); + netReply->ignoreSslErrors(); x2goDebug<<"store certificate in "<<homeDir+"/.x2go/ssl/exceptions/"+ lurl.host() +"/"+fname; requestTime.restart(); diff --git a/httpbrokerclient.h b/httpbrokerclient.h index 4ea4a3d..8a772df 100644 --- a/httpbrokerclient.h +++ b/httpbrokerclient.h @@ -18,6 +18,10 @@ #ifndef HTTPBROKERCLIENT_H #define HTTPBROKERCLIENT_H #include "x2goclientconfig.h" +#include <QNetworkAccessManager> +#include <QUrl> +#include <QNetworkRequest> +#include <QNetworkReply> #include <QSslError> #include <QBuffer> #include <QObject> @@ -27,7 +31,7 @@ /** @author Oleksandr Shneyder <oleksandr.shneyder@obviously-nice.de> */ -class QHttp; +class QNetworkAccessManager; struct ConfigFile; class ONMainWindow; @@ -41,14 +45,13 @@ public: void changePassword(QString newPass); void testConnection(); private: - QBuffer httpCmdAnswer; - QBuffer httpSessionAnswer; - QHttp* http; + QNetworkAccessManager* http; + QNetworkRequest* netRequest; QSslSocket* sslSocket; - int sessionsRequest; - int selSessRequest; - int chPassRequest; - int testConRequest; + QNetworkReply* sessionsRequest; + QNetworkReply* selSessRequest; + QNetworkReply* chPassRequest; + QNetworkReply* testConRequest; QString newBrokerPass; ConfigFile* config; ONMainWindow* mainWindow; @@ -62,8 +65,8 @@ private: bool checkAccess(QString answer); private slots: - void slotRequestFinished ( int id, bool error ); - void slotSslErrors ( const QList<QSslError> & errors ) ; + void slotRequestFinished ( QNetworkReply* reply ); + void slotSslErrors ( QNetworkReply* netReply, const QList<QSslError> & errors ) ; QString getHexVal ( const QByteArray& ba ); void slotSshConnectionError ( QString message, QString lastSessionError ); void slotSshServerAuthError ( int error, QString sshMessage, SshMasterConnection* connection ); -- Alioth's /srv/git/_hooks_/post-receive-email on /srv/git/code.x2go.org/x2goclient.git