mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-09 10:19:41 +02:00
Merge branch '4.4'
This commit is contained in:
commit
4fefa92e40
22 changed files with 288 additions and 132 deletions
|
@ -183,6 +183,10 @@ public abstract class FileTransfer {
|
|||
|
||||
protected void setException(Exception exception) {
|
||||
this.exception = exception;
|
||||
Status currentStatus = getStatus();
|
||||
if (currentStatus != Status.error) {
|
||||
updateStatus(currentStatus, Status.error);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setStatus(Status status) {
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
|||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.filetransfer.FileTransferException.NoAcceptableTransferMechanisms;
|
||||
import org.jivesoftware.smackx.filetransfer.FileTransferException.NoStreamMethodsOfferedException;
|
||||
import org.jivesoftware.smackx.formtypes.FormFieldRegistry;
|
||||
import org.jivesoftware.smackx.si.packet.StreamInitiation;
|
||||
import org.jivesoftware.smackx.xdata.FormField;
|
||||
import org.jivesoftware.smackx.xdata.ListSingleFormField;
|
||||
|
@ -66,6 +67,9 @@ public final class FileTransferNegotiator extends Manager {
|
|||
private static final String STREAM_INIT_PREFIX = "jsi_";
|
||||
|
||||
static final String STREAM_DATA_FIELD_NAME = "stream-method";
|
||||
static {
|
||||
FormFieldRegistry.addLookasideFieldRegistryEntry(STREAM_DATA_FIELD_NAME, FormField.Type.list_single);
|
||||
}
|
||||
|
||||
private static final Random randomGenerator = new Random();
|
||||
|
||||
|
|
|
@ -324,6 +324,10 @@ public class OutgoingFileTransfer extends FileTransfer {
|
|||
transferThread.start();
|
||||
}
|
||||
|
||||
public void setCallback(NegotiationProgress negotiationProcess) {
|
||||
this.callback = negotiationProcess;
|
||||
}
|
||||
|
||||
private void handleXMPPException(XMPPErrorException e) {
|
||||
StanzaError error = e.getStanzaError();
|
||||
if (error != null) {
|
||||
|
|
|
@ -36,6 +36,8 @@ public class FormFieldRegistry {
|
|||
|
||||
private static final Map<String, FormField.Type> CLARK_NOTATION_FIELD_REGISTRY = new ConcurrentHashMap<>();
|
||||
|
||||
private static final Map<String, FormField.Type> LOOKASIDE_FIELD_REGISTRY = new ConcurrentHashMap<>();
|
||||
|
||||
@SuppressWarnings("ReferenceEquality")
|
||||
public static void register(DataForm dataForm) {
|
||||
// TODO: Also allow forms of type 'result'?
|
||||
|
@ -98,11 +100,11 @@ public class FormFieldRegistry {
|
|||
|
||||
public static FormField.Type lookup(String formType, String fieldName) {
|
||||
if (formType == null) {
|
||||
if (!XmlUtil.isClarkNotation(fieldName)) {
|
||||
return null;
|
||||
if (XmlUtil.isClarkNotation(fieldName)) {
|
||||
return CLARK_NOTATION_FIELD_REGISTRY.get(fieldName);
|
||||
}
|
||||
|
||||
return CLARK_NOTATION_FIELD_REGISTRY.get(fieldName);
|
||||
return LOOKASIDE_FIELD_REGISTRY.get(fieldName);
|
||||
}
|
||||
|
||||
synchronized (REGISTRY) {
|
||||
|
@ -122,4 +124,7 @@ public class FormFieldRegistry {
|
|||
return lookup(null, fieldName);
|
||||
}
|
||||
|
||||
public static void addLookasideFieldRegistryEntry(String fieldName, FormField.Type formFieldType) {
|
||||
LOOKASIDE_FIELD_REGISTRY.put(fieldName, formFieldType);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2007 Jive Software. 2020 Florian Schmaus
|
||||
* Copyright 2003-2007 Jive Software. 2020-2021 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -149,6 +149,8 @@ public class MultiUserChat {
|
|||
private EntityFullJid myRoomJid;
|
||||
private StanzaCollector messageCollector;
|
||||
|
||||
private DiscoverInfo mucServiceDiscoInfo;
|
||||
|
||||
/**
|
||||
* Used to signal that the reflected self-presence was received <b>and</b> processed by us.
|
||||
*/
|
||||
|
@ -342,7 +344,8 @@ public class MultiUserChat {
|
|||
private Presence enter(MucEnterConfiguration conf) throws NotConnectedException, NoResponseException,
|
||||
XMPPErrorException, InterruptedException, NotAMucServiceException {
|
||||
final DomainBareJid mucService = room.asDomainBareJid();
|
||||
if (!multiUserChatManager.providesMucService(mucService)) {
|
||||
mucServiceDiscoInfo = multiUserChatManager.getMucServiceDiscoInfo(mucService);
|
||||
if (mucServiceDiscoInfo == null) {
|
||||
throw new NotAMucServiceException(this);
|
||||
}
|
||||
// We enter a room by sending a presence packet where the "to"
|
||||
|
@ -757,6 +760,10 @@ public class MultiUserChat {
|
|||
throw new MucNotJoinedException(this);
|
||||
}
|
||||
|
||||
// TODO: Consider adding a origin-id to the presence, once it is moved form smack-experimental into
|
||||
// smack-extensions, in case the MUC service does not support stable IDs, and modify
|
||||
// reflectedLeavePresenceFilters accordingly.
|
||||
|
||||
// We leave a room by sending a presence packet where the "to"
|
||||
// field is in the form "roomName@service/nickname"
|
||||
Presence leavePresence = connection.getStanzaFactory().buildPresenceStanza()
|
||||
|
@ -764,14 +771,19 @@ public class MultiUserChat {
|
|||
.to(myRoomJid)
|
||||
.build();
|
||||
|
||||
StanzaFilter reflectedLeavePresenceFilter = new AndFilter(
|
||||
StanzaTypeFilter.PRESENCE,
|
||||
new StanzaIdFilter(leavePresence),
|
||||
new OrFilter(
|
||||
new AndFilter(FromMatchesFilter.createFull(myRoomJid), PresenceTypeFilter.UNAVAILABLE, MUCUserStatusCodeFilter.STATUS_110_PRESENCE_TO_SELF),
|
||||
new AndFilter(fromRoomFilter, PresenceTypeFilter.ERROR)
|
||||
)
|
||||
);
|
||||
List<StanzaFilter> reflectedLeavePresenceFilters = new ArrayList<>(3);
|
||||
reflectedLeavePresenceFilters.add(StanzaTypeFilter.PRESENCE);
|
||||
reflectedLeavePresenceFilters.add(new OrFilter(
|
||||
new AndFilter(FromMatchesFilter.createFull(myRoomJid), PresenceTypeFilter.UNAVAILABLE,
|
||||
MUCUserStatusCodeFilter.STATUS_110_PRESENCE_TO_SELF),
|
||||
new AndFilter(fromRoomFilter, PresenceTypeFilter.ERROR)));
|
||||
|
||||
boolean supportsStableId = mucServiceDiscoInfo.containsFeature(MultiUserChatConstants.STABLE_ID_FEATURE);
|
||||
if (supportsStableId) {
|
||||
reflectedLeavePresenceFilters.add(new StanzaIdFilter(leavePresence));
|
||||
}
|
||||
|
||||
StanzaFilter reflectedLeavePresenceFilter = new AndFilter(reflectedLeavePresenceFilters);
|
||||
|
||||
// Reset occupant information first so that we are assume that we left the room even if sendStanza() would
|
||||
// throw.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2020 Florian Schmaus
|
||||
* Copyright 2020-2021 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -20,4 +20,6 @@ public class MultiUserChatConstants {
|
|||
|
||||
public static final String NAMESPACE = "http://jabber.org/protocol/muc";
|
||||
|
||||
public static final String STABLE_ID_FEATURE = NAMESPACE + "#stable_id";
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2014-2020 Florian Schmaus
|
||||
* Copyright © 2014-2021 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -137,7 +137,7 @@ public final class MultiUserChatManager extends Manager {
|
|||
private static final StanzaFilter INVITATION_FILTER = new AndFilter(StanzaTypeFilter.MESSAGE, new StanzaExtensionFilter(new MUCUser()),
|
||||
new NotFilter(MessageTypeFilter.ERROR));
|
||||
|
||||
private static final ExpirationCache<DomainBareJid, Void> KNOWN_MUC_SERVICES = new ExpirationCache<>(
|
||||
private static final ExpirationCache<DomainBareJid, DiscoverInfo> KNOWN_MUC_SERVICES = new ExpirationCache<>(
|
||||
100, 1000 * 60 * 60 * 24);
|
||||
|
||||
private final Set<InvitationListener> invitationsListeners = new CopyOnWriteArraySet<InvitationListener>();
|
||||
|
@ -396,16 +396,23 @@ public final class MultiUserChatManager extends Manager {
|
|||
*/
|
||||
public boolean providesMucService(DomainBareJid domainBareJid) throws NoResponseException,
|
||||
XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
boolean contains = KNOWN_MUC_SERVICES.containsKey(domainBareJid);
|
||||
if (!contains) {
|
||||
if (serviceDiscoveryManager.supportsFeature(domainBareJid,
|
||||
MUCInitialPresence.NAMESPACE)) {
|
||||
KNOWN_MUC_SERVICES.put(domainBareJid, null);
|
||||
return true;
|
||||
}
|
||||
return getMucServiceDiscoInfo(domainBareJid) != null;
|
||||
}
|
||||
|
||||
DiscoverInfo getMucServiceDiscoInfo(DomainBareJid mucServiceAddress)
|
||||
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
DiscoverInfo discoInfo = KNOWN_MUC_SERVICES.get(mucServiceAddress);
|
||||
if (discoInfo != null) {
|
||||
return discoInfo;
|
||||
}
|
||||
|
||||
return contains;
|
||||
discoInfo = serviceDiscoveryManager.discoverInfo(mucServiceAddress);
|
||||
if (!discoInfo.containsFeature(MUCInitialPresence.NAMESPACE)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
KNOWN_MUC_SERVICES.put(mucServiceAddress, discoInfo);
|
||||
return discoInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue