Renamed Params to Parameters

This commit is contained in:
sta 2014-06-26 15:38:06 +09:00
parent 2b42af79c0
commit df4b23807e
4 changed files with 72 additions and 73 deletions

View File

@ -36,26 +36,26 @@ namespace WebSocketSharp
{ {
#region Private Fields #region Private Fields
private NameValueCollection _params; private NameValueCollection _parameters;
private string _scheme; private string _scheme;
#endregion #endregion
#region Internal Constructors #region Internal Constructors
internal AuthenticationChallenge (string authScheme, string authParams) internal AuthenticationChallenge (string scheme, string parameters)
{ {
_scheme = authScheme; _scheme = scheme;
_params = authParams.ParseAuthParams (); _parameters = parameters.ParseAuthParameters ();
} }
#endregion #endregion
#region Internal Properties #region Internal Properties
internal NameValueCollection Params { internal NameValueCollection Parameters {
get { get {
return _params; return _parameters;
} }
} }
@ -65,37 +65,37 @@ namespace WebSocketSharp
public string Algorithm { public string Algorithm {
get { get {
return _params ["algorithm"]; return _parameters ["algorithm"];
} }
} }
public string Domain { public string Domain {
get { get {
return _params ["domain"]; return _parameters ["domain"];
} }
} }
public string Nonce { public string Nonce {
get { get {
return _params ["nonce"]; return _parameters ["nonce"];
} }
} }
public string Opaque { public string Opaque {
get { get {
return _params ["opaque"]; return _parameters ["opaque"];
} }
} }
public string Qop { public string Qop {
get { get {
return _params ["qop"]; return _parameters ["qop"];
} }
} }
public string Realm { public string Realm {
get { get {
return _params ["realm"]; return _parameters ["realm"];
} }
} }
@ -107,7 +107,7 @@ namespace WebSocketSharp
public string Stale { public string Stale {
get { get {
return _params ["stale"]; return _parameters ["stale"];
} }
} }
@ -118,8 +118,10 @@ namespace WebSocketSharp
public static AuthenticationChallenge Parse (string value) public static AuthenticationChallenge Parse (string value)
{ {
var challenge = value.Split (new [] { ' ' }, 2); var challenge = value.Split (new [] { ' ' }, 2);
var scheme = challenge [0].ToLower (); if (challenge.Length != 2)
return null;
var scheme = challenge [0].ToLower ();
return scheme == "basic" || scheme == "digest" return scheme == "basic" || scheme == "digest"
? new AuthenticationChallenge (scheme, challenge [1]) ? new AuthenticationChallenge (scheme, challenge [1])
: null; : null;

View File

@ -39,17 +39,17 @@ namespace WebSocketSharp
#region Private Fields #region Private Fields
private uint _nonceCount; private uint _nonceCount;
private NameValueCollection _params; private NameValueCollection _parameters;
private string _scheme; private string _scheme;
#endregion #endregion
#region Private Constructors #region Private Constructors
private AuthenticationResponse (string authScheme, NameValueCollection authParams) private AuthenticationResponse (string scheme, NameValueCollection parameters)
{ {
_scheme = authScheme; _scheme = scheme;
_params = authParams; _parameters = parameters;
} }
#endregion #endregion
@ -62,24 +62,19 @@ namespace WebSocketSharp
} }
internal AuthenticationResponse ( internal AuthenticationResponse (
AuthenticationChallenge challenge, AuthenticationChallenge challenge, NetworkCredential credentials, uint nonceCount)
NetworkCredential credentials, : this (challenge.Scheme, challenge.Parameters, credentials, nonceCount)
uint nonceCount)
: this (challenge.Scheme, challenge.Params, credentials, nonceCount)
{ {
} }
internal AuthenticationResponse ( internal AuthenticationResponse (
string authScheme, string scheme, NameValueCollection parameters, NetworkCredential credentials, uint nonceCount)
NameValueCollection authParams,
NetworkCredential credentials,
uint nonceCount)
{ {
_scheme = authScheme.ToLower (); _scheme = scheme.ToLower ();
_params = authParams; _parameters = parameters;
_params ["username"] = credentials.UserName; _parameters ["username"] = credentials.UserName;
_params ["password"] = credentials.Password; _parameters ["password"] = credentials.Password;
_params ["uri"] = credentials.Domain; _parameters ["uri"] = credentials.Domain;
_nonceCount = nonceCount; _nonceCount = nonceCount;
if (_scheme == "digest") if (_scheme == "digest")
initAsDigest (); initAsDigest ();
@ -97,9 +92,9 @@ namespace WebSocketSharp
} }
} }
internal NameValueCollection Params { internal NameValueCollection Parameters {
get { get {
return _params; return _parameters;
} }
} }
@ -109,55 +104,55 @@ namespace WebSocketSharp
public string Algorithm { public string Algorithm {
get { get {
return _params ["algorithm"]; return _parameters ["algorithm"];
} }
} }
public string Cnonce { public string Cnonce {
get { get {
return _params ["cnonce"]; return _parameters ["cnonce"];
} }
} }
public string Nc { public string Nc {
get { get {
return _params ["nc"]; return _parameters ["nc"];
} }
} }
public string Nonce { public string Nonce {
get { get {
return _params ["nonce"]; return _parameters ["nonce"];
} }
} }
public string Opaque { public string Opaque {
get { get {
return _params ["opaque"]; return _parameters ["opaque"];
} }
} }
public string Password { public string Password {
get { get {
return _params ["password"]; return _parameters ["password"];
} }
} }
public string Qop { public string Qop {
get { get {
return _params ["qop"]; return _parameters ["qop"];
} }
} }
public string Realm { public string Realm {
get { get {
return _params ["realm"]; return _parameters ["realm"];
} }
} }
public string Response { public string Response {
get { get {
return _params ["response"]; return _parameters ["response"];
} }
} }
@ -169,13 +164,13 @@ namespace WebSocketSharp
public string Uri { public string Uri {
get { get {
return _params ["uri"]; return _parameters ["uri"];
} }
} }
public string UserName { public string UserName {
get { get {
return _params ["username"]; return _parameters ["username"];
} }
} }
@ -185,20 +180,20 @@ namespace WebSocketSharp
private void initAsDigest () private void initAsDigest ()
{ {
var qops = _params ["qop"]; var qops = _parameters ["qop"];
if (qops != null) { if (qops != null) {
if (qops.Split (',').Contains (qop => qop.Trim ().ToLower () == "auth")) { if (qops.Split (',').Contains (qop => qop.Trim ().ToLower () == "auth")) {
_params ["qop"] = "auth"; _parameters ["qop"] = "auth";
_params ["nc"] = String.Format ("{0:x8}", ++_nonceCount); _parameters ["nc"] = String.Format ("{0:x8}", ++_nonceCount);
_params ["cnonce"] = HttpUtility.CreateNonceValue (); _parameters ["cnonce"] = HttpUtility.CreateNonceValue ();
} }
else { else {
_params ["qop"] = null; _parameters ["qop"] = null;
} }
} }
_params ["method"] = "GET"; _parameters ["method"] = "GET";
_params ["response"] = HttpUtility.CreateRequestDigest (_params); _parameters ["response"] = HttpUtility.CreateRequestDigest (_parameters);
} }
#endregion #endregion
@ -216,7 +211,7 @@ namespace WebSocketSharp
return scheme == "basic" return scheme == "basic"
? new AuthenticationResponse (scheme, credentials [1].ParseBasicCredentials ()) ? new AuthenticationResponse (scheme, credentials [1].ParseBasicCredentials ())
: scheme == "digest" : scheme == "digest"
? new AuthenticationResponse (scheme, credentials [1].ParseAuthParams ()) ? new AuthenticationResponse (scheme, credentials [1].ParseAuthParameters ())
: null; : null;
} }
catch { catch {
@ -228,18 +223,20 @@ namespace WebSocketSharp
public IIdentity ToIdentity () public IIdentity ToIdentity ()
{ {
return _scheme == "basic" return _scheme == "basic"
? new HttpBasicIdentity (_params ["username"], _params ["password"]) as IIdentity ? new HttpBasicIdentity (
_parameters ["username"], _parameters ["password"]) as IIdentity
: _scheme == "digest" : _scheme == "digest"
? new HttpDigestIdentity (_params) ? new HttpDigestIdentity (_parameters)
: null; : null;
} }
public override string ToString () public override string ToString ()
{ {
return _scheme == "basic" return _scheme == "basic"
? HttpUtility.CreateBasicAuthCredentials (_params ["username"], _params ["password"]) ? HttpUtility.CreateBasicAuthCredentials (
_parameters ["username"], _parameters ["password"])
: _scheme == "digest" : _scheme == "digest"
? HttpUtility.CreateDigestAuthCredentials (_params) ? HttpUtility.CreateDigestAuthCredentials (_parameters)
: String.Empty; : String.Empty;
} }

View File

@ -571,7 +571,7 @@ namespace WebSocketSharp
return true; return true;
} }
internal static NameValueCollection ParseAuthParams (this string value) internal static NameValueCollection ParseAuthParameters (this string value)
{ {
var res = new NameValueCollection (); var res = new NameValueCollection ();
foreach (var param in value.SplitHeaderValue (',')) { foreach (var param in value.SplitHeaderValue (',')) {
@ -579,7 +579,7 @@ namespace WebSocketSharp
var name = i > 0 ? param.Substring (0, i).Trim () : null; var name = i > 0 ? param.Substring (0, i).Trim () : null;
var val = i < 0 var val = i < 0
? param.Trim ().Trim ('"') ? param.Trim ().Trim ('"')
: param.Length > i + 1 : i < param.Length - 1
? param.Substring (i + 1).Trim ().Trim ('"') ? param.Substring (i + 1).Trim ().Trim ('"')
: String.Empty; : String.Empty;

View File

@ -39,16 +39,16 @@ namespace WebSocketSharp.Net
{ {
#region Private Fields #region Private Fields
private NameValueCollection _params; private NameValueCollection _parameters;
#endregion #endregion
#region Internal Constructors #region Internal Constructors
internal HttpDigestIdentity (NameValueCollection authParams) internal HttpDigestIdentity (NameValueCollection parameters)
: base (authParams ["username"], "Digest") : base (parameters ["username"], "Digest")
{ {
_params = authParams; _parameters = parameters;
} }
#endregion #endregion
@ -63,7 +63,7 @@ namespace WebSocketSharp.Net
/// </value> /// </value>
public string Algorithm { public string Algorithm {
get { get {
return _params ["algorithm"]; return _parameters ["algorithm"];
} }
} }
@ -75,7 +75,7 @@ namespace WebSocketSharp.Net
/// </value> /// </value>
public string Cnonce { public string Cnonce {
get { get {
return _params ["cnonce"]; return _parameters ["cnonce"];
} }
} }
@ -87,7 +87,7 @@ namespace WebSocketSharp.Net
/// </value> /// </value>
public string Nc { public string Nc {
get { get {
return _params ["nc"]; return _parameters ["nc"];
} }
} }
@ -99,7 +99,7 @@ namespace WebSocketSharp.Net
/// </value> /// </value>
public string Nonce { public string Nonce {
get { get {
return _params ["nonce"]; return _parameters ["nonce"];
} }
} }
@ -111,7 +111,7 @@ namespace WebSocketSharp.Net
/// </value> /// </value>
public string Opaque { public string Opaque {
get { get {
return _params ["opaque"]; return _parameters ["opaque"];
} }
} }
@ -123,7 +123,7 @@ namespace WebSocketSharp.Net
/// </value> /// </value>
public string Qop { public string Qop {
get { get {
return _params ["qop"]; return _parameters ["qop"];
} }
} }
@ -135,7 +135,7 @@ namespace WebSocketSharp.Net
/// </value> /// </value>
public string Realm { public string Realm {
get { get {
return _params ["realm"]; return _parameters ["realm"];
} }
} }
@ -147,7 +147,7 @@ namespace WebSocketSharp.Net
/// </value> /// </value>
public string Response { public string Response {
get { get {
return _params ["response"]; return _parameters ["response"];
} }
} }
@ -159,7 +159,7 @@ namespace WebSocketSharp.Net
/// </value> /// </value>
public string Uri { public string Uri {
get { get {
return _params ["uri"]; return _parameters ["uri"];
} }
} }
@ -169,13 +169,13 @@ namespace WebSocketSharp.Net
internal bool IsValid (string password, string realm, string method, string entity) internal bool IsValid (string password, string realm, string method, string entity)
{ {
var parameters = new NameValueCollection (_params); var parameters = new NameValueCollection (_parameters);
parameters ["password"] = password; parameters ["password"] = password;
parameters ["realm"] = realm; parameters ["realm"] = realm;
parameters ["method"] = method; parameters ["method"] = method;
parameters ["entity"] = entity; parameters ["entity"] = entity;
return _params ["response"] == HttpUtility.CreateRequestDigest (parameters); return _parameters ["response"] == HttpUtility.CreateRequestDigest (parameters);
} }
#endregion #endregion