Search in sources :

Example 16 with ClientSession

use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.

the class Roster method broadcastPresence.

/**
     * <p>Broadcast the presence update to all subscribers of the roter.</p>
     * <p>Any presence change typically results in a broadcast to the roster members.</p>
     *
     * @param packet The presence packet to broadcast
     */
public void broadcastPresence(Presence packet) {
    if (routingTable == null) {
        return;
    }
    // Get the privacy list of this user
    PrivacyList list = null;
    JID from = packet.getFrom();
    if (from != null) {
        // Try to use the active list of the session. If none was found then try to use
        // the default privacy list of the session
        ClientSession session = sessionManager.getSession(from);
        if (session != null) {
            list = session.getActiveList();
            list = list == null ? session.getDefaultList() : list;
        }
    }
    if (list == null) {
        // No privacy list was found (based on the session) so check if there is a default list
        list = PrivacyListManager.getInstance().getDefaultPrivacyList(username);
    }
    // Broadcast presence to subscribed entities
    for (RosterItem item : rosterItems.values()) {
        if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_FROM) {
            packet.setTo(item.getJid());
            if (list != null && list.shouldBlockPacket(packet)) {
                // Outgoing presence notifications are blocked for this contact
                continue;
            }
            JID searchNode = new JID(item.getJid().getNode(), item.getJid().getDomain(), null, true);
            for (JID jid : routingTable.getRoutes(searchNode, null)) {
                try {
                    routingTable.routePacket(jid, packet, false);
                } catch (Exception e) {
                    // Theoretically only happens if session has been closed.
                    Log.debug(e.getMessage(), e);
                }
            }
        }
    }
    // Broadcast presence to shared contacts whose subscription status is FROM
    for (String contact : implicitFrom.keySet()) {
        if (contact.contains("@")) {
            String node = contact.substring(0, contact.lastIndexOf("@"));
            String domain = contact.substring(contact.lastIndexOf("@") + 1);
            node = JID.escapeNode(node);
            contact = new JID(node, domain, null).toBareJID();
        }
        packet.setTo(contact);
        if (list != null && list.shouldBlockPacket(packet)) {
            // Outgoing presence notifications are blocked for this contact
            continue;
        }
        for (JID jid : routingTable.getRoutes(new JID(contact), null)) {
            try {
                routingTable.routePacket(jid, packet, false);
            } catch (Exception e) {
                // Theoretically only happens if session has been closed.
                Log.debug(e.getMessage(), e);
            }
        }
    }
    if (from != null) {
        // Broadcast presence to other user's resources
        sessionManager.broadcastPresenceToOtherResources(from, packet);
    }
}
Also used : JID(org.xmpp.packet.JID) PrivacyList(org.jivesoftware.openfire.privacy.PrivacyList) ClientSession(org.jivesoftware.openfire.session.ClientSession) SharedGroupException(org.jivesoftware.openfire.SharedGroupException) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) IOException(java.io.IOException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) CannotCalculateSizeException(org.jivesoftware.util.cache.CannotCalculateSizeException)

Example 17 with ClientSession

use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.

the class PresenceManagerImpl method getPresence.

@Override
public Presence getPresence(User user) {
    if (user == null) {
        return null;
    }
    Presence presence = null;
    for (ClientSession session : sessionManager.getSessions(user.getUsername())) {
        if (presence == null) {
            presence = session.getPresence();
        } else {
            // Get the ordinals of the presences to compare. If no ordinal is available then
            // assume a value of -1
            int o1 = presence.getShow() != null ? presence.getShow().ordinal() : -1;
            int o2 = session.getPresence().getShow() != null ? session.getPresence().getShow().ordinal() : -1;
            // Compare the presences' show ordinals
            if (o1 > o2) {
                presence = session.getPresence();
            }
        }
    }
    return presence;
}
Also used : ClientSession(org.jivesoftware.openfire.session.ClientSession) Presence(org.xmpp.packet.Presence)

Example 18 with ClientSession

use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.

the class BaseTransport method start.

/**
     * Handles startup of the transport.
     */
public void start() {
    RosterEventDispatcher.addListener(this);
    UserEventDispatcher.addListener(this);
    SessionEventDispatcher.addListener(this);
    VCardEventDispatcher.addListener(this);
    InterceptorManager.getInstance().addInterceptor(this);
    if (!JiveGlobals.getBooleanProperty("plugin.gateway.tweak.noprobeonstart", false)) {
        // TODO: Do we need to account for local vs other node sessions?
        for (ClientSession session : SessionManager.getInstance().getSessions()) {
            try {
                JID jid = XMPPServer.getInstance().createJID(session.getUsername(), null);
                if (RegistrationManager.getInstance().isRegistered(jid, getType())) {
                    Presence p = new Presence(Presence.Type.probe);
                    p.setFrom(this.getJID());
                    p.setTo(jid);
                    sendPacket(p);
                }
            } catch (UserNotFoundException e) {
            // Not a valid user for the gateway then
            }
        }
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) ClientSession(org.jivesoftware.openfire.session.ClientSession)

Example 19 with ClientSession

use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.

the class ClientSessionTask method run.

public void run() {
    if (getSession() == null || getSession().isClosed()) {
        logger.error("Session not found for JID: " + address);
        return;
    }
    super.run();
    ClientSession session = (ClientSession) getSession();
    if (session instanceof RemoteClientSession) {
        // The session is being hosted by other cluster node so log this unexpected case
        Cache<String, ClientRoute> usersCache = CacheFactory.createCache(RoutingTableImpl.C2S_CACHE_NAME);
        ClientRoute route = usersCache.get(address.toString());
        NodeID nodeID = route.getNodeID();
        logger.warn("Found remote session instead of local session. JID: " + address + " found in Node: " + nodeID.toByteArray() + " and local node is: " + XMPPServer.getInstance().getNodeID().toByteArray());
    }
    if (operation == Operation.isInitialized) {
        if (session instanceof RemoteClientSession) {
            // Something is wrong since the session shoud be local instead of remote
            // Assume some default value
            result = true;
        } else {
            result = session.isInitialized();
        }
    } else if (operation == Operation.incrementConflictCount) {
        if (session instanceof RemoteClientSession) {
            // Something is wrong since the session shoud be local instead of remote
            // Assume some default value
            result = 2;
        } else {
            result = session.incrementConflictCount();
        }
    }
}
Also used : ClientSession(org.jivesoftware.openfire.session.ClientSession) ClientRoute(org.jivesoftware.openfire.spi.ClientRoute) NodeID(org.jivesoftware.openfire.cluster.NodeID)

Example 20 with ClientSession

use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.

the class RemoteSession method doSynchronousClusterTask.

/**
     * Invokes a task on the remote cluster member synchronously and returns the result of
     * the remote operation.
     *
     * @param task        the ClusterTask object to be invoked on a given cluster member.
     * @return result of remote operation.
     */
protected Object doSynchronousClusterTask(ClusterTask task) {
    ClusterNodeInfo info = CacheFactory.getClusterNodeInfo(nodeID);
    Object result = null;
    if (info == null && task instanceof RemoteSessionTask) {
        // clean up invalid session
        Session remoteSession = ((RemoteSessionTask) task).getSession();
        if (remoteSession instanceof ClientSession) {
            SessionManager.getInstance().removeSession(null, remoteSession.getAddress(), false, false);
        }
    } else {
        result = (info == null) ? null : CacheFactory.doSynchronousClusterTask(task, nodeID);
    }
    return result;
}
Also used : ClientSession(org.jivesoftware.openfire.session.ClientSession) ClusterNodeInfo(org.jivesoftware.openfire.cluster.ClusterNodeInfo) ClientSession(org.jivesoftware.openfire.session.ClientSession) Session(org.jivesoftware.openfire.session.Session)

Aggregations

ClientSession (org.jivesoftware.openfire.session.ClientSession)49 JID (org.xmpp.packet.JID)15 Element (org.dom4j.Element)14 LocalClientSession (org.jivesoftware.openfire.session.LocalClientSession)14 IQ (org.xmpp.packet.IQ)12 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)8 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)7 PrivacyList (org.jivesoftware.openfire.privacy.PrivacyList)7 StreamError (org.xmpp.packet.StreamError)7 DataForm (org.xmpp.forms.DataForm)6 FormField (org.xmpp.forms.FormField)6 Message (org.xmpp.packet.Message)6 Presence (org.xmpp.packet.Presence)6 PacketRejectedException (org.jivesoftware.openfire.interceptor.PacketRejectedException)5 StringprepException (gnu.inet.encoding.StringprepException)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)3 SessionEntities (org.jivesoftware.openfire.plugin.rest.entity.SessionEntities)3 SQLException (java.sql.SQLException)2