added client field to the remoting host class to identify the entity last requested.

tong [09-11-22 03:26]
added client field to the remoting host class to identify the entity last requested.
minor hx remoting fixes.
renamed HXR parsing utility class.
Filename
jabber/remoting/Connection.hx
jabber/remoting/Host.hx
xmpp/HXR.hx
xmpp/HaXe.hx
diff --git a/jabber/remoting/Connection.hx b/jabber/remoting/Connection.hx
index 2ce6e49..f4ae7c2 100644
--- a/jabber/remoting/Connection.hx
+++ b/jabber/remoting/Connection.hx
@@ -20,11 +20,13 @@ package jabber.remoting;
 import haxe.remoting.AsyncConnection;

 /**
-	haXe remoting connection over XMPP.
+	haXe remoting connection to a XMPP entity.<br/>
+	User Service Discovery to determine if an entity supports haXe-remoting.<br/>
 */
 class Connection implements AsyncConnection, implements Dynamic<AsyncConnection> {

-	public var target(default,null) : String;
+	/** JID of the entity requested */
+	public var target : String;
 	public var stream(default,null) : jabber.Stream;

 	var __error : Dynamic->Void;
@@ -44,21 +46,22 @@ class Connection implements AsyncConnection, implements Dynamic<AsyncConnection>
 	}

 	public function setErrorHandler( h : Dynamic->Void ) {
-		__error = h; //TODO
+		__error = h;
 	}

-	public function call( params : Array<Dynamic>, ?onResult : Dynamic -> Void ) {
+	/**
+	*/
+	public function call( params : Array<Dynamic>, ?onResult : Dynamic->Void ) {
 		var s = new haxe.Serializer();
 		s.serialize( __path );
 		s.serialize( params );
-		var iq = new xmpp.IQ( null, null, target );
-		iq.properties.push( xmpp.HaXe.create( s.toString() ) );
+		var iq = new xmpp.IQ( null, null, target, stream.jidstr );
+		iq.properties.push( xmpp.HXR.create( s.toString() ) );
 		var error = __error;
 		stream.sendIQ( iq, function(r) {
 			switch( r.type ) {
 			case result :
-				var x = r.x.toXml();
-				var v = x.firstChild().nodeValue;
+				var v = xmpp.HXR.getData( r.x.toXml() );
 				var ok = true;
 				var ret;
 				try {
@@ -72,15 +75,20 @@ class Connection implements AsyncConnection, implements Dynamic<AsyncConnection>
 					error( err );
 				}
 				if( ok && onResult != null )
-					onResult(ret);
+					onResult( ret );
 			case error :
 				var err = xmpp.Error.fromPacket( r );
 				error( err );
 			default :
+				#if JABBER DEBUG
+				trace( "Invalid remoting response type "+r.type );
+				#end
 			}
 		} );
 	}

+	/**
+	*/
 	public static function connect( stream : jabber.Stream, target : String ) {
 		return new Connection( stream, target, [], function(e) throw e );
 	}
diff --git a/jabber/remoting/Host.hx b/jabber/remoting/Host.hx
index c4bd065..1de7877 100644
--- a/jabber/remoting/Host.hx
+++ b/jabber/remoting/Host.hx
@@ -20,45 +20,50 @@ package jabber.remoting;
 import haxe.remoting.Context;

 /**
-	haXe/XMPP remoting host .
+	haXe/XMPP remoting host.<br/>
+	<a href="http://haxe.org/doc/remoting">haXe-remoting</a>
 */
 class Host {
-
+
+	/** Current/Last calling client JID */
+	public var client(default,null) : String;
+	public var ctx : Context;
 	public var stream(default,null) : jabber.Stream;
-
-	var ctx : Context;
-
-	public function new( stream : jabber.Stream, ctx :  haxe.remoting.Context ) {
+
+	public function new( stream : jabber.Stream, ctx : Context ) {
 		this.stream = stream;
 		this.ctx = ctx;
-		stream.features.add( xmpp.HaXe.XMLNS );
-		var f_type = new xmpp.filter.IQFilter( xmpp.HaXe.XMLNS );
-		stream.collect( [cast f_type], handleIQ, true );
+		stream.features.add( xmpp.HXR.XMLNS );
+		stream.collect( [cast new xmpp.filter.IQFilter( xmpp.HXR.XMLNS, null, xmpp.IQType.get )], handleIQ, true );
 	}

 	function handleIQ( iq : xmpp.IQ ) {
-		switch( iq.type ) {
-		case get :
-			var request = xmpp.HaXe.getData( iq.x.toXml() );
-			var response = processRequest( request, ctx );
-			var r = xmpp.IQ.createResult( iq );
-			r.properties.push( xmpp.HaXe.create( response ) );
-			stream.sendPacket( r );
-		default :
-			//TODO check error settings
-			var r = xmpp.IQ.createErrorResult( iq, [new xmpp.Error(xmpp.ErrorType.modify,null,xmpp.ErrorCondition.NOT_ACCEPTABLE)] );
-			stream.sendPacket( r );
-		}
+		client = iq.from;
+		var request = xmpp.HXR.getData( iq.x.toXml() );
+		var response = processRequest( request, ctx );
+		var r = xmpp.IQ.createResult( iq );
+		//TODO send empty result IQ (void)
+		r.properties.push( xmpp.HXR.create( response ) );
+		stream.sendPacket( r );
+		/*
+		//TODO check error settings
+		var r = xmpp.IQ.createErrorResult( iq, [new xmpp.Error(xmpp.ErrorType.modify,null,xmpp.ErrorCondition.NOT_ACCEPTABLE)] );
+		stream.sendPacket( r );
+		*/
 	}

-	public static function processRequest( requestData : String, ctx : Context ) : String {
+	/**
+	*/
+	public static function processRequest( data : String, ctx : Context ) : String {
 		try {
-			var u = new haxe.Unserializer( requestData );
+			var u = new haxe.Unserializer( data );
 			var path = u.unserialize();
+			//trace(path);
 			var args = u.unserialize();
-			var data = ctx.call( path, args );
+			//trace(args);
+			var d = ctx.call( path, args );
 			var s = new haxe.Serializer();
-			s.serialize( data );
+			s.serialize( d );
 			return "hxr"+s.toString();
 		} catch( e : Dynamic ) {
 			var s = new haxe.Serializer();
diff --git a/xmpp/HXR.hx b/xmpp/HXR.hx
new file mode 100644
index 0000000..d416a2f
--- /dev/null
+++ b/xmpp/HXR.hx
@@ -0,0 +1,22 @@
+package xmpp;
+
+/**
+	haXe/XMPP remoting extension parsing utilities.
+*/
+class HXR {
+
+	public static inline var XMLNS = "http://haxe.org/hxr";
+	//public static inline var XMLNS_CALL = XMLNS+"/call";
+	//public static inline var XMLNS_RESPONSE = XMLNS+"/response";
+
+	public static inline function create( ?data : String ) : Xml {
+		var x = xmpp.IQ.createQueryXml( XMLNS );
+		if( data != null ) x.addChild( Xml.createPCData( data ) );
+		return x;
+	}
+
+	public static inline function getData( x : Xml ) : String {
+		return x.firstChild().nodeValue;
+	}
+
+}
diff --git a/xmpp/HaXe.hx b/xmpp/HaXe.hx
deleted file mode 100644
index 1c2b5ea..0000000
--- a/xmpp/HaXe.hx
+++ /dev/null
@@ -1,17 +0,0 @@
-package xmpp;
-
-class HaXe {
-
-	public static inline var XMLNS = "http://haxe.org/remoting";
-
-	public static function create( ?data : String ) : Xml {
-		var x = xmpp.IQ.createQueryXml( XMLNS );
-		if( data != null ) x.addChild( Xml.createPCData( data ) );
-		return x;
-	}
-
-	public static inline function getData( x : Xml ) : String {
-		return x.firstChild().nodeValue;
-	}
-
-}
ViewGit