Search in sources :

Example 26 with IQ

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

the class BroadcastPlugin method processIQ.

private void processIQ(IQ iq, boolean targetAll, Group group, boolean canProceed) {
    IQ reply = IQ.createResultIQ(iq);
    Element childElement = iq.getChildElement();
    String namespace = childElement.getNamespaceURI();
    Element childElementCopy = iq.getChildElement().createCopy();
    reply.setChildElement(childElementCopy);
    if ("http://jabber.org/protocol/disco#info".equals(namespace)) {
        if (iq.getTo().getNode() == null) {
            // Return service identity and features
            Element identity = childElementCopy.addElement("identity");
            identity.addAttribute("category", "component");
            identity.addAttribute("type", "generic");
            identity.addAttribute("name", "Broadcast service");
            childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#info");
            childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#items");
        } else {
            if (targetAll) {
                // Return identity and features of the "all" group
                Element identity = childElementCopy.addElement("identity");
                identity.addAttribute("category", "component");
                identity.addAttribute("type", "generic");
                identity.addAttribute("name", "Broadcast all connected users");
                childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#info");
            } else if (group != null && canProceed) {
                // Return identity and features of the "all" group
                Element identity = childElementCopy.addElement("identity");
                identity.addAttribute("category", "component");
                identity.addAttribute("type", "generic");
                identity.addAttribute("name", "Broadcast " + group.getName());
                childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#info");
            } else {
                // Group not found or not allowed to use that group so
                // answer item_not_found error
                reply.setError(PacketError.Condition.item_not_found);
            }
        }
    } else if ("http://jabber.org/protocol/disco#items".equals(namespace)) {
        if (iq.getTo().getNode() == null) {
            // Return the list of groups hosted by the service that can be used by the user
            Collection<Group> groups;
            JID address = new JID(iq.getFrom().toBareJID());
            if (allowedUsers.contains(address)) {
                groups = groupManager.getGroups();
            } else {
                groups = groupManager.getGroups(iq.getFrom());
            }
            for (Group userGroup : groups) {
                try {
                    JID groupJID = new JID(userGroup.getName() + "@" + serviceName + "." + componentManager.getServerName());
                    childElementCopy.addElement("item").addAttribute("jid", groupJID.toString());
                } catch (Exception e) {
                // Group name is not valid to be used as a JID
                }
            }
            if (allowedUsers.isEmpty() || allowedUsers.contains(address)) {
                // Add the "all" group to the list
                childElementCopy.addElement("item").addAttribute("jid", "all@" + serviceName + "." + componentManager.getServerName());
            }
        }
    } else {
        // Answer an error since the server can't handle the requested namespace
        reply.setError(PacketError.Condition.service_unavailable);
    }
    try {
        componentManager.sendPacket(this, reply);
    } catch (Exception e) {
        Log.error(e.getMessage(), e);
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) Collection(java.util.Collection) ComponentException(org.xmpp.component.ComponentException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 27 with IQ

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

the class BroadcastPlugin method processPacket.

public void processPacket(Packet packet) {
    boolean canProceed = false;
    Group group = null;
    String toNode = packet.getTo().getNode();
    // Check if user is allowed to send packet to this service[+group]
    boolean targetAll = "all".equals(toNode);
    if (targetAll) {
        // See if the user is allowed to send the packet.
        JID address = new JID(packet.getFrom().toBareJID());
        if (allowedUsers.isEmpty() || allowedUsers.contains(address)) {
            canProceed = true;
        }
    } else {
        try {
            if (toNode != null) {
                group = groupManager.getGroup(toNode);
                boolean isGroupUser = group.isUser(packet.getFrom()) || group.isUser(new JID(packet.getFrom().toBareJID()));
                if (disableGroupPermissions || (groupMembersAllowed && isGroupUser) || allowedUsers.contains(new JID(packet.getFrom().toBareJID()))) {
                    canProceed = true;
                }
            }
        } catch (GroupNotFoundException e) {
        // Ignore.
        }
    }
    if (packet instanceof Message) {
        // Respond to incoming messages
        Message message = (Message) packet;
        processMessage(message, targetAll, group, canProceed);
    } else if (packet instanceof Presence) {
        // Respond to presence subscription request or presence probe
        Presence presence = (Presence) packet;
        processPresence(canProceed, presence);
    } else if (packet instanceof IQ) {
        // Handle disco packets
        IQ iq = (IQ) packet;
        // Ignore IQs of type ERROR or RESULT
        if (IQ.Type.error == iq.getType() || IQ.Type.result == iq.getType()) {
            return;
        }
        processIQ(iq, targetAll, group, canProceed);
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID) Message(org.xmpp.packet.Message) IQ(org.xmpp.packet.IQ) Presence(org.xmpp.packet.Presence) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 28 with IQ

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

the class SparkManager method processPacket.

/**
     * Client features are detected using Service Discovery, allowing
     * for ease of use within the client.  When a client "discovers" the
     * manager, they can query for related features within that discovered item.
     *
     * @param packet the packet
     */
public void processPacket(Packet packet) {
    if (packet instanceof IQ) {
        IQ iqPacket = (IQ) packet;
        Element childElement = (iqPacket).getChildElement();
        String namespace = null;
        if (childElement != null) {
            namespace = childElement.getNamespaceURI();
        }
        if (IQ.Type.get == iqPacket.getType()) {
            // Handle any disco info requests.
            if ("http://jabber.org/protocol/disco#info".equals(namespace)) {
                handleDiscoInfo(iqPacket);
            } else // Handle any disco item requests.
            if ("http://jabber.org/protocol/disco#items".equals(namespace)) {
                handleDiscoItems(iqPacket);
            } else if ("jabber:iq:version".equals(namespace)) {
                IQ reply = IQ.createResultIQ(iqPacket);
                Element version = reply.setChildElement("query", "jabber:iq:version");
                version.addElement("name").setText("Client Control Manager");
                version.addElement("version").setText("3.5");
                sendPacket(reply);
            } else {
                // Return error since this is an unknown service request
                IQ reply = IQ.createResultIQ(iqPacket);
                reply.setError(PacketError.Condition.service_unavailable);
                sendPacket(reply);
            }
        } else if (IQ.Type.error == iqPacket.getType() || IQ.Type.result == iqPacket.getType()) {
            if ("jabber:iq:version".equals(namespace)) {
                handleClientVersion(iqPacket);
            }
        } else {
            // Return error since this is an unknown service request
            IQ reply = IQ.createResultIQ(iqPacket);
            reply.setError(PacketError.Condition.service_unavailable);
            sendPacket(reply);
        }
    }
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ)

Example 29 with IQ

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

the class LocalOutgoingServerSession method returnErrorToSender.

private void returnErrorToSender(Packet packet) {
    RoutingTable routingTable = XMPPServer.getInstance().getRoutingTable();
    if (packet.getError() != null) {
        Log.debug("Possible double bounce: " + packet.toXML());
    }
    try {
        if (packet instanceof IQ) {
            if (((IQ) packet).isResponse()) {
                Log.debug("XMPP specs forbid us to respond with an IQ error to: " + packet.toXML());
                return;
            }
            IQ reply = new IQ();
            reply.setID(packet.getID());
            reply.setTo(packet.getFrom());
            reply.setFrom(packet.getTo());
            reply.setChildElement(((IQ) packet).getChildElement().createCopy());
            reply.setType(IQ.Type.error);
            reply.setError(PacketError.Condition.remote_server_not_found);
            routingTable.routePacket(reply.getTo(), reply, true);
        } else if (packet instanceof Presence) {
            if (((Presence) packet).getType() == Presence.Type.error) {
                Log.debug("Double-bounce of presence: " + packet.toXML());
                return;
            }
            Presence reply = new Presence();
            reply.setID(packet.getID());
            reply.setTo(packet.getFrom());
            reply.setFrom(packet.getTo());
            reply.setType(Presence.Type.error);
            reply.setError(PacketError.Condition.remote_server_not_found);
            routingTable.routePacket(reply.getTo(), reply, true);
        } else if (packet instanceof Message) {
            if (((Message) packet).getType() == Message.Type.error) {
                Log.debug("Double-bounce of message: " + packet.toXML());
                return;
            }
            Message reply = new Message();
            reply.setID(packet.getID());
            reply.setTo(packet.getFrom());
            reply.setFrom(packet.getTo());
            reply.setType(Message.Type.error);
            reply.setThread(((Message) packet).getThread());
            reply.setError(PacketError.Condition.remote_server_not_found);
            routingTable.routePacket(reply.getTo(), reply, true);
        }
    } catch (Exception e) {
        Log.error("Error returning error to sender. Original packet: " + packet, e);
    }
}
Also used : RoutingTable(org.jivesoftware.openfire.RoutingTable) Message(org.xmpp.packet.Message) IQ(org.xmpp.packet.IQ) Presence(org.xmpp.packet.Presence) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) DocumentException(org.dom4j.DocumentException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 30 with IQ

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

the class Workgroup method processInvitation.

public void processInvitation(InvitationRequest invitation, IQ packet) {
    IQ reply = IQ.createResultIQ(packet);
    reply.setFrom(getJID());
    // Verify that requester is a valid agent
    AgentSession agentSession = null;
    try {
        agentSession = agentManager.getAgentSession(packet.getFrom());
    } catch (AgentNotFoundException e) {
    // Ignore
    }
    if (agentSession == null) {
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
        send(reply);
        Log.debug("Agent not found while accepting offer");
        return;
    }
    // Answer that the invitation was received and that it is being processed
    send(reply);
    // Execute the invitation
    invitation.execute();
}
Also used : IQ(org.xmpp.packet.IQ) PacketError(org.xmpp.packet.PacketError)

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