How to add a plug in to WildFire?

Hi,

I would like to add a “component/plug in” to wildfire that will respond to some

“IQ” request I do.

By exemple, I use my own namespace

and wildfire should be able to respond to this special and custom IQ message with a iq response.

So, … how can I do a plug in like this ?

Thanks for your help

Hi cdemez,

A good starting point would be to look at the “Implementing Your Plugin” section of the Wildfire Plugin Guide[/url]. It shows you how to register a plugin as an IQHandler.

Hope that helps,

Ryan

Hi,

Thanks for your answer… I have start to write the plug in, but have some problems to continue…

I have add an IqHandler but :

1 - I need to filter the IQ packet by namespace. But how ?

2 - How can I know the IP of the socket that receive this IQ message ?

3 - I want to send back the IQ message to the sender. But how ?

Please, can you advice ?

Here is my current code :


package com.ufoz

import org.jivesoftware.wildfire.container.Plugin;

import org.jivesoftware.wildfire.container.PluginManager;

import java.io.File;

/**

  • This plug in allow to send back the external IP.

  • When we send a message behind a router/firewall, we only know our “internal ip” (192…)

  • But with this plug in, we can discover our IP as seen by external softwares.

*/

public class ExternalIPPlugin implements Plugin

{

public void initializePlugin(PluginManager manager, File pluginDirectory)

{

IQHandler iqHandler = new ExternalIPIQHandler();

IQRouter iqRouter = XMPPServer.getInstance().getIQRouter();

iqRouter.addHandler( iqHandler );

}

public void destroyPlugin()

{

IQRouter iqRouter = XMPPServer.getInstance().getIQRouter();

iqRouter.removeHandler( iqHandler );

}

}

public class ExternalIPIQHandler implements IQHandler

{

public IQ handleIQ(IQ packet) throws UnauthorizedException

{

//---- 1. Get the IP that produce this IQ packet

//---- 2. Send back an IQ packet that contains this IP

}

}

Hi cdemez,

If you look at the url=http://www.jivesoftware.org/builds/wildfire/docs/latest/documentation/javado cjavadocs[/url] you’‘ll see a number of classes that implement the IQHandler interface, which you can then look at to see how to handle namespaces and the routing of packets back to sender; I’‘d look at the IQVersionHandler class first, since it’'s pretty simple, paying particular attention to the handleIQ and getInfo methods.

In order to get the ip address, you could do something like the following in your handleIQ method:

String address = XMPPServer.getInstance().getSessionManager().getSession(packet.getFrom()).getCo nnection().getInetAddress().getHostAddress();

/code

Hope that helps,

Ryan

Thanks a lot…

I will try this

Greaaattttttttttttt