use of org.jivesoftware.smackx.disco.packet.DiscoverItems in project Smack by igniterealtime.
the class MultiUserChatManager method getJoinedRooms.
/**
* Returns a List of the rooms where the requested user has joined. The Iterator will contain Strings where each
* String represents a room (e.g. room@muc.jabber.org).
*
* @param user the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com.
* @return a List of the rooms where the requested user has joined.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public List<EntityBareJid> getJoinedRooms(EntityJid user) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
// Send the disco packet to the user
DiscoverItems result = ServiceDiscoveryManager.getInstanceFor(connection()).discoverItems(user, DISCO_NODE);
List<DiscoverItems.Item> items = result.getItems();
List<EntityBareJid> answer = new ArrayList<>(items.size());
// Collect the entityID for each returned item
for (DiscoverItems.Item item : items) {
EntityBareJid muc = item.getEntityID().asEntityBareJidIfPossible();
if (muc == null) {
LOGGER.warning("Not a bare JID: " + item.getEntityID());
continue;
}
answer.add(muc);
}
return answer;
}
use of org.jivesoftware.smackx.disco.packet.DiscoverItems in project Smack by igniterealtime.
the class MultiUserChatManager method getHostedRooms.
/**
* Returns a List 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 serviceName the service that is hosting the rooms to discover.
* @return a collection of HostedRooms.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
* @throws NotAMucServiceException
*/
public List<HostedRoom> getHostedRooms(DomainBareJid serviceName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotAMucServiceException {
if (!providesMucService(serviceName)) {
throw new NotAMucServiceException(serviceName);
}
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection());
DiscoverItems discoverItems = discoManager.discoverItems(serviceName);
List<DiscoverItems.Item> items = discoverItems.getItems();
List<HostedRoom> answer = new ArrayList<HostedRoom>(items.size());
for (DiscoverItems.Item item : items) {
answer.add(new HostedRoom(item));
}
return answer;
}
use of org.jivesoftware.smackx.disco.packet.DiscoverItems in project Smack by igniterealtime.
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 XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public DiscoverItems discoverNodes(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
DiscoverItems items = new DiscoverItems();
if (nodeId != null)
items.setNode(nodeId);
items.setTo(pubSubService);
DiscoverItems nodeItems = connection().createStanzaCollectorAndSend(items).nextResultOrThrow();
return nodeItems;
}
use of org.jivesoftware.smackx.disco.packet.DiscoverItems in project Smack by igniterealtime.
the class LeafNode method discoverItems.
/**
* Get information on the items in the node in standard
* {@link DiscoverItems} format.
*
* @return The item details in {@link DiscoverItems} format
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public DiscoverItems discoverItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
DiscoverItems items = new DiscoverItems();
items.setTo(pubSubManager.getServiceJid());
items.setNode(getId());
return pubSubManager.getConnection().createStanzaCollectorAndSend(items).nextResultOrThrow();
}
use of org.jivesoftware.smackx.disco.packet.DiscoverItems in project Smack by igniterealtime.
the class Socks5ByteStreamManagerTest method shouldFailIfTargetDoesNotAcceptSocks5Bytestream.
/**
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if the
* target does not accept a SOCKS5 Bytestream. See <a
* href="http://xmpp.org/extensions/xep-0065.html#usecase-alternate">XEP-0065 Section 5.2 A2</a>
*/
@Test
public void shouldFailIfTargetDoesNotAcceptSocks5Bytestream() {
// disable clients local SOCKS5 proxy
Socks5Proxy.setLocalSocks5ProxyEnabled(false);
// get Socks5ByteStreamManager for connection
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
/**
* create responses in the order they should be queried specified by the XEP-0065
* specification
*/
// build discover info that supports the SOCKS5 feature
DiscoverInfo discoverInfo = Socks5PacketUtils.createDiscoverInfo(targetJID, initiatorJID);
discoverInfo.addFeature(Bytestream.NAMESPACE);
// return that SOCKS5 is supported if target is queried
protocol.addResponse(discoverInfo, Verification.correspondingSenderReceiver, Verification.requestTypeGET);
// build discover items containing a proxy item
DiscoverItems discoverItems = Socks5PacketUtils.createDiscoverItems(xmppServer, initiatorJID);
Item item = new Item(proxyJID);
discoverItems.addItem(item);
// return the proxy item if XMPP server is queried
protocol.addResponse(discoverItems, Verification.correspondingSenderReceiver, Verification.requestTypeGET);
// build discover info for proxy containing information about being a SOCKS5 proxy
DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
Identity identity = new Identity("proxy", proxyJID.toString(), "bytestreams");
proxyInfo.addIdentity(identity);
// return the socks5 bytestream proxy identity if proxy is queried
protocol.addResponse(proxyInfo, Verification.correspondingSenderReceiver, Verification.requestTypeGET);
// build a socks5 stream host info containing the address and the port of the
// proxy
Bytestream streamHostInfo = Socks5PacketUtils.createBytestreamResponse(proxyJID, initiatorJID);
streamHostInfo.addStreamHost(proxyJID, proxyAddress, 7778);
// return stream host info if it is queried
protocol.addResponse(streamHostInfo, Verification.correspondingSenderReceiver, Verification.requestTypeGET);
// build error packet to reject SOCKS5 Bytestream
XMPPError.Builder builder = XMPPError.getBuilder(XMPPError.Condition.not_acceptable);
IQ rejectPacket = new ErrorIQ(builder);
rejectPacket.setFrom(targetJID);
rejectPacket.setTo(initiatorJID);
// return error packet as response to the bytestream initiation
protocol.addResponse(rejectPacket, Verification.correspondingSenderReceiver, Verification.requestTypeSET);
try {
// start SOCKS5 Bytestream
byteStreamManager.establishSession(targetJID, sessionID);
fail("exception should be thrown");
} catch (XMPPErrorException e) {
protocol.verifyAll();
assertEquals(rejectPacket.getError(), e.getXMPPError());
} catch (Exception e) {
fail(e.getMessage());
}
}
Aggregations