Search in sources :

Example 1 with Connection

use of org.jivesoftware.smack.Connection in project ecf by eclipse.

the class EntityCapsManager method updateLocalEntityCaps.

/**
 * Updates the local user Entity Caps information with the data provided
 *
 * If we are connected and there was already a presence send, another
 * presence is send to inform others about your new Entity Caps node string.
 *
 * @param discoverInfo
 *            the local users discover info (mostly the service discovery
 *            features)
 * @param identityType
 *            the local users identity type
 * @param identityName
 *            the local users identity name
 * @param extendedInfo
 *            the local users extended info
 */
public void updateLocalEntityCaps() {
    Connection connection = weakRefConnection.get();
    DiscoverInfo discoverInfo = new DiscoverInfo();
    discoverInfo.setType(IQ.Type.RESULT);
    discoverInfo.setNode(getLocalNodeVer());
    if (connection != null)
        discoverInfo.setFrom(connection.getUser());
    sdm.addDiscoverInfoTo(discoverInfo);
    currentCapsVersion = generateVerificationString(discoverInfo, "sha-1");
    addDiscoverInfoByNode(ENTITY_NODE + '#' + currentCapsVersion, discoverInfo);
    if (lastLocalCapsVersions.size() > 10) {
        String oldCapsVersion = lastLocalCapsVersions.poll();
        sdm.removeNodeInformationProvider(ENTITY_NODE + '#' + oldCapsVersion);
    }
    lastLocalCapsVersions.add(currentCapsVersion);
    caps.put(currentCapsVersion, discoverInfo);
    if (connection != null)
        jidCaps.put(connection.getUser(), new NodeVerHash(ENTITY_NODE, currentCapsVersion, "sha-1"));
    sdm.setNodeInformationProvider(ENTITY_NODE + '#' + currentCapsVersion, new NodeInformationProvider() {

        List<String> features = sdm.getFeaturesList();

        List<Identity> identities = new LinkedList<Identity>(ServiceDiscoveryManager.getIdentities());

        List<PacketExtension> packetExtensions = sdm.getExtendedInfoAsList();

        public List<Item> getNodeItems() {
            return null;
        }

        public List<String> getNodeFeatures() {
            return features;
        }

        public List<Identity> getNodeIdentities() {
            return identities;
        }

        public List<PacketExtension> getNodePacketExtensions() {
            return packetExtensions;
        }
    });
    // to respect ConnectionConfiguration.isSendPresence()
    if (connection != null && connection.isAuthenticated() && presenceSend) {
        Presence presence = new Presence(Presence.Type.available);
        connection.sendPacket(presence);
    }
}
Also used : PacketExtension(org.jivesoftware.smack.packet.PacketExtension) DiscoverInfo(org.jivesoftware.smackx.packet.DiscoverInfo) NodeInformationProvider(org.jivesoftware.smackx.NodeInformationProvider) Connection(org.jivesoftware.smack.Connection) XMPPConnection(org.jivesoftware.smack.XMPPConnection) LinkedList(java.util.LinkedList) Presence(org.jivesoftware.smack.packet.Presence) LinkedList(java.util.LinkedList) List(java.util.List) Identity(org.jivesoftware.smackx.packet.DiscoverInfo.Identity)

Example 2 with Connection

use of org.jivesoftware.smack.Connection in project ecf by eclipse.

the class EntityCapsManager method init.

private void init() {
    Connection connection = weakRefConnection.get();
    instances.put(connection, this);
    connection.addConnectionListener(new ConnectionListener() {

        public void connectionClosed() {
            // Unregister this instance since the connection has been closed
            presenceSend = false;
            instances.remove(weakRefConnection.get());
        }

        public void connectionClosedOnError(Exception e) {
            presenceSend = false;
        }

        public void reconnectionFailed(Exception e) {
        // ignore
        }

        public void reconnectingIn(int seconds) {
        // ignore
        }

        public void reconnectionSuccessful() {
        // ignore
        }
    });
    // This calculates the local entity caps version
    updateLocalEntityCaps();
    if (SmackConfiguration.autoEnableEntityCaps())
        enableEntityCaps();
    PacketFilter packetFilter = new AndFilter(new PacketTypeFilter(Presence.class), new PacketExtensionFilter(ELEMENT, NAMESPACE));
    connection.addPacketListener(new PacketListener() {

        // Listen for remote presence stanzas with the caps extension
        // If we receive such a stanza, record the JID and nodeVer
        public void processPacket(Packet packet) {
            if (!entityCapsEnabled())
                return;
            CapsExtension ext = (CapsExtension) packet.getExtension(EntityCapsManager.ELEMENT, EntityCapsManager.NAMESPACE);
            String hash = ext.getHash().toLowerCase();
            if (!SUPPORTED_HASHES.containsKey(hash))
                return;
            String from = packet.getFrom();
            String node = ext.getNode();
            String ver = ext.getVer();
            jidCaps.put(from, new NodeVerHash(node, ver, hash));
        }
    }, packetFilter);
    packetFilter = new AndFilter(new PacketTypeFilter(Presence.class), new NotFilter(new PacketExtensionFilter(ELEMENT, NAMESPACE)));
    connection.addPacketListener(new PacketListener() {

        public void processPacket(Packet packet) {
            // always remove the JID from the map, even if entityCaps are
            // disabled
            String from = packet.getFrom();
            jidCaps.remove(from);
        }
    }, packetFilter);
    packetFilter = new PacketTypeFilter(Presence.class);
    connection.addPacketSendingListener(new PacketListener() {

        public void processPacket(Packet packet) {
            presenceSend = true;
        }
    }, packetFilter);
    // Intercept presence packages and add caps data when intended.
    // XEP-0115 specifies that a client SHOULD include entity capabilities
    // with every presence notification it sends.
    PacketFilter capsPacketFilter = new PacketTypeFilter(Presence.class);
    PacketInterceptor packetInterceptor = new PacketInterceptor() {

        public void interceptPacket(Packet packet) {
            if (!entityCapsEnabled)
                return;
            CapsExtension caps = new CapsExtension(ENTITY_NODE, getCapsVersion(), "sha-1");
            packet.addExtension(caps);
        }
    };
    connection.addPacketInterceptor(packetInterceptor, capsPacketFilter);
    // It's important to do this as last action. Since it changes the
    // behavior of the SDM in some ways
    sdm.setEntityCapsManager(this);
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) PacketFilter(org.jivesoftware.smack.filter.PacketFilter) Connection(org.jivesoftware.smack.Connection) XMPPConnection(org.jivesoftware.smack.XMPPConnection) PacketTypeFilter(org.jivesoftware.smack.filter.PacketTypeFilter) ConnectionListener(org.jivesoftware.smack.ConnectionListener) CapsExtension(org.jivesoftware.smackx.entitycaps.packet.CapsExtension) PacketListener(org.jivesoftware.smack.PacketListener) PacketInterceptor(org.jivesoftware.smack.PacketInterceptor) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) XMPPException(org.jivesoftware.smack.XMPPException) AndFilter(org.jivesoftware.smack.filter.AndFilter) PacketExtensionFilter(org.jivesoftware.smack.filter.PacketExtensionFilter) NotFilter(org.jivesoftware.smack.filter.NotFilter) Presence(org.jivesoftware.smack.packet.Presence)

