// TODO: consider refactoring this to return error code void WdtSocket::readEncryptionSettingsOnce(int timeoutMs) { if (!encryptionParams_.isSet() || encryptionSettingsRead_) { return; } WDT_CHECK(!encryptionParams_.getSecret().empty()); int numRead = readInternal(buf_, 1, timeoutMs, true); if (numRead != 1) { LOG(ERROR) << "Failed to read encryption settings " << numRead << " " << port_; return; } if (buf_[0] != Protocol::ENCRYPTION_CMD) { LOG(ERROR) << "Expected to read ENCRYPTION_CMD(e), but got " << buf_[0]; readErrorCode_ = UNEXPECTED_CMD_ERROR; return; } int toRead = Protocol::kMaxEncryption - 1; // already read 1 byte for cmd numRead = readInternal(buf_, toRead, threadCtx_.getOptions().read_timeout_millis, true); if (numRead != toRead) { LOG(ERROR) << "Failed to read encryption settings " << numRead << " " << toRead << " " << port_; readErrorCode_ = SOCKET_READ_ERROR; return; } int64_t off = 0; EncryptionType encryptionType; std::string iv; if (!Protocol::decodeEncryptionSettings(buf_, off, Protocol::kMaxEncryption, encryptionType, iv)) { LOG(ERROR) << "Failed to decode encryption settings"; readErrorCode_ = PROTOCOL_ERROR; return; } if (encryptionType != encryptionParams_.getType()) { LOG(ERROR) << "Encryption type mismatch " << encryptionTypeToStr(encryptionType) << " " << encryptionTypeToStr(encryptionParams_.getType()); readErrorCode_ = PROTOCOL_ERROR; return; } if (!decryptor_.start(encryptionParams_, iv)) { readErrorCode_ = ENCRYPTION_ERROR; return; } LOG(INFO) << "Successfully read encryption settings " << port_ << " " << encryptionTypeToStr(encryptionType); encryptionSettingsRead_ = true; }
void NuCachedSource2::onRead(const sp<AMessage> &msg) { ALOGV("onRead"); int64_t offset; CHECK(msg->findInt64("offset", &offset)); void *data; CHECK(msg->findPointer("data", &data)); size_t size; CHECK(msg->findSize("size", &size)); ssize_t result = readInternal(offset, data, size); if (result == -EAGAIN) { msg->post(50000); return; } Mutex::Autolock autoLock(mLock); if (mDisconnecting) { mCondition.signal(); return; } CHECK(mAsyncResult == NULL); mAsyncResult = new AMessage; mAsyncResult->setInt32("result", result); mCondition.signal(); }
void FileReader::readAsDataURL(Blob* blob, ExceptionState& exceptionState) { ASSERT(blob); WTF_LOG(FileAPI, "FileReader: reading as data URL: %s %s\n", utf8BlobUUID(blob).data(), utf8FilePath(blob).data()); readInternal(blob, FileReaderLoader::ReadAsDataURL, exceptionState); }
void FileReader::readAsArrayBuffer(Blob* blob, ExceptionState& exceptionState) { ASSERT(blob); WTF_LOG(FileAPI, "FileReader: reading as array buffer: %s %s\n", utf8BlobUUID(blob).data(), utf8FilePath(blob).data()); readInternal(blob, FileReaderLoader::ReadAsArrayBuffer, exceptionState); }
int WdtSocket::readWithTimeout(char *buf, int nbyte, int timeoutMs, bool tryFull) { WDT_CHECK_GT(nbyte, 0); if (readErrorCode_ != OK && readErrorCode_ != WDT_TIMEOUT) { WLOG(ERROR) << "Socket read failed before, not trying to read again " << port_; return -1; } readErrorCode_ = OK; int numRead = 0; readEncryptionSettingsOnce(timeoutMs); if (supportUnencryptedPeer_ && readErrorCode_ == UNEXPECTED_CMD_ERROR) { WLOG(WARNING) << "Turning off encryption since the other side does not support " "encryption " << port_; readErrorCode_ = OK; buf[0] = buf_[0]; numRead = 1; // also turn off encryption encryptionParams_.erase(); } else if (readErrorCode_ != OK) { return -1; } if (nbyte == numRead) { return nbyte; } bool encrypt = encryptionParams_.isSet(); int ret = readInternal(buf + numRead, nbyte - numRead, timeoutMs, tryFull); if (ret >= 0) { numRead += ret; } else { return (numRead > 0 ? numRead : -1); } if (!encrypt) { return numRead; } int numDecrypted = 0; if (ctxSaveOffset_ >= 0) { if (ctxSaveOffset_ <= numRead) { if (!decryptor_.decrypt(buf, ctxSaveOffset_, buf)) { readErrorCode_ = ENCRYPTION_ERROR; return -1; } decryptor_.saveContext(); numDecrypted = ctxSaveOffset_; ctxSaveOffset_ = CTX_SAVED; } else { ctxSaveOffset_ -= numRead; } } // have to decrypt data if (!decryptor_.decrypt((buf + numDecrypted), (numRead - numDecrypted), (buf + numDecrypted))) { readErrorCode_ = ENCRYPTION_ERROR; return -1; } return numRead; }
void FileReader::readAsText(Blob* blob, const String& encoding, ExceptionState& exceptionState) { ASSERT(blob); WTF_LOG(FileAPI, "FileReader: reading as text: %s %s\n", utf8BlobUUID(blob).data(), utf8FilePath(blob).data()); m_encoding = encoding; readInternal(blob, FileReaderLoader::ReadAsText, exceptionState); }
void FileReader::readAsBinaryString(Blob* blob, ExceptionCode& ec) { if (!blob) return; LOG(FileAPI, "FileReader: reading as binary: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? toFile(blob)->path().utf8().data() : ""); readInternal(blob, FileReaderLoader::ReadAsBinaryString, ec); }
void FileReader::readAsArrayBuffer(Blob* blob, ExceptionCode& ec) { if (!blob) return; LOG(FileAPI, "FileReader: reading as array buffer: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? static_cast<File*>(blob)->path().utf8().data() : ""); readInternal(blob, FileReaderLoader::ReadAsArrayBuffer, ec); }
void FileReader::readAsDataURL(Blob* blob, ExceptionCode& ec) { if (!blob) return; LOG(FileAPI, "FileReader: reading as data URL: %s %s\n", blob->url().string().utf8().data(), is<File>(*blob) ? downcast<File>(*blob).path().utf8().data() : ""); readInternal(blob, FileReaderLoader::ReadAsDataURL, ec); }
void FileReader::readAsBinaryString(Blob* blob) { if (!blob) return; LOG(FileAPI, "FileReader: reading as binary: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? static_cast<File*>(blob)->path().utf8().data() : ""); readInternal(blob, FileReaderLoader::ReadAsBinaryString); }
void FileReader::readAsDataURL(Blob* blob, ExceptionCode& ec) { if (!blob) return; LOG(FileAPI, "FileReader: reading as data URL: %s %s\n", utf8BlobURL(blob).data(), utf8FilePath(blob).data()); readInternal(blob, FileReaderLoader::ReadAsDataURL, ec); }
int LSM9DS1_G::readY() { int data = 0; if (readInternal(AG_GYR_Y_H, AG_GYR_Y_L, &data)) { _y = data; } // Decode Gyroscope y-axis [mdps measurement unit] return (g_lsb_sentivity * _y); }
KoFilter::ConversionStatus XlsxXmlDocumentReader::read(MSOOXML::MsooXmlReaderContext* context) { m_context = dynamic_cast<XlsxXmlDocumentReaderContext*>(context); Q_ASSERT(m_context); const KoFilter::ConversionStatus result = readInternal(); m_context = 0; if (result == KoFilter::OK) return KoFilter::OK; return result; }
void FileReader::readAsText(Blob* blob, const String& encoding, ExceptionCode& ec) { if (!blob) return; LOG(FileAPI, "FileReader: reading as text: %s %s\n", utf8BlobURL(blob).data(), utf8FilePath(blob).data()); m_encoding = encoding; readInternal(blob, FileReaderLoader::ReadAsText, ec); }
int LSM9DS1_A::readX() { int data = 0; if (readInternal(AG_ACC_X_H, AG_ACC_X_L, &data)) { _x = data; } // Decode Accel x-axis [mdps measurement unit] return (a_lsb_sentivity * _x); }
int LSM9DS1_A::readY() { int data = 0; if (readInternal(AG_ACC_Y_H, AG_ACC_Y_L, &data)) { _y = data; } // Decode Accel y-axis [mdps measurement unit] return (a_lsb_sentivity * _y); }
void FileReader::readAsDataURL(Blob* blob) { if (!blob) return; LOG(FileAPI, "FileReader: reading as data URL: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? static_cast<File*>(blob)->path().utf8().data() : ""); m_fileType = blob->type(); readInternal(blob, ReadFileAsDataURL); }
int LSM9DS1_M::readY() { int data = 0; if (readInternal(M_Y_H, M_Y_L, &data)) { _y = data; } // Decode magnetic y-axis [mgauss measurement unit] return (m_lsb_sentivity * _y); }
int LSM9DS1_M::readX() { int data = 0; if (readInternal(M_X_H, M_X_L, &data)) { _x = data; } // Decode magnetic x-axis [mgauss measurement unit] return (m_lsb_sentivity * _x); }
int LSM9DS1_G::readZ() { int data = 0; if (readInternal(AG_GYR_Z_H, AG_GYR_Z_L, &data)) { _z = data; } // Decode Gyroscope z-axis [mdps measurement unit] return (g_lsb_sentivity * _z); }
int LSM9DS1_G::readX() { int data = 0; if (readInternal(AG_GYR_X_H, AG_GYR_X_L, &data)) { _x = data; } // Decode Gyroscope x-axis [mdps measurement unit] return (g_lsb_sentivity * _x); }
int LSM9DS1_A::readZ() { int data = 0; if (readInternal(AG_ACC_Z_H, AG_ACC_Z_L, &data)) { _z = data; } // Decode Accel z-axis [mdps measurement unit] return (a_lsb_sentivity * _z); }
int LSM9DS1_M::readZ() { int data = 0; if (readInternal(M_Z_H, M_Z_L, &data)) { _z = data; } // Decode magnetic z-axis [mgauss measurement unit] return (m_lsb_sentivity * _z); }
void FileReader::readAsText(Blob* blob, const String& encoding, ExceptionCode& ec) { if (!blob) return; LOG(FileAPI, "FileReader: reading as text: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? static_cast<File*>(blob)->path().utf8().data() : ""); m_encoding = encoding; readInternal(blob, FileReaderLoader::ReadAsText, ec); }
void FileReader::readAsDataURL(Blob* blob, ExceptionState& exceptionState) { if (!blob) { exceptionState.throwTypeError("The argument is not a Blob."); return; } WTF_LOG(FileAPI, "FileReader: reading as data URL: %s %s\n", utf8BlobUUID(blob).data(), utf8FilePath(blob).data()); readInternal(blob, FileReaderLoader::ReadAsDataURL, exceptionState); }
void FileReader::readAsText(Blob* blob, const String& encoding) { if (!blob) return; LOG(FileAPI, "FileReader: reading as text: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? static_cast<File*>(blob)->path().utf8().data() : ""); if (!encoding.isEmpty()) m_encoding = TextEncoding(encoding); readInternal(blob, ReadFileAsText); }
void FileReader::readAsText(Blob* blob, const String& encoding, ExceptionState& exceptionState) { if (!blob) { exceptionState.throwTypeError("The argument is not a Blob."); return; } WTF_LOG(FileAPI, "FileReader: reading as text: %s %s\n", utf8BlobUUID(blob).data(), utf8FilePath(blob).data()); m_encoding = encoding; readInternal(blob, FileReaderLoader::ReadAsText, exceptionState); }
KoFilter::ConversionStatus XlsxXmlCommentsReader::read(MSOOXML::MsooXmlReaderContext* context) { m_context = dynamic_cast<XlsxXmlCommentsReaderContext*>(context); Q_ASSERT(m_context); m_colorIndices = m_context->colorIndices; m_themes = m_context->themes; const KoFilter::ConversionStatus result = readInternal(); m_context = 0; if (result == KoFilter::OK) return KoFilter::OK; return result; }
bool X86AtaDevice::read(uint64_t address, uint16_t *buf, size_t sectors) { if (sectors == 0) return false; if (sectors > 10) { size_t const bufIncr = sectorSize() / sizeof(uint16_t); bool success = true; for (size_t offset = 0; offset < sectors; offset += 10) { size_t const bufOffset = bufIncr * offset; size_t sectorsToRead = sectors - offset < 10 ? sectors - offset : 10; success = readInternal(address + offset, buf + bufOffset, sectorsToRead); if (!success) { break; } } return success; } else { return readInternal(address, buf, sectors); } }
KoFilter::ConversionStatus XlsxXmlCommentsReader::read(MSOOXML::MsooXmlReaderContext* context) { m_context = dynamic_cast<XlsxXmlCommentsReaderContext*>(context); Q_ASSERT(m_context); m_colorIndices = m_context->colorIndices; m_themes = m_context->themes; const KoFilter::ConversionStatus result = readInternal(); m_context = 0; if (result != KoFilter::OK) { kWarning() << "Failure reading the comments"; } // We're not going to fail reading the whole file because the comments cannot be read return KoFilter::OK; }