powered by Jive Software

Adding features through a plugin?

We have developed some custom functionality. I need to be able to inform the client if the custom features are enabled or not. The approach we are investigating is to add information to the result of a disco#info query.

I’‘d like to be able to add another to the reply packet. I’'ve tried to write a plugin by using the source available in the Search plugin. My first attempt looked like this:

IQ replyPacket = IQ.createResultIQ(packet);
Element responseElement = DocumentHelper.createElement(QName.get("query", "http://jabber.org/protocol/disco#info"));                                       responseElement.addElement("feature").addAttribute("var", "some:feature:name"); replyPacket.setChildElement(responseElement); componentManager.sendPacket(this, replyPacket);

This, of course, resulted in a packet being returned that only contains my feature. After looking at the Javadoc for IQ.createResultIQ(), I understand why this happens.

So, I tried this next:

Element child = packet.getChildElement();
child.addElement("feature").addAttribute("var", "some:feature:name");
                   componentManager.sendPacket(this, packet);

This code never returns a result from the server, and my client gets disconnected.

Can anybody help? It seems that what I’‘m trying to do shouldn’‘t be that difficult, but I’'m obviously missing something.

Thanks!

Hi iamthechad,

Are you adding you child element to the packet before sending it? i.e.:

Element child = packet.getChildElement();
child.addElement("feature").addAttribute("var", "some:feature:name"); packet.setChildElement(child); //<-- new stuff componentManager.sendPacket(this, packet);

~Ryan

Ryan,

Yeah. I’'ve actually tried it both ways, with the same results.

Chad

Hi Chat,

When I was working on the search plugin I remember having the same disconnect issue you’‘re seeing. Which client are you using? Some clients (jajc is the one I most remeber) wouldn’'t work properly unless you added an “identity” element with all the proper attributes.

Hope that helps,

Ryan

Hey guys,

To add to Ryan’'s comment, the disco spec specifies that an identity element MUST be included in the disco#info response. So make sure that you are providing at least one identity and at least one feature.

Regards,

– Gato

I’‘m currently using Psi as a standalone client, but we’'re developing a client embedded in some existing software using the Smack API.

Gato,

This seems to be what is happening. It looks like my plugin is causing everything to be stripped from the response packet.

What I really want to do is append some information of my own to the results that would normally be returned from the disco#info query. Specifically, I need to add a feature entry and possibly a data form.

Thanks

Chad

Hey Chad,

From your code I see that you are creating a new component. When using components the server will route all packets to the component whose domain matches the component’‘s subdomain. That implies that the component is now responsible for answering the whole disco request. Therefore, you cannot append your information to the server’'s response since the server will not respond that disco request packet.

Hope that helps.

Regards,

– Gato

Gato,

I was afraid this would be the case. Is there anyway I can write a plugin to append information to a disco#info respose, or am I going to have to get creative?

Thanks

Chad

Hey Chad,

Currently the server features list is unmodifiable. We will need to do two modifications if you need to “advertise” your functionality as a server feature. But if you are writing a component then you can handle the disco#info (identity and features) yourself. That means that the component will be in charge of building the whole disco#info response.

I will create a Jira issue to make “server features” more dynamic but that feature will be available with JM 2.2.

Regards,

– Gato