~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to src/network/access/qhttpnetworkconnectionchannel_p.h

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the QtNetwork module of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
9
** Commercial License Usage
 
10
** Licensees holding valid commercial Qt licenses may use this file in
 
11
** accordance with the commercial license agreement provided with the
 
12
** Software or, alternatively, in accordance with the terms contained in
 
13
** a written agreement between you and Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/contact-us.
 
16
**
 
17
** GNU Lesser General Public License Usage
 
18
** Alternatively, this file may be used under the terms of the GNU Lesser
 
19
** General Public License version 2.1 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL included in the
 
21
** packaging of this file.  Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 2.1 requirements
 
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#ifndef QHTTPNETWORKCONNECTIONCHANNEL_H
 
43
#define QHTTPNETWORKCONNECTIONCHANNEL_H
 
44
 
 
45
//
 
46
//  W A R N I N G
 
47
//  -------------
 
48
//
 
49
// This file is not part of the Qt API.  It exists for the convenience
 
50
// of the Network Access API.  This header file may change from
 
51
// version to version without notice, or even be removed.
 
52
//
 
53
// We mean it.
 
54
//
 
55
#include <QtNetwork/qnetworkrequest.h>
 
56
#include <QtNetwork/qnetworkreply.h>
 
57
#include <QtNetwork/qabstractsocket.h>
 
58
 
 
59
#include <private/qobject_p.h>
 
60
#include <qauthenticator.h>
 
61
#include <qnetworkproxy.h>
 
62
#include <qbuffer.h>
 
63
 
 
64
#include <private/qhttpnetworkheader_p.h>
 
65
#include <private/qhttpnetworkrequest_p.h>
 
66
#include <private/qhttpnetworkreply_p.h>
 
67
 
 
68
#include <private/qhttpnetworkconnection_p.h>
 
69
 
 
70
#ifndef QT_NO_HTTP
 
71
 
 
72
#ifndef QT_NO_SSL
 
73
#    include <QtNetwork/qsslsocket.h>
 
74
#    include <QtNetwork/qsslerror.h>
 
75
#    include <QtNetwork/qsslconfiguration.h>
 
76
#else
 
77
#   include <QtNetwork/qtcpsocket.h>
 
78
#endif
 
79
 
 
80
QT_BEGIN_NAMESPACE
 
81
 
 
82
class QHttpNetworkRequest;
 
83
class QHttpNetworkReply;
 
84
class QByteArray;
 
85
 
 
86
#ifndef HttpMessagePair
 
87
typedef QPair<QHttpNetworkRequest, QHttpNetworkReply*> HttpMessagePair;
 
88
#endif
 
