Search in sources :

Example 36 with Presence

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

the class RemoteClientSession method isInitialized.

public boolean isInitialized() {
    if (initialized == -1) {
        Presence presence = getPresence();
        if (presence != null && presence.isAvailable()) {
            // Optimization to avoid making a remote call
            initialized = 1;
        } else {
            ClusterTask task = getRemoteSessionTask(RemoteSessionTask.Operation.isInitialized);
            initialized = (Boolean) doSynchronousClusterTask(task) ? 1 : 0;
        }
    }
    return initialized == 1;
}
Also used : ClusterTask(org.jivesoftware.util.cache.ClusterTask) Presence(org.xmpp.packet.Presence)

Example 37 with Presence

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

the class ClusterListener method cleanupPresences.

/**
     * Simulate an unavailable presence for sessions that were being hosted in other
     * cluster nodes. This method should be used ONLY when this JVM left the cluster.
     *
     * @param key the key that identifies the node that is no longer available.
     */
private void cleanupPresences(NodeID key) {
    Set<String> registeredUsers = lookupJIDList(key, C2SCache.getName());
    if (!registeredUsers.isEmpty()) {
        for (String fullJID : new ArrayList<String>(registeredUsers)) {
            JID offlineJID = new JID(fullJID);
            try {
                Presence presence = new Presence(Presence.Type.unavailable);
                presence.setFrom(offlineJID);
                XMPPServer.getInstance().getPresenceRouter().route(presence);
            } catch (PacketException e) {
                Log.error(e);
            }
        }
    }
    Set<String> anonymousUsers = lookupJIDList(key, anonymousC2SCache.getName());
    if (!anonymousUsers.isEmpty()) {
        for (String fullJID : new ArrayList<String>(anonymousUsers)) {
            JID offlineJID = new JID(fullJID);
            try {
                Presence presence = new Presence(Presence.Type.unavailable);
                presence.setFrom(offlineJID);
                XMPPServer.getInstance().getPresenceRouter().route(presence);
            } catch (PacketException e) {
                Log.error(e);
            }
        }
    }
    nodeSessions.remove(key);
}
Also used : JID(org.xmpp.packet.JID) Presence(org.xmpp.packet.Presence) DirectedPresence(org.jivesoftware.openfire.handler.DirectedPresence)

Example 38 with Presence

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

the class ContentFilterPlugin method sendViolationNotification.

private void sendViolationNotification(Packet originalPacket) {
    String subject = "Content filter notification! (" + originalPacket.getFrom().getNode() + ")";
    String body;
    if (originalPacket instanceof Message) {
        Message originalMsg = (Message) originalPacket;
        body = "Disallowed content detected in message from:" + originalMsg.getFrom() + " to:" + originalMsg.getTo() + ", message was " + (allowOnMatch ? "allowed" + (contentFilter.isMaskingContent() ? " and masked." : " but not masked.") : "rejected.") + (violationIncludeOriginalPacketEnabled ? "\nOriginal subject:" + (originalMsg.getSubject() != null ? originalMsg.getSubject() : "") + "\nOriginal content:" + (originalMsg.getBody() != null ? originalMsg.getBody() : "") : "");
    } else {
        // presence
        Presence originalPresence = (Presence) originalPacket;
        body = "Disallowed status detected in presence from:" + originalPresence.getFrom() + ", status was " + (allowOnMatch ? "allowed" + (contentFilter.isMaskingContent() ? " and masked." : " but not masked.") : "rejected.") + (violationIncludeOriginalPacketEnabled ? "\nOriginal status:" + originalPresence.getStatus() : "");
    }
    if (violationNotificationByIMEnabled) {
        if (Log.isDebugEnabled()) {
            Log.debug("Content filter: sending IM notification");
        }
        sendViolationNotificationIM(subject, body);
    }
    if (violationNotificationByEmailEnabled) {
        if (Log.isDebugEnabled()) {
            Log.debug("Content filter: sending email notification");
        }
        sendViolationNotificationEmail(subject, body);
    }
}
Also used : Message(org.xmpp.packet.Message) Presence(org.xmpp.packet.Presence)

Example 39 with Presence

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

the class ContentFilterTest method testFilterAvailablePresence.

@Test
public void testFilterAvailablePresence() throws Exception {
    // setup available presence
    Presence presence = new Presence();
    presence.setStatus("fox is now online!");
    System.out.println(presence.toXML());
    // filter on the word "fox" and "dog"
    filter.setPatterns("fox,dog");
    filter.setMask("**");
    boolean matched = filter.filter(presence);
    // matches should not be found
    assertTrue(matched);
    // content has changed
    assertEquals("** is now online!", presence.getStatus());
}
Also used : Presence(org.xmpp.packet.Presence) Test(org.junit.Test)

Example 40 with Presence

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

the class SessionManager method broadcastPresenceOfOtherResource.

/**
     * Sends the presences of other connected resources to the resource that just connected.
     *
     * @param session the newly created session.
     */
private void broadcastPresenceOfOtherResource(LocalClientSession session) {
    if (!SessionManager.isOtherResourcePresenceEnabled()) {
        return;
    }
    Presence presence;
    // Get list of sessions of the same user
    JID searchJID = new JID(session.getAddress().getNode(), session.getAddress().getDomain(), null);
    List<JID> addresses = routingTable.getRoutes(searchJID, null);
    for (JID address : addresses) {
        if (address.equals(session.getAddress())) {
            continue;
        }
        // Send the presence of an existing session to the session that has just changed
        // the presence
        ClientSession userSession = routingTable.getClientRoute(address);
        presence = userSession.getPresence().createCopy();
        presence.setTo(session.getAddress());
        session.process(presence);
    }
}
Also used : JID(org.xmpp.packet.JID) LocalClientSession(org.jivesoftware.openfire.session.LocalClientSession) ClientSession(org.jivesoftware.openfire.session.ClientSession) 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