Qt 4.8
Public Functions | Public Variables | Private Functions | Properties | List of all members
QHttpPartPrivate Class Reference

#include <qhttpmultipart_p.h>

Inheritance diagram for QHttpPartPrivate:
QSharedData QNetworkHeadersPrivate

Public Functions

qint64 bytesAvailable () const
 
bool operator== (const QHttpPartPrivate &other) const
 
 QHttpPartPrivate ()
 
 QHttpPartPrivate (const QHttpPartPrivate &other)
 
qint64 readData (char *data, qint64 maxSize)
 
bool reset ()
 
void setBody (const QByteArray &newBody)
 
void setBodyDevice (QIODevice *device)
 
qint64 size () const
 
 ~QHttpPartPrivate ()
 
- Public Functions inherited from QSharedData
 QSharedData ()
 Constructs a QSharedData object with a reference count of 0. More...
 
 QSharedData (const QSharedData &)
 Constructs a QSharedData object with reference count 0. More...
 
- Public Functions inherited from QNetworkHeadersPrivate
RawHeadersList allRawHeaders () const
 
RawHeadersList::ConstIterator findRawHeader (const QByteArray &key) const
 
QList< QByteArrayrawHeadersKeys () const
 
void setAllRawHeaders (const RawHeadersList &list)
 Sets the internal raw headers list to match list. More...
 
void setCookedHeader (QNetworkRequest::KnownHeaders header, const QVariant &value)
 
void setRawHeader (const QByteArray &key, const QByteArray &value)
 

Public Variables

QByteArray body
 
QIODevicebodyDevice
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 
- Public Variables inherited from QNetworkHeadersPrivate
AttributesMap attributes
 
CookedHeadersMap cookedHeaders
 
QWeakPointer< QObjectoriginatingObject
 
RawHeadersList rawHeaders
 

Private Functions

void checkHeaderCreated () const
 

Properties

QByteArray header
 
bool headerCreated
 
qint64 readPointer
 

Additional Inherited Members

- Public Types inherited from QNetworkHeadersPrivate
typedef QHash< QNetworkRequest::Attribute, QVariantAttributesMap
 
typedef QHash< QNetworkRequest::KnownHeaders, QVariantCookedHeadersMap
 
typedef QPair< QByteArray, QByteArrayRawHeaderPair
 
typedef QList< RawHeaderPairRawHeadersList
 
- Static Public Functions inherited from QNetworkHeadersPrivate
static QDateTime fromHttpDate (const QByteArray &value)
 
static QByteArray toHttpDate (const QDateTime &dt)
 

Detailed Description

Definition at line 63 of file qhttpmultipart_p.h.

Constructors and Destructors

◆ QHttpPartPrivate() [1/2]

QHttpPartPrivate::QHttpPartPrivate ( )
inline

Definition at line 66 of file qhttpmultipart_p.h.

66  : bodyDevice(0), headerCreated(false), readPointer(0)
67  {
68  }
QIODevice * bodyDevice

◆ ~QHttpPartPrivate()

QHttpPartPrivate::~QHttpPartPrivate ( )
inline

Definition at line 69 of file qhttpmultipart_p.h.

70  {
71  }

◆ QHttpPartPrivate() [2/2]

QHttpPartPrivate::QHttpPartPrivate ( const QHttpPartPrivate other)
inline

Definition at line 74 of file qhttpmultipart_p.h.

75  : QSharedData(other), QNetworkHeadersPrivate(other), body(other.body),
77  {
78  bodyDevice = other.bodyDevice;
79  }
QSharedData()
Constructs a QSharedData object with a reference count of 0.
Definition: qshareddata.h:61
QIODevice * bodyDevice

Functions

◆ bytesAvailable()

qint64 QHttpPartPrivate::bytesAvailable ( ) const

Definition at line 358 of file qhttpmultipart.cpp.

Referenced by setBody().

359 {
362  if (bodyDevice) {
363  bytesAvailable += bodyDevice->bytesAvailable() - readPointer;
364  } else {
365  bytesAvailable += body.count() - readPointer;
366  }
367  // the device might have closed etc., so make sure we do not return a negative value
368  return qMax(bytesAvailable, (qint64) 0);
369 }
void checkHeaderCreated() const
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
qint64 bytesAvailable() const
__int64 qint64
Definition: qglobal.h:942
int count(char c) const
Returns the number of occurrences of character ch in the byte array.
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
Definition: qiodevice.cpp:752
QIODevice * bodyDevice

◆ checkHeaderCreated()

void QHttpPartPrivate::checkHeaderCreated ( ) const
private

Definition at line 426 of file qhttpmultipart.cpp.

427 {
428  if (!headerCreated) {
429  // copied from QHttpNetworkRequestPrivate::header() and adapted
431  QList<QPair<QByteArray, QByteArray> >::const_iterator it = fields.constBegin();
432  for (; it != fields.constEnd(); ++it)
433  header += it->first + ": " + it->second + "\r\n";
434  header += "\r\n";
435  headerCreated = true;
436  }
437 }
#define it(className, varName)
RawHeadersList allRawHeaders() const
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ operator==()

bool QHttpPartPrivate::operator== ( const QHttpPartPrivate other) const
inline

Definition at line 81 of file qhttpmultipart_p.h.

82  {
83  return rawHeaders == other.rawHeaders && body == other.body &&
84  bodyDevice == other.bodyDevice && readPointer == other.readPointer;
85  }
QIODevice * bodyDevice

◆ readData()

qint64 QHttpPartPrivate::readData ( char *  data,
qint64  maxSize 
)

Definition at line 371 of file qhttpmultipart.cpp.

Referenced by QHttpMultiPartIODevice::bytesToWrite(), and setBody().

372 {
374  qint64 bytesRead = 0;
375  qint64 headerDataCount = header.count();
376 
377  // read header if it has not been read yet
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;
383  }
384  // read content if there is still space
385  if (bytesRead < maxSize) {
386  if (bodyDevice) {
387  qint64 dataBytesRead = bodyDevice->read(data + bytesRead, maxSize - bytesRead);
388  if (dataBytesRead == -1)
389  return -1;
390  bytesRead += dataBytesRead;
391  readPointer += dataBytesRead;
392  } else {
393  qint64 contentBytesRead = qMin(body.count() - readPointer + headerDataCount, maxSize - bytesRead);
394  const char *contentData = body.constData();
395  // if this method is called several times, we need to find the
396  // right offset in the content ourselves:
397  memcpy(data + bytesRead, contentData + readPointer - headerDataCount, contentBytesRead);
398  bytesRead += contentBytesRead;
399  readPointer += contentBytesRead;
400  }
401  }
402  return bytesRead;
403 }
void checkHeaderCreated() const
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
static const char * data(const QByteArray &arr)
__int64 qint64
Definition: qglobal.h:942
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int count(char c) const
Returns the number of occurrences of character ch in the byte array.
QIODevice * bodyDevice

◆ reset()

bool QHttpPartPrivate::reset ( )

Definition at line 417 of file qhttpmultipart.cpp.

Referenced by QHttpMultiPartIODevice::bytesToWrite(), and setBody().

418 {
419  bool ret = true;
420  if (bodyDevice)
421  if (!bodyDevice->reset())
422  ret = false;
423  readPointer = 0;
424  return ret;
425 }
virtual bool reset()
Seeks to the start of input for random-access devices.
Definition: qiodevice.cpp:732
QIODevice * bodyDevice

◆ setBody()

void QHttpPartPrivate::setBody ( const QByteArray newBody)
inline

Definition at line 91 of file qhttpmultipart_p.h.

Referenced by QHttpPart::setBody().

91  {
92  body = newBody;
93  readPointer = 0;
94  }

◆ setBodyDevice()

void QHttpPartPrivate::setBodyDevice ( QIODevice device)
inline

Definition at line 87 of file qhttpmultipart_p.h.

Referenced by QHttpPart::setBodyDevice().

87  {
88  bodyDevice = device;
89  readPointer = 0;
90  }
QIODevice * bodyDevice

◆ size()

qint64 QHttpPartPrivate::size ( ) const

Definition at line 405 of file qhttpmultipart.cpp.

Referenced by QHttpMultiPartIODevice::atEnd(), QHttpMultiPartIODevice::bytesAvailable(), QHttpMultiPartIODevice::bytesToWrite(), QHttpMultiPartIODevice::readData(), and setBody().

406 {
408  qint64 size = header.count();
409  if (bodyDevice) {
410  size += bodyDevice->size();
411  } else {
412  size += body.count();
413  }
414  return size;
415 }
void checkHeaderCreated() const
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
Definition: qiodevice.cpp:642
__int64 qint64
Definition: qglobal.h:942
int count(char c) const
Returns the number of occurrences of character ch in the byte array.
QIODevice * bodyDevice
qint64 size() const

Properties

◆ body

QByteArray QHttpPartPrivate::body

Definition at line 103 of file qhttpmultipart_p.h.

Referenced by operator==(), and setBody().

◆ bodyDevice

QIODevice* QHttpPartPrivate::bodyDevice

Definition at line 104 of file qhttpmultipart_p.h.

Referenced by operator==(), QHttpPartPrivate(), and setBodyDevice().

◆ header

QByteArray QHttpPartPrivate::header
mutableprivate

Definition at line 109 of file qhttpmultipart_p.h.

◆ headerCreated

bool QHttpPartPrivate::headerCreated
mutableprivate

Definition at line 110 of file qhttpmultipart_p.h.

◆ readPointer

qint64 QHttpPartPrivate::readPointer
private

The documentation for this class was generated from the following files: