Search in sources :

Example 16 with DiscoverItems

use of org.jivesoftware.smackx.disco.packet.DiscoverItems in project xabber-android by redsolution.

the class ServerInfoActivity method getServerInfo.

@NonNull
List<String> getServerInfo(ServiceDiscoveryManager serviceDiscoveryManager) {
    final List<String> serverInfoList = new ArrayList<>();
    XMPPTCPConnection connection = accountItem.getConnection();
    if (!connection.isAuthenticated()) {
        serverInfoList.add(getString(R.string.NOT_CONNECTED));
        return serverInfoList;
    }
    try {
        boolean muc = !MultiUserChatManager.getInstanceFor(connection).getXMPPServiceDomains().isEmpty();
        boolean pep = PEPManager.getInstanceFor(connection).isSupported();
        boolean blockingCommand = BlockingCommandManager.getInstanceFor(connection).isSupportedByServer();
        boolean sm = connection.isSmAvailable();
        boolean rosterVersioning = Roster.getInstanceFor(connection).isRosterVersioningSupported();
        boolean carbons = org.jivesoftware.smackx.carbons.CarbonManager.getInstanceFor(connection).isSupportedByServer();
        boolean mam = MamManager.getInstanceFor(connection).isSupportedByServer();
        boolean csi = ClientStateIndicationManager.isSupported(connection);
        boolean push = PushNotificationsManager.getInstanceFor(connection).isSupportedByServer();
        boolean fileUpload = HttpFileUploadManager.getInstance().isFileUploadSupported(accountItem.getAccount());
        boolean mucLight = !MultiUserChatLightManager.getInstanceFor(connection).getLocalServices().isEmpty();
        boolean bookmarks = BookmarksManager.getInstance().isSupported(accountItem.getAccount());
        serverInfoList.add(getString(R.string.xep_0045_muc) + " " + getCheckOrCross(muc));
        serverInfoList.add(getString(R.string.xep_0163_pep) + " " + getCheckOrCross(pep));
        serverInfoList.add(getString(R.string.xep_0191_blocking) + " " + getCheckOrCross(blockingCommand));
        serverInfoList.add(getString(R.string.xep_0198_sm) + " " + getCheckOrCross(sm));
        serverInfoList.add(getString(R.string.xep_0237_roster_ver) + " " + getCheckOrCross(rosterVersioning));
        serverInfoList.add(getString(R.string.xep_0280_carbons) + " " + getCheckOrCross(carbons));
        serverInfoList.add(getString(R.string.xep_0313_mam) + " " + getCheckOrCross(mam));
        serverInfoList.add(getString(R.string.xep_0352_csi) + " " + getCheckOrCross(csi));
        serverInfoList.add(getString(R.string.xep_0357_push) + " " + getCheckOrCross(push));
        serverInfoList.add(getString(R.string.xep_0363_file_upload) + " " + getCheckOrCross(fileUpload));
        serverInfoList.add(getString(R.string.xep_xxxx_muc_light) + " " + getCheckOrCross(mucLight));
        serverInfoList.add(getString(R.string.xep_0048_bookmarks) + " " + getCheckOrCross(bookmarks));
        serverInfoList.add("");
    } catch (InterruptedException | SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException e) {
        LogManager.exception(LOG_TAG, e);
    }
    DomainBareJid xmppServiceDomain = connection.getXMPPServiceDomain();
    try {
        DiscoverInfo discoverInfo = serviceDiscoveryManager.discoverInfo(xmppServiceDomain);
        List<DiscoverInfo.Identity> identities = discoverInfo.getIdentities();
        if (!identities.isEmpty()) {
            serverInfoList.add(getString(R.string.identities));
            for (DiscoverInfo.Identity identity : identities) {
                serverInfoList.add(identity.getCategory() + " " + identity.getType() + " " + identity.getName());
            }
            serverInfoList.add("");
        }
        if (!discoverInfo.getFeatures().isEmpty()) {
            serverInfoList.add(getString(R.string.features));
            for (DiscoverInfo.Feature feature : discoverInfo.getFeatures()) {
                serverInfoList.add(feature.getVar());
            }
            serverInfoList.add("");
        }
        DiscoverItems items = serviceDiscoveryManager.discoverItems(xmppServiceDomain);
        if (!items.getItems().isEmpty()) {
            serverInfoList.add(getString(R.string.items));
            for (DiscoverItems.Item item : items.getItems()) {
                serverInfoList.add(item.getEntityID().toString());
            }
        }
    } catch (InterruptedException | SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException e) {
        LogManager.exception(LOG_TAG, e);
    }
    if (serverInfoList.isEmpty()) {
        serverInfoList.add(getString(R.string.SERVER_INFO_ERROR));
    }
    return serverInfoList;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) XMPPTCPConnection(org.jivesoftware.smack.tcp.XMPPTCPConnection) ArrayList(java.util.ArrayList) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) DomainBareJid(org.jxmpp.jid.DomainBareJid) NonNull(android.support.annotation.NonNull)

