use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project Smack by igniterealtime.
the class ServiceDiscoveryManager method findService.
public DomainBareJid findService(String feature, boolean useCache, String category, String type) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
List<DiscoverInfo> services = findServicesDiscoverInfo(feature, true, useCache);
if (services.isEmpty()) {
return null;
}
DiscoverInfo info = services.get(0);
if (category != null && type != null) {
if (!info.hasIdentity(category, type)) {
return null;
}
} else if (category != null || type != null) {
throw new IllegalArgumentException("Must specify either both, category and type, or none");
}
return info.getFrom().asDomainBareJid();
}
use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project Smack by igniterealtime.
the class ServiceDiscoveryManager method discoverInfo.
/**
* Returns the discovered information of a given XMPP entity addressed by its JID.
* Use null as entityID to query the server
*
* @param entityID the address of the XMPP entity or null.
* @return the discovered information.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public DiscoverInfo discoverInfo(Jid entityID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
if (entityID == null)
return discoverInfo(null, null);
// Check if the have it cached in the Entity Capabilities Manager
DiscoverInfo info = EntityCapsManager.getDiscoverInfoByUser(entityID);
if (info != null) {
// avoided a disco request, hurray!
return info;
}
// Try to get the newest node#version if it's known, otherwise null is
// returned
EntityCapsManager.NodeVerHash nvh = EntityCapsManager.getNodeVerHashByJid(entityID);
// Discover by requesting the information from the remote entity
// Note that wee need to use NodeVer as argument for Node if it exists
info = discoverInfo(entityID, nvh != null ? nvh.getNodeVer() : null);
// If the node version is known, store the new entry.
if (nvh != null) {
if (EntityCapsManager.verifyDiscoverInfoVersion(nvh.getVer(), nvh.getHash(), info))
EntityCapsManager.addDiscoverInfoByNode(nvh.getNodeVer(), info);
}
return info;
}
use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project Smack by igniterealtime.
the class ServiceDiscoveryManager method discoverInfo.
/**
* Returns the discovered information 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.
*
* @see <a href="http://xmpp.org/extensions/xep-0030.html#info-basic">XEP-30 Basic Protocol</a>
* @see <a href="http://xmpp.org/extensions/xep-0030.html#info-nodes">XEP-30 Info Nodes</a>
*
* @param entityID the address of the XMPP entity.
* @param node the optional attribute that supplements the 'jid' attribute.
* @return the discovered information.
* @throws XMPPErrorException if the operation failed for some reason.
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public DiscoverInfo discoverInfo(Jid entityID, String node) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
// Discover the entity's info
DiscoverInfo disco = new DiscoverInfo();
disco.setType(IQ.Type.get);
disco.setTo(entityID);
disco.setNode(node);
Stanza result = connection().createStanzaCollectorAndSend(disco).nextResultOrThrow();
return (DiscoverInfo) result;
}
use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project Smack by igniterealtime.
the class SimpleDirectoryPersistentCache method lookup.
@Override
public DiscoverInfo lookup(String nodeVer) {
File nodeFile = getFileFor(nodeVer);
if (!nodeFile.isFile()) {
return null;
}
DiscoverInfo info = null;
try {
info = restoreInfoFromFile(nodeFile);
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Coud not restore info from file", e);
}
return info;
}
use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project Smack by igniterealtime.
the class RTPBridge method serviceAvailable.
/**
* Check if the server support RTPBridge Service.
*
* @param connection
* @return true if the server supports the RTPBridge service
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public static boolean serviceAvailable(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
if (!connection.isConnected()) {
return false;
}
LOGGER.fine("Service listing");
ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(connection);
// DiscoverItems items = disco.discoverItems(connection.getXMPPServiceDomain());
// Iterator iter = items.getItems();
// while (iter.hasNext()) {
// DiscoverItems.Item item = (DiscoverItems.Item) iter.next();
// if (item.getEntityID().startsWith("rtpbridge.")) {
// return true;
// }
// }
DiscoverInfo discoInfo = disco.discoverInfo(connection.getXMPPServiceDomain());
for (DiscoverInfo.Identity identity : discoInfo.getIdentities()) {
if ((identity.getName() != null) && (identity.getName().startsWith("rtpbridge"))) {
return true;
}
}
return false;
}
Aggregations