Fix a few for TcpListenerWebSocketContext.cs

This commit is contained in:
sta 2014-05-10 17:20:37 +09:00
parent 4125e4d3e1
commit 091b45c8b0
4 changed files with 22 additions and 24 deletions

View File

@ -510,9 +510,9 @@ namespace WebSocketSharp
}
internal static TcpListenerWebSocketContext GetWebSocketContext (
this TcpClient client, string protocol, X509Certificate cert, bool secure, Logger logger)
this TcpClient client, string protocol, bool secure, X509Certificate cert, Logger logger)
{
return new TcpListenerWebSocketContext (client, protocol, cert, secure, logger);
return new TcpListenerWebSocketContext (client, protocol, secure, cert, logger);
}
internal static bool IsCompressionExtension (this string value)

View File

@ -59,14 +59,12 @@ namespace WebSocketSharp.Net.WebSockets
#region Internal Constructors
internal TcpListenerWebSocketContext (
TcpClient client, string protocol, X509Certificate cert, bool secure, Logger logger)
TcpClient client, string protocol, bool secure, X509Certificate cert, Logger logger)
{
_client = client;
_secure = secure;
_stream = WsStream.CreateServerStream (client, cert, secure);
_request = _stream.ReadHandshake<HandshakeRequest> (
HandshakeRequest.Parse, 90000);
_stream = WsStream.CreateServerStream (client, secure, cert);
_request = _stream.ReadHandshake<HandshakeRequest> (HandshakeRequest.Parse, 90000);
_websocket = new WebSocket (this, protocol, logger);
}
@ -356,7 +354,7 @@ namespace WebSocketSharp.Net.WebSockets
}
internal void SetUser (
AuthenticationSchemes expectedScheme,
AuthenticationSchemes scheme,
string realm,
Func<IIdentity, NetworkCredential> credentialsFinder)
{
@ -364,29 +362,29 @@ namespace WebSocketSharp.Net.WebSockets
if (authRes == null)
return;
var identity = authRes.ToIdentity ();
if (identity == null)
var id = authRes.ToIdentity ();
if (id == null)
return;
NetworkCredential credentials = null;
NetworkCredential cred = null;
try {
credentials = credentialsFinder (identity);
cred = credentialsFinder (id);
}
catch {
}
if (credentials == null)
if (cred == null)
return;
var valid = expectedScheme == AuthenticationSchemes.Basic
? ((HttpBasicIdentity) identity).Password == credentials.Password
: expectedScheme == AuthenticationSchemes.Digest
? ((HttpDigestIdentity) identity).IsValid (
credentials.Password, realm, _request.HttpMethod, null)
var valid = scheme == AuthenticationSchemes.Basic
? ((HttpBasicIdentity) id).Password == cred.Password
: scheme == AuthenticationSchemes.Digest
? ((HttpDigestIdentity) id).IsValid (
cred.Password, realm, _request.HttpMethod, null)
: false;
if (valid)
_user = new GenericPrincipal (identity, credentials.Roles);
_user = new GenericPrincipal (id, cred.Roles);
}
#endregion

View File

@ -476,7 +476,7 @@ namespace WebSocketSharp.Server
ThreadPool.QueueUserWorkItem (
state => {
try {
var context = client.GetWebSocketContext (null, _cert, _secure, _logger);
var context = client.GetWebSocketContext (null, _secure, _cert, _logger);
if (_authSchemes != AuthenticationSchemes.Anonymous &&
!authenticateRequest (_authSchemes, context))
return;

View File

@ -163,7 +163,7 @@ namespace WebSocketSharp
}
internal static WsStream CreateServerStream (
TcpClient client, X509Certificate cert, bool secure)
TcpClient client, bool secure, X509Certificate cert)
{
var netStream = client.GetStream ();
if (secure) {