Example 17 with DiscoverItems

use of org.jivesoftware.smackx.disco.packet.DiscoverItems in project Smack by igniterealtime.

the class MultiUserChatLightManager method getOccupiedRooms.

/**
     * Returns a List of the rooms the user occupies.
     *
     * @param mucLightService
     * @return a List of the rooms the user occupies.
     * @throws XMPPErrorException
     * @throws NoResponseException
     * @throws NotConnectedException
     * @throws InterruptedException
     */
public List<Jid> getOccupiedRooms(DomainBareJid mucLightService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    DiscoverItems result = ServiceDiscoveryManager.getInstanceFor(connection()).discoverItems(mucLightService);
    List<DiscoverItems.Item> items = result.getItems();
    List<Jid> answer = new ArrayList<>(items.size());
    for (DiscoverItems.Item item : items) {
        Jid mucLight = item.getEntityID();
        answer.add(mucLight);
    }
    return answer;
}
Also used : Jid(org.jxmpp.jid.Jid) DomainBareJid(org.jxmpp.jid.DomainBareJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) ArrayList(java.util.ArrayList) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems)

Example 18 with DiscoverItems

use of org.jivesoftware.smackx.disco.packet.DiscoverItems in project Smack by igniterealtime.

the class ServiceDiscoveryManager method discoverItems.

/**
     * Returns the discovered items of a given XMPP entity addressed by its JID and
     * note attribute. Use this message only when trying to query information which is not 
     * directly addressable.
     * 
     * @param entityID the address of the XMPP entity.
     * @param node the optional attribute that supplements the 'jid' attribute.
     * @return the discovered items.
     * @throws XMPPErrorException if the operation failed for some reason.
     * @throws NoResponseException if there was no response from the server.
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public DiscoverItems discoverItems(Jid entityID, String node) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    // Discover the entity's items
    DiscoverItems disco = new DiscoverItems();
    disco.setType(IQ.Type.get);
    disco.setTo(entityID);
    disco.setNode(node);
    Stanza result = connection().createStanzaCollectorAndSend(disco).nextResultOrThrow();
    return (DiscoverItems) result;
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems)

Example 19 with DiscoverItems

use of org.jivesoftware.smackx.disco.packet.DiscoverItems in project Smack by igniterealtime.

the class Socks5BytestreamManager method determineProxies.

/**
     * Returns a list of JIDs of SOCKS5 proxies by querying the XMPP server. The SOCKS5 proxies are
     * in the same order as returned by the XMPP server.
     * 
     * @return list of JIDs of SOCKS5 proxies
     * @throws XMPPErrorException if there was an error querying the XMPP server for SOCKS5 proxies
     * @throws NoResponseException if there was no response from the server.
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
private List<Jid> determineProxies() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    XMPPConnection connection = connection();
    ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
    List<Jid> proxies = new ArrayList<>();
    // get all items from XMPP server
    DiscoverItems discoverItems = serviceDiscoveryManager.discoverItems(connection.getXMPPServiceDomain());
    // query all items if they are SOCKS5 proxies
    for (Item item : discoverItems.getItems()) {
        // skip blacklisted servers
        if (this.proxyBlacklist.contains(item.getEntityID())) {
            continue;
        }
        DiscoverInfo proxyInfo;
        try {
            proxyInfo = serviceDiscoveryManager.discoverInfo(item.getEntityID());
        } catch (NoResponseException | XMPPErrorException e) {
            // blacklist errornous server
            proxyBlacklist.add(item.getEntityID());
            continue;
        }
        if (proxyInfo.hasIdentity("proxy", "bytestreams")) {
            proxies.add(item.getEntityID());
        } else {
            /*
                 * server is not a SOCKS5 proxy, blacklist server to skip next time a Socks5
                 * bytestream should be established
                 */
            this.proxyBlacklist.add(item.getEntityID());
        }
    }
    return proxies;
}
Also used : Item(org.jivesoftware.smackx.disco.packet.DiscoverItems.Item) DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) Jid(org.jxmpp.jid.Jid) ArrayList(java.util.ArrayList) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) XMPPConnection(org.jivesoftware.smack.XMPPConnection) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 20 with DiscoverItems

