Search in sources :

Example 11 with StanzaFilter

use of org.jivesoftware.smack.filter.StanzaFilter in project Smack by igniterealtime.

the class JingleSession method updatePacketListener.

/**
     * Install the stanza(/packet) listener. The listener is responsible for responding
     * to any stanza(/packet) that we receive...
     */
protected void updatePacketListener() {
    removeAsyncPacketListener();
    LOGGER.fine("UpdatePacketListener");
    packetListener = new StanzaListener() {

        @Override
        public void processStanza(Stanza packet) {
            try {
                receivePacketAndRespond((IQ) packet);
            } catch (Exception e) {
                LOGGER.log(Level.WARNING, "exception", e);
            }
        }
    };
    packetFilter = new StanzaFilter() {

        @Override
        public boolean accept(Stanza packet) {
            if (packet instanceof IQ) {
                IQ iq = (IQ) packet;
                Jid me = getConnection().getUser();
                if (!iq.getTo().equals(me)) {
                    return false;
                }
                Jid other = getResponder().equals(me) ? getInitiator() : getResponder();
                if (iq.getFrom() == null || !iq.getFrom().equals(other == null ? "" : other)) {
                    return false;
                }
                if (iq instanceof Jingle) {
                    Jingle jin = (Jingle) iq;
                    String sid = jin.getSid();
                    if (sid == null || !sid.equals(getSid())) {
                        LOGGER.fine("Ignored Jingle(SID) " + sid + "|" + getSid() + " :" + iq.toXML());
                        return false;
                    }
                    Jid ini = jin.getInitiator();
                    if (!ini.equals(getInitiator())) {
                        LOGGER.fine("Ignored Jingle(INI): " + iq.toXML());
                        return false;
                    }
                } else {
                    // We accept some non-Jingle IQ packets: ERRORs and ACKs
                    if (iq.getType().equals(IQ.Type.set)) {
                        LOGGER.fine("Ignored Jingle(TYPE): " + iq.toXML());
                        return false;
                    } else if (iq.getType().equals(IQ.Type.get)) {
                        LOGGER.fine("Ignored Jingle(TYPE): " + iq.toXML());
                        return false;
                    }
                }
                return true;
            }
            return false;
        }
    };
    getConnection().addAsyncStanzaListener(packetListener, packetFilter);
}
Also used : Jingle(org.jivesoftware.smackx.jingleold.packet.Jingle) StanzaFilter(org.jivesoftware.smack.filter.StanzaFilter) Jid(org.jxmpp.jid.Jid) Stanza(org.jivesoftware.smack.packet.Stanza) IQ(org.jivesoftware.smack.packet.IQ) StanzaListener(org.jivesoftware.smack.StanzaListener) SmackException(org.jivesoftware.smack.SmackException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) XMPPException(org.jivesoftware.smack.XMPPException)

Example 12 with StanzaFilter

use of org.jivesoftware.smack.filter.StanzaFilter in project Smack by igniterealtime.

the class OnceForThisStanza method setup.

public static void setup(XMPPTCPConnection connection, Stanza packet) {
    StanzaFilter packetFilter = new OnceForThisStanza(connection, packet);
    connection.addRequestAckPredicate(packetFilter);
}
Also used : StanzaFilter(org.jivesoftware.smack.filter.StanzaFilter)

Aggregations

StanzaFilter (org.jivesoftware.smack.filter.StanzaFilter)12 StanzaCollector (org.jivesoftware.smack.StanzaCollector)5 AndFilter (org.jivesoftware.smack.filter.AndFilter)5 Stanza (org.jivesoftware.smack.packet.Stanza)4 IQReplyFilter (org.jivesoftware.smack.filter.IQReplyFilter)3 IQ (org.jivesoftware.smack.packet.IQ)3 Message (org.jivesoftware.smack.packet.Message)3 Presence (org.jivesoftware.smack.packet.Presence)3 ArrayList (java.util.ArrayList)2 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)2 StanzaListener (org.jivesoftware.smack.StanzaListener)2 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)2 Jingle (org.jivesoftware.smackx.jingleold.packet.Jingle)2 MUCInitialPresence (org.jivesoftware.smackx.muc.packet.MUCInitialPresence)2 SmackException (org.jivesoftware.smack.SmackException)1 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 XMPPException (org.jivesoftware.smack.XMPPException)1 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)1 NotFilter (org.jivesoftware.smack.filter.NotFilter)1