| @@ -0,0 +1,301 @@ | ||
| /**************************************************************************** | ||
| ** | ||
| ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). | ||
| ** Contact: http://www.qt-project.org/legal | ||
| ** | ||
| ** This file is part of the QtNetwork module of the Qt Toolkit. | ||
| ** | ||
| ** $QT_BEGIN_LICENSE:LGPL$ | ||
| ** Commercial License Usage | ||
| ** Licensees holding valid commercial Qt licenses may use this file in | ||
| ** accordance with the commercial license agreement provided with the | ||
| ** Software or, alternatively, in accordance with the terms contained in | ||
| ** a written agreement between you and Digia. For licensing terms and | ||
| ** conditions see http://qt.digia.com/licensing. For further information | ||
| ** use the contact form at http://qt.digia.com/contact-us. | ||
| ** | ||
| ** GNU Lesser General Public License Usage | ||
| ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| ** General Public License version 2.1 as published by the Free Software | ||
| ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| ** packaging of this file. Please review the following information to | ||
| ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| ** | ||
| ** In addition, as a special exception, Digia gives you certain additional | ||
| ** rights. These rights are described in the Digia Qt LGPL Exception | ||
| ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| ** | ||
| ** GNU General Public License Usage | ||
| ** Alternatively, this file may be used under the terms of the GNU | ||
| ** General Public License version 3.0 as published by the Free Software | ||
| ** Foundation and appearing in the file LICENSE.GPL included in the | ||
| ** packaging of this file. Please review the following information to | ||
| ** ensure the GNU General Public License version 3.0 requirements will be | ||
| ** met: http://www.gnu.org/copyleft/gpl.html. | ||
| ** | ||
| ** | ||
| ** $QT_END_LICENSE$ | ||
| ** | ||
| ****************************************************************************/ | ||
|
|
||
| #ifndef QHTTP_H | ||
| #define QHTTP_H | ||
|
|
||
| #include <QtCore/qobject.h> | ||
| #include <QtCore/qstringlist.h> | ||
| #include <QtCore/qmap.h> | ||
| #include <QtCore/qpair.h> | ||
| #include <QtCore/qscopedpointer.h> | ||
|
|
||
| QT_BEGIN_HEADER | ||
|
|
||
| class QTcpSocket; | ||
| class QTimerEvent; | ||
| class QIODevice; | ||
| class QAuthenticator; | ||
| class QNetworkProxy; | ||
| class QSslError; | ||
|
|
||
| class QHttpPrivate; | ||
|
|
||
| class QHttpHeaderPrivate; | ||
| class QHttpHeader | ||
| { | ||
| public: | ||
| QHttpHeader(); | ||
| QHttpHeader(const QHttpHeader &header); | ||
| QHttpHeader(const QString &str); | ||
| virtual ~QHttpHeader(); | ||
|
|
||
| QHttpHeader &operator=(const QHttpHeader &h); | ||
|
|
||
| void setValue(const QString &key, const QString &value); | ||
| void setValues(const QList<QPair<QString, QString> > &values); | ||
| void addValue(const QString &key, const QString &value); | ||
| QList<QPair<QString, QString> > values() const; | ||
| bool hasKey(const QString &key) const; | ||
| QStringList keys() const; | ||
| QString value(const QString &key) const; | ||
| QStringList allValues(const QString &key) const; | ||
| void removeValue(const QString &key); | ||
| void removeAllValues(const QString &key); | ||
|
|
||
| // ### Qt 5: change to qint64 | ||
| bool hasContentLength() const; | ||
| uint contentLength() const; | ||
| void setContentLength(int len); | ||
|
|
||
| bool hasContentType() const; | ||
| QString contentType() const; | ||
| void setContentType(const QString &type); | ||
|
|
||
| virtual QString toString() const; | ||
| bool isValid() const; | ||
|
|
||
| virtual int majorVersion() const = 0; | ||
| virtual int minorVersion() const = 0; | ||
|
|
||
| protected: | ||
| virtual bool parseLine(const QString &line, int number); | ||
| bool parse(const QString &str); | ||
| void setValid(bool); | ||
|
|
||
| QHttpHeader(QHttpHeaderPrivate &dd, const QString &str = QString()); | ||
| QHttpHeader(QHttpHeaderPrivate &dd, const QHttpHeader &header); | ||
| QScopedPointer<QHttpHeaderPrivate> d_ptr; | ||
|
|
||
| private: | ||
| Q_DECLARE_PRIVATE(QHttpHeader) | ||
| }; | ||
|
|
||
| class QHttpResponseHeaderPrivate; | ||
| class QHttpResponseHeader : public QHttpHeader | ||
| { | ||
| public: | ||
| QHttpResponseHeader(); | ||
| QHttpResponseHeader(const QHttpResponseHeader &header); | ||
| QHttpResponseHeader(const QString &str); | ||
| QHttpResponseHeader(int code, const QString &text = QString(), int majorVer = 1, int minorVer = 1); | ||
| QHttpResponseHeader &operator=(const QHttpResponseHeader &header); | ||
|
|
||
| void setStatusLine(int code, const QString &text = QString(), int majorVer = 1, int minorVer = 1); | ||
|
|
||
| int statusCode() const; | ||
| QString reasonPhrase() const; | ||
|
|
||
| int majorVersion() const; | ||
| int minorVersion() const; | ||
|
|
||
| QString toString() const; | ||
|
|
||
| protected: | ||
| bool parseLine(const QString &line, int number); | ||
|
|
||
| private: | ||
| Q_DECLARE_PRIVATE(QHttpResponseHeader) | ||
| friend class QHttpPrivate; | ||
| }; | ||
|
|
||
| class QHttpRequestHeaderPrivate; | ||
| class QHttpRequestHeader : public QHttpHeader | ||
| { | ||
| public: | ||
| QHttpRequestHeader(); | ||
| QHttpRequestHeader(const QString &method, const QString &path, int majorVer = 1, int minorVer = 1); | ||
| QHttpRequestHeader(const QHttpRequestHeader &header); | ||
| QHttpRequestHeader(const QString &str); | ||
| QHttpRequestHeader &operator=(const QHttpRequestHeader &header); | ||
|
|
||
| void setRequest(const QString &method, const QString &path, int majorVer = 1, int minorVer = 1); | ||
|
|
||
| QString method() const; | ||
| QString path() const; | ||
|
|
||
| int majorVersion() const; | ||
| int minorVersion() const; | ||
|
|
||
| QString toString() const; | ||
|
|
||
| protected: | ||
| bool parseLine(const QString &line, int number); | ||
|
|
||
| private: | ||
| Q_DECLARE_PRIVATE(QHttpRequestHeader) | ||
| }; | ||
|
|
||
| class QHttp : public QObject | ||
| { | ||
| Q_OBJECT | ||
|
|
||
| public: | ||
| enum ConnectionMode { | ||
| ConnectionModeHttp, | ||
| ConnectionModeHttps | ||
| }; | ||
|
|
||
| explicit QHttp(QObject *parent = 0); | ||
| QHttp(const QString &hostname, quint16 port = 80, QObject *parent = 0); | ||
| QHttp(const QString &hostname, ConnectionMode mode, quint16 port = 0, QObject *parent = 0); | ||
| virtual ~QHttp(); | ||
|
|
||
| enum State { | ||
| Unconnected, | ||
| HostLookup, | ||
| Connecting, | ||
| Sending, | ||
| Reading, | ||
| Connected, | ||
| Closing | ||
| }; | ||
| enum Error { | ||
| NoError, | ||
| UnknownError, | ||
| HostNotFound, | ||
| ConnectionRefused, | ||
| UnexpectedClose, | ||
| InvalidResponseHeader, | ||
| WrongContentLength, | ||
| Aborted, | ||
| AuthenticationRequiredError, | ||
| ProxyAuthenticationRequiredError | ||
| }; | ||
|
|
||
| int setHost(const QString &hostname, quint16 port = 80); | ||
| int setHost(const QString &hostname, ConnectionMode mode, quint16 port = 0); | ||
|
|
||
| int setSocket(QTcpSocket *socket); | ||
| int setUser(const QString &username, const QString &password = QString()); | ||
|
|
||
| #ifndef QT_NO_NETWORKPROXY | ||
| int setProxy(const QString &host, int port, | ||
| const QString &username = QString(), | ||
| const QString &password = QString()); | ||
| int setProxy(const QNetworkProxy &proxy); | ||
| #endif | ||
|
|
||
| int get(const QString &path, QIODevice *to=0); | ||
| int post(const QString &path, QIODevice *data, QIODevice *to=0 ); | ||
| int post(const QString &path, const QByteArray &data, QIODevice *to=0); | ||
| int head(const QString &path); | ||
| int request(const QHttpRequestHeader &header, QIODevice *device=0, QIODevice *to=0); | ||
| int request(const QHttpRequestHeader &header, const QByteArray &data, QIODevice *to=0); | ||
|
|
||
| int closeConnection(); | ||
| int close(); | ||
|
|
||
| qint64 bytesAvailable() const; | ||
| qint64 read(char *data, qint64 maxlen); | ||
| QByteArray readAll(); | ||
|
|
||
| int currentId() const; | ||
| QIODevice *currentSourceDevice() const; | ||
| QIODevice *currentDestinationDevice() const; | ||
| QHttpRequestHeader currentRequest() const; | ||
| QHttpResponseHeader lastResponse() const; | ||
| bool hasPendingRequests() const; | ||
| void clearPendingRequests(); | ||
|
|
||
| State state() const; | ||
|
|
||
| Error error() const; | ||
| QString errorString() const; | ||
|
|
||
| public Q_SLOTS: | ||
| void abort(); | ||
|
|
||
| #ifndef QT_NO_OPENSSL | ||
| void ignoreSslErrors(); | ||
| #endif | ||
|
|
||
| Q_SIGNALS: | ||
| void stateChanged(int); | ||
| void responseHeaderReceived(const QHttpResponseHeader &resp); | ||
| void readyRead(const QHttpResponseHeader &resp); | ||
|
|
||
| // ### Qt 5: change to qint64 | ||
| void dataSendProgress(int, int); | ||
| void dataReadProgress(int, int); | ||
|
|
||
| void requestStarted(int); | ||
| void requestFinished(int, bool); | ||
| void done(bool); | ||
|
|
||
| #ifndef QT_NO_NETWORKPROXY | ||
| void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *); | ||
| #endif | ||
| void authenticationRequired(const QString &hostname, quint16 port, QAuthenticator *); | ||
|
|
||
| #ifndef QT_NO_OPENSSL | ||
| void sslErrors(const QList<QSslError> &errors); | ||
| #endif | ||
|
|
||
| private: | ||
| Q_DISABLE_COPY(QHttp) | ||
| QScopedPointer<QHttpPrivate> d; | ||
|
|
||
| Q_PRIVATE_SLOT(d, void _q_startNextRequest()) | ||
| Q_PRIVATE_SLOT(d, void _q_slotReadyRead()) | ||
| Q_PRIVATE_SLOT(d, void _q_slotConnected()) | ||
| Q_PRIVATE_SLOT(d, void _q_slotError(QAbstractSocket::SocketError)) | ||
| Q_PRIVATE_SLOT(d, void _q_slotClosed()) | ||
| Q_PRIVATE_SLOT(d, void _q_slotBytesWritten(qint64 numBytes)) | ||
| #ifndef QT_NO_OPENSSL | ||
| Q_PRIVATE_SLOT(d, void _q_slotEncryptedBytesWritten(qint64 numBytes)) | ||
| #endif | ||
| Q_PRIVATE_SLOT(d, void _q_slotDoFinished()) | ||
| Q_PRIVATE_SLOT(d, void _q_slotSendRequest()) | ||
| Q_PRIVATE_SLOT(d, void _q_continuePost()) | ||
|
|
||
| friend class QHttpNormalRequest; | ||
| friend class QHttpSetHostRequest; | ||
| friend class QHttpSetSocketRequest; | ||
| friend class QHttpSetUserRequest; | ||
| friend class QHttpSetProxyRequest; | ||
| friend class QHttpCloseRequest; | ||
| friend class QHttpPGHRequest; | ||
| }; | ||
|
|
||
| QT_END_HEADER | ||
|
|
||
| #endif // QHTTP_H |
| @@ -0,0 +1,15 @@ | ||
| load(qt_build_config) | ||
|
|
||
| TARGET = QtHttp | ||
| CONFIG += static | ||
| CONFIG -= shared | ||
| QT = core network | ||
|
|
||
| MODULE_PRI = ../../modules/qt_http.pri | ||
| MODULE = http | ||
|
|
||
| load(qt_module) | ||
|
|
||
| # Input | ||
| HEADERS += qhttp.h qringbuffer_p.h qhttpauthenticator_p.h | ||
| SOURCES += qhttp.cpp qhttpauthenticator.cpp |
| @@ -0,0 +1,148 @@ | ||
| /**************************************************************************** | ||
| ** | ||
| ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). | ||
| ** Contact: http://www.qt-project.org/legal | ||
| ** | ||
| ** This file is part of the QtNetwork module of the Qt Toolkit. | ||
| ** | ||
| ** $QT_BEGIN_LICENSE:LGPL$ | ||
| ** Commercial License Usage | ||
| ** Licensees holding valid commercial Qt licenses may use this file in | ||
| ** accordance with the commercial license agreement provided with the | ||
| ** Software or, alternatively, in accordance with the terms contained in | ||
| ** a written agreement between you and Digia. For licensing terms and | ||
| ** conditions see http://qt.digia.com/licensing. For further information | ||
| ** use the contact form at http://qt.digia.com/contact-us. | ||
| ** | ||
| ** GNU Lesser General Public License Usage | ||
| ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| ** General Public License version 2.1 as published by the Free Software | ||
| ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| ** packaging of this file. Please review the following information to | ||
| ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| ** | ||
| ** In addition, as a special exception, Digia gives you certain additional | ||
| ** rights. These rights are described in the Digia Qt LGPL Exception | ||
| ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| ** | ||
| ** GNU General Public License Usage | ||
| ** Alternatively, this file may be used under the terms of the GNU | ||
| ** General Public License version 3.0 as published by the Free Software | ||
| ** Foundation and appearing in the file LICENSE.GPL included in the | ||
| ** packaging of this file. Please review the following information to | ||
| ** ensure the GNU General Public License version 3.0 requirements will be | ||
| ** met: http://www.gnu.org/copyleft/gpl.html. | ||
| ** | ||
| ** | ||
| ** $QT_END_LICENSE$ | ||
| ** | ||
| ****************************************************************************/ | ||
|
|
||
| #ifndef QHTTPAUTHENTICATOR_P_H | ||
| #define QHTTPAUTHENTICATOR_P_H | ||
|
|
||
| // | ||
| // W A R N I N G | ||
| // ------------- | ||
| // | ||
| // This file is not part of the Qt API. It exists purely as an | ||
| // implementation detail. This header file may change from version to | ||
| // version without notice, or even be removed. | ||
| // | ||
| // We mean it. | ||
| // | ||
|
|
||
| #include <qhash.h> | ||
| #include <qbytearray.h> | ||
| #include <qstring.h> | ||
| #include <qvariant.h> | ||
| #include <QAuthenticator> | ||
|
|
||
| class QHttpResponseHeader; | ||
|
|
||
| class QHttpAuthenticatorPrivate; | ||
| class QUrl; | ||
|
|
||
| class QHttpAuthenticator | ||
| { | ||
| public: | ||
| QHttpAuthenticator(); | ||
| ~QHttpAuthenticator(); | ||
|
|
||
| QHttpAuthenticator(const QHttpAuthenticator &other); | ||
| QHttpAuthenticator &operator=(const QHttpAuthenticator &other); | ||
|
|
||
| bool operator==(const QHttpAuthenticator &other) const; | ||
| inline bool operator!=(const QHttpAuthenticator &other) const { return !operator==(other); } | ||
|
|
||
| QString user() const; | ||
| void setUser(const QString &user); | ||
|
|
||
| QString password() const; | ||
| void setPassword(const QString &password); | ||
|
|
||
| QString realm() const; | ||
|
|
||
| QVariant option(const QString &opt) const; | ||
| QVariantHash options() const; | ||
| void setOption(const QString &opt, const QVariant &value); | ||
|
|
||
| bool isNull() const; | ||
| void detach(); | ||
|
|
||
| QHttpAuthenticator &operator=(const QAuthenticator& auth); | ||
| QAuthenticator toQAuthenticator(); | ||
| private: | ||
| friend class QHttpAuthenticatorPrivate; | ||
| QHttpAuthenticatorPrivate *d; | ||
| }; | ||
|
|
||
| class QHttpAuthenticatorPrivate | ||
| { | ||
| public: | ||
| enum Method { None, Basic, Plain, Login, Ntlm, CramMd5, DigestMd5 }; | ||
| QHttpAuthenticatorPrivate(); | ||
|
|
||
| QAtomicInt ref; | ||
| QString user; | ||
| QString extractedUser; | ||
| QString password; | ||
| QVariantHash options; | ||
| Method method; | ||
| QString realm; | ||
| QByteArray challenge; | ||
| bool hasFailed; //credentials have been tried but rejected by server. | ||
|
|
||
| enum Phase { | ||
| Start, | ||
| Phase2, | ||
| Done, | ||
| Invalid | ||
| }; | ||
| Phase phase; | ||
|
|
||
| // digest specific | ||
| QByteArray cnonce; | ||
| int nonceCount; | ||
|
|
||
| // ntlm specific | ||
| QString workstation; | ||
| QString userDomain; | ||
|
|
||
| QByteArray calculateResponse(const QByteArray &method, const QByteArray &path); | ||
|
|
||
| inline static QHttpAuthenticatorPrivate *getPrivate(QHttpAuthenticator &auth) { return auth.d; } | ||
| inline static const QHttpAuthenticatorPrivate *getPrivate(const QHttpAuthenticator &auth) { return auth.d; } | ||
|
|
||
| QByteArray digestMd5Response(const QByteArray &challenge, const QByteArray &method, const QByteArray &path); | ||
| static QHash<QByteArray, QByteArray> parseDigestAuthenticationChallenge(const QByteArray &challenge); | ||
|
|
||
| #ifndef QT_NO_HTTP | ||
| void parseHttpResponse(const QHttpResponseHeader &, bool isProxy); | ||
| #endif | ||
| void parseHttpResponse(const QList<QPair<QByteArray, QByteArray> >&, bool isProxy); | ||
|
|
||
| }; | ||
|
|
||
| #endif |
| @@ -0,0 +1,3 @@ | ||
| TEMPLATE = subdirs | ||
|
|
||
| SUBDIRS += qhttp |
| @@ -0,0 +1,23 @@ | ||
| %modules = ( # path to module name map | ||
| "QtHttp" => "$basedir/src/qhttp", | ||
| ); | ||
| %moduleheaders = ( # restrict the module headers to those found in relative path | ||
| ); | ||
| %classnames = ( | ||
| ); | ||
| %mastercontent = ( | ||
| "core" => "#include <QtCore/QtCore>\n", | ||
| "network" => "#include <QtNetwork/QtNetwork>\n", | ||
| ); | ||
| %modulepris = ( | ||
| "QtHttp" => "$basedir/modules/qt_http.pri", | ||
| ); | ||
| # Module dependencies. | ||
| # Every module that is required to build this module should have one entry. | ||
| # Each of the module version specifiers can take one of the following values: | ||
| # - A specific Git revision. | ||
| # - any git symbolic ref resolvable from the module's repository (e.g. "refs/heads/master" to track master branch) | ||
| # | ||
| %dependencies = ( | ||
| "qtbase" => "refs/heads/master", | ||
| ); |
| @@ -0,0 +1,5 @@ | ||
| TEMPLATE = subdirs | ||
|
|
||
| SUBDIRS += headersclean | ||
| SUBDIRS += qhttp | ||
| SUBDIRS += cmake |
| @@ -0,0 +1,14 @@ | ||
|
|
||
| cmake_minimum_required(VERSION 2.8) | ||
|
|
||
| project(qmake_cmake_files) | ||
|
|
||
| enable_testing() | ||
|
|
||
| find_package(Qt5Core REQUIRED) | ||
|
|
||
| include("${_Qt5CTestMacros}") | ||
|
|
||
| test_module_includes( | ||
| Http QHttp | ||
| ) |
| @@ -0,0 +1,7 @@ | ||
|
|
||
| # Cause make to do nothing. | ||
| TEMPLATE = subdirs | ||
|
|
||
| CMAKE_QT_MODULES_UNDER_TEST = http | ||
|
|
||
| CONFIG += ctest_testcase |
| @@ -0,0 +1,3 @@ | ||
| QT = core testlib http | ||
| include($${QT.core.sources}/../../tests/auto/other/headersclean/headersclean.pri) | ||
| DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 |
| @@ -0,0 +1,52 @@ | ||
| /**************************************************************************** | ||
| ** | ||
| ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). | ||
| ** Contact: http://www.qt-project.org/legal | ||
| ** | ||
| ** This file is part of the test suite of the Qt Toolkit. | ||
| ** | ||
| ** $QT_BEGIN_LICENSE:LGPL$ | ||
| ** Commercial License Usage | ||
| ** Licensees holding valid commercial Qt licenses may use this file in | ||
| ** accordance with the commercial license agreement provided with the | ||
| ** Software or, alternatively, in accordance with the terms contained in | ||
| ** a written agreement between you and Digia. For licensing terms and | ||
| ** conditions see http://qt.digia.com/licensing. For further information | ||
| ** use the contact form at http://qt.digia.com/contact-us. | ||
| ** | ||
| ** GNU Lesser General Public License Usage | ||
| ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| ** General Public License version 2.1 as published by the Free Software | ||
| ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| ** packaging of this file. Please review the following information to | ||
| ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| ** | ||
| ** In addition, as a special exception, Digia gives you certain additional | ||
| ** rights. These rights are described in the Digia Qt LGPL Exception | ||
| ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| ** | ||
| ** GNU General Public License Usage | ||
| ** Alternatively, this file may be used under the terms of the GNU | ||
| ** General Public License version 3.0 as published by the Free Software | ||
| ** Foundation and appearing in the file LICENSE.GPL included in the | ||
| ** packaging of this file. Please review the following information to | ||
| ** ensure the GNU General Public License version 3.0 requirements will be | ||
| ** met: http://www.gnu.org/copyleft/gpl.html. | ||
| ** | ||
| ** | ||
| ** $QT_END_LICENSE$ | ||
| ** | ||
| ****************************************************************************/ | ||
|
|
||
| #ifndef QT_HEADERSCLEAN_HEADERS | ||
| #define QT_HEADERSCLEAN_HEADERS | ||
|
|
||
| /* | ||
| This file should include all the headers to be tested by the headersclean | ||
| test. It may be copied and customized for each module. | ||
| */ | ||
|
|
||
| #include <QtHttp/QtHttp> | ||
|
|
||
| #endif |
| @@ -0,0 +1,160 @@ | ||
| /**************************************************************************** | ||
| ** | ||
| ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). | ||
| ** Contact: http://www.qt-project.org/legal | ||
| ** | ||
| ** This file is part of the test suite of the Qt Toolkit. | ||
| ** | ||
| ** $QT_BEGIN_LICENSE:LGPL$ | ||
| ** Commercial License Usage | ||
| ** Licensees holding valid commercial Qt licenses may use this file in | ||
| ** accordance with the commercial license agreement provided with the | ||
| ** Software or, alternatively, in accordance with the terms contained in | ||
| ** a written agreement between you and Digia. For licensing terms and | ||
| ** conditions see http://qt.digia.com/licensing. For further information | ||
| ** use the contact form at http://qt.digia.com/contact-us. | ||
| ** | ||
| ** GNU Lesser General Public License Usage | ||
| ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| ** General Public License version 2.1 as published by the Free Software | ||
| ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| ** packaging of this file. Please review the following information to | ||
| ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| ** | ||
| ** In addition, as a special exception, Digia gives you certain additional | ||
| ** rights. These rights are described in the Digia Qt LGPL Exception | ||
| ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| ** | ||
| ** GNU General Public License Usage | ||
| ** Alternatively, this file may be used under the terms of the GNU | ||
| ** General Public License version 3.0 as published by the Free Software | ||
| ** Foundation and appearing in the file LICENSE.GPL included in the | ||
| ** packaging of this file. Please review the following information to | ||
| ** ensure the GNU General Public License version 3.0 requirements will be | ||
| ** met: http://www.gnu.org/copyleft/gpl.html. | ||
| ** | ||
| ** | ||
| ** $QT_END_LICENSE$ | ||
| ** | ||
| ****************************************************************************/ | ||
|
|
||
| #include <QString> | ||
| #ifdef QT_NETWORK_LIB | ||
| #include <QtNetwork/QHostInfo> | ||
| #endif | ||
|
|
||
| class QtNetworkSettings | ||
| { | ||
| public: | ||
|
|
||
| static QString serverLocalName() | ||
| { | ||
| return QString("qt-test-server"); | ||
| } | ||
| static QString serverDomainName() | ||
| { | ||
| return QString("qt-test-net"); | ||
| } | ||
| static QString serverName() | ||
| { | ||
| return serverLocalName() + "." + serverDomainName(); | ||
| } | ||
| static QString winServerName() | ||
| { | ||
| return serverName(); | ||
| } | ||
| static QString wildcardServerName() | ||
| { | ||
| return "qt-test-server.wildcard.dev." + serverDomainName(); | ||
| } | ||
|
|
||
| #ifdef QT_NETWORK_LIB | ||
| static QHostAddress serverIP() | ||
| { | ||
| return QHostInfo::fromName(serverName()).addresses().first(); | ||
| } | ||
| #endif | ||
|
|
||
| static bool compareReplyIMAP(QByteArray const& actual) | ||
| { | ||
| QList<QByteArray> expected; | ||
|
|
||
| // Mandriva; old test server | ||
| expected << QByteArray( "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] " ) | ||
| .append(QtNetworkSettings::serverName().toAscii()) | ||
| .append(" Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n"); | ||
|
|
||
| // Ubuntu 10.04; new test server | ||
| expected << QByteArray( "* OK " ) | ||
| .append(QtNetworkSettings::serverLocalName().toAscii()) | ||
| .append(" Cyrus IMAP4 v2.2.13-Debian-2.2.13-19 server ready\r\n"); | ||
|
|
||
| // Feel free to add more as needed | ||
|
|
||
| Q_FOREACH (QByteArray const& ba, expected) { | ||
| if (ba == actual) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| static bool compareReplyIMAPSSL(QByteArray const& actual) | ||
| { | ||
| QList<QByteArray> expected; | ||
|
|
||
| // Mandriva; old test server | ||
| expected << QByteArray( "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID AUTH=PLAIN SASL-IR] " ) | ||
| .append(QtNetworkSettings::serverName().toAscii()) | ||
| .append(" Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n"); | ||
|
|
||
| // Ubuntu 10.04; new test server | ||
| expected << QByteArray( "* OK " ) | ||
| .append(QtNetworkSettings::serverLocalName().toAscii()) | ||
| .append(" Cyrus IMAP4 v2.2.13-Debian-2.2.13-19 server ready\r\n"); | ||
|
|
||
| // Feel free to add more as needed | ||
|
|
||
| Q_FOREACH (QByteArray const& ba, expected) { | ||
| if (ba == actual) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| static bool compareReplyFtp(QByteArray const& actual) | ||
| { | ||
| QList<QByteArray> expected; | ||
|
|
||
| // A few different vsFTPd versions. | ||
| // Feel free to add more as needed | ||
| expected << QByteArray( "220 (vsFTPd 2.0.5)\r\n221 Goodbye.\r\n" ); | ||
| expected << QByteArray( "220 (vsFTPd 2.2.2)\r\n221 Goodbye.\r\n" ); | ||
|
|
||
| Q_FOREACH (QByteArray const& ba, expected) { | ||
| if (ba == actual) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| #ifdef QT_NETWORK_LIB | ||
| static bool verifyTestNetworkSettings() | ||
| { | ||
| QHostInfo testServerResult = QHostInfo::fromName(QtNetworkSettings::serverName()); | ||
| if (testServerResult.error() != QHostInfo::NoError) { | ||
| qWarning() << "Could not lookup" << QtNetworkSettings::serverName(); | ||
| qWarning() << "Please configure the test environment!"; | ||
| qWarning() << "See /etc/hosts or network-settings.h"; | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| #endif | ||
| }; |
| @@ -0,0 +1 @@ | ||
| rfc3252.txt -crlf |
| @@ -0,0 +1 @@ | ||
| tst_qhttp |
| @@ -0,0 +1,114 @@ | ||
| /**************************************************************************** | ||
| ** | ||
| ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). | ||
| ** Contact: http://www.qt-project.org/legal | ||
| ** | ||
| ** This file is part of the test suite of the Qt Toolkit. | ||
| ** | ||
| ** $QT_BEGIN_LICENSE:LGPL$ | ||
| ** Commercial License Usage | ||
| ** Licensees holding valid commercial Qt licenses may use this file in | ||
| ** accordance with the commercial license agreement provided with the | ||
| ** Software or, alternatively, in accordance with the terms contained in | ||
| ** a written agreement between you and Digia. For licensing terms and | ||
| ** conditions see http://qt.digia.com/licensing. For further information | ||
| ** use the contact form at http://qt.digia.com/contact-us. | ||
| ** | ||
| ** GNU Lesser General Public License Usage | ||
| ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| ** General Public License version 2.1 as published by the Free Software | ||
| ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| ** packaging of this file. Please review the following information to | ||
| ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| ** | ||
| ** In addition, as a special exception, Digia gives you certain additional | ||
| ** rights. These rights are described in the Digia Qt LGPL Exception | ||
| ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| ** | ||
| ** GNU General Public License Usage | ||
| ** Alternatively, this file may be used under the terms of the GNU | ||
| ** General Public License version 3.0 as published by the Free Software | ||
| ** Foundation and appearing in the file LICENSE.GPL included in the | ||
| ** packaging of this file. Please review the following information to | ||
| ** ensure the GNU General Public License version 3.0 requirements will be | ||
| ** met: http://www.gnu.org/copyleft/gpl.html. | ||
| ** | ||
| ** | ||
| ** $QT_END_LICENSE$ | ||
| ** | ||
| ****************************************************************************/ | ||
| // Use if you need | ||
|
|
||
| class DummyHttpServer : public QTcpServer | ||
| { | ||
| Q_OBJECT | ||
| public: | ||
| DummyHttpServer() : phase(Header) | ||
| { listen(); } | ||
|
|
||
| protected: | ||
| enum { | ||
| Header, | ||
| Data1, | ||
| Data2, | ||
| Close | ||
| } phase; | ||
| void incomingConnection(int socketDescriptor) | ||
| { | ||
| QSslSocket *socket = new QSslSocket(this); | ||
| socket->setSocketDescriptor(socketDescriptor, QAbstractSocket::ConnectedState); | ||
| socket->ignoreSslErrors(); | ||
| socket->startServerEncryption(); | ||
| connect(socket, SIGNAL(readyRead()), SLOT(handleReadyRead())); | ||
| } | ||
|
|
||
| public slots: | ||
| void handleReadyRead() | ||
| { | ||
| QTcpSocket *socket = static_cast<QTcpSocket *>(sender()); | ||
| socket->readAll(); | ||
| if (phase != Header) | ||
| return; | ||
|
|
||
| phase = Data1; | ||
| static const char header[] = | ||
| "HTTP/1.0 200 OK\r\n" | ||
| "Date: Fri, 07 Sep 2007 12:33:18 GMT\r\n" | ||
| "Server: Apache\r\n" | ||
| "Expires:\r\n" | ||
| "Cache-Control:\r\n" | ||
| "Pragma:\r\n" | ||
| "Last-Modified: Thu, 06 Sep 2007 08:52:06 +0000\r\n" | ||
| "Etag: a700f59a6ccb1ad39af68d998aa36fb1\r\n" | ||
| "Vary: Accept-Encoding\r\n" | ||
| "Content-Length: 6560\r\n" | ||
| "Connection: close\r\n" | ||
| "Content-Type: text/html; charset=utf-8\r\n" | ||
| "\r\n"; | ||
|
|
||
|
|
||
| socket->write(header, sizeof header - 1); | ||
| connect(socket, SIGNAL(bytesWritten(qint64)), SLOT(handleBytesWritten()), Qt::QueuedConnection); | ||
| } | ||
|
|
||
| void handleBytesWritten() | ||
| { | ||
| QTcpSocket *socket = static_cast<QTcpSocket *>(sender()); | ||
| if (socket->bytesToWrite() != 0) | ||
| return; | ||
|
|
||
| if (phase == Data1) { | ||
| QByteArray data(4096, 'a'); | ||
| socket->write(data); | ||
| phase = Data2; | ||
| } else if (phase == Data2) { | ||
| QByteArray data(2464, 'a'); | ||
| socket->write(data); | ||
| phase = Close; | ||
| } else { | ||
| //socket->disconnectFromHost(); | ||
| //socket->deleteLater(); | ||
| } | ||
| } | ||
| }; |
| @@ -0,0 +1,23 @@ | ||
| CONFIG += testcase | ||
| SOURCES += tst_qhttp.cpp | ||
| INCLUDEPATH += "../../../include" | ||
|
|
||
| QT = core network testlib http | ||
|
|
||
| TARGET = tst_qhttp | ||
|
|
||
| wince*: { | ||
| webFiles.files = webserver/* | ||
| webFiles.path = webserver | ||
| cgi.files = webserver/cgi-bin/* | ||
| cgi.path = webserver/cgi-bin | ||
| addFiles.files = rfc3252.txt testhtml | ||
| addFiles.path = . | ||
| DEPLOYMENT += addFiles webFiles cgi | ||
| DEFINES += SRCDIR=\\\"\\\" | ||
| } else:vxworks*: { | ||
| DEFINES += SRCDIR=\\\"\\\" | ||
| } else { | ||
| DEFINES += SRCDIR=\\\"$$PWD/\\\" | ||
| } | ||
| DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 |
| @@ -0,0 +1,8 @@ | ||
| <html> | ||
| <head> | ||
| <title>Test</title> | ||
| </head> | ||
| <body> | ||
| <h1>Test</h1> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,6 @@ | ||
| #!/bin/sh | ||
|
|
||
| echo "Content-type: text/plain"; | ||
| echo | ||
| cat testfile | ||
| echo "no file retrieved" > testfile |
| @@ -0,0 +1,5 @@ | ||
| #!/bin/sh | ||
|
|
||
| echo "Content-type: text/plain"; | ||
| echo | ||
| cat ../rfc3252 |
| @@ -0,0 +1,6 @@ | ||
| #!/bin/sh | ||
|
|
||
| echo "Content-type: text/plain"; | ||
| echo | ||
| echo "file stored under 'testfile'" | ||
| cat > testfile |
| @@ -0,0 +1,3 @@ | ||
| TEMPLATE = subdirs | ||
|
|
||
| SUBDIRS += auto |
| @@ -6,6 +6,7 @@ include_directories( | ||
| ${ZLIB_INCLUDE_DIR} | ||
| ${PYTHON_INCLUDE_DIRS} | ||
| ${XercesC_INCLUDE_DIRS} | ||
| ${QTHTTP_INCLUDE_DIR} | ||
| ) | ||
|
|
||
| set(WebGui_LIBS | ||