Ejemplo n.º 1
0
void QAuthenticatorPrivate::parseHttpResponse(const QHttpResponseHeader &header, bool isProxy)
{
    QList<QPair<QString, QString> > values = header.values();
    const char *search = isProxy ? "proxy-authenticate" : "www-authenticate";

    method = None;
    /*
      Fun from the HTTP 1.1 specs, that we currently ignore:

      User agents are advised to take special care in parsing the WWW-
      Authenticate field value as it might contain more than one challenge,
      or if more than one WWW-Authenticate header field is provided, the
      contents of a challenge itself can contain a comma-separated list of
      authentication parameters.
    */

    QString headerVal;
    for (int i = 0; i < values.size(); ++i) {
        const QPair<QString, QString> &current = values.at(i);
        if (current.first.toLower() != QLatin1String(search))
            continue;
        QString str = current.second;
        if (method < Basic && str.startsWith(QLatin1String("Basic"), Qt::CaseInsensitive)) {
            method = Basic; headerVal = str.mid(6);
        } else if (method < Ntlm && str.startsWith(QLatin1String("NTLM"), Qt::CaseInsensitive)) {
            method = Ntlm;
            headerVal = str.mid(5);
        } else if (method < DigestMd5 && str.startsWith(QLatin1String("Digest"), Qt::CaseInsensitive)) {
            method = DigestMd5;
            headerVal = str.mid(7);
        }
    }

    challenge = headerVal.trimmed().toLatin1();
    QHash<QByteArray, QByteArray> options = parseDigestAuthenticationChallenge(challenge);

    switch(method) {
    case Basic:
        realm = QString::fromLatin1(options.value("realm"));
        if (user.isEmpty())
            phase = Done;
        break;
    case Ntlm:
        // #### extract from header
        realm = QString();
        break;
    case DigestMd5: {
        realm = QString::fromLatin1(options.value("realm"));
        if (options.value("stale").toLower() == "true")
            phase = Start;
        if (user.isEmpty())
            phase = Done;
        break;
    }
    default:
        realm = QString();
        challenge = QByteArray();
        phase = Invalid;
    }
}
Ejemplo n.º 2
0
void QAuthenticatorPrivate::parseHttpResponse(const QHttpResponseHeader &header, bool isProxy)
{
    const QList<QPair<QString, QString> > values = header.values();
    QList<QPair<QByteArray, QByteArray> > rawValues;

    QList<QPair<QString, QString> >::const_iterator it, end;
    for (it = values.constBegin(), end = values.constEnd(); it != end; ++it)
        rawValues.append(qMakePair(it->first.toLatin1(), it->second.toUtf8()));

    // continue in byte array form
    parseHttpResponse(rawValues, isProxy);
}
Ejemplo n.º 3
0
void DownloadHandler::readResponseHeader( const QHttpResponseHeader &responseHeader )
{
   const QString contentType("Content-Type");
#if USE_TRACE
TRACESTART(DownloadHandler::readResponseHeader)
#endif
   if( (responseHeader.statusCode() >= 300) && (responseHeader.statusCode() < 400) )
   {
      TheMagic *magic = new TheMagic( *mpTheMagic );
      magic->mURL = responseHeader.value("location");
      mpMagicQueue->addMagic( magic );
      mpTheMagic->fail();
   }
   else if( responseHeader.statusCode() != 200 )
   {
      errorMessage( mpTheMagic->mURL + ":" + QString::number( responseHeader.statusCode() ) +
                    " " + responseHeader.reasonPhrase() );
      mpTheMagic->fail();
   }

   if( responseHeader.hasContentType() )
   {
      mpTheMagic->setContentType( responseHeader.contentType() );
   }

   const QString setCookie("Set-Cookie");
   QList<QPair<QString, QString> > values( responseHeader.values() );
   for( int i = 0; i < values.size(); i++ )
   {
      if( !QString::compare(values.at(i).first, setCookie, Qt::CaseInsensitive) )
      {
#if USE_TRACE
TRACEMSG << values.at(i).second;
#endif
         mCookieJar.store( values.at(i).second );
      }
   }
}