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;
}
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);
}
});
}
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;
}
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();
}
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;
}
Aggregations