QByteArray BasketModel::modelDataToXML(bool encrypted) { QDomDocument doc; QDomElement root = doc.createElement( "basket-passwords" ); root.setAttribute(QString("ident"), identifier()); setTimeModified(QDateTime::currentDateTime()); //lastDBModified = QDateTime::currentDateTime(); root.setAttribute(QString("modified"), lastDBModified.toString(DATE_TIME_FORMAT)); doc.appendChild( root ); for ( int i = 0; i < rootItem->childCount(); i++ ) { QDomElement child = convertBasketItemToDomElement(rootItem->childItemAt(i), doc); root.appendChild(child); } QByteArray clearBuffer; QBuffer clearFile ( &clearBuffer ); if ( !clearFile.open( QIODevice::WriteOnly | QIODevice::Text ) ) return QByteArray(); QTextStream clearStream(&clearFile); doc.save(clearStream, 4); clearFile.close(); if ( !encrypted ) return clearBuffer; BasketUtils butil; QByteArray encryptedBuffer = butil.crypt(clearBuffer, hash()); return encryptedBuffer; }
void NetworkDataTaskBlob::didGetSize(long long size) { ASSERT(isMainThread()); if (m_state == State::Canceling || m_state == State::Completed || (!m_client && !isDownload())) { clearStream(); return; } // If the size is -1, it means the file has been moved or changed. Fail now. if (size == -1) { didFail(Error::NotFoundError); return; } // The size passed back is the size of the whole file. If the underlying item is a sliced file, we need to use the slice length. const BlobDataItem& item = m_blobData->items().at(m_sizeItemCount); size = item.length(); // Cache the size. m_itemLengthList.append(size); // Count the size. m_totalSize += size; m_totalRemainingSize += size; m_sizeItemCount++; // Continue with the next item. getSizeForNext(); }
QByteArray BasketModel::indexesToXML(const QModelIndexList &indexes) const { QDomDocument doc; QDomElement root = doc.createElement( "basket-passwords-items" ); doc.appendChild( root ); foreach(QModelIndex idx, indexes) { if ( !idx.isValid() ) continue; if ( idx.column() != 0 ) continue; BasketBaseItem *item = static_cast<BasketBaseItem *>(idx.internalPointer()); if ( !item ) continue; QDomElement child = convertBasketItemToDomElement(item, doc); root.appendChild(child); } QByteArray clearBuffer; QBuffer clearFile ( &clearBuffer ); if ( !clearFile.open( QIODevice::WriteOnly | QIODevice::Text ) ) return QByteArray(); QTextStream clearStream(&clearFile); doc.save(clearStream, 4); clearFile.close(); return clearBuffer; }
NetworkDataTaskBlob::~NetworkDataTaskBlob() { for (auto& fileReference : m_fileReferences) fileReference->revokeFileAccess(); clearStream(); m_session->unregisterNetworkDataTask(*this); }
void NetworkDataTaskBlob::didFinish() { if (m_downloadFile != invalidPlatformFileHandle) { didFinishDownload(); return; } ASSERT(!m_sandboxExtension); LOG(NetworkSession, "%p - NetworkDataTaskBlob::didFinish", this); clearStream(); ASSERT(m_client); m_client->didCompleteWithError({ }); }
void NetworkDataTaskBlob::didRead(int bytesRead) { if (m_state == State::Canceling || m_state == State::Completed || (!m_client && !isDownload())) { clearStream(); return; } if (bytesRead < 0) { didFail(Error::NotReadableError); return; } Ref<NetworkDataTaskBlob> protectedThis(*this); consumeData(m_buffer.data(), bytesRead); }
void NetworkDataTaskBlob::didOpen(bool success) { if (m_state == State::Canceling || m_state == State::Completed || (!m_client && !isDownload())) { clearStream(); return; } if (!success) { didFail(Error::NotReadableError); return; } Ref<NetworkDataTaskBlob> protectedThis(*this); read(); }
void PSD::clearData() { removeFromStorage(); layerIdIdxMap.clear(); pathMap.clear(); storageStarted = false; psd::PSDFile::clearData(); #ifdef LOAD_MEMORY clearMemory(); #else clearStream(); #endif }
void NetworkDataTaskBlob::didFail(Error errorCode) { ASSERT(!m_sandboxExtension); Ref<NetworkDataTaskBlob> protectedThis(*this); if (isDownload()) { didFailDownload(ResourceError(webKitBlobResourceDomain, static_cast<int>(errorCode), m_firstRequest.url(), String())); return; } LOG(NetworkSession, "%p - NetworkDataTaskBlob::didFail", this); clearStream(); ASSERT(m_client); m_client->didCompleteWithError(ResourceError(webKitBlobResourceDomain, static_cast<int>(errorCode), m_firstRequest.url(), String())); }
void NetworkDataTaskBlob::didFinishDownload() { LOG(NetworkSession, "%p - NetworkDataTaskBlob::didFinishDownload", this); ASSERT(isDownload()); closeFile(m_downloadFile); m_downloadFile = invalidPlatformFileHandle; if (m_sandboxExtension) { m_sandboxExtension->revoke(); m_sandboxExtension = nullptr; } clearStream(); auto* download = NetworkProcess::singleton().downloadManager().download(m_pendingDownloadID); ASSERT(download); download->didFinish(); }
void NetworkDataTaskBlob::didFailDownload(const ResourceError& error) { LOG(NetworkSession, "%p - NetworkDataTaskBlob::didFailDownload", this); clearStream(); cleanDownloadFiles(); if (m_sandboxExtension) { m_sandboxExtension->revoke(); m_sandboxExtension = nullptr; } if (m_client) m_client->didCompleteWithError(error); else { auto* download = NetworkProcess::singleton().downloadManager().download(m_pendingDownloadID); ASSERT(download); download->didFail(error, IPC::DataReference()); } }
void NetworkDataTaskBlob::resume() { ASSERT(m_state != State::Running); if (m_state == State::Canceling || m_state == State::Completed) return; m_state = State::Running; if (m_scheduledFailureType != NoFailure) { ASSERT(m_failureTimer.isActive()); return; } RunLoop::main().dispatch([this, protectedThis = makeRef(*this)] { if (m_state == State::Canceling || m_state == State::Completed || !m_client) { clearStream(); return; } if (!equalLettersIgnoringASCIICase(m_firstRequest.httpMethod(), "get")) { didFail(Error::MethodNotAllowed); return; } // If the blob data is not found, fail now. if (!m_blobData) { didFail(Error::NotFoundError); return; } // Parse the "Range" header we care about. String range = m_firstRequest.httpHeaderField(HTTPHeaderName::Range); if (!range.isEmpty() && !parseRange(range, m_rangeOffset, m_rangeEnd, m_rangeSuffixLength)) { didReceiveResponse(Error::RangeError); return; } getSizeForNext(); }); }
void NetworkDataTaskBlob::didReceiveResponse(Error errorCode) { LOG(NetworkSession, "%p - NetworkDataTaskBlob::didReceiveResponse(%u)", this, static_cast<unsigned>(errorCode)); Ref<NetworkDataTaskBlob> protectedThis(*this); ResourceResponse response(m_firstRequest.url(), errorCode != Error::NoError ? "text/plain" : m_blobData->contentType(), errorCode != Error::NoError ? 0 : m_totalRemainingSize, String()); switch (errorCode) { case Error::NoError: { bool isRangeRequest = m_rangeOffset != kPositionNotSpecified; response.setHTTPStatusCode(isRangeRequest ? httpPartialContent : httpOK); response.setHTTPStatusText(isRangeRequest ? httpPartialContentText : httpOKText); response.setHTTPHeaderField(HTTPHeaderName::ContentType, m_blobData->contentType()); response.setHTTPHeaderField(HTTPHeaderName::ContentLength, String::number(m_totalRemainingSize)); if (isRangeRequest) response.setHTTPHeaderField(HTTPHeaderName::ContentRange, ParsedContentRange(m_rangeOffset, m_rangeEnd, m_totalSize).headerValue()); // FIXME: If a resource identified with a blob: URL is a File object, user agents must use that file's name attribute, // as if the response had a Content-Disposition header with the filename parameter set to the File's name attribute. // Notably, this will affect a name suggested in "File Save As". break; } case Error::RangeError: response.setHTTPStatusCode(httpRequestedRangeNotSatisfiable); response.setHTTPStatusText(httpRequestedRangeNotSatisfiableText); break; case Error::SecurityError: response.setHTTPStatusCode(httpNotAllowed); response.setHTTPStatusText(httpNotAllowedText); break; default: response.setHTTPStatusCode(httpInternalError); response.setHTTPStatusText(httpInternalErrorText); break; } m_client->didReceiveResponseNetworkSession(WTFMove(response), [this, protectedThis = WTFMove(protectedThis), errorCode](PolicyAction policyAction) { LOG(NetworkSession, "%p - NetworkDataTaskBlob::didReceiveResponse completionHandler (%u)", this, static_cast<unsigned>(policyAction)); if (m_state == State::Canceling || m_state == State::Completed) { clearStream(); return; } if (errorCode != Error::NoError) { didFinish(); return; } switch (policyAction) { case PolicyAction::PolicyUse: m_buffer.resize(bufferSize); read(); break; case PolicyAction::PolicyIgnore: break; case PolicyAction::PolicyDownload: download(); break; } }); }
void NetworkDataTaskBlob::invalidateAndCancel() { cancel(); clearStream(); }
void scannar::convertIntToStr() { clearStream(); convert<<lineNumber; lineNo=convert.str(); }