use of org.jivesoftware.smackx.disco.packet.DiscoverItems in project Smack by igniterealtime.

the class Socks5ByteStreamManagerTest method shouldFailIfNoSocks5ProxyFound1.

/**
     * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if XMPP
     * server doesn't return any proxies.
     */
@Test
public void shouldFailIfNoSocks5ProxyFound1() {
    // disable clients local SOCKS5 proxy
    Socks5Proxy.setLocalSocks5ProxyEnabled(false);
    // get Socks5ByteStreamManager for connection
    Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
    /**
         * create responses in the order they should be queried specified by the XEP-0065
         * specification
         */
    // build discover info that supports the SOCKS5 feature
    DiscoverInfo discoverInfo = Socks5PacketUtils.createDiscoverInfo(targetJID, initiatorJID);
    discoverInfo.addFeature(Bytestream.NAMESPACE);
    // return that SOCKS5 is supported if target is queried
    protocol.addResponse(discoverInfo, Verification.correspondingSenderReceiver, Verification.requestTypeGET);
    // build discover items with no proxy items
    DiscoverItems discoverItems = Socks5PacketUtils.createDiscoverItems(xmppServer, initiatorJID);
    // return the item with no proxy if XMPP server is queried
    protocol.addResponse(discoverItems, Verification.correspondingSenderReceiver, Verification.requestTypeGET);
    try {
        // start SOCKS5 Bytestream
        byteStreamManager.establishSession(targetJID, sessionID);
        fail("exception should be thrown");
    } catch (SmackException e) {
        protocol.verifyAll();
        assertTrue(e.getMessage().contains("no SOCKS5 proxies available"));
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) SmackException(org.jivesoftware.smack.SmackException) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) SmackException(org.jivesoftware.smack.SmackException) FeatureNotSupportedException(org.jivesoftware.smack.SmackException.FeatureNotSupportedException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) XMPPException(org.jivesoftware.smack.XMPPException) Test(org.junit.Test)

Aggregations

DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)23 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)13 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)8 Item (org.jivesoftware.smackx.disco.packet.DiscoverItems.Item)8 Test (org.junit.Test)8 Identity (org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)7 IOException (java.io.IOException)6 ConnectException (java.net.ConnectException)6 ArrayList (java.util.ArrayList)6 SmackException (org.jivesoftware.smack.SmackException)6 FeatureNotSupportedException (org.jivesoftware.smack.SmackException.FeatureNotSupportedException)6 XMPPException (org.jivesoftware.smack.XMPPException)6 Bytestream (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream)6 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)6 ErrorIQ (org.jivesoftware.smack.packet.ErrorIQ)3 IQ (org.jivesoftware.smack.packet.IQ)3 StreamHost (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost)3 ServiceDiscoveryManager (org.jivesoftware.smackx.disco.ServiceDiscoveryManager)3 DomainBareJid (org.jxmpp.jid.DomainBareJid)3 Jid (org.jxmpp.jid.Jid)3