Search in sources :

Example 76 with Presence

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

the class SessionManager method removeSession.

/**
     * Removes a session.
     *
     * @param session the session or null when session is derived from fullJID.
     * @param fullJID the address of the session.
     * @param anonymous true if the authenticated user is anonymous.
     * @param forceUnavailable true if an unavailable presence must be created and routed.
     * @return true if the requested session was successfully removed.
     */
public boolean removeSession(ClientSession session, JID fullJID, boolean anonymous, boolean forceUnavailable) {
    // is shutting down the serverName will be null.
    if (serverName == null) {
        return false;
    }
    if (session == null) {
        session = getSession(fullJID);
    }
    // Remove route to the removed session (anonymous or not)
    boolean removed = routingTable.removeClientRoute(fullJID);
    if (removed) {
        // Fire session event.
        if (anonymous) {
            SessionEventDispatcher.dispatchEvent(session, SessionEventDispatcher.EventType.anonymous_session_destroyed);
        } else {
            SessionEventDispatcher.dispatchEvent(session, SessionEventDispatcher.EventType.session_destroyed);
        }
    }
    // Remove the session from the pre-Authenticated sessions list (if present)
    boolean preauth_removed = localSessionManager.getPreAuthenticatedSessions().remove(fullJID.getResource()) != null;
    // If the user is still available then send an unavailable presence
    if (forceUnavailable || session.getPresence().isAvailable()) {
        Presence offline = new Presence();
        offline.setFrom(fullJID);
        offline.setTo(new JID(null, serverName, null, true));
        offline.setType(Presence.Type.unavailable);
        router.route(offline);
    }
    // Stop tracking information about the session and share it with other cluster nodes
    sessionInfoCache.remove(fullJID.toString());
    if (removed || preauth_removed) {
        // Decrement the counter of user sessions
        connectionsCounter.decrementAndGet();
        return true;
    }
    return false;
}
Also used : JID(org.xmpp.packet.JID) Presence(org.xmpp.packet.Presence)

Example 77 with Presence

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

the class BroadcastPlugin method processPresence.

private void processPresence(boolean canProceed, Presence presence) {
    try {
        if (Presence.Type.subscribe == presence.getType()) {
            // Accept all presence requests if user has permissions
            // Reply that the subscription request was approved or rejected
            Presence reply = new Presence();
            reply.setTo(presence.getFrom());
            reply.setFrom(presence.getTo());
            reply.setType(canProceed ? Presence.Type.subscribed : Presence.Type.unsubscribed);
            componentManager.sendPacket(this, reply);
        } else if (Presence.Type.unsubscribe == presence.getType()) {
            // Send confirmation of unsubscription
            Presence reply = new Presence();
            reply.setTo(presence.getFrom());
            reply.setFrom(presence.getTo());
            reply.setType(Presence.Type.unsubscribed);
            componentManager.sendPacket(this, reply);
            if (!canProceed) {
                // Send unavailable presence of the service
                reply = new Presence();
                reply.setTo(presence.getFrom());
                reply.setFrom(presence.getTo());
                reply.setType(Presence.Type.unavailable);
                componentManager.sendPacket(this, reply);
            }
        } else if (Presence.Type.probe == presence.getType()) {
            // Send that the service is available
            Presence reply = new Presence();
            reply.setTo(presence.getFrom());
            reply.setFrom(presence.getTo());
            if (!canProceed) {
                // Send forbidden error since user is not allowed
                reply.setError(PacketError.Condition.forbidden);
            }
            componentManager.sendPacket(this, reply);
        }
    } catch (ComponentException e) {
        Log.error(e.getMessage(), e);
    }
}
Also used : ComponentException(org.xmpp.component.ComponentException) Presence(org.xmpp.packet.Presence)

Example 78 with Presence

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

the class ContentFilterTest method testFilterPresenceXML.

