Ejemplo n.º 1
0
SSL_CTX *initCTX() {
	SSL_CTX *m_ctx;
	ERR((m_ctx = SSL_CTX_new(SSLv23_method())) == NULL,
		COMP("SSL_CTX_new():%1", SSLErrors()))

	SSL_CTX_set_options(m_ctx, SSL_OP_ALL|SSL_OP_NO_SSLv2);
	ERR(SSL_CTX_set_default_verify_paths(m_ctx) == 0,
		COMP("SSL_CTX_set_default_verify_paths():%1", SSLErrors()))
	return m_ctx;
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
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();
}