Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
5 | ** | - |
6 | ** This file is part of the QtNetwork module of the Qt Toolkit. | - |
7 | ** | - |
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
9 | ** Commercial License Usage | - |
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
11 | ** accordance with the commercial license agreement provided with the | - |
12 | ** Software or, alternatively, in accordance with the terms contained in | - |
13 | ** a written agreement between you and Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
16 | ** | - |
17 | ** GNU Lesser General Public License Usage | - |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
19 | ** General Public License version 2.1 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | #include "qhttpmultipart.h" | - |
43 | #include "qhttpmultipart_p.h" | - |
44 | #include "QtCore/qdatetime.h" // for initializing the random number generator with QTime | - |
45 | #include "QtCore/qmutex.h" | - |
46 | #include "QtCore/qthreadstorage.h" | - |
47 | | - |
48 | QT_BEGIN_NAMESPACE | - |
49 | | - |
50 | /*! | - |
51 | \class QHttpPart | - |
52 | \brief The QHttpPart class holds a body part to be used inside a | - |
53 | HTTP multipart MIME message. | - |
54 | \since 4.8 | - |
55 | | - |
56 | \ingroup network | - |
57 | \ingroup shared | - |
58 | \inmodule QtNetwork | - |
59 | | - |
60 | The QHttpPart class holds a body part to be used inside a HTTP | - |
61 | multipart MIME message (which is represented by the QHttpMultiPart class). | - |
62 | A QHttpPart consists of a header block | - |
63 | and a data block, which are separated by each other by two | - |
64 | consecutive new lines. An example for one part would be: | - |
65 | | - |
66 | \snippet code/src_network_access_qhttppart.cpp 0 | - |
67 | | - |
68 | For setting headers, use setHeader() and setRawHeader(), which behave | - |
69 | exactly like QNetworkRequest::setHeader() and QNetworkRequest::setRawHeader(). | - |
70 | | - |
71 | For reading small pieces of data, use setBody(); for larger data blocks | - |
72 | like e.g. images, use setBodyDevice(). The latter method saves memory by | - |
73 | not copying the data internally, but reading directly from the device. | - |
74 | This means that the device must be opened and readable at the moment when | - |
75 | the multipart message containing the body part is sent on the network via | - |
76 | QNetworkAccessManager::post(). | - |
77 | | - |
78 | To construct a QHttpPart with a small body, consider the following snippet | - |
79 | (this produces the data shown in the example above): | - |
80 | | - |
81 | \snippet code/src_network_access_qhttppart.cpp 1 | - |
82 | | - |
83 | To construct a QHttpPart reading from a device (e.g. a file), the following | - |
84 | can be applied: | - |
85 | | - |
86 | \snippet code/src_network_access_qhttppart.cpp 2 | - |
87 | | - |
88 | Be aware that QHttpPart does not take ownership of the device when set, so | - |
89 | it is the developer's responsibility to destroy it when it is not needed anymore. | - |
90 | A good idea might be to set the multipart message as parent object for the device, | - |
91 | as documented at the documentation for QHttpMultiPart. | - |
92 | | - |
93 | \sa QHttpMultiPart, QNetworkAccessManager | - |
94 | */ | - |
95 | | - |
96 | | - |
97 | /*! | - |
98 | Constructs an empty QHttpPart object. | - |
99 | */ | - |
100 | QHttpPart::QHttpPart() : d(new QHttpPartPrivate) | - |
101 | { | - |
102 | } executed: } Execution Count:30 | 30 |
103 | | - |
104 | /*! | - |
105 | Creates a copy of \a other. | - |
106 | */ | - |
107 | QHttpPart::QHttpPart(const QHttpPart &other) : d(other.d) | - |
108 | { | - |
109 | } executed: } Execution Count:45 | 45 |
110 | | - |
111 | /*! | - |
112 | Destroys this QHttpPart. | - |
113 | */ | - |
114 | QHttpPart::~QHttpPart() | - |
115 | { | - |
116 | d = 0; executed (the execution status of this line is deduced): d = 0; | - |
117 | } executed: } Execution Count:60 | 60 |
118 | | - |
119 | /*! | - |
120 | Creates a copy of \a other. | - |
121 | */ | - |
122 | QHttpPart &QHttpPart::operator=(const QHttpPart &other) | - |
123 | { | - |
124 | d = other.d; never executed (the execution status of this line is deduced): d = other.d; | - |
125 | return *this; never executed: return *this; | 0 |
126 | } | - |
127 | | - |
128 | /*! | - |
129 | \fn void QHttpPart::swap(QHttpPart &other) | - |
130 | \since 5.0 | - |
131 | | - |
132 | Swaps this HTTP part with \a other. This function is very fast and | - |
133 | never fails. | - |
134 | */ | - |
135 | | - |
136 | /*! | - |
137 | Returns true if this object is the same as \a other (i.e., if they | - |
138 | have the same headers and body). | - |
139 | | - |
140 | \sa operator!=() | - |
141 | */ | - |
142 | bool QHttpPart::operator==(const QHttpPart &other) const | - |
143 | { | - |
144 | return d == other.d || *d == *other.d; never executed: return d == other.d || *d == *other.d; | 0 |
145 | } | - |
146 | | - |
147 | /*! | - |
148 | \fn bool QHttpPart::operator!=(const QHttpPart &other) const | - |
149 | | - |
150 | Returns true if this object is not the same as \a other. | - |
151 | | - |
152 | \sa operator==() | - |
153 | */ | - |
154 | | - |
155 | /*! | - |
156 | Sets the value of the known header \a header to be \a value, | - |
157 | overriding any previously set headers. | - |
158 | | - |
159 | \sa QNetworkRequest::KnownHeaders, setRawHeader(), QNetworkRequest::setHeader() | - |
160 | */ | - |
161 | void QHttpPart::setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value) | - |
162 | { | - |
163 | d->setCookedHeader(header, value); executed (the execution status of this line is deduced): d->setCookedHeader(header, value); | - |
164 | } executed: } Execution Count:60 | 60 |
165 | | - |
166 | /*! | - |
167 | Sets the header \a headerName to be of value \a headerValue. If \a | - |
168 | headerName corresponds to a known header (see | - |
169 | QNetworkRequest::KnownHeaders), the raw format will be parsed and | - |
170 | the corresponding "cooked" header will be set as well. | - |
171 | | - |
172 | Note: setting the same header twice overrides the previous | - |
173 | setting. To accomplish the behaviour of multiple HTTP headers of | - |
174 | the same name, you should concatenate the two values, separating | - |
175 | them with a comma (",") and set one single raw header. | - |
176 | | - |
177 | \sa QNetworkRequest::KnownHeaders, setHeader(), QNetworkRequest::setRawHeader() | - |
178 | */ | - |
179 | void QHttpPart::setRawHeader(const QByteArray &headerName, const QByteArray &headerValue) | - |
180 | { | - |
181 | d->setRawHeader(headerName, headerValue); executed (the execution status of this line is deduced): d->setRawHeader(headerName, headerValue); | - |
182 | } executed: } Execution Count:24 | 24 |
183 | | - |
184 | /*! | - |
185 | Sets the body of this MIME part to \a body. The body set with this method | - |
186 | will be used unless the device is set via setBodyDevice(). For a large | - |
187 | amount of data (e.g. an image), use setBodyDevice(), which will not copy | - |
188 | the data internally. | - |
189 | | - |
190 | \sa setBodyDevice() | - |
191 | */ | - |
192 | void QHttpPart::setBody(const QByteArray &body) | - |
193 | { | - |
194 | d->setBody(body); executed (the execution status of this line is deduced): d->setBody(body); | - |
195 | } executed: } Execution Count:15 | 15 |
196 | | - |
197 | /*! | - |
198 | Sets the device to read the content from to \a device. For large amounts of data | - |
199 | this method should be preferred over setBody(), | - |
200 | because the content is not copied when using this method, but read | - |
201 | directly from the device. | - |
202 | \a device must be open and readable. QHttpPart does not take ownership | - |
203 | of \a device, i.e. the device must be closed and destroyed if necessary. | - |
204 | if \a device is sequential (e.g. sockets, but not files), | - |
205 | QNetworkAccessManager::post() should be called after \a device has | - |
206 | emitted finished(). | - |
207 | For unsetting the device and using data set via setBody(), use | - |
208 | "setBodyDevice(0)". | - |
209 | | - |
210 | \sa setBody(), QNetworkAccessManager::post() | - |
211 | */ | - |
212 | void QHttpPart::setBodyDevice(QIODevice *device) | - |
213 | { | - |
214 | d->setBodyDevice(device); executed (the execution status of this line is deduced): d->setBodyDevice(device); | - |
215 | } executed: } Execution Count:27 | 27 |
216 | | - |
217 | | - |
218 | | - |
219 | /*! | - |
220 | \class QHttpMultiPart | - |
221 | \brief The QHttpMultiPart class resembles a MIME multipart message to be sent over HTTP. | - |
222 | \since 4.8 | - |
223 | | - |
224 | \ingroup network | - |
225 | \inmodule QtNetwork | - |
226 | | - |
227 | The QHttpMultiPart resembles a MIME multipart message, as described in RFC 2046, | - |
228 | which is to be sent over HTTP. | - |
229 | A multipart message consists of an arbitrary number of body parts (see QHttpPart), | - |
230 | which are separated by a unique boundary. The boundary of the QHttpMultiPart is | - |
231 | constructed with the string "boundary_.oOo._" followed by random characters, | - |
232 | and provides enough uniqueness to make sure it does not occur inside the parts itself. | - |
233 | If desired, the boundary can still be set via setBoundary(). | - |
234 | | - |
235 | As an example, consider the following code snippet, which constructs a multipart | - |
236 | message containing a text part followed by an image part: | - |
237 | | - |
238 | \snippet code/src_network_access_qhttpmultipart.cpp 0 | - |
239 | | - |
240 | \sa QHttpPart, QNetworkAccessManager::post() | - |
241 | */ | - |
242 | | - |
243 | /*! | - |
244 | \enum QHttpMultiPart::ContentType | - |
245 | | - |
246 | List of known content types for a multipart subtype as described | - |
247 | in RFC 2046 and others. | - |
248 | | - |
249 | \value MixedType corresponds to the "multipart/mixed" subtype, | - |
250 | meaning the body parts are independent of each other, as described | - |
251 | in RFC 2046. | - |
252 | | - |
253 | \value RelatedType corresponds to the "multipart/related" subtype, | - |
254 | meaning the body parts are related to each other, as described in RFC 2387. | - |
255 | | - |
256 | \value FormDataType corresponds to the "multipart/form-data" | - |
257 | subtype, meaning the body parts contain form elements, as described in RFC 2388. | - |
258 | | - |
259 | \value AlternativeType corresponds to the "multipart/alternative" | - |
260 | subtype, meaning the body parts are alternative representations of | - |
261 | the same information, as described in RFC 2046. | - |
262 | | - |
263 | \sa setContentType() | - |
264 | */ | - |
265 | | - |
266 | /*! | - |
267 | Constructs a QHttpMultiPart with content type MixedType and sets | - |
268 | \a parent as the parent object. | - |
269 | | - |
270 | \sa QHttpMultiPart::ContentType | - |
271 | */ | - |
272 | QHttpMultiPart::QHttpMultiPart(QObject *parent) : QObject(*new QHttpMultiPartPrivate, parent) | - |
273 | { | - |
274 | Q_D(QHttpMultiPart); executed (the execution status of this line is deduced): QHttpMultiPartPrivate * const d = d_func(); | - |
275 | d->contentType = MixedType; executed (the execution status of this line is deduced): d->contentType = MixedType; | - |
276 | } executed: } Execution Count:27 | 27 |
277 | | - |
278 | /*! | - |
279 | Constructs a QHttpMultiPart with content type \a contentType and | - |
280 | sets parent as the parent object. | - |
281 | | - |
282 | \sa QHttpMultiPart::ContentType | - |
283 | */ | - |
284 | QHttpMultiPart::QHttpMultiPart(QHttpMultiPart::ContentType contentType, QObject *parent) : QObject(*new QHttpMultiPartPrivate, parent) | - |
285 | { | - |
286 | Q_D(QHttpMultiPart); executed (the execution status of this line is deduced): QHttpMultiPartPrivate * const d = d_func(); | - |
287 | d->contentType = contentType; executed (the execution status of this line is deduced): d->contentType = contentType; | - |
288 | } executed: } Execution Count:6 | 6 |
289 | | - |
290 | /*! | - |
291 | Destroys the multipart. | - |
292 | */ | - |
293 | QHttpMultiPart::~QHttpMultiPart() | - |
294 | { | - |
295 | } | - |
296 | | - |
297 | /*! | - |
298 | Appends \a httpPart to this multipart. | - |
299 | */ | - |
300 | void QHttpMultiPart::append(const QHttpPart &httpPart) | - |
301 | { | - |
302 | d_func()->parts.append(httpPart); executed (the execution status of this line is deduced): d_func()->parts.append(httpPart); | - |
303 | } executed: } Execution Count:45 | 45 |
304 | | - |
305 | /*! | - |
306 | Sets the content type to \a contentType. The content type will be used | - |
307 | in the HTTP header section when sending the multipart message via | - |
308 | QNetworkAccessManager::post(). | - |
309 | In case you want to use a multipart subtype not contained in | - |
310 | QHttpMultiPart::ContentType, | - |
311 | you can add the "Content-Type" header field to the QNetworkRequest | - |
312 | by hand, and then use this request together with the multipart | - |
313 | message for posting. | - |
314 | | - |
315 | \sa QHttpMultiPart::ContentType, QNetworkAccessManager::post() | - |
316 | */ | - |
317 | void QHttpMultiPart::setContentType(QHttpMultiPart::ContentType contentType) | - |
318 | { | - |
319 | d_func()->contentType = contentType; executed (the execution status of this line is deduced): d_func()->contentType = contentType; | - |
320 | } executed: } Execution Count:21 | 21 |
321 | | - |
322 | /*! | - |
323 | returns the boundary. | - |
324 | | - |
325 | \sa setBoundary() | - |
326 | */ | - |
327 | QByteArray QHttpMultiPart::boundary() const | - |
328 | { | - |
329 | return d_func()->boundary; executed: return d_func()->boundary; Execution Count:134 | 134 |
330 | } | - |
331 | | - |
332 | /*! | - |
333 | Sets the boundary to \a boundary. | - |
334 | | - |
335 | Usually, you do not need to generate a boundary yourself; upon construction | - |
336 | the boundary is initiated with the string "boundary_.oOo._" followed by random | - |
337 | characters, and provides enough uniqueness to make sure it does not occur | - |
338 | inside the parts itself. | - |
339 | | - |
340 | \sa boundary() | - |
341 | */ | - |
342 | void QHttpMultiPart::setBoundary(const QByteArray &boundary) | - |
343 | { | - |
344 | d_func()->boundary = boundary; never executed (the execution status of this line is deduced): d_func()->boundary = boundary; | - |
345 | } | 0 |
346 | | - |
347 | | - |
348 | | - |
349 | // ------------------------------------------------------------------ | - |
350 | // ----------- implementations of private classes: ------------------ | - |
351 | // ------------------------------------------------------------------ | - |
352 | | - |
353 | | - |
354 | | - |
355 | qint64 QHttpPartPrivate::bytesAvailable() const | - |
356 | { | - |
357 | checkHeaderCreated(); never executed (the execution status of this line is deduced): checkHeaderCreated(); | - |
358 | qint64 bytesAvailable = header.count(); never executed (the execution status of this line is deduced): qint64 bytesAvailable = header.count(); | - |
359 | if (bodyDevice) { never evaluated: bodyDevice | 0 |
360 | bytesAvailable += bodyDevice->bytesAvailable() - readPointer; never executed (the execution status of this line is deduced): bytesAvailable += bodyDevice->bytesAvailable() - readPointer; | - |
361 | } else { | 0 |
362 | bytesAvailable += body.count() - readPointer; never executed (the execution status of this line is deduced): bytesAvailable += body.count() - readPointer; | - |
363 | } | 0 |
364 | // the device might have closed etc., so make sure we do not return a negative value | - |
365 | return qMax(bytesAvailable, (qint64) 0); never executed: return qMax(bytesAvailable, (qint64) 0); | 0 |
366 | } | - |
367 | | - |
368 | qint64 QHttpPartPrivate::readData(char *data, qint64 maxSize) | - |
369 | { | - |
370 | checkHeaderCreated(); executed (the execution status of this line is deduced): checkHeaderCreated(); | - |
371 | qint64 bytesRead = 0; executed (the execution status of this line is deduced): qint64 bytesRead = 0; | - |
372 | qint64 headerDataCount = header.count(); executed (the execution status of this line is deduced): qint64 headerDataCount = header.count(); | - |
373 | | - |
374 | // read header if it has not been read yet | - |
375 | if (readPointer < headerDataCount) { evaluated: readPointer < headerDataCount yes Evaluation Count:30 | yes Evaluation Count:828 |
| 30-828 |
376 | bytesRead = qMin(headerDataCount - readPointer, maxSize); executed (the execution status of this line is deduced): bytesRead = qMin(headerDataCount - readPointer, maxSize); | - |
377 | const char *headerData = header.constData(); executed (the execution status of this line is deduced): const char *headerData = header.constData(); | - |
378 | memcpy(data, headerData + readPointer, bytesRead); executed (the execution status of this line is deduced): memcpy(data, headerData + readPointer, bytesRead); | - |
379 | readPointer += bytesRead; executed (the execution status of this line is deduced): readPointer += bytesRead; | - |
380 | } executed: } Execution Count:30 | 30 |
381 | // read content if there is still space | - |
382 | if (bytesRead < maxSize) { partially evaluated: bytesRead < maxSize yes Evaluation Count:858 | no Evaluation Count:0 |
| 0-858 |
383 | if (bodyDevice) { evaluated: bodyDevice yes Evaluation Count:714 | yes Evaluation Count:144 |
| 144-714 |
384 | qint64 dataBytesRead = bodyDevice->read(data + bytesRead, maxSize - bytesRead); executed (the execution status of this line is deduced): qint64 dataBytesRead = bodyDevice->read(data + bytesRead, maxSize - bytesRead); | - |
385 | if (dataBytesRead == -1) partially evaluated: dataBytesRead == -1 no Evaluation Count:0 | yes Evaluation Count:714 |
| 0-714 |
386 | return -1; never executed: return -1; | 0 |
387 | bytesRead += dataBytesRead; executed (the execution status of this line is deduced): bytesRead += dataBytesRead; | - |
388 | readPointer += dataBytesRead; executed (the execution status of this line is deduced): readPointer += dataBytesRead; | - |
389 | } else { executed: } Execution Count:714 | 714 |
390 | qint64 contentBytesRead = qMin(body.count() - readPointer + headerDataCount, maxSize - bytesRead); executed (the execution status of this line is deduced): qint64 contentBytesRead = qMin(body.count() - readPointer + headerDataCount, maxSize - bytesRead); | - |
391 | const char *contentData = body.constData(); executed (the execution status of this line is deduced): const char *contentData = body.constData(); | - |
392 | // if this method is called several times, we need to find the | - |
393 | // right offset in the content ourselves: | - |
394 | memcpy(data + bytesRead, contentData + readPointer - headerDataCount, contentBytesRead); executed (the execution status of this line is deduced): memcpy(data + bytesRead, contentData + readPointer - headerDataCount, contentBytesRead); | - |
395 | bytesRead += contentBytesRead; executed (the execution status of this line is deduced): bytesRead += contentBytesRead; | - |
396 | readPointer += contentBytesRead; executed (the execution status of this line is deduced): readPointer += contentBytesRead; | - |
397 | } executed: } Execution Count:144 | 144 |
398 | } | - |
399 | return bytesRead; executed: return bytesRead; Execution Count:858 | 858 |
400 | } | - |
401 | | - |
402 | qint64 QHttpPartPrivate::size() const | - |
403 | { | - |
404 | checkHeaderCreated(); executed (the execution status of this line is deduced): checkHeaderCreated(); | - |
405 | qint64 size = header.count(); executed (the execution status of this line is deduced): qint64 size = header.count(); | - |
406 | if (bodyDevice) { evaluated: bodyDevice yes Evaluation Count:3022 | yes Evaluation Count:930 |
| 930-3022 |
407 | size += bodyDevice->size(); executed (the execution status of this line is deduced): size += bodyDevice->size(); | - |
408 | } else { executed: } Execution Count:3022 | 3022 |
409 | size += body.count(); executed (the execution status of this line is deduced): size += body.count(); | - |
410 | } executed: } Execution Count:930 | 930 |
411 | return size; executed: return size; Execution Count:3952 | 3952 |
412 | } | - |
413 | | - |
414 | bool QHttpPartPrivate::reset() | - |
415 | { | - |
416 | bool ret = true; never executed (the execution status of this line is deduced): bool ret = true; | - |
417 | if (bodyDevice) never evaluated: bodyDevice | 0 |
418 | if (!bodyDevice->reset()) never evaluated: !bodyDevice->reset() | 0 |
419 | ret = false; never executed: ret = false; | 0 |
420 | readPointer = 0; never executed (the execution status of this line is deduced): readPointer = 0; | - |
421 | return ret; never executed: return ret; | 0 |
422 | } | - |
423 | void QHttpPartPrivate::checkHeaderCreated() const | - |
424 | { | - |
425 | if (!headerCreated) { evaluated: !headerCreated yes Evaluation Count:20 | yes Evaluation Count:4790 |
| 20-4790 |
426 | // copied from QHttpNetworkRequestPrivate::header() and adapted | - |
427 | QList<QPair<QByteArray, QByteArray> > fields = allRawHeaders(); executed (the execution status of this line is deduced): QList<QPair<QByteArray, QByteArray> > fields = allRawHeaders(); | - |
428 | QList<QPair<QByteArray, QByteArray> >::const_iterator it = fields.constBegin(); executed (the execution status of this line is deduced): QList<QPair<QByteArray, QByteArray> >::const_iterator it = fields.constBegin(); | - |
429 | for (; it != fields.constEnd(); ++it) evaluated: it != fields.constEnd() yes Evaluation Count:56 | yes Evaluation Count:20 |
| 20-56 |
430 | header += it->first + ": " + it->second + "\r\n"; executed: header += it->first + ": " + it->second + "\r\n"; Execution Count:56 | 56 |
431 | header += "\r\n"; executed (the execution status of this line is deduced): header += "\r\n"; | - |
432 | headerCreated = true; executed (the execution status of this line is deduced): headerCreated = true; | - |
433 | } executed: } Execution Count:20 | 20 |
434 | } executed: } Execution Count:4810 | 4810 |
435 | | - |
436 | Q_GLOBAL_STATIC(QThreadStorage<bool *>, seedCreatedStorage); never executed: delete x; executed: return thisGlobalStatic.pointer.load(); Execution Count:34 partially evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x) no Evaluation Count:0 | yes Evaluation Count:1 |
evaluated: !thisGlobalStatic.pointer.load() yes Evaluation Count:1 | yes Evaluation Count:33 |
partially evaluated: !thisGlobalStatic.destroyed yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-34 |
437 | | - |
438 | QHttpMultiPartPrivate::QHttpMultiPartPrivate() : contentType(QHttpMultiPart::MixedType), device(new QHttpMultiPartIODevice(this)) | - |
439 | { | - |
440 | if (!seedCreatedStorage()->hasLocalData()) { evaluated: !seedCreatedStorage()->hasLocalData() yes Evaluation Count:1 | yes Evaluation Count:32 |
| 1-32 |
441 | qsrand(QTime(0,0,0).msecsTo(QTime::currentTime()) ^ reinterpret_cast<quintptr>(this)); executed (the execution status of this line is deduced): qsrand(QTime(0,0,0).msecsTo(QTime::currentTime()) ^ reinterpret_cast<quintptr>(this)); | - |
442 | seedCreatedStorage()->setLocalData(new bool(true)); executed (the execution status of this line is deduced): seedCreatedStorage()->setLocalData(new bool(true)); | - |
443 | } executed: } Execution Count:1 | 1 |
444 | | - |
445 | boundary = QByteArray("boundary_.oOo._") executed (the execution status of this line is deduced): boundary = QByteArray("boundary_.oOo._") | - |
446 | + QByteArray::number(qrand()).toBase64() executed (the execution status of this line is deduced): + QByteArray::number(qrand()).toBase64() | - |
447 | + QByteArray::number(qrand()).toBase64() executed (the execution status of this line is deduced): + QByteArray::number(qrand()).toBase64() | - |
448 | + QByteArray::number(qrand()).toBase64(); executed (the execution status of this line is deduced): + QByteArray::number(qrand()).toBase64(); | - |
449 | | - |
450 | // boundary must not be longer than 70 characters, see RFC 2046, section 5.1.1 | - |
451 | if (boundary.count() > 70) partially evaluated: boundary.count() > 70 no Evaluation Count:0 | yes Evaluation Count:33 |
| 0-33 |
452 | boundary = boundary.left(70); never executed: boundary = boundary.left(70); | 0 |
453 | } executed: } Execution Count:33 | 33 |
454 | | - |
455 | qint64 QHttpMultiPartIODevice::size() const | - |
456 | { | - |
457 | // if not done yet, we calculate the size and the offsets of each part, | - |
458 | // including boundary (needed later in readData) | - |
459 | if (deviceSize == -1) { evaluated: deviceSize == -1 yes Evaluation Count:22 | yes Evaluation Count:2594 |
| 22-2594 |
460 | qint64 currentSize = 0; executed (the execution status of this line is deduced): qint64 currentSize = 0; | - |
461 | qint64 boundaryCount = multiPart->boundary.count(); executed (the execution status of this line is deduced): qint64 boundaryCount = multiPart->boundary.count(); | - |
462 | for (int a = 0; a < multiPart->parts.count(); a++) { evaluated: a < multiPart->parts.count() yes Evaluation Count:30 | yes Evaluation Count:22 |
| 22-30 |
463 | partOffsets.append(currentSize); executed (the execution status of this line is deduced): partOffsets.append(currentSize); | - |
464 | // 4 additional bytes for the "--" before and the "\r\n" after the boundary, | - |
465 | // and 2 bytes for the "\r\n" after the content | - |
466 | currentSize += boundaryCount + 4 + multiPart->parts.at(a).d->size() + 2; executed (the execution status of this line is deduced): currentSize += boundaryCount + 4 + multiPart->parts.at(a).d->size() + 2; | - |
467 | } executed: } Execution Count:30 | 30 |
468 | currentSize += boundaryCount + 6; // size for ending boundary, 2 beginning and ending dashes and "\r\n" executed (the execution status of this line is deduced): currentSize += boundaryCount + 6; | - |
469 | deviceSize = currentSize; executed (the execution status of this line is deduced): deviceSize = currentSize; | - |
470 | } executed: } Execution Count:22 | 22 |
471 | return deviceSize; executed: return deviceSize; Execution Count:2616 | 2616 |
472 | } | - |
473 | | - |
474 | bool QHttpMultiPartIODevice::isSequential() const | - |
475 | { | - |
476 | for (int a = 0; a < multiPart->parts.count(); a++) { evaluated: a < multiPart->parts.count() yes Evaluation Count:6150 | yes Evaluation Count:2638 |
| 2638-6150 |
477 | QIODevice *device = multiPart->parts.at(a).d->bodyDevice; executed (the execution status of this line is deduced): QIODevice *device = multiPart->parts.at(a).d->bodyDevice; | - |
478 | // we are sequential if any of the bodyDevices of our parts are sequential; | - |
479 | // when reading from a byte array, we are not sequential | - |
480 | if (device && device->isSequential()) evaluated: device yes Evaluation Count:4944 | yes Evaluation Count:1206 |
partially evaluated: device->isSequential() no Evaluation Count:0 | yes Evaluation Count:4944 |
| 0-4944 |
481 | return true; never executed: return true; | 0 |
482 | } executed: } Execution Count:6150 | 6150 |
483 | return false; executed: return false; Execution Count:2638 | 2638 |
484 | } | - |
485 | | - |
486 | bool QHttpMultiPartIODevice::reset() | - |
487 | { | - |
488 | for (int a = 0; a < multiPart->parts.count(); a++) never evaluated: a < multiPart->parts.count() | 0 |
489 | if (!multiPart->parts[a].d->reset()) never evaluated: !multiPart->parts[a].d->reset() | 0 |
490 | return false; never executed: return false; | 0 |
491 | return true; never executed: return true; | 0 |
492 | } | - |
493 | qint64 QHttpMultiPartIODevice::readData(char *data, qint64 maxSize) | - |
494 | { | - |
495 | qint64 bytesRead = 0, index = 0; executed (the execution status of this line is deduced): qint64 bytesRead = 0, index = 0; | - |
496 | | - |
497 | // skip the parts we have already read | - |
498 | while (index < multiPart->parts.count() && evaluated: index < multiPart->parts.count() yes Evaluation Count:3034 | yes Evaluation Count:28 |
| 28-3034 |
499 | readPointer >= partOffsets.at(index) + multiPart->parts.at(index).d->size()) evaluated: readPointer >= partOffsets.at(index) + multiPart->parts.at(index).d->size() yes Evaluation Count:1362 | yes Evaluation Count:1672 |
| 1362-1672 |
500 | index++; executed: index++; Execution Count:1362 | 1362 |
501 | | - |
502 | // read the data | - |
503 | while (bytesRead < maxSize && index < multiPart->parts.count()) { evaluated: bytesRead < maxSize yes Evaluation Count:880 | yes Evaluation Count:1678 |
evaluated: index < multiPart->parts.count() yes Evaluation Count:858 | yes Evaluation Count:22 |
| 22-1678 |
504 | | - |
505 | // check whether we need to read the boundary of the current part | - |
506 | QByteArray boundaryData = "--" + multiPart->boundary + "\r\n"; executed (the execution status of this line is deduced): QByteArray boundaryData = "--" + multiPart->boundary + "\r\n"; | - |
507 | qint64 boundaryCount = boundaryData.count(); executed (the execution status of this line is deduced): qint64 boundaryCount = boundaryData.count(); | - |
508 | qint64 partIndex = readPointer - partOffsets.at(index); executed (the execution status of this line is deduced): qint64 partIndex = readPointer - partOffsets.at(index); | - |
509 | if (partIndex < boundaryCount) { evaluated: partIndex < boundaryCount yes Evaluation Count:30 | yes Evaluation Count:828 |
| 30-828 |
510 | qint64 boundaryBytesRead = qMin(boundaryCount - partIndex, maxSize - bytesRead); executed (the execution status of this line is deduced): qint64 boundaryBytesRead = qMin(boundaryCount - partIndex, maxSize - bytesRead); | - |
511 | memcpy(data + bytesRead, boundaryData.constData() + partIndex, boundaryBytesRead); executed (the execution status of this line is deduced): memcpy(data + bytesRead, boundaryData.constData() + partIndex, boundaryBytesRead); | - |
512 | bytesRead += boundaryBytesRead; executed (the execution status of this line is deduced): bytesRead += boundaryBytesRead; | - |
513 | readPointer += boundaryBytesRead; executed (the execution status of this line is deduced): readPointer += boundaryBytesRead; | - |
514 | partIndex += boundaryBytesRead; executed (the execution status of this line is deduced): partIndex += boundaryBytesRead; | - |
515 | } executed: } Execution Count:30 | 30 |
516 | | - |
517 | // check whether we need to read the data of the current part | - |
518 | if (bytesRead < maxSize && partIndex >= boundaryCount && partIndex < boundaryCount + multiPart->parts.at(index).d->size()) { partially evaluated: bytesRead < maxSize yes Evaluation Count:858 | no Evaluation Count:0 |
partially evaluated: partIndex >= boundaryCount yes Evaluation Count:858 | no Evaluation Count:0 |
partially evaluated: partIndex < boundaryCount + multiPart->parts.at(index).d->size() yes Evaluation Count:858 | no Evaluation Count:0 |
| 0-858 |
519 | qint64 dataBytesRead = multiPart->parts[index].d->readData(data + bytesRead, maxSize - bytesRead); executed (the execution status of this line is deduced): qint64 dataBytesRead = multiPart->parts[index].d->readData(data + bytesRead, maxSize - bytesRead); | - |
520 | if (dataBytesRead == -1) partially evaluated: dataBytesRead == -1 no Evaluation Count:0 | yes Evaluation Count:858 |
| 0-858 |
521 | return -1; never executed: return -1; | 0 |
522 | bytesRead += dataBytesRead; executed (the execution status of this line is deduced): bytesRead += dataBytesRead; | - |
523 | readPointer += dataBytesRead; executed (the execution status of this line is deduced): readPointer += dataBytesRead; | - |
524 | partIndex += dataBytesRead; executed (the execution status of this line is deduced): partIndex += dataBytesRead; | - |
525 | } executed: } Execution Count:858 | 858 |
526 | | - |
527 | // check whether we need to read the ending CRLF of the current part | - |
528 | if (bytesRead < maxSize && partIndex >= boundaryCount + multiPart->parts.at(index).d->size()) { evaluated: bytesRead < maxSize yes Evaluation Count:30 | yes Evaluation Count:828 |
partially evaluated: partIndex >= boundaryCount + multiPart->parts.at(index).d->size() yes Evaluation Count:30 | no Evaluation Count:0 |
| 0-828 |
529 | if (bytesRead == maxSize - 1) partially evaluated: bytesRead == maxSize - 1 no Evaluation Count:0 | yes Evaluation Count:30 |
| 0-30 |
530 | return bytesRead; never executed: return bytesRead; | 0 |
531 | memcpy(data + bytesRead, "\r\n", 2); executed (the execution status of this line is deduced): memcpy(data + bytesRead, "\r\n", 2); | - |
532 | bytesRead += 2; executed (the execution status of this line is deduced): bytesRead += 2; | - |
533 | readPointer += 2; executed (the execution status of this line is deduced): readPointer += 2; | - |
534 | index++; executed (the execution status of this line is deduced): index++; | - |
535 | } executed: } Execution Count:30 | 30 |
536 | } executed: } Execution Count:858 | 858 |
537 | // check whether we need to return the final boundary | - |
538 | if (bytesRead < maxSize && index == multiPart->parts.count()) { evaluated: bytesRead < maxSize yes Evaluation Count:22 | yes Evaluation Count:1678 |
partially evaluated: index == multiPart->parts.count() yes Evaluation Count:22 | no Evaluation Count:0 |
| 0-1678 |
539 | QByteArray finalBoundary = "--" + multiPart->boundary + "--\r\n"; executed (the execution status of this line is deduced): QByteArray finalBoundary = "--" + multiPart->boundary + "--\r\n"; | - |
540 | qint64 boundaryIndex = readPointer + finalBoundary.count() - size(); executed (the execution status of this line is deduced): qint64 boundaryIndex = readPointer + finalBoundary.count() - size(); | - |
541 | qint64 lastBoundaryBytesRead = qMin(finalBoundary.count() - boundaryIndex, maxSize - bytesRead); executed (the execution status of this line is deduced): qint64 lastBoundaryBytesRead = qMin(finalBoundary.count() - boundaryIndex, maxSize - bytesRead); | - |
542 | memcpy(data + bytesRead, finalBoundary.constData() + boundaryIndex, lastBoundaryBytesRead); executed (the execution status of this line is deduced): memcpy(data + bytesRead, finalBoundary.constData() + boundaryIndex, lastBoundaryBytesRead); | - |
543 | bytesRead += lastBoundaryBytesRead; executed (the execution status of this line is deduced): bytesRead += lastBoundaryBytesRead; | - |
544 | readPointer += lastBoundaryBytesRead; executed (the execution status of this line is deduced): readPointer += lastBoundaryBytesRead; | - |
545 | } executed: } Execution Count:22 | 22 |
546 | return bytesRead; executed: return bytesRead; Execution Count:1700 | 1700 |
547 | } | - |
548 | | - |
549 | qint64 QHttpMultiPartIODevice::writeData(const char *data, qint64 maxSize) | - |
550 | { | - |
551 | Q_UNUSED(data); never executed (the execution status of this line is deduced): (void)data;; | - |
552 | Q_UNUSED(maxSize); never executed (the execution status of this line is deduced): (void)maxSize;; | - |
553 | return -1; never executed: return -1; | 0 |
554 | } | - |
555 | | - |
556 | | - |
557 | QT_END_NAMESPACE | - |
558 | | - |
| | |