use of org.jivesoftware.smackx.packet.DiscoverItems in project ecf by eclipse.
the class MultiUserChat method getHostedRooms.
/**
* Returns a collection of HostedRooms where each HostedRoom has the XMPP address of the room
* and the room's name. Once discovered the rooms hosted by a chat service it is possible to
* discover more detailed room information or join the room.
*
* @param connection the XMPP connection to use for discovering hosted rooms by the MUC service.
* @param serviceName the service that is hosting the rooms to discover.
* @return a collection of HostedRooms.
* @throws XMPPException if an error occured while trying to discover the information.
*/
public static Collection<HostedRoom> getHostedRooms(Connection connection, String serviceName) throws XMPPException {
List<HostedRoom> answer = new ArrayList<HostedRoom>();
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
DiscoverItems items = discoManager.discoverItems(serviceName);
for (Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext(); ) {
answer.add(new HostedRoom(it.next()));
}
return answer;
}
use of org.jivesoftware.smackx.packet.DiscoverItems in project ecf by eclipse.
the class UserSearchManager method getSearchServices.
/**
* Returns a collection of search services found on the server.
*
* @return a Collection of search services found on the server.
* @throws XMPPException thrown if a server error has occurred.
*/
public Collection<String> getSearchServices() throws XMPPException {
final List<String> searchServices = new ArrayList<String>();
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(con);
DiscoverItems items = discoManager.discoverItems(con.getServiceName());
Iterator<DiscoverItems.Item> iter = items.getItems();
while (iter.hasNext()) {
DiscoverItems.Item item = iter.next();
try {
DiscoverInfo info;
try {
info = discoManager.discoverInfo(item.getEntityID());
} catch (XMPPException e) {
// Ignore Case
continue;
}
if (info.containsFeature("jabber:iq:search")) {
searchServices.add(item.getEntityID());
}
} catch (Exception e) {
// No info found.
break;
}
}
return searchServices;
}
use of org.jivesoftware.smackx.packet.DiscoverItems in project ecf by eclipse.
the class PubSubManager method discoverNodes.
/**
* Get all the nodes that currently exist as a child of the specified
* collection node. If the service does not support collection nodes
* then all nodes will be returned.
*
* To retrieve contents of the root collection node (if it exists),
* or there is no root collection node, pass null as the nodeId.
*
* @param nodeId - The id of the collection node for which the child
* nodes will be returned.
* @return {@link DiscoverItems} representing the existing nodes
*
* @throws XMPPException
*/
public DiscoverItems discoverNodes(String nodeId) throws XMPPException {
DiscoverItems items = new DiscoverItems();
if (nodeId != null)
items.setNode(nodeId);
items.setTo(to);
DiscoverItems nodeItems = (DiscoverItems) SyncPacketSend.getReply(con, items);
return nodeItems;
}
use of org.jivesoftware.smackx.packet.DiscoverItems in project ecf by eclipse.
the class Socks5BytestreamManager method determineProxies.
/**
* Returns a list of JIDs of SOCKS5 proxies by querying the XMPP server. The SOCKS5 proxies are
* in the same order as returned by the XMPP server.
*
* @return list of JIDs of SOCKS5 proxies
* @throws XMPPException if there was an error querying the XMPP server for SOCKS5 proxies
*/
private List<String> determineProxies() throws XMPPException {
ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(this.connection);
List<String> proxies = new ArrayList<String>();
// get all items form XMPP server
DiscoverItems discoverItems = serviceDiscoveryManager.discoverItems(this.connection.getServiceName());
Iterator<Item> itemIterator = discoverItems.getItems();
// query all items if they are SOCKS5 proxies
while (itemIterator.hasNext()) {
Item item = itemIterator.next();
// skip blacklisted servers
if (this.proxyBlacklist.contains(item.getEntityID())) {
continue;
}
try {
DiscoverInfo proxyInfo;
proxyInfo = serviceDiscoveryManager.discoverInfo(item.getEntityID());
Iterator<Identity> identities = proxyInfo.getIdentities();
// item must have category "proxy" and type "bytestream"
while (identities.hasNext()) {
Identity identity = identities.next();
if ("proxy".equalsIgnoreCase(identity.getCategory()) && "bytestreams".equalsIgnoreCase(identity.getType())) {
proxies.add(item.getEntityID());
break;
}
/*
* server is not a SOCKS5 proxy, blacklist server to skip next time a Socks5
* bytestream should be established
*/
this.proxyBlacklist.add(item.getEntityID());
}
} catch (XMPPException e) {
// blacklist errornous server
this.proxyBlacklist.add(item.getEntityID());
}
}
return proxies;
}
use of org.jivesoftware.smackx.packet.DiscoverItems in project ecf by eclipse.
the class MultipleRecipientManager method getMultipleRecipienServiceAddress.
/**
* Returns the address of the multiple recipients service. To obtain such address service
* discovery is going to be used on the connected server and if none was found then another
* attempt will be tried on the server items. The discovered information is going to be
* cached for 24 hours.
*
* @param connection the connection to use for disco. The connected server is going to be
* queried.
* @return the address of the multiple recipients service or <tt>null</tt> if none was found.
*/
private static String getMultipleRecipienServiceAddress(Connection connection) {
String serviceName = connection.getServiceName();
String serviceAddress = (String) services.get(serviceName);
if (serviceAddress == null) {
synchronized (services) {
serviceAddress = (String) services.get(serviceName);
if (serviceAddress == null) {
// Send the disco packet to the server itself
try {
DiscoverInfo info = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(serviceName);
// Check if the server supports JEP-33
if (info.containsFeature("http://jabber.org/protocol/address")) {
serviceAddress = serviceName;
} else {
// Get the disco items and send the disco packet to each server item
DiscoverItems items = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems(serviceName);
for (Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext(); ) {
DiscoverItems.Item item = it.next();
info = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(item.getEntityID(), item.getNode());
if (info.containsFeature("http://jabber.org/protocol/address")) {
serviceAddress = serviceName;
break;
}
}
}
// Cache the discovered information
services.put(serviceName, serviceAddress == null ? "" : serviceAddress);
} catch (XMPPException e) {
e.printStackTrace();
}
}
}
}
return "".equals(serviceAddress) ? null : serviceAddress;
}
Aggregations