forked from Olivine-Labs/Alchemy-Websockets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
338a26e
commit 80aeebd
Showing
2 changed files
with
97 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters