powered by Jive Software

Possible Roster.getEntry bug

Hello - the following code:

Roster roster = connection.getRoster();
Iterator i = roster.getEntries();
while( i.hasNext() )
{
     RosterEntry entry = (RosterEntry)i.next();
     RosterEntry test = roster.getEntry( entry.getUser() );
     if( test == null ) System.out.println( "Not found" );
}

Prints out “Not Found” for every one of my transports, who’'s jabber IDs are:

msn.jabber.hawkesnest.net/registered

icq.jabber.hawkesnest.net/registered

aim.jabber.hawkesnest.net/registered

Is this a bug, or am I doing it wrong?

Here’'s the problem - in Roster.java:

/**
     * Returns the roster entry associated with the given XMPP address or
     * <tt>null</tt> if the user is not an entry in the roster.
     *
     * @param user the XMPP address of the user (eg "jsmith@example.com").
     * @return the roster entry or <tt>null</tt> if it does not exist.
     */
    public RosterEntry getEntry(String user) {
        if (user == null) {
            return null;
        }
        // Roster entries never include a resource so remove the resource
        // if it''s a part of the XMPP address.
        user = StringUtils.parseBareAddress(user);
        synchronized (entries) {
            for (Iterator i=entries.iterator(); i.hasNext(); ) {
                RosterEntry entry = (RosterEntry)i.next();
                if (entry.getUser().equals(user)) {
                    return entry;
                }
            }
        }
        return null;
    }

“Roster entries never include a resource so remove the resource” is not always true. Possibly if( entry.getUser().indexOf( “@” ) < 0 ) then don’'t remove the resource.

Adam

Message was edited by: synic

Any word on this? Transports are usually stored in the roster like so: msn.jabber.razorsedge.org/registered. I don’'t think “registered” is considered a resource at all, because they are stored in the roster in every client like that. Using Roster.getUser() on that ID will never work.

Adam

Hey Adam,

First of all I want to make clear that I don’'t have any experience with gateways so this answer is purely based on the XMPP spec.

According to the JEP Gateway Interaction (JEP-100) the section url=http://www.jabber.org/jeps/jep-0100.html#addressingAddressing[/url] specifies that a gateway address should be a hostname only, and that hostname should not be supplemented with a resource identifier. According to http://www.jabber.org/ietf/draft-ietf-xmpp-core-24.html#addressing an address must be of the form: [ node “@” ] domain [ “/” resource ]. As you can see a “/” means that the address contains a resource identifier .

On the other hand, users of legacy IM services should include an @ (except for MSN users) and may include a resource. So a question that I have is what are you storing in your roster? The gateway’‘s address or an address of a legacy IM service’'s user?

In summary, IMHO the Roster.getEntry(String user) and StringUtils.parseBareAddress(String XMPPAddress) methods are correct. And it seems that the problem is within the gateway since it’'s returning an invalid address.

Regards,

– Gato

The gateways themselves are the ones that are having the trouble. When you register for them, they are added to your roster (all of them behave this way with no ‘’@’’ and a resource tacked on the end).

Once you have a gateway or transport added to your roster, you can then add buddies from these systems to your roster. If you have registered for msn.jabber.razorsedge.org/registerd, and you want to add an MSN user to your roster, you would add him as something like adamolsen%hotmail.com@msn.jabber.razorsedge.org to your roster. These buddies that you add are fine and work with Roster.getUser() - it’'s the gateways that have the problem.

I’'ll see if I can find more information on it.

Thanks Gato,

Adam

From what I can see in XMPP-IM section 7.1, any valid JID can be a part of the Roster.

If a valid address is in the form of [ node “@” ] domain [ “/” resource ] then the only part that is required to be a part of the JID is the domain, but the node and the resource can optionally be a part of it.

However - it does seem that the gateways currently are following an old JEP found here: http://www.jabber.org/old-docs/really-old/transport-1.0.html and they are in fact invalid for JEP-100.

So while the gateways aren’‘t exactly following the standards, it’'s still ok to have a JID with a resource in your Roster.

What do you think?

Adam Olsen

Adam,

From what I can see in XMPP-IM section 7.1, any valid

JID can be a part of the Roster.

I couldn’'t find any text that specifies that any valid JID can be part of a roster. However, I found this text in section 7.1 which says: “The “key” or unique identifier for each roster item is a JID, encapsulated in the ‘‘jid’’ attribute of the element (which is REQUIRED). The value of the ‘‘jid’’ attribute SHOULD be of the form user@domain if the item is associated with another (human) instant messaging user.”

Unfortunately, the spec does not specify the valid form of a JID for items not associated with (human) instant messaging user. Although, we can say, in some way, that a gateway is some kind of IM user.

Could you provide me the exact text where you read/understood your statement?

Thanks,

– Gato

In the terminalogy section of most JEPs they refer to the rfc standards (http://www.ietf.org/rfc/rfc2119.txt) for all caps words like SHOULD - which shows that it doesn’'t exactly have to be user@domain in all cases, though it is “recommended”.

Adam

Adam,

Very good point! The subtlety of the word “should”…this conversation has turned into a lawyers conversation.

So according to this interpretation of section 7.1 we “should” allow to store any valid JID in the roster. Let me think a little more on this and I’'ll be back to you later.

Thanks,

– Gato

Adam,

I created a bug issue with this problem for the next release.

Thanks,

– Gato

Thanks a bunch!