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);
}
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);
}
Aggregations