source: trunk/src/network/access/qnetworkaccessbackend_p.h@ 123

Last change on this file since 123 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 7.5 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtNetwork module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QNETWORKACCESSBACKEND_P_H
43#define QNETWORKACCESSBACKEND_P_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
56#include "qnetworkreplyimpl_p.h"
57#include "QtCore/qobject.h"
58
59QT_BEGIN_NAMESPACE
60
61class QAuthenticator;
62class QNetworkProxy;
63class QNetworkProxyQuery;
64class QNetworkRequest;
65class QUrl;
66class QUrlInfo;
67class QSslConfiguration;
68
69class QNetworkAccessManagerPrivate;
70class QNetworkReplyImplPrivate;
71class QAbstractNetworkCache;
72class QNetworkCacheMetaData;
73
74// Should support direct file upload from disk or download to disk.
75//
76// - The HTTP handler will use two QIODevices for communication (pull mechanism)
77// - KIO uses a pull mechanism too (data/dataReq signals)
78class QNetworkAccessBackend : public QObject
79{
80 Q_OBJECT
81public:
82 QNetworkAccessBackend();
83 virtual ~QNetworkAccessBackend();
84
85 // To avoid mistaking with QIODevice names, the functions here
86 // have different names. The Connection has two streams:
87 //
88 // - Upstream:
89 // Upstream is data that is being written into this connection,
90 // from the user. Upstream operates in a "pull" mechanism: the
91 // connection will be notified that there is more data available
92 // by a call to "upstreamReadyRead". The number of bytes
93 // available is given by upstreamBytesAvailable(). A call to
94 // readUpstream() always yields the entire upstream buffer. When
95 // the connection has processed a certain amount of bytes from
96 // that buffer, it should call upstreamBytesConsumed().
97 //
98 // - Downstream:
99 // Downstream is the data that is being read from this
100 // connection and is given to the user. Downstream operates in a
101 // semi-"push" mechanism: the Connection object pushes the data
102 // it gets from the network, but it should avoid writing too
103 // much if the data isn't being used fast enough. The value
104 // returned by suggestedDownstreamBlockSize() can be used to
105 // determine how much should be written at a time. The
106 // downstreamBytesConsumed() function will be called when the
107 // downstream buffer is consumed by the user -- the Connection
108 // may choose to re-fill it with more data it has ready or get
109 // more data from the network (for instance, by reading from its
110 // socket).
111
112 virtual void open() = 0;
113 virtual void closeDownstreamChannel() = 0;
114 virtual void closeUpstreamChannel() = 0;
115 virtual bool waitForDownstreamReadyRead(int msecs) = 0;
116 virtual bool waitForUpstreamBytesWritten(int msecs) = 0;
117
118 // slot-like:
119 virtual void upstreamReadyRead();
120 virtual void downstreamReadyWrite();
121 virtual void copyFinished(QIODevice *);
122 virtual void ignoreSslErrors();
123
124 virtual void fetchSslConfiguration(QSslConfiguration &configuration) const;
125 virtual void setSslConfiguration(const QSslConfiguration &configuration);
126
127 virtual QNetworkCacheMetaData fetchCacheMetaData(const QNetworkCacheMetaData &metaData) const;
128
129 // information about the request
130 QNetworkAccessManager::Operation operation() const;
131 QNetworkRequest request() const;
132#ifndef QT_NO_NETWORKPROXY
133 QList<QNetworkProxy> proxyList() const;
134#endif
135
136 QAbstractNetworkCache *networkCache() const;
137 void setCachingEnabled(bool enable);
138 bool isCachingEnabled() const;
139
140 // information about the reply
141 QUrl url() const;
142 void setUrl(const QUrl &url);
143
144 // "cooked" headers
145 QVariant header(QNetworkRequest::KnownHeaders header) const;
146 void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value);
147
148 // raw headers:
149 bool hasRawHeader(const QByteArray &headerName) const;
150 QList<QByteArray> rawHeaderList() const;
151 QByteArray rawHeader(const QByteArray &headerName) const;
152 void setRawHeader(const QByteArray &headerName, const QByteArray &value);
153
154 // attributes:
155 QVariant attribute(QNetworkRequest::Attribute code) const;
156 void setAttribute(QNetworkRequest::Attribute code, const QVariant &value);
157
158protected:
159 // these functions control the upstream mechanism
160 // that is, data coming into the backend and out via the connection
161 qint64 upstreamBytesAvailable() const;
162 void upstreamBytesConsumed(qint64 count);
163 QByteArray readUpstream();
164
165 // these functions control the downstream mechanism
166 // that is, data that has come via the connection and is going out the backend
167 qint64 nextDownstreamBlockSize() const;
168 qint64 downstreamBytesToConsume() const;
169 void writeDownstreamData(const QByteArray &data);
170 void writeDownstreamData(QIODevice *data);
171
172protected slots:
173 void finished();
174 void error(QNetworkReply::NetworkError code, const QString &errorString);
175#ifndef QT_NO_NETWORKPROXY
176 void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth);
177#endif
178 void authenticationRequired(QAuthenticator *auth);
179 void metaDataChanged();
180 void redirectionRequested(const QUrl &destination);
181 void sslErrors(const QList<QSslError> &errors);
182
183private:
184 friend class QNetworkAccessManager;
185 friend class QNetworkAccessManagerPrivate;
186 QNetworkAccessManagerPrivate *manager;
187 QNetworkReplyImplPrivate *reply;
188};
189
190class QNetworkAccessBackendFactory
191{
192public:
193 QNetworkAccessBackendFactory();
194 virtual ~QNetworkAccessBackendFactory();
195 virtual QNetworkAccessBackend *create(QNetworkAccessManager::Operation op,
196 const QNetworkRequest &request) const = 0;
197};
198
199QT_END_NAMESPACE
200
201#endif
202
Note: See TracBrowser for help on using the repository browser.