Browse Source

added 'domains' and policy-file-request handling

Nicolas Cannasse 16 years ago
parent
commit
fb9fcfa229
2 changed files with 26 additions and 6 deletions
  1. 1 0
      doc/CHANGES.txt
  2. 25 6
      std/neko/net/ThreadRemotingServer.hx

+ 1 - 0
doc/CHANGES.txt

@@ -31,6 +31,7 @@ TODO :
 	compiler : added TClosure - optimize closure creation and ease code generation
 	cpp : added CPP platform
 	all : added 'using' syntax
+	neko : added 'domains' optional param to ThreadRemotingServer to answer policy-file-request
 
 2009-03-22: 2.03
 	optimized Type.enumEq : use index instead of tag comparison for neko/flash9/php

+ 25 - 6
std/neko/net/ThreadRemotingServer.hx

@@ -26,9 +26,13 @@ package neko.net;
 
 class ThreadRemotingServer extends ThreadServer<haxe.remoting.SocketConnection,String> {
 
-	public function new() {
+	var domains : Array<String>;
+	var port : Int;
+
+	public function new( ?domains ) {
 		super();
 		messageHeaderSize = 2;
+		this.domains = domains;
 	}
 
 	public dynamic function initClientApi( cnx : haxe.remoting.SocketConnection, ctx : haxe.remoting.Context ) {
@@ -39,6 +43,19 @@ class ThreadRemotingServer extends ThreadServer<haxe.remoting.SocketConnection,S
 		throw "Unhandled XML data '"+data+"'";
 	}
 
+	public dynamic function makePolicyFile() {
+		var str = "<cross-domain-policy>";
+		for( d in domains )
+			str += '<allow-access-from domain="'+d+'" to-ports="'+port+'"/>';
+		str += "</cross-domain-policy>";
+		return str;
+	}
+
+	public override function run( host, port ) {
+		this.port = port;
+		super.run(host,port);
+	}
+
 	public override function clientConnected( s : neko.net.Socket ) {
 		var ctx = new haxe.remoting.Context();
 		var cnx = haxe.remoting.SocketConnection.create(s,ctx);
@@ -82,12 +99,14 @@ class ThreadRemotingServer extends ThreadServer<haxe.remoting.SocketConnection,S
 	}
 
 	public override function clientMessage( cnx : haxe.remoting.SocketConnection, msg : String ) {
-		if( msg.charCodeAt(0) == 60 ) {
-			onXml(cnx,msg);
-			return;
-		}
 		try {
-			cnx.processMessage(msg);
+			if( msg.charCodeAt(0) == 60 ) {
+				if( domains != null && msg == "<policy-file-request/>" )
+					cnx.getProtocol().socket.write(makePolicyFile()+"\x00");
+				else
+					onXml(cnx,msg);
+			} else
+				cnx.processMessage(msg);
 		} catch( e : Dynamic ) {
 			if( !Std.is(e,haxe.io.Eof) && !Std.is(e,haxe.io.Error) )
 				logError(e);