CarrotChat v2.8.60.240131版本的 MD5 值为:2baf8b9f31830b86b5c5a85ae6b47e05
以下内容为反编译后的 AbstractXMPPConnection.java 源代码,内容仅作参考
package org.jivesoftware.smack;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.StanzaCollector;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.compress.packet.Compress;
import org.jivesoftware.smack.compression.XMPPInputOutputStream;
import org.jivesoftware.smack.debugger.SmackDebugger;
import org.jivesoftware.smack.filter.IQReplyFilter;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.filter.StanzaIdFilter;
import org.jivesoftware.smack.iqrequest.IQRequestHandler;
import org.jivesoftware.smack.packet.Bind;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Mechanisms;
import org.jivesoftware.smack.packet.Nonza;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Session;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.StartTls;
import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.sasl.core.SASLAnonymous;
import org.jivesoftware.smack.util.BoundedThreadPoolExecutor;
import org.jivesoftware.smack.util.DNSUtil;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smack.util.SmackExecutorThreadFactory;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.dns.DNSResolver;
import org.jivesoftware.smack.util.dns.HostAddress;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.EntityFullJid;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.parts.Resourcepart;
import org.jxmpp.util.XmppStringUtils;
import org.xmlpull.v1.XmlPullParser;
public abstract class AbstractXMPPConnection implements XMPPConnection {
static final boolean $assertionsDisabled = false;
private static final Logger LOGGER = Logger.getLogger(AbstractXMPPConnection.class.getName());
private static final AtomicInteger connectionCounter = new AtomicInteger(0);
protected XMPPInputOutputStream compressionHandler;
protected final ConnectionConfiguration config;
protected String host;
protected List<HostAddress> hostAddresses;
private long lastStanzaReceived;
protected int port;
protected Reader reader;
protected final SASLAuthentication saslAuthentication;
protected String streamId;
private String usedPassword;
private Resourcepart usedResource;
private String usedUsername;
protected EntityFullJid user;
protected Writer writer;
private DomainBareJid xmppServiceDomain;
protected final Set<ConnectionListener> connectionListeners = new CopyOnWriteArraySet();
private final Collection<StanzaCollector> collectors = new ConcurrentLinkedQueue();
private final Map<StanzaListener, ListenerWrapper> syncRecvListeners = new LinkedHashMap();
private final Map<StanzaListener, ListenerWrapper> asyncRecvListeners = new LinkedHashMap();
private final Map<StanzaListener, ListenerWrapper> sendListeners = new HashMap();
private final Map<StanzaListener, InterceptorWrapper> interceptors = new HashMap();
protected final Lock connectionLock = new ReentrantLock();
protected final Map<String, ExtensionElement> streamFeatures = new HashMap();
protected boolean connected = false;
private long replyTimeout = SmackConfiguration.getDefaultReplyTimeout();
protected SmackDebugger debugger = null;
protected final SynchronizationPoint<SmackException> tlsHandled = new SynchronizationPoint<>(this, "establishing TLS");
protected final SynchronizationPoint<Exception> lastFeaturesReceived = new SynchronizationPoint<>(this, "last stream features received from server");
protected final SynchronizationPoint<XMPPException> saslFeatureReceived = new SynchronizationPoint<>(this, "SASL mechanisms stream feature from server");
protected final int connectionCounterValue = connectionCounter.getAndIncrement();
private XMPPConnection.FromMode fromMode = XMPPConnection.FromMode.OMITTED;
private ParsingExceptionCallback parsingExceptionCallback = SmackConfiguration.getDefaultParsingExceptionCallback();
private final BoundedThreadPoolExecutor executorService = new BoundedThreadPoolExecutor(1, 1, 0, TimeUnit.SECONDS, 100, new SmackExecutorThreadFactory(this, "Incoming Processor"));
private final ScheduledExecutorService removeCallbacksService = Executors.newSingleThreadScheduledExecutor(new SmackExecutorThreadFactory(this, "Remove Callbacks"));
private final ExecutorService cachedExecutorService = Executors.newCachedThreadPool(new SmackExecutorThreadFactory(this, "Cached Executor"));
private final ExecutorService singleThreadedExecutorService = Executors.newSingleThreadExecutor(new SmackExecutorThreadFactory(this, "Single Threaded Executor"));
protected boolean authenticated = false;
protected boolean wasAuthenticated = false;
private final Map<String, IQRequestHandler> setIqRequestHandler = new HashMap();
private final Map<String, IQRequestHandler> getIqRequestHandler = new HashMap();
private SmackConfiguration.UnknownIqRequestReplyMode unknownIqRequestReplyMode = SmackConfiguration.getUnknownIqRequestReplyMode();
public static class AnonymousClass10 {
static final int[] $SwitchMap$org$jivesoftware$smack$SmackConfiguration$UnknownIqRequestReplyMode;
static final int[] $SwitchMap$org$jivesoftware$smack$XMPPConnection$FromMode;
static final int[] $SwitchMap$org$jivesoftware$smack$iqrequest$IQRequestHandler$Mode;
static final int[] $SwitchMap$org$jivesoftware$smack$packet$IQ$Type;
static {
int[] iArr = new int[IQRequestHandler.Mode.values().length];
$SwitchMap$org$jivesoftware$smack$iqrequest$IQRequestHandler$Mode = iArr;
try {
iArr[IQRequestHandler.Mode.sync.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$org$jivesoftware$smack$iqrequest$IQRequestHandler$Mode[IQRequestHandler.Mode.async.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
int[] iArr2 = new int[SmackConfiguration.UnknownIqRequestReplyMode.values().length];
$SwitchMap$org$jivesoftware$smack$SmackConfiguration$UnknownIqRequestReplyMode = iArr2;
try {
iArr2[SmackConfiguration.UnknownIqRequestReplyMode.doNotReply.ordinal()] = 1;
} catch (NoSuchFieldError unused3) {
}
try {
$SwitchMap$org$jivesoftware$smack$SmackConfiguration$UnknownIqRequestReplyMode[SmackConfiguration.UnknownIqRequestReplyMode.replyFeatureNotImplemented.ordinal()] = 2;
} catch (NoSuchFieldError unused4) {
}
try {
$SwitchMap$org$jivesoftware$smack$SmackConfiguration$UnknownIqRequestReplyMode[SmackConfiguration.UnknownIqRequestReplyMode.replyServiceUnavailable.ordinal()] = 3;
} catch (NoSuchFieldError unused5) {
}
int[] iArr3 = new int[IQ.Type.values().length];
$SwitchMap$org$jivesoftware$smack$packet$IQ$Type = iArr3;
try {
iArr3[IQ.Type.set.ordinal()] = 1;
} catch (NoSuchFieldError unused6) {
}
try {
$SwitchMap$org$jivesoftware$smack$packet$IQ$Type[IQ.Type.get.ordinal()] = 2;
} catch (NoSuchFieldError unused7) {
}
int[] iArr4 = new int[XMPPConnection.FromMode.values().length];
$SwitchMap$org$jivesoftware$smack$XMPPConnection$FromMode = iArr4;
try {
iArr4[XMPPConnection.FromMode.OMITTED.ordinal()] = 1;
} catch (NoSuchFieldError unused8) {
}
try {
$SwitchMap$org$jivesoftware$smack$XMPPConnection$FromMode[XMPPConnection.FromMode.USER.ordinal()] = 2;
} catch (NoSuchFieldError unused9) {
}
try {
$SwitchMap$org$jivesoftware$smack$XMPPConnection$FromMode[XMPPConnection.FromMode.UNCHANGED.ordinal()] = 3;
} catch (NoSuchFieldError unused10) {
}
}
}
public static class InterceptorWrapper {
private final StanzaFilter packetFilter;
private final StanzaListener packetInterceptor;
public InterceptorWrapper(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
this.packetInterceptor = stanzaListener;
this.packetFilter = stanzaFilter;
}
public boolean filterMatches(Stanza stanza) {
StanzaFilter stanzaFilter = this.packetFilter;
return stanzaFilter == null || stanzaFilter.accept(stanza);
}
public StanzaListener getInterceptor() {
return this.packetInterceptor;
}
}
public static class ListenerWrapper {
private final StanzaFilter packetFilter;
private final StanzaListener packetListener;
public ListenerWrapper(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
this.packetListener = stanzaListener;
this.packetFilter = stanzaFilter;
}
public boolean filterMatches(Stanza stanza) {
StanzaFilter stanzaFilter = this.packetFilter;
return stanzaFilter == null || stanzaFilter.accept(stanza);
}
public StanzaListener getListener() {
return this.packetListener;
}
}
static {
SmackConfiguration.getVersion();
}
public AbstractXMPPConnection(ConnectionConfiguration connectionConfiguration) {
this.saslAuthentication = new SASLAuthentication(this, connectionConfiguration);
this.config = connectionConfiguration;
for (ConnectionCreationListener connectionCreationListener : XMPPConnectionRegistry.getConnectionCreationListeners()) {
connectionCreationListener.connectionCreated(this);
}
}
private void firePacketInterceptors(Stanza stanza) {
LinkedList<StanzaListener> linkedList = new LinkedList();
synchronized (this.interceptors) {
for (InterceptorWrapper interceptorWrapper : this.interceptors.values()) {
if (interceptorWrapper.filterMatches(stanza)) {
linkedList.add(interceptorWrapper.getInterceptor());
}
}
}
for (StanzaListener stanzaListener : linkedList) {
try {
stanzaListener.processStanza(stanza);
} catch (Exception e2) {
LOGGER.log(Level.SEVERE, "Packet interceptor threw exception", (Throwable) e2);
}
}
}
@Deprecated
public static void setReplyToUnknownIqDefault(boolean z) {
SmackConfiguration.UnknownIqRequestReplyMode unknownIqRequestReplyMode;
if (z) {
unknownIqRequestReplyMode = SmackConfiguration.UnknownIqRequestReplyMode.replyServiceUnavailable;
} else {
unknownIqRequestReplyMode = SmackConfiguration.UnknownIqRequestReplyMode.doNotReply;
}
SmackConfiguration.setUnknownIqRequestReplyMode(unknownIqRequestReplyMode);
}
@Override
public void addAsyncStanzaListener(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
Objects.requireNonNull(stanzaListener, "Packet listener is null.");
ListenerWrapper listenerWrapper = new ListenerWrapper(stanzaListener, stanzaFilter);
synchronized (this.asyncRecvListeners) {
this.asyncRecvListeners.put(stanzaListener, listenerWrapper);
}
}
@Override
public void addConnectionListener(ConnectionListener connectionListener) {
if (connectionListener == null) {
return;
}
this.connectionListeners.add(connectionListener);
}
@Override
public void addOneTimeSyncCallback(final StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
final StanzaListener stanzaListener2 = new StanzaListener() {
@Override
public void processStanza(Stanza stanza) throws SmackException.NotConnectedException, InterruptedException, SmackException.NotLoggedInException {
try {
stanzaListener.processStanza(stanza);
} finally {
AbstractXMPPConnection.this.removeSyncStanzaListener(this);
}
}
};
addSyncStanzaListener(stanzaListener2, stanzaFilter);
this.removeCallbacksService.schedule(new Runnable() {
@Override
public void run() {
AbstractXMPPConnection.this.removeSyncStanzaListener(stanzaListener2);
}
}, getReplyTimeout(), TimeUnit.MILLISECONDS);
}
@Override
public void addPacketInterceptor(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
Objects.requireNonNull(stanzaListener, "Packet interceptor is null.");
InterceptorWrapper interceptorWrapper = new InterceptorWrapper(stanzaListener, stanzaFilter);
synchronized (this.interceptors) {
this.interceptors.put(stanzaListener, interceptorWrapper);
}
}
@Override
@Deprecated
public void addPacketListener(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
addAsyncStanzaListener(stanzaListener, stanzaFilter);
}
@Override
public void addPacketSendingListener(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
Objects.requireNonNull(stanzaListener, "Packet listener is null.");
ListenerWrapper listenerWrapper = new ListenerWrapper(stanzaListener, stanzaFilter);
synchronized (this.sendListeners) {
this.sendListeners.put(stanzaListener, listenerWrapper);
}
}
protected void addStreamFeature(ExtensionElement extensionElement) {
this.streamFeatures.put(XmppStringUtils.generateKey(extensionElement.getElementName(), extensionElement.getNamespace()), extensionElement);
}
@Override
public void addSyncStanzaListener(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
Objects.requireNonNull(stanzaListener, "Packet listener is null.");
ListenerWrapper listenerWrapper = new ListenerWrapper(stanzaListener, stanzaFilter);
synchronized (this.syncRecvListeners) {
this.syncRecvListeners.put(stanzaListener, listenerWrapper);
}
}
protected void afterFeaturesReceived() throws SmackException.SecurityRequiredException, SmackException.NotConnectedException, InterruptedException {
}
public void afterSuccessfulLogin(boolean z) throws SmackException.NotConnectedException, InterruptedException {
SmackDebugger smackDebugger;
this.authenticated = true;
if (this.config.isDebuggerEnabled() && (smackDebugger = this.debugger) != null) {
smackDebugger.userHasLogged(this.user);
}
callConnectionAuthenticatedListener(z);
if (!this.config.isSendPresence() || z) {
return;
}
sendStanza(new Presence(Presence.Type.available));
}
public final void asyncGo(Runnable runnable) {
this.cachedExecutorService.execute(runnable);
}
public void bindResourceAndEstablishSession(Resourcepart resourcepart) throws XMPPException.XMPPErrorException, SmackException, InterruptedException {
LOGGER.finer("Waiting for last features to be received before continuing with resource binding");
this.lastFeaturesReceived.checkIfSuccessOrWait();
if (hasFeature(Bind.ELEMENT, Bind.NAMESPACE)) {
Bind newSet = Bind.newSet(resourcepart);
EntityFullJid jid = ((Bind) createStanzaCollectorAndSend(new StanzaIdFilter(newSet), newSet).nextResultOrThrow()).getJid();
this.user = jid;
this.xmppServiceDomain = jid.asDomainBareJid();
Session.Feature feature = (Session.Feature) getFeature(Session.ELEMENT, Session.NAMESPACE);
boolean isLegacySessionDisabled = getConfiguration().isLegacySessionDisabled();
if (feature == null || feature.isOptional() || isLegacySessionDisabled) {
return;
}
Session session = new Session();
createStanzaCollectorAndSend(new StanzaIdFilter(session), session).nextResultOrThrow();
return;
}
throw new SmackException.ResourceBindingNotOfferedException();
}
protected void callConnectionAuthenticatedListener(boolean z) {
for (ConnectionListener connectionListener : this.connectionListeners) {
try {
connectionListener.authenticated(this, z);
} catch (Exception e2) {
LOGGER.log(Level.SEVERE, "Exception in authenticated listener", (Throwable) e2);
}
}
}
void callConnectionClosedListener() {
for (ConnectionListener connectionListener : this.connectionListeners) {
try {
connectionListener.connectionClosed();
} catch (Exception e2) {
LOGGER.log(Level.SEVERE, "Error in listener while closing connection", (Throwable) e2);
}
}
}
public void callConnectionClosedOnErrorListener(Exception exc) {
boolean z;
if ((exc instanceof XMPPException.StreamErrorException) && ((XMPPException.StreamErrorException) exc).getStreamError().getCondition() == StreamError.Condition.not_authorized && this.wasAuthenticated) {
z = false;
LOGGER.log(Level.FINE, "Connection closed with not-authorized stream error after it was already authenticated. The account was likely deleted/unregistered on the server");
} else {
z = true;
}
if (z) {
Logger logger = LOGGER;
Level level = Level.WARNING;
logger.log(level, "Connection " + this + " closed with error", (Throwable) exc);
}
for (ConnectionListener connectionListener : this.connectionListeners) {
try {
connectionListener.connectionClosedOnError(exc);
} catch (Exception e2) {
LOGGER.log(Level.SEVERE, "Error in listener while closing connection", (Throwable) e2);
}
}
}
protected void callConnectionConnectedListener() {
for (ConnectionListener connectionListener : this.connectionListeners) {
connectionListener.connected(this);
}
}
public synchronized AbstractXMPPConnection connect() throws SmackException, IOException, XMPPException, InterruptedException {
throwAlreadyConnectedExceptionIfAppropriate();
this.saslAuthentication.init();
this.saslFeatureReceived.init();
this.lastFeaturesReceived.init();
this.tlsHandled.init();
this.streamId = null;
connectInternal();
this.tlsHandled.checkIfSuccessOrWaitOrThrow();
this.saslFeatureReceived.checkIfSuccessOrWaitOrThrow();
if (!isSecureConnection() && getConfiguration().getSecurityMode() == ConnectionConfiguration.SecurityMode.required) {
shutdown();
throw new SmackException.SecurityRequiredByClientException();
}
this.connected = true;
callConnectionConnectedListener();
return this;
}
protected abstract void connectInternal() throws SmackException, IOException, XMPPException, InterruptedException;
@Override
public StanzaCollector createStanzaCollector(StanzaFilter stanzaFilter) {
return createStanzaCollector(StanzaCollector.newConfiguration().setStanzaFilter(stanzaFilter));
}
@Override
public StanzaCollector createStanzaCollectorAndSend(IQ iq) throws SmackException.NotConnectedException, InterruptedException {
return createStanzaCollectorAndSend(new IQReplyFilter(iq, this), iq);
}
public void disconnect() {
try {
disconnect(new Presence(Presence.Type.unavailable));
} catch (SmackException.NotConnectedException e2) {
LOGGER.log(Level.FINEST, "Connection is already disconnected", (Throwable) e2);
}
}
protected void finalize() throws Throwable {
Logger logger = LOGGER;
logger.fine("finalizing " + this + ": Shutting down executor services");
try {
this.executorService.shutdownNow();
this.cachedExecutorService.shutdown();
this.removeCallbacksService.shutdownNow();
this.singleThreadedExecutorService.shutdownNow();
} finally {
try {
} finally {
}
}
}
public void firePacketSendingListeners(final Stanza stanza) {
final LinkedList linkedList = new LinkedList();
synchronized (this.sendListeners) {
for (ListenerWrapper listenerWrapper : this.sendListeners.values()) {
if (listenerWrapper.filterMatches(stanza)) {
linkedList.add(listenerWrapper.getListener());
}
}
}
if (linkedList.isEmpty()) {
return;
}
asyncGo(new Runnable() {
@Override
public void run() {
for (StanzaListener stanzaListener : linkedList) {
try {
stanzaListener.processStanza(stanza);
} catch (Exception e2) {
AbstractXMPPConnection.LOGGER.log(Level.WARNING, "Sending listener threw exception", (Throwable) e2);
}
}
}
});
}
public ConnectionConfiguration getConfiguration() {
return this.config;
}
@Override
public int getConnectionCounter() {
return this.connectionCounterValue;
}
public Lock getConnectionLock() {
return this.connectionLock;
}
@Override
public <F extends ExtensionElement> F getFeature(String str, String str2) {
return (F) this.streamFeatures.get(XmppStringUtils.generateKey(str, str2));
}
@Override
public XMPPConnection.FromMode getFromMode() {
return this.fromMode;
}
@Override
public String getHost() {
return this.host;
}
@Override
public long getLastStanzaReceived() {
return this.lastStanzaReceived;
}
@Override
public long getPacketReplyTimeout() {
return getReplyTimeout();
}
public ParsingExceptionCallback getParsingExceptionCallback() {
return this.parsingExceptionCallback;
}
@Override
public int getPort() {
return this.port;
}
@Override
public long getReplyTimeout() {
return this.replyTimeout;
}
public SASLAuthentication getSASLAuthentication() {
return this.saslAuthentication;
}
@Override
public DomainBareJid getServiceName() {
return getXMPPServiceDomain();
}
@Override
public String getStreamId() {
if (isConnected()) {
return this.streamId;
}
return null;
}
public final String getUsedSaslMechansism() {
return this.saslAuthentication.getNameOfLastUsedSaslMechansism();
}
@Override
public final EntityFullJid getUser() {
return this.user;
}
@Override
public DomainBareJid getXMPPServiceDomain() {
DomainBareJid domainBareJid = this.xmppServiceDomain;
return domainBareJid != null ? domainBareJid : this.config.getXMPPServiceDomain();
}
@Override
public boolean hasFeature(String str, String str2) {
return getFeature(str, str2) != null;
}
public void initDebugger() {
if (this.reader != null && this.writer != null) {
if (this.config.isDebuggerEnabled()) {
if (this.debugger == null) {
this.debugger = SmackConfiguration.createDebugger(this, this.writer, this.reader);
}
SmackDebugger smackDebugger = this.debugger;
if (smackDebugger == null) {
LOGGER.severe("Debugging enabled but could not find debugger class");
return;
}
this.reader = smackDebugger.newConnectionReader(this.reader);
this.writer = this.debugger.newConnectionWriter(this.writer);
return;
}
return;
}
throw new NullPointerException("Reader or writer isn't initialized.");
}
protected void invokeStanzaCollectorsAndNotifyRecvListeners(final Stanza stanza) {
final IQRequestHandler iQRequestHandler;
XMPPError.Condition condition;
if (stanza instanceof IQ) {
final IQ iq = (IQ) stanza;
IQ.Type type = iq.getType();
int[] iArr = AnonymousClass10.$SwitchMap$org$jivesoftware$smack$packet$IQ$Type;
int i = iArr[type.ordinal()];
if (i == 1 || i == 2) {
String generateKey = XmppStringUtils.generateKey(iq.getChildElementName(), iq.getChildElementNamespace());
int i2 = iArr[type.ordinal()];
if (i2 == 1) {
synchronized (this.setIqRequestHandler) {
iQRequestHandler = this.setIqRequestHandler.get(generateKey);
}
} else if (i2 == 2) {
synchronized (this.getIqRequestHandler) {
iQRequestHandler = this.getIqRequestHandler.get(generateKey);
}
} else {
throw new IllegalStateException("Should only encounter IQ type 'get' or 'set'");
}
if (iQRequestHandler == null) {
int i3 = AnonymousClass10.$SwitchMap$org$jivesoftware$smack$SmackConfiguration$UnknownIqRequestReplyMode[this.unknownIqRequestReplyMode.ordinal()];
if (i3 == 1) {
return;
}
if (i3 == 2) {
condition = XMPPError.Condition.feature_not_implemented;
} else if (i3 == 3) {
condition = XMPPError.Condition.service_unavailable;
} else {
throw new AssertionError();
}
try {
sendStanza(IQ.createErrorResponse(iq, XMPPError.getBuilder(condition)));
} catch (InterruptedException | SmackException.NotConnectedException e2) {
LOGGER.log(Level.WARNING, "Exception while sending error IQ to unkown IQ request", e2);
}
} else {
ExecutorService executorService = null;
int i4 = AnonymousClass10.$SwitchMap$org$jivesoftware$smack$iqrequest$IQRequestHandler$Mode[iQRequestHandler.getMode().ordinal()];
if (i4 == 1) {
executorService = this.singleThreadedExecutorService;
} else if (i4 == 2) {
executorService = this.cachedExecutorService;
}
executorService.execute(new Runnable() {
@Override
public void run() {
IQ handleIQRequest = iQRequestHandler.handleIQRequest(iq);
if (handleIQRequest == null) {
return;
}
try {
AbstractXMPPConnection.this.sendStanza(handleIQRequest);
} catch (InterruptedException | SmackException.NotConnectedException e3) {
AbstractXMPPConnection.LOGGER.log(Level.WARNING, "Exception while sending response to IQ request", e3);
}
}
});
return;
}
}
}
final LinkedList<StanzaListener> linkedList = new LinkedList();
synchronized (this.asyncRecvListeners) {
for (ListenerWrapper listenerWrapper : this.asyncRecvListeners.values()) {
if (listenerWrapper.filterMatches(stanza)) {
linkedList.add(listenerWrapper.getListener());
}
}
}
for (final StanzaListener stanzaListener : linkedList) {
asyncGo(new Runnable() {
@Override
public void run() {
try {
stanzaListener.processStanza(stanza);
} catch (Exception e3) {
AbstractXMPPConnection.LOGGER.log(Level.SEVERE, "Exception in async packet listener", (Throwable) e3);
}
}
});
}
for (StanzaCollector stanzaCollector : this.collectors) {
stanzaCollector.processStanza(stanza);
}
linkedList.clear();
synchronized (this.syncRecvListeners) {
for (ListenerWrapper listenerWrapper2 : this.syncRecvListeners.values()) {
if (listenerWrapper2.filterMatches(stanza)) {
linkedList.add(listenerWrapper2.getListener());
}
}
}
this.singleThreadedExecutorService.execute(new Runnable() {
@Override
public void run() {
for (StanzaListener stanzaListener2 : linkedList) {
try {
stanzaListener2.processStanza(stanza);
} catch (SmackException.NotConnectedException e3) {
AbstractXMPPConnection.LOGGER.log(Level.WARNING, "Got not connected exception, aborting", (Throwable) e3);
return;
} catch (Exception e4) {
AbstractXMPPConnection.LOGGER.log(Level.SEVERE, "Exception in packet listener", (Throwable) e4);
}
}
}
});
}
@Override
public final boolean isAnonymous() {
return isAuthenticated() && SASLAnonymous.NAME.equals(getUsedSaslMechansism());
}
@Override
public final boolean isAuthenticated() {
return this.authenticated;
}
@Override
public final boolean isConnected() {
return this.connected;
}
@Override
public abstract boolean isSecureConnection();
@Override
public abstract boolean isUsingCompression();
public synchronized void login() throws XMPPException, SmackException, IOException, InterruptedException {
CharSequence charSequence = this.usedUsername;
if (charSequence == null) {
charSequence = this.config.getUsername();
}
String str = this.usedPassword;
if (str == null) {
str = this.config.getPassword();
}
Resourcepart resourcepart = this.usedResource;
if (resourcepart == null) {
resourcepart = this.config.getResource();
}
login(charSequence, str, resourcepart);
}
protected abstract void loginInternal(String str, String str2, Resourcepart resourcepart) throws XMPPException, SmackException, IOException, InterruptedException;
@Deprecated
protected void notifyReconnection() {
for (ConnectionListener connectionListener : this.connectionListeners) {
try {
connectionListener.reconnectionSuccessful();
} catch (Exception e2) {
LOGGER.log(Level.WARNING, "notifyReconnection()", (Throwable) e2);
}
}
}
public void parseAndProcessStanza(XmlPullParser xmlPullParser) throws Exception {
Stanza stanza;
ParserUtils.assertAtStartTag(xmlPullParser);
int depth = xmlPullParser.getDepth();
try {
stanza = PacketParserUtils.parseStanza(xmlPullParser);
} catch (Exception e2) {
UnparseableStanza unparseableStanza = new UnparseableStanza(PacketParserUtils.parseContentDepth(xmlPullParser, depth), e2);
ParsingExceptionCallback parsingExceptionCallback = getParsingExceptionCallback();
if (parsingExceptionCallback != null) {
parsingExceptionCallback.handleUnparsableStanza(unparseableStanza);
}
stanza = null;
}
ParserUtils.assertAtEndTag(xmlPullParser);
if (stanza != null) {
processStanza(stanza);
}
}
public final void parseFeatures(XmlPullParser xmlPullParser) throws Exception {
this.streamFeatures.clear();
int depth = xmlPullParser.getDepth();
while (true) {
int next = xmlPullParser.next();
char c2 = 3;
if (next == 2 && xmlPullParser.getDepth() == depth + 1) {
ExtensionElement extensionElement = null;
String name = xmlPullParser.getName();
String namespace = xmlPullParser.getNamespace();
name.hashCode();
switch (name.hashCode()) {
case -676919238:
if (name.equals(Mechanisms.ELEMENT)) {
c2 = 0;
break;
}
c2 = 65535;
break;
case 3023933:
if (name.equals(Bind.ELEMENT)) {
c2 = 1;
break;
}
c2 = 65535;
break;
case 1316817241:
if (name.equals(StartTls.ELEMENT)) {
c2 = 2;
break;
}
c2 = 65535;
break;
case 1431984486:
break;
case 1984987798:
if (name.equals(Session.ELEMENT)) {
c2 = 4;
break;
}
c2 = 65535;
break;
default:
c2 = 65535;
break;
}
switch (c2) {
case 0:
extensionElement = new Mechanisms(PacketParserUtils.parseMechanisms(xmlPullParser));
break;
case 1:
extensionElement = Bind.Feature.INSTANCE;
break;
case 2:
extensionElement = PacketParserUtils.parseStartTlsFeature(xmlPullParser);
break;
case 3:
extensionElement = PacketParserUtils.parseCompressionFeature(xmlPullParser);
break;
case 4:
extensionElement = PacketParserUtils.parseSessionFeature(xmlPullParser);
break;
default:
ExtensionElementProvider<ExtensionElement> streamFeatureProvider = ProviderManager.getStreamFeatureProvider(name, namespace);
if (streamFeatureProvider != null) {
extensionElement = (ExtensionElement) streamFeatureProvider.parse(xmlPullParser);
break;
}
break;
}
if (extensionElement != null) {
addStreamFeature(extensionElement);
}
} else if (next == 3 && xmlPullParser.getDepth() == depth) {
if (hasFeature(Mechanisms.ELEMENT, "urn:ietf:params:xml:ns:xmpp-sasl") && (!hasFeature(StartTls.ELEMENT, StartTls.NAMESPACE) || this.config.getSecurityMode() == ConnectionConfiguration.SecurityMode.disabled)) {
this.tlsHandled.reportSuccess();
this.saslFeatureReceived.reportSuccess();
}
if (hasFeature(Bind.ELEMENT, Bind.NAMESPACE) && (!hasFeature(Compress.Feature.ELEMENT, "http://jabber.org/protocol/compress") || !this.config.isCompressionEnabled())) {
this.lastFeaturesReceived.reportSuccess();
}
afterFeaturesReceived();
return;
}
}
}
public List<HostAddress> populateHostAddresses() {
LinkedList linkedList = new LinkedList();
ConnectionConfiguration connectionConfiguration = this.config;
if (connectionConfiguration.hostAddress != null) {
this.hostAddresses = new ArrayList(1);
ConnectionConfiguration connectionConfiguration2 = this.config;
this.hostAddresses.add(new HostAddress(connectionConfiguration2.port, connectionConfiguration2.hostAddress));
} else if (connectionConfiguration.host != null) {
this.hostAddresses = new ArrayList(1);
DNSResolver dNSResolver = DNSUtil.getDNSResolver();
ConnectionConfiguration connectionConfiguration3 = this.config;
HostAddress lookupHostAddress = dNSResolver.lookupHostAddress(connectionConfiguration3.host, connectionConfiguration3.port, linkedList, connectionConfiguration3.getDnssecMode());
if (lookupHostAddress != null) {
this.hostAddresses.add(lookupHostAddress);
}
} else {
this.hostAddresses = DNSUtil.resolveXMPPServiceDomain(connectionConfiguration.getXMPPServiceDomain().toString(), linkedList, this.config.getDnssecMode());
}
return linkedList;
}
protected void processStanza(final Stanza stanza) throws InterruptedException {
this.lastStanzaReceived = System.currentTimeMillis();
this.executorService.executeBlocking(new Runnable() {
@Override
public void run() {
AbstractXMPPConnection.this.invokeStanzaCollectorsAndNotifyRecvListeners(stanza);
}
});
}
@Override
public IQRequestHandler registerIQRequestHandler(IQRequestHandler iQRequestHandler) {
IQRequestHandler put;
IQRequestHandler put2;
String generateKey = XmppStringUtils.generateKey(iQRequestHandler.getElement(), iQRequestHandler.getNamespace());
int i = AnonymousClass10.$SwitchMap$org$jivesoftware$smack$packet$IQ$Type[iQRequestHandler.getType().ordinal()];
if (i == 1) {
synchronized (this.setIqRequestHandler) {
put = this.setIqRequestHandler.put(generateKey, iQRequestHandler);
}
return put;
} else if (i == 2) {
synchronized (this.getIqRequestHandler) {
put2 = this.getIqRequestHandler.put(generateKey, iQRequestHandler);
}
return put2;
} else {
throw new IllegalArgumentException("Only IQ type of 'get' and 'set' allowed");
}
}
@Override
public boolean removeAsyncStanzaListener(StanzaListener stanzaListener) {
boolean z;
synchronized (this.asyncRecvListeners) {
z = this.asyncRecvListeners.remove(stanzaListener) != null;
}
return z;
}
@Override
public void removeConnectionListener(ConnectionListener connectionListener) {
this.connectionListeners.remove(connectionListener);
}
@Override
public void removePacketInterceptor(StanzaListener stanzaListener) {
synchronized (this.interceptors) {
this.interceptors.remove(stanzaListener);
}
}
@Override
@Deprecated
public boolean removePacketListener(StanzaListener stanzaListener) {
return removeAsyncStanzaListener(stanzaListener);
}
@Override
public void removePacketSendingListener(StanzaListener stanzaListener) {
synchronized (this.sendListeners) {
this.sendListeners.remove(stanzaListener);
}
}
@Override
public void removeStanzaCollector(StanzaCollector stanzaCollector) {
this.collectors.remove(stanzaCollector);
}
@Override
public boolean removeSyncStanzaListener(StanzaListener stanzaListener) {
boolean z;
synchronized (this.syncRecvListeners) {
z = this.syncRecvListeners.remove(stanzaListener) != null;
}
return z;
}
public final ScheduledFuture<?> schedule(Runnable runnable, long j, TimeUnit timeUnit) {
return this.removeCallbacksService.schedule(runnable, j, timeUnit);
}
@Override
public void sendIqWithResponseCallback(IQ iq, StanzaListener stanzaListener) throws SmackException.NotConnectedException, InterruptedException {
sendIqWithResponseCallback(iq, stanzaListener, null);
}
@Override
public abstract void sendNonza(Nonza nonza) throws SmackException.NotConnectedException, InterruptedException;
@Override
@Deprecated
public void sendPacket(Stanza stanza) throws SmackException.NotConnectedException, InterruptedException {
sendStanza(stanza);
}
@Override
public void sendStanza(Stanza stanza) throws SmackException.NotConnectedException, InterruptedException {
org.jivesoftware.smack.util.Objects.requireNonNull(stanza, "Stanza must not be null");
throwNotConnectedExceptionIfAppropriate();
int i = AnonymousClass10.$SwitchMap$org$jivesoftware$smack$XMPPConnection$FromMode[this.fromMode.ordinal()];
if (i == 1) {
stanza.setFrom((Jid) null);
} else if (i == 2) {
stanza.setFrom(getUser());
}
firePacketInterceptors(stanza);
sendStanzaInternal(stanza);
}
protected abstract void sendStanzaInternal(Stanza stanza) throws SmackException.NotConnectedException, InterruptedException;
@Override
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter stanzaFilter, StanzaListener stanzaListener) throws SmackException.NotConnectedException, InterruptedException {
sendStanzaWithResponseCallback(stanza, stanzaFilter, stanzaListener, null);
}
@Override
public void setFromMode(XMPPConnection.FromMode fromMode) {
this.fromMode = fromMode;
}
@Override
public void setPacketReplyTimeout(long j) {
setReplyTimeout(j);
}
public void setParsingExceptionCallback(ParsingExceptionCallback parsingExceptionCallback) {
this.parsingExceptionCallback = parsingExceptionCallback;
}
@Override
public void setReplyTimeout(long j) {
this.replyTimeout = j;
}
@Deprecated
public void setReplyToUnknownIq(boolean z) {
SmackConfiguration.UnknownIqRequestReplyMode unknownIqRequestReplyMode;
if (z) {
unknownIqRequestReplyMode = SmackConfiguration.UnknownIqRequestReplyMode.replyServiceUnavailable;
} else {
unknownIqRequestReplyMode = SmackConfiguration.UnknownIqRequestReplyMode.doNotReply;
}
this.unknownIqRequestReplyMode = unknownIqRequestReplyMode;
}
public void setUnknownIqRequestReplyMode(SmackConfiguration.UnknownIqRequestReplyMode unknownIqRequestReplyMode) {
this.unknownIqRequestReplyMode = (SmackConfiguration.UnknownIqRequestReplyMode) org.jivesoftware.smack.util.Objects.requireNonNull(unknownIqRequestReplyMode, "Mode must not be null");
}
public void setWasAuthenticated() {
if (this.wasAuthenticated) {
return;
}
this.wasAuthenticated = this.authenticated;
}
protected abstract void shutdown();
protected void throwAlreadyConnectedExceptionIfAppropriate() throws SmackException.AlreadyConnectedException {
if (isConnected()) {
throw new SmackException.AlreadyConnectedException();
}
}
protected void throwAlreadyLoggedInExceptionIfAppropriate() throws SmackException.AlreadyLoggedInException {
if (isAuthenticated()) {
throw new SmackException.AlreadyLoggedInException();
}
}
protected void throwNotConnectedExceptionIfAppropriate() throws SmackException.NotConnectedException {
throwNotConnectedExceptionIfAppropriate(null);
}
public final String toString() {
EntityFullJid user = getUser();
String obj = user == null ? "not-authenticated" : user.toString();
return getClass().getSimpleName() + '[' + obj + "] (" + getConnectionCounter() + ')';
}
@Override
public final IQRequestHandler unregisterIQRequestHandler(IQRequestHandler iQRequestHandler) {
return unregisterIQRequestHandler(iQRequestHandler.getElement(), iQRequestHandler.getNamespace(), iQRequestHandler.getType());
}
@Override
public void sendIqWithResponseCallback(IQ iq, StanzaListener stanzaListener, ExceptionCallback exceptionCallback) throws SmackException.NotConnectedException, InterruptedException {
sendIqWithResponseCallback(iq, stanzaListener, exceptionCallback, getReplyTimeout());
}
@Override
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter stanzaFilter, StanzaListener stanzaListener, ExceptionCallback exceptionCallback) throws SmackException.NotConnectedException, InterruptedException {
sendStanzaWithResponseCallback(stanza, stanzaFilter, stanzaListener, exceptionCallback, getReplyTimeout());
}
protected void throwNotConnectedExceptionIfAppropriate(String str) throws SmackException.NotConnectedException {
if (!isConnected()) {
throw new SmackException.NotConnectedException(str);
}
}
@Override
public StanzaCollector createStanzaCollector(StanzaCollector.Configuration configuration) {
StanzaCollector stanzaCollector = new StanzaCollector(this, configuration);
this.collectors.add(stanzaCollector);
return stanzaCollector;
}
@Override
public StanzaCollector createStanzaCollectorAndSend(StanzaFilter stanzaFilter, Stanza stanza) throws SmackException.NotConnectedException, InterruptedException {
StanzaCollector createStanzaCollector = createStanzaCollector(stanzaFilter);
try {
sendStanza(stanza);
return createStanzaCollector;
} catch (InterruptedException | RuntimeException | SmackException.NotConnectedException e2) {
createStanzaCollector.cancel();
throw e2;
}
}
public synchronized void disconnect(Presence presence) throws SmackException.NotConnectedException {
try {
sendStanza(presence);
} catch (InterruptedException e2) {
LOGGER.log(Level.FINE, "Was interrupted while sending unavailable presence. Continuing to disconnect the connection", (Throwable) e2);
}
shutdown();
callConnectionClosedListener();
}
@Override
public void sendIqWithResponseCallback(IQ iq, StanzaListener stanzaListener, ExceptionCallback exceptionCallback, long j) throws SmackException.NotConnectedException, InterruptedException {
sendStanzaWithResponseCallback(iq, new IQReplyFilter(iq, this), stanzaListener, exceptionCallback, j);
}
@Override
public void sendStanzaWithResponseCallback(Stanza stanza, final StanzaFilter stanzaFilter, final StanzaListener stanzaListener, final ExceptionCallback exceptionCallback, long j) throws SmackException.NotConnectedException, InterruptedException {
org.jivesoftware.smack.util.Objects.requireNonNull(stanza, "stanza must not be null");
org.jivesoftware.smack.util.Objects.requireNonNull(stanzaFilter, "replyFilter must not be null");
org.jivesoftware.smack.util.Objects.requireNonNull(stanzaListener, "callback must not be null");
final StanzaListener stanzaListener2 = new StanzaListener() {
@Override
public void processStanza(Stanza stanza2) throws SmackException.NotConnectedException, InterruptedException, SmackException.NotLoggedInException {
if (AbstractXMPPConnection.this.removeAsyncStanzaListener(this)) {
try {
XMPPException.XMPPErrorException.ifHasErrorThenThrow(stanza2);
stanzaListener.processStanza(stanza2);
} catch (XMPPException.XMPPErrorException e2) {
ExceptionCallback exceptionCallback2 = exceptionCallback;
if (exceptionCallback2 != null) {
exceptionCallback2.processException(e2);
}
}
}
}
};
this.removeCallbacksService.schedule(new Runnable() {
@Override
public void run() {
Exception newWith;
if (!AbstractXMPPConnection.this.removeAsyncStanzaListener(stanzaListener2) || exceptionCallback == null) {
return;
}
if (!AbstractXMPPConnection.this.isConnected()) {
newWith = new SmackException.NotConnectedException(AbstractXMPPConnection.this, stanzaFilter);
} else {
newWith = SmackException.NoResponseException.newWith(AbstractXMPPConnection.this, stanzaFilter);
}
exceptionCallback.processException(newWith);
}
}, j, TimeUnit.MILLISECONDS);
addAsyncStanzaListener(stanzaListener2, stanzaFilter);
sendStanza(stanza);
}
@Override
public IQRequestHandler unregisterIQRequestHandler(String str, String str2, IQ.Type type) {
IQRequestHandler remove;
IQRequestHandler remove2;
String generateKey = XmppStringUtils.generateKey(str, str2);
int i = AnonymousClass10.$SwitchMap$org$jivesoftware$smack$packet$IQ$Type[type.ordinal()];
if (i == 1) {
synchronized (this.setIqRequestHandler) {
remove = this.setIqRequestHandler.remove(generateKey);
}
return remove;
} else if (i == 2) {
synchronized (this.getIqRequestHandler) {
remove2 = this.getIqRequestHandler.remove(generateKey);
}
return remove2;
} else {
throw new IllegalArgumentException("Only IQ type of 'get' and 'set' allowed");
}
}
public synchronized void login(CharSequence charSequence, String str) throws XMPPException, SmackException, IOException, InterruptedException {
login(charSequence, str, this.config.getResource());
}
public synchronized void login(CharSequence charSequence, String str, Resourcepart resourcepart) throws XMPPException, SmackException, IOException, InterruptedException {
if (!this.config.allowNullOrEmptyUsername) {
StringUtils.requireNotNullOrEmpty(charSequence, "Username must not be null or empty");
}
throwNotConnectedExceptionIfAppropriate("Did you call connect() before login()?");
throwAlreadyLoggedInExceptionIfAppropriate();
String charSequence2 = charSequence != null ? charSequence.toString() : null;
this.usedUsername = charSequence2;
this.usedPassword = str;
this.usedResource = resourcepart;
loginInternal(charSequence2, str, resourcepart);
}
}