@Test
public void testFilterPresenceXML() throws Exception {
    String presenceXML = "<presence from=\"bob@127.0.0.1/frodo\">" + "<show>away</show>" + "<status>fox</status>" + "<priority>0</priority>" + "<x xmlns=\"vcard-temp:x:update\">" + "<photo>f9a514f112c0bcb988d5aa12bc1a9a6f22de5262</photo>" + "</x>" + "<c xmlns=\"http://jabber.org/protocol/caps\" node=\"apple:ichat:caps\" ver=\"392\" ext=\"avavail maudio mvideo avcap audio\"/>" + "<x xmlns=\"http://jabber.org/protocol/tune\"/>" + "</presence>";
    XPPReader packetReader = new XPPReader();
    Document doc = packetReader.read(new StringReader(presenceXML));
    Presence p = new Presence(doc.getRootElement());
    // filter on the word "fox" and "dog"
    filter.setPatterns("fox,dog,message");
    filter.setMask("**");
    String expectedXML = presenceXML.replaceAll("fox", filter.getMask());
    // do filter
    boolean matched = filter.filter(p);
    assertTrue(matched);
    assertEquals(expectedXML, expectedXML, p.toXML());
}
Also used : StringReader(java.io.StringReader) Presence(org.xmpp.packet.Presence) XPPReader(org.dom4j.io.XPPReader) Document(org.dom4j.Document) Test(org.junit.Test)

Example 79 with Presence

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

the class AgentSession method sendStatusOfAllAgents.

/**
     * Sends the presence of each available agent in the workgroup to this agent.
     *
     * @param workgroup the workgroup whose agents' presences will be sent to this agent.
     */
private void sendStatusOfAllAgents(Workgroup workgroup) {
    for (AgentSession agentSession : workgroup.getAgentSessions()) {
        if (!agentSession.getJID().equals(address)) {
            Presence statusPacket = agentSession.getPresence().createCopy();
            statusPacket.setFrom(agentSession.getJID());
            statusPacket.setTo(address);
            // Add the agent-status element
            agentSession.getAgentStatus(statusPacket, workgroup);
            workgroup.send(statusPacket);
        }
    }
}
Also used : Presence(org.xmpp.packet.Presence)

Example 80 with Presence

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

the class AgentSession method sendStatusToAllAgents.

/**
     * Sends this agent's status to all other agents in the Workgroup.
     *
     * @param workgroup the workgroup whose agent will be notified
     */
private void sendStatusToAllAgents(Workgroup workgroup) {
    for (AgentSession agentSession : workgroup.getAgentSessions()) {
        // receive other agents' information
        if (agentSession.hasRequestedAgentInfo() && !agentSession.getJID().equals(address)) {
            Presence statusPacket = presence.createCopy();
            statusPacket.setFrom(address);
            statusPacket.setTo(agentSession.getJID());
            // Add the agent-status element
            getAgentStatus(statusPacket, workgroup);
            workgroup.send(statusPacket);
        }
    }
}
Also used : Presence(org.xmpp.packet.Presence)

Aggregations

Presence (org.xmpp.packet.Presence)109 JID (org.xmpp.packet.JID)38 Element (org.dom4j.Element)34 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)20 Message (org.xmpp.packet.Message)17 IQ (org.xmpp.packet.IQ)16 UpdatePresence (org.jivesoftware.openfire.muc.cluster.UpdatePresence)14 NotFoundException (org.jivesoftware.util.NotFoundException)12 ArrayList (java.util.ArrayList)11 MUCRole (org.jivesoftware.openfire.muc.MUCRole)10 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)9 DefaultElement (org.dom4j.tree.DefaultElement)8 IOException (java.io.IOException)7 SQLException (java.sql.SQLException)7 GroupJID (org.jivesoftware.openfire.group.GroupJID)7 NotAllowedException (org.jivesoftware.openfire.muc.NotAllowedException)7 Date (java.util.Date)6 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)6 ConflictException (org.jivesoftware.openfire.muc.ConflictException)6 ForbiddenException (org.jivesoftware.openfire.muc.ForbiddenException)6