/** * override for Manager base find an object ... ideally in the cache, but it will search thoroughly if not * initially found */ RoomRef RoomManager::Get(const RoomID roomID) const { RoomRef theRoom = GetCached(roomID); if (theRoom) return theRoom; theRoom = occupiedRooms.Get(roomID); if (theRoom) return theRoom; theRoom = observedRooms.Get(roomID); if (theRoom) return theRoom; theRoom = watchedRooms.Get(roomID); if (theRoom) return theRoom; return theRoom; }
TagLib::ByteVector CloudStream::readBlock(ulong length) { const uint start = cursor_; const uint end = qMin(cursor_ + length - 1, length_ - 1); if (end < start) { return TagLib::ByteVector(); } if (CheckCache(start, end)) { TagLib::ByteVector cached = GetCached(start, end); cursor_ += cached.size(); return cached; } QNetworkRequest request = QNetworkRequest(url_); if (!auth_.isEmpty()) { request.setRawHeader("Authorization", auth_.toUtf8()); } request.setRawHeader("Range", QString("bytes=%1-%2").arg(start).arg(end).toUtf8()); request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork); // The Ubuntu One server applies the byte range to the gzipped data, rather // than the raw data so we must disable compression. if (url_.host() == "files.one.ubuntu.com") { request.setRawHeader("Accept-Encoding", "identity"); } QNetworkReply* reply = network_->get(request); connect(reply, SIGNAL(sslErrors(QList<QSslError>)), SLOT(SSLErrors(QList<QSslError>))); ++num_requests_; QEventLoop loop; QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); reply->deleteLater(); int code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (code >= 400) { qLog(Debug) << "Error retrieving url to tag:" << url_; return TagLib::ByteVector(); } QByteArray data = reply->readAll(); TagLib::ByteVector bytes(data.data(), data.size()); cursor_ += data.size(); FillCache(start, bytes); return bytes; }
TagLib::ByteVector CloudStream::readBlock(ulong length) { const uint start = cursor_; const uint end = qMin(cursor_ + length - 1, length_ - 1); if (end < start) { return TagLib::ByteVector(); } if (CheckCache(start, end)) { TagLib::ByteVector cached = GetCached(start, end); cursor_ += cached.size(); return cached; } QNetworkRequest request = QNetworkRequest(url_); foreach (const QString& key, headers_) { request.setRawHeader(key.toLatin1(), headers_[key].toUtf8()); }
TagLib::ByteVector CloudStream::readBlock( ulong length ) { const uint start = m_cursor; const uint end = qMin( m_cursor + length - 1, m_length - 1 ); //tDebug( LOGINFO ) << "#### CloudStream : parsing from " << m_url.toString(); //tDebug( LOGINFO ) << "#### CloudStream : parsing from (encoded) " << m_url.toEncoded().constData(); if ( end < start ) { return TagLib::ByteVector(); } if ( CheckCache( start, end ) ) { TagLib::ByteVector cached = GetCached( start, end ); m_cursor += cached.size(); return cached; } if ( m_num_requests_in_error > MAX_ALLOW_ERROR_QUERY ) { //precache(); return TagLib::ByteVector(); } if ( m_refreshUrlEachTime ) { if( !refreshStreamUrl() ) { tDebug( LOGINFO ) << "#### CloudStream : cannot refresh streamUrl for " << m_filename; } } QNetworkRequest request = QNetworkRequest( m_url ); //setings of specials OAuth (1 or 2) headers foreach ( const QString& headerName, m_headers.keys() ) { request.setRawHeader( headerName.toLocal8Bit(), m_headers[headerName].toString().toLocal8Bit() ); } request.setRawHeader( "Range", QString( "bytes=%1-%2" ).arg( start ).arg( end ).toUtf8() ); request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork ); // The Ubuntu One server applies the byte range to the gzipped data, rather // than the raw data so we must disable compression. if ( m_url.host() == "files.one.ubuntu.com" ) { request.setRawHeader( "Accept-Encoding", "identity" ); } tDebug() << "######## CloudStream : HTTP request : "; tDebug() << "#### CloudStream : url : " << request.url(); m_currentBlocklength = length; m_currentStart = start; m_reply = m_network->get( request ); connect( m_reply, SIGNAL( sslErrors( QList<QSslError> ) ), SLOT( SSLErrors( QList<QSslError> ) ) ); connect( m_reply, SIGNAL( finished() ), this, SLOT( onRequestFinished() ) ); ++m_num_requests; return TagLib::ByteVector(); }