Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 1c17f6492b6ebb82fb8e3d685e930e7ded364055 Mon Sep 17 00:00:00 2001
- From: Thiago Macieira <thiago.macieira@nokia.com>
- Date: Tue, 16 Mar 2010 19:23:54 +0100
- Subject: [PATCH] Implement generic options for QAuthenticator.
- This will allow QAuthenticator to be a more generic mechanism for passing
- options parsed from the server and to allow client-side additional algorithms.
- ---
- src/network/kernel/qauthenticator.cpp | 138 ++++++++++++++++++++++++++++++++-
- src/network/kernel/qauthenticator.h | 15 ++++
- src/network/kernel/qauthenticator_p.h | 4 +-
- 3 files changed, 153 insertions(+), 4 deletions(-)
- diff --git a/src/network/kernel/qauthenticator.cpp b/src/network/kernel/qauthenticator.cpp
- index e4023c8..95be0d1 100644
- --- a/src/network/kernel/qauthenticator.cpp
- +++ b/src/network/kernel/qauthenticator.cpp
- @@ -83,6 +83,49 @@ static QByteArray qNtlmPhase3(QAuthenticatorPrivate *ctx, const QByteArray& phas
- Note that, in particular, NTLM version 2 is not supported.
- + \section1 Options
- +
- + In addition to the username and password required for authentication, a
- + QAuthenticator object can also contain additional options. The
- + incomingOptions() function can be used to query incoming options sent by
- + the server; the setOutgoingOption() and setOutgoingOptions() functions can
- + be used to set outgoing options, to be processed by the authenticator
- + calculation. The options accepted and provided depend on the authentication
- + type (see method()).
- +
- + The following tables list known incoming options as well as accepted
- + outgoing options. The list of incoming options is not exhaustive, since
- + servers may include additional information at any time. The list of
- + outgoing options is exhaustive, however, and no unknown options will be
- + treated or sent back to the server.
- +
- + \section2 Basic
- +
- + \table
- + \header \o Option \o Direction \o Description
- + \row \o \tt{realm} \o Incoming \o Contains the realm of the authentication, the same as realm()
- + \endtable
- +
- + The Basic authentication mechanism supports no outgoing options.
- +
- + \section2 NTLM version 1
- +
- + The NTLM authentication mechanism currently supports no incoming or outgoing options.
- +
- + \section2 Digest-MD5
- +
- + \table
- + \header \o Option \o Direction \o Description
- + \row \o \tt{realm} \o Incoming \o Contains the realm of the authentication, the same as realm()
- + \row \o \tt{stale} \o Incoming \o DIGEST-MD5 option \tt{stale}
- + \row \o \tt{qop} \o Incoming \o DIGEST-MD5 option \tt{qop}
- + \row \o \tt{nonce} \o Incoming \o DIGEST-MD5 option \tt{nonce}
- + \row \o \tt{opaque} \o Incoming \o DIGEST-MD5 option \tt{opaque}
- + \row \o \tt{algorithm} \o Incoming \o DIGEST-MD5 option \tt{algorithm}
- + \endtable
- +
- + The Digest-MD5 authentication mechanism supports no outgoing options.
- +
- \sa QSslSocket
- */
- @@ -138,7 +181,9 @@ bool QAuthenticator::operator==(const QAuthenticator &other) const
- return d->user == other.d->user
- && d->password == other.d->password
- && d->realm == other.d->realm
- - && d->method == other.d->method;
- + && d->method == other.d->method
- + && d->options == other.d->options
- + && d->outgoingOptions == other.d->outgoingOptions;
- }
- /*!
- @@ -198,16 +243,103 @@ void QAuthenticator::detach()
- }
- /*!
- + \since 4.7
- + Returns the authentication method used by the server to request
- + authentication or Unknown if the authentication method is not supported.
- +*/
- +QAuthenticator::AuthenticationMethod QAuthenticator::method() const
- +{
- + if (!d)
- + return Unknown;
- + switch (d->method) {
- + case QAuthenticatorPrivate::Basic:
- + return Basic;
- + case QAuthenticatorPrivate::Ntlm:
- + return NtlmV1;
- + case QAuthenticatorPrivate::DigestMd5:
- + return DigestMd5;
- + default:
- + return Unknown;
- + }
- +}
- +
- +/*!
- returns the realm requiring authentication.
- */
- QString QAuthenticator::realm() const
- {
- - return d ? d->realm : QString();
- + return incomingOption(QLatin1String("realm")).toString();
- +}
- +
- +/*!
- + \since 4.7
- + Returns the value related to option \a opt if it was set by the server.
- + See \l{QAuthenticator#Options} for more information on incoming options.
- + If option \a opt isn't found, an invalid QVariant will be returned.
- +
- + \sa options(), QAuthenticator#Options
- +*/
- +QVariant QAuthenticator::incomingOption(const QString &opt) const
- +{
- + return d ? d->options.value(opt) : QVariant();
- +}
- +
- +/*!
- + \since 4.7
- + Returns all incoming options set in this QAuthenticator object by parsing
- + the server reply. See \l{QAuthenticator#Options} for more information
- + on incoming options.
- +
- + \sa option(), QAuthenticator#Options
- +*/
- +QVariantHash QAuthenticator::incomingOptions() const
- +{
- + return d ? d->options : QVariantHash();
- +}
- +
- +/*!
- + \since 4.7
- + Returns all outgoing options set in this QAuthenticator object by calls
- + to setOption() or setOptions(). See \l{QAuthenticator#Options} for more
- + information on incoming options.
- +
- + \sa setOutgoingOption(), setOutgoingOptions() QAuthenticator#Options
- +*/
- +QVariantHash QAuthenticator::outgoingOptions() const
- +{
- + return d ? d->outgoingOptions : QVariantHash();
- +}
- +
- +/*!
- + \since 4.7
- +
- + Sets the outgoing option \a opt to value \a value.
- + See \l{QAuthenticator#Options} for more information on outgoing options.
- +
- + \sa outgoingOptions(), setOutgoingOptions(), QAuthenticator#Options
- +*/
- +void QAuthenticator::setOutgoingOption(const QString &opt, const QVariant &value)
- +{
- + detach();
- + d->outgoingOptions.insert(opt, value);
- +}
- +
- +/*!
- + \since 4.7
- + Sets the options in this authenticator to be the hash \a options.
- + See \l{QAuthenticator#Options} for more information on outgoing options.
- +
- + \sa options(), setOption(), QAuthenticator#Options
- +*/
- +void QAuthenticator::setOutgoingOptions(const QVariantHash &options)
- +{
- + detach();
- + d->outgoingOptions = options;
- }
- /*!
- - returns true if the authenticator is null.
- + Returns true if the authenticator is null.
- */
- bool QAuthenticator::isNull() const
- {
- diff --git a/src/network/kernel/qauthenticator.h b/src/network/kernel/qauthenticator.h
- index 13ce593..dd33f4b 100644
- --- a/src/network/kernel/qauthenticator.h
- +++ b/src/network/kernel/qauthenticator.h
- @@ -43,6 +43,7 @@
- #define QAUTHENTICATOR_H
- #include <QtCore/qstring.h>
- +#include <QtCore/qvariant.h>
- QT_BEGIN_HEADER
- @@ -56,6 +57,13 @@ class QUrl;
- class Q_NETWORK_EXPORT QAuthenticator
- {
- public:
- + enum AuthenticationMethod {
- + Unknown = 0,
- + Basic,
- + NtlmV1,
- + DigestMd5
- + };
- +
- QAuthenticator();
- ~QAuthenticator();
- @@ -71,8 +79,15 @@ public:
- QString password() const;
- void setPassword(const QString &password);
- + AuthenticationMethod method() const;
- QString realm() const;
- + QVariant incomingOption(const QString &opt) const;
- + QVariantHash incomingOptions() const;
- + QVariantHash outgoingOptions() const;
- + void setOutgoingOption(const QString &opt, const QVariant &value);
- + void setOutgoingOptions(const QVariantHash &options);
- +
- bool isNull() const;
- void detach();
- private:
- diff --git a/src/network/kernel/qauthenticator_p.h b/src/network/kernel/qauthenticator_p.h
- index e9ce9ac..36227cc 100644
- --- a/src/network/kernel/qauthenticator_p.h
- +++ b/src/network/kernel/qauthenticator_p.h
- @@ -57,6 +57,7 @@
- #include <qbytearray.h>
- #include <qstring.h>
- #include <qauthenticator.h>
- +#include <qvariant.h>
- QT_BEGIN_NAMESPACE
- @@ -71,7 +72,8 @@ public:
- QAtomicInt ref;
- QString user;
- QString password;
- - QHash<QByteArray, QByteArray> options;
- + QVariantHash options;
- + QVariantHash outgoingOptions;
- Method method;
- QString realm;
- QByteArray challenge;
- --
- 1.7.0.rc2.29.g363cd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement