44 #include "QtCore/qdatetime.h" 45 #include "QtCore/qmutex.h" 46 #include "QtCore/qthreadstorage.h" 138 return d == other.
d || *
d == *other.
d;
290 d->contentType = contentType;
305 d_func()->parts.append(httpPart);
322 d_func()->contentType = contentType;
332 return d_func()->boundary;
360 checkHeaderCreated();
361 qint64 bytesAvailable = header.count();
363 bytesAvailable += bodyDevice->bytesAvailable() - readPointer;
365 bytesAvailable += body.count() - readPointer;
373 checkHeaderCreated();
375 qint64 headerDataCount = header.count();
378 if (readPointer < headerDataCount) {
379 bytesRead =
qMin(headerDataCount - readPointer, maxSize);
380 const char *headerData = header.constData();
381 memcpy(data, headerData + readPointer, bytesRead);
382 readPointer += bytesRead;
385 if (bytesRead < maxSize) {
387 qint64 dataBytesRead = bodyDevice->read(data + bytesRead, maxSize - bytesRead);
388 if (dataBytesRead == -1)
390 bytesRead += dataBytesRead;
391 readPointer += dataBytesRead;
393 qint64 contentBytesRead =
qMin(body.count() - readPointer + headerDataCount, maxSize - bytesRead);
394 const char *contentData = body.constData();
397 memcpy(data + bytesRead, contentData + readPointer - headerDataCount, contentBytesRead);
398 bytesRead += contentBytesRead;
399 readPointer += contentBytesRead;
407 checkHeaderCreated();
408 qint64 size = header.count();
410 size += bodyDevice->size();
412 size += body.count();
421 if (!bodyDevice->reset())
428 if (!headerCreated) {
433 header += it->
first +
": " + it->second +
"\r\n";
435 headerCreated =
true;
443 if (!seedCreatedStorage()->hasLocalData()) {
445 seedCreatedStorage()->setLocalData(
new bool(
true));
462 if (deviceSize == -1) {
464 qint64 boundaryCount = multiPart->boundary.count();
465 for (
int a = 0;
a < multiPart->parts.count();
a++) {
466 partOffsets.append(currentSize);
469 currentSize += boundaryCount + 4 + multiPart->parts.at(
a).d->size() + 2;
471 currentSize += boundaryCount + 6;
472 deviceSize = currentSize;
479 for (
int a = 0;
a < multiPart->parts.count();
a++) {
491 for (
int a = 0;
a < multiPart->parts.count();
a++)
492 if (!multiPart->parts[
a].d->reset())
503 readPointer >= partOffsets.at(
index) + multiPart->parts.at(
index).d->size()
504 + multiPart->boundary.count() + 6)
508 while (bytesRead < maxSize && index < multiPart->
parts.
count()) {
511 QByteArray boundaryData =
"--" + multiPart->boundary +
"\r\n";
513 qint64 partIndex = readPointer - partOffsets.at(
index);
514 if (partIndex < boundaryCount) {
515 qint64 boundaryBytesRead =
qMin(boundaryCount - partIndex, maxSize - bytesRead);
516 memcpy(data + bytesRead, boundaryData.
constData() + partIndex, boundaryBytesRead);
517 bytesRead += boundaryBytesRead;
518 readPointer += boundaryBytesRead;
519 partIndex += boundaryBytesRead;
523 if (bytesRead < maxSize && partIndex >= boundaryCount && partIndex < boundaryCount + multiPart->
parts.
at(
index).
d->
size()) {
524 qint64 dataBytesRead = multiPart->parts[
index].d->readData(data + bytesRead, maxSize - bytesRead);
525 if (dataBytesRead == -1)
527 bytesRead += dataBytesRead;
528 readPointer += dataBytesRead;
529 partIndex += dataBytesRead;
533 if (bytesRead < maxSize && partIndex >= boundaryCount + multiPart->parts.at(
index).d->size()) {
534 if (bytesRead == maxSize - 1)
536 memcpy(data + bytesRead,
"\r\n", 2);
543 if (bytesRead < maxSize && index == multiPart->
parts.
count()) {
544 QByteArray finalBoundary =
"--" + multiPart->boundary +
"--\r\n";
545 qint64 boundaryIndex = readPointer + finalBoundary.
count() - size();
546 qint64 lastBoundaryBytesRead =
qMin(finalBoundary.
count() - boundaryIndex, maxSize - bytesRead);
547 memcpy(data + bytesRead, finalBoundary.
constData() + boundaryIndex, lastBoundaryBytesRead);
548 bytesRead += lastBoundaryBytesRead;
549 readPointer += lastBoundaryBytesRead;
The QVariant class acts like a union for the most common Qt data types.
void checkHeaderCreated() const
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
virtual qint64 writeData(const char *data, qint64 maxSize)
Writes up to maxSize bytes from data to the device.
#define it(className, varName)
static QByteArray headerName(QNetworkRequest::KnownHeaders header)
The QByteArray class provides an array of bytes.
Q_GLOBAL_STATIC(QThreadStorage< bool *>, seedCreatedStorage)
void append(const QHttpPart &httpPart)
Appends httpPart to this multipart.
bool operator==(const QHttpPart &other) const
Returns true if this object is the same as other (i.e., if they have the same headers and body)...
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
Q_CORE_EXPORT int qrand()
The QObject class is the base class of all Qt objects.
KnownHeaders
List of known header types that QNetworkRequest parses.
~QHttpMultiPart()
Destroys the multipart.
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
void setRawHeader(const QByteArray &headerName, const QByteArray &headerValue)
Sets the header headerName to be of value headerValue.
QByteArray boundary() const
returns the boundary.
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
void setBody(const QByteArray &newBody)
QHttpMultiPartIODevice * device
The QTime class provides clock time functions.
#define QT_BEGIN_NAMESPACE
This macro expands to.
~QHttpPart()
Destroys this QHttpPart.
QHttpPart()
Constructs an empty QHttpPart object.
void setBody(const QByteArray &body)
Sets the body of this MIME part to body.
const T & at(int i) const
Returns the item at index position i in the list.
qint64 bytesAvailable() const
static const char * data(const QByteArray &arr)
QByteArray left(int len) const
Returns a byte array that contains the leftmost len bytes of this byte array.
QSharedDataPointer< QHttpPartPrivate > d
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
T & first()
Returns a reference to the first item in the list.
const char * constData() const
Returns a pointer to the data stored in the byte array.
int count(char c) const
Returns the number of occurrences of character ch in the byte array.
static QTime currentTime()
Returns the current time as reported by the system clock.
QHttpMultiPart(QObject *parent=0)
Constructs a QHttpMultiPart with content type MixedType and sets parent as the parent object...
QObject * parent() const
Returns a pointer to the parent object.
void setBodyDevice(QIODevice *device)
virtual bool reset()
Seeks to the start of input for random-access devices.
void setBodyDevice(QIODevice *device)
Sets the device to read the content from to device.
qint64 readData(char *data, qint64 maxSize)
QByteArray toBase64() const
Returns a copy of the byte array, encoded as Base64.
The QHttpMultiPart class resembles a MIME multipart message to be sent over HTTP. ...
The QHttpPart class holds a body part to be used inside a HTTP multipart MIME message.
ContentType
List of known content types for a multipart subtype as described in RFC 2046 and others.
QHttpPart & operator=(const QHttpPart &other)
Creates a copy of other.
Q_CORE_EXPORT void qsrand(uint seed)
virtual qint64 readData(char *data, qint64 maxSize)
Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an...
void setContentType(ContentType contentType)
Sets the content type to contentType.
The QIODevice class is the base interface class of all I/O devices in Qt.
static QByteArray headerValue(QNetworkRequest::KnownHeaders header, const QVariant &value)
void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value)
Sets the value of the known header header to be value, overriding any previously set headers...
The QThreadStorage class provides per-thread data storage.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...
void setBoundary(const QByteArray &boundary)
Sets the boundary to boundary.
The QList class is a template class that provides lists.
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...