正在查看: Housing v14.7.8 应用的 AbstractXMPPConnection.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Housing v14.7.8 应用的 AbstractXMPPConnection.java JAVA 源代码文件
本页面展示 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.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
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.PacketCollector;
import org.jivesoftware.smack.SmackException;
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.PlainStreamElement;
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.XMPPError;
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
import org.jivesoftware.smack.parsing.UnparsablePacket;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.util.BoundedThreadPoolExecutor;
import org.jivesoftware.smack.util.DNSUtil;
import org.jivesoftware.smack.util.Objects;
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.HostAddress;
import org.jxmpp.util.XmppStringUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
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);
private static boolean replyToUnknownIqDefault;
protected boolean authenticated;
private final ExecutorService cachedExecutorService;
protected XMPPInputOutputStream compressionHandler;
protected final ConnectionConfiguration config;
protected final int connectionCounterValue;
private final BoundedThreadPoolExecutor executorService;
private XMPPConnection.FromMode fromMode;
private final Map<String, IQRequestHandler> getIqRequestHandler;
protected String host;
protected List<HostAddress> hostAddresses;
private long lastStanzaReceived;
private ParsingExceptionCallback parsingExceptionCallback;
protected int port;
protected Reader reader;
private final ScheduledExecutorService removeCallbacksService;
private boolean replyToUnkownIq;
private String serviceName;
private final Map<String, IQRequestHandler> setIqRequestHandler;
private final ExecutorService singleThreadedExecutorService;
protected String streamId;
private String usedPassword;
private String usedResource;
private String usedUsername;
protected String user;
protected boolean wasAuthenticated;
protected Writer writer;
protected final Set<ConnectionListener> connectionListeners = new CopyOnWriteArraySet();
private final Collection<PacketCollector> 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 packetReplyTimeout = SmackConfiguration.getDefaultPacketReplyTimeout();
protected SmackDebugger debugger = null;
protected final SynchronizationPoint<Exception> lastFeaturesReceived = new SynchronizationPoint<>(this);
protected final SynchronizationPoint<SmackException> saslFeatureReceived = new SynchronizationPoint<>(this);
protected SASLAuthentication saslAuthentication = new SASLAuthentication(this);
public static class AnonymousClass9 {
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[IQ.Type.values().length];
$SwitchMap$org$jivesoftware$smack$packet$IQ$Type = iArr2;
try {
iArr2[IQ.Type.set.ordinal()] = 1;
} catch (NoSuchFieldError unused3) {
}
try {
$SwitchMap$org$jivesoftware$smack$packet$IQ$Type[IQ.Type.get.ordinal()] = 2;
} catch (NoSuchFieldError unused4) {
}
int[] iArr3 = new int[XMPPConnection.FromMode.values().length];
$SwitchMap$org$jivesoftware$smack$XMPPConnection$FromMode = iArr3;
try {
iArr3[XMPPConnection.FromMode.OMITTED.ordinal()] = 1;
} catch (NoSuchFieldError unused5) {
}
try {
$SwitchMap$org$jivesoftware$smack$XMPPConnection$FromMode[XMPPConnection.FromMode.USER.ordinal()] = 2;
} catch (NoSuchFieldError unused6) {
}
try {
$SwitchMap$org$jivesoftware$smack$XMPPConnection$FromMode[XMPPConnection.FromMode.UNCHANGED.ordinal()] = 3;
} catch (NoSuchFieldError unused7) {
}
}
}
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 class ListenerNotification implements Runnable {
private final Stanza packet;
public ListenerNotification(Stanza stanza) {
this.packet = stanza;
}
@Override
public void run() {
AbstractXMPPConnection.this.invokePacketCollectorsAndNotifyRecvListeners(this.packet);
}
}
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();
replyToUnknownIqDefault = true;
}
public AbstractXMPPConnection(ConnectionConfiguration connectionConfiguration) {
int andIncrement = connectionCounter.getAndIncrement();
this.connectionCounterValue = andIncrement;
this.fromMode = XMPPConnection.FromMode.OMITTED;
this.parsingExceptionCallback = SmackConfiguration.getDefaultParsingExceptionCallback();
this.executorService = new BoundedThreadPoolExecutor(1, 1, 0L, TimeUnit.SECONDS, 100, new SmackExecutorThreadFactory(andIncrement, "Incoming Processor"));
this.removeCallbacksService = Executors.newSingleThreadScheduledExecutor(new SmackExecutorThreadFactory(andIncrement, "Remove Callbacks"));
this.cachedExecutorService = Executors.newCachedThreadPool(new SmackExecutorThreadFactory(andIncrement, "Cached Executor"));
this.singleThreadedExecutorService = Executors.newSingleThreadExecutor(new SmackExecutorThreadFactory(getConnectionCounter(), "Single Threaded Executor"));
this.authenticated = false;
this.wasAuthenticated = false;
this.setIqRequestHandler = new HashMap();
this.getIqRequestHandler = new HashMap();
this.replyToUnkownIq = replyToUnknownIqDefault;
this.config = connectionConfiguration;
}
private void addStreamFeature(ExtensionElement extensionElement) {
this.streamFeatures.put(XmppStringUtils.generateKey(extensionElement.getElementName(), extensionElement.getNamespace()), extensionElement);
}
private void firePacketInterceptors(Stanza stanza) {
LinkedList linkedList = new LinkedList();
synchronized (this.interceptors) {
try {
for (InterceptorWrapper interceptorWrapper : this.interceptors.values()) {
if (interceptorWrapper.filterMatches(stanza)) {
linkedList.add(interceptorWrapper.getInterceptor());
}
}
} catch (Throwable th) {
throw th;
}
}
Iterator it = linkedList.iterator();
while (it.hasNext()) {
try {
((StanzaListener) it.next()).processPacket(stanza);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Packet interceptor threw exception", (Throwable) e);
}
}
}
public static Collection<ConnectionCreationListener> getConnectionCreationListeners() {
return XMPPConnectionRegistry.getConnectionCreationListeners();
}
public static void setReplyToUnknownIqDefault(boolean z) {
replyToUnknownIqDefault = z;
}
@Override
public void addAsyncStanzaListener(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
if (stanzaListener == null) {
throw new NullPointerException("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 processPacket(Stanza stanza) throws SmackException.NotConnectedException {
try {
stanzaListener.processPacket(stanza);
} finally {
AbstractXMPPConnection.this.removeSyncStanzaListener(this);
}
}
};
addSyncStanzaListener(stanzaListener2, stanzaFilter);
this.removeCallbacksService.schedule(new Runnable() {
@Override
public void run() {
AbstractXMPPConnection.this.removeSyncStanzaListener(stanzaListener2);
}
}, getPacketReplyTimeout(), TimeUnit.MILLISECONDS);
}
@Override
public void addPacketInterceptor(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
if (stanzaListener == null) {
throw new NullPointerException("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) {
if (stanzaListener == null) {
throw new NullPointerException("Packet listener is null.");
}
ListenerWrapper listenerWrapper = new ListenerWrapper(stanzaListener, stanzaFilter);
synchronized (this.sendListeners) {
this.sendListeners.put(stanzaListener, listenerWrapper);
}
}
@Override
public void addSyncStanzaListener(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
if (stanzaListener == null) {
throw new NullPointerException("Packet listener is null.");
}
ListenerWrapper listenerWrapper = new ListenerWrapper(stanzaListener, stanzaFilter);
synchronized (this.syncRecvListeners) {
this.syncRecvListeners.put(stanzaListener, listenerWrapper);
}
}
public void afterFeaturesReceived() throws SmackException.SecurityRequiredException, SmackException.NotConnectedException {
}
public void afterSuccessfulLogin(boolean z) throws SmackException.NotConnectedException {
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(String str) throws XMPPException.XMPPErrorException, IOException, SmackException {
LOGGER.finer("Waiting for last features to be received before continuing with resource binding");
this.lastFeaturesReceived.checkIfSuccessOrWait();
if (!hasFeature(Bind.ELEMENT, Bind.NAMESPACE)) {
throw new SmackException.ResourceBindingNotOfferedException();
}
Bind newSet = Bind.newSet(str);
String jid = ((Bind) createPacketCollectorAndSend(new StanzaIdFilter(newSet), newSet).nextResultOrThrow()).getJid();
this.user = jid;
this.serviceName = XmppStringUtils.parseDomain(jid);
Session.Feature feature = (Session.Feature) getFeature("session", Session.NAMESPACE);
if (feature == null || feature.isOptional() || getConfiguration().isLegacySessionDisabled()) {
return;
}
Session session = new Session();
createPacketCollectorAndSend(new StanzaIdFilter(session), session).nextResultOrThrow();
}
public void callConnectionAuthenticatedListener(boolean z) {
Iterator<ConnectionListener> it = this.connectionListeners.iterator();
while (it.hasNext()) {
try {
it.next().authenticated(this, z);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Exception in authenticated listener", (Throwable) e);
}
}
}
public void callConnectionClosedListener() {
Iterator<ConnectionListener> it = this.connectionListeners.iterator();
while (it.hasNext()) {
try {
it.next().connectionClosed();
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Error in listener while closing connection", (Throwable) e);
}
}
}
public void callConnectionClosedOnErrorListener(Exception exc) {
LOGGER.log(Level.WARNING, "Connection closed due to inactivity server");
Iterator<ConnectionListener> it = this.connectionListeners.iterator();
while (it.hasNext()) {
try {
it.next().connectionClosedOnError(exc);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Error in listener while closing connection", (Throwable) e);
}
}
}
public void callConnectionConnectedListener() {
Iterator<ConnectionListener> it = this.connectionListeners.iterator();
while (it.hasNext()) {
it.next().connected(this);
}
}
public synchronized AbstractXMPPConnection connect() throws SmackException, IOException, XMPPException {
throwAlreadyConnectedExceptionIfAppropriate();
this.saslAuthentication.init();
this.saslFeatureReceived.init();
this.lastFeaturesReceived.init();
this.streamId = null;
connectInternal();
return this;
}
public abstract void connectInternal() throws SmackException, IOException, XMPPException;
@Override
public PacketCollector createPacketCollector(PacketCollector.Configuration configuration) {
PacketCollector packetCollector = new PacketCollector(this, configuration);
this.collectors.add(packetCollector);
return packetCollector;
}
@Override
public PacketCollector createPacketCollectorAndSend(StanzaFilter stanzaFilter, Stanza stanza) throws SmackException.NotConnectedException {
PacketCollector createPacketCollector = createPacketCollector(stanzaFilter);
try {
sendStanza(stanza);
return createPacketCollector;
} catch (RuntimeException | SmackException.NotConnectedException e) {
createPacketCollector.cancel();
throw e;
}
}
public void disconnect() {
try {
disconnect(new Presence(Presence.Type.unavailable));
} catch (SmackException.NotConnectedException e) {
LOGGER.log(Level.FINEST, "Connection is already disconnected", (Throwable) e);
}
}
public void finalize() throws Throwable {
LOGGER.fine("finalizing XMPPConnection ( " + getConnectionCounter() + "): Shutting down executor services");
try {
this.executorService.shutdownNow();
this.cachedExecutorService.shutdown();
this.removeCallbacksService.shutdownNow();
this.singleThreadedExecutorService.shutdownNow();
} catch (Throwable th) {
try {
LOGGER.log(Level.WARNING, "finalize() threw trhowable", th);
} finally {
super.finalize();
}
}
}
public void firePacketSendingListeners(final Stanza stanza) {
final LinkedList linkedList = new LinkedList();
synchronized (this.sendListeners) {
try {
for (ListenerWrapper listenerWrapper : this.sendListeners.values()) {
if (listenerWrapper.filterMatches(stanza)) {
linkedList.add(listenerWrapper.getListener());
}
}
} catch (Throwable th) {
throw th;
}
}
if (linkedList.isEmpty()) {
return;
}
asyncGo(new Runnable() {
@Override
public void run() {
Iterator it = linkedList.iterator();
while (it.hasNext()) {
try {
((StanzaListener) it.next()).processPacket(stanza);
} catch (Exception e) {
AbstractXMPPConnection.LOGGER.log(Level.WARNING, "Sending listener threw exception", (Throwable) e);
}
}
}
});
}
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 this.packetReplyTimeout;
}
public ParsingExceptionCallback getParsingExceptionCallback() {
return this.parsingExceptionCallback;
}
@Override
public int getPort() {
return this.port;
}
public SASLAuthentication getSASLAuthentication() {
return this.saslAuthentication;
}
@Override
public String getServiceName() {
String str = this.serviceName;
return str != null ? str : this.config.getServiceName();
}
@Override
public String getStreamId() {
if (isConnected()) {
return this.streamId;
}
return null;
}
@Override
public final String getUser() {
return this.user;
}
@Override
public boolean hasFeature(String str, String str2) {
return getFeature(str, str2) != null;
}
public void initDebugger() {
if (this.reader == null || this.writer == null) {
throw new NullPointerException("Reader or writer isn't initialized.");
}
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");
} else {
this.reader = smackDebugger.newConnectionReader(this.reader);
this.writer = this.debugger.newConnectionWriter(this.writer);
}
}
}
public void invokePacketCollectorsAndNotifyRecvListeners(final Stanza stanza) {
final IQRequestHandler iQRequestHandler;
if (stanza instanceof IQ) {
final IQ iq2 = (IQ) stanza;
IQ.Type type = iq2.getType();
int[] iArr = AnonymousClass9.$SwitchMap$org$jivesoftware$smack$packet$IQ$Type;
int i = iArr[type.ordinal()];
if (i == 1 || i == 2) {
String generateKey = XmppStringUtils.generateKey(iq2.getChildElementName(), iq2.getChildElementNamespace());
int i2 = iArr[type.ordinal()];
if (i2 == 1) {
synchronized (this.setIqRequestHandler) {
iQRequestHandler = this.setIqRequestHandler.get(generateKey);
}
} else {
if (i2 != 2) {
throw new IllegalStateException("Should only encounter IQ type 'get' or 'set'");
}
synchronized (this.getIqRequestHandler) {
iQRequestHandler = this.getIqRequestHandler.get(generateKey);
}
}
if (iQRequestHandler != null) {
int i3 = AnonymousClass9.$SwitchMap$org$jivesoftware$smack$iqrequest$IQRequestHandler$Mode[iQRequestHandler.getMode().ordinal()];
(i3 != 1 ? i3 != 2 ? null : this.cachedExecutorService : this.singleThreadedExecutorService).execute(new Runnable() {
@Override
public void run() {
IQ handleIQRequest = iQRequestHandler.handleIQRequest(iq2);
if (handleIQRequest == null) {
return;
}
try {
AbstractXMPPConnection.this.sendStanza(handleIQRequest);
} catch (SmackException.NotConnectedException e) {
AbstractXMPPConnection.LOGGER.log(Level.WARNING, "NotConnectedException while sending response to IQ request", (Throwable) e);
}
}
});
return;
} else {
if (!this.replyToUnkownIq) {
return;
}
try {
sendStanza(IQ.createErrorResponse(iq2, new XMPPError(XMPPError.Condition.feature_not_implemented)));
} catch (SmackException.NotConnectedException e) {
LOGGER.log(Level.WARNING, "NotConnectedException while sending error IQ to unkown IQ request", (Throwable) e);
}
}
}
}
final LinkedList<StanzaListener> linkedList = new LinkedList();
synchronized (this.asyncRecvListeners) {
try {
for (ListenerWrapper listenerWrapper : this.asyncRecvListeners.values()) {
if (listenerWrapper.filterMatches(stanza)) {
linkedList.add(listenerWrapper.getListener());
}
}
} finally {
}
}
for (final StanzaListener stanzaListener : linkedList) {
asyncGo(new Runnable() {
@Override
public void run() {
try {
stanzaListener.processPacket(stanza);
} catch (Exception e2) {
AbstractXMPPConnection.LOGGER.log(Level.SEVERE, "Exception in async packet listener", (Throwable) e2);
}
}
});
}
Iterator<PacketCollector> it = this.collectors.iterator();
while (it.hasNext()) {
it.next().processPacket(stanza);
}
linkedList.clear();
synchronized (this.syncRecvListeners) {
try {
for (ListenerWrapper listenerWrapper2 : this.syncRecvListeners.values()) {
if (listenerWrapper2.filterMatches(stanza)) {
linkedList.add(listenerWrapper2.getListener());
}
}
} finally {
}
}
this.singleThreadedExecutorService.execute(new Runnable() {
@Override
public void run() {
Iterator it2 = linkedList.iterator();
while (it2.hasNext()) {
try {
((StanzaListener) it2.next()).processPacket(stanza);
} catch (SmackException.NotConnectedException e2) {
AbstractXMPPConnection.LOGGER.log(Level.WARNING, "Got not connected exception, aborting", (Throwable) e2);
return;
} catch (Exception e3) {
AbstractXMPPConnection.LOGGER.log(Level.SEVERE, "Exception in packet listener", (Throwable) e3);
}
}
}
});
}
@Override
public final boolean isAnonymous() {
return this.config.getUsername() == null && this.usedUsername == null && !this.config.allowNullOrEmptyUsername;
}
@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 {
try {
if (isAnonymous()) {
throwNotConnectedExceptionIfAppropriate("Did you call connect() before login()?");
throwAlreadyLoggedInExceptionIfAppropriate();
loginAnonymously();
} else {
CharSequence charSequence = this.usedUsername;
if (charSequence == null) {
charSequence = this.config.getUsername();
}
String str = this.usedPassword;
if (str == null) {
str = this.config.getPassword();
}
String str2 = this.usedResource;
if (str2 == null) {
str2 = this.config.getResource();
}
login(charSequence, str, str2);
}
} catch (Throwable th) {
throw th;
}
}
public abstract void loginAnonymously() throws XMPPException, SmackException, IOException;
public abstract void loginNonAnonymously(String str, String str2, String str3) throws XMPPException, SmackException, IOException;
public void notifyReconnection() {
Iterator<ConnectionListener> it = this.connectionListeners.iterator();
while (it.hasNext()) {
try {
it.next().reconnectionSuccessful();
} catch (Exception e) {
LOGGER.log(Level.WARNING, "notifyReconnection()", (Throwable) e);
}
}
}
public void parseAndProcessStanza(XmlPullParser xmlPullParser) throws Exception {
Stanza stanza;
ParserUtils.assertAtStartTag(xmlPullParser);
int depth = xmlPullParser.getDepth();
try {
stanza = PacketParserUtils.parseStanza(xmlPullParser);
} catch (Exception e) {
UnparsablePacket unparsablePacket = new UnparsablePacket(PacketParserUtils.parseContentDepth(xmlPullParser, depth), e);
ParsingExceptionCallback parsingExceptionCallback = getParsingExceptionCallback();
if (parsingExceptionCallback != null) {
parsingExceptionCallback.handleUnparsablePacket(unparsablePacket);
}
stanza = null;
}
ParserUtils.assertAtEndTag(xmlPullParser);
if (stanza != null) {
processPacket(stanza);
}
}
public final void parseFeatures(XmlPullParser xmlPullParser) throws XmlPullParserException, IOException, SmackException {
String name;
String namespace;
ExtensionElement mechanisms;
this.streamFeatures.clear();
int depth = xmlPullParser.getDepth();
while (true) {
int next = xmlPullParser.next();
if (next == 2 && xmlPullParser.getDepth() == depth + 1) {
name = xmlPullParser.getName();
namespace = xmlPullParser.getNamespace();
name.getClass();
switch (name) {
case "mechanisms":
mechanisms = new Mechanisms(PacketParserUtils.parseMechanisms(xmlPullParser));
break;
case "bind":
mechanisms = Bind.Feature.INSTANCE;
break;
case "starttls":
mechanisms = PacketParserUtils.parseStartTlsFeature(xmlPullParser);
break;
case "compression":
mechanisms = PacketParserUtils.parseCompressionFeature(xmlPullParser);
break;
case "session":
mechanisms = PacketParserUtils.parseSessionFeature(xmlPullParser);
break;
default:
ExtensionElementProvider<ExtensionElement> streamFeatureProvider = ProviderManager.getStreamFeatureProvider(name, namespace);
if (streamFeatureProvider == null) {
mechanisms = null;
break;
} else {
mechanisms = (ExtensionElement) streamFeatureProvider.parse(xmlPullParser);
break;
}
}
if (mechanisms != null) {
addStreamFeature(mechanisms);
}
} 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.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.host != null) {
this.hostAddresses = new ArrayList(1);
ConnectionConfiguration connectionConfiguration2 = this.config;
this.hostAddresses.add(new HostAddress(connectionConfiguration2.host, connectionConfiguration2.port));
} else {
this.hostAddresses = DNSUtil.resolveXMPPDomain(connectionConfiguration.serviceName, linkedList);
}
return linkedList;
}
public void processPacket(Stanza stanza) throws InterruptedException {
this.lastStanzaReceived = System.currentTimeMillis();
this.executorService.executeBlocking(new ListenerNotification(stanza));
}
@Override
public IQRequestHandler registerIQRequestHandler(IQRequestHandler iQRequestHandler) {
IQRequestHandler put;
IQRequestHandler put2;
String generateKey = XmppStringUtils.generateKey(iQRequestHandler.getElement(), iQRequestHandler.getNamespace());
int i = AnonymousClass9.$SwitchMap$org$jivesoftware$smack$packet$IQ$Type[iQRequestHandler.getType().ordinal()];
if (i == 1) {
synchronized (this.setIqRequestHandler) {
put = this.setIqRequestHandler.put(generateKey, iQRequestHandler);
}
return put;
}
if (i != 2) {
throw new IllegalArgumentException("Only IQ type of 'get' and 'set' allowed");
}
synchronized (this.getIqRequestHandler) {
put2 = this.getIqRequestHandler.put(generateKey, iQRequestHandler);
}
return put2;
}
@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 removePacketCollector(PacketCollector packetCollector) {
this.collectors.remove(packetCollector);
}
@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 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 abstract void send(PlainStreamElement plainStreamElement) throws SmackException.NotConnectedException;
@Override
public void sendIqWithResponseCallback(IQ iq2, StanzaListener stanzaListener) throws SmackException.NotConnectedException {
sendIqWithResponseCallback(iq2, stanzaListener, null);
}
@Override
@Deprecated
public void sendPacket(Stanza stanza) throws SmackException.NotConnectedException {
sendStanza(stanza);
}
@Override
public void sendStanza(Stanza stanza) throws SmackException.NotConnectedException {
String user;
Objects.requireNonNull(stanza, "Packet must not be null");
throwNotConnectedExceptionIfAppropriate();
int i = AnonymousClass9.$SwitchMap$org$jivesoftware$smack$XMPPConnection$FromMode[this.fromMode.ordinal()];
if (i != 1) {
user = i == 2 ? getUser() : null;
firePacketInterceptors(stanza);
sendStanzaInternal(stanza);
}
stanza.setFrom(user);
firePacketInterceptors(stanza);
sendStanzaInternal(stanza);
}
public abstract void sendStanzaInternal(Stanza stanza) throws SmackException.NotConnectedException;
@Override
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter stanzaFilter, StanzaListener stanzaListener) throws SmackException.NotConnectedException {
sendStanzaWithResponseCallback(stanza, stanzaFilter, stanzaListener, null);
}
@Override
public void setFromMode(XMPPConnection.FromMode fromMode) {
this.fromMode = fromMode;
}
@Override
public void setPacketReplyTimeout(long j) {
this.packetReplyTimeout = j;
}
public void setParsingExceptionCallback(ParsingExceptionCallback parsingExceptionCallback) {
this.parsingExceptionCallback = parsingExceptionCallback;
}
public void setReplyToUnknownIq(boolean z) {
this.replyToUnkownIq = z;
}
public void setWasAuthenticated() {
if (this.wasAuthenticated) {
return;
}
this.wasAuthenticated = this.authenticated;
}
public abstract void shutdown();
public void throwAlreadyConnectedExceptionIfAppropriate() throws SmackException.AlreadyConnectedException {
if (isConnected()) {
throw new SmackException.AlreadyConnectedException();
}
}
public void throwAlreadyLoggedInExceptionIfAppropriate() throws SmackException.AlreadyLoggedInException {
if (isAuthenticated()) {
throw new SmackException.AlreadyLoggedInException();
}
}
public void throwNotConnectedExceptionIfAppropriate() throws SmackException.NotConnectedException {
throwNotConnectedExceptionIfAppropriate(null);
}
@Override
public IQRequestHandler unregisterIQRequestHandler(String str, String str2, IQ.Type type) {
IQRequestHandler remove;
IQRequestHandler remove2;
String generateKey = XmppStringUtils.generateKey(str, str2);
int i = AnonymousClass9.$SwitchMap$org$jivesoftware$smack$packet$IQ$Type[type.ordinal()];
if (i == 1) {
synchronized (this.setIqRequestHandler) {
remove = this.setIqRequestHandler.remove(generateKey);
}
return remove;
}
if (i != 2) {
throw new IllegalArgumentException("Only IQ type of 'get' and 'set' allowed");
}
synchronized (this.getIqRequestHandler) {
remove2 = this.getIqRequestHandler.remove(generateKey);
}
return remove2;
}
@Override
public PacketCollector createPacketCollector(StanzaFilter stanzaFilter) {
return createPacketCollector(PacketCollector.newConfiguration().setStanzaFilter(stanzaFilter));
}
@Override
public PacketCollector createPacketCollectorAndSend(IQ iq2) throws SmackException.NotConnectedException {
return createPacketCollectorAndSend(new IQReplyFilter(iq2, this), iq2);
}
public synchronized void disconnect(Presence presence) throws SmackException.NotConnectedException {
sendStanza(presence);
shutdown();
callConnectionClosedListener();
}
public synchronized void login(CharSequence charSequence, String str) throws XMPPException, SmackException, IOException {
login(charSequence, str, this.config.getResource());
}
@Override
public void sendIqWithResponseCallback(IQ iq2, StanzaListener stanzaListener, ExceptionCallback exceptionCallback) throws SmackException.NotConnectedException {
sendIqWithResponseCallback(iq2, stanzaListener, exceptionCallback, getPacketReplyTimeout());
}
@Override
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter stanzaFilter, StanzaListener stanzaListener, ExceptionCallback exceptionCallback) throws SmackException.NotConnectedException {
sendStanzaWithResponseCallback(stanza, stanzaFilter, stanzaListener, exceptionCallback, getPacketReplyTimeout());
}
public void throwNotConnectedExceptionIfAppropriate(String str) throws SmackException.NotConnectedException {
if (!isConnected()) {
throw new SmackException.NotConnectedException(str);
}
}
@Override
public final IQRequestHandler unregisterIQRequestHandler(IQRequestHandler iQRequestHandler) {
return unregisterIQRequestHandler(iQRequestHandler.getElement(), iQRequestHandler.getNamespace(), iQRequestHandler.getType());
}
public synchronized void login(CharSequence charSequence, String str, String str2) throws XMPPException, SmackException, IOException {
try {
if (!this.config.allowNullOrEmptyUsername) {
StringUtils.requireNotNullOrEmpty(charSequence, "Username must not be null or empty");
}
throwNotConnectedExceptionIfAppropriate();
throwAlreadyLoggedInExceptionIfAppropriate();
String charSequence2 = charSequence != null ? charSequence.toString() : null;
this.usedUsername = charSequence2;
this.usedPassword = str;
this.usedResource = str2;
loginNonAnonymously(charSequence2, str, str2);
} catch (Throwable th) {
throw th;
}
}
@Override
public void sendIqWithResponseCallback(IQ iq2, StanzaListener stanzaListener, ExceptionCallback exceptionCallback, long j) throws SmackException.NotConnectedException {
sendStanzaWithResponseCallback(iq2, new IQReplyFilter(iq2, this), stanzaListener, exceptionCallback, j);
}
@Override
public void sendStanzaWithResponseCallback(Stanza stanza, final StanzaFilter stanzaFilter, final StanzaListener stanzaListener, final ExceptionCallback exceptionCallback, long j) throws SmackException.NotConnectedException {
Objects.requireNonNull(stanza, "stanza must not be null");
Objects.requireNonNull(stanzaFilter, "replyFilter must not be null");
Objects.requireNonNull(stanzaListener, "callback must not be null");
final StanzaListener stanzaListener2 = new StanzaListener() {
@Override
public void processPacket(Stanza stanza2) throws SmackException.NotConnectedException {
try {
XMPPException.XMPPErrorException.ifHasErrorThenThrow(stanza2);
stanzaListener.processPacket(stanza2);
} catch (XMPPException.XMPPErrorException e) {
ExceptionCallback exceptionCallback2 = exceptionCallback;
if (exceptionCallback2 != null) {
exceptionCallback2.processException(e);
}
} finally {
AbstractXMPPConnection.this.removeAsyncStanzaListener(this);
}
}
};
this.removeCallbacksService.schedule(new Runnable() {
@Override
public void run() {
ExceptionCallback exceptionCallback2;
if (!AbstractXMPPConnection.this.removeAsyncStanzaListener(stanzaListener2) || (exceptionCallback2 = exceptionCallback) == null) {
return;
}
exceptionCallback2.processException(SmackException.NoResponseException.newWith(AbstractXMPPConnection.this, stanzaFilter));
}
}, j, TimeUnit.MILLISECONDS);
addAsyncStanzaListener(stanzaListener2, stanzaFilter);
sendStanza(stanza);
}
}