Permalink
Browse files

Finished variable renaming.

  • Loading branch information...
1 parent 84ff63e commit 56c1994939c821719988ceb70d5d0e2191293c86 @DorianGray DorianGray committed Oct 30, 2011
View
18 Classes/DataFrame.cs
@@ -27,7 +27,7 @@
namespace Alchemy.Server.Classes
{
/// <summary>
- /// Simple WebSocket Data Frame implementation.
+ /// Simple WebSocket data Frame implementation.
/// Automatically manages adding received data to an existing frame and checking whether or not we've received the entire frame yet.
/// See http://www.whatwg.org/specs/web-socket-protocol/ for more details on the WebSocket Protocol.
/// </summary>
@@ -78,7 +78,7 @@ public DataState State
/// Wraps the specified data.
/// Accepts a string, converts to bytes, sends to the real wrap function.
/// </summary>
- /// <param name="Data">The data.</param>
+ /// <param name="data">The data.</param>
/// <returns></returns>
public byte[] Wrap(string data)
{
@@ -90,21 +90,21 @@ public byte[] Wrap(string data)
/// Wraps the specified data in WebSocket Start/End Bytes.
/// Accepts a byte array.
/// </summary>
- /// <param name="Data">The data.</param>
- /// <returns>The Data array wrapped in WebSocket DataFrame Start/End qualifiers.</returns>
+ /// <param name="data">The data.</param>
+ /// <returns>The data array wrapped in WebSocket DataFrame Start/End qualifiers.</returns>
public abstract byte[] Wrap(byte[] data);
/// <summary>
/// Appends the specified data to the internal byte buffer.
/// </summary>
- /// <param name="Data">The data.</param>
+ /// <param name="data">The data.</param>
public abstract void Append(byte[] data);
/// <summary>
- /// Returns a <see cref="System.String"/> that represents this Data Frame.
+ /// Returns a <see cref="System.String"/> that represents this data Frame.
/// </summary>
/// <returns>
- /// A <see cref="System.String"/> that represents this Data Frame.
+ /// A <see cref="System.String"/> that represents this data Frame.
/// </returns>
public override string ToString()
{
@@ -115,10 +115,10 @@ public override string ToString()
}
/// <summary>
- /// Returns a Byte Array that represents this Data Frame.
+ /// Returns a Byte Array that represents this data Frame.
/// </summary>
/// <returns>
- /// A Byte Array that represents this Data Frame.
+ /// A Byte Array that represents this data Frame.
/// </returns>
public byte[] ToBytes()
{
View
2 Classes/Header.cs
@@ -95,7 +95,7 @@ public class Header
/// Initializes a new instance of the <see cref="Header"/> class.
/// Accepts a string that represents an HTTP header.
/// </summary>
- /// <param name="Data">The data.</param>
+ /// <param name="data">The data.</param>
public Header(string Data)
{
try
View
18 Classes/UserContext.cs
@@ -39,7 +39,7 @@ public class UserContext
/// </summary>
private Context Context = null;
/// <summary>
- /// The Data Frame that this client is currently processing.
+ /// The data Frame that this client is currently processing.
/// </summary>
public DataFrame DataFrame = null;
/// <summary>
@@ -75,7 +75,7 @@ public class UserContext
/// <summary>
/// Initializes a new instance of the <see cref="UserContext"/> class.
/// </summary>
- /// <param name="AContext">The user context.</param>
+ /// <param name="context">The user context.</param>
public UserContext(Context AContext)
{
this.Context = AContext;
@@ -170,8 +170,8 @@ public void SetOnReceive(OnEventDelegate ADelegate)
/// <summary>
/// Sends the specified data.
/// </summary>
- /// <param name="Data">The data.</param>
- /// <param name="Close">if set to <c>true</c> [close].</param>
+ /// <param name="data">The data.</param>
+ /// <param name="close">if set to <c>true</c> [close].</param>
public void Send(string Data, bool Close = false)
{
Send(Encoding.GetBytes(Data), Close);
@@ -180,8 +180,8 @@ public void Send(string Data, bool Close = false)
/// <summary>
/// Sends the specified data.
/// </summary>
- /// <param name="Data">The data.</param>
- /// <param name="Close">if set to <c>true</c> [close].</param>
+ /// <param name="data">The data.</param>
+ /// <param name="close">if set to <c>true</c> [close].</param>
public void Send(byte[] Data, bool Close = false)
{
Context.Handler.Send(Data, Context, Close);
@@ -190,10 +190,10 @@ public void Send(byte[] Data, bool Close = false)
/// <summary>
/// Sends raw data.
/// </summary>
- /// <param name="Data">The data.</param>
+ /// <param name="data">The data.</param>
public void SendRaw(byte[] Data)
{
- DefaultHandler.Instance.Send(Data, Context);
+ _defaultHandler.Instance.Send(Data, Context);
}
}
@@ -233,7 +233,7 @@ public class Context : IDisposable
/// <summary>
/// The current connection handler.
/// </summary>
- public Handler Handler = DefaultHandler.Instance;
+ public Handler Handler = _defaultHandler.Instance;
/// <summary>
/// Semaphores that limit sends and receives to 1 and a time.
/// </summary>
View
114 Handlers/DefaultHandler.cs
@@ -30,23 +30,23 @@ namespace Alchemy.Server.Handlers
/// When the protocol has not yet been determined the system defaults to this request handler.
/// Singleton, just like the other handlers.
/// </summary>
- class DefaultHandler : Handler
+ class _defaultHandler : Handler
{
- private static DefaultHandler _Instance;
+ private static _defaultHandler _instance;
- private DefaultHandler() { }
+ private _defaultHandler() { }
- public static DefaultHandler Instance
+ public static _defaultHandler Instance
{
get
{
- CreateLock.Wait();
- if (_Instance == null)
+ _createLock.Wait();
+ if (_instance == null)
{
- _Instance = new DefaultHandler();
+ _instance = new _defaultHandler();
}
- CreateLock.Release();
- return _Instance;
+ _createLock.Release();
+ return _instance;
}
}
@@ -55,128 +55,128 @@ public static DefaultHandler Instance
/// Attempts to process the header that should have been sent.
/// Otherwise, through magic and wizardry, the client gets disconnected.
/// </summary>
- /// <param name="AContext">The user context.</param>
- public override void HandleRequest(Context AContext)
+ /// <param name="context">The user context.</param>
+ public override void HandleRequest(Context context)
{
- if (AContext.IsSetup)
+ if (context.IsSetup)
{
- AContext.Dispose();
+ context.Dispose();
}
else
{
- ProcessHeader(AContext);
+ ProcessHeader(context);
}
}
/// <summary>
/// Processes the header.
/// </summary>
- /// <param name="AContext">The user context.</param>
- public void ProcessHeader(Context AContext)
+ /// <param name="context">The user context.</param>
+ public void ProcessHeader(Context context)
{
- string Data = AContext.UserContext.Encoding.GetString(AContext.Buffer, 0, AContext.ReceivedByteCount);
+ string data = context.UserContext.Encoding.GetString(context.Buffer, 0, context.ReceivedByteCount);
//Check first to see if this is a flash socket XML request.
- if (Data == "<policy-file-request/>\0")
+ if (data == "<policy-file-request/>\0")
{
try
{
//if it is, we access the Access Policy Server instance to send the appropriate response.
- AContext.Server.AccessPolicyServer.SendResponse(AContext.Connection);
+ context.Server.AccessPolicyServer.SendResponse(context.Connection);
}
catch { }
- AContext.Dispose();
+ context.Dispose();
}
else//If it isn't, process http/websocket header as normal.
{
- AContext.Header = new Header(Data);
- switch (AContext.Header.Protocol)
+ context.Header = new Header(data);
+ switch (context.Header.Protocol)
{
case Protocol.WebSocketHybi00:
- AContext.Handler = Alchemy.Server.Handlers.WebSocket.hybi00.WebSocketHandler.Instance;
- AContext.UserContext.DataFrame = new Alchemy.Server.Handlers.WebSocket.hybi00.DataFrame();
+ context.Handler = Alchemy.Server.Handlers.WebSocket.hybi00.WebSocketHandler.Instance;
+ context.UserContext.DataFrame = new Alchemy.Server.Handlers.WebSocket.hybi00.DataFrame();
break;
case Protocol.WebSocketHybi10:
- AContext.Handler = Alchemy.Server.Handlers.WebSocket.hybi10.WebSocketHandler.Instance;
- AContext.UserContext.DataFrame = new Alchemy.Server.Handlers.WebSocket.hybi10.DataFrame();
+ context.Handler = Alchemy.Server.Handlers.WebSocket.hybi10.WebSocketHandler.Instance;
+ context.UserContext.DataFrame = new Alchemy.Server.Handlers.WebSocket.hybi10.DataFrame();
break;
case Protocol.FlashSocket:
- AContext.Handler = Alchemy.Server.Handlers.WebSocket.hybi00.WebSocketHandler.Instance;
- AContext.UserContext.DataFrame = new Alchemy.Server.Handlers.WebSocket.hybi00.DataFrame();
+ context.Handler = Alchemy.Server.Handlers.WebSocket.hybi00.WebSocketHandler.Instance;
+ context.UserContext.DataFrame = new Alchemy.Server.Handlers.WebSocket.hybi00.DataFrame();
break;
default:
- AContext.Header.Protocol = Protocol.None;
+ context.Header.Protocol = Protocol.None;
break;
}
- if (AContext.Header.Protocol != Protocol.None)
+ if (context.Header.Protocol != Protocol.None)
{
- AContext.Handler.HandleRequest(AContext);
+ context.Handler.HandleRequest(context);
}
else
{
- AContext.UserContext.Send(Response.NotImplemented, true);
+ context.UserContext.Send(Response.NotImplemented, true);
}
}
}
/// <summary>
/// Sends the specified data.
/// </summary>
- /// <param name="Data">The data.</param>
- /// <param name="AContext">The user context.</param>
- /// <param name="Close">if set to <c>true</c> [close].</param>
- public override void Send(byte[] Data, Context AContext, bool Close = false)
+ /// <param name="data">The data.</param>
+ /// <param name="context">The user context.</param>
+ /// <param name="close">if set to <c>true</c> [close].</param>
+ public override void Send(byte[] data, Context context, bool close = false)
{
- AsyncCallback ACallback = EndSend;
- if (Close)
- ACallback = EndSendAndClose;
- AContext.SendReady.Wait();
+ AsyncCallback callback = EndSend;
+ if (close)
+ callback = EndSendAndClose;
+ context.SendReady.Wait();
try
{
- AContext.Connection.Client.BeginSend(Data, 0, Data.Length, SocketFlags.None, ACallback, AContext);
+ context.Connection.Client.BeginSend(data, 0, data.Length, SocketFlags.None, callback, context);
}
catch
{
- AContext.SendReady.Release();
+ context.SendReady.Release();
}
}
/// <summary>
/// Ends the send.
/// </summary>
- /// <param name="AResult">The Async result.</param>
- public override void EndSend(IAsyncResult AResult)
+ /// <param name="result">The Async result.</param>
+ public override void EndSend(IAsyncResult result)
{
- Context AContext = (Context)AResult.AsyncState;
+ Context context = (Context)result.AsyncState;
try
{
- AContext.Connection.Client.EndSend(AResult);
- AContext.SendReady.Release();
+ context.Connection.Client.EndSend(result);
+ context.SendReady.Release();
}
catch
{
- AContext.SendReady.Release();
+ context.SendReady.Release();
}
- AContext.UserContext.OnSend();
+ context.UserContext.OnSend();
}
/// <summary>
/// Ends the send and closes the connection.
/// </summary>
- /// <param name="AResult">The Async result.</param>
- public override void EndSendAndClose(IAsyncResult AResult)
+ /// <param name="result">The Async result.</param>
+ public override void EndSendAndClose(IAsyncResult result)
{
- Context AContext = (Context)AResult.AsyncState;
+ Context context = (Context)result.AsyncState;
try
{
- AContext.Connection.Client.EndSend(AResult);
- AContext.SendReady.Release();
+ context.Connection.Client.EndSend(result);
+ context.SendReady.Release();
}
catch
{
- AContext.SendReady.Release();
+ context.SendReady.Release();
}
- AContext.UserContext.OnSend();
- AContext.Dispose();
+ context.UserContext.OnSend();
+ context.Dispose();
}
}
}
View
2 Handlers/Handler.cs
@@ -34,7 +34,7 @@ namespace Alchemy.Server.Handlers
public abstract class Handler
{
public WebSocketAuthentication Authentication = null;
- protected static SemaphoreSlim CreateLock = new SemaphoreSlim(1);
+ protected static SemaphoreSlim _createLock = new SemaphoreSlim(1);
public abstract void HandleRequest(Context Request);
public abstract void Send(byte[] Data, Context AContext, bool Close = false);
public abstract void EndSend(IAsyncResult AResult);
View
8 Handlers/WebSocket/hybi00/DataFrame.cs
@@ -26,7 +26,7 @@
namespace Alchemy.Server.Handlers.WebSocket.hybi00
{
/// <summary>
- /// Simple WebSocket Data Frame implementation.
+ /// Simple WebSocket data Frame implementation.
/// Automatically manages adding received data to an existing frame and checking whether or not we've received the entire frame yet.
/// See http://www.whatwg.org/specs/web-socket-protocol/ for more details on the WebSocket Protocol.
/// </summary>
@@ -39,8 +39,8 @@ public class DataFrame : Alchemy.Server.Classes.DataFrame
/// Wraps the specified data in WebSocket Start/End Bytes.
/// Accepts a byte array.
/// </summary>
- /// <param name="Data">The data.</param>
- /// <returns>The Data array wrapped in WebSocket DataFrame Start/End qualifiers.</returns>
+ /// <param name="data">The data.</param>
+ /// <returns>The data array wrapped in WebSocket DataFrame Start/End qualifiers.</returns>
public override byte[] Wrap(byte[] data)
{
// wrap the array with the wrapper bytes
@@ -54,7 +54,7 @@ public override byte[] Wrap(byte[] data)
/// <summary>
/// Appends the specified data to the internal byte buffer.
/// </summary>
- /// <param name="Data">The data.</param>
+ /// <param name="data">The data.</param>
public override void Append(byte[] data)
{
if (data.Length > 0)
View
46 Handlers/WebSocket/hybi00/Handshakes.cs
@@ -36,7 +36,7 @@ public class ClientHandshake
/// <summary>
/// The preformatted handshake as a string.
/// </summary>
- private const String Handshake =
+ private const String _handshake =
"GET {0} HTTP/1.1\r\n" +
"Upgrade: WebSocket\r\n" +
"Connection: Upgrade\r\n" +
@@ -60,17 +60,17 @@ public class ClientHandshake
/// Initializes a new instance of the <see cref="ClientHandshake"/> class.
/// </summary>
/// <param name="ChallengeBytes">The challenge bytes.</param>
- /// <param name="AHeader">The header.</param>
- public ClientHandshake(ArraySegment<byte> ChallengeBytes, Header AHeader)
+ /// <param name="header">The header.</param>
+ public ClientHandshake(ArraySegment<byte> challengeBytes, Header header)
{
- this.ChallengeBytes = ChallengeBytes;
- ResourcePath = AHeader.RequestPath;
- Key1 = AHeader["sec-websocket-key1"];
- Key2 = AHeader["sec-websocket-key2"];
- SubProtocol = AHeader["sec-websocket-protocol"];
- Origin = AHeader["origin"];
- Host = AHeader["host"];
- Cookies = AHeader.Cookies;
+ ChallengeBytes = challengeBytes;
+ ResourcePath = header.RequestPath;
+ Key1 = header["sec-websocket-key1"];
+ Key2 = header["sec-websocket-key2"];
+ SubProtocol = header["sec-websocket-protocol"];
+ Origin = header["origin"];
+ Host = header["host"];
+ Cookies = header.Cookies;
}
/// <summary>
@@ -99,25 +99,25 @@ public bool IsValid()
/// </returns>
public override string ToString()
{
- string AdditionalFields = String.Empty;
+ string additionalFields = String.Empty;
if (Cookies != null)
{
- AdditionalFields += "Cookie: " + Cookies.ToString() + "\r\n";
+ additionalFields += "Cookie: " + Cookies.ToString() + "\r\n";
}
if (SubProtocol != null)
- AdditionalFields += "Sec-Websocket-Protocol: " + SubProtocol + "\r\n";
+ additionalFields += "Sec-Websocket-Protocol: " + SubProtocol + "\r\n";
- if (AdditionalFields != null)
+ if (additionalFields != null)
{
foreach (KeyValuePair<string, string> field in this.AdditionalFields)
{
- AdditionalFields += field.Key + ": " + field.Value + "\r\n";
+ additionalFields += field.Key + ": " + field.Value + "\r\n";
}
}
- AdditionalFields += "\r\n";
+ additionalFields += "\r\n";
- return String.Format(Handshake, ResourcePath, Origin, Host, Key1, Key2, AdditionalFields);
+ return String.Format(_handshake, ResourcePath, Origin, Host, Key1, Key2, AdditionalFields);
}
}
@@ -130,7 +130,7 @@ public class ServerHandshake
/// <summary>
/// The preformatted handshake string.
/// </summary>
- private const string Handshake =
+ private const string _handshake =
"HTTP/1.1 101 Web Socket Protocol Handshake\r\n" +
"Upgrade: WebSocket\r\n" +
"Connection: Upgrade\r\n" +
@@ -153,14 +153,14 @@ public class ServerHandshake
/// </returns>
public override string ToString()
{
- string AdditionalFields = String.Empty;
+ string additionalFields = String.Empty;
if (SubProtocol != null)
{
- AdditionalFields += "Sec-WebSocket-Protocol: " + SubProtocol + "\r\n";
+ additionalFields += "Sec-WebSocket-Protocol: " + SubProtocol + "\r\n";
}
- AdditionalFields += "\r\n";
+ additionalFields += "\r\n";
- return String.Format(Handshake, Origin, Location, AdditionalFields);
+ return String.Format(_handshake, Origin, Location, AdditionalFields);
}
}
}
View
73 Handlers/WebSocket/hybi00/WebSocketAuthentication.cs
@@ -35,7 +35,8 @@ public class WebSocketAuthentication : Alchemy.Server.Handlers.WebSocket.WebSock
{
public static string Origin = string.Empty;
public static string Location = string.Empty;
- private static SemaphoreSlim CreateLock = new SemaphoreSlim(1);
+
+ private static SemaphoreSlim _createLock = new SemaphoreSlim(1);
private static WebSocketAuthentication _instance = null;
private WebSocketAuthentication()
@@ -47,12 +48,12 @@ public static WebSocketAuthentication Instance
{
get
{
- CreateLock.Wait();
+ _createLock.Wait();
if (_instance == null)
{
_instance = new WebSocketAuthentication();
}
- CreateLock.Release();
+ _createLock.Release();
return _instance;
}
}
@@ -67,82 +68,82 @@ public void SetLocation(string location)
Location = location;
}
- public bool CheckHandshake(Context AContext)
+ public bool CheckHandshake(Context context)
{
- if (AContext.ReceivedByteCount > 8)
+ if (context.ReceivedByteCount > 8)
{
- ClientHandshake AHandshake = new ClientHandshake(new ArraySegment<byte>(AContext.Buffer, AContext.ReceivedByteCount - 8, 8), AContext.Header);
+ ClientHandshake handshake = new ClientHandshake(new ArraySegment<byte>(context.Buffer, context.ReceivedByteCount - 8, 8), context.Header);
// See if our header had the required information
- if (AHandshake.IsValid())
+ if (handshake.IsValid())
{
// Optionally check Origin and Location if they're set.
if (Origin != string.Empty)
- if (AHandshake.Origin != "http://" + Origin)
+ if (handshake.Origin != "http://" + Origin)
return false;
if (Location != string.Empty)
- if (AHandshake.Host != Location + ":" + AContext.Server.Port.ToString())
+ if (handshake.Host != Location + ":" + context.Server.Port.ToString())
return false;
// Generate response handshake for the client
- ServerHandshake ServerShake = GenerateResponseHandshake(AHandshake);
+ ServerHandshake serverShake = GenerateResponseHandshake(handshake);
// Send the response handshake
- SendServerHandshake(ServerShake, AContext);
+ SendServerHandshake(serverShake, context);
return true;
}
}
return false;
}
- private static ServerHandshake GenerateResponseHandshake(ClientHandshake AHandshake)
+ private static ServerHandshake GenerateResponseHandshake(ClientHandshake handshake)
{
- ServerHandshake AResponseHandshake = new ServerHandshake();
- AResponseHandshake.Location = "ws://" + AHandshake.Host + AHandshake.ResourcePath;
- AResponseHandshake.Origin = AHandshake.Origin;
- AResponseHandshake.SubProtocol = AHandshake.SubProtocol;
- AResponseHandshake.AnswerBytes = GenerateAnswerBytes(AHandshake.Key1, AHandshake.Key2, AHandshake.ChallengeBytes);
+ ServerHandshake responseHandshake = new ServerHandshake();
+ responseHandshake.Location = "ws://" + handshake.Host + handshake.ResourcePath;
+ responseHandshake.Origin = handshake.Origin;
+ responseHandshake.SubProtocol = handshake.SubProtocol;
+ responseHandshake.AnswerBytes = GenerateAnswerBytes(handshake.Key1, handshake.Key2, handshake.ChallengeBytes);
- return AResponseHandshake;
+ return responseHandshake;
}
- private static void SendServerHandshake(ServerHandshake AHandshake, Context AContext)
+ private static void SendServerHandshake(ServerHandshake handshake, Context context)
{
// generate a byte array representation of the handshake including the answer to the challenge
- byte[] HandshakeBytes = AContext.UserContext.Encoding.GetBytes(AHandshake.ToString());
- Array.Copy(AHandshake.AnswerBytes, 0, HandshakeBytes, HandshakeBytes.Length - 16, 16);
+ byte[] handshakeBytes = context.UserContext.Encoding.GetBytes(handshake.ToString());
+ Array.Copy(handshake.AnswerBytes, 0, handshakeBytes, handshakeBytes.Length - 16, 16);
- AContext.UserContext.SendRaw(HandshakeBytes);
+ context.UserContext.SendRaw(handshakeBytes);
}
- private static byte[] TranslateKey(string AKey)
+ private static byte[] TranslateKey(string key)
{
// Count total spaces in the keys
- int KeySpaceCount = AKey.Count(x => x == ' ');
+ int keySpaceCount = key.Count(x => x == ' ');
// Get a number which is a concatenation of all digits in the keys.
- string KeyNumberString = new String(AKey.Where(x => Char.IsDigit(x)).ToArray());
+ string keyNumberString = new String(key.Where(x => Char.IsDigit(x)).ToArray());
// Divide the number with the number of spaces
- Int32 KeyResult = (Int32)(Int64.Parse(KeyNumberString) / KeySpaceCount);
+ Int32 keyResult = (Int32)(Int64.Parse(keyNumberString) / keySpaceCount);
// convert the results to 32 bit big endian byte arrays
- byte[] KeyResultBytes = BitConverter.GetBytes(KeyResult);
+ byte[] KeyResultBytes = BitConverter.GetBytes(keyResult);
if (BitConverter.IsLittleEndian)
{
Array.Reverse(KeyResultBytes);
}
return KeyResultBytes;
}
- private static byte[] GenerateAnswerBytes(string Key1, string Key2, ArraySegment<byte> AChallenge)
+ private static byte[] GenerateAnswerBytes(string key1, string key2, ArraySegment<byte> challenge)
{
// Translate the two keys, concatenate them and the 8 challenge bytes from the client
- byte[] RawAnswer = new byte[16];
- Array.Copy(TranslateKey(Key1), 0, RawAnswer, 0, 4);
- Array.Copy(TranslateKey(Key2), 0, RawAnswer, 4, 4);
- Array.Copy(AChallenge.Array, AChallenge.Offset, RawAnswer, 8, 8);
-
- // Create a hash of the RawAnswer and return it
- MD5 Hasher = MD5.Create();
- return Hasher.ComputeHash(RawAnswer);
+ byte[] rawAnswer = new byte[16];
+ Array.Copy(TranslateKey(key1), 0, rawAnswer, 0, 4);
+ Array.Copy(TranslateKey(key2), 0, rawAnswer, 4, 4);
+ Array.Copy(challenge.Array, challenge.Offset, rawAnswer, 8, 8);
+
+ // Create a hash of the rawAnswer and return it
+ MD5 hasher = MD5.Create();
+ return hasher.ComputeHash(rawAnswer);
}
}
}
View
116 Handlers/WebSocket/hybi00/WebSocketHandler.cs
@@ -42,153 +42,153 @@ public static WebSocketHandler Instance
{
get
{
- CreateLock.Wait();
+ _createLock.Wait();
if (_instance == null)
{
_instance = new WebSocketHandler();
}
- CreateLock.Release();
+ _createLock.Release();
return _instance;
}
}
/// <summary>
/// Handles the request.
/// </summary>
- /// <param name="AContext">The user context.</param>
- public override void HandleRequest(Context AContext)
+ /// <param name="context">The user context.</param>
+ public override void HandleRequest(Context context)
{
- if (AContext.IsSetup)
+ if (context.IsSetup)
{
- AContext.UserContext.DataFrame.Append(AContext.Buffer);
- if (AContext.UserContext.DataFrame.State == DataFrame.DataState.Complete)
+ context.UserContext.DataFrame.Append(context.Buffer);
+ if (context.UserContext.DataFrame.State == DataFrame.DataState.Complete)
{
- switch (AContext.UserContext.DataFrame.Length)
+ switch (context.UserContext.DataFrame.Length)
{
case 1:
//Process Command
- string ACommand = AContext.UserContext.DataFrame.ToString();
- if (ACommand == AContext.Server.PingCommand)
+ string command = context.UserContext.DataFrame.ToString();
+ if (command == context.Server.PingCommand)
{
- SendPingResponse(AContext);
- AContext.Pings++;
+ SendPingResponse(context);
+ context.Pings++;
}
else
{
- AContext.Pings = 0;
- AContext.UserContext.OnReceive();
+ context.Pings = 0;
+ context.UserContext.OnReceive();
}
- if ((AContext.Pings >= AContext.Server.MaxPingsInSequence) && (AContext.Server.MaxPingsInSequence != 0))
+ if ((context.Pings >= context.Server.MaxPingsInSequence) && (context.Server.MaxPingsInSequence != 0))
{
- AContext.Dispose();
+ context.Dispose();
}
break;
default:
- AContext.Pings = 0;
- AContext.UserContext.OnReceive();
+ context.Pings = 0;
+ context.UserContext.OnReceive();
break;
}
}
- else if (AContext.UserContext.DataFrame.State == DataFrame.DataState.Closed)
+ else if (context.UserContext.DataFrame.State == DataFrame.DataState.Closed)
{
- AContext.UserContext.Send(new byte[0], true);
+ context.UserContext.Send(new byte[0], true);
}
}
else
{
- Authenticate(AContext);
+ Authenticate(context);
}
}
/// <summary>
/// Attempts to authenticates the specified user context.
/// If authentication fails it kills the connection.
/// </summary>
- /// <param name="AContext">The user context.</param>
- private void Authenticate(Context AContext)
+ /// <param name="context">The user context.</param>
+ private static void Authenticate(Context context)
{
- if (AContext.Handler.Authentication.CheckHandshake(AContext))
+ if (context.Handler.Authentication.CheckHandshake(context))
{
- AContext.UserContext.Protocol = AContext.Header.Protocol;
- AContext.UserContext.RequestPath = AContext.Header.RequestPath;
- AContext.Header = null;
- AContext.IsSetup = true;
+ context.UserContext.Protocol = context.Header.Protocol;
+ context.UserContext.RequestPath = context.Header.RequestPath;
+ context.Header = null;
+ context.IsSetup = true;
}
else
{
- AContext.Dispose();
+ context.Dispose();
}
}
/// <summary>
/// Sends the specified data.
/// </summary>
- /// <param name="Data">The data.</param>
- /// <param name="AContext">The user context.</param>
- /// <param name="Close">if set to <c>true</c> [close].</param>
- public override void Send(byte[] Data, Context AContext, bool Close = false)
+ /// <param name="data">The data.</param>
+ /// <param name="context">The user context.</param>
+ /// <param name="close">if set to <c>true</c> [close].</param>
+ public override void Send(byte[] data, Context context, bool close = false)
{
- byte[] WrappedData = AContext.UserContext.DataFrame.Wrap(Data);
- AsyncCallback ACallback = EndSend;
- if (Close)
- ACallback = EndSendAndClose;
- AContext.SendReady.Wait();
+ byte[] wrappedData = context.UserContext.DataFrame.Wrap(data);
+ AsyncCallback callback = EndSend;
+ if (close)
+ callback = EndSendAndClose;
+ context.SendReady.Wait();
try
{
- AContext.Connection.Client.BeginSend(WrappedData, 0, WrappedData.Length, SocketFlags.None, ACallback, AContext);
+ context.Connection.Client.BeginSend(wrappedData, 0, wrappedData.Length, SocketFlags.None, callback, context);
}
catch
{
- AContext.SendReady.Release();
+ context.SendReady.Release();
}
}
/// <summary>
/// Ends the send.
/// </summary>
- /// <param name="AResult">The Async result.</param>
- public override void EndSend(IAsyncResult AResult)
+ /// <param name="result">The Async result.</param>
+ public override void EndSend(IAsyncResult result)
{
- Context AContext = (Context)AResult.AsyncState;
+ Context context = (Context)result.AsyncState;
try
{
- AContext.Connection.Client.EndSend(AResult);
- AContext.SendReady.Release();
+ context.Connection.Client.EndSend(result);
+ context.SendReady.Release();
}
catch
{
- AContext.SendReady.Release();
+ context.SendReady.Release();
}
- AContext.UserContext.OnSend();
+ context.UserContext.OnSend();
}
/// <summary>
/// Ends the send and closes the connection.
/// </summary>
- /// <param name="AResult">The Async result.</param>
- public override void EndSendAndClose(IAsyncResult AResult)
+ /// <param name="result">The Async result.</param>
+ public override void EndSendAndClose(IAsyncResult result)
{
- Context AContext = (Context)AResult.AsyncState;
+ Context context = (Context)result.AsyncState;
try
{
- AContext.Connection.Client.EndSend(AResult);
- AContext.SendReady.Release();
+ context.Connection.Client.EndSend(result);
+ context.SendReady.Release();
}
catch
{
- AContext.SendReady.Release();
+ context.SendReady.Release();
}
- AContext.UserContext.OnSend();
- AContext.Dispose();
+ context.UserContext.OnSend();
+ context.Dispose();
}
/// <summary>
/// Sends the ping response.
/// </summary>
- /// <param name="AContext">The user context.</param>
- private void SendPingResponse(Context AContext)
+ /// <param name="context">The user context.</param>
+ private static void SendPingResponse(Context context)
{
- AContext.UserContext.Send(AContext.Server.PongCommand);
+ context.UserContext.Send(context.Server.PongCommand);
}
}
}
View
8 Handlers/WebSocket/hybi10/DataFrame.cs
@@ -27,7 +27,7 @@
namespace Alchemy.Server.Handlers.WebSocket.hybi10
{
/// <summary>
- /// Simple WebSocket Data Frame implementation.
+ /// Simple WebSocket data Frame implementation.
/// Automatically manages adding received data to an existing frame and checking whether or not we've received the entire frame yet.
/// See http://www.whatwg.org/specs/web-socket-protocol/ for more details on the WebSocket Protocol.
/// </summary>
@@ -50,8 +50,8 @@ public enum OpCode
/// Wraps the specified data in WebSocket Start/End Bytes.
/// Accepts a byte array.
/// </summary>
- /// <param name="Data">The data.</param>
- /// <returns>The Data array wrapped in WebSocket DataFrame Start/End qualifiers.</returns>
+ /// <param name="data">The data.</param>
+ /// <returns>The data array wrapped in WebSocket DataFrame Start/End qualifiers.</returns>
public override byte[] Wrap(byte[] data)
{
byte[] wrappedBytes = null;
@@ -116,7 +116,7 @@ public override byte[] Wrap(byte[] data)
/// <summary>
/// Appends the specified data to the internal byte buffer.
/// </summary>
- /// <param name="Data">The data.</param>
+ /// <param name="data">The data.</param>
public override void Append(byte[] data)
{
if (data.Length > 0)
View
42 Handlers/WebSocket/hybi10/Handshakes.cs
@@ -36,7 +36,7 @@ public class ClientHandshake
/// <summary>
/// The preformatted handshake as a string.
/// </summary>
- private const String Handshake =
+ private const String _handshake =
"GET {0} HTTP/1.1\r\n" +
"Host: {2}\r\n" +
"Upgrade: websocket\r\n" +
@@ -60,16 +60,16 @@ public class ClientHandshake
/// Initializes a new instance of the <see cref="ClientHandshake"/> class.
/// </summary>
/// <param name="ChallengeBytes">The challenge bytes.</param>
- /// <param name="AHeader">The header.</param>
- public ClientHandshake(Header AHeader)
+ /// <param name="header">The header.</param>
+ public ClientHandshake(Header header)
{
- ResourcePath= AHeader.RequestPath;
- Key = AHeader["sec-websocket-key"];
- SubProtocol = AHeader["sec-websocket-protocol"];
- Origin = AHeader["sec-websocket-origin"];
- Host = AHeader["host"];
- Version = AHeader["sec-websocket-version"];
- Cookies = AHeader.Cookies;
+ ResourcePath= header.RequestPath;
+ Key = header["sec-websocket-key"];
+ SubProtocol = header["sec-websocket-protocol"];
+ Origin = header["sec-websocket-origin"];
+ Host = header["host"];
+ Version = header["sec-websocket-version"];
+ Cookies = header.Cookies;
}
/// <summary>
@@ -97,23 +97,23 @@ public bool IsValid()
/// </returns>
public override string ToString()
{
- string AdditionalFields = String.Empty;
+ string additionalFields = String.Empty;
if (Cookies != null)
{
- AdditionalFields += "Cookie: " + Cookies.ToString() + "\r\n";
+ additionalFields += "Cookie: " + Cookies.ToString() + "\r\n";
}
- if (AdditionalFields != null)
+ if (additionalFields != null)
{
foreach (KeyValuePair<string, string> field in this.AdditionalFields)
{
- AdditionalFields += field.Key + ": " + field.Value + "\r\n";
+ additionalFields += field.Key + ": " + field.Value + "\r\n";
}
}
- AdditionalFields += "\r\n";
+ additionalFields += "\r\n";
- return String.Format(Handshake, ResourcePath, Origin, Host, SubProtocol, Key, AdditionalFields);
+ return String.Format(_handshake, ResourcePath, Origin, Host, SubProtocol, Key, additionalFields);
}
}
@@ -126,7 +126,7 @@ public class ServerHandshake
/// <summary>
/// The preformatted handshake string.
/// </summary>
- private const string Handshake =
+ private const string _handshake =
"HTTP/1.1 101 Switching Protocols\r\n" +
"Upgrade: websocket\r\n" +
"Connection: Upgrade\r\n" +
@@ -146,13 +146,13 @@ public class ServerHandshake
/// </returns>
public override string ToString()
{
- string AdditionalFields = String.Empty;
+ string additionalFields = String.Empty;
if (SubProtocol != null)
{
- AdditionalFields += "Sec-WebSocket-Protocol: " + SubProtocol + "\r\n";
+ additionalFields += "Sec-WebSocket-Protocol: " + SubProtocol + "\r\n";
}
- AdditionalFields += "\r\n";
- return String.Format(Handshake, Accept, AdditionalFields);
+ additionalFields += "\r\n";
+ return String.Format(_handshake, Accept, additionalFields);
}
}
}
View
50 Handlers/WebSocket/hybi10/WebSocketAuthentication.cs
@@ -34,7 +34,7 @@ public class WebSocketAuthentication : Alchemy.Server.Handlers.WebSocket.WebSock
{
public static string Origin = string.Empty;
public static string Location = string.Empty;
- private static SemaphoreSlim CreateLock = new SemaphoreSlim(1);
+ private static SemaphoreSlim _createLock = new SemaphoreSlim(1);
private static WebSocketAuthentication _instance = null;
private WebSocketAuthentication()
@@ -46,12 +46,12 @@ public static WebSocketAuthentication Instance
{
get
{
- CreateLock.Wait();
+ _createLock.Wait();
if (_instance == null)
{
_instance = new WebSocketAuthentication();
}
- CreateLock.Release();
+ _createLock.Release();
return _instance;
}
}
@@ -66,54 +66,54 @@ public void SetLocation(string location)
Location = location;
}
- public bool CheckHandshake(Context AContext)
+ public bool CheckHandshake(Context context)
{
- if(AContext.ReceivedByteCount > 8)
+ if(context.ReceivedByteCount > 8)
{
- ClientHandshake AHandshake = new ClientHandshake(AContext.Header);
+ ClientHandshake handshake = new ClientHandshake(context.Header);
// See if our header had the required information
- if (AHandshake.IsValid())
+ if (handshake.IsValid())
{
// Optionally check Origin and Location if they're set.
if (Origin != string.Empty)
- if (AHandshake.Origin != "http://" + Origin)
+ if (handshake.Origin != "http://" + Origin)
return false;
if (Location != string.Empty)
- if (AHandshake.Host != Location + ":" + AContext.Server.Port.ToString())
+ if (handshake.Host != Location + ":" + context.Server.Port.ToString())
return false;
// Generate response handshake for the client
- ServerHandshake ServerShake = GenerateResponseHandshake(AHandshake, AContext);
- ServerShake.SubProtocol = AHandshake.SubProtocol;
+ ServerHandshake serverShake = GenerateResponseHandshake(handshake, context);
+ serverShake.SubProtocol = handshake.SubProtocol;
// Send the response handshake
- SendServerHandshake(ServerShake, AContext);
+ SendServerHandshake(serverShake, context);
return true;
}
}
return false;
}
- private static ServerHandshake GenerateResponseHandshake(ClientHandshake AHandshake, Context AContext)
+ private static ServerHandshake GenerateResponseHandshake(ClientHandshake handshake, Context context)
{
- ServerHandshake AResponseHandshake = new ServerHandshake();
- AResponseHandshake.Accept = GenerateAccept(AHandshake.Key, AContext);
- return AResponseHandshake;
+ ServerHandshake responseHandshake = new ServerHandshake();
+ responseHandshake.Accept = GenerateAccept(handshake.Key, context);
+ return responseHandshake;
}
- private static void SendServerHandshake(ServerHandshake AHandshake, Context AContext)
+ private static void SendServerHandshake(ServerHandshake handshake, Context context)
{
// generate a byte array representation of the handshake including the answer to the challenge
- string temp = AHandshake.ToString();
- byte[] HandshakeBytes = AContext.UserContext.Encoding.GetBytes(temp);
- AContext.UserContext.SendRaw(HandshakeBytes);
+ string temp = handshake.ToString();
+ byte[] handshakeBytes = context.UserContext.Encoding.GetBytes(temp);
+ context.UserContext.SendRaw(handshakeBytes);
}
- private static string GenerateAccept(string Key, Context AContext)
+ private static string GenerateAccept(string key, Context context)
{
- string RawAnswer = Key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
+ string rawAnswer = key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
- // Create a hash of the RawAnswer and return it
- SHA1 Hasher = SHA1.Create();
- return Convert.ToBase64String(Hasher.ComputeHash(AContext.UserContext.Encoding.GetBytes(RawAnswer)));
+ // Create a hash of the rawAnswer and return it
+ SHA1 hasher = SHA1.Create();
+ return Convert.ToBase64String(hasher.ComputeHash(context.UserContext.Encoding.GetBytes(rawAnswer)));
}
}
}
View
116 Handlers/WebSocket/hybi10/WebSocketHandler.cs
@@ -42,153 +42,153 @@ public static WebSocketHandler Instance
{
get
{
- CreateLock.Wait();
+ _createLock.Wait();
if (_instance == null)
{
_instance = new WebSocketHandler();
}
- CreateLock.Release();
+ _createLock.Release();
return _instance;
}
}
/// <summary>
/// Handles the request.
/// </summary>
- /// <param name="AContext">The user context.</param>
- public override void HandleRequest(Context AContext)
+ /// <param name="context">The user context.</param>
+ public override void HandleRequest(Context context)
{
- if (AContext.IsSetup)
+ if (context.IsSetup)
{
- AContext.UserContext.DataFrame.Append(AContext.Buffer);
- if (AContext.UserContext.DataFrame.State == DataFrame.DataState.Complete)
+ context.UserContext.DataFrame.Append(context.Buffer);
+ if (context.UserContext.DataFrame.State == DataFrame.DataState.Complete)
{
- switch (AContext.UserContext.DataFrame.Length)
+ switch (context.UserContext.DataFrame.Length)
{
case 1:
//Process Command
- string ACommand = AContext.UserContext.DataFrame.ToString();
- if (ACommand == AContext.Server.PingCommand)
+ string command = context.UserContext.DataFrame.ToString();
+ if (command == context.Server.PingCommand)
{
- SendPingResponse(AContext);
- AContext.Pings++;
+ SendPingResponse(context);
+ context.Pings++;
}
else
{
- AContext.Pings = 0;
- AContext.UserContext.OnReceive();
+ context.Pings = 0;
+ context.UserContext.OnReceive();
}
- if ((AContext.Pings >= AContext.Server.MaxPingsInSequence) && (AContext.Server.MaxPingsInSequence != 0))
+ if ((context.Pings >= context.Server.MaxPingsInSequence) && (context.Server.MaxPingsInSequence != 0))
{
- AContext.Dispose();
+ context.Dispose();
}
break;
default:
- AContext.Pings = 0;
- AContext.UserContext.OnReceive();
+ context.Pings = 0;
+ context.UserContext.OnReceive();
break;
}
}
- else if (AContext.UserContext.DataFrame.State == DataFrame.DataState.Closed)
+ else if (context.UserContext.DataFrame.State == DataFrame.DataState.Closed)
{
- AContext.UserContext.Send(new byte[0], true);
+ context.UserContext.Send(new byte[0], true);
}
}
else
{
- Authenticate(AContext);
+ Authenticate(context);
}
}
/// <summary>
/// Attempts to authenticates the specified user context.
/// If authentication fails it kills the connection.
/// </summary>
- /// <param name="AContext">The user context.</param>
- private void Authenticate(Context AContext)
+ /// <param name="context">The user context.</param>
+ private void Authenticate(Context context)
{
- if (AContext.Handler.Authentication.CheckHandshake(AContext))
+ if (context.Handler.Authentication.CheckHandshake(context))
{
- AContext.UserContext.Protocol = AContext.Header.Protocol;
- AContext.UserContext.RequestPath = AContext.Header.RequestPath;
- AContext.Header = null;
- AContext.IsSetup = true;
+ context.UserContext.Protocol = context.Header.Protocol;
+ context.UserContext.RequestPath = context.Header.RequestPath;
+ context.Header = null;
+ context.IsSetup = true;
}
else
{
- AContext.Dispose();
+ context.Dispose();
}
}
/// <summary>
/// Sends the specified data.
/// </summary>
- /// <param name="Data">The data.</param>
- /// <param name="AContext">The user context.</param>
- /// <param name="Close">if set to <c>true</c> [close].</param>
- public override void Send(byte[] Data, Context AContext, bool Close = false)
+ /// <param name="data">The data.</param>
+ /// <param name="context">The user context.</param>
+ /// <param name="close">if set to <c>true</c> [close].</param>
+ public override void Send(byte[] data, Context context, bool close = false)
{
- byte[] WrappedData = AContext.UserContext.DataFrame.Wrap(Data);
- AsyncCallback ACallback = EndSend;
- if (Close)
- ACallback = EndSendAndClose;
- AContext.SendReady.Wait();
+ byte[] wrappedData = context.UserContext.DataFrame.Wrap(data);
+ AsyncCallback callback = EndSend;
+ if (close)
+ callback = EndSendAndClose;
+ context.SendReady.Wait();
try
{
- AContext.Connection.Client.BeginSend(WrappedData, 0, WrappedData.Length, SocketFlags.None, ACallback, AContext);
+ context.Connection.Client.BeginSend(wrappedData, 0, wrappedData.Length, SocketFlags.None, callback, context);
}
catch
{
- AContext.SendReady.Release();
+ context.SendReady.Release();
}
}
/// <summary>
/// Ends the send.
/// </summary>
- /// <param name="AResult">The Async result.</param>
- public override void EndSend(IAsyncResult AResult)
+ /// <param name="result">The Async result.</param>
+ public override void EndSend(IAsyncResult result)
{
- Context AContext = (Context)AResult.AsyncState;
+ Context context = (Context)result.AsyncState;
try
{
- AContext.Connection.Client.EndSend(AResult);
- AContext.SendReady.Release();
+ context.Connection.Client.EndSend(result);
+ context.SendReady.Release();
}
catch
{
- AContext.SendReady.Release();
+ context.SendReady.Release();
}
- AContext.UserContext.OnSend();
+ context.UserContext.OnSend();
}
/// <summary>
/// Ends the send and closes the connection.
/// </summary>
- /// <param name="AResult">The Async result.</param>
- public override void EndSendAndClose(IAsyncResult AResult)
+ /// <param name="result">The Async result.</param>
+ public override void EndSendAndClose(IAsyncResult result)
{
- Context AContext = (Context)AResult.AsyncState;
+ Context context = (Context)result.AsyncState;
try
{
- AContext.Connection.Client.EndSend(AResult);
- AContext.SendReady.Release();
+ context.Connection.Client.EndSend(result);
+ context.SendReady.Release();
}
catch
{
- AContext.SendReady.Release();
+ context.SendReady.Release();
}
- AContext.UserContext.OnSend();
- AContext.Dispose();
+ context.UserContext.OnSend();
+ context.Dispose();
}
/// <summary>
/// Sends the ping response.
/// </summary>
- /// <param name="AContext">The user context.</param>
- private void SendPingResponse(Context AContext)
+ /// <param name="context">The user context.</param>
+ private void SendPingResponse(Context context)
{
- AContext.UserContext.Send(AContext.Server.PongCommand);
+ context.UserContext.Send(context.Server.PongCommand);
}
}
}
View
2 TCPServer.cs
@@ -144,7 +144,7 @@ private void Listen(object State)
/// Executes in it's own thread.
/// Utilizes a semaphore(ReceiveReady) to limit the number of receive events active for this client to 1 at a time.
/// </summary>
- /// <param name="AResult">The A result.</param>
+ /// <param name="result">The A result.</param>
private void RunClient(IAsyncResult result)
{
TcpClient connection = null;
View
2 WSServer.cs
@@ -234,7 +234,7 @@ protected override void OnRunClient(TcpClient connection)
/// <summary>
/// The root receive event for each client. Executes in it's own thread.
/// </summary>
- /// <param name="AResult">The Async result.</param>
+ /// <param name="result">The Async result.</param>
private void DoReceive(IAsyncResult result)
{
Context context = (Context)result.AsyncState;

0 comments on commit 56c1994

Please sign in to comment.