Search in sources :

Example 1 with PacketError

use of org.xmpp.packet.PacketError 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 2 with PacketError

use of org.xmpp.packet.PacketError 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)

Example 3 with PacketError

use of org.xmpp.packet.PacketError 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)

Example 4 with PacketError

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

the class Workgroup method processTransfer.

public void processTransfer(TransferRequest transfer, 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 transfer was received and that it is being processed
    send(reply);
    // Execute the transfer
    transfer.execute();
}
Also used : IQ(org.xmpp.packet.IQ) PacketError(org.xmpp.packet.PacketError)

Example 5 with PacketError

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

the class OfflineSettingsProvider method executeGet.

public void executeGet(IQ packet, Workgroup workgroup) {
    IQ reply = IQ.createResultIQ(packet);
    OfflineSettingsManager offlineSettingsManager = new OfflineSettingsManager();
    OfflineSettings settings;
    try {
        settings = offlineSettingsManager.getOfflineSettings(workgroup);
    } catch (OfflineSettingsNotFound offlineSettingsNotFound) {
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
        workgroup.send(reply);
        return;
    }
    Element offline = reply.setChildElement("offline-settings", "http://jivesoftware.com/protocol/workgroup");
    if (ModelUtil.hasLength(settings.getRedirectURL())) {
        offline.addElement("redirectPage").setText(settings.getRedirectURL());
    } else {
        offline.addElement("emailAddress").setText(settings.getEmailAddress());
        offline.addElement("offlineText").setText(settings.getOfflineText());
        offline.addElement("subject").setText(settings.getSubject());
    }
    workgroup.send(reply);
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) PacketError(org.xmpp.packet.PacketError)

Aggregations

PacketError (org.xmpp.packet.PacketError)39 IQ (org.xmpp.packet.IQ)35 Element (org.dom4j.Element)32 JID (org.xmpp.packet.JID)11 AgentNotFoundException (org.jivesoftware.xmpp.workgroup.AgentNotFoundException)10 AgentSession (org.jivesoftware.xmpp.workgroup.AgentSession)4 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 File (java.io.File)2 SQLException (java.sql.SQLException)2 HashMap (java.util.HashMap)2 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)2 NotFoundException (org.jivesoftware.util.NotFoundException)2 Agent (org.jivesoftware.xmpp.workgroup.Agent)2 DbProperties (org.jivesoftware.xmpp.workgroup.DbProperties)2 WorkgroupManager (org.jivesoftware.xmpp.workgroup.WorkgroupManager)2 PacketRejectedException (org.jivesoftware.xmpp.workgroup.interceptor.PacketRejectedException)2 UserRequest (org.jivesoftware.xmpp.workgroup.request.UserRequest)2