Search in sources :

Example 31 with DiscoverInfo

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

the class CapabilitiesManager method getCachedClientInfo.

@Nullable
public ClientInfo getCachedClientInfo(final Jid jid) {
    ClientInfo clientInfo = clientInfoCache.get(jid);
    if (clientInfo != null) {
        return clientInfo;
    }
    DiscoverInfo discoverInfoByUser = EntityCapsManager.getDiscoverInfoByUser(jid);
    if (discoverInfoByUser == null) {
        discoverInfoByUser = discoverInfoCache.get(jid);
    }
    if (discoverInfoByUser != null) {
        clientInfo = ClientInfo.fromDiscoveryInfo(discoverInfoByUser);
        clientInfoCache.put(jid, clientInfo);
    }
    return clientInfo;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) Nullable(android.support.annotation.Nullable)

Example 32 with DiscoverInfo

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

the class CapabilitiesManager method onPresence.

public void onPresence(final AccountJid accountJid, final Presence presence) {
    final Jid from = presence.getFrom();
    discoverInfoCache.remove(from);
    clientInfoCache.remove(from);
    DiscoverInfo discoverInfoByUser = EntityCapsManager.getDiscoverInfoByUser(from);
    if (discoverInfoByUser != null) {
        return;
    }
    Application.getInstance().runInBackground(new Runnable() {

        @Override
        public void run() {
            updateClientInfo(accountJid, from);
        }
    });
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) Jid(org.jxmpp.jid.Jid) AccountJid(com.xabber.android.data.entity.AccountJid)

Example 33 with DiscoverInfo

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

the class EntityCapsCache method lookup.

@Override
public DiscoverInfo lookup(String nodeVer) {
    Realm realm = RealmManager.getInstance().getNewRealm();
    DiscoveryInfoCache discoveryInfoCache = realm.where(DiscoveryInfoCache.class).equalTo(DiscoveryInfoCache.Fields.NODE_VER, nodeVer).findFirst();
    DiscoverInfo discoverInfo = null;
    if (discoveryInfoCache != null) {
        discoverInfo = realm.copyFromRealm(discoveryInfoCache).getDiscoveryInfo();
    }
    realm.close();
    return discoverInfo;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) DiscoveryInfoCache(com.xabber.android.data.database.realm.DiscoveryInfoCache) Realm(io.realm.Realm)

Example 34 with DiscoverInfo

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

the class HttpFileUploadManager method requestSlot.

/**
     * Request a new upload slot with optional content type from custom upload service.
     *
     * When you get slot you should upload file to PUT URL and share GET URL.
     * Note that this is a synchronous call -- Smack must wait for the server response.
     *
     * @param filename name of file to be uploaded
     * @param fileSize file size in bytes.
     * @param contentType file content-type or null
     * @param uploadServiceAddress the address of the upload service to use or null for default one
     * @return file upload Slot in case of success
     * @throws IllegalArgumentException if fileSize is less than or equal to zero or greater than the maximum size
     *         supported by the service.
     * @throws SmackException
     * @throws InterruptedException
     * @throws XMPPException.XMPPErrorException
     */
public Slot requestSlot(String filename, long fileSize, String contentType, DomainBareJid uploadServiceAddress) throws SmackException, InterruptedException, XMPPException.XMPPErrorException {
    final XMPPConnection connection = connection();
    final UploadService defaultUploadService = this.defaultUploadService;
    // The upload service we are going to use.
    UploadService uploadService;
    if (uploadServiceAddress == null) {
        uploadService = defaultUploadService;
    } else {
        if (defaultUploadService != null && defaultUploadService.getAddress().equals(uploadServiceAddress)) {
            // Avoid performing a service discovery if we already know about the given service.
            uploadService = defaultUploadService;
        } else {
            DiscoverInfo discoverInfo = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(uploadServiceAddress);
            if (!containsHttpFileUploadNamespace(discoverInfo)) {
                throw new IllegalArgumentException("There is no HTTP upload service running at the given address '" + uploadServiceAddress + '\'');
            }
            uploadService = uploadServiceFrom(discoverInfo);
        }
    }
    if (uploadService == null) {
        throw new SmackException("No upload service specified and also none discovered.");
    }
    if (!uploadService.acceptsFileOfSize(fileSize)) {
        throw new IllegalArgumentException("Requested file size " + fileSize + " is greater than max allowed size " + uploadService.getMaxFileSize());
    }
    SlotRequest slotRequest;
    switch(uploadService.getVersion()) {
        case v0_3:
            slotRequest = new SlotRequest(uploadService.getAddress(), filename, fileSize, contentType);
            break;
        case v0_2:
            slotRequest = new SlotRequest_V0_2(uploadService.getAddress(), filename, fileSize, contentType);
            break;
        default:
            throw new AssertionError();
    }
    return connection.createStanzaCollectorAndSend(slotRequest).nextResultOrThrow();
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) SmackException(org.jivesoftware.smack.SmackException) XMPPConnection(org.jivesoftware.smack.XMPPConnection) SlotRequest_V0_2(org.jivesoftware.smackx.httpfileupload.element.SlotRequest_V0_2) SlotRequest(org.jivesoftware.smackx.httpfileupload.element.SlotRequest)

Example 35 with DiscoverInfo

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

the class HttpFileUploadManager method discoverUploadService.

/**
     * Discover upload service.
     *
     * Called automatically when connection is authenticated.
     *
     * Note that this is a synchronous call -- Smack must wait for the server response.
     *
     * @return true if upload service was discovered

     * @throws XMPPException.XMPPErrorException
     * @throws SmackException.NotConnectedException
     * @throws InterruptedException
     * @throws SmackException.NoResponseException
     */
public boolean discoverUploadService() throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection());
    List<DiscoverInfo> servicesDiscoverInfo = sdm.findServicesDiscoverInfo(NAMESPACE, true, true);
    if (servicesDiscoverInfo.isEmpty()) {
        servicesDiscoverInfo = sdm.findServicesDiscoverInfo(NAMESPACE_0_2, true, true);
        if (servicesDiscoverInfo.isEmpty()) {
            return false;
        }
    }
    DiscoverInfo discoverInfo = servicesDiscoverInfo.get(0);
    defaultUploadService = uploadServiceFrom(discoverInfo);
    return true;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

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