1
1
/****************************************************************************
3
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
4
5
** Contact: Nokia Corporation (qt-info@nokia.com)
6
7
** This file is part of the QtNetwork module of the Qt Toolkit.
8
9
** $QT_BEGIN_LICENSE:LGPL$
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.
10
** No Commercial Usage
11
** This file contains pre-release code and may not be distributed.
12
** You may use this file in accordance with the terms and conditions
13
** contained in the Technology Preview License Agreement accompanying
15
16
** GNU Lesser General Public License Usage
16
17
** Alternatively, this file may be used under the terms of the GNU Lesser
20
21
** ensure the GNU Lesser General Public License version 2.1 requirements
21
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
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
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.
36
** If you are unsure which license is appropriate for your use, please
37
** contact the sales department at http://www.qtsoftware.com/contact.
24
** In addition, as a special exception, Nokia gives you certain additional
25
** rights. These rights are described in the Nokia Qt LGPL Exception
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
38
38
** $QT_END_LICENSE$
40
40
****************************************************************************/
108
109
QString fileName = url.toLocalFile();
109
110
if (fileName.isEmpty()) {
110
111
if (url.scheme() == QLatin1String("qrc"))
111
fileName = QLatin1String(":") + url.path();
112
fileName = QLatin1Char(':') + url.path();
113
114
fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery);
127
128
case QNetworkAccessManager::PutOperation:
128
129
mode = QIODevice::WriteOnly | QIODevice::Truncate;
130
uploadByteDevice = createUploadByteDevice();
131
QObject::connect(uploadByteDevice, SIGNAL(readyRead()), this, SLOT(uploadReadyReadSlot()));
132
QMetaObject::invokeMethod(this, "uploadReadyReadSlot", Qt::QueuedConnection);
131
135
Q_ASSERT_X(false, "QNetworkAccessFileBackend::open",
159
void QNetworkAccessFileBackend::uploadReadyReadSlot()
161
if (hasUploadFinished)
166
const char *readPointer = uploadByteDevice->readPointer(-1, haveRead);
167
if (haveRead == -1) {
169
hasUploadFinished = true;
174
} else if (haveRead == 0 || readPointer == 0) {
175
// nothing to read right now, we will be called again later
179
haveWritten = file.write(readPointer, haveRead);
181
if (haveWritten < 0) {
183
QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Write error writing to %1: %2")
184
.arg(url().toString(), file.errorString());
185
error(QNetworkReply::ProtocolFailure, msg);
190
uploadByteDevice->advanceReadPointer(haveWritten);
155
199
void QNetworkAccessFileBackend::closeDownstreamChannel()
157
201
if (operation() == QNetworkAccessManager::GetOperation) {
159
//downstreamChannelClosed();
163
void QNetworkAccessFileBackend::closeUpstreamChannel()
165
if (operation() == QNetworkAccessManager::PutOperation) {
174
209
return readMoreFromFile();
177
bool QNetworkAccessFileBackend::waitForUpstreamBytesWritten(int)
179
Q_ASSERT_X(false, "QNetworkAccessFileBackend::waitForUpstreamBytesWritten",
180
"This function should never have been called, since there is never anything "
181
"left to be written!");
185
void QNetworkAccessFileBackend::upstreamReadyRead()
187
Q_ASSERT_X(operation() == QNetworkAccessManager::PutOperation, "QNetworkAccessFileBackend",
188
"We're being told to upload data but operation isn't PUT!");
190
// there's more data to be written to the file
191
while (upstreamBytesAvailable()) {
192
// write everything and let QFile handle it
193
int written = file.write(readUpstream());
197
QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Write error writing to %1: %2")
198
.arg(url().toString(), file.errorString());
199
error(QNetworkReply::ProtocolFailure, msg);
207
upstreamBytesConsumed(written);
211
212
void QNetworkAccessFileBackend::downstreamReadyWrite()
213
214
Q_ASSERT_X(operation() == QNetworkAccessManager::GetOperation, "QNetworkAccessFileBackend",
263
264
data.resize(actuallyRead);
264
265
totalBytes += actuallyRead;
265
writeDownstreamData(data);
267
QByteDataBuffer list;
269
data.clear(); // important because of implicit sharing!
270
writeDownstreamData(list);