Example 3 with Connection

use of org.jivesoftware.smack.Connection in project ecf by eclipse.

the class InBandBytestreamRequest method accept.

/**
 * Accepts the In-Band Bytestream open request and returns the session to
 * send/receive data.
 *
 * @return the session to send/receive data
 * @throws XMPPException if stream is invalid.
 */
public InBandBytestreamSession accept() throws XMPPException {
    Connection connection = this.manager.getConnection();
    // create In-Band Bytestream session and store it
    InBandBytestreamSession ibbSession = new InBandBytestreamSession(connection, this.byteStreamRequest, this.byteStreamRequest.getFrom());
    this.manager.getSessions().put(this.byteStreamRequest.getSessionID(), ibbSession);
    // acknowledge request
    IQ resultIQ = IQ.createResultIQ(this.byteStreamRequest);
    connection.sendPacket(resultIQ);
    return ibbSession;
}
Also used : Connection(org.jivesoftware.smack.Connection) IQ(org.jivesoftware.smack.packet.IQ)

Example 4 with Connection

use of org.jivesoftware.smack.Connection in project ecf by eclipse.

the class XMPPChatRoomManager method setConnection.

public void setConnection(Namespace connectNamespace, ID connectedID, ECFConnection connection) {
    this.connectNamespace = connectNamespace;
    this.connectedID = connectedID;
    this.ecfConnection = connection;
    if (connection != null) {
        // Setup invitation requestListener
        MultiUserChat.addInvitationListener(ecfConnection.getXMPPConnection(), new InvitationListener() {

            public void invitationReceived(Connection arg0, String arg1, String arg2, String arg3, String arg4, Message arg5) {
                fireInvitationReceived(createRoomIDFromName(arg1), createUserIDFromName(arg2), createUserIDFromName(arg5.getTo()), arg5.getSubject(), arg3);
            }
        });
    } else {
        disposeChatRooms();
    }
}
Also used : InvitationListener(org.jivesoftware.smackx.muc.InvitationListener) IChatRoomInvitationListener(org.eclipse.ecf.presence.chatroom.IChatRoomInvitationListener) Message(org.jivesoftware.smack.packet.Message) Connection(org.jivesoftware.smack.Connection) XMPPConnection(org.jivesoftware.smack.XMPPConnection) ECFConnection(org.eclipse.ecf.internal.provider.xmpp.smack.ECFConnection)

Aggregations

Connection (org.jivesoftware.smack.Connection)4 XMPPConnection (org.jivesoftware.smack.XMPPConnection)3 Presence (org.jivesoftware.smack.packet.Presence)2 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ECFConnection (org.eclipse.ecf.internal.provider.xmpp.smack.ECFConnection)1 IChatRoomInvitationListener (org.eclipse.ecf.presence.chatroom.IChatRoomInvitationListener)1 ConnectionListener (org.jivesoftware.smack.ConnectionListener)1 PacketInterceptor (org.jivesoftware.smack.PacketInterceptor)1 PacketListener (org.jivesoftware.smack.PacketListener)1 XMPPException (org.jivesoftware.smack.XMPPException)1 AndFilter (org.jivesoftware.smack.filter.AndFilter)1 NotFilter (org.jivesoftware.smack.filter.NotFilter)1 PacketExtensionFilter (org.jivesoftware.smack.filter.PacketExtensionFilter)1 PacketFilter (org.jivesoftware.smack.filter.PacketFilter)1 PacketTypeFilter (org.jivesoftware.smack.filter.PacketTypeFilter)1 IQ (org.jivesoftware.smack.packet.IQ)1 Message (org.jivesoftware.smack.packet.Message)1