author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 01:19:32 +0300 | |
changeset 37 | 758a864f9613 |
parent 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
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 |
** 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 |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
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. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qnetworkaccessdatabackend_p.h" |
|
43 |
#include "qnetworkrequest.h" |
|
44 |
#include "qnetworkreply.h" |
|
45 |
#include "qurlinfo.h" |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
46 |
#include "private/qdataurl_p.h" |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
47 |
#include <qcoreapplication.h> |
0 | 48 |
|
49 |
QT_BEGIN_NAMESPACE |
|
50 |
||
51 |
QNetworkAccessBackend * |
|
52 |
QNetworkAccessDataBackendFactory::create(QNetworkAccessManager::Operation, |
|
53 |
const QNetworkRequest &request) const |
|
54 |
{ |
|
55 |
if (request.url().scheme() == QLatin1String("data")) |
|
56 |
return new QNetworkAccessDataBackend; |
|
57 |
||
58 |
return 0; |
|
59 |
} |
|
60 |
||
61 |
QNetworkAccessDataBackend::QNetworkAccessDataBackend() |
|
62 |
{ |
|
63 |
} |
|
64 |
||
65 |
QNetworkAccessDataBackend::~QNetworkAccessDataBackend() |
|
66 |
{ |
|
67 |
} |
|
68 |
||
69 |
void QNetworkAccessDataBackend::open() |
|
70 |
{ |
|
71 |
QUrl uri = request().url(); |
|
72 |
||
73 |
if (operation() != QNetworkAccessManager::GetOperation && |
|
74 |
operation() != QNetworkAccessManager::HeadOperation) { |
|
75 |
// data: doesn't support anything but GET |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
76 |
const QString msg = QCoreApplication::translate("QNetworkAccessDataBackend", |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
77 |
"Operation not supported on %1") |
0 | 78 |
.arg(uri.toString()); |
79 |
error(QNetworkReply::ContentOperationNotPermittedError, msg); |
|
80 |
finished(); |
|
81 |
return; |
|
82 |
} |
|
83 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
84 |
QPair<QString, QByteArray> decoded = qDecodeDataUrl(uri); |
0 | 85 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
86 |
if (! decoded.first.isNull()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
87 |
setHeader(QNetworkRequest::ContentTypeHeader, decoded.first); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
88 |
setHeader(QNetworkRequest::ContentLengthHeader, decoded.second.size()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
89 |
emit metaDataChanged(); |
0 | 90 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
91 |
QByteDataBuffer list; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
92 |
list.append(decoded.second); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
93 |
decoded.second.clear(); // important because of implicit sharing! |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
94 |
writeDownstreamData(list); |
0 | 95 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
96 |
finished(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
97 |
return; |
0 | 98 |
} |
99 |
||
100 |
// something wrong with this URI |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
101 |
const QString msg = QCoreApplication::translate("QNetworkAccessDataBackend", |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
102 |
"Invalid URI: %1").arg(uri.toString()); |
0 | 103 |
error(QNetworkReply::ProtocolFailure, msg); |
104 |
finished(); |
|
105 |
} |
|
106 |
||
107 |
void QNetworkAccessDataBackend::closeDownstreamChannel() |
|
108 |
{ |
|
109 |
} |
|
110 |
||
111 |
void QNetworkAccessDataBackend::closeUpstreamChannel() |
|
112 |
{ |
|
113 |
} |
|
114 |
||
115 |
bool QNetworkAccessDataBackend::waitForDownstreamReadyRead(int) |
|
116 |
{ |
|
117 |
return false; |
|
118 |
} |
|
119 |
||
120 |
bool QNetworkAccessDataBackend::waitForUpstreamBytesWritten(int) |
|
121 |
{ |
|
122 |
return false; |
|
123 |
} |
|
124 |
||
125 |
QT_END_NAMESPACE |