use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project Smack by igniterealtime.
the class STUN method serviceAvailable.
/**
* Check if the server support STUN Service.
*
* @param connection the connection
* @return true if the server support STUN
* @throws SmackException
* @throws XMPPException
* @throws InterruptedException
*/
public static boolean serviceAvailable(XMPPConnection connection) throws XMPPException, SmackException, InterruptedException {
if (!connection.isConnected()) {
return false;
}
LOGGER.fine("Service listing");
ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(connection);
DiscoverItems items = disco.discoverItems(connection.getXMPPServiceDomain());
for (DiscoverItems.Item item : items.getItems()) {
DiscoverInfo info = disco.discoverInfo(item.getEntityID());
for (DiscoverInfo.Identity identity : info.getIdentities()) {
if (identity.getCategory().equals("proxy") && identity.getType().equals("stun"))
if (info.containsFeature(NAMESPACE))
return true;
}
LOGGER.fine(item.getName() + "-" + info.getType());
}
return false;
}
use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project Smack by igniterealtime.
the class Node method discoverInfo.
/**
* Discover node information in standard {@link DiscoverInfo} format.
*
* @return The discovery information about the node.
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public DiscoverInfo discoverInfo() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
DiscoverInfo info = new DiscoverInfo();
info.setTo(pubSubManager.getServiceJid());
info.setNode(getId());
return pubSubManager.getConnection().createStanzaCollectorAndSend(info).nextResultOrThrow();
}
use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project Smack by igniterealtime.
the class PubSubManager method getNode.
/**
* Retrieves the requested node, if it exists. It will throw an
* exception if it does not.
*
* @param id - The unique id of the node
* @return the node
* @throws XMPPErrorException The node does not exist
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public <T extends Node> T getNode(String id) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
Node node = nodeMap.get(id);
if (node == null) {
DiscoverInfo info = new DiscoverInfo();
info.setTo(pubSubService);
info.setNode(id);
DiscoverInfo infoReply = connection().createStanzaCollectorAndSend(info).nextResultOrThrow();
if (infoReply.hasIdentity(PubSub.ELEMENT, "leaf")) {
node = new LeafNode(this, id);
} else if (infoReply.hasIdentity(PubSub.ELEMENT, "collection")) {
node = new CollectionNode(this, id);
} else {
// If this is not the case, then we are dealing with an PubSub implementation that doesn't follow the specification.
throw new AssertionError("PubSub service '" + pubSubService + "' returned disco info result for node '" + id + "', but it did not contain an Identity of type 'leaf' or 'collection' (and category 'pubsub'), which is not allowed according to XEP-60 5.3.");
}
nodeMap.put(id, node);
}
@SuppressWarnings("unchecked") T res = (T) node;
return res;
}
use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project Smack by igniterealtime.
the class EntityCapsTest method testPreventDiscoInfo.
/**
* Test if entity caps actually prevent a disco info request and reply.
*
* @throws XMPPException
* @throws InterruptedException
* @throws NotConnectedException
* @throws NoResponseException
*
*/
@SmackIntegrationTest
public void testPreventDiscoInfo() throws XMPPException, NoResponseException, NotConnectedException, InterruptedException {
final String dummyFeature = getNewDummyFeature();
conOne.addPacketSendingListener(new StanzaListener() {
@Override
public void processStanza(Stanza stanza) {
discoInfoSend = true;
}
}, new AndFilter(new StanzaTypeFilter(DiscoverInfo.class), IQTypeFilter.GET));
// add a bogus feature so that con1 ver won't match con0's
sdmTwo.addFeature(dummyFeature);
dropCapsCache();
// discover that
DiscoverInfo info = sdmOne.discoverInfo(conTwo.getUser());
// that discovery should cause a disco#info
assertTrue(discoInfoSend);
assertTrue(info.containsFeature(dummyFeature));
discoInfoSend = false;
// discover that
info = sdmOne.discoverInfo(conTwo.getUser());
// that discovery shouldn't cause a disco#info
assertFalse(discoInfoSend);
assertTrue(info.containsFeature(dummyFeature));
}
use of org.jivesoftware.smackx.disco.packet.DiscoverInfo 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