mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 12:02:05 +01:00
Add SubscribeAnswer.ApproveAndAlsoRequestIfRequired
This commit is contained in:
parent
9a34e9e870
commit
65b4f506dc
7 changed files with 50 additions and 13 deletions
|
@ -46,6 +46,7 @@ import org.jivesoftware.smack.SmackException.AlreadyConnectedException;
|
||||||
import org.jivesoftware.smack.SmackException.AlreadyLoggedInException;
|
import org.jivesoftware.smack.SmackException.AlreadyLoggedInException;
|
||||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||||
|
import org.jivesoftware.smack.SmackException.NotLoggedInException;
|
||||||
import org.jivesoftware.smack.SmackException.ResourceBindingNotOfferedException;
|
import org.jivesoftware.smack.SmackException.ResourceBindingNotOfferedException;
|
||||||
import org.jivesoftware.smack.SmackException.SecurityRequiredByClientException;
|
import org.jivesoftware.smack.SmackException.SecurityRequiredByClientException;
|
||||||
import org.jivesoftware.smack.SmackException.SecurityRequiredException;
|
import org.jivesoftware.smack.SmackException.SecurityRequiredException;
|
||||||
|
@ -1527,7 +1528,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
|
|
||||||
final StanzaListener packetListener = new StanzaListener() {
|
final StanzaListener packetListener = new StanzaListener() {
|
||||||
@Override
|
@Override
|
||||||
public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException {
|
public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException, NotLoggedInException {
|
||||||
boolean removed = removeAsyncStanzaListener(this);
|
boolean removed = removeAsyncStanzaListener(this);
|
||||||
if (!removed) {
|
if (!removed) {
|
||||||
// We lost a race against the "no response" handling runnable. Avoid calling the callback, as the
|
// We lost a race against the "no response" handling runnable. Avoid calling the callback, as the
|
||||||
|
@ -1591,7 +1592,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
public void addOneTimeSyncCallback(final StanzaListener callback, final StanzaFilter packetFilter) {
|
public void addOneTimeSyncCallback(final StanzaListener callback, final StanzaFilter packetFilter) {
|
||||||
final StanzaListener packetListener = new StanzaListener() {
|
final StanzaListener packetListener = new StanzaListener() {
|
||||||
@Override
|
@Override
|
||||||
public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException {
|
public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException, NotLoggedInException {
|
||||||
try {
|
try {
|
||||||
callback.processStanza(packet);
|
callback.processStanza(packet);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package org.jivesoftware.smack;
|
package org.jivesoftware.smack;
|
||||||
|
|
||||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||||
|
import org.jivesoftware.smack.SmackException.NotLoggedInException;
|
||||||
import org.jivesoftware.smack.packet.Stanza;
|
import org.jivesoftware.smack.packet.Stanza;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,7 +50,8 @@ public interface StanzaListener {
|
||||||
* @param packet the stanza(/packet) to process.
|
* @param packet the stanza(/packet) to process.
|
||||||
* @throws NotConnectedException
|
* @throws NotConnectedException
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
|
* @throws NotLoggedInException
|
||||||
*/
|
*/
|
||||||
public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException;
|
public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException, NotLoggedInException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package org.jivesoftware.smackx.bytestreams.ibb;
|
package org.jivesoftware.smackx.bytestreams.ibb;
|
||||||
|
|
||||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||||
|
import org.jivesoftware.smack.SmackException.NotLoggedInException;
|
||||||
import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
|
import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
|
|
||||||
|
@ -65,7 +66,7 @@ class DataListener extends AbstractIqRequestHandler {
|
||||||
ibbSession.processIQPacket(data);
|
ibbSession.processIQPacket(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (NotConnectedException | InterruptedException e) {
|
catch (NotConnectedException | InterruptedException | NotLoggedInException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||||
|
import org.jivesoftware.smack.SmackException.NotLoggedInException;
|
||||||
import org.jivesoftware.smack.StanzaListener;
|
import org.jivesoftware.smack.StanzaListener;
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.filter.AndFilter;
|
import org.jivesoftware.smack.filter.AndFilter;
|
||||||
|
@ -847,8 +848,9 @@ public class InBandBytestreamSession implements BytestreamSession {
|
||||||
* @param data
|
* @param data
|
||||||
* @throws NotConnectedException
|
* @throws NotConnectedException
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
|
* @throws NotLoggedInException
|
||||||
*/
|
*/
|
||||||
public void processIQPacket(Data data) throws NotConnectedException, InterruptedException {
|
public void processIQPacket(Data data) throws NotConnectedException, InterruptedException, NotLoggedInException {
|
||||||
inputStream.dataPacketListener.processStanza(data);
|
inputStream.dataPacketListener.processStanza(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -249,9 +249,10 @@ public final class Roster extends Manager {
|
||||||
connection.addSyncStanzaListener(presencePacketListener, PRESENCE_PACKET_FILTER);
|
connection.addSyncStanzaListener(presencePacketListener, PRESENCE_PACKET_FILTER);
|
||||||
|
|
||||||
connection.addAsyncStanzaListener(new StanzaListener() {
|
connection.addAsyncStanzaListener(new StanzaListener() {
|
||||||
|
@SuppressWarnings("fallthrough")
|
||||||
@Override
|
@Override
|
||||||
public void processStanza(Stanza stanza) throws NotConnectedException,
|
public void processStanza(Stanza stanza) throws NotConnectedException,
|
||||||
InterruptedException {
|
InterruptedException, NotLoggedInException {
|
||||||
Presence presence = (Presence) stanza;
|
Presence presence = (Presence) stanza;
|
||||||
Jid from = presence.getFrom();
|
Jid from = presence.getFrom();
|
||||||
SubscribeAnswer subscribeAnswer = null;
|
SubscribeAnswer subscribeAnswer = null;
|
||||||
|
@ -277,13 +278,26 @@ public final class Roster extends Manager {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (subscribeAnswer == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Presence response;
|
Presence response;
|
||||||
if (subscribeAnswer == SubscribeAnswer.Approve) {
|
switch (subscribeAnswer) {
|
||||||
|
case ApproveAndAlsoRequestIfRequired:
|
||||||
|
BareJid bareFrom = from.asBareJid();
|
||||||
|
RosterUtil.askForSubscriptionIfRequired(Roster.this, bareFrom);
|
||||||
|
// The fall through is intended.
|
||||||
|
case Approve:
|
||||||
response = new Presence(Presence.Type.subscribed);
|
response = new Presence(Presence.Type.subscribed);
|
||||||
}
|
break;
|
||||||
else {
|
case Deny:
|
||||||
response = new Presence(Presence.Type.unsubscribed);
|
response = new Presence(Presence.Type.unsubscribed);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
response.setTo(presence.getFrom());
|
response.setTo(presence.getFrom());
|
||||||
connection.sendStanza(response);
|
connection.sendStanza(response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2015 Florian Schmaus
|
* Copyright 2015-2017 Florian Schmaus
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -23,13 +23,29 @@ import org.jxmpp.jid.Jid;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle incoming requests to subscribe to our presence.
|
* Handle incoming requests to subscribe to our presence. The
|
||||||
|
* {@link #processSubscribe(Jid, Presence)} method may return a subscribe
|
||||||
|
* answer. If no subscribe answer is returned, the next listener will be
|
||||||
|
* notified and asked. If no listener returns an answer, then nothing happens.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public interface SubscribeListener {
|
public interface SubscribeListener {
|
||||||
|
|
||||||
public enum SubscribeAnswer {
|
public enum SubscribeAnswer {
|
||||||
|
/**
|
||||||
|
* Approve the subscription request.
|
||||||
|
*/
|
||||||
Approve,
|
Approve,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Approve the subscription request and also request subscription from the other party if not already subscribed.
|
||||||
|
* @since 4.2.2
|
||||||
|
*/
|
||||||
|
ApproveAndAlsoRequestIfRequired,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deny the subscription request.
|
||||||
|
*/
|
||||||
Deny,
|
Deny,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,7 @@ import org.jivesoftware.smack.SmackException.AlreadyLoggedInException;
|
||||||
import org.jivesoftware.smack.SmackException.ConnectionException;
|
import org.jivesoftware.smack.SmackException.ConnectionException;
|
||||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||||
|
import org.jivesoftware.smack.SmackException.NotLoggedInException;
|
||||||
import org.jivesoftware.smack.SmackException.SecurityRequiredByServerException;
|
import org.jivesoftware.smack.SmackException.SecurityRequiredByServerException;
|
||||||
import org.jivesoftware.smack.StanzaListener;
|
import org.jivesoftware.smack.StanzaListener;
|
||||||
import org.jivesoftware.smack.SynchronizationPoint;
|
import org.jivesoftware.smack.SynchronizationPoint;
|
||||||
|
@ -1887,7 +1888,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
||||||
try {
|
try {
|
||||||
listener.processStanza(ackedStanza);
|
listener.processStanza(ackedStanza);
|
||||||
}
|
}
|
||||||
catch (InterruptedException | NotConnectedException e) {
|
catch (InterruptedException | NotConnectedException | NotLoggedInException e) {
|
||||||
LOGGER.log(Level.FINER, "Received exception", e);
|
LOGGER.log(Level.FINER, "Received exception", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1900,7 +1901,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
||||||
try {
|
try {
|
||||||
listener.processStanza(ackedStanza);
|
listener.processStanza(ackedStanza);
|
||||||
}
|
}
|
||||||
catch (InterruptedException | NotConnectedException e) {
|
catch (InterruptedException | NotConnectedException | NotLoggedInException e) {
|
||||||
LOGGER.log(Level.FINER, "Received exception", e);
|
LOGGER.log(Level.FINER, "Received exception", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue