Skip to content

Commit

Permalink
Renamed stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
DorianGray committed Dec 17, 2011
1 parent 338a26e commit 80aeebd
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 97 deletions.
190 changes: 95 additions & 95 deletions APServer.cs → AccessPolicyServer.cs
Original file line number Diff line number Diff line change
@@ -1,96 +1,96 @@
/*
Copyright 2011 Olivine Labs, LLC.
http://www.olivinelabs.com
*/

/*
This file is part of Alchemy Websockets.
Alchemy Websockets is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Alchemy Websockets is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Alchemy Websockets. If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

namespace Alchemy.Server
{
/// <summary>
/// This is the Flash Access Policy Server
/// It manages sending the XML cross domain policy to flash socket clients over port 843.
/// See http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html for details.
/// </summary>
public class AccessPolicyServer : TcpServer, IDisposable
{
/// <summary>
/// The pre-formatted XML response.
/// </summary>
private const string Response =
"<cross-domain-policy>\r\n" +
"\t<allow-access-from domain=\"{0}\" to-ports=\"{1}\" />\r\n" +
"</cross-domain-policy>\r\n\0";

private readonly string _allowedHost = "localhost";
private readonly int _allowedPort = 80;

/// <summary>
/// Initializes a new instance of the <see cref="AccessPolicyServer"/> class.
/// </summary>
/// <param name="listenAddress">The listen address.</param>
/// <param name="originDomain">The origin domain.</param>
/// <param name="allowedPort">The allowed port.</param>
public AccessPolicyServer(IPAddress listenAddress, string originDomain, int allowedPort)
: base(843, listenAddress)
{
_allowedHost = "*";
if (originDomain != String.Empty)
{
_allowedHost = originDomain;
}

_allowedPort = allowedPort;
}

/// <summary>
/// Fires when a client connects.
/// </summary>
/// <param name="connection">The TCP Connection.</param>
protected override void OnRunClient(TcpClient connection)
{
try
{
connection.Client.Receive(new byte[32]);
SendResponse(connection);
connection.Client.Close();
}
// ReSharper disable EmptyGeneralCatchClause
catch
// ReSharper restore EmptyGeneralCatchClause
{
/* Ignore */
}
}

/// <summary>
/// Sends the response.
/// </summary>
/// <param name="connection">The TCP Connection.</param>
public void SendResponse(TcpClient connection)
{
connection.Client.Send(
Encoding.UTF8.GetBytes(String.Format(Response, _allowedHost, _allowedPort.ToString())));
}
}
/*
Copyright 2011 Olivine Labs, LLC.
http://www.olivinelabs.com
*/

/*
This file is part of Alchemy Websockets.
Alchemy Websockets is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Alchemy Websockets is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Alchemy Websockets. If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

namespace Alchemy.Server
{
/// <summary>
/// This is the Flash Access Policy Server
/// It manages sending the XML cross domain policy to flash socket clients over port 843.
/// See http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html for details.
/// </summary>
public class AccessPolicyServer : TcpServer, IDisposable
{
/// <summary>
/// The pre-formatted XML response.
/// </summary>
private const string Response =
"<cross-domain-policy>\r\n" +
"\t<allow-access-from domain=\"{0}\" to-ports=\"{1}\" />\r\n" +
"</cross-domain-policy>\r\n\0";

private readonly string _allowedHost = "localhost";
private readonly int _allowedPort = 80;

/// <summary>
/// Initializes a new instance of the <see cref="AccessPolicyServer"/> class.
/// </summary>
/// <param name="listenAddress">The listen address.</param>
/// <param name="originDomain">The origin domain.</param>
/// <param name="allowedPort">The allowed port.</param>
public AccessPolicyServer(IPAddress listenAddress, string originDomain, int allowedPort)
: base(843, listenAddress)
{
_allowedHost = "*";
if (originDomain != String.Empty)
{
_allowedHost = originDomain;
}

_allowedPort = allowedPort;
}

/// <summary>
/// Fires when a client connects.
/// </summary>
/// <param name="connection">The TCP Connection.</param>
protected override void OnRunClient(TcpClient connection)
{
try
{
connection.Client.Receive(new byte[32]);
SendResponse(connection);
connection.Client.Close();
}
// ReSharper disable EmptyGeneralCatchClause
catch
// ReSharper restore EmptyGeneralCatchClause
{
/* Ignore */
}
}

/// <summary>
/// Sends the response.
/// </summary>
/// <param name="connection">The TCP Connection.</param>
public void SendResponse(TcpClient connection)
{
connection.Client.Send(
Encoding.UTF8.GetBytes(String.Format(Response, _allowedHost, _allowedPort.ToString())));
}
}
}
4 changes: 2 additions & 2 deletions Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<Reference Include="System.XML" />
</ItemGroup>
<ItemGroup>
<Compile Include="APServer.cs" />
<Compile Include="AccessPolicyServer.cs" />
<Compile Include="Handlers\WebSocket\DataFrame.cs" />
<Compile Include="Handlers\WebSocket\hybi00\DataFrame.cs" />
<Compile Include="Handlers\WebSocket\hybi10\DataFrame.cs" />
Expand All @@ -58,7 +58,7 @@
<Compile Include="Handlers\WebSocket\hybi10\Handshakes.cs" />
<Compile Include="Handlers\WebSocket\hybi10\WebSocketHandler.cs" />
<Compile Include="Handlers\WebSocket\IWebSocketAuthentication.cs" />
<Compile Include="TCPServer.cs" />
<Compile Include="TcpServer.cs" />
<Compile Include="WebSocketServer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down

0 comments on commit 80aeebd

Please sign in to comment.