89
 
 
90
class QHttpNetworkConnectionChannel : public QObject {
 
91
    Q_OBJECT
 
92
public:
 
93
    enum ChannelState {
 
94
        IdleState = 0,          // ready to send request
 
95
        ConnectingState = 1,    // connecting to host
 
96
        WritingState = 2,       // writing the data
 
97
        WaitingState = 4,       // waiting for reply
 
98
        ReadingState = 8,       // reading the reply
 
99
        ClosingState = 16,
 
100
        BusyState = (ConnectingState|WritingState|WaitingState|ReadingState|ClosingState)
 
101
    };
 
102
    QAbstractSocket *socket;
 
103
    bool ssl;
 
104
    bool isInitialized;
 
105
    ChannelState state;
 
106
    QHttpNetworkRequest request; // current request
 
107
    QHttpNetworkReply *reply; // current reply for this request
 
108
    qint64 written;
 
109
    qint64 bytesTotal;
 
110
    bool resendCurrent;
 
111
    int lastStatus; // last status received on this channel
 
112
    bool pendingEncrypt; // for https (send after encrypted)
 
113
    int reconnectAttempts; // maximum 2 reconnection attempts
 
114
    QAuthenticatorPrivate::Method authMethod;
 
115
    QAuthenticatorPrivate::Method proxyAuthMethod;
 
116
    QAuthenticator authenticator;
 
117
    QAuthenticator proxyAuthenticator;
 
118
    bool authenticationCredentialsSent;
 
119
    bool proxyCredentialsSent;
 
120
#ifndef QT_NO_SSL
 
121
    bool ignoreAllSslErrors;
 
122
    QList<QSslError> ignoreSslErrorsList;
 
123
    QSslConfiguration sslConfiguration;
 
124
    void ignoreSslErrors();
 
125
    void ignoreSslErrors(const QList<QSslError> &errors);
 
126
    void setSslConfiguration(const QSslConfiguration &config);
 
127
#endif
 
128
#ifndef QT_NO_BEARERMANAGEMENT
 
129
    QSharedPointer<QNetworkSession> networkSession;
 
130
#endif
 
131
 
 
132
    // HTTP pipelining -> http://en.wikipedia.org/wiki/Http_pipelining
 
133
    enum PipeliningSupport {
 
134
        PipeliningSupportUnknown, // default for a new connection
 
135
        PipeliningProbablySupported, // after having received a server response that indicates support
 
136
        PipeliningNotSupported // currently not used
 
137
    };
 
138
    PipeliningSupport pipeliningSupported;
 
139
    QList<HttpMessagePair> alreadyPipelinedRequests;
 
140
    QByteArray pipeline; // temporary buffer that gets sent to socket in pipelineFlush
 
141
    void pipelineInto(HttpMessagePair &pair);
 
142
    void pipelineFlush();
 
143
    void requeueCurrentlyPipelinedRequests();
 
144
    void detectPipeliningSupport();
 
145
 
 
146
    QHttpNetworkConnectionChannel();
 
147
 
 
148
    QAbstractSocket::NetworkLayerProtocol networkLayerPreference;
 
149
    
 
150
    void setConnection(QHttpNetworkConnection *c);
 
151
    QPointer<QHttpNetworkConnection> connection;
 
152
 
 
153
#ifndef QT_NO_NETWORKPROXY
 
154
    QNetworkProxy proxy;
 
155
    void setProxy(const QNetworkProxy &networkProxy);
 
156
#endif
 
157
 
 
158
    void init();
 
159
    void close();
 
160
 
 
161
    bool sendRequest();
 
162
 
 
163
    bool ensureConnection();
 
164
 
 
165
    void allDone(); // reply header + body have been read
 
166
    void handleStatus(); // called from allDone()
 
167
 
 
168
    bool resetUploadData(); // return true if resetting worked or there is no upload data
 
169
 
 
170
    void handleUnexpectedEOF();
 
171
    void closeAndResendCurrentRequest();
 
172
 
 
173
    bool isSocketBusy() const;
 
174
    bool isSocketWriting() const;
 
175
    bool isSocketWaiting() const;
 
176
    bool isSocketReading() const;
 
177
 
 
178
    protected slots:
 
179
    void _q_receiveReply();
 
180
    void _q_bytesWritten(qint64 bytes); // proceed sending
 
181
    void _q_readyRead(); // pending data to read
 
182
    void _q_disconnected(); // disconnected from host
 
183
    void _q_connected(); // start sending request
 
184
    void _q_error(QAbstractSocket::SocketError); // error from socket
 
185
#ifndef QT_NO_NETWORKPROXY
 
186
    void _q_proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth); // from transparent proxy
 
187
#endif
 
188
 
 
189
    void _q_uploadDataReadyRead();
 
190
 
 
191
#ifndef QT_NO_SSL
 
192
    void _q_encrypted(); // start sending request (https)
 
193
    void _q_sslErrors(const QList<QSslError> &errors); // ssl errors from the socket
 
194
    void _q_encryptedBytesWritten(qint64 bytes); // proceed sending
 
195
#endif
 
196
};
 
197
 
 
198
QT_END_NAMESPACE
 
199
 
 
200
#endif // QT_NO_HTTP
 
201
 
 
202
#endif