Qt 4.8
qhttpnetworkconnectionchannel_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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_OPENSSL
73 # include <QtNetwork/qsslsocket.h>
74 # include <QtNetwork/qsslerror.h>
75 #else
76 # include <QtNetwork/qtcpsocket.h>
77 #endif
78 
80 
82 class QHttpNetworkReply;
83 class QByteArray;
84 
85 #ifndef HttpMessagePair
87 #endif
88 
90  Q_OBJECT
91 public:
92  enum ChannelState {
93  IdleState = 0, // ready to send request
94  ConnectingState = 1, // connecting to host
95  WritingState = 2, // writing the data
96  WaitingState = 4, // waiting for reply
97  ReadingState = 8, // reading the reply
100  };
102  bool ssl;
104  QHttpNetworkRequest request; // current request
105  QHttpNetworkReply *reply; // current reply for this request
109  int lastStatus; // last status received on this channel
110  bool pendingEncrypt; // for https (send after encrypted)
111  int reconnectAttempts; // maximum 2 reconnection attempts
118 #ifndef QT_NO_OPENSSL
121 #endif
122 #ifndef QT_NO_BEARERMANAGEMENT
124 #endif
125 
126  // HTTP pipelining -> http://en.wikipedia.org/wiki/Http_pipelining
128  PipeliningSupportUnknown, // default for a new connection
129  PipeliningProbablySupported, // after having received a server response that indicates support
130  PipeliningNotSupported // currently not used
131  };
134  QByteArray pipeline; // temporary buffer that gets sent to socket in pipelineFlush
135  void pipelineInto(HttpMessagePair &pair);
136  void pipelineFlush();
139 
141 
144 
145  void init();
146  void close();
147 
148  bool sendRequest();
149 
150  bool ensureConnection();
151 
152  bool expand(bool dataComplete);
153  void allDone(); // reply header + body have been read
154  void handleStatus(); // called from allDone()
155 
156  bool resetUploadData(); // return true if resetting worked or there is no upload data
157 
158  void handleUnexpectedEOF();
160 
161  bool isSocketBusy() const;
162  bool isSocketWriting() const;
163  bool isSocketWaiting() const;
164  bool isSocketReading() const;
165 
167 
168  protected slots:
169  void _q_receiveReply();
170  void _q_bytesWritten(qint64 bytes); // proceed sending
171  void _q_readyRead(); // pending data to read
172  void _q_disconnected(); // disconnected from host
173  void _q_connected(); // start sending request
174  void _q_error(QAbstractSocket::SocketError); // error from socket
175 #ifndef QT_NO_NETWORKPROXY
176  void _q_proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth); // from transparent proxy
177 #endif
178 
179  void _q_uploadDataReadyRead();
180 
181 #ifndef QT_NO_OPENSSL
182  void _q_encrypted(); // start sending request (https)
183  void _q_sslErrors(const QList<QSslError> &errors); // ssl errors from the socket
184  void _q_encryptedBytesWritten(qint64 bytes); // proceed sending
185 #endif
186 };
187 
189 
190 #endif // QT_NO_HTTP
191 
192 #endif
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QAuthenticatorPrivate::Method authMethod
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void _q_sslErrors(const QList< QSslError > &errors)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
void _q_error(QAbstractSocket::SocketError)
The QNetworkProxy class provides a network layer proxy.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QSharedPointer< QNetworkSession > networkSession
QPointer< QHttpNetworkConnection > connection
SocketError
This enum describes the socket errors that can occur.
__int64 qint64
Definition: qglobal.h:942
#define Q_OBJECT
Definition: qobjectdefs.h:157
The QAuthenticator class provides an authentication object.
void _q_proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth)
#define slots
Definition: qobjectdefs.h:68
The QAbstractSocket class provides the base functionality common to all socket types.
void setConnection(QHttpNetworkConnection *c)
QPair< QHttpNetworkRequest, QHttpNetworkReply * > HttpMessagePair
QAuthenticatorPrivate::Method proxyAuthMethod