access/qhttpmultipart.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3QHttpPart::QHttpPart() : d(new QHttpPartPrivate) -
4{ -
5}
executed: }
Execution Count:30
30
6 -
7 -
8 -
9 -
10QHttpPart::QHttpPart(const QHttpPart &other) : d(other.d) -
11{ -
12}
executed: }
Execution Count:45
45
13 -
14 -
15 -
16 -
17QHttpPart::~QHttpPart() -
18{ -
19 d = 0; -
20}
executed: }
Execution Count:60
60
21 -
22 -
23 -
24 -
25QHttpPart &QHttpPart::operator=(const QHttpPart &other) -
26{ -
27 d = other.d; -
28 return *this;
never executed: return *this;
0
29} -
30bool QHttpPart::operator==(const QHttpPart &other) const -
31{ -
32 return d == other.d || *d == *other.d;
never executed: return d == other.d || *d == *other.d;
0
33} -
34void QHttpPart::setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value) -
35{ -
36 d->setCookedHeader(header, value); -
37}
executed: }
Execution Count:60
60
38void QHttpPart::setRawHeader(const QByteArray &headerName, const QByteArray &headerValue) -
39{ -
40 d->setRawHeader(headerName, headerValue); -
41}
executed: }
Execution Count:24
24
42void QHttpPart::setBody(const QByteArray &body) -
43{ -
44 d->setBody(body); -
45}
executed: }
Execution Count:15
15
46void QHttpPart::setBodyDevice(QIODevice *device) -
47{ -
48 d->setBodyDevice(device); -
49}
executed: }
Execution Count:27
27
50QHttpMultiPart::QHttpMultiPart(QObject *parent) : QObject(*new QHttpMultiPartPrivate, parent) -
51{ -
52 QHttpMultiPartPrivate * const d = d_func(); -
53 d->contentType = MixedType; -
54}
executed: }
Execution Count:27
27
55 -
56 -
57 -
58 -
59 -
60 -
61 -
62QHttpMultiPart::QHttpMultiPart(QHttpMultiPart::ContentType contentType, QObject *parent) : QObject(*new QHttpMultiPartPrivate, parent) -
63{ -
64 QHttpMultiPartPrivate * const d = d_func(); -
65 d->contentType = contentType; -
66}
executed: }
Execution Count:6
6
67 -
68 -
69 -
70 -
71QHttpMultiPart::~QHttpMultiPart() -
72{ -
73} -
74 -
75 -
76 -
77 -
78void QHttpMultiPart::append(const QHttpPart &httpPart) -
79{ -
80 d_func()->parts.append(httpPart); -
81}
executed: }
Execution Count:45
45
82void QHttpMultiPart::setContentType(QHttpMultiPart::ContentType contentType) -
83{ -
84 d_func()->contentType = contentType; -
85}
executed: }
Execution Count:21
21
86 -
87 -
88 -
89 -
90 -
91 -
92QByteArray QHttpMultiPart::boundary() const -
93{ -
94 return d_func()->boundary;
executed: return d_func()->boundary;
Execution Count:134
134
95} -
96void QHttpMultiPart::setBoundary(const QByteArray &boundary) -
97{ -
98 d_func()->boundary = boundary; -
99}
never executed: }
0
100qint64 QHttpPartPrivate::bytesAvailable() const -
101{ -
102 checkHeaderCreated(); -
103 qint64 bytesAvailable = header.count(); -
104 if (bodyDevice) {
never evaluated: bodyDevice
0
105 bytesAvailable += bodyDevice->bytesAvailable() - readPointer; -
106 } else {
never executed: }
0
107 bytesAvailable += body.count() - readPointer; -
108 }
never executed: }
0
109 -
110 return qMax(bytesAvailable, (qint64) 0);
never executed: return qMax(bytesAvailable, (qint64) 0);
0
111} -
112 -
113qint64 QHttpPartPrivate::readData(char *data, qint64 maxSize) -
114{ -
115 checkHeaderCreated(); -
116 qint64 bytesRead = 0; -
117 qint64 headerDataCount = header.count(); -
118 -
119 -
120 if (readPointer < headerDataCount) {
evaluated: readPointer < headerDataCount
TRUEFALSE
yes
Evaluation Count:30
yes
Evaluation Count:828
30-828
121 bytesRead = qMin(headerDataCount - readPointer, maxSize); -
122 const char *headerData = header.constData(); -
123 memcpy(data, headerData + readPointer, bytesRead); -
124 readPointer += bytesRead; -
125 }
executed: }
Execution Count:30
30
126 -
127 if (bytesRead < maxSize) {
partially evaluated: bytesRead < maxSize
TRUEFALSE
yes
Evaluation Count:858
no
Evaluation Count:0
0-858
128 if (bodyDevice) {
evaluated: bodyDevice
TRUEFALSE
yes
Evaluation Count:714
yes
Evaluation Count:144
144-714
129 qint64 dataBytesRead = bodyDevice->read(data + bytesRead, maxSize - bytesRead); -
130 if (dataBytesRead == -1)
partially evaluated: dataBytesRead == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:714
0-714
131 return -1;
never executed: return -1;
0
132 bytesRead += dataBytesRead; -
133 readPointer += dataBytesRead; -
134 } else {
executed: }
Execution Count:714
714
135 qint64 contentBytesRead = qMin(body.count() - readPointer + headerDataCount, maxSize - bytesRead); -
136 const char *contentData = body.constData(); -
137 -
138 -
139 memcpy(data + bytesRead, contentData + readPointer - headerDataCount, contentBytesRead); -
140 bytesRead += contentBytesRead; -
141 readPointer += contentBytesRead; -
142 }
executed: }
Execution Count:144
144
143 } -
144 return bytesRead;
executed: return bytesRead;
Execution Count:858
858
145} -
146 -
147qint64 QHttpPartPrivate::size() const -
148{ -
149 checkHeaderCreated(); -
150 qint64 size = header.count(); -
151 if (bodyDevice) {
evaluated: bodyDevice
TRUEFALSE
yes
Evaluation Count:3022
yes
Evaluation Count:930
930-3022
152 size += bodyDevice->size(); -
153 } else {
executed: }
Execution Count:3022
3022
154 size += body.count(); -
155 }
executed: }
Execution Count:930
930
156 return size;
executed: return size;
Execution Count:3952
3952
157} -
158 -
159bool QHttpPartPrivate::reset() -
160{ -
161 bool ret = true; -
162 if (bodyDevice)
never evaluated: bodyDevice
0
163 if (!bodyDevice->reset())
never evaluated: !bodyDevice->reset()
0
164 ret = false;
never executed: ret = false;
0
165 readPointer = 0; -
166 return ret;
never executed: return ret;
0
167} -
168void QHttpPartPrivate::checkHeaderCreated() const -
169{ -
170 if (!headerCreated) {
evaluated: !headerCreated
TRUEFALSE
yes
Evaluation Count:20
yes
Evaluation Count:4790
20-4790
171 -
172 QList<QPair<QByteArray, QByteArray> > fields = allRawHeaders(); -
173 QList<QPair<QByteArray, QByteArray> >::const_iterator it = fields.constBegin(); -
174 for (; it != fields.constEnd(); ++it)
evaluated: it != fields.constEnd()
TRUEFALSE
yes
Evaluation Count:56
yes
Evaluation Count:20
20-56
175 header += it->first + ": " + it->second + "\r\n";
executed: header += it->first + ": " + it->second + "\r\n";
Execution Count:56
56
176 header += "\r\n"; -
177 headerCreated = true; -
178 }
executed: }
Execution Count:20
20
179}
executed: }
Execution Count:4810
4810
180 -
181static QThreadStorage<bool *> *seedCreatedStorage() { static QGlobalStatic<QThreadStorage<bool *> > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QThreadStorage<bool *> *x = new QThreadStorage<bool *>; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QThreadStorage<bool *> > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); };
never executed: delete x;
executed: return thisGlobalStatic.pointer.load();
Execution Count:34
partially evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
evaluated: !thisGlobalStatic.pointer.load()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:33
partially evaluated: !thisGlobalStatic.destroyed
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-34
182 -
183QHttpMultiPartPrivate::QHttpMultiPartPrivate() : contentType(QHttpMultiPart::MixedType), device(new QHttpMultiPartIODevice(this)) -
184{ -
185 if (!seedCreatedStorage()->hasLocalData()) {
evaluated: !seedCreatedStorage()->hasLocalData()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:32
1-32
186 qsrand(QTime(0,0,0).msecsTo(QTime::currentTime()) ^ reinterpret_cast<quintptr>(this)); -
187 seedCreatedStorage()->setLocalData(new bool(true)); -
188 }
executed: }
Execution Count:1
1
189 -
190 boundary = QByteArray("boundary_.oOo._") -
191 + QByteArray::number(qrand()).toBase64() -
192 + QByteArray::number(qrand()).toBase64() -
193 + QByteArray::number(qrand()).toBase64(); -
194 -
195 -
196 if (boundary.count() > 70)
partially evaluated: boundary.count() > 70
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:33
0-33
197 boundary = boundary.left(70);
never executed: boundary = boundary.left(70);
0
198}
executed: }
Execution Count:33
33
199 -
200qint64 QHttpMultiPartIODevice::size() const -
201{ -
202 -
203 -
204 if (deviceSize == -1) {
evaluated: deviceSize == -1
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:2594
22-2594
205 qint64 currentSize = 0; -
206 qint64 boundaryCount = multiPart->boundary.count(); -
207 for (int a = 0; a < multiPart->parts.count(); a++) {
evaluated: a < multiPart->parts.count()
TRUEFALSE
yes
Evaluation Count:30
yes
Evaluation Count:22
22-30
208 partOffsets.append(currentSize); -
209 -
210 -
211 currentSize += boundaryCount + 4 + multiPart->parts.at(a).d->size() + 2; -
212 }
executed: }
Execution Count:30
30
213 currentSize += boundaryCount + 6; -
214 deviceSize = currentSize; -
215 }
executed: }
Execution Count:22
22
216 return deviceSize;
executed: return deviceSize;
Execution Count:2616
2616
217} -
218 -
219bool QHttpMultiPartIODevice::isSequential() const -
220{ -
221 for (int a = 0; a < multiPart->parts.count(); a++) {
evaluated: a < multiPart->parts.count()
TRUEFALSE
yes
Evaluation Count:6150
yes
Evaluation Count:2638
2638-6150
222 QIODevice *device = multiPart->parts.at(a).d->bodyDevice; -
223 -
224 -
225 if (device && device->isSequential())
evaluated: device
TRUEFALSE
yes
Evaluation Count:4944
yes
Evaluation Count:1206
partially evaluated: device->isSequential()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4944
0-4944
226 return true;
never executed: return true;
0
227 }
executed: }
Execution Count:6150
6150
228 return false;
executed: return false;
Execution Count:2638
2638
229} -
230 -
231bool QHttpMultiPartIODevice::reset() -
232{ -
233 for (int a = 0; a < multiPart->parts.count(); a++)
never evaluated: a < multiPart->parts.count()
0
234 if (!multiPart->parts[a].d->reset())
never evaluated: !multiPart->parts[a].d->reset()
0
235 return false;
never executed: return false;
0
236 return true;
never executed: return true;
0
237} -
238qint64 QHttpMultiPartIODevice::readData(char *data, qint64 maxSize) -
239{ -
240 qint64 bytesRead = 0, index = 0; -
241 -
242 -
243 while (index < multiPart->parts.count() &&
evaluated: index < multiPart->parts.count()
TRUEFALSE
yes
Evaluation Count:3034
yes
Evaluation Count:28
28-3034
244 readPointer >= partOffsets.at(index) + multiPart->parts.at(index).d->size())
evaluated: readPointer >= partOffsets.at(index) + multiPart->parts.at(index).d->size()
TRUEFALSE
yes
Evaluation Count:1362
yes
Evaluation Count:1672
1362-1672
245 index++;
executed: index++;
Execution Count:1362
1362
246 -
247 -
248 while (bytesRead < maxSize && index < multiPart->parts.count()) {
evaluated: bytesRead < maxSize
TRUEFALSE
yes
Evaluation Count:880
yes
Evaluation Count:1678
evaluated: index < multiPart->parts.count()
TRUEFALSE
yes
Evaluation Count:858
yes
Evaluation Count:22
22-1678
249 -
250 -
251 QByteArray boundaryData = "--" + multiPart->boundary + "\r\n"; -
252 qint64 boundaryCount = boundaryData.count(); -
253 qint64 partIndex = readPointer - partOffsets.at(index); -
254 if (partIndex < boundaryCount) {
evaluated: partIndex < boundaryCount
TRUEFALSE
yes
Evaluation Count:30
yes
Evaluation Count:828
30-828
255 qint64 boundaryBytesRead = qMin(boundaryCount - partIndex, maxSize - bytesRead); -
256 memcpy(data + bytesRead, boundaryData.constData() + partIndex, boundaryBytesRead); -
257 bytesRead += boundaryBytesRead; -
258 readPointer += boundaryBytesRead; -
259 partIndex += boundaryBytesRead; -
260 }
executed: }
Execution Count:30
30
261 -
262 -
263 if (bytesRead < maxSize && partIndex >= boundaryCount && partIndex < boundaryCount + multiPart->parts.at(index).d->size()) {
partially evaluated: bytesRead < maxSize
TRUEFALSE
yes
Evaluation Count:858
no
Evaluation Count:0
partially evaluated: partIndex >= boundaryCount
TRUEFALSE
yes
Evaluation Count:858
no
Evaluation Count:0
partially evaluated: partIndex < boundaryCount + multiPart->parts.at(index).d->size()
TRUEFALSE
yes
Evaluation Count:858
no
Evaluation Count:0
0-858
264 qint64 dataBytesRead = multiPart->parts[index].d->readData(data + bytesRead, maxSize - bytesRead); -
265 if (dataBytesRead == -1)
partially evaluated: dataBytesRead == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:858
0-858
266 return -1;
never executed: return -1;
0
267 bytesRead += dataBytesRead; -
268 readPointer += dataBytesRead; -
269 partIndex += dataBytesRead; -
270 }
executed: }
Execution Count:858
858
271 -
272 -
273 if (bytesRead < maxSize && partIndex >= boundaryCount + multiPart->parts.at(index).d->size()) {
evaluated: bytesRead < maxSize
TRUEFALSE
yes
Evaluation Count:30
yes
Evaluation Count:828
partially evaluated: partIndex >= boundaryCount + multiPart->parts.at(index).d->size()
TRUEFALSE
yes
Evaluation Count:30
no
Evaluation Count:0
0-828
274 if (bytesRead == maxSize - 1)
partially evaluated: bytesRead == maxSize - 1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:30
0-30
275 return bytesRead;
never executed: return bytesRead;
0
276 memcpy(data + bytesRead, "\r\n", 2); -
277 bytesRead += 2; -
278 readPointer += 2; -
279 index++; -
280 }
executed: }
Execution Count:30
30
281 }
executed: }
Execution Count:858
858
282 -
283 if (bytesRead < maxSize && index == multiPart->parts.count()) {
evaluated: bytesRead < maxSize
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:1678
partially evaluated: index == multiPart->parts.count()
TRUEFALSE
yes
Evaluation Count:22
no
Evaluation Count:0
0-1678
284 QByteArray finalBoundary = "--" + multiPart->boundary + "--\r\n"; -
285 qint64 boundaryIndex = readPointer + finalBoundary.count() - size(); -
286 qint64 lastBoundaryBytesRead = qMin(finalBoundary.count() - boundaryIndex, maxSize - bytesRead); -
287 memcpy(data + bytesRead, finalBoundary.constData() + boundaryIndex, lastBoundaryBytesRead); -
288 bytesRead += lastBoundaryBytesRead; -
289 readPointer += lastBoundaryBytesRead; -
290 }
executed: }
Execution Count:22
22
291 return bytesRead;
executed: return bytesRead;
Execution Count:1700
1700
292} -
293 -
294qint64 QHttpMultiPartIODevice::writeData(const char *data, qint64 maxSize) -
295{ -
296 (void)data;; -
297 (void)maxSize;; -
298 return -1;
never executed: return -1;
0
299} -
300 -
301 -
302 -
303 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial