Search in sources :

Example 21 with IQ

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

the class TransferRequest method userJoinedRoom.

@Override
public void userJoinedRoom(JID roomJID, JID user) {
    Log.debug("User " + user + " has joined " + roomJID + ". User should be kicked.");
    if (actualInvitee != null && actualInvitee.toBareJID().equals(user.toBareJID())) {
        joinedRoom = System.currentTimeMillis();
        // This request has been completed so remove it from the list of related
        // requests of the original user request
        userRequest.removeRelatedRequest(this);
        // Kick the inviter from the room
        IQ kick = new IQ(IQ.Type.set);
        kick.setTo(roomJID);
        kick.setFrom(workgroup.getFullJID());
        Element childElement = kick.setChildElement("query", "http://jabber.org/protocol/muc#admin");
        Element item = childElement.addElement("item");
        item.addAttribute("jid", inviter.toString());
        item.addAttribute("role", "none");
        item.addElement("reason").setText("Transfer was successful");
        workgroup.send(kick);
        Log.debug("Sent kicked to  " + user + " in room " + roomJID + ".");
    }
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ)

Example 22 with IQ

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

the class WorkgroupFormProvider method executeGet.

public void executeGet(IQ packet, Workgroup workgroup) {
    IQ reply = IQ.createResultIQ(packet);
    FormManager formManager = FormManager.getInstance();
    DataForm dataForm = formManager.getDataForm(workgroup);
    if (dataForm == null) {
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
        workgroup.send(reply);
        return;
    }
    Element iq = packet.getChildElement();
    if (iq.elements().isEmpty()) {
        reply.setChildElement(iq.createCopy());
        // Send the data form to the requestor
        reply.addExtension(dataForm.createCopy());
        workgroup.send(reply);
    }
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) DataForm(org.xmpp.forms.DataForm) PacketError(org.xmpp.packet.PacketError)

Example 23 with IQ

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

the class SparkManager method handleDiscoInfo.

/**
     * Send a reply back to the client to inform the client that this server has
     * a Spark Manager.
     *
     * @param packet the IQ packet.
     */
private void handleDiscoInfo(IQ packet) {
    IQ replyPacket = IQ.createResultIQ(packet);
    Element responseElement = replyPacket.setChildElement("query", "http://jabber.org/protocol/disco#info");
    Element identity = responseElement.addElement("identity");
    identity.addAttribute("category", "manager");
    identity.addAttribute("type", "text");
    identity.addAttribute("name", "Client Control Manager");
    // Add features set
    buildFeatureSet(responseElement);
    // Send reply
    sendPacket(replyPacket);
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ)

Example 24 with IQ

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

the class SparkManager method requestSoftwareVersion.

/**
     * Make a version request (JEP-0092) of the client the specified session is using. If the response is NOT the Spark IM
     * client, send a StreamError notification and disconnect the user.
     *
     * @param session             the users session.
     */
private void requestSoftwareVersion(final Session session) {
    // Send IQ get to check client version.
    final IQ clientPacket = new IQ(IQ.Type.get);
    clientPacket.setTo(session.getAddress());
    clientPacket.setFrom(serviceName + "." + componentManager.getServerName());
    clientPacket.setChildElement("query", "jabber:iq:version");
    sendPacket(clientPacket);
}
Also used : IQ(org.xmpp.packet.IQ)

Example 25 with IQ

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

the class SparkVersionManager method handleSparkIQ.

private void handleSparkIQ(IQ packet) {
    IQ reply;
    Element iq = packet.getChildElement();
    // Define default values
    String os = iq.element("os").getText();
    reply = IQ.createResultIQ(packet);
    // Handle Invalid Requests
    if (os == null || (!os.equals("windows") && !os.equals("mac") && !os.equals("linux"))) {
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.not_acceptable));
        sendPacket(reply);
        return;
    }
    Element sparkElement = reply.setChildElement("query", "jabber:iq:spark");
    String client = null;
    // Handle Windows clients
    if (os.equals("windows")) {
        client = JiveGlobals.getProperty("spark.windows.client");
    } else // Handle Mac clients.
    if (os.equals("mac")) {
        client = JiveGlobals.getProperty("spark.mac.client");
    } else // Handle Linux Client.
    if (os.equals("linux")) {
        client = JiveGlobals.getProperty("spark.linux.client");
    }
    if (client != null) {
        int index = client.indexOf("_");
        // Add version number
        String versionNumber = client.substring(index + 1);
        int indexOfPeriod = versionNumber.indexOf(".");
        versionNumber = versionNumber.substring(0, indexOfPeriod);
        versionNumber = versionNumber.replaceAll("_", ".");
        sparkElement.addElement("version").setText(versionNumber);
        // Add updated time.
        File clientFile = new File(JiveGlobals.getHomeDirectory(), "enterprise/spark/" + client);
        if (!clientFile.exists()) {
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.item_not_found));
            sendPacket(reply);
            return;
        }
        long updatedTime = clientFile.lastModified();
        sparkElement.addElement("updatedTime").setText(Long.toString(updatedTime));
        // Add download url
        String downloadURL = JiveGlobals.getProperty("spark.client.downloadURL");
        String server = XMPPServer.getInstance().getServerInfo().getXMPPDomain();
        downloadURL = downloadURL.replace("127.0.0.1", server);
        sparkElement.addElement("downloadURL").setText(downloadURL + "?client=" + client);
        String displayMessage = JiveGlobals.getProperty("spark.client.displayMessage");
        if (displayMessage != null && displayMessage.trim().length() > 0) {
            sparkElement.addElement("displayMessage").setText(displayMessage);
        }
    } else {
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
        sendPacket(reply);
        return;
    }
    sendPacket(reply);
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) PacketError(org.xmpp.packet.PacketError) File(java.io.File)

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