Search in sources :

Example 26 with DiscoverInfo

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

the class PingTest method checkSuccessfulDiscoRequest.

@Test
public void checkSuccessfulDiscoRequest() throws Exception {
    ThreadedDummyConnection con = getAuthentiactedDummyConnection();
    DiscoverInfo info = new DiscoverInfo();
    info.addFeature(Ping.NAMESPACE);
    //@formatter:off
    String reply = "<iq type='result' id='qrzSp-16' to='test@myserver.com'>" + "<query xmlns='http://jabber.org/protocol/disco#info'><identity category='client' type='pc' name='Pidgin'/>" + "<feature var='urn:xmpp:ping'/>" + "</query></iq>";
    //@formatter:on
    IQ discoReply = (IQ) PacketParserUtils.parseStanza(reply);
    con.addIQReply(discoReply);
    PingManager pinger = PingManager.getInstanceFor(con);
    boolean pingSupported = pinger.isPingSupported(DUMMY_AT_EXAMPLE_ORG);
    assertTrue(pingSupported);
}
Also used : ThreadedDummyConnection(org.jivesoftware.smack.ThreadedDummyConnection) DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.Test)

Example 27 with DiscoverInfo

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

the class Node method discoverInfo.

/**
     * Discover node information in standard {@link DiscoverInfo} format.
     * 
     * @return The discovery information about the node.
     * @throws XMPPErrorException 
     * @throws NoResponseException if there was no response from the server.
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public DiscoverInfo discoverInfo() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    DiscoverInfo info = new DiscoverInfo();
    info.setTo(pubSubManager.getServiceJid());
    info.setNode(getId());
    return pubSubManager.getConnection().createStanzaCollectorAndSend(info).nextResultOrThrow();
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo)

Example 28 with DiscoverInfo

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

the class PubSubManager method getNode.

/**
     * Retrieves the requested node, if it exists.  It will throw an 
     * exception if it does not.
     * 
     * @param id - The unique id of the node
     * @return the node
     * @throws XMPPErrorException The node does not exist
     * @throws NoResponseException if there was no response from the server.
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public <T extends Node> T getNode(String id) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    Node node = nodeMap.get(id);
    if (node == null) {
        DiscoverInfo info = new DiscoverInfo();
        info.setTo(pubSubService);
        info.setNode(id);
        DiscoverInfo infoReply = connection().createStanzaCollectorAndSend(info).nextResultOrThrow();
        if (infoReply.hasIdentity(PubSub.ELEMENT, "leaf")) {
            node = new LeafNode(this, id);
        } else if (infoReply.hasIdentity(PubSub.ELEMENT, "collection")) {
            node = new CollectionNode(this, id);
        } else {
            // If this is not the case, then we are dealing with an PubSub implementation that doesn't follow the specification.
            throw new AssertionError("PubSub service '" + pubSubService + "' returned disco info result for node '" + id + "', but it did not contain an Identity of type 'leaf' or 'collection' (and category 'pubsub'), which is not allowed according to XEP-60 5.3.");
        }
        nodeMap.put(id, node);
    }
    @SuppressWarnings("unchecked") T res = (T) node;
    return res;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo)

Example 29 with DiscoverInfo

use of org.jivesoftware.smackx.disco.packet.DiscoverInfo 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 30 with DiscoverInfo

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

the class CapabilitiesManager method updateClientInfo.

@SuppressWarnings("WeakerAccess")
void updateClientInfo(final AccountJid account, final Jid jid) {
    DiscoverInfo discoverInfo = EntityCapsManager.getDiscoverInfoByUser(jid);
    if (discoverInfo != null) {
        return;
    }
    AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    if (accountItem == null) {
        return;
    }
    try {
        discoverInfo = ServiceDiscoveryManager.getInstanceFor(accountItem.getConnection()).discoverInfo(jid);
        EntityCapsManager.NodeVerHash nodeVerHashByJid = EntityCapsManager.getNodeVerHashByJid(jid);
        if (nodeVerHashByJid == null) {
            discoverInfoCache.put(jid, discoverInfo);
        }
        if (discoverInfo != null) {
            clientInfoCache.put(jid, ClientInfo.fromDiscoveryInfo(discoverInfo));
        }
    } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | SmackException.NotConnectedException e) {
        LogManager.exception(this, e);
        clientInfoCache.put(jid, ClientInfo.INVALID_CLIENT_INFO);
    }
    RosterContact rosterContact = RosterManager.getInstance().getRosterContact(account, jid.asBareJid());
    if (rosterContact != null) {
        final ArrayList<RosterContact> rosterContacts = new ArrayList<>();
        rosterContacts.add(rosterContact);
        Application.getInstance().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                for (OnContactChangedListener onContactChangedListener : Application.getInstance().getUIListeners(OnContactChangedListener.class)) {
                    onContactChangedListener.onContactsChanged(rosterContacts);
                }
            }
        });
    }
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) RosterContact(com.xabber.android.data.roster.RosterContact) AccountItem(com.xabber.android.data.account.AccountItem) ArrayList(java.util.ArrayList) EntityCapsManager(org.jivesoftware.smackx.caps.EntityCapsManager) OnContactChangedListener(com.xabber.android.data.roster.OnContactChangedListener)

Aggregations

DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)58 Test (org.junit.Test)18 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)13 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)11 Identity (org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)11 IOException (java.io.IOException)8 SmackException (org.jivesoftware.smack.SmackException)8 XMPPException (org.jivesoftware.smack.XMPPException)8 Item (org.jivesoftware.smackx.disco.packet.DiscoverItems.Item)8 ConnectException (java.net.ConnectException)7 FeatureNotSupportedException (org.jivesoftware.smack.SmackException.FeatureNotSupportedException)7 ServiceDiscoveryManager (org.jivesoftware.smackx.disco.ServiceDiscoveryManager)7 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)7 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)7 ArrayList (java.util.ArrayList)6 IQ (org.jivesoftware.smack.packet.IQ)6 Bytestream (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream)6 FormField (org.jivesoftware.smackx.xdata.FormField)6 XMPPConnection (org.jivesoftware.smack.XMPPConnection)5 DomainBareJid (org.jxmpp.jid.DomainBareJid)5