author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 01:19:32 +0300 | |
changeset 37 | 758a864f9613 |
parent 33 | 3e2da88830cd |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
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 "qnetworkaccessmanager.h" |
|
43 |
#include "qnetworkaccessmanager_p.h" |
|
44 |
#include "qnetworkrequest.h" |
|
45 |
#include "qnetworkreply.h" |
|
46 |
#include "qnetworkreply_p.h" |
|
47 |
#include "qnetworkcookie.h" |
|
48 |
#include "qabstractnetworkcache.h" |
|
49 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
50 |
#include "QtNetwork/qnetworksession.h" |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
51 |
|
0 | 52 |
#include "qnetworkaccesshttpbackend_p.h" |
53 |
#include "qnetworkaccessftpbackend_p.h" |
|
54 |
#include "qnetworkaccessfilebackend_p.h" |
|
55 |
#include "qnetworkaccessdatabackend_p.h" |
|
56 |
#include "qnetworkaccessdebugpipebackend_p.h" |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
57 |
#include "qfilenetworkreply_p.h" |
0 | 58 |
|
59 |
#include "QtCore/qbuffer.h" |
|
60 |
#include "QtCore/qurl.h" |
|
61 |
#include "QtCore/qvector.h" |
|
62 |
#include "QtNetwork/qauthenticator.h" |
|
63 |
#include "QtNetwork/qsslconfiguration.h" |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
64 |
#include "QtNetwork/qnetworkconfigmanager.h" |
0 | 65 |
|
66 |
QT_BEGIN_NAMESPACE |
|
67 |
||
68 |
#ifndef QT_NO_HTTP |
|
69 |
Q_GLOBAL_STATIC(QNetworkAccessHttpBackendFactory, httpBackend) |
|
70 |
#endif // QT_NO_HTTP |
|
71 |
Q_GLOBAL_STATIC(QNetworkAccessFileBackendFactory, fileBackend) |
|
72 |
Q_GLOBAL_STATIC(QNetworkAccessDataBackendFactory, dataBackend) |
|
73 |
#ifndef QT_NO_FTP |
|
74 |
Q_GLOBAL_STATIC(QNetworkAccessFtpBackendFactory, ftpBackend) |
|
75 |
#endif // QT_NO_FTP |
|
76 |
||
77 |
#ifdef QT_BUILD_INTERNAL |
|
78 |
Q_GLOBAL_STATIC(QNetworkAccessDebugPipeBackendFactory, debugpipeBackend) |
|
79 |
#endif |
|
80 |
||
81 |
static void ensureInitialized() |
|
82 |
{ |
|
83 |
#ifndef QT_NO_HTTP |
|
84 |
(void) httpBackend(); |
|
85 |
#endif // QT_NO_HTTP |
|
86 |
(void) dataBackend(); |
|
87 |
#ifndef QT_NO_FTP |
|
88 |
(void) ftpBackend(); |
|
89 |
#endif |
|
90 |
||
91 |
#ifdef QT_BUILD_INTERNAL |
|
92 |
(void) debugpipeBackend(); |
|
93 |
#endif |
|
94 |
||
95 |
// leave this one last since it will query the special QAbstractFileEngines |
|
96 |
(void) fileBackend(); |
|
97 |
} |
|
98 |
||
99 |
/*! |
|
100 |
\class QNetworkAccessManager |
|
101 |
\brief The QNetworkAccessManager class allows the application to |
|
102 |
send network requests and receive replies |
|
103 |
\since 4.4 |
|
104 |
||
105 |
\ingroup network |
|
106 |
\inmodule QtNetwork |
|
107 |
\reentrant |
|
108 |
||
109 |
The Network Access API is constructed around one QNetworkAccessManager |
|
110 |
object, which holds the common configuration and settings for the requests |
|
111 |
it sends. It contains the proxy and cache configuration, as well as the |
|
112 |
signals related to such issues, and reply signals that can be used to |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
113 |
monitor the progress of a network operation. One QNetworkAccessManager |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
114 |
should be enough for the whole Qt application. |
0 | 115 |
|
116 |
Once a QNetworkAccessManager object has been created, the application can |
|
117 |
use it to send requests over the network. A group of standard functions |
|
118 |
are supplied that take a request and optional data, and each return a |
|
119 |
QNetworkReply object. The returned object is used to obtain any data |
|
120 |
returned in response to the corresponding request. |
|
121 |
||
122 |
A simple download off the network could be accomplished with: |
|
123 |
\snippet doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp 0 |
|
124 |
||
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
125 |
QNetworkAccessManager has an asynchronous API. |
0 | 126 |
When the \tt replyFinished slot above is called, the parameter it |
127 |
takes is the QNetworkReply object containing the downloaded data |
|
128 |
as well as meta-data (headers, etc.). |
|
129 |
||
130 |
\note After the request has finished, it is the responsibility of the user |
|
131 |
to delete the QNetworkReply object at an appropriate time. Do not directly |
|
132 |
delete it inside the slot connected to finished(). You can use the |
|
133 |
deleteLater() function. |
|
134 |
||
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
135 |
\note QNetworkAccessManager queues the requests it receives. The number |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
136 |
of requests executed in parallel is dependent on the protocol. |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
137 |
Currently, for the HTTP protocol on desktop platforms, 6 requests are |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
138 |
executed in parallel for one host/port combination. |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
139 |
|
0 | 140 |
A more involved example, assuming the manager is already existent, |
141 |
can be: |
|
142 |
\snippet doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp 1 |
|
143 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
144 |
\section1 Network and Roaming support |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
145 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
146 |
With the addition of the \l {Bearer Management} API to Qt 4.7 |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
147 |
QNetworkAccessManager gained the ability to manage network connections. |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
148 |
QNetworkAccessManager can start the network interface if the device is |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
149 |
offline and terminates the interface if the current process is the last |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
150 |
one to use the uplink. Note that some platform utilize grace periods from |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
151 |
when the last application stops using a uplink until the system actually |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
152 |
terminates the connectivity link. Roaming is equally transparent. Any |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
153 |
queued/pending network requests are automatically transferred to new |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
154 |
access point. |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
155 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
156 |
Clients wanting to utilize this feature should not require any changes. In fact |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
157 |
it is likely that existing platform specific connection code can simply be |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
158 |
removed from the application. |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
159 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
160 |
\note The network and roaming support in QNetworkAccessManager is conditional |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
161 |
upon the platform supporting connection management. The |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
162 |
\l QNetworkConfigurationManager::NetworkSessionRequired can be used to |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
163 |
detect whether QNetworkAccessManager utilizes this feature. Currently only |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
164 |
Meego/Harmattan and Symbian platforms provide connection management support. |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
165 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
166 |
\note This feature cannot be used in combination with the Bearer Management |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
167 |
API as provided by QtMobility. Applications have to migrate to the Qt version |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
168 |
of Bearer Management. |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
169 |
|
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
170 |
\section1 Symbian Platform Security Requirements |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
171 |
|
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
172 |
On Symbian, processes which use this class must have the |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
173 |
\c NetworkServices platform security capability. If the client |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
174 |
process lacks this capability, operations will result in a panic. |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
175 |
|
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
176 |
Platform security capabilities are added via the |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
177 |
\l{qmake-variable-reference.html#target-capability}{TARGET.CAPABILITY} |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
178 |
qmake variable. |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
179 |
|
0 | 180 |
\sa QNetworkRequest, QNetworkReply, QNetworkProxy |
181 |
*/ |
|
182 |
||
183 |
/*! |
|
184 |
\enum QNetworkAccessManager::Operation |
|
185 |
||
186 |
Indicates the operation this reply is processing. |
|
187 |
||
188 |
\value HeadOperation retrieve headers operation (created |
|
189 |
with head()) |
|
190 |
||
191 |
\value GetOperation retrieve headers and download contents |
|
192 |
(created with get()) |
|
193 |
||
194 |
\value PutOperation upload contents operation (created |
|
195 |
with put()) |
|
196 |
||
197 |
\value PostOperation send the contents of an HTML form for |
|
198 |
processing via HTTP POST (created with post()) |
|
199 |
||
200 |
\value DeleteOperation delete contents operation (created with |
|
201 |
deleteResource()) |
|
202 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
203 |
\value CustomOperation custom operation (created with |
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
204 |
sendCustomRequest()) \since 4.7 |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
205 |
|
0 | 206 |
\omitvalue UnknownOperation |
207 |
||
208 |
\sa QNetworkReply::operation() |
|
209 |
*/ |
|
210 |
||
211 |
/*! |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
212 |
\enum QNetworkAccessManager::NetworkAccessibility |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
213 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
214 |
Indicates whether the network is accessible via this network access manager. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
215 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
216 |
\value UnknownAccessibility The network accessibility cannot be determined. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
217 |
\value NotAccessible The network is not currently accessible, either because there |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
218 |
is currently no network coverage or network access has been |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
219 |
explicitly disabled by a call to setNetworkAccessible(). |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
220 |
\value Accessible The network is accessible. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
221 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
222 |
\sa networkAccessible |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
223 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
224 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
225 |
/*! |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
226 |
\property QNetworkAccessManager::networkAccessible |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
227 |
\brief whether the network is currently accessible via this network access manager. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
228 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
229 |
\since 4.7 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
230 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
231 |
If the network is \l {NotAccessible}{not accessible} the network access manager will not |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
232 |
process any new network requests, all such requests will fail with an error. Requests with |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
233 |
URLs with the file:// scheme will still be processed. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
234 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
235 |
By default the value of this property reflects the physical state of the device. Applications |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
236 |
may override it to disable all network requests via this network access manager by calling |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
237 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
238 |
\snippet doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp 4 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
239 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
240 |
Network requests can be reenabled again by calling |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
241 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
242 |
\snippet doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp 5 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
243 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
244 |
\note Calling setNetworkAccessible() does not change the network state. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
245 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
246 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
247 |
/*! |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
248 |
\fn void QNetworkAccessManager::networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessible) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
249 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
250 |
This signal is emitted when the value of the \l networkAccessible property changes. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
251 |
\a accessible is the new network accessibility. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
252 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
253 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
254 |
/*! |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
255 |
\fn void QNetworkAccessManager::networkSessionConnected() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
256 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
257 |
\since 4.7 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
258 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
259 |
\internal |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
260 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
261 |
This signal is emitted when the status of the network session changes into a usable (Connected) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
262 |
state. It is used to signal to QNetworkReplys to start or migrate their network operation once |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
263 |
the network session has been opened or finished roaming. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
264 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
265 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
266 |
/*! |
0 | 267 |
\fn void QNetworkAccessManager::proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator) |
268 |
||
269 |
This signal is emitted whenever a proxy requests authentication |
|
270 |
and QNetworkAccessManager cannot find a valid, cached |
|
271 |
credential. The slot connected to this signal should fill in the |
|
272 |
credentials for the proxy \a proxy in the \a authenticator object. |
|
273 |
||
274 |
QNetworkAccessManager will cache the credentials internally. The |
|
275 |
next time the proxy requests authentication, QNetworkAccessManager |
|
276 |
will automatically send the same credential without emitting the |
|
277 |
proxyAuthenticationRequired signal again. |
|
278 |
||
279 |
If the proxy rejects the credentials, QNetworkAccessManager will |
|
280 |
emit the signal again. |
|
281 |
||
282 |
\sa proxy(), setProxy(), authenticationRequired() |
|
283 |
*/ |
|
284 |
||
285 |
/*! |
|
286 |
\fn void QNetworkAccessManager::authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator) |
|
287 |
||
288 |
This signal is emitted whenever a final server requests |
|
289 |
authentication before it delivers the requested contents. The slot |
|
290 |
connected to this signal should fill the credentials for the |
|
291 |
contents (which can be determined by inspecting the \a reply |
|
292 |
object) in the \a authenticator object. |
|
293 |
||
294 |
QNetworkAccessManager will cache the credentials internally and |
|
295 |
will send the same values if the server requires authentication |
|
296 |
again, without emitting the authenticationRequired() signal. If it |
|
297 |
rejects the credentials, this signal will be emitted again. |
|
298 |
||
299 |
\sa proxyAuthenticationRequired() |
|
300 |
*/ |
|
301 |
||
302 |
/*! |
|
303 |
\fn void QNetworkAccessManager::finished(QNetworkReply *reply) |
|
304 |
||
305 |
This signal is emitted whenever a pending network reply is |
|
306 |
finished. The \a reply parameter will contain a pointer to the |
|
307 |
reply that has just finished. This signal is emitted in tandem |
|
308 |
with the QNetworkReply::finished() signal. |
|
309 |
||
310 |
See QNetworkReply::finished() for information on the status that |
|
311 |
the object will be in. |
|
312 |
||
313 |
\note Do not delete the \a reply object in the slot connected to this |
|
314 |
signal. Use deleteLater(). |
|
315 |
||
316 |
\sa QNetworkReply::finished(), QNetworkReply::error() |
|
317 |
*/ |
|
318 |
||
319 |
/*! |
|
320 |
\fn void QNetworkAccessManager::sslErrors(QNetworkReply *reply, const QList<QSslError> &errors) |
|
321 |
||
322 |
This signal is emitted if the SSL/TLS session encountered errors |
|
323 |
during the set up, including certificate verification errors. The |
|
324 |
\a errors parameter contains the list of errors and \a reply is |
|
325 |
the QNetworkReply that is encountering these errors. |
|
326 |
||
327 |
To indicate that the errors are not fatal and that the connection |
|
328 |
should proceed, the QNetworkReply::ignoreSslErrors() function should be called |
|
329 |
from the slot connected to this signal. If it is not called, the |
|
330 |
SSL session will be torn down before any data is exchanged |
|
331 |
(including the URL). |
|
332 |
||
333 |
This signal can be used to display an error message to the user |
|
334 |
indicating that security may be compromised and display the |
|
335 |
SSL settings (see sslConfiguration() to obtain it). If the user |
|
336 |
decides to proceed after analyzing the remote certificate, the |
|
337 |
slot should call ignoreSslErrors(). |
|
338 |
||
339 |
\sa QSslSocket::sslErrors(), QNetworkReply::sslErrors(), |
|
340 |
QNetworkReply::sslConfiguration(), QNetworkReply::ignoreSslErrors() |
|
341 |
*/ |
|
342 |
||
343 |
class QNetworkAuthenticationCredential |
|
344 |
{ |
|
345 |
public: |
|
346 |
QString domain; |
|
347 |
QString user; |
|
348 |
QString password; |
|
349 |
}; |
|
350 |
Q_DECLARE_TYPEINFO(QNetworkAuthenticationCredential, Q_MOVABLE_TYPE); |
|
351 |
inline bool operator<(const QNetworkAuthenticationCredential &t1, const QString &t2) |
|
352 |
{ return t1.domain < t2; } |
|
353 |
||
354 |
class QNetworkAuthenticationCache: private QVector<QNetworkAuthenticationCredential>, |
|
355 |
public QNetworkAccessCache::CacheableObject |
|
356 |
{ |
|
357 |
public: |
|
358 |
QNetworkAuthenticationCache() |
|
359 |
{ |
|
360 |
setExpires(false); |
|
361 |
setShareable(true); |
|
362 |
reserve(1); |
|
363 |
} |
|
364 |
||
365 |
QNetworkAuthenticationCredential *findClosestMatch(const QString &domain) |
|
366 |
{ |
|
367 |
iterator it = qLowerBound(begin(), end(), domain); |
|
368 |
if (it == end() && !isEmpty()) |
|
369 |
--it; |
|
370 |
if (it == end() || !domain.startsWith(it->domain)) |
|
371 |
return 0; |
|
372 |
return &*it; |
|
373 |
} |
|
374 |
||
375 |
void insert(const QString &domain, const QString &user, const QString &password) |
|
376 |
{ |
|
377 |
QNetworkAuthenticationCredential *closestMatch = findClosestMatch(domain); |
|
378 |
if (closestMatch && closestMatch->domain == domain) { |
|
379 |
// we're overriding the current credentials |
|
380 |
closestMatch->user = user; |
|
381 |
closestMatch->password = password; |
|
382 |
} else { |
|
383 |
QNetworkAuthenticationCredential newCredential; |
|
384 |
newCredential.domain = domain; |
|
385 |
newCredential.user = user; |
|
386 |
newCredential.password = password; |
|
387 |
||
388 |
if (closestMatch) |
|
389 |
QVector<QNetworkAuthenticationCredential>::insert(++closestMatch, newCredential); |
|
390 |
else |
|
391 |
QVector<QNetworkAuthenticationCredential>::insert(end(), newCredential); |
|
392 |
} |
|
393 |
} |
|
394 |
||
395 |
virtual void dispose() { delete this; } |
|
396 |
}; |
|
397 |
||
398 |
#ifndef QT_NO_NETWORKPROXY |
|
399 |
static QByteArray proxyAuthenticationKey(const QNetworkProxy &proxy, const QString &realm) |
|
400 |
{ |
|
401 |
QUrl key; |
|
402 |
||
403 |
switch (proxy.type()) { |
|
404 |
case QNetworkProxy::Socks5Proxy: |
|
405 |
key.setScheme(QLatin1String("proxy-socks5")); |
|
406 |
break; |
|
407 |
||
408 |
case QNetworkProxy::HttpProxy: |
|
409 |
case QNetworkProxy::HttpCachingProxy: |
|
410 |
key.setScheme(QLatin1String("proxy-http")); |
|
411 |
break; |
|
412 |
||
413 |
case QNetworkProxy::FtpCachingProxy: |
|
414 |
key.setScheme(QLatin1String("proxy-ftp")); |
|
415 |
break; |
|
416 |
||
417 |
case QNetworkProxy::DefaultProxy: |
|
418 |
case QNetworkProxy::NoProxy: |
|
419 |
// shouldn't happen |
|
420 |
return QByteArray(); |
|
421 |
||
422 |
// no default: |
|
423 |
// let there be errors if a new proxy type is added in the future |
|
424 |
} |
|
425 |
||
426 |
if (key.scheme().isEmpty()) |
|
427 |
// proxy type not handled |
|
428 |
return QByteArray(); |
|
429 |
||
430 |
key.setUserName(proxy.user()); |
|
431 |
key.setHost(proxy.hostName()); |
|
432 |
key.setPort(proxy.port()); |
|
433 |
key.setFragment(realm); |
|
434 |
return "auth:" + key.toEncoded(); |
|
435 |
} |
|
436 |
#endif |
|
437 |
||
438 |
static inline QByteArray authenticationKey(const QUrl &url, const QString &realm) |
|
439 |
{ |
|
440 |
QUrl copy = url; |
|
441 |
copy.setFragment(realm); |
|
442 |
return "auth:" + copy.toEncoded(QUrl::RemovePassword | QUrl::RemovePath | QUrl::RemoveQuery); |
|
443 |
} |
|
444 |
||
445 |
/*! |
|
446 |
Constructs a QNetworkAccessManager object that is the center of |
|
447 |
the Network Access API and sets \a parent as the parent object. |
|
448 |
*/ |
|
449 |
QNetworkAccessManager::QNetworkAccessManager(QObject *parent) |
|
450 |
: QObject(*new QNetworkAccessManagerPrivate, parent) |
|
451 |
{ |
|
452 |
ensureInitialized(); |
|
453 |
} |
|
454 |
||
455 |
/*! |
|
456 |
Destroys the QNetworkAccessManager object and frees up any |
|
457 |
resources. Note that QNetworkReply objects that are returned from |
|
458 |
this class have this object set as their parents, which means that |
|
459 |
they will be deleted along with it if you don't call |
|
460 |
QObject::setParent() on them. |
|
461 |
*/ |
|
462 |
QNetworkAccessManager::~QNetworkAccessManager() |
|
463 |
{ |
|
464 |
#ifndef QT_NO_NETWORKPROXY |
|
465 |
delete d_func()->proxyFactory; |
|
466 |
#endif |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
467 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
468 |
// Delete the QNetworkReply children first. |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
469 |
// Else a QAbstractNetworkCache might get deleted in ~QObject |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
470 |
// before a QNetworkReply that accesses the QAbstractNetworkCache |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
471 |
// object in its destructor. |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
472 |
qDeleteAll(findChildren<QNetworkReply *>()); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
473 |
// The other children will be deleted in this ~QObject |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
474 |
// FIXME instead of this "hack" make the QNetworkReplyImpl |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
475 |
// properly watch the cache deletion, e.g. via a QWeakPointer. |
0 | 476 |
} |
477 |
||
478 |
#ifndef QT_NO_NETWORKPROXY |
|
479 |
/*! |
|
480 |
Returns the QNetworkProxy that the requests sent using this |
|
481 |
QNetworkAccessManager object will use. The default value for the |
|
482 |
proxy is QNetworkProxy::DefaultProxy. |
|
483 |
||
484 |
\sa setProxy(), setProxyFactory(), proxyAuthenticationRequired() |
|
485 |
*/ |
|
486 |
QNetworkProxy QNetworkAccessManager::proxy() const |
|
487 |
{ |
|
488 |
return d_func()->proxy; |
|
489 |
} |
|
490 |
||
491 |
/*! |
|
492 |
Sets the proxy to be used in future requests to be \a proxy. This |
|
493 |
does not affect requests that have already been sent. The |
|
494 |
proxyAuthenticationRequired() signal will be emitted if the proxy |
|
495 |
requests authentication. |
|
496 |
||
497 |
A proxy set with this function will be used for all requests |
|
498 |
issued by QNetworkAccessManager. In some cases, it might be |
|
499 |
necessary to select different proxies depending on the type of |
|
500 |
request being sent or the destination host. If that's the case, |
|
501 |
you should consider using setProxyFactory(). |
|
502 |
||
503 |
\sa proxy(), proxyAuthenticationRequired() |
|
504 |
*/ |
|
505 |
void QNetworkAccessManager::setProxy(const QNetworkProxy &proxy) |
|
506 |
{ |
|
507 |
Q_D(QNetworkAccessManager); |
|
508 |
delete d->proxyFactory; |
|
509 |
d->proxy = proxy; |
|
510 |
d->proxyFactory = 0; |
|
511 |
} |
|
512 |
||
513 |
/*! |
|
514 |
\fn QNetworkProxyFactory *QNetworkAccessManager::proxyFactory() const |
|
515 |
\since 4.5 |
|
516 |
||
517 |
Returns the proxy factory that this QNetworkAccessManager object |
|
518 |
is using to determine the proxies to be used for requests. |
|
519 |
||
520 |
Note that the pointer returned by this function is managed by |
|
521 |
QNetworkAccessManager and could be deleted at any time. |
|
522 |
||
523 |
\sa setProxyFactory(), proxy() |
|
524 |
*/ |
|
525 |
QNetworkProxyFactory *QNetworkAccessManager::proxyFactory() const |
|
526 |
{ |
|
527 |
return d_func()->proxyFactory; |
|
528 |
} |
|
529 |
||
530 |
/*! |
|
531 |
\since 4.5 |
|
532 |
||
533 |
Sets the proxy factory for this class to be \a factory. A proxy |
|
534 |
factory is used to determine a more specific list of proxies to be |
|
535 |
used for a given request, instead of trying to use the same proxy |
|
536 |
value for all requests. |
|
537 |
||
538 |
All queries sent by QNetworkAccessManager will have type |
|
539 |
QNetworkProxyQuery::UrlRequest. |
|
540 |
||
541 |
For example, a proxy factory could apply the following rules: |
|
542 |
\list |
|
543 |
\o if the target address is in the local network (for example, |
|
544 |
if the hostname contains no dots or if it's an IP address in |
|
545 |
the organization's range), return QNetworkProxy::NoProxy |
|
546 |
\o if the request is FTP, return an FTP proxy |
|
547 |
\o if the request is HTTP or HTTPS, then return an HTTP proxy |
|
548 |
\o otherwise, return a SOCKSv5 proxy server |
|
549 |
\endlist |
|
550 |
||
551 |
The lifetime of the object \a factory will be managed by |
|
552 |
QNetworkAccessManager. It will delete the object when necessary. |
|
553 |
||
554 |
\note If a specific proxy is set with setProxy(), the factory will not |
|
555 |
be used. |
|
556 |
||
557 |
\sa proxyFactory(), setProxy(), QNetworkProxyQuery |
|
558 |
*/ |
|
559 |
void QNetworkAccessManager::setProxyFactory(QNetworkProxyFactory *factory) |
|
560 |
{ |
|
561 |
Q_D(QNetworkAccessManager); |
|
562 |
delete d->proxyFactory; |
|
563 |
d->proxyFactory = factory; |
|
564 |
d->proxy = QNetworkProxy(); |
|
565 |
} |
|
566 |
#endif |
|
567 |
||
568 |
/*! |
|
569 |
\since 4.5 |
|
570 |
||
571 |
Returns the cache that is used to store data obtained from the network. |
|
572 |
||
573 |
\sa setCache() |
|
574 |
*/ |
|
575 |
QAbstractNetworkCache *QNetworkAccessManager::cache() const |
|
576 |
{ |
|
577 |
Q_D(const QNetworkAccessManager); |
|
578 |
return d->networkCache; |
|
579 |
} |
|
580 |
||
581 |
/*! |
|
582 |
\since 4.5 |
|
583 |
||
584 |
Sets the manager's network cache to be the \a cache specified. The cache |
|
585 |
is used for all requests dispatched by the manager. |
|
586 |
||
587 |
Use this function to set the network cache object to a class that implements |
|
588 |
additional features, like saving the cookies to permanent storage. |
|
589 |
||
590 |
\note QNetworkAccessManager takes ownership of the \a cache object. |
|
591 |
||
592 |
QNetworkAccessManager by default does not have a set cache. |
|
593 |
Qt provides a simple disk cache, QNetworkDiskCache, which can be used. |
|
594 |
||
595 |
\sa cache(), QNetworkRequest::CacheLoadControl |
|
596 |
*/ |
|
597 |
void QNetworkAccessManager::setCache(QAbstractNetworkCache *cache) |
|
598 |
{ |
|
599 |
Q_D(QNetworkAccessManager); |
|
600 |
if (d->networkCache != cache) { |
|
601 |
delete d->networkCache; |
|
602 |
d->networkCache = cache; |
|
603 |
if (d->networkCache) |
|
604 |
d->networkCache->setParent(this); |
|
605 |
} |
|
606 |
} |
|
607 |
||
608 |
/*! |
|
609 |
Returns the QNetworkCookieJar that is used to store cookies |
|
610 |
obtained from the network as well as cookies that are about to be |
|
611 |
sent. |
|
612 |
||
613 |
\sa setCookieJar() |
|
614 |
*/ |
|
615 |
QNetworkCookieJar *QNetworkAccessManager::cookieJar() const |
|
616 |
{ |
|
617 |
Q_D(const QNetworkAccessManager); |
|
618 |
if (!d->cookieJar) |
|
619 |
d->createCookieJar(); |
|
620 |
return d->cookieJar; |
|
621 |
} |
|
622 |
||
623 |
/*! |
|
624 |
Sets the manager's cookie jar to be the \a cookieJar specified. |
|
625 |
The cookie jar is used by all requests dispatched by the manager. |
|
626 |
||
627 |
Use this function to set the cookie jar object to a class that |
|
628 |
implements additional features, like saving the cookies to permanent |
|
629 |
storage. |
|
630 |
||
631 |
\note QNetworkAccessManager takes ownership of the \a cookieJar object. |
|
632 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
633 |
If \a cookieJar is in the same thread as this QNetworkAccessManager, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
634 |
it will set the parent of the \a cookieJar |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
635 |
so that the cookie jar is deleted when this |
0 | 636 |
object is deleted as well. If you want to share cookie jars |
637 |
between different QNetworkAccessManager objects, you may want to |
|
638 |
set the cookie jar's parent to 0 after calling this function. |
|
639 |
||
640 |
QNetworkAccessManager by default does not implement any cookie |
|
641 |
policy of its own: it accepts all cookies sent by the server, as |
|
642 |
long as they are well formed and meet the minimum security |
|
643 |
requirements (cookie domain matches the request's and cookie path |
|
644 |
matches the request's). In order to implement your own security |
|
645 |
policy, override the QNetworkCookieJar::cookiesForUrl() and |
|
646 |
QNetworkCookieJar::setCookiesFromUrl() virtual functions. Those |
|
647 |
functions are called by QNetworkAccessManager when it detects a |
|
648 |
new cookie. |
|
649 |
||
650 |
\sa cookieJar(), QNetworkCookieJar::cookiesForUrl(), QNetworkCookieJar::setCookiesFromUrl() |
|
651 |
*/ |
|
652 |
void QNetworkAccessManager::setCookieJar(QNetworkCookieJar *cookieJar) |
|
653 |
{ |
|
654 |
Q_D(QNetworkAccessManager); |
|
655 |
d->cookieJarCreated = true; |
|
656 |
if (d->cookieJar != cookieJar) { |
|
657 |
if (d->cookieJar && d->cookieJar->parent() == this) |
|
658 |
delete d->cookieJar; |
|
659 |
d->cookieJar = cookieJar; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
660 |
if (thread() == cookieJar->thread()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
661 |
d->cookieJar->setParent(this); |
0 | 662 |
} |
663 |
} |
|
664 |
||
665 |
/*! |
|
666 |
Posts a request to obtain the network headers for \a request |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
667 |
and returns a new QNetworkReply object which will contain such headers. |
0 | 668 |
|
669 |
The function is named after the HTTP request associated (HEAD). |
|
670 |
*/ |
|
671 |
QNetworkReply *QNetworkAccessManager::head(const QNetworkRequest &request) |
|
672 |
{ |
|
673 |
return d_func()->postProcess(createRequest(QNetworkAccessManager::HeadOperation, request)); |
|
674 |
} |
|
675 |
||
676 |
/*! |
|
677 |
Posts a request to obtain the contents of the target \a request |
|
678 |
and returns a new QNetworkReply object opened for reading which emits the |
|
679 |
\l{QIODevice::readyRead()}{readyRead()} signal whenever new data |
|
680 |
arrives. |
|
681 |
||
682 |
The contents as well as associated headers will be downloaded. |
|
683 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
684 |
\sa post(), put(), deleteResource(), sendCustomRequest() |
0 | 685 |
*/ |
686 |
QNetworkReply *QNetworkAccessManager::get(const QNetworkRequest &request) |
|
687 |
{ |
|
688 |
return d_func()->postProcess(createRequest(QNetworkAccessManager::GetOperation, request)); |
|
689 |
} |
|
690 |
||
691 |
/*! |
|
692 |
Sends an HTTP POST request to the destination specified by \a request |
|
693 |
and returns a new QNetworkReply object opened for reading that will |
|
694 |
contain the reply sent by the server. The contents of the \a data |
|
695 |
device will be uploaded to the server. |
|
696 |
||
697 |
\a data must be open for reading and must remain valid until the |
|
698 |
finished() signal is emitted for this reply. |
|
699 |
||
700 |
\note Sending a POST request on protocols other than HTTP and |
|
701 |
HTTPS is undefined and will probably fail. |
|
702 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
703 |
\sa get(), put(), deleteResource(), sendCustomRequest() |
0 | 704 |
*/ |
705 |
QNetworkReply *QNetworkAccessManager::post(const QNetworkRequest &request, QIODevice *data) |
|
706 |
{ |
|
707 |
return d_func()->postProcess(createRequest(QNetworkAccessManager::PostOperation, request, data)); |
|
708 |
} |
|
709 |
||
710 |
/*! |
|
711 |
\overload |
|
712 |
||
713 |
Sends the contents of the \a data byte array to the destination |
|
714 |
specified by \a request. |
|
715 |
*/ |
|
716 |
QNetworkReply *QNetworkAccessManager::post(const QNetworkRequest &request, const QByteArray &data) |
|
717 |
{ |
|
718 |
QBuffer *buffer = new QBuffer; |
|
719 |
buffer->setData(data); |
|
720 |
buffer->open(QIODevice::ReadOnly); |
|
721 |
||
722 |
QNetworkReply *reply = post(request, buffer); |
|
723 |
buffer->setParent(reply); |
|
724 |
return reply; |
|
725 |
} |
|
726 |
||
727 |
/*! |
|
728 |
Uploads the contents of \a data to the destination \a request and |
|
729 |
returnes a new QNetworkReply object that will be open for reply. |
|
730 |
||
731 |
\a data must be opened for reading when this function is called |
|
732 |
and must remain valid until the finished() signal is emitted for |
|
733 |
this reply. |
|
734 |
||
735 |
Whether anything will be available for reading from the returned |
|
736 |
object is protocol dependent. For HTTP, the server may send a |
|
737 |
small HTML page indicating the upload was successful (or not). |
|
738 |
Other protocols will probably have content in their replies. |
|
739 |
||
740 |
\note For HTTP, this request will send a PUT request, which most servers |
|
741 |
do not allow. Form upload mechanisms, including that of uploading |
|
742 |
files through HTML forms, use the POST mechanism. |
|
743 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
744 |
\sa get(), post(), deleteResource(), sendCustomRequest() |
0 | 745 |
*/ |
746 |
QNetworkReply *QNetworkAccessManager::put(const QNetworkRequest &request, QIODevice *data) |
|
747 |
{ |
|
748 |
return d_func()->postProcess(createRequest(QNetworkAccessManager::PutOperation, request, data)); |
|
749 |
} |
|
750 |
||
751 |
/*! |
|
752 |
\overload |
|
753 |
Sends the contents of the \a data byte array to the destination |
|
754 |
specified by \a request. |
|
755 |
*/ |
|
756 |
QNetworkReply *QNetworkAccessManager::put(const QNetworkRequest &request, const QByteArray &data) |
|
757 |
{ |
|
758 |
QBuffer *buffer = new QBuffer; |
|
759 |
buffer->setData(data); |
|
760 |
buffer->open(QIODevice::ReadOnly); |
|
761 |
||
762 |
QNetworkReply *reply = put(request, buffer); |
|
763 |
buffer->setParent(reply); |
|
764 |
return reply; |
|
765 |
} |
|
766 |
||
767 |
/*! |
|
768 |
\since 4.6 |
|
769 |
||
770 |
Sends a request to delete the resource identified by the URL of \a request. |
|
771 |
||
772 |
\note This feature is currently available for HTTP only, performing an |
|
773 |
HTTP DELETE request. |
|
774 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
775 |
\sa get(), post(), put(), sendCustomRequest() |
0 | 776 |
*/ |
777 |
QNetworkReply *QNetworkAccessManager::deleteResource(const QNetworkRequest &request) |
|
778 |
{ |
|
779 |
return d_func()->postProcess(createRequest(QNetworkAccessManager::DeleteOperation, request)); |
|
780 |
} |
|
781 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
782 |
#ifndef QT_NO_BEARERMANAGEMENT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
783 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
784 |
/*! |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
785 |
\since 4.7 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
786 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
787 |
Sets the network configuration that will be used when creating the |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
788 |
\l {QNetworkSession}{network session} to \a config. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
789 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
790 |
The network configuration is used to create and open a network session before any request that |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
791 |
requires network access is process. If no network configuration is explicitly set via this |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
792 |
function the network configuration returned by |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
793 |
QNetworkConfigurationManager::defaultConfiguration() will be used. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
794 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
795 |
To restore the default network configuration set the network configuration to the value |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
796 |
returned from QNetworkConfigurationManager::defaultConfiguration(). |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
797 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
798 |
\snippet doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp 2 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
799 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
800 |
If an invalid network configuration is set, a network session will not be created. In this |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
801 |
case network requests will be processed regardless, but may fail. For example: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
802 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
803 |
\snippet doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp 3 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
804 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
805 |
\sa configuration(), QNetworkSession |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
806 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
807 |
void QNetworkAccessManager::setConfiguration(const QNetworkConfiguration &config) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
808 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
809 |
d_func()->createSession(config); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
810 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
811 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
812 |
/*! |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
813 |
\since 4.7 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
814 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
815 |
Returns the network configuration that will be used to create the |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
816 |
\l {QNetworkSession}{network session} which will be used when processing network requests. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
817 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
818 |
\sa setConfiguration(), activeConfiguration() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
819 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
820 |
QNetworkConfiguration QNetworkAccessManager::configuration() const |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
821 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
822 |
Q_D(const QNetworkAccessManager); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
823 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
824 |
if (d->networkSession) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
825 |
return d->networkSession->configuration(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
826 |
else |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
827 |
return QNetworkConfiguration(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
828 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
829 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
830 |
/*! |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
831 |
\since 4.7 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
832 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
833 |
Returns the current active network configuration. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
834 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
835 |
If the network configuration returned by configuration() is of type |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
836 |
QNetworkConfiguration::ServiceNetwork this function will return the current active child |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
837 |
network configuration of that configuration. Otherwise returns the same network configuration |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
838 |
as configuration(). |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
839 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
840 |
Use this function to return the actual network configuration currently in use by the network |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
841 |
session. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
842 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
843 |
\sa configuration() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
844 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
845 |
QNetworkConfiguration QNetworkAccessManager::activeConfiguration() const |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
846 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
847 |
Q_D(const QNetworkAccessManager); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
848 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
849 |
if (d->networkSession) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
850 |
QNetworkConfigurationManager manager; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
851 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
852 |
return manager.configurationFromIdentifier( |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
853 |
d->networkSession->sessionProperty(QLatin1String("ActiveConfiguration")).toString()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
854 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
855 |
return QNetworkConfiguration(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
856 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
857 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
858 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
859 |
/*! |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
860 |
\since 4.7 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
861 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
862 |
Overrides the reported network accessibility. If \a accessible is NotAccessible the reported |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
863 |
network accessiblity will always be NotAccessible. Otherwise the reported network |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
864 |
accessibility will reflect the actual device state. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
865 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
866 |
void QNetworkAccessManager::setNetworkAccessible(QNetworkAccessManager::NetworkAccessibility accessible) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
867 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
868 |
Q_D(QNetworkAccessManager); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
869 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
870 |
if (d->networkAccessible != accessible) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
871 |
NetworkAccessibility previous = networkAccessible(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
872 |
d->networkAccessible = accessible; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
873 |
NetworkAccessibility current = networkAccessible(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
874 |
if (previous != current) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
875 |
emit networkAccessibleChanged(current); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
876 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
877 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
878 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
879 |
/*! |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
880 |
\since 4.7 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
881 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
882 |
Returns the current network accessibility. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
883 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
884 |
QNetworkAccessManager::NetworkAccessibility QNetworkAccessManager::networkAccessible() const |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
885 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
886 |
Q_D(const QNetworkAccessManager); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
887 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
888 |
if (d->networkSession) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
889 |
// d->online holds online/offline state of this network session. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
890 |
if (d->online) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
891 |
return d->networkAccessible; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
892 |
else |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
893 |
return NotAccessible; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
894 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
895 |
// Network accessibility is either disabled or unknown. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
896 |
return (d->networkAccessible == NotAccessible) ? NotAccessible : UnknownAccessibility; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
897 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
898 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
899 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
900 |
#endif // QT_NO_BEARERMANAGEMENT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
901 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
902 |
/*! |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
903 |
\since 4.7 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
904 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
905 |
Sends a custom request to the server identified by the URL of \a request. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
906 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
907 |
It is the user's responsibility to send a \a verb to the server that is valid |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
908 |
according to the HTTP specification. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
909 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
910 |
This method provides means to send verbs other than the common ones provided |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
911 |
via get() or post() etc., for instance sending an HTTP OPTIONS command. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
912 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
913 |
If \a data is not empty, the contents of the \a data |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
914 |
device will be uploaded to the server; in that case, data must be open for |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
915 |
reading and must remain valid until the finished() signal is emitted for this reply. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
916 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
917 |
\note This feature is currently available for HTTP only. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
918 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
919 |
\sa get(), post(), put(), deleteResource() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
920 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
921 |
QNetworkReply *QNetworkAccessManager::sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
922 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
923 |
QNetworkRequest newRequest(request); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
924 |
newRequest.setAttribute(QNetworkRequest::CustomVerbAttribute, verb); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
925 |
return d_func()->postProcess(createRequest(QNetworkAccessManager::CustomOperation, newRequest, data)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
926 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
927 |
|
0 | 928 |
/*! |
929 |
Returns a new QNetworkReply object to handle the operation \a op |
|
930 |
and request \a req. The device \a outgoingData is always 0 for Get and |
|
931 |
Head requests, but is the value passed to post() and put() in |
|
932 |
those operations (the QByteArray variants will pass a QBuffer |
|
933 |
object). |
|
934 |
||
935 |
The default implementation calls QNetworkCookieJar::cookiesForUrl() |
|
936 |
on the cookie jar set with setCookieJar() to obtain the cookies to |
|
937 |
be sent to the remote server. |
|
938 |
||
939 |
The returned object must be in an open state. |
|
940 |
*/ |
|
941 |
QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Operation op, |
|
942 |
const QNetworkRequest &req, |
|
943 |
QIODevice *outgoingData) |
|
944 |
{ |
|
945 |
Q_D(QNetworkAccessManager); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
946 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
947 |
// fast path for GET on file:// URLs |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
948 |
// Also if the scheme is empty we consider it a file. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
949 |
// The QNetworkAccessFileBackend will right now only be used |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
950 |
// for PUT or qrc:// |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
951 |
if ((op == QNetworkAccessManager::GetOperation || op == QNetworkAccessManager::HeadOperation) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
952 |
&& (req.url().scheme() == QLatin1String("file") |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
953 |
|| req.url().scheme().isEmpty())) { |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
954 |
return new QFileNetworkReply(this, req, op); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
955 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
956 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
957 |
#ifndef QT_NO_BEARERMANAGEMENT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
958 |
// Return a disabled network reply if network access is disabled. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
959 |
// Except if the scheme is empty or file://. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
960 |
if (!d->networkAccessible && !(req.url().scheme() == QLatin1String("file") || |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
961 |
req.url().scheme().isEmpty())) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
962 |
return new QDisabledNetworkReply(this, req, op); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
963 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
964 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
965 |
if (!d->networkSession && (d->initializeSession || !d->networkConfiguration.isEmpty())) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
966 |
QNetworkConfigurationManager manager; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
967 |
if (!d->networkConfiguration.isEmpty()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
968 |
d->createSession(manager.configurationFromIdentifier(d->networkConfiguration)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
969 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
970 |
if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
971 |
d->createSession(manager.defaultConfiguration()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
972 |
else |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
973 |
d->initializeSession = false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
974 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
975 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
976 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
977 |
if (d->networkSession) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
978 |
d->networkSession->setSessionProperty(QLatin1String("AutoCloseSessionTimeout"), -1); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
979 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
980 |
|
0 | 981 |
QNetworkRequest request = req; |
982 |
if (!request.header(QNetworkRequest::ContentLengthHeader).isValid() && |
|
983 |
outgoingData && !outgoingData->isSequential()) { |
|
984 |
// request has no Content-Length |
|
985 |
// but the data that is outgoing is random-access |
|
986 |
request.setHeader(QNetworkRequest::ContentLengthHeader, outgoingData->size()); |
|
987 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
988 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
989 |
if (static_cast<QNetworkRequest::LoadControl> |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
990 |
(request.attribute(QNetworkRequest::CookieLoadControlAttribute, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
991 |
QNetworkRequest::Automatic).toInt()) == QNetworkRequest::Automatic) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
992 |
if (d->cookieJar) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
993 |
QList<QNetworkCookie> cookies = d->cookieJar->cookiesForUrl(request.url()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
994 |
if (!cookies.isEmpty()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
995 |
request.setHeader(QNetworkRequest::CookieHeader, qVariantFromValue(cookies)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
996 |
} |
0 | 997 |
} |
998 |
||
999 |
// first step: create the reply |
|
1000 |
QUrl url = request.url(); |
|
1001 |
QNetworkReplyImpl *reply = new QNetworkReplyImpl(this); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1002 |
#ifndef QT_NO_BEARERMANAGEMENT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1003 |
if (req.url().scheme() != QLatin1String("file") && !req.url().scheme().isEmpty()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1004 |
connect(this, SIGNAL(networkSessionConnected()), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1005 |
reply, SLOT(_q_networkSessionConnected())); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1006 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1007 |
#endif |
0 | 1008 |
QNetworkReplyImplPrivate *priv = reply->d_func(); |
1009 |
priv->manager = this; |
|
1010 |
||
1011 |
// second step: fetch cached credentials |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1012 |
if (static_cast<QNetworkRequest::LoadControl> |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1013 |
(request.attribute(QNetworkRequest::AuthenticationReuseAttribute, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1014 |
QNetworkRequest::Automatic).toInt()) == QNetworkRequest::Automatic) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1015 |
QNetworkAuthenticationCredential *cred = d->fetchCachedCredentials(url); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1016 |
if (cred) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1017 |
url.setUserName(cred->user); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1018 |
url.setPassword(cred->password); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1019 |
priv->urlForLastAuthentication = url; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1020 |
} |
0 | 1021 |
} |
1022 |
||
1023 |
// third step: find a backend |
|
1024 |
priv->backend = d->findBackend(op, request); |
|
1025 |
||
1026 |
#ifndef QT_NO_NETWORKPROXY |
|
1027 |
QList<QNetworkProxy> proxyList = d->queryProxy(QNetworkProxyQuery(request.url())); |
|
1028 |
priv->proxyList = proxyList; |
|
1029 |
#endif |
|
1030 |
if (priv->backend) { |
|
1031 |
priv->backend->setParent(reply); |
|
1032 |
priv->backend->reply = priv; |
|
1033 |
} |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1034 |
// fourth step: setup the reply |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1035 |
priv->setup(op, request, outgoingData); |
0 | 1036 |
|
1037 |
#ifndef QT_NO_OPENSSL |
|
1038 |
reply->setSslConfiguration(request.sslConfiguration()); |
|
1039 |
#endif |
|
1040 |
return reply; |
|
1041 |
} |
|
1042 |
||
1043 |
void QNetworkAccessManagerPrivate::_q_replyFinished() |
|
1044 |
{ |
|
1045 |
Q_Q(QNetworkAccessManager); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1046 |
|
0 | 1047 |
QNetworkReply *reply = qobject_cast<QNetworkReply *>(q->sender()); |
1048 |
if (reply) |
|
1049 |
emit q->finished(reply); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1050 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1051 |
#ifndef QT_NO_BEARERMANAGEMENT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1052 |
if (networkSession && q->findChildren<QNetworkReply *>().count() == 1) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1053 |
networkSession->setSessionProperty(QLatin1String("AutoCloseSessionTimeout"), 120000); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1054 |
#endif |
0 | 1055 |
} |
1056 |
||
1057 |
void QNetworkAccessManagerPrivate::_q_replySslErrors(const QList<QSslError> &errors) |
|
1058 |
{ |
|
1059 |
#ifndef QT_NO_OPENSSL |
|
1060 |
Q_Q(QNetworkAccessManager); |
|
1061 |
QNetworkReply *reply = qobject_cast<QNetworkReply *>(q->sender()); |
|
1062 |
if (reply) |
|
1063 |
emit q->sslErrors(reply, errors); |
|
1064 |
#else |
|
1065 |
Q_UNUSED(errors); |
|
1066 |
#endif |
|
1067 |
} |
|
1068 |
||
1069 |
QNetworkReply *QNetworkAccessManagerPrivate::postProcess(QNetworkReply *reply) |
|
1070 |
{ |
|
1071 |
Q_Q(QNetworkAccessManager); |
|
1072 |
QNetworkReplyPrivate::setManager(reply, q); |
|
1073 |
q->connect(reply, SIGNAL(finished()), SLOT(_q_replyFinished())); |
|
1074 |
#ifndef QT_NO_OPENSSL |
|
1075 |
/* In case we're compiled without SSL support, we don't have this signal and we need to |
|
1076 |
* avoid getting a connection error. */ |
|
1077 |
q->connect(reply, SIGNAL(sslErrors(QList<QSslError>)), SLOT(_q_replySslErrors(QList<QSslError>))); |
|
1078 |
#endif |
|
1079 |
||
1080 |
return reply; |
|
1081 |
} |
|
1082 |
||
1083 |
void QNetworkAccessManagerPrivate::createCookieJar() const |
|
1084 |
{ |
|
1085 |
if (!cookieJarCreated) { |
|
1086 |
// keep the ugly hack in here |
|
1087 |
QNetworkAccessManagerPrivate *that = const_cast<QNetworkAccessManagerPrivate *>(this); |
|
1088 |
that->cookieJar = new QNetworkCookieJar(that->q_func()); |
|
1089 |
that->cookieJarCreated = true; |
|
1090 |
} |
|
1091 |
} |
|
1092 |
||
1093 |
void QNetworkAccessManagerPrivate::authenticationRequired(QNetworkAccessBackend *backend, |
|
1094 |
QAuthenticator *authenticator) |
|
1095 |
{ |
|
1096 |
Q_Q(QNetworkAccessManager); |
|
1097 |
||
1098 |
// FIXME: Add support for domains (i.e., the leading path) |
|
1099 |
QUrl url = backend->reply->url; |
|
1100 |
||
1101 |
// don't try the cache for the same URL twice in a row |
|
1102 |
// being called twice for the same URL means the authentication failed |
|
1103 |
if (url != backend->reply->urlForLastAuthentication) { |
|
1104 |
QNetworkAuthenticationCredential *cred = fetchCachedCredentials(url, authenticator); |
|
1105 |
if (cred) { |
|
1106 |
authenticator->setUser(cred->user); |
|
1107 |
authenticator->setPassword(cred->password); |
|
1108 |
backend->reply->urlForLastAuthentication = url; |
|
1109 |
return; |
|
1110 |
} |
|
1111 |
} |
|
1112 |
||
1113 |
backend->reply->urlForLastAuthentication = url; |
|
1114 |
emit q->authenticationRequired(backend->reply->q_func(), authenticator); |
|
1115 |
addCredentials(url, authenticator); |
|
1116 |
} |
|
1117 |
||
1118 |
#ifndef QT_NO_NETWORKPROXY |
|
1119 |
void QNetworkAccessManagerPrivate::proxyAuthenticationRequired(QNetworkAccessBackend *backend, |
|
1120 |
const QNetworkProxy &proxy, |
|
1121 |
QAuthenticator *authenticator) |
|
1122 |
{ |
|
1123 |
Q_Q(QNetworkAccessManager); |
|
1124 |
// ### FIXME Tracking of successful authentications |
|
1125 |
// This code is a bit broken right now for SOCKS authentication |
|
1126 |
// first request: proxyAuthenticationRequired gets emitted, credentials gets saved |
|
1127 |
// second request: (proxy != backend->reply->lastProxyAuthentication) does not evaluate to true, |
|
1128 |
// proxyAuthenticationRequired gets emitted again |
|
1129 |
// possible solution: some tracking inside the authenticator |
|
1130 |
// or a new function proxyAuthenticationSucceeded(true|false) |
|
1131 |
if (proxy != backend->reply->lastProxyAuthentication) { |
|
1132 |
QNetworkAuthenticationCredential *cred = fetchCachedCredentials(proxy); |
|
1133 |
if (cred) { |
|
1134 |
authenticator->setUser(cred->user); |
|
1135 |
authenticator->setPassword(cred->password); |
|
1136 |
return; |
|
1137 |
} |
|
1138 |
} |
|
1139 |
||
1140 |
backend->reply->lastProxyAuthentication = proxy; |
|
1141 |
emit q->proxyAuthenticationRequired(proxy, authenticator); |
|
1142 |
addCredentials(proxy, authenticator); |
|
1143 |
} |
|
1144 |
||
1145 |
void QNetworkAccessManagerPrivate::addCredentials(const QNetworkProxy &p, |
|
1146 |
const QAuthenticator *authenticator) |
|
1147 |
{ |
|
1148 |
Q_ASSERT(authenticator); |
|
1149 |
Q_ASSERT(p.type() != QNetworkProxy::DefaultProxy); |
|
1150 |
Q_ASSERT(p.type() != QNetworkProxy::NoProxy); |
|
1151 |
||
1152 |
QString realm = authenticator->realm(); |
|
1153 |
QNetworkProxy proxy = p; |
|
1154 |
proxy.setUser(authenticator->user()); |
|
1155 |
// Set two credentials: one with the username and one without |
|
1156 |
do { |
|
1157 |
// Set two credentials actually: one with and one without the realm |
|
1158 |
do { |
|
1159 |
QByteArray cacheKey = proxyAuthenticationKey(proxy, realm); |
|
1160 |
if (cacheKey.isEmpty()) |
|
1161 |
return; // should not happen |
|
1162 |
||
1163 |
QNetworkAuthenticationCache *auth = new QNetworkAuthenticationCache; |
|
1164 |
auth->insert(QString(), authenticator->user(), authenticator->password()); |
|
1165 |
objectCache.addEntry(cacheKey, auth); // replace the existing one, if there's any |
|
1166 |
||
1167 |
if (realm.isEmpty()) { |
|
1168 |
break; |
|
1169 |
} else { |
|
1170 |
realm.clear(); |
|
1171 |
} |
|
1172 |
} while (true); |
|
1173 |
||
1174 |
if (proxy.user().isEmpty()) |
|
1175 |
break; |
|
1176 |
else |
|
1177 |
proxy.setUser(QString()); |
|
1178 |
} while (true); |
|
1179 |
} |
|
1180 |
||
1181 |
QNetworkAuthenticationCredential * |
|
1182 |
QNetworkAccessManagerPrivate::fetchCachedCredentials(const QNetworkProxy &p, |
|
1183 |
const QAuthenticator *authenticator) |
|
1184 |
{ |
|
1185 |
QNetworkProxy proxy = p; |
|
1186 |
if (proxy.type() == QNetworkProxy::DefaultProxy) { |
|
1187 |
proxy = QNetworkProxy::applicationProxy(); |
|
1188 |
} |
|
1189 |
if (!proxy.password().isEmpty()) |
|
1190 |
return 0; // no need to set credentials if it already has them |
|
1191 |
||
1192 |
QString realm; |
|
1193 |
if (authenticator) |
|
1194 |
realm = authenticator->realm(); |
|
1195 |
||
1196 |
QByteArray cacheKey = proxyAuthenticationKey(proxy, realm); |
|
1197 |
if (cacheKey.isEmpty()) |
|
1198 |
return 0; |
|
1199 |
if (!objectCache.hasEntry(cacheKey)) |
|
1200 |
return 0; |
|
1201 |
||
1202 |
QNetworkAuthenticationCache *auth = |
|
1203 |
static_cast<QNetworkAuthenticationCache *>(objectCache.requestEntryNow(cacheKey)); |
|
1204 |
QNetworkAuthenticationCredential *cred = auth->findClosestMatch(QString()); |
|
1205 |
objectCache.releaseEntry(cacheKey); |
|
1206 |
||
1207 |
// proxy cache credentials always have exactly one item |
|
1208 |
Q_ASSERT_X(cred, "QNetworkAccessManager", |
|
1209 |
"Internal inconsistency: found a cache key for a proxy, but it's empty"); |
|
1210 |
return cred; |
|
1211 |
} |
|
1212 |
||
1213 |
QList<QNetworkProxy> QNetworkAccessManagerPrivate::queryProxy(const QNetworkProxyQuery &query) |
|
1214 |
{ |
|
1215 |
QList<QNetworkProxy> proxies; |
|
1216 |
if (proxyFactory) { |
|
1217 |
proxies = proxyFactory->queryProxy(query); |
|
1218 |
if (proxies.isEmpty()) { |
|
1219 |
qWarning("QNetworkAccessManager: factory %p has returned an empty result set", |
|
1220 |
proxyFactory); |
|
1221 |
proxies << QNetworkProxy::NoProxy; |
|
1222 |
} |
|
1223 |
} else if (proxy.type() == QNetworkProxy::DefaultProxy) { |
|
1224 |
// no proxy set, query the application |
|
1225 |
return QNetworkProxyFactory::proxyForQuery(query); |
|
1226 |
} else { |
|
1227 |
proxies << proxy; |
|
1228 |
} |
|
1229 |
||
1230 |
return proxies; |
|
1231 |
} |
|
1232 |
#endif |
|
1233 |
||
1234 |
void QNetworkAccessManagerPrivate::addCredentials(const QUrl &url, |
|
1235 |
const QAuthenticator *authenticator) |
|
1236 |
{ |
|
1237 |
Q_ASSERT(authenticator); |
|
1238 |
QString domain = QString::fromLatin1("/"); // FIXME: make QAuthenticator return the domain |
|
1239 |
QString realm = authenticator->realm(); |
|
1240 |
||
1241 |
// Set two credentials actually: one with and one without the username in the URL |
|
1242 |
QUrl copy = url; |
|
1243 |
copy.setUserName(authenticator->user()); |
|
1244 |
do { |
|
1245 |
QByteArray cacheKey = authenticationKey(copy, realm); |
|
1246 |
if (objectCache.hasEntry(cacheKey)) { |
|
1247 |
QNetworkAuthenticationCache *auth = |
|
1248 |
static_cast<QNetworkAuthenticationCache *>(objectCache.requestEntryNow(cacheKey)); |
|
1249 |
auth->insert(domain, authenticator->user(), authenticator->password()); |
|
1250 |
objectCache.releaseEntry(cacheKey); |
|
1251 |
} else { |
|
1252 |
QNetworkAuthenticationCache *auth = new QNetworkAuthenticationCache; |
|
1253 |
auth->insert(domain, authenticator->user(), authenticator->password()); |
|
1254 |
objectCache.addEntry(cacheKey, auth); |
|
1255 |
} |
|
1256 |
||
1257 |
if (copy.userName().isEmpty()) { |
|
1258 |
break; |
|
1259 |
} else { |
|
1260 |
copy.setUserName(QString()); |
|
1261 |
} |
|
1262 |
} while (true); |
|
1263 |
} |
|
1264 |
||
1265 |
/*! |
|
1266 |
Fetch the credential data from the credential cache. |
|
1267 |
||
1268 |
If auth is 0 (as it is when called from createRequest()), this will try to |
|
1269 |
look up with an empty realm. That fails in most cases for HTTP (because the |
|
1270 |
realm is seldom empty for HTTP challenges). In any case, QHttpNetworkConnection |
|
1271 |
never sends the credentials on the first attempt: it needs to find out what |
|
1272 |
authentication methods the server supports. |
|
1273 |
||
1274 |
For FTP, realm is always empty. |
|
1275 |
*/ |
|
1276 |
QNetworkAuthenticationCredential * |
|
1277 |
QNetworkAccessManagerPrivate::fetchCachedCredentials(const QUrl &url, |
|
1278 |
const QAuthenticator *authentication) |
|
1279 |
{ |
|
1280 |
if (!url.password().isEmpty()) |
|
1281 |
return 0; // no need to set credentials if it already has them |
|
1282 |
||
1283 |
QString realm; |
|
1284 |
if (authentication) |
|
1285 |
realm = authentication->realm(); |
|
1286 |
||
1287 |
QByteArray cacheKey = authenticationKey(url, realm); |
|
1288 |
if (!objectCache.hasEntry(cacheKey)) |
|
1289 |
return 0; |
|
1290 |
||
1291 |
QNetworkAuthenticationCache *auth = |
|
1292 |
static_cast<QNetworkAuthenticationCache *>(objectCache.requestEntryNow(cacheKey)); |
|
1293 |
QNetworkAuthenticationCredential *cred = auth->findClosestMatch(url.path()); |
|
1294 |
objectCache.releaseEntry(cacheKey); |
|
1295 |
return cred; |
|
1296 |
} |
|
1297 |
||
1298 |
void QNetworkAccessManagerPrivate::clearCache(QNetworkAccessManager *manager) |
|
1299 |
{ |
|
1300 |
manager->d_func()->objectCache.clear(); |
|
1301 |
} |
|
1302 |
||
1303 |
QNetworkAccessManagerPrivate::~QNetworkAccessManagerPrivate() |
|
1304 |
{ |
|
1305 |
} |
|
1306 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1307 |
#ifndef QT_NO_BEARERMANAGEMENT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1308 |
void QNetworkAccessManagerPrivate::createSession(const QNetworkConfiguration &config) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1309 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1310 |
Q_Q(QNetworkAccessManager); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1311 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1312 |
initializeSession = false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1313 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1314 |
if (networkSession) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1315 |
delete networkSession; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1316 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1317 |
if (!config.isValid()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1318 |
networkSession = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1319 |
online = false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1320 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1321 |
if (networkAccessible == QNetworkAccessManager::NotAccessible) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1322 |
emit q->networkAccessibleChanged(QNetworkAccessManager::NotAccessible); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1323 |
else |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1324 |
emit q->networkAccessibleChanged(QNetworkAccessManager::UnknownAccessibility); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1325 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1326 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1327 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1328 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1329 |
networkSession = new QNetworkSession(config, q); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1330 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1331 |
QObject::connect(networkSession, SIGNAL(opened()), q, SIGNAL(networkSessionConnected())); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1332 |
QObject::connect(networkSession, SIGNAL(closed()), q, SLOT(_q_networkSessionClosed())); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1333 |
QObject::connect(networkSession, SIGNAL(stateChanged(QNetworkSession::State)), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1334 |
q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State))); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1335 |
QObject::connect(networkSession, SIGNAL(newConfigurationActivated()), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1336 |
q, SLOT(_q_networkSessionNewConfigurationActivated())); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1337 |
QObject::connect(networkSession, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1338 |
SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool)), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1339 |
q, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1340 |
SLOT(_q_networkSessionPreferredConfigurationChanged(QNetworkConfiguration,bool))); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1341 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1342 |
_q_networkSessionStateChanged(networkSession->state()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1343 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1344 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1345 |
void QNetworkAccessManagerPrivate::_q_networkSessionClosed() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1346 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1347 |
if (networkSession) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1348 |
networkConfiguration = networkSession->configuration().identifier(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1349 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1350 |
networkSession->deleteLater(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1351 |
networkSession = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1352 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1353 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1354 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1355 |
void QNetworkAccessManagerPrivate::_q_networkSessionNewConfigurationActivated() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1356 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1357 |
Q_Q(QNetworkAccessManager); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1358 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1359 |
if (networkSession) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1360 |
networkSession->accept(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1361 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1362 |
emit q->networkSessionConnected(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1363 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1364 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1365 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1366 |
void QNetworkAccessManagerPrivate::_q_networkSessionPreferredConfigurationChanged(const QNetworkConfiguration &, bool) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1367 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1368 |
if (networkSession) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1369 |
networkSession->migrate(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1370 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1371 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1372 |
void QNetworkAccessManagerPrivate::_q_networkSessionStateChanged(QNetworkSession::State state) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1373 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1374 |
Q_Q(QNetworkAccessManager); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1375 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1376 |
if (online) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1377 |
if (state != QNetworkSession::Connected && state != QNetworkSession::Roaming) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1378 |
online = false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1379 |
emit q->networkAccessibleChanged(QNetworkAccessManager::NotAccessible); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1380 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1381 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1382 |
if (state == QNetworkSession::Connected || state == QNetworkSession::Roaming) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1383 |
online = true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1384 |
emit q->networkAccessibleChanged(networkAccessible); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1385 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1386 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1387 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1388 |
#endif // QT_NO_BEARERMANAGEMENT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1389 |
|
0 | 1390 |
QT_END_NAMESPACE |
1391 |
||
1392 |
#include "moc_qnetworkaccessmanager.cpp" |