Search in sources :

Example 6 with DiscoverItems

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;
}
Also used : ArrayList(java.util.ArrayList) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 7 with DiscoverItems

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;
}
Also used : ArrayList(java.util.ArrayList) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) NotAMucServiceException(org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 8 with DiscoverItems

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;
}
Also used : DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems)

Example 9 with DiscoverItems

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();
}
Also used : DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems)

Example 10 with DiscoverItems

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());
    }
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) Item(org.jivesoftware.smackx.disco.packet.DiscoverItems.Item) ErrorIQ(org.jivesoftware.smack.packet.ErrorIQ) Bytestream(org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) ErrorIQ(org.jivesoftware.smack.packet.ErrorIQ) IQ(org.jivesoftware.smack.packet.IQ) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) XMPPError(org.jivesoftware.smack.packet.XMPPError) Identity(org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity) SmackException(org.jivesoftware.smack.SmackException) FeatureNotSupportedException(org.jivesoftware.smack.SmackException.FeatureNotSupportedException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) XMPPException(org.jivesoftware.smack.XMPPException) Test(org.junit.Test)

Aggregations

DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)22 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)12 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)8 Item (org.jivesoftware.smackx.disco.packet.DiscoverItems.Item)8 Test (org.junit.Test)8 Identity (org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)7 IOException (java.io.IOException)6 ConnectException (java.net.ConnectException)6 SmackException (org.jivesoftware.smack.SmackException)6 FeatureNotSupportedException (org.jivesoftware.smack.SmackException.FeatureNotSupportedException)6 XMPPException (org.jivesoftware.smack.XMPPException)6 Bytestream (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream)6 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)6 ArrayList (java.util.ArrayList)5 ErrorIQ (org.jivesoftware.smack.packet.ErrorIQ)3 IQ (org.jivesoftware.smack.packet.IQ)3 StreamHost (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost)3 ServiceDiscoveryManager (org.jivesoftware.smackx.disco.ServiceDiscoveryManager)3 Jid (org.jxmpp.jid.Jid)3 InputStream (java.io.InputStream)2