Search in sources :

Example 1 with EntityFullJid

use of org.jxmpp.jid.EntityFullJid in project Smack by igniterealtime.

the class MamManager method ensureMamQueryResultMatchesThisManager.

private void ensureMamQueryResultMatchesThisManager(MamQueryResult mamQueryResult) {
    EntityFullJid localAddress = connection().getUser();
    EntityBareJid localBareAddress = null;
    if (localAddress != null) {
        localBareAddress = localAddress.asEntityBareJid();
    }
    boolean isLocalUserArchive = archiveAddress == null || archiveAddress.equals(localBareAddress);
    Jid finIqFrom = mamQueryResult.mamFin.getFrom();
    if (finIqFrom != null) {
        if (finIqFrom.equals(archiveAddress) || (isLocalUserArchive && finIqFrom.equals(localBareAddress))) {
            return;
        }
        throw new IllegalArgumentException("The given MamQueryResult is from the MAM archive '" + finIqFrom + "' whereas this MamManager is responsible for '" + archiveAddress + '\'');
    } else if (!isLocalUserArchive) {
        throw new IllegalArgumentException("The given MamQueryResult is from the local entity (user) MAM archive, whereas this MamManager is responsible for '" + archiveAddress + '\'');
    }
}
Also used : EntityBareJid(org.jxmpp.jid.EntityBareJid) Jid(org.jxmpp.jid.Jid) EntityFullJid(org.jxmpp.jid.EntityFullJid) EntityFullJid(org.jxmpp.jid.EntityFullJid) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 2 with EntityFullJid

use of org.jxmpp.jid.EntityFullJid in project Smack by igniterealtime.

the class BindIQProvider method parse.

@Override
public Bind parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException {
    String name;
    Bind bind = null;
    outerloop: while (true) {
        int eventType = parser.next();
        switch(eventType) {
            case XmlPullParser.START_TAG:
                name = parser.getName();
                switch(name) {
                    case "resource":
                        String resourceString = parser.nextText();
                        bind = Bind.newSet(Resourcepart.from(resourceString));
                        break;
                    case "jid":
                        EntityFullJid fullJid = JidCreate.entityFullFrom(parser.nextText());
                        bind = Bind.newResult(fullJid);
                        break;
                }
                break;
            case XmlPullParser.END_TAG:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
        }
    }
    return bind;
}
Also used : Bind(org.jivesoftware.smack.packet.Bind) EntityFullJid(org.jxmpp.jid.EntityFullJid)

Example 3 with EntityFullJid

use of org.jxmpp.jid.EntityFullJid in project Smack by igniterealtime.

the class AbstractXMPPConnection method toString.

@Override
public final String toString() {
    EntityFullJid localEndpoint = getUser();
    String localEndpointString = localEndpoint == null ? "not-authenticated" : localEndpoint.toString();
    return getClass().getSimpleName() + '[' + localEndpointString + "] (" + getConnectionCounter() + ')';
}
Also used : EntityFullJid(org.jxmpp.jid.EntityFullJid)

Example 4 with EntityFullJid

use of org.jxmpp.jid.EntityFullJid in project Smack by igniterealtime.

the class MultipleRecipientManager method reply.

/**
 * Sends a reply to a previously received stanza that was sent to multiple recipients. Before
 * attempting to send the reply message some checks are performed. If any of those checks
 * fails, then an XMPPException is going to be thrown with the specific error detail.
 *
 * @param connection the connection to use to send the reply.
 * @param original   the previously received stanza that was sent to multiple recipients.
 * @param reply      the new message to send as a reply.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws FeatureNotSupportedException if a requested feature is not supported by the remote entity.
 * @throws NoResponseException if there was no response from the remote entity.
 */
public static void reply(XMPPConnection connection, Message original, Message reply) throws XMPPErrorException, InterruptedException, NotConnectedException, NoResponseException, FeatureNotSupportedException {
    MultipleRecipientInfo info = getMultipleRecipientInfo(original);
    if (info == null) {
        throw new IllegalArgumentException("Original message does not contain multiple recipient info");
    }
    if (info.shouldNotReply()) {
        throw new IllegalArgumentException("Original message should not be replied");
    }
    if (info.getReplyRoom() != null) {
        throw new IllegalArgumentException("Reply should be sent through a room");
    }
    // Any <thread/> element from the initial message MUST be copied into the reply.
    if (original.getThread() != null) {
        reply.asBuilder().setThread(original.getThread()).build();
    }
    MultipleAddresses.Address replyAddress = info.getReplyAddress();
    if (replyAddress != null && replyAddress.getJid() != null) {
        // Send reply to the reply_to address
        reply.setTo(replyAddress.getJid());
        connection.sendStanza(reply);
    } else {
        // Send reply to multiple recipients
        List<Jid> to = new ArrayList<>(info.getTOAddresses().size());
        List<Jid> cc = new ArrayList<>(info.getCCAddresses().size());
        for (MultipleAddresses.Address jid : info.getTOAddresses()) {
            to.add(jid.getJid());
        }
        for (MultipleAddresses.Address jid : info.getCCAddresses()) {
            cc.add(jid.getJid());
        }
        // Add original sender as a 'to' address (if not already present)
        if (!to.contains(original.getFrom()) && !cc.contains(original.getFrom())) {
            to.add(original.getFrom());
        }
        // Remove the sender from the TO/CC list (try with bare JID too)
        EntityFullJid from = connection.getUser();
        if (!to.remove(from) && !cc.remove(from)) {
            EntityBareJid bareJID = from.asEntityBareJid();
            to.remove(bareJID);
            cc.remove(bareJID);
        }
        send(connection, reply, to, cc, null, null, null, false);
    }
}
Also used : MultipleAddresses(org.jivesoftware.smackx.address.packet.MultipleAddresses) Jid(org.jxmpp.jid.Jid) EntityFullJid(org.jxmpp.jid.EntityFullJid) DomainBareJid(org.jxmpp.jid.DomainBareJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) EntityFullJid(org.jxmpp.jid.EntityFullJid) ArrayList(java.util.ArrayList) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 5 with EntityFullJid

use of org.jxmpp.jid.EntityFullJid in project Smack by igniterealtime.

the class Socks5BytestreamManager method getLocalStreamHost.

/**
 * Returns the stream host information of the local SOCKS5 proxy containing the IP address and
 * the port. The returned list may be empty if the local SOCKS5 proxy is not running.
 *
 * @return the stream host information of the local SOCKS5 proxy
 */
public List<StreamHost> getLocalStreamHost() {
    // Ensure that the local SOCKS5 proxy is running (if enabled).
    Socks5Proxy.getSocks5Proxy();
    List<StreamHost> streamHosts = new ArrayList<>();
    XMPPConnection connection = connection();
    EntityFullJid myJid = connection.getUser();
    for (Socks5Proxy socks5Server : Socks5Proxy.getRunningProxies()) {
        List<InetAddress> addresses = socks5Server.getLocalAddresses();
        if (addresses.isEmpty()) {
            continue;
        }
        final int port = socks5Server.getPort();
        for (InetAddress address : addresses) {
            // Prevent loopback addresses from appearing as streamhost
            if (address.isLoopbackAddress()) {
                continue;
            }
            streamHosts.add(new StreamHost(myJid, address, port));
        }
    }
    return streamHosts;
}
Also used : EntityFullJid(org.jxmpp.jid.EntityFullJid) ArrayList(java.util.ArrayList) XMPPConnection(org.jivesoftware.smack.XMPPConnection) StreamHost(org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost) InetAddress(java.net.InetAddress)

Aggregations

EntityFullJid (org.jxmpp.jid.EntityFullJid)24 EntityBareJid (org.jxmpp.jid.EntityBareJid)12 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)10 XMPPException (org.jivesoftware.smack.XMPPException)9 Resourcepart (org.jxmpp.jid.parts.Resourcepart)9 TestNotPossibleException (org.igniterealtime.smack.inttest.TestNotPossibleException)8 ResultSyncPoint (org.igniterealtime.smack.inttest.util.ResultSyncPoint)8 SmackException (org.jivesoftware.smack.SmackException)8 AndFilter (org.jivesoftware.smack.filter.AndFilter)4 Presence (org.jivesoftware.smack.packet.Presence)4 Jid (org.jxmpp.jid.Jid)4 ArrayList (java.util.ArrayList)3 MucNotJoinedException (org.jivesoftware.smackx.muc.MultiUserChatException.MucNotJoinedException)3 MUCInitialPresence (org.jivesoftware.smackx.muc.packet.MUCInitialPresence)3 StanzaListener (org.jivesoftware.smack.StanzaListener)2 XMPPConnection (org.jivesoftware.smack.XMPPConnection)2 StanzaFilter (org.jivesoftware.smack.filter.StanzaFilter)2 Bind (org.jivesoftware.smack.packet.Bind)2 Message (org.jivesoftware.smack.packet.Message)2 Stanza (org.jivesoftware.smack.packet.Stanza)2