Presence update problem from an external component

I’'m developing an external component for managing x10 devices. This component contains a few entites. for example, if the jid for the component is x10.some.jabber.server, then jids of contained entities are:

lamp@x10.some.jabber.server

sensor@x10.some.jabber.server, etc.

when these individual entity wants to update its presence, it sends out a presence stanza with no ‘‘to’’ address, which, according to the jabber protocol and if I understood correctly, will make the jabber server to broadcast the presence update to all subscribers.

However, this did not work for me. The warning I got is:

presence requested from server someserver by unknown user lamp@x10.someserver.

I looked at the wildfire source code that I just downloaded and found that codes right after this warning is commented out. Can someone please tell me how to broadcast presence from an external component?

BTW, I’'m copying the source code snippet for the reference.

=================================================

org.jivesoftware.wildfire.handler.PresenceUpdateHandler.java

=================================================

// Foreign updates will do a reverse lookup of entries in rosters

// on the server

Log.warn("Presence requested from server "

  • localServer.getServerInfo().getName()

  • " by unknown user: " + update.getFrom());

/*

Connection con = null;

PreparedStatement pstmt = null;

try {

pstmt = con.prepareStatement(GET_ROSTER_SUBS);

pstmt.setString(1, update.getSender().toBareString().toLowerCase());

ResultSet rs = pstmt.executeQuery();

while (rs.next()){

long userID = rs.getLong(1);

try {

User user = server.getUserManager().getUser(userID);

update.setRecipient(user.getAddress());

server.getSessionManager().userBroadcast(user.getUsername(),

update.getPacket());

} catch (UserNotFoundException e) {

Log.error(LocaleUtils.getLocalizedString(“admin.error”),e);

} catch (UnauthorizedException e) {

Log.error(LocaleUtils.getLocalizedString(“admin.error”),e);

}

}

}

catch (SQLException e) {

Log.error(LocaleUtils.getLocalizedString(“admin.error”),e);

}

*/

First, that’‘s super sweet that you’'re working on an X10 component. Are you going to support ad-hoc commands for each attached device?

Normally, the server will handle presence packets. However, it’‘s a different contract with components. A component is responsible for all traffic to and from. That’'s why you have to set the full JID on every packet.

Basically, the component should reply to presence probes and subscriptions. It could be something like the following:

private void processPresence(Presence presence) {

try {

if (Presence.Type.subscribe == presence.getType()) {

// Accept all presence requests if user has permissions

// Reply that the subscription request was approved or rejected

Presence reply = new Presence();

reply.setTo(presence.getFrom());

reply.setFrom(presence.getTo());

reply.setType(Presence.Type.subscribed);

getComponentManager().sendPacket(this, reply);

} else if (Presence.Type.unsubscribe == presence.getType()) {

// Send confirmation of unsubscription

Presence reply = new Presence();

reply.setTo(presence.getFrom());

reply.setFrom(presence.getTo());

reply.setType(Presence.Type.unsubscribed);

getComponentManager().sendPacket(this, reply);

} else if (Presence.Type.probe == presence.getType()) {

// Send that the service is available

Presence reply = new Presence();

reply.setTo(presence.getFrom());

reply.setFrom(presence.getTo());

getComponentManager().sendPacket(this, reply);

}

}

catch (ComponentException e) {

getComponentManager().getLog().error(e);

}

}

/code

The code above will need to change a bit of course. Will presence actually change for items? Or does everything just go online/offline when the component starts or stops?

Regards,

Matt

Thanks for the reply, Matt.

Yes indeed, we are going to support ad-hoc command. Back to the presence question, I realized that the component is responsible for every incoming and outgoing packet., and the component is able to handle individual presence subscription and probe. What I intended was to take advantage of the Jabber server broadcasting presence update if it has no ‘‘to’’ address. So let me rephrase my question, if the component sends out the following stanza,

does wildfire broadcast it to entities who have subscribed to the presence of sensor@x10.jabber.server? Or I have to add a to address for every subscriber and send it seperately?

To your end question, the presence will change to reflect the actual situation of x10 devices, for example, if I use an x10 remote controller to turn off a lamp, the component will send out a cooresponding presence update.

Thanks!

Hey slando,

slando wrote:

So let me rephrase my question, if the component sends out the following stanza,

<presence from=’‘sensor@x10.jabber.server’’ xml:lang=’‘en’’>chatno motion detected in the past minute

does wildfire broadcast it to entities who have subscribed to the presence of sensor@x10.jabber.server? Or I have to add a to address for every subscriber and send it seperately?

External components are much like remote servers. Roster management and presence management is something that each entity is responsible for. That means that Widfire is not tracking who is subscribed to the component. Therefore, Wildfire does not have the info to perform the presence broadcast operation. Wildfire will just pass packets sent to the external component and let the component handle it.

Regards,

– Gato

Gotcha. Thanks!