// m_formElements[0] is the current item. If the destination buffer is // big enough we are going to read from more than one FormDataElement qint64 FormDataIODevice::readData(char* destination, qint64 size) { if (m_formElements.isEmpty()) return -1; qint64 copied = 0; while (copied < size && !m_formElements.isEmpty()) { const FormDataElement& element = m_formElements[0]; const qint64 available = size-copied; if (element.m_type == FormDataElement::data) { const qint64 toCopy = qMin<qint64>(available, element.m_data.size() - m_currentDelta); memcpy(destination+copied, element.m_data.data()+m_currentDelta, toCopy); m_currentDelta += toCopy; copied += toCopy; if (m_currentDelta == element.m_data.size()) moveToNextElement(); } else { const QByteArray data = m_currentFile->read(available); memcpy(destination+copied, data.constData(), data.size()); copied += data.size(); if (m_currentFile->atEnd() || !m_currentFile->isOpen()) moveToNextElement(); } } return copied; }
// m_formElements[0] is the current item. If the destination buffer is // big enough we are going to read from more than one FormDataElement qint64 FormDataIODevice::readData(char* destination, qint64 size) { if (m_formElements.isEmpty()) return -1; qint64 copied = 0; while (copied < size && !m_formElements.isEmpty()) { const FormDataElement& element = m_formElements[0]; const qint64 available = size-copied; if (element.m_type == FormDataElement::data) { const qint64 toCopy = qMin<qint64>(available, element.m_data.size() - m_currentDelta); memcpy(destination+copied, element.m_data.data()+m_currentDelta, toCopy); m_currentDelta += toCopy; copied += toCopy; if (m_currentDelta == element.m_data.size()) moveToNextElement(); } else if (element.m_type == FormDataElement::encodedFile) { quint64 toCopy = available; #if ENABLE(BLOB) if (element.m_fileLength != BlobDataItem::toEndOfFile) toCopy = qMin<qint64>(toCopy, element.m_fileLength - m_currentDelta); #endif const QByteArray data = m_currentFile->read(toCopy); memcpy(destination+copied, data.constData(), data.size()); m_currentDelta += data.size(); copied += data.size(); if (m_currentFile->atEnd() || !m_currentFile->isOpen()) moveToNextElement(); #if ENABLE(BLOB) else if (element.m_fileLength != BlobDataItem::toEndOfFile && m_currentDelta == element.m_fileLength) moveToNextElement(); #endif } } return copied; }
void FormDataIODevice::openFileForCurrentElement() { if (!m_currentFile) m_currentFile = new QFile; m_currentFile->setFileName(m_formElements[0].m_filename); m_currentFile->open(QFile::ReadOnly); #if ENABLE(BLOB) if (isValidFileTime(m_formElements[0].m_expectedFileModificationTime)) { QFileInfo info(*m_currentFile); if (!info.exists() || static_cast<time_t>(m_formElements[0].m_expectedFileModificationTime) < info.lastModified().toTime_t()) { moveToNextElement(); return; } } if (m_formElements[0].m_fileStart) m_currentFile->seek(m_formElements[0].m_fileStart); #endif }