powered by Jive Software

Looking for a simple working XIFF 3.0 example

I’‘m trying to login to a Jabber server with XIFF, but I’'m only getting a connect followed by a disconnect event. Is there something wrong in the following code?

trace(Security.sandboxType );

import org.jivesoftware.xiff.core.XMPPConnection;

var connection : XMPPConnection = new XMPPConnection();

connection.username = “user”;

connection.password = “secret”;

connection.server = “localhost”;

connection.connect();

Here is what my working code looks like:

// connect to the jabber server

public function connect( host:String, username:String, password:String ) : void {

try {

connection.username = username;

connection.password = password;

connection.server = host;

connection.addEventListener(LoginEvent.LOGIN, eventHandler);

connection.addEventListener(IncomingDataEvent.INCOMING_DATA, eventHandler);

connection.addEventListener(OutgoingDataEvent.OUTGOING_DATA, eventHandler);

connection.addEventListener(MessageEvent.MESSAGE, onMessageHandler);

var result:Boolean = connection.connect(’‘flash’’);

}
catch (errObject:Error) {

logger.append(logger.MESSAGETYPE_ERROR, errObject.message);

}
}

// primary event handler, just logging for now
private function eventHandler ( eventObj:Object ) : void {

try {

switch( eventObj.type ) {

case “outgoingData”:

logger.append(logger.MESSAGETYPE_INFO, eventObj.type + ‘’: ‘’ + eventObj.data);

break;

case “incomingData”:

logger.append(logger.MESSAGETYPE_INFO, eventObj.type + ‘’: ‘’ + eventObj.data);

break;

case “login”:

logger.append(logger.MESSAGETYPE_INFO, eventObj.type);

break;

}
}
catch (errObject:Error) {

logger.append(logger.MESSAGETYPE_ERROR, errObject.message);

}

}

You may also need to add a roster to the connection:

roster = new Roster(connection);

You can attach event handlers to the roster and the connection for presence:

connection.addEventListener(PresenceEvent.PRESENCE, thisRosterCollection.presenceEventHandler);

roster.addEventListener(RosterEvent.USER_ADDED, thisRosterCollection.rosterEventHandler);

Message was edited by: cseibert

Message was edited by: cseibert

That doesn’‘t work for me with ejabberd. First ejabberd does not support the non-compliant XMPPConnection (XMLSocket) and “flash”, “flashTerminated” and “standardTerminated”. But even with XMPPSocketConnection (“standard”) I’‘m not able to login. It seems that ejabberd and Xiff don’‘t agree about the authentication, but I’'m not a XMPP expert:

(Trace) Security Sandbox: localTrusted

(Trace) Connection Result: true

(Trace) outgoingData:

(Trace) error: 503 - service-unavailable

I had to change line 108 in XMPPSocketConnection.as from

openingStreamTag = “<?xml version=\"1.0\"?><stream:stream to=”" + server + “” xmlns=“jabber:client” xmlns:stream=“http://etherx.jabber.org/streams” version=“1.0”>";

to

openingStreamTag = “<?xml version=\"1.0\"?><stream:stream to=”" + server + “” xmlns=“jabber:client” xmlns:stream="http://etherx.jabber.org/streams">";

(removed version=“1.0” at the end of the line)

Bug in XIFF or ejabberd?

Oli, I don’‘t know if it’‘s a bug, I had to do exactly the same thing to get ejabberd to work with XIFF 3. I did a bit of digging and found that the rfc’‘s for session initialisation in xmpp http://www.xmpp.org/rfcs/rfc3921.html#session include the version=1.0 that is causing ejabberd to fail when XIFF talks to it. So it would appear that XIFF is complying here and ejabberd and XIFF don’'t play nice together. Not technical, kind of inconclusive, but the best I have for you.

Message was edited by: simba because I couldn’'t figure out how the linking worked!

Message was edited by: simba (again)

With version=1.0 the XIFF client tells the server that it understands XMPP 1.0. Unfortunately it seems that XIFF is not XMPP 1.0 compliant, otherwise it should understand the response from ejabberd.

XIFF wants only understands Non-SASL authentication, but asks the server to try SASL and gets confused.

see http://www.xmpp.org/extensions/xep-0078.html

I would call it a XIFF bug.

(That’'s how I understand it, but I could be wrong)

That’'s how I understand it, too.

Now I’'m coming to the conclusion that the XIFF library is neat, but 3 key problems make me consider looking at alternatives to building a jabber interface in flash/ flex:

  1. no SASL

  2. no TLS

the above could possibly be fixed with a proxy but my view is that once you get into having to create a (python/perl) proxy to enable SASL/ TLS, you might as well do the whole thing in python/perl so I didn’'t investigate that too hard.

  1. cross-domain sandbox security in swfs can prevent access to jabber services not hosted on the swf’'s domain

So as I see it, XIFF and Flash/ Flex are good if you want a sweet user interface to a jabber server located on your own network/ servers. It’'s not so good if, like me, you want to create a standalone swf to interface with 3rd party or cross domain jabber servers such as google talk.

I’'d love to be proved wrong on any/ all of the above 3 points though.

  1. no SASL

this could be added to XIFF. as3xmpp supports SASL (I have not tested it)

  1. no TLS

I think it’'s not possible to encrypt the channel in Flash (without writing a SSL implementation in Flash). You have to use HTTP Binding (BOSH).

  1. cross-domain sandbox security

What do you mean with standalone swf?

thanks, that was really useful stuff.

oli wrote:

1."as3xmpp supports SASL -

I’‘d forgotten about this. I downloaded as3xmpp ages ago from a link on Daniel Dura’‘s site and must’‘ve got a duff version because the authentication script was incomplete (or, at least, I couldn’‘t make it work). As a result, I abandoned it in favour of XIFF and haven’‘t looked at as3xmpp again since. I’‘ll certainly be having another look now it’'s on google code.

oli wrote:

You have to use HTTP Binding (BOSH)

ok, I didn’‘t know about this and shall investigate. if you’‘ve got any links you think would be useful, that’'d be great

oli wrote:

What do you mean standalone swf?

“standalone” was a poor choice of word. All I meant was a swf hosted on a different network/ server to the jabber host. Sorry for the confusion.

Thanks again

Message was edited by: simba

Message was edited by: simba (one more time!)

found the bosh stuff very useful

Message was edited by: simba