/// <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)
 {
     if (AContext.Handler.Authentication.CheckHandshake(AContext))
     {
         AContext.UserContext.Protocol = AContext.Header.Protocol;
         AContext.UserContext.RequestPath = AContext.Header.RequestPath;
         AContext.Header = null;
         AContext.IsSetup = true;
     }
     else
     {
         AContext.Dispose();
     }
 }
 /// <summary>
 /// Handles the request.
 /// </summary>
 /// <param name="AContext">The user context.</param>
 public override void HandleRequest(Context AContext)
 {
     if (AContext.IsSetup)
     {
         AContext.UserContext.DataFrame.Append(AContext.Buffer);
         if (AContext.UserContext.DataFrame.State == DataFrame.DataState.Complete)
         {
             switch (AContext.UserContext.DataFrame.Length)
             {
                 case 1:
                     //Process Command
                     string ACommand = AContext.UserContext.DataFrame.ToString();
                     if (ACommand == AContext.Server.PingCommand)
                     {
                         SendPingResponse(AContext);
                         AContext.Pings++;
                     }
                     else
                     {
                         AContext.Pings = 0;
                         AContext.UserContext.OnReceive();
                     }
                     if ((AContext.Pings >= AContext.Server.MaxPingsInSequence) && (AContext.Server.MaxPingsInSequence != 0))
                     {
                         AContext.Dispose();
                     }
                     break;
                 default:
                     AContext.Pings = 0;
                     AContext.UserContext.OnReceive();
                     break;
             }
         }
         else if (AContext.UserContext.DataFrame.State == DataFrame.DataState.Closed)
         {
             AContext.UserContext.Send(new byte[0], true);
         }
     }
     else
     {
         Authenticate(AContext);
     }
 }
 /// <summary>
 /// Processes the header.
 /// </summary>
 /// <param name="context">The user context.</param>
 public void ProcessHeader(Context context)
 {
     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")
     {
         try
         {
             //if it is, we access the Access Policy Server instance to send the appropriate response.
             context.Server.AccessPolicyServer.SendResponse(context.Connection);
         }
         catch { }
         context.Dispose();
     }
     else//If it isn't, process http/websocket header as normal.
     {
         context.Header = new Header(data);
         switch (context.Header.Protocol)
         {
             case Protocol.WebSocketHybi00:
                 context.Handler = Alchemy.Server.Handlers.WebSocket.hybi00.WebSocketHandler.Instance;
                 context.UserContext.DataFrame = new Alchemy.Server.Handlers.WebSocket.hybi00.DataFrame();
                 break;
             case Protocol.WebSocketHybi10:
                 context.Handler = Alchemy.Server.Handlers.WebSocket.hybi10.WebSocketHandler.Instance;
                 context.UserContext.DataFrame = new Alchemy.Server.Handlers.WebSocket.hybi10.DataFrame();
                 break;
             case Protocol.FlashSocket:
                 context.Handler = Alchemy.Server.Handlers.WebSocket.hybi00.WebSocketHandler.Instance;
                 context.UserContext.DataFrame = new Alchemy.Server.Handlers.WebSocket.hybi00.DataFrame();
                 break;
             default:
                 context.Header.Protocol = Protocol.None;
                 break;
         }
         if (context.Header.Protocol != Protocol.None)
         {
             context.Handler.HandleRequest(context);
         }
         else
         {
             context.UserContext.Send(Response.NotImplemented, true);
         }
     }
 }
Example #4
0
 /// <summary>
 /// Handles the initial request.
 /// 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)
 {
     if (AContext.IsSetup)
     {
         AContext.Dispose();
     }
     else
     {
         ProcessHeader(AContext);
     }
 }
 /// <summary>
 /// Attempts to authenticates the specified user context.
 /// If authentication fails it kills the connection.
 /// </summary>
 /// <param name="context">The user context.</param>
 private static void Authenticate(Context context)
 {
     if (context.Handler.Authentication.CheckHandshake(context))
     {
         context.UserContext.Protocol = context.Header.Protocol;
         context.UserContext.RequestPath = context.Header.RequestPath;
         context.Header = null;
         context.IsSetup = true;
     }
     else
     {
         context.Dispose();
     }
 }