Search in sources :

Example 51 with IQ

use of org.xmpp.packet.IQ in project Openfire by igniterealtime.

the class BaseMUCTransport method sendRoomInfo.

/**
     * Sends information about a room as a response to a service discovery request.
     *
     * @param to JID we will be sending the response to.
     * @param roomjid JID of the room info was requested about.
     * @param room A MUCTransportRoom object containing information to return as a response.
     */
public void sendRoomInfo(JID to, JID roomjid, MUCTransportRoom room) {
    IQ request = getPendingRequest(to, roomjid, NameSpace.DISCO_INFO);
    if (request != null) {
        IQ result = IQ.createResultIQ(request);
        Element response = DocumentHelper.createElement(QName.get("query", NameSpace.DISCO_INFO));
        response.addElement("identity").addAttribute("category", "conference").addAttribute("type", "text").addAttribute("name", room.getName());
        response.addElement("feature").addAttribute("var", NameSpace.MUC);
        response.addElement("feature").addAttribute("var", NameSpace.DISCO_INFO);
        response.addElement("feature").addAttribute("var", NameSpace.DISCO_ITEMS);
        if (room.getPassword_protected()) {
            response.addElement("feature").addAttribute("var", "muc_passwordprotected");
        }
        if (room.getHidden()) {
            response.addElement("feature").addAttribute("var", "muc_hidden");
        }
        if (room.getTemporary()) {
            response.addElement("feature").addAttribute("var", "muc_temporary");
        }
        if (room.getOpen()) {
            response.addElement("feature").addAttribute("var", "muc_open");
        }
        if (!room.getModerated()) {
            response.addElement("feature").addAttribute("var", "muc_unmoderated");
        }
        if (!room.getAnonymous()) {
            response.addElement("feature").addAttribute("var", "muc_nonanonymous");
        }
        Element form = DocumentHelper.createElement(QName.get("x", NameSpace.XDATA));
        form.addAttribute("type", "result");
        form.addElement("field").addAttribute("var", "FORM_TYPE").addAttribute("type", "hidden").addElement("value").addCDATA("http://jabber.org/protocol/muc#roominfo");
        if (room.getContact() != null) {
            form.addElement("field").addAttribute("var", "muc#roominfo_contactjid").addAttribute("label", "Contact Addresses").addElement("value").addCDATA(room.getContact().toString());
        }
        if (room.getName() != null) {
            form.addElement("field").addAttribute("var", "muc#roominfo_description").addAttribute("label", "Short Description of Room").addElement("value").addCDATA(room.getName());
        }
        if (room.getLanguage() != null) {
            form.addElement("field").addAttribute("var", "muc#roominfo_lang").addAttribute("label", "Natural Language for Room Discussions").addElement("value").addCDATA(room.getLanguage());
        }
        if (room.getLog_location() != null) {
            form.addElement("field").addAttribute("var", "muc#roominfo_logs").addAttribute("label", "URL for Archived Discussion Logs").addElement("value").addCDATA(room.getLog_location());
        }
        if (room.getOccupant_count() != null) {
            form.addElement("field").addAttribute("var", "muc#roominfo_occupants").addAttribute("label", "Current Number of Occupants in Room").addElement("value").addCDATA(room.getOccupant_count().toString());
        }
        if (room.getTopic() != null) {
            form.addElement("field").addAttribute("var", "muc#roominfo_subject").addAttribute("label", "Current Subject or Discussion Topic in Room").addElement("value").addCDATA(room.getTopic());
        }
        response.add(form);
        result.setChildElement(response);
        this.sendPacket(result);
    }
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ)

Example 52 with IQ

use of org.xmpp.packet.IQ in project jitsi-videobridge by jitsi.

the class ComponentImpl method handleIQ.

/**
 * Handles an <tt>org.xmpp.packet.IQ</tt> stanza of type <tt>get</tt> or
 * <tt>set</tt> which represents a request. Converts the specified
 * <tt>org.xmpp.packet.IQ</tt> to an
 * <tt>org.jivesoftware.smack.packet.IQ</tt> stanza, handles the Smack
 * stanza via a call to {@link #handleIQ(org.jivesoftware.smack.packet.IQ)},
 * converts the result Smack stanza to an <tt>org.xmpp.packet.iQ</tt> which
 * is returned as the response to the request.
 *
 * @param iq the <tt>org.xmpp.packet.IQ</tt> stanza of type <tt>get</tt> or
 * <tt>set</tt> which represents the request to handle
 * @return an <tt>org.xmpp.packet.IQ</tt> stanza which represents the
 * response to the specified request or <tt>null</tt> to reply with
 * <tt>feature-not-implemented</tt>
 * @throws Exception to reply with <tt>internal-server-error</tt> to the
 * specified request
 */
private IQ handleIQ(IQ iq) throws Exception {
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("RECV: " + iq.toXML());
        }
        org.jivesoftware.smack.packet.IQ smackIQ = IQUtils.convert(iq);
        // Failed to convert to Smack IQ ?
        if (smackIQ == null) {
            if (iq.isRequest()) {
                IQ error = new IQ(IQ.Type.error, iq.getID());
                error.setFrom(iq.getTo());
                error.setTo(iq.getFrom());
                error.setError(new PacketError(PacketError.Condition.bad_request, PacketError.Type.modify, "Failed to parse incoming stanza"));
                return error;
            } else {
                logger.error("Failed to convert stanza: " + iq.toXML());
            }
        }
        org.jivesoftware.smack.packet.IQ resultSmackIQ = handleIQ(smackIQ);
        IQ resultIQ;
        if (resultSmackIQ == null) {
            resultIQ = null;
        } else {
            resultIQ = IQUtils.convert(resultSmackIQ);
            if (logger.isDebugEnabled()) {
                logger.debug("SENT: " + resultIQ.toXML());
            }
        }
        return resultIQ;
    } catch (Exception e) {
        logger.error("Failed to handle IQ with id=" + (iq == null ? "null" : iq.getID()), e);
        throw e;
    }
}
Also used : IQ(org.xmpp.packet.IQ) org.jivesoftware.smack.packet(org.jivesoftware.smack.packet) org.xmpp.packet(org.xmpp.packet)

Example 53 with IQ

use of org.xmpp.packet.IQ in project Openfire by igniterealtime.

the class InternalComponentManager method sendSoftwareVersion.

/**
 *  Send a SoftwareVersion request to the new component. If the component provides information
 *  then it will be added to the  session of current component.
 *
 * @param component the new component that was added to this manager.
 * @param componentJID the XMPP address of the new component.
 */
private void sendSoftwareVersion(Component component, JID componentJID) {
    // Build a "jabber:iq:version" request that will be sent to the component
    IQ iq = new IQ(IQ.Type.get);
    iq.setFrom(getAddress());
    iq.setTo(componentJID);
    iq.setChildElement("query", "jabber:iq:version");
    // Send the "jabber:iq:version" request to the component. The reply (if any) will be processed in
    // #process(Packet) or org.jivesoftware.openfire.net.ComponentStanzaHandler#rocessIQ(Packet)
    // sendPacket(component, iq);
    component.processPacket(iq);
}
Also used : IQ(org.xmpp.packet.IQ)

Example 54 with IQ

use of org.xmpp.packet.IQ in project Openfire by igniterealtime.

the class InternalComponentManager method query.

@Override
public IQ query(Component component, IQ packet, long timeout) throws ComponentException {
    final LinkedBlockingQueue<IQ> answer = new LinkedBlockingQueue<>(8);
    XMPPServer.getInstance().getIQRouter().addIQResultListener(packet.getID(), new IQResultListener() {

        @Override
        public void receivedAnswer(IQ packet) {
            answer.offer(packet);
        }

        @Override
        public void answerTimeout(String packetId) {
            Log.warn("An answer to a previously sent IQ stanza was never received. Packet id: " + packetId);
        }
    });
    sendPacket(component, packet);
    IQ reply = null;
    try {
        reply = answer.poll(timeout, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
    // Ignore
    }
    return reply;
}
Also used : IQ(org.xmpp.packet.IQ) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 55 with IQ

use of org.xmpp.packet.IQ in project Openfire by igniterealtime.

the class InternalComponentManager method leftCluster.

@Override
public void leftCluster() {
    // The local cluster node left the cluster.
    if (XMPPServer.getInstance().isShuttingDown()) {
        // Do not put effort in restoring the correct state if we're shutting down anyway.
        return;
    }
    // Upon leaving a cluster, clustered caches are reset to their local equivalent (by the swap from the clustered
    // cache implementation to the default cache implementation that's done in the implementation of
    // org.jivesoftware.util.cache.CacheFactory.leftCluster). This means that they now hold no data (as a new cache
    // has been created). Data that's available on the local node needs to be added again.
    restoreCacheContent();
    // Determine what components that we are broadcasting were available only on other
    // cluster nodes than the local one. For these, unavailability events need
    // to be sent out (eventing will be limited to the local node, as we're no longer
    // part of a cluster).
    final Iterator<Map.Entry<String, IQ>> iterator = componentInfo.entrySet().iterator();
    while (iterator.hasNext()) {
        // TODO: Iterating over the 'componentInfo' is not ideal, as there might be components for which there is no recorded data in 'componentInfo'. There currently is no other way to determine what components were active on the cluster though.
        final Map.Entry<String, IQ> entry = iterator.next();
        final JID domain = new JID(entry.getKey());
        if (!componentCache.containsKey(domain)) {
            Log.debug("The local cluster node left the cluster. The component '{}' was living on one (or more) other cluster nodes, and is no longer available. Invoking the 'component unregistered' event.", domain);
            notifyComponentUnregistered(domain);
            // Also clean up the cache of cluster-wide service discovery results.
            iterator.remove();
        }
    }
}
Also used : JID(org.xmpp.packet.JID) IQ(org.xmpp.packet.IQ) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

IQ (org.xmpp.packet.IQ)208 Element (org.dom4j.Element)141 JID (org.xmpp.packet.JID)49 PacketError (org.xmpp.packet.PacketError)35 Presence (org.xmpp.packet.Presence)19 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)18 Message (org.xmpp.packet.Message)17 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)16 ClientSession (org.jivesoftware.openfire.session.ClientSession)14 DataForm (org.xmpp.forms.DataForm)13 ArrayList (java.util.ArrayList)11 AgentNotFoundException (org.jivesoftware.xmpp.workgroup.AgentNotFoundException)10 Packet (org.xmpp.packet.Packet)10 PacketException (org.jivesoftware.openfire.PacketException)9 User (org.jivesoftware.openfire.user.User)8 List (java.util.List)7 PrivacyList (org.jivesoftware.openfire.privacy.PrivacyList)7 Iterator (java.util.Iterator)6 Test (org.junit.Test)6 FormField (org.xmpp.forms.FormField)6