Search in sources :

Example 1 with TrackerEntry

use of org.xmpp.jnodes.smack.TrackerEntry in project Openfire by igniterealtime.

the class JingleNodesComponent method handleIQGet.

@Override
protected IQ handleIQGet(IQ iq) throws Exception {
    final IQ reply = IQ.createResultIQ(iq);
    final Element element = iq.getChildElement();
    final String namespace = element.getNamespaceURI();
    if (JingleChannelIQ.NAME.equals(element.getName()) && JingleChannelIQ.NAMESPACE.equals(namespace) && UDP.equals(element.attributeValue(PROTOCOL))) {
        final Element childElement = iq.getChildElement().createCopy();
        final RelayChannel channel = plugin.createRelayChannel();
        if (channel != null) {
            childElement.addAttribute(HOST, plugin.getPublicIP());
            childElement.addAttribute(LOCAL_PORT, Integer.toString(channel.getPortA()));
            childElement.addAttribute(REMOTE_PORT, Integer.toString(channel.getPortB()));
            reply.setChildElement(childElement);
            Log.debug("Created relay channel {}:{}, {}:{}, {}:{}", new Object[] { HOST, plugin.getPublicIP(), LOCAL_PORT, Integer.toString(channel.getPortA()), REMOTE_PORT, Integer.toString(channel.getPortB()) });
        } else {
            reply.setError(PacketError.Condition.internal_server_error);
        }
        return reply;
    } else if (JingleTrackerIQ.NAME.equals(element.getName()) && JingleTrackerIQ.NAMESPACE.equals(namespace)) {
        final List<TrackerEntry> entries = new ArrayList<TrackerEntry>();
        entries.add(new TrackerEntry(TrackerEntry.Type.relay, TrackerEntry.Policy._roster, plugin.getServiceName() + "." + getDomain(), UDP));
        final String elements = getChildElementXML(entries);
        final Element e = DocumentHelper.parseText(elements).getRootElement();
        reply.setChildElement(e);
        return reply;
    }
    // feature not implemented.
    return null;
}
Also used : TrackerEntry(org.xmpp.jnodes.smack.TrackerEntry) Element(org.dom4j.Element) JingleChannelIQ(org.xmpp.jnodes.smack.JingleChannelIQ) JingleTrackerIQ(org.xmpp.jnodes.smack.JingleTrackerIQ) IQ(org.xmpp.packet.IQ) ArrayList(java.util.ArrayList) List(java.util.List) RelayChannel(org.xmpp.jnodes.RelayChannel)

Example 2 with TrackerEntry

use of org.xmpp.jnodes.smack.TrackerEntry in project Openfire by igniterealtime.

the class JingleNodesComponent method getChildElementXML.

public String getChildElementXML(final List<TrackerEntry> entries) {
    final StringBuilder str = new StringBuilder();
    str.append("<").append(JingleTrackerIQ.NAME).append(" xmlns='").append(JingleTrackerIQ.NAMESPACE).append("'>");
    for (final TrackerEntry entry : entries) {
        str.append("<").append(entry.getType().toString());
        str.append(" policy='").append(entry.getPolicy().toString()).append("'");
        str.append(" address='").append(entry.getJid()).append("'");
        str.append(" protocol='").append(entry.getProtocol()).append("'");
        if (entry.isVerified()) {
            str.append(" verified='").append(entry.isVerified()).append("'");
        }
        str.append("/>");
    }
    str.append("</").append(JingleTrackerIQ.NAME).append(">");
    return str.toString();
}
Also used : TrackerEntry(org.xmpp.jnodes.smack.TrackerEntry)

Aggregations

TrackerEntry (org.xmpp.jnodes.smack.TrackerEntry)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Element (org.dom4j.Element)1 RelayChannel (org.xmpp.jnodes.RelayChannel)1 JingleChannelIQ (org.xmpp.jnodes.smack.JingleChannelIQ)1 JingleTrackerIQ (org.xmpp.jnodes.smack.JingleTrackerIQ)1 IQ (org.xmpp.packet.IQ)1