Search in sources :

Example 1 with XMPPTCPConnection

use of com.xabber.xmpp.smack.XMPPTCPConnection 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 = PushManager.getInstance().isSupport(connection);
        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(com.xabber.xmpp.smack.XMPPTCPConnection) ArrayList(java.util.ArrayList) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) DomainBareJid(org.jxmpp.jid.DomainBareJid) NonNull(androidx.annotation.NonNull)

Example 2 with XMPPTCPConnection

use of com.xabber.xmpp.smack.XMPPTCPConnection in project xabber-android by redsolution.

the class PrivateStorageManager method setPrivateData.

private void setPrivateData(AccountJid accountJid, PrivateData privateData) {
    AccountItem accountItem = AccountManager.getInstance().getAccount(accountJid);
    if (accountItem == null || !accountItem.isEnabled())
        return;
    XMPPTCPConnection connection = accountItem.getConnection();
    PrivateDataManager privateDataManager = PrivateDataManager.getInstanceFor(connection);
    try {
        if (!privateDataManager.isSupported())
            return;
        privateDataManager.setPrivateData(privateData);
    } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException | IllegalArgumentException e) {
        e.printStackTrace();
    }
}
Also used : XMPPTCPConnection(com.xabber.xmpp.smack.XMPPTCPConnection) AccountItem(com.xabber.android.data.account.AccountItem) PrivateDataManager(org.jivesoftware.smackx.iqprivate.PrivateDataManager)

Example 3 with XMPPTCPConnection

use of com.xabber.xmpp.smack.XMPPTCPConnection in project xabber-android by redsolution.

the class BlockingManager method getBlockingCommandManager.

@SuppressWarnings("WeakerAccess")
@Nullable
BlockingCommandManager getBlockingCommandManager(AccountJid account) {
    AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    if (accountItem == null) {
        return null;
    }
    XMPPTCPConnection connection = accountItem.getConnection();
    // "Must have a local (user) JID set. Either you didn't configure one or you where not connected at least once"
    if (connection.getUser() == null) {
        return null;
    }
    return BlockingCommandManager.getInstanceFor(connection);
}
Also used : XMPPTCPConnection(com.xabber.xmpp.smack.XMPPTCPConnection) AccountItem(com.xabber.android.data.account.AccountItem) Nullable(androidx.annotation.Nullable)

Example 4 with XMPPTCPConnection

use of com.xabber.xmpp.smack.XMPPTCPConnection in project xabber-android by redsolution.

the class NextMamManager method requestToMessageArchive.

/**
 * T extends MamManager.MamQueryResult or T extends MamManager.MamPrefsResult
 */
private <T> T requestToMessageArchive(AccountItem accountItem, MamRequest<T> request) {
    T result = null;
    XMPPTCPConnection connection = accountItem.getConnection();
    if (connection.isAuthenticated()) {
        MamManager mamManager = MamManager.getInstanceFor(connection);
        try {
            result = request.execute(mamManager);
        } catch (Exception e) {
            LogManager.exception(this, e);
        }
    }
    return result;
}
Also used : MamManager(org.jivesoftware.smackx.mam.MamManager) XMPPTCPConnection(com.xabber.xmpp.smack.XMPPTCPConnection) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException) IOException(java.io.IOException)

Example 5 with XMPPTCPConnection

use of com.xabber.xmpp.smack.XMPPTCPConnection in project xabber-android by redsolution.

the class PrivateStorageManager method getPrivateData.

@Nullable
private PrivateData getPrivateData(AccountJid accountJid, String namespace, String elementName) {
    AccountItem accountItem = AccountManager.getInstance().getAccount(accountJid);
    if (accountItem == null || !accountItem.isEnabled())
        return null;
    XMPPTCPConnection connection = accountItem.getConnection();
    PrivateDataManager privateDataManager = PrivateDataManager.getInstanceFor(connection);
    try {
        if (!privateDataManager.isSupported())
            return null;
        return privateDataManager.getPrivateData(elementName, namespace);
    } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException | IllegalArgumentException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : XMPPTCPConnection(com.xabber.xmpp.smack.XMPPTCPConnection) AccountItem(com.xabber.android.data.account.AccountItem) PrivateDataManager(org.jivesoftware.smackx.iqprivate.PrivateDataManager) Nullable(androidx.annotation.Nullable)

Aggregations

XMPPTCPConnection (com.xabber.xmpp.smack.XMPPTCPConnection)8 AccountItem (com.xabber.android.data.account.AccountItem)4 NonNull (androidx.annotation.NonNull)3 Nullable (androidx.annotation.Nullable)2 PrivateDataManager (org.jivesoftware.smackx.iqprivate.PrivateDataManager)2 NetworkException (com.xabber.android.data.NetworkException)1 SASLXTOKENMechanism (com.xabber.xmpp.smack.SASLXTOKENMechanism)1 XMPPTCPConnectionConfiguration (com.xabber.xmpp.smack.XMPPTCPConnectionConfiguration)1 MemorizingTrustManager (de.duenndns.ssl.MemorizingTrustManager)1 IOException (java.io.IOException)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 SSLContext (javax.net.ssl.SSLContext)1 AllowAllHostnameVerifier (org.apache.http.conn.ssl.AllowAllHostnameVerifier)1 SmackException (org.jivesoftware.smack.SmackException)1 XMPPException (org.jivesoftware.smack.XMPPException)1 StreamManagementException (org.jivesoftware.smack.sm.StreamManagementException)1 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)1 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)1