Advertisement
Guest User

Untitled

a guest
May 19th, 2017
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.69 KB | None | 0 0
  1. From 1c17f6492b6ebb82fb8e3d685e930e7ded364055 Mon Sep 17 00:00:00 2001
  2. From: Thiago Macieira <thiago.macieira@nokia.com>
  3. Date: Tue, 16 Mar 2010 19:23:54 +0100
  4. Subject: [PATCH] Implement generic options for QAuthenticator.
  5.  
  6. This will allow QAuthenticator to be a more generic mechanism for passing
  7. options parsed from the server and to allow client-side additional algorithms.
  8. ---
  9. src/network/kernel/qauthenticator.cpp |  138 ++++++++++++++++++++++++++++++++-
  10.  src/network/kernel/qauthenticator.h   |   15 ++++
  11.  src/network/kernel/qauthenticator_p.h |    4 +-
  12.  3 files changed, 153 insertions(+), 4 deletions(-)
  13.  
  14. diff --git a/src/network/kernel/qauthenticator.cpp b/src/network/kernel/qauthenticator.cpp
  15. index e4023c8..95be0d1 100644
  16. --- a/src/network/kernel/qauthenticator.cpp
  17. +++ b/src/network/kernel/qauthenticator.cpp
  18. @@ -83,6 +83,49 @@ static QByteArray qNtlmPhase3(QAuthenticatorPrivate *ctx, const QByteArray& phas
  19.  
  20.    Note that, in particular, NTLM version 2 is not supported.
  21.  
  22. +  \section1 Options
  23. +
  24. +  In addition to the username and password required for authentication, a
  25. +  QAuthenticator object can also contain additional options. The
  26. +  incomingOptions() function can be used to query incoming options sent by
  27. +  the server; the setOutgoingOption() and setOutgoingOptions() functions can
  28. +  be used to set outgoing options, to be processed by the authenticator
  29. +  calculation. The options accepted and provided depend on the authentication
  30. +  type (see method()).
  31. +
  32. +  The following tables list known incoming options as well as accepted
  33. +  outgoing options. The list of incoming options is not exhaustive, since
  34. +  servers may include additional information at any time. The list of
  35. +  outgoing options is exhaustive, however, and no unknown options will be
  36. +  treated or sent back to the server.
  37. +
  38. +  \section2 Basic
  39. +
  40. +  \table
  41. +    \header \o Option \o Direction \o Description
  42. +    \row \o \tt{realm} \o Incoming \o Contains the realm of the authentication, the same as realm()
  43. +  \endtable
  44. +
  45. +  The Basic authentication mechanism supports no outgoing options.
  46. +
  47. +  \section2 NTLM version 1
  48. +
  49. +  The NTLM authentication mechanism currently supports no incoming or outgoing options.
  50. +
  51. +  \section2 Digest-MD5
  52. +
  53. +  \table
  54. +    \header \o Option \o Direction \o Description
  55. +    \row \o \tt{realm} \o Incoming \o Contains the realm of the authentication, the same as realm()
  56. +    \row \o \tt{stale} \o Incoming \o DIGEST-MD5 option \tt{stale}
  57. +    \row \o \tt{qop} \o Incoming \o DIGEST-MD5 option \tt{qop}
  58. +    \row \o \tt{nonce} \o Incoming \o DIGEST-MD5 option \tt{nonce}
  59. +    \row \o \tt{opaque} \o Incoming \o DIGEST-MD5 option \tt{opaque}
  60. +    \row \o \tt{algorithm} \o Incoming \o DIGEST-MD5 option \tt{algorithm}
  61. +  \endtable
  62. +
  63. +  The Digest-MD5 authentication mechanism supports no outgoing options.
  64. +
  65.    \sa QSslSocket
  66.  */
  67.  
  68. @@ -138,7 +181,9 @@ bool QAuthenticator::operator==(const QAuthenticator &other) const
  69.      return d->user == other.d->user
  70.          && d->password == other.d->password
  71.          && d->realm == other.d->realm
  72. -        && d->method == other.d->method;
  73. +        && d->method == other.d->method
  74. +        && d->options == other.d->options
  75. +        && d->outgoingOptions == other.d->outgoingOptions;
  76.  }
  77.  
  78.  /*!
  79. @@ -198,16 +243,103 @@ void QAuthenticator::detach()
  80.  }
  81.  
  82.  /*!
  83. +    \since 4.7
  84. +    Returns the authentication method used by the server to request
  85. +    authentication or Unknown if the authentication method is not supported.
  86. +*/
  87. +QAuthenticator::AuthenticationMethod QAuthenticator::method() const
  88. +{
  89. +    if (!d)
  90. +        return Unknown;
  91. +    switch (d->method) {
  92. +    case QAuthenticatorPrivate::Basic:
  93. +        return Basic;
  94. +    case QAuthenticatorPrivate::Ntlm:
  95. +        return NtlmV1;
  96. +    case QAuthenticatorPrivate::DigestMd5:
  97. +        return DigestMd5;
  98. +    default:
  99. +        return Unknown;
  100. +    }
  101. +}
  102. +
  103. +/*!
  104.    returns the realm requiring authentication.
  105.  */
  106.  QString QAuthenticator::realm() const
  107.  {
  108. -    return d ? d->realm : QString();
  109. +    return incomingOption(QLatin1String("realm")).toString();
  110. +}
  111. +
  112. +/*!
  113. +    \since 4.7
  114. +    Returns the value related to option \a opt if it was set by the server.
  115. +    See \l{QAuthenticator#Options} for more information on incoming options.
  116. +    If option \a opt isn't found, an invalid QVariant will be returned.
  117. +
  118. +    \sa options(), QAuthenticator#Options
  119. +*/
  120. +QVariant QAuthenticator::incomingOption(const QString &opt) const
  121. +{
  122. +    return d ? d->options.value(opt) : QVariant();
  123. +}
  124. +
  125. +/*!
  126. +    \since 4.7
  127. +    Returns all incoming options set in this QAuthenticator object by parsing
  128. +    the server reply. See \l{QAuthenticator#Options} for more information
  129. +    on incoming options.
  130. +
  131. +    \sa option(), QAuthenticator#Options
  132. +*/
  133. +QVariantHash QAuthenticator::incomingOptions() const
  134. +{
  135. +    return d ? d->options : QVariantHash();
  136. +}
  137. +
  138. +/*!
  139. +    \since 4.7
  140. +    Returns all outgoing options set in this QAuthenticator object by calls
  141. +    to setOption() or setOptions(). See \l{QAuthenticator#Options} for more
  142. +    information on incoming options.
  143. +
  144. +    \sa setOutgoingOption(), setOutgoingOptions() QAuthenticator#Options
  145. +*/
  146. +QVariantHash QAuthenticator::outgoingOptions() const
  147. +{
  148. +    return d ? d->outgoingOptions : QVariantHash();
  149. +}
  150. +
  151. +/*!
  152. +    \since 4.7
  153. +
  154. +    Sets the outgoing option \a opt to value \a value.
  155. +    See \l{QAuthenticator#Options} for more information on outgoing options.
  156. +
  157. +    \sa outgoingOptions(), setOutgoingOptions(), QAuthenticator#Options
  158. +*/
  159. +void QAuthenticator::setOutgoingOption(const QString &opt, const QVariant &value)
  160. +{
  161. +    detach();
  162. +    d->outgoingOptions.insert(opt, value);
  163. +}
  164. +
  165. +/*!
  166. +    \since 4.7
  167. +    Sets the options in this authenticator to be the hash \a options.
  168. +    See \l{QAuthenticator#Options} for more information on outgoing options.
  169. +
  170. +    \sa options(), setOption(), QAuthenticator#Options
  171. +*/
  172. +void QAuthenticator::setOutgoingOptions(const QVariantHash &options)
  173. +{
  174. +    detach();
  175. +    d->outgoingOptions = options;
  176.  }
  177.  
  178.  
  179.  /*!
  180. -  returns true if the authenticator is null.
  181. +    Returns true if the authenticator is null.
  182.  */
  183.  bool QAuthenticator::isNull() const
  184.  {
  185. diff --git a/src/network/kernel/qauthenticator.h b/src/network/kernel/qauthenticator.h
  186. index 13ce593..dd33f4b 100644
  187. --- a/src/network/kernel/qauthenticator.h
  188. +++ b/src/network/kernel/qauthenticator.h
  189. @@ -43,6 +43,7 @@
  190.  #define QAUTHENTICATOR_H
  191.  
  192.  #include <QtCore/qstring.h>
  193. +#include <QtCore/qvariant.h>
  194.  
  195.  QT_BEGIN_HEADER
  196.  
  197. @@ -56,6 +57,13 @@ class QUrl;
  198.  class Q_NETWORK_EXPORT QAuthenticator
  199.  {
  200.  public:
  201. +    enum AuthenticationMethod {
  202. +        Unknown = 0,
  203. +        Basic,
  204. +        NtlmV1,
  205. +        DigestMd5
  206. +    };
  207. +
  208.      QAuthenticator();
  209.      ~QAuthenticator();
  210.  
  211. @@ -71,8 +79,15 @@ public:
  212.      QString password() const;
  213.      void setPassword(const QString &password);
  214.  
  215. +    AuthenticationMethod method() const;
  216.      QString realm() const;
  217.  
  218. +    QVariant incomingOption(const QString &opt) const;
  219. +    QVariantHash incomingOptions() const;
  220. +    QVariantHash outgoingOptions() const;
  221. +    void setOutgoingOption(const QString &opt, const QVariant &value);
  222. +    void setOutgoingOptions(const QVariantHash &options);
  223. +
  224.      bool isNull() const;
  225.      void detach();
  226.  private:
  227. diff --git a/src/network/kernel/qauthenticator_p.h b/src/network/kernel/qauthenticator_p.h
  228. index e9ce9ac..36227cc 100644
  229. --- a/src/network/kernel/qauthenticator_p.h
  230. +++ b/src/network/kernel/qauthenticator_p.h
  231. @@ -57,6 +57,7 @@
  232.  #include <qbytearray.h>
  233.  #include <qstring.h>
  234.  #include <qauthenticator.h>
  235. +#include <qvariant.h>
  236.  
  237.  QT_BEGIN_NAMESPACE
  238.  
  239. @@ -71,7 +72,8 @@ public:
  240.      QAtomicInt ref;
  241.      QString user;
  242.      QString password;
  243. -    QHash<QByteArray, QByteArray> options;
  244. +    QVariantHash options;
  245. +    QVariantHash outgoingOptions;
  246.      Method method;
  247.      QString realm;
  248.      QByteArray challenge;
  249. --
  250. 1.7.0.rc2.29.g363cd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement