mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-25 15:52:06 +01:00
Bump Error Prone version to 2.3.4 and fix new bug patterns
This commit is contained in:
parent
1c0bdfae40
commit
d65f2c932e
19 changed files with 499 additions and 585 deletions
|
@ -283,7 +283,7 @@ tasks.withType(Javadoc) {
|
||||||
testFixturesApi "org.mockito:mockito-core:3.3.3"
|
testFixturesApi "org.mockito:mockito-core:3.3.3"
|
||||||
testImplementation 'com.jamesmurty.utils:java-xmlbuilder:1.2'
|
testImplementation 'com.jamesmurty.utils:java-xmlbuilder:1.2'
|
||||||
|
|
||||||
errorprone 'com.google.errorprone:error_prone_core:2.3.3'
|
errorprone 'com.google.errorprone:error_prone_core:2.3.4'
|
||||||
errorproneJavac('com.google.errorprone:javac:9+181-r4173-1')
|
errorproneJavac('com.google.errorprone:javac:9+181-r4173-1')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -373,17 +373,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
|
|
||||||
protected final AsyncButOrdered<StanzaListener> inOrderListeners = new AsyncButOrdered<>();
|
protected final AsyncButOrdered<StanzaListener> inOrderListeners = new AsyncButOrdered<>();
|
||||||
|
|
||||||
/**
|
|
||||||
* An executor which uses {@link #asyncGoLimited(Runnable)} to limit the number of asynchronously processed runnables
|
|
||||||
* per connection.
|
|
||||||
*/
|
|
||||||
private final Executor limitedExcutor = new Executor() {
|
|
||||||
@Override
|
|
||||||
public void execute(Runnable runnable) {
|
|
||||||
asyncGoLimited(runnable);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The used host to establish the connection to
|
* The used host to establish the connection to
|
||||||
*/
|
*/
|
||||||
|
@ -1524,7 +1513,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
executorService = ASYNC_BUT_ORDERED.asExecutorFor(this);
|
executorService = ASYNC_BUT_ORDERED.asExecutorFor(this);
|
||||||
break;
|
break;
|
||||||
case async:
|
case async:
|
||||||
executorService = limitedExcutor;
|
executorService = this::asyncGoLimited;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
final IQRequestHandler finalIqRequestHandler = iqRequestHandler;
|
final IQRequestHandler finalIqRequestHandler = iqRequestHandler;
|
||||||
|
|
|
@ -38,7 +38,6 @@ import java.util.Set;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.net.ssl.HostnameVerifier;
|
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||||
import javax.net.ssl.SSLSession;
|
import javax.net.ssl.SSLSession;
|
||||||
|
@ -143,14 +142,6 @@ public class TLSUtils {
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HostnameVerifier DOES_NOT_VERIFY_VERIFIER = new HostnameVerifier() {
|
|
||||||
@Override
|
|
||||||
public boolean verify(String hostname, SSLSession session) {
|
|
||||||
// This verifier doesn't verify the hostname, it always returns true.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disable the hostname verification of TLS certificates.
|
* Disable the hostname verification of TLS certificates.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -164,7 +155,9 @@ public class TLSUtils {
|
||||||
* @return the given builder.
|
* @return the given builder.
|
||||||
*/
|
*/
|
||||||
public static <B extends ConnectionConfiguration.Builder<B, ?>> B disableHostnameVerificationForTlsCertificates(B builder) {
|
public static <B extends ConnectionConfiguration.Builder<B, ?>> B disableHostnameVerificationForTlsCertificates(B builder) {
|
||||||
builder.setHostnameVerifier(DOES_NOT_VERIFY_VERIFIER);
|
builder.setHostnameVerifier((hostname, session) -> {
|
||||||
|
return true;
|
||||||
|
});
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
public class DnsUtilTest {
|
public class DnsUtilTest {
|
||||||
|
|
||||||
|
@SuppressWarnings("UnnecessaryAnonymousClass")
|
||||||
private static final SmackDaneProvider DNS_UTIL_TEST_DANE_PROVIDER = new SmackDaneProvider() {
|
private static final SmackDaneProvider DNS_UTIL_TEST_DANE_PROVIDER = new SmackDaneProvider() {
|
||||||
@Override
|
@Override
|
||||||
public SmackDaneVerifier newInstance() {
|
public SmackDaneVerifier newInstance() {
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.jivesoftware.smack.AsyncButOrdered;
|
||||||
import org.jivesoftware.smack.ConnectionCreationListener;
|
import org.jivesoftware.smack.ConnectionCreationListener;
|
||||||
import org.jivesoftware.smack.Manager;
|
import org.jivesoftware.smack.Manager;
|
||||||
import org.jivesoftware.smack.SmackException;
|
import org.jivesoftware.smack.SmackException;
|
||||||
import org.jivesoftware.smack.StanzaListener;
|
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.XMPPConnectionRegistry;
|
import org.jivesoftware.smack.XMPPConnectionRegistry;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
|
@ -68,9 +67,7 @@ public final class FallbackIndicationManager extends Manager {
|
||||||
private final StanzaFilter fallbackIndicationElementFilter = new AndFilter(StanzaTypeFilter.MESSAGE,
|
private final StanzaFilter fallbackIndicationElementFilter = new AndFilter(StanzaTypeFilter.MESSAGE,
|
||||||
new StanzaExtensionFilter(FallbackIndicationElement.ELEMENT, FallbackIndicationElement.NAMESPACE));
|
new StanzaExtensionFilter(FallbackIndicationElement.ELEMENT, FallbackIndicationElement.NAMESPACE));
|
||||||
|
|
||||||
private final StanzaListener fallbackIndicationElementListener = new StanzaListener() {
|
private void fallbackIndicationElementListener(Stanza packet) {
|
||||||
@Override
|
|
||||||
public void processStanza(Stanza packet) {
|
|
||||||
Message message = (Message) packet;
|
Message message = (Message) packet;
|
||||||
FallbackIndicationElement indicator = FallbackIndicationElement.fromMessage(message);
|
FallbackIndicationElement indicator = FallbackIndicationElement.fromMessage(message);
|
||||||
String body = message.getBody();
|
String body = message.getBody();
|
||||||
|
@ -80,11 +77,10 @@ public final class FallbackIndicationManager extends Manager {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
private FallbackIndicationManager(XMPPConnection connection) {
|
private FallbackIndicationManager(XMPPConnection connection) {
|
||||||
super(connection);
|
super(connection);
|
||||||
connection.addAsyncStanzaListener(fallbackIndicationElementListener, fallbackIndicationElementFilter);
|
connection.addAsyncStanzaListener(this::fallbackIndicationElementListener, fallbackIndicationElementFilter);
|
||||||
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(FallbackIndicationElement.NAMESPACE);
|
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(FallbackIndicationElement.NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -307,7 +307,9 @@ public final class HttpFileUploadManager extends Manager {
|
||||||
public URL uploadFile(InputStream inputStream, String fileName, long fileSize, UploadProgressListener listener) throws XMPPErrorException, InterruptedException, SmackException, IOException {
|
public URL uploadFile(InputStream inputStream, String fileName, long fileSize, UploadProgressListener listener) throws XMPPErrorException, InterruptedException, SmackException, IOException {
|
||||||
Objects.requireNonNull(inputStream, "Input Stream cannot be null");
|
Objects.requireNonNull(inputStream, "Input Stream cannot be null");
|
||||||
Objects.requireNonNull(fileName, "Filename Stream cannot be null");
|
Objects.requireNonNull(fileName, "Filename Stream cannot be null");
|
||||||
Objects.requireNonNull(fileSize, "Filesize Stream cannot be null");
|
if (fileSize < 0) {
|
||||||
|
throw new IllegalArgumentException("File size cannot be negative");
|
||||||
|
}
|
||||||
final Slot slot = requestSlot(fileName, fileSize, "application/octet-stream");
|
final Slot slot = requestSlot(fileName, fileSize, "application/octet-stream");
|
||||||
upload(inputStream, fileSize, slot, listener);
|
upload(inputStream, fileSize, slot, listener);
|
||||||
return slot.getGetUrl();
|
return slot.getGetUrl();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2018 Paul Schaub
|
* Copyright 2018 Paul Schaub, 2020 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.
|
||||||
|
@ -29,10 +29,6 @@ import org.jivesoftware.smack.filter.NotFilter;
|
||||||
import org.jivesoftware.smack.filter.StanzaExtensionFilter;
|
import org.jivesoftware.smack.filter.StanzaExtensionFilter;
|
||||||
import org.jivesoftware.smack.filter.StanzaFilter;
|
import org.jivesoftware.smack.filter.StanzaFilter;
|
||||||
import org.jivesoftware.smack.filter.ToTypeFilter;
|
import org.jivesoftware.smack.filter.ToTypeFilter;
|
||||||
import org.jivesoftware.smack.packet.Message;
|
|
||||||
import org.jivesoftware.smack.packet.MessageBuilder;
|
|
||||||
import org.jivesoftware.smack.util.Consumer;
|
|
||||||
import org.jivesoftware.smack.util.Predicate;
|
|
||||||
|
|
||||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
import org.jivesoftware.smackx.sid.element.OriginIdElement;
|
import org.jivesoftware.smackx.sid.element.OriginIdElement;
|
||||||
|
@ -62,14 +58,8 @@ public final class StableUniqueStanzaIdManager extends Manager {
|
||||||
// Filter that filters for messages with an origin id
|
// Filter that filters for messages with an origin id
|
||||||
private static final StanzaFilter ORIGIN_ID_FILTER = new StanzaExtensionFilter(OriginIdElement.ELEMENT, NAMESPACE);
|
private static final StanzaFilter ORIGIN_ID_FILTER = new StanzaExtensionFilter(OriginIdElement.ELEMENT, NAMESPACE);
|
||||||
|
|
||||||
// Listener for outgoing stanzas that adds origin-ids to outgoing stanzas.
|
|
||||||
private static final Consumer<MessageBuilder> ADD_ORIGIN_ID_INTERCEPTOR = mb -> OriginIdElement.addOriginId(mb);
|
|
||||||
|
|
||||||
// We need a filter for outgoing messages that do not carry an origin-id already.
|
// We need a filter for outgoing messages that do not carry an origin-id already.
|
||||||
private static final StanzaFilter ADD_ORIGIN_ID_FILTER = new AndFilter(OUTGOING_FILTER, new NotFilter(ORIGIN_ID_FILTER));
|
private static final StanzaFilter ADD_ORIGIN_ID_FILTER = new AndFilter(OUTGOING_FILTER, new NotFilter(ORIGIN_ID_FILTER));
|
||||||
private static final Predicate<Message> ADD_ORIGIN_ID_PREDICATE = m -> {
|
|
||||||
return ADD_ORIGIN_ID_FILTER.accept(m);
|
|
||||||
};
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
|
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
|
||||||
|
@ -113,7 +103,7 @@ public final class StableUniqueStanzaIdManager extends Manager {
|
||||||
* Start appending origin-id elements to outgoing stanzas and add the feature to disco.
|
* Start appending origin-id elements to outgoing stanzas and add the feature to disco.
|
||||||
*/
|
*/
|
||||||
public synchronized void enable() {
|
public synchronized void enable() {
|
||||||
connection().addMessageInterceptor(ADD_ORIGIN_ID_INTERCEPTOR, ADD_ORIGIN_ID_PREDICATE);
|
connection().addMessageInterceptor(OriginIdElement::addTo, ADD_ORIGIN_ID_FILTER::accept);
|
||||||
ServiceDiscoveryManager.getInstanceFor(connection()).addFeature(NAMESPACE);
|
ServiceDiscoveryManager.getInstanceFor(connection()).addFeature(NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +112,7 @@ public final class StableUniqueStanzaIdManager extends Manager {
|
||||||
*/
|
*/
|
||||||
public synchronized void disable() {
|
public synchronized void disable() {
|
||||||
ServiceDiscoveryManager.getInstanceFor(connection()).removeFeature(NAMESPACE);
|
ServiceDiscoveryManager.getInstanceFor(connection()).removeFeature(NAMESPACE);
|
||||||
connection().removeMessageInterceptor(ADD_ORIGIN_ID_INTERCEPTOR);
|
connection().removeMessageInterceptor(OriginIdElement::addTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class OriginIdElement extends StableAndUniqueIdElement {
|
||||||
*
|
*
|
||||||
* @param message message.
|
* @param message message.
|
||||||
* @return the added origin-id element.
|
* @return the added origin-id element.
|
||||||
* @deprecated use {@link #addOriginId(MessageBuilder)} instead.
|
* @deprecated use {@link #addTo(MessageBuilder)} instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
// TODO: Remove in Smack 4.5.
|
// TODO: Remove in Smack 4.5.
|
||||||
|
@ -57,7 +57,7 @@ public class OriginIdElement extends StableAndUniqueIdElement {
|
||||||
* @param messageBuilder the message builder to add an origin ID to.
|
* @param messageBuilder the message builder to add an origin ID to.
|
||||||
* @return the added origin-id element.
|
* @return the added origin-id element.
|
||||||
*/
|
*/
|
||||||
public static OriginIdElement addOriginId(MessageBuilder messageBuilder) {
|
public static OriginIdElement addTo(MessageBuilder messageBuilder) {
|
||||||
OriginIdElement originId = new OriginIdElement();
|
OriginIdElement originId = new OriginIdElement();
|
||||||
messageBuilder.addExtension(originId);
|
messageBuilder.addExtension(originId);
|
||||||
// TODO: Find solution to have both the originIds stanzaId and a nice to look at incremental stanzaID.
|
// TODO: Find solution to have both the originIds stanzaId and a nice to look at incremental stanzaID.
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class StableUniqueStanzaIdTest extends SmackTestSuite {
|
||||||
assertFalse(OriginIdElement.hasOriginId(message));
|
assertFalse(OriginIdElement.hasOriginId(message));
|
||||||
assertFalse(StanzaIdElement.hasStanzaId(message));
|
assertFalse(StanzaIdElement.hasStanzaId(message));
|
||||||
|
|
||||||
OriginIdElement.addOriginId(messageBuilder);
|
OriginIdElement.addTo(messageBuilder);
|
||||||
|
|
||||||
message = messageBuilder.build();
|
message = messageBuilder.build();
|
||||||
assertTrue(OriginIdElement.hasOriginId(message));
|
assertTrue(OriginIdElement.hasOriginId(message));
|
||||||
|
|
|
@ -54,7 +54,6 @@ import org.jivesoftware.smack.packet.PresenceBuilder;
|
||||||
import org.jivesoftware.smack.packet.Stanza;
|
import org.jivesoftware.smack.packet.Stanza;
|
||||||
import org.jivesoftware.smack.roster.AbstractPresenceEventListener;
|
import org.jivesoftware.smack.roster.AbstractPresenceEventListener;
|
||||||
import org.jivesoftware.smack.roster.Roster;
|
import org.jivesoftware.smack.roster.Roster;
|
||||||
import org.jivesoftware.smack.util.Consumer;
|
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||||
|
|
||||||
|
@ -312,11 +311,11 @@ public final class EntityCapsManager extends Manager {
|
||||||
// Intercept presence packages and add caps data when intended.
|
// Intercept presence packages and add caps data when intended.
|
||||||
// XEP-0115 specifies that a client SHOULD include entity capabilities
|
// XEP-0115 specifies that a client SHOULD include entity capabilities
|
||||||
// with every presence notification it sends.
|
// with every presence notification it sends.
|
||||||
private final Consumer<PresenceBuilder> presenceInterceptor = presenceBuilder -> {
|
private void addCapsExtension(PresenceBuilder presenceBuilder) {
|
||||||
CapsVersionAndHash capsVersionAndHash = getCapsVersionAndHash();
|
CapsVersionAndHash capsVersionAndHash = getCapsVersionAndHash();
|
||||||
CapsExtension caps = new CapsExtension(entityNode, capsVersionAndHash.version, capsVersionAndHash.hash);
|
CapsExtension caps = new CapsExtension(entityNode, capsVersionAndHash.version, capsVersionAndHash.hash);
|
||||||
presenceBuilder.overrideExtension(caps);
|
presenceBuilder.overrideExtension(caps);
|
||||||
};
|
}
|
||||||
|
|
||||||
private EntityCapsManager(XMPPConnection connection) {
|
private EntityCapsManager(XMPPConnection connection) {
|
||||||
super(connection);
|
super(connection);
|
||||||
|
@ -402,7 +401,7 @@ public final class EntityCapsManager extends Manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void enableEntityCaps() {
|
public synchronized void enableEntityCaps() {
|
||||||
connection().addPresenceInterceptor(presenceInterceptor, p -> {
|
connection().addPresenceInterceptor(this::addCapsExtension, p -> {
|
||||||
return PresenceTypeFilter.AVAILABLE.accept(p);
|
return PresenceTypeFilter.AVAILABLE.accept(p);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -415,7 +414,7 @@ public final class EntityCapsManager extends Manager {
|
||||||
entityCapsEnabled = false;
|
entityCapsEnabled = false;
|
||||||
sdm.removeFeature(NAMESPACE);
|
sdm.removeFeature(NAMESPACE);
|
||||||
|
|
||||||
connection().removePresenceInterceptor(presenceInterceptor);
|
connection().removePresenceInterceptor(this::addCapsExtension);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean entityCapsEnabled() {
|
public boolean entityCapsEnabled() {
|
||||||
|
|
|
@ -517,7 +517,7 @@ public final class AdHocCommandManager extends Manager {
|
||||||
|
|
||||||
private boolean sessionSweeperScheduled;
|
private boolean sessionSweeperScheduled;
|
||||||
|
|
||||||
private final Runnable sessionSweeper = () -> {
|
private void sessionSweeper() {
|
||||||
final long currentTime = System.currentTimeMillis();
|
final long currentTime = System.currentTimeMillis();
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
for (Iterator<Entry<String, LocalCommand>> it = executingCommands.entrySet().iterator(); it.hasNext();) {
|
for (Iterator<Entry<String, LocalCommand>> it = executingCommands.entrySet().iterator(); it.hasNext();) {
|
||||||
|
@ -553,7 +553,7 @@ public final class AdHocCommandManager extends Manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionSweeperScheduled = true;
|
sessionSweeperScheduled = true;
|
||||||
schedule(sessionSweeper, 10, TimeUnit.SECONDS);
|
schedule(this::sessionSweeper, 10, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -390,7 +390,7 @@ public final class PingManager extends Manager {
|
||||||
int nextPingIn = pingInterval - delta;
|
int nextPingIn = pingInterval - delta;
|
||||||
LOGGER.fine("Scheduling ServerPingTask in " + nextPingIn + " seconds (pingInterval="
|
LOGGER.fine("Scheduling ServerPingTask in " + nextPingIn + " seconds (pingInterval="
|
||||||
+ pingInterval + ", delta=" + delta + ")");
|
+ pingInterval + ", delta=" + delta + ")");
|
||||||
nextAutomaticPing = schedule(pingServerRunnable, nextPingIn, TimeUnit.SECONDS);
|
nextAutomaticPing = schedule(this::pingServerIfNecessary, nextPingIn, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,13 +467,4 @@ public final class PingManager extends Manager {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Runnable pingServerRunnable = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
LOGGER.fine("ServerPingTask run()");
|
|
||||||
pingServerIfNecessary();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2013-2014 Georg Lukas, 2015-2019 Florian Schmaus
|
* Copyright 2013-2014 Georg Lukas, 2015-2020 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.
|
||||||
|
@ -38,11 +38,9 @@ import org.jivesoftware.smack.filter.StanzaExtensionFilter;
|
||||||
import org.jivesoftware.smack.filter.StanzaFilter;
|
import org.jivesoftware.smack.filter.StanzaFilter;
|
||||||
import org.jivesoftware.smack.filter.StanzaTypeFilter;
|
import org.jivesoftware.smack.filter.StanzaTypeFilter;
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.Message;
|
||||||
import org.jivesoftware.smack.packet.MessageBuilder;
|
|
||||||
import org.jivesoftware.smack.packet.Stanza;
|
import org.jivesoftware.smack.packet.Stanza;
|
||||||
import org.jivesoftware.smack.packet.StanzaBuilder;
|
import org.jivesoftware.smack.packet.StanzaBuilder;
|
||||||
import org.jivesoftware.smack.roster.Roster;
|
import org.jivesoftware.smack.roster.Roster;
|
||||||
import org.jivesoftware.smack.util.Consumer;
|
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
|
|
||||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
|
@ -273,8 +271,6 @@ public final class DeliveryReceiptManager extends Manager {
|
||||||
);
|
);
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
|
||||||
private static final Consumer<MessageBuilder> AUTO_ADD_DELIVERY_RECEIPT_REQUESTS_LISTENER = mb -> DeliveryReceiptRequest.addTo(mb);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables automatic requests of delivery receipts for outgoing messages of
|
* Enables automatic requests of delivery receipts for outgoing messages of
|
||||||
* {@link org.jivesoftware.smack.packet.Message.Type#normal}, {@link org.jivesoftware.smack.packet.Message.Type#chat} or {@link org.jivesoftware.smack.packet.Message.Type#headline}, and
|
* {@link org.jivesoftware.smack.packet.Message.Type#normal}, {@link org.jivesoftware.smack.packet.Message.Type#chat} or {@link org.jivesoftware.smack.packet.Message.Type#headline}, and
|
||||||
|
@ -284,7 +280,7 @@ public final class DeliveryReceiptManager extends Manager {
|
||||||
* @see #dontAutoAddDeliveryReceiptRequests()
|
* @see #dontAutoAddDeliveryReceiptRequests()
|
||||||
*/
|
*/
|
||||||
public void autoAddDeliveryReceiptRequests() {
|
public void autoAddDeliveryReceiptRequests() {
|
||||||
connection().addMessageInterceptor(AUTO_ADD_DELIVERY_RECEIPT_REQUESTS_LISTENER, m -> {
|
connection().addMessageInterceptor(DeliveryReceiptRequest::addTo, m -> {
|
||||||
return MESSAGES_TO_REQUEST_RECEIPTS_FOR.accept(m);
|
return MESSAGES_TO_REQUEST_RECEIPTS_FOR.accept(m);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -296,7 +292,7 @@ public final class DeliveryReceiptManager extends Manager {
|
||||||
* @see #autoAddDeliveryReceiptRequests()
|
* @see #autoAddDeliveryReceiptRequests()
|
||||||
*/
|
*/
|
||||||
public void dontAutoAddDeliveryReceiptRequests() {
|
public void dontAutoAddDeliveryReceiptRequests() {
|
||||||
connection().removeMessageInterceptor(AUTO_ADD_DELIVERY_RECEIPT_REQUESTS_LISTENER);
|
connection().removeMessageInterceptor(DeliveryReceiptRequest::addTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2013-2015 the original author or authors
|
* Copyright 2013-2015 the original author or authors, 2020 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.
|
||||||
|
@ -17,7 +17,6 @@
|
||||||
package org.jivesoftware.smack.roster.rosterstore;
|
package org.jivesoftware.smack.roster.rosterstore;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -56,16 +55,11 @@ public final class DirectoryRosterStore implements RosterStore {
|
||||||
private static final String STORE_ID = "DEFAULT_ROSTER_STORE";
|
private static final String STORE_ID = "DEFAULT_ROSTER_STORE";
|
||||||
private static final Logger LOGGER = Logger.getLogger(DirectoryRosterStore.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(DirectoryRosterStore.class.getName());
|
||||||
|
|
||||||
private static final FileFilter rosterDirFilter = new FileFilter() {
|
private static boolean rosterDirFilter(File file) {
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean accept(File file) {
|
|
||||||
String name = file.getName();
|
String name = file.getName();
|
||||||
return name.startsWith(ENTRY_PREFIX);
|
return name.startsWith(ENTRY_PREFIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param baseDir TODO javadoc me please
|
* @param baseDir TODO javadoc me please
|
||||||
* will be the directory where all roster entries are stored. One
|
* will be the directory where all roster entries are stored. One
|
||||||
|
@ -122,7 +116,7 @@ public final class DirectoryRosterStore implements RosterStore {
|
||||||
public List<Item> getEntries() {
|
public List<Item> getEntries() {
|
||||||
List<Item> entries = new ArrayList<>();
|
List<Item> entries = new ArrayList<>();
|
||||||
|
|
||||||
for (File file : fileDir.listFiles(rosterDirFilter)) {
|
for (File file : fileDir.listFiles(DirectoryRosterStore::rosterDirFilter)) {
|
||||||
Item entry = readEntry(file);
|
Item entry = readEntry(file);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
// Roster directory store corrupt. Abort and signal this by returning null.
|
// Roster directory store corrupt. Abort and signal this by returning null.
|
||||||
|
@ -168,7 +162,7 @@ public final class DirectoryRosterStore implements RosterStore {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean resetEntries(Collection<Item> items, String version) {
|
public boolean resetEntries(Collection<Item> items, String version) {
|
||||||
for (File file : fileDir.listFiles(rosterDirFilter)) {
|
for (File file : fileDir.listFiles(DirectoryRosterStore::rosterDirFilter)) {
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
for (Item item : items) {
|
for (Item item : items) {
|
||||||
|
|
|
@ -21,7 +21,6 @@ import org.jivesoftware.smack.chat2.ChatManager;
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.Message;
|
||||||
|
|
||||||
import org.jivesoftware.smackx.chatstates.ChatState;
|
import org.jivesoftware.smackx.chatstates.ChatState;
|
||||||
import org.jivesoftware.smackx.chatstates.ChatStateListener;
|
|
||||||
import org.jivesoftware.smackx.chatstates.ChatStateManager;
|
import org.jivesoftware.smackx.chatstates.ChatStateManager;
|
||||||
|
|
||||||
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
|
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
|
||||||
|
@ -34,25 +33,19 @@ public class ChatStateIntegrationTest extends AbstractSmackIntegrationTest {
|
||||||
|
|
||||||
// Listener for composing chat state
|
// Listener for composing chat state
|
||||||
private final SimpleResultSyncPoint composingSyncPoint = new SimpleResultSyncPoint();
|
private final SimpleResultSyncPoint composingSyncPoint = new SimpleResultSyncPoint();
|
||||||
private final ChatStateListener composingListener = new ChatStateListener() {
|
private void composingListener(Chat chat, ChatState state, Message message) {
|
||||||
@Override
|
|
||||||
public void stateChanged(Chat chat, ChatState state, Message message) {
|
|
||||||
if (state.equals(ChatState.composing)) {
|
if (state.equals(ChatState.composing)) {
|
||||||
composingSyncPoint.signal();
|
composingSyncPoint.signal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
// Listener for active chat state
|
// Listener for active chat state
|
||||||
private final SimpleResultSyncPoint activeSyncPoint = new SimpleResultSyncPoint();
|
private final SimpleResultSyncPoint activeSyncPoint = new SimpleResultSyncPoint();
|
||||||
private final ChatStateListener activeListener = new ChatStateListener() {
|
private void activeListener(Chat chat, ChatState state, Message message) {
|
||||||
@Override
|
|
||||||
public void stateChanged(Chat chat, ChatState state, Message message) {
|
|
||||||
if (state.equals(ChatState.active)) {
|
if (state.equals(ChatState.active)) {
|
||||||
activeSyncPoint.signal();
|
activeSyncPoint.signal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
public ChatStateIntegrationTest(SmackIntegrationTestEnvironment environment) {
|
public ChatStateIntegrationTest(SmackIntegrationTestEnvironment environment) {
|
||||||
|
@ -65,8 +58,8 @@ public class ChatStateIntegrationTest extends AbstractSmackIntegrationTest {
|
||||||
ChatStateManager manTwo = ChatStateManager.getInstance(conTwo);
|
ChatStateManager manTwo = ChatStateManager.getInstance(conTwo);
|
||||||
|
|
||||||
// Add chatState listeners.
|
// Add chatState listeners.
|
||||||
manTwo.addChatStateListener(composingListener);
|
manTwo.addChatStateListener(this::composingListener);
|
||||||
manTwo.addChatStateListener(activeListener);
|
manTwo.addChatStateListener(this::activeListener);
|
||||||
|
|
||||||
Chat chatOne = ChatManager.getInstanceFor(conOne)
|
Chat chatOne = ChatManager.getInstanceFor(conOne)
|
||||||
.chatWith(conTwo.getUser().asEntityBareJid());
|
.chatWith(conTwo.getUser().asEntityBareJid());
|
||||||
|
@ -86,7 +79,7 @@ public class ChatStateIntegrationTest extends AbstractSmackIntegrationTest {
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public void cleanup() {
|
public void cleanup() {
|
||||||
ChatStateManager manTwo = ChatStateManager.getInstance(conTwo);
|
ChatStateManager manTwo = ChatStateManager.getInstance(conTwo);
|
||||||
manTwo.removeChatStateListener(composingListener);
|
manTwo.removeChatStateListener(this::composingListener);
|
||||||
manTwo.removeChatStateListener(activeListener);
|
manTwo.removeChatStateListener(this::activeListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2017 Paul Schaub
|
* Copyright 2017 Paul Schaub, 2020 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.
|
||||||
|
@ -37,17 +37,14 @@ import java.util.logging.Logger;
|
||||||
import org.jivesoftware.smack.ConnectionListener;
|
import org.jivesoftware.smack.ConnectionListener;
|
||||||
import org.jivesoftware.smack.Manager;
|
import org.jivesoftware.smack.Manager;
|
||||||
import org.jivesoftware.smack.SmackException;
|
import org.jivesoftware.smack.SmackException;
|
||||||
import org.jivesoftware.smack.StanzaListener;
|
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.filter.StanzaFilter;
|
|
||||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.Message;
|
||||||
import org.jivesoftware.smack.packet.MessageBuilder;
|
import org.jivesoftware.smack.packet.MessageBuilder;
|
||||||
import org.jivesoftware.smack.packet.Stanza;
|
import org.jivesoftware.smack.packet.Stanza;
|
||||||
import org.jivesoftware.smack.util.Async;
|
import org.jivesoftware.smack.util.Async;
|
||||||
|
|
||||||
import org.jivesoftware.smackx.carbons.CarbonCopyReceivedListener;
|
|
||||||
import org.jivesoftware.smackx.carbons.CarbonManager;
|
import org.jivesoftware.smackx.carbons.CarbonManager;
|
||||||
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
|
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
|
||||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
|
@ -74,7 +71,6 @@ import org.jivesoftware.smackx.omemo.trust.OmemoFingerprint;
|
||||||
import org.jivesoftware.smackx.omemo.trust.OmemoTrustCallback;
|
import org.jivesoftware.smackx.omemo.trust.OmemoTrustCallback;
|
||||||
import org.jivesoftware.smackx.omemo.trust.TrustState;
|
import org.jivesoftware.smackx.omemo.trust.TrustState;
|
||||||
import org.jivesoftware.smackx.omemo.util.MessageOrOmemoMessage;
|
import org.jivesoftware.smackx.omemo.util.MessageOrOmemoMessage;
|
||||||
import org.jivesoftware.smackx.pep.PepListener;
|
|
||||||
import org.jivesoftware.smackx.pep.PepManager;
|
import org.jivesoftware.smackx.pep.PepManager;
|
||||||
import org.jivesoftware.smackx.pubsub.EventElement;
|
import org.jivesoftware.smackx.pubsub.EventElement;
|
||||||
import org.jivesoftware.smackx.pubsub.ItemsExtension;
|
import org.jivesoftware.smackx.pubsub.ItemsExtension;
|
||||||
|
@ -897,23 +893,23 @@ public final class OmemoManager extends Manager {
|
||||||
CarbonManager carbonManager = CarbonManager.getInstanceFor(connection());
|
CarbonManager carbonManager = CarbonManager.getInstanceFor(connection());
|
||||||
|
|
||||||
// Remove listeners to avoid them getting added twice
|
// Remove listeners to avoid them getting added twice
|
||||||
connection().removeAsyncStanzaListener(internalOmemoMessageStanzaListener);
|
connection().removeAsyncStanzaListener(this::internalOmemoMessageStanzaListener);
|
||||||
carbonManager.removeCarbonCopyReceivedListener(internalOmemoCarbonCopyListener);
|
carbonManager.removeCarbonCopyReceivedListener(this::internalOmemoCarbonCopyListener);
|
||||||
pepManager.removePepListener(deviceListUpdateListener);
|
pepManager.removePepListener(this::deviceListUpdateListener);
|
||||||
|
|
||||||
// Add listeners
|
// Add listeners
|
||||||
pepManager.addPepListener(deviceListUpdateListener);
|
pepManager.addPepListener(this::deviceListUpdateListener);
|
||||||
connection().addAsyncStanzaListener(internalOmemoMessageStanzaListener, omemoMessageStanzaFilter);
|
connection().addAsyncStanzaListener(this::internalOmemoMessageStanzaListener, OmemoManager::isOmemoMessage);
|
||||||
carbonManager.addCarbonCopyReceivedListener(internalOmemoCarbonCopyListener);
|
carbonManager.addCarbonCopyReceivedListener(this::internalOmemoCarbonCopyListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove active stanza listeners needed for OMEMO.
|
* Remove active stanza listeners needed for OMEMO.
|
||||||
*/
|
*/
|
||||||
public void stopStanzaAndPEPListeners() {
|
public void stopStanzaAndPEPListeners() {
|
||||||
PepManager.getInstanceFor(connection()).removePepListener(deviceListUpdateListener);
|
PepManager.getInstanceFor(connection()).removePepListener(this::deviceListUpdateListener);
|
||||||
connection().removeAsyncStanzaListener(internalOmemoMessageStanzaListener);
|
connection().removeAsyncStanzaListener(this::internalOmemoMessageStanzaListener);
|
||||||
CarbonManager.getInstanceFor(connection()).removeCarbonCopyReceivedListener(internalOmemoCarbonCopyListener);
|
CarbonManager.getInstanceFor(connection()).removeCarbonCopyReceivedListener(this::internalOmemoCarbonCopyListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -961,10 +957,7 @@ public final class OmemoManager extends Manager {
|
||||||
/**
|
/**
|
||||||
* StanzaListener that listens for incoming Stanzas which contain OMEMO elements.
|
* StanzaListener that listens for incoming Stanzas which contain OMEMO elements.
|
||||||
*/
|
*/
|
||||||
private final StanzaListener internalOmemoMessageStanzaListener = new StanzaListener() {
|
private void internalOmemoMessageStanzaListener(final Stanza packet) {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void processStanza(final Stanza packet) {
|
|
||||||
Async.go(new Runnable() {
|
Async.go(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -977,20 +970,17 @@ public final class OmemoManager extends Manager {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CarbonCopyListener that listens for incoming carbon copies which contain OMEMO elements.
|
* CarbonCopyListener that listens for incoming carbon copies which contain OMEMO elements.
|
||||||
*/
|
*/
|
||||||
private final CarbonCopyReceivedListener internalOmemoCarbonCopyListener = new CarbonCopyReceivedListener() {
|
private void internalOmemoCarbonCopyListener(final CarbonExtension.Direction direction,
|
||||||
@Override
|
|
||||||
public void onCarbonCopyReceived(final CarbonExtension.Direction direction,
|
|
||||||
final Message carbonCopy,
|
final Message carbonCopy,
|
||||||
final Message wrappingMessage) {
|
final Message wrappingMessage) {
|
||||||
Async.go(new Runnable() {
|
Async.go(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (omemoMessageStanzaFilter.accept(carbonCopy)) {
|
if (isOmemoMessage(carbonCopy)) {
|
||||||
try {
|
try {
|
||||||
getOmemoService().onOmemoCarbonCopyReceived(direction, carbonCopy, wrappingMessage,
|
getOmemoService().onOmemoCarbonCopyReceived(direction, carbonCopy, wrappingMessage,
|
||||||
new LoggedInOmemoManager(OmemoManager.this));
|
new LoggedInOmemoManager(OmemoManager.this));
|
||||||
|
@ -1001,15 +991,11 @@ public final class OmemoManager extends Manager {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PEPListener that listens for OMEMO deviceList updates.
|
* PEPListener that listens for OMEMO deviceList updates.
|
||||||
*/
|
*/
|
||||||
private final PepListener deviceListUpdateListener = new PepListener() {
|
private void deviceListUpdateListener(EntityBareJid from, EventElement event, Message message) {
|
||||||
@Override
|
|
||||||
public void eventReceived(EntityBareJid from, EventElement event, Message message) {
|
|
||||||
|
|
||||||
// Unknown sender, no more work to do.
|
// Unknown sender, no more work to do.
|
||||||
if (from == null) {
|
if (from == null) {
|
||||||
// TODO: This DOES happen for some reason. Figure out when...
|
// TODO: This DOES happen for some reason. Figure out when...
|
||||||
|
@ -1071,17 +1057,13 @@ public final class OmemoManager extends Manager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StanzaFilter that filters messages containing a OMEMO element.
|
* StanzaFilter that filters messages containing a OMEMO element.
|
||||||
*/
|
*/
|
||||||
private final StanzaFilter omemoMessageStanzaFilter = new StanzaFilter() {
|
private static boolean isOmemoMessage(Stanza stanza) {
|
||||||
@Override
|
|
||||||
public boolean accept(Stanza stanza) {
|
|
||||||
return stanza instanceof Message && OmemoManager.stanzaContainsOmemoElement(stanza);
|
return stanza instanceof Message && OmemoManager.stanzaContainsOmemoElement(stanza);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Guard class which ensures that the wrapped OmemoManager knows its BareJid.
|
* Guard class which ensures that the wrapped OmemoManager knows its BareJid.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2017-2019 Florian Schmaus, 2018 Paul Schaub.
|
* Copyright 2017-2020 Florian Schmaus, 2018 Paul Schaub.
|
||||||
*
|
*
|
||||||
* 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.
|
||||||
|
@ -39,7 +39,6 @@ import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.chat2.Chat;
|
import org.jivesoftware.smack.chat2.Chat;
|
||||||
import org.jivesoftware.smack.chat2.ChatManager;
|
import org.jivesoftware.smack.chat2.ChatManager;
|
||||||
import org.jivesoftware.smack.chat2.IncomingChatMessageListener;
|
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.Message;
|
||||||
import org.jivesoftware.smack.util.Async;
|
import org.jivesoftware.smack.util.Async;
|
||||||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||||
|
@ -180,7 +179,7 @@ public final class OpenPgpManager extends Manager {
|
||||||
*/
|
*/
|
||||||
private OpenPgpManager(XMPPConnection connection) {
|
private OpenPgpManager(XMPPConnection connection) {
|
||||||
super(connection);
|
super(connection);
|
||||||
ChatManager.getInstanceFor(connection).addIncomingListener(incomingOpenPgpMessageListener);
|
ChatManager.getInstanceFor(connection).addIncomingListener(this::incomingChatMessageListener);
|
||||||
pepManager = PepManager.getInstanceFor(connection);
|
pepManager = PepManager.getInstanceFor(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +278,7 @@ public final class OpenPgpManager extends Manager {
|
||||||
publishPublicKey(pepManager, pubkeyElement, primaryFingerprint);
|
publishPublicKey(pepManager, pubkeyElement, primaryFingerprint);
|
||||||
|
|
||||||
// Subscribe to public key changes
|
// Subscribe to public key changes
|
||||||
PepManager.getInstanceFor(connection()).addPepListener(metadataListener);
|
PepManager.getInstanceFor(connection()).addPepListener(this::metadataListener);
|
||||||
ServiceDiscoveryManager.getInstanceFor(connection())
|
ServiceDiscoveryManager.getInstanceFor(connection())
|
||||||
.addFeature(PEP_NODE_PUBLIC_KEYS_NOTIFY);
|
.addFeature(PEP_NODE_PUBLIC_KEYS_NOTIFY);
|
||||||
}
|
}
|
||||||
|
@ -381,7 +380,7 @@ public final class OpenPgpManager extends Manager {
|
||||||
* Remove the metadata listener. This method is mainly used in tests.
|
* Remove the metadata listener. This method is mainly used in tests.
|
||||||
*/
|
*/
|
||||||
public void stopMetadataListener() {
|
public void stopMetadataListener() {
|
||||||
PepManager.getInstanceFor(connection()).removePepListener(metadataListener);
|
PepManager.getInstanceFor(connection()).removePepListener(this::metadataListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -502,9 +501,7 @@ public final class OpenPgpManager extends Manager {
|
||||||
*
|
*
|
||||||
* @see <a href="https://xmpp.org/extensions/xep-0373.html#pubsub-notifications">XEP-0373 §4.4</a>
|
* @see <a href="https://xmpp.org/extensions/xep-0373.html#pubsub-notifications">XEP-0373 §4.4</a>
|
||||||
*/
|
*/
|
||||||
private final PepListener metadataListener = new PepListener() {
|
private void metadataListener(final EntityBareJid from, final EventElement event, final Message message) {
|
||||||
@Override
|
|
||||||
public void eventReceived(final EntityBareJid from, final EventElement event, final Message message) {
|
|
||||||
if (PEP_NODE_PUBLIC_KEYS.equals(event.getEvent().getNode())) {
|
if (PEP_NODE_PUBLIC_KEYS.equals(event.getEvent().getNode())) {
|
||||||
final BareJid contact = from.asBareJid();
|
final BareJid contact = from.asBareJid();
|
||||||
LOGGER.log(Level.INFO, "Received OpenPGP metadata update from " + contact);
|
LOGGER.log(Level.INFO, "Received OpenPGP metadata update from " + contact);
|
||||||
|
@ -520,7 +517,6 @@ public final class OpenPgpManager extends Manager {
|
||||||
}, "ProcessOXMetadata");
|
}, "ProcessOXMetadata");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
private void processPublicKeysListElement(BareJid contact, PublicKeysListElement listElement) {
|
private void processPublicKeysListElement(BareJid contact, PublicKeysListElement listElement) {
|
||||||
OpenPgpContact openPgpContact = getOpenPgpContact(contact.asEntityBareJidIfPossible());
|
OpenPgpContact openPgpContact = getOpenPgpContact(contact.asEntityBareJidIfPossible());
|
||||||
|
@ -548,10 +544,7 @@ public final class OpenPgpManager extends Manager {
|
||||||
return provider.decryptAndOrVerify(element, getOpenPgpSelf(), sender);
|
return provider.decryptAndOrVerify(element, getOpenPgpSelf(), sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final IncomingChatMessageListener incomingOpenPgpMessageListener =
|
private void incomingChatMessageListener(final EntityBareJid from, final Message message, Chat chat) {
|
||||||
new IncomingChatMessageListener() {
|
|
||||||
@Override
|
|
||||||
public void newIncomingMessage(final EntityBareJid from, final Message message, Chat chat) {
|
|
||||||
Async.go(new Runnable() {
|
Async.go(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -578,7 +571,8 @@ public final class OpenPgpManager extends Manager {
|
||||||
|
|
||||||
if (contentElement instanceof SigncryptElement) {
|
if (contentElement instanceof SigncryptElement) {
|
||||||
for (SigncryptElementReceivedListener l : signcryptElementReceivedListeners) {
|
for (SigncryptElementReceivedListener l : signcryptElementReceivedListeners) {
|
||||||
l.signcryptElementReceived(contact, message, (SigncryptElement) contentElement, decrypted.getMetadata());
|
l.signcryptElementReceived(contact, message, (SigncryptElement) contentElement,
|
||||||
|
decrypted.getMetadata());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -592,7 +586,8 @@ public final class OpenPgpManager extends Manager {
|
||||||
|
|
||||||
if (contentElement instanceof CryptElement) {
|
if (contentElement instanceof CryptElement) {
|
||||||
for (CryptElementReceivedListener l : cryptElementReceivedListeners) {
|
for (CryptElementReceivedListener l : cryptElementReceivedListeners) {
|
||||||
l.cryptElementReceived(contact, message, (CryptElement) contentElement, decrypted.getMetadata());
|
l.cryptElementReceived(contact, message, (CryptElement) contentElement,
|
||||||
|
decrypted.getMetadata());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -603,7 +598,6 @@ public final class OpenPgpManager extends Manager {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a {@link PubkeyElement} which contains the OpenPGP public key of {@code owner} which belongs to
|
* Create a {@link PubkeyElement} which contains the OpenPGP public key of {@code owner} which belongs to
|
||||||
|
|
|
@ -44,7 +44,6 @@ import org.jivesoftware.smackx.ox.crypto.OpenPgpElementAndMetadata;
|
||||||
import org.jivesoftware.smackx.ox.element.OpenPgpContentElement;
|
import org.jivesoftware.smackx.ox.element.OpenPgpContentElement;
|
||||||
import org.jivesoftware.smackx.ox.element.OpenPgpElement;
|
import org.jivesoftware.smackx.ox.element.OpenPgpElement;
|
||||||
import org.jivesoftware.smackx.ox.element.SigncryptElement;
|
import org.jivesoftware.smackx.ox.element.SigncryptElement;
|
||||||
import org.jivesoftware.smackx.ox.listener.SigncryptElementReceivedListener;
|
|
||||||
|
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.jxmpp.jid.BareJid;
|
import org.jxmpp.jid.BareJid;
|
||||||
|
@ -127,7 +126,7 @@ public final class OXInstantMessagingManager extends Manager {
|
||||||
private OXInstantMessagingManager(final XMPPConnection connection) {
|
private OXInstantMessagingManager(final XMPPConnection connection) {
|
||||||
super(connection);
|
super(connection);
|
||||||
openPgpManager = OpenPgpManager.getInstanceFor(connection);
|
openPgpManager = OpenPgpManager.getInstanceFor(connection);
|
||||||
openPgpManager.registerSigncryptReceivedListener(signcryptElementReceivedListener);
|
openPgpManager.registerSigncryptReceivedListener(this::signcryptElementReceivedListener);
|
||||||
announceSupportForOxInstantMessaging();
|
announceSupportForOxInstantMessaging();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,12 +357,9 @@ public final class OXInstantMessagingManager extends Manager {
|
||||||
message.setBody("This message is encrypted using XEP-0374: OpenPGP for XMPP: Instant Messaging.");
|
message.setBody("This message is encrypted using XEP-0374: OpenPGP for XMPP: Instant Messaging.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private final SigncryptElementReceivedListener signcryptElementReceivedListener = new SigncryptElementReceivedListener() {
|
private void signcryptElementReceivedListener(OpenPgpContact contact, Message originalMessage, SigncryptElement signcryptElement, OpenPgpMetadata metadata) {
|
||||||
@Override
|
|
||||||
public void signcryptElementReceived(OpenPgpContact contact, Message originalMessage, SigncryptElement signcryptElement, OpenPgpMetadata metadata) {
|
|
||||||
for (OxMessageListener listener : oxMessageListeners) {
|
for (OxMessageListener listener : oxMessageListeners) {
|
||||||
listener.newIncomingOxMessage(contact, originalMessage, signcryptElement, metadata);
|
listener.newIncomingOxMessage(contact, originalMessage, signcryptElement, metadata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.net.InetSocketAddress;
|
||||||
import java.nio.Buffer;
|
import java.nio.Buffer;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.ClosedChannelException;
|
import java.nio.channels.ClosedChannelException;
|
||||||
|
import java.nio.channels.SelectableChannel;
|
||||||
import java.nio.channels.SelectionKey;
|
import java.nio.channels.SelectionKey;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
||||||
|
@ -61,7 +62,6 @@ import org.jivesoftware.smack.SmackException.SecurityRequiredByServerException;
|
||||||
import org.jivesoftware.smack.SmackException.SmackWrappedException;
|
import org.jivesoftware.smack.SmackException.SmackWrappedException;
|
||||||
import org.jivesoftware.smack.SmackFuture;
|
import org.jivesoftware.smack.SmackFuture;
|
||||||
import org.jivesoftware.smack.SmackFuture.InternalSmackFuture;
|
import org.jivesoftware.smack.SmackFuture.InternalSmackFuture;
|
||||||
import org.jivesoftware.smack.SmackReactor.ChannelSelectedCallback;
|
|
||||||
import org.jivesoftware.smack.SmackReactor.SelectionKeyAttachment;
|
import org.jivesoftware.smack.SmackReactor.SelectionKeyAttachment;
|
||||||
import org.jivesoftware.smack.XMPPException.FailedNonzaException;
|
import org.jivesoftware.smack.XMPPException.FailedNonzaException;
|
||||||
import org.jivesoftware.smack.XmppInputOutputFilter;
|
import org.jivesoftware.smack.XmppInputOutputFilter;
|
||||||
|
@ -280,8 +280,7 @@ public class XmppTcpTransportModule extends ModularXmppClientToServerConnectionM
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final ChannelSelectedCallback channelSelectedCallback =
|
private void onChannelSelected(SelectableChannel selectedChannel, SelectionKey selectedSelectionKey) {
|
||||||
(selectedChannel, selectedSelectionKey) -> {
|
|
||||||
assert selectionKey == null || selectionKey == selectedSelectionKey;
|
assert selectionKey == null || selectionKey == selectedSelectionKey;
|
||||||
SocketChannel selectedSocketChannel = (SocketChannel) selectedChannel;
|
SocketChannel selectedSocketChannel = (SocketChannel) selectedChannel;
|
||||||
// We are *always* interested in OP_READ.
|
// We are *always* interested in OP_READ.
|
||||||
|
@ -488,7 +487,6 @@ public class XmppTcpTransportModule extends ModularXmppClientToServerConnectionM
|
||||||
+ " for " + this + ". This probably means that the TCP connection was terminated.");
|
+ " for " + this + ". This probably means that the TCP connection was terminated.");
|
||||||
// According to the socket channel javadoc section about "asynchronous reads" a socket channel's
|
// According to the socket channel javadoc section about "asynchronous reads" a socket channel's
|
||||||
// read() may return -1 if the input side of a socket is shut down.
|
// read() may return -1 if the input side of a socket is shut down.
|
||||||
|
|
||||||
// Note that we do not call notifyConnectionError() here because the connection may be
|
// Note that we do not call notifyConnectionError() here because the connection may be
|
||||||
// cleanly shutdown which would also cause read() to return '-1. I assume that this socket
|
// cleanly shutdown which would also cause read() to return '-1. I assume that this socket
|
||||||
// will be selected again, on which read() would throw an IOException, which will be catched
|
// will be selected again, on which read() would throw an IOException, which will be catched
|
||||||
|
@ -567,7 +565,7 @@ public class XmppTcpTransportModule extends ModularXmppClientToServerConnectionM
|
||||||
}
|
}
|
||||||
|
|
||||||
connectionInternal.setInterestOps(selectionKey, newInterestedOps);
|
connectionInternal.setInterestOps(selectionKey, newInterestedOps);
|
||||||
};
|
}
|
||||||
|
|
||||||
private void handleReadWriteIoException(IOException e) {
|
private void handleReadWriteIoException(IOException e) {
|
||||||
if (e instanceof ClosedChannelException && !tcpNioTransport.isConnected()) {
|
if (e instanceof ClosedChannelException && !tcpNioTransport.isConnected()) {
|
||||||
|
@ -677,7 +675,7 @@ public class XmppTcpTransportModule extends ModularXmppClientToServerConnectionM
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Stats getStats() {
|
public XmppTcpTransportModule.Stats getStats() {
|
||||||
return XmppTcpTransportModule.this.getStats();
|
return XmppTcpTransportModule.this.getStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -774,7 +772,7 @@ public class XmppTcpTransportModule extends ModularXmppClientToServerConnectionM
|
||||||
remoteAddress = (InetSocketAddress) socketChannel.socket().getRemoteSocketAddress();
|
remoteAddress = (InetSocketAddress) socketChannel.socket().getRemoteSocketAddress();
|
||||||
|
|
||||||
selectionKey = connectionInternal.registerWithSelector(socketChannel, SelectionKey.OP_READ,
|
selectionKey = connectionInternal.registerWithSelector(socketChannel, SelectionKey.OP_READ,
|
||||||
channelSelectedCallback);
|
XmppTcpTransportModule.this::onChannelSelected);
|
||||||
selectionKeyAttachment = (SelectionKeyAttachment) selectionKey.attachment();
|
selectionKeyAttachment = (SelectionKeyAttachment) selectionKey.attachment();
|
||||||
|
|
||||||
connectionInternal.setTransport(tcpNioTransport);
|
connectionInternal.setTransport(tcpNioTransport);
|
||||||
|
@ -1316,7 +1314,7 @@ public class XmppTcpTransportModule extends ModularXmppClientToServerConnectionM
|
||||||
pendingOutputFilterData = true;
|
pendingOutputFilterData = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
channelSelectedCallback.onChannelSelected(channel, key);
|
onChannelSelected(channel, key);
|
||||||
} finally {
|
} finally {
|
||||||
channelSelectedCallbackLock.unlock();
|
channelSelectedCallbackLock.unlock();
|
||||||
}
|
}
|
||||||
|
@ -1347,7 +1345,7 @@ public class XmppTcpTransportModule extends ModularXmppClientToServerConnectionM
|
||||||
return CollectionUtil.removeUntil(buffers, b -> b.hasRemaining());
|
return CollectionUtil.removeUntil(buffers, b -> b.hasRemaining());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stats getStats() {
|
public XmppTcpTransportModule.Stats getStats() {
|
||||||
return new Stats(this);
|
return new Stats(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue