CryptoMessage v1.3.2版本的 MD5 值为:66c611ce56a11450659dc23697562928

以下内容为反编译后的 AbstractXMPPConnection.java 源代码,内容仅作参考


package org.jivesoftware.smack;

import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.lang.Thread;
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.Map;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
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 javax.net.ssl.SSLSession;
import javax.xml.namespace.QName;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.NonzaCallback;
import org.jivesoftware.smack.ScheduledAction;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackFuture;
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.datatypes.UInt16;
import org.jivesoftware.smack.debugger.SmackDebugger;
import org.jivesoftware.smack.debugger.SmackDebuggerFactory;
import org.jivesoftware.smack.filter.IQReplyFilter;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.filter.StanzaIdFilter;
import org.jivesoftware.smack.internal.SmackTlsContext;
import org.jivesoftware.smack.iqrequest.IQRequestHandler;
import org.jivesoftware.smack.packet.AbstractStreamOpen;
import org.jivesoftware.smack.packet.Bind;
import org.jivesoftware.smack.packet.ErrorIQ;
import org.jivesoftware.smack.packet.FullyQualifiedElement;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Mechanisms;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.MessageBuilder;
import org.jivesoftware.smack.packet.MessageOrPresence;
import org.jivesoftware.smack.packet.MessageOrPresenceBuilder;
import org.jivesoftware.smack.packet.Nonza;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.PresenceBuilder;
import org.jivesoftware.smack.packet.Session;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.StanzaError;
import org.jivesoftware.smack.packet.StanzaFactory;
import org.jivesoftware.smack.packet.StartTls;
import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.packet.StreamOpen;
import org.jivesoftware.smack.packet.TopLevelStreamElement;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.provider.NonzaProvider;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.sasl.SASLErrorException;
import org.jivesoftware.smack.sasl.SASLMechanism;
import org.jivesoftware.smack.sasl.core.SASLAnonymous;
import org.jivesoftware.smack.sasl.packet.SaslNonza;
import org.jivesoftware.smack.util.Async;
import org.jivesoftware.smack.util.CollectionUtil;
import org.jivesoftware.smack.util.Consumer;
import org.jivesoftware.smack.util.MultiMap;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smack.util.Predicate;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.Supplier;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.EntityFullJid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.jid.parts.Resourcepart;
import org.jxmpp.stringprep.XmppStringprepException;
import org.jxmpp.util.XmppStringUtils;

public abstract class AbstractXMPPConnection implements XMPPConnection {
    static final boolean $assertionsDisabled = false;
    protected long authenticatedConnectionInitiallyEstablishedTimestamp;
    protected boolean closingStreamReceived;
    protected XMPPInputOutputStream compressionHandler;
    protected final ConnectionConfiguration config;
    private final CSPConfiguration cspConfiguration;
    private int currentAsyncRunnables;
    protected SmackException currentSmackException;
    protected XMPPException currentXmppException;
    protected final SmackDebugger debugger;
    private int deferredAsyncRunnablesCount;
    private int deferredAsyncRunnablesCountPrevious;
    private final String fileUploadAddress;
    protected String host;
    private XmlEnvironment incomingStreamXmlEnvironment;
    protected boolean lastFeaturesReceived;
    private long lastStanzaReceived;
    private final String mediaDirectory;
    protected XmlEnvironment outgoingStreamXmlEnvironment;
    protected UInt16 port;
    protected Reader reader;
    private final SASLAuthentication saslAuthentication;
    protected boolean saslFeatureReceived;
    private final StanzaFactory stanzaFactory;
    protected String streamId;
    protected boolean tlsHandled;
    private String usedPassword;
    private Resourcepart usedResource;
    private String usedUsername;
    protected EntityFullJid user;
    protected Writer writer;
    private DomainBareJid xmppServiceDomain;
    protected static final AsyncButOrdered<AbstractXMPPConnection> ASYNC_BUT_ORDERED = new AsyncButOrdered<>();
    private static final Logger LOGGER = Logger.getLogger(AbstractXMPPConnection.class.getName());
    private static final AtomicInteger connectionCounter = new AtomicInteger(0);
    private static final ExecutorService CACHED_EXECUTOR_SERVICE = Executors.newCachedThreadPool(new ThreadFactory() {
        @Override
        public final Thread newThread(Runnable runnable) {
            Thread lambda$static$1;
            lambda$static$1 = AbstractXMPPConnection.lambda$static$1(runnable);
            return lambda$static$1;
        }
    });
    protected static final SmackReactor SMACK_REACTOR = SmackReactor.getInstance();
    protected final Set<ConnectionListener> connectionListeners = new CopyOnWriteArraySet();
    protected final Lock connectionLock = new ReentrantLock();
    protected final Map<QName, FullyQualifiedElement> streamFeatures = new HashMap();
    protected final int connectionCounterValue = connectionCounter.getAndIncrement();
    protected final AsyncButOrdered<StanzaListener> inOrderListeners = new AsyncButOrdered<>();
    final MultiMap<QName, NonzaCallback> nonzaCallbacksMap = new MultiMap<>();
    private final Collection<StanzaCollector> collectors = new ConcurrentLinkedQueue();
    private final Map<StanzaListener, ListenerWrapper> recvListeners = new LinkedHashMap();
    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();
    private final Map<Consumer<MessageBuilder>, GenericInterceptorWrapper<MessageBuilder, Message>> messageInterceptors = new HashMap();
    private final Map<Consumer<PresenceBuilder>, GenericInterceptorWrapper<PresenceBuilder, Presence>> presenceInterceptors = new HashMap();
    private final Map<QName, IQRequestHandler> setIqRequestHandler = new HashMap();
    private final Map<QName, IQRequestHandler> getIqRequestHandler = new HashMap();
    private final Object internalMonitor = new Object();
    private final Object notifyConnectionErrorMonitor = new Object();
    private final Queue<Runnable> deferredAsyncRunnables = new LinkedList();
    protected boolean connected = false;
    protected boolean authenticated = false;
    protected boolean wasAuthenticated = false;
    private long replyTimeout = SmackConfiguration.getDefaultReplyTimeout();
    private XMPPConnection.FromMode fromMode = XMPPConnection.FromMode.OMITTED;
    private ParsingExceptionCallback parsingExceptionCallback = SmackConfiguration.getDefaultParsingExceptionCallback();
    private SmackConfiguration.UnknownIqRequestReplyMode unknownIqRequestReplyMode = SmackConfiguration.getUnknownIqRequestReplyMode();
    private int maxAsyncRunnables = SmackConfiguration.getDefaultConcurrencyLevelLimit();
    private LinkedList<BackgroundListener> backgroundListeners = new LinkedList<>();

    public enum SyncPointState {
        initial,
        request_sent,
        successful
    }

    protected void afterFeaturesReceived() throws SmackException.SecurityRequiredException, SmackException.NotConnectedException, InterruptedException {
    }

    protected abstract void connectInternal() throws SmackException, IOException, XMPPException, InterruptedException;

    public abstract void instantShutdown();

    @Override
    public abstract boolean isSecureConnection();

    @Override
    public abstract boolean isUsingCompression();

    protected abstract void loginInternal(String str, String str2, Resourcepart resourcepart) throws XMPPException, SmackException, IOException, InterruptedException;

    @Override
    public abstract void sendNonza(Nonza nonza) throws SmackException.NotConnectedException, InterruptedException;

    protected abstract void sendStanzaInternal(Stanza stanza) throws SmackException.NotConnectedException, InterruptedException;

    protected abstract void shutdown();

    static int access$510(AbstractXMPPConnection abstractXMPPConnection) {
        int i = abstractXMPPConnection.currentAsyncRunnables;
        abstractXMPPConnection.currentAsyncRunnables = i - 1;
        return i;
    }

    static int access$610(AbstractXMPPConnection abstractXMPPConnection) {
        int i = abstractXMPPConnection.deferredAsyncRunnablesCount;
        abstractXMPPConnection.deferredAsyncRunnablesCount = i - 1;
        return i;
    }

    static {
        Smack.ensureInitialized();
    }

    public static Thread lambda$static$1(Runnable runnable) {
        Thread thread = new Thread(runnable);
        thread.setName("Smack Cached Executor");
        thread.setDaemon(true);
        thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            @Override
            public final void uncaughtException(Thread thread2, Throwable th) {
                AbstractXMPPConnection.lambda$static$0(thread2, th);
            }
        });
        return thread;
    }

    public static void lambda$static$0(Thread thread, Throwable th) {
        LOGGER.log(Level.WARNING, thread + " encountered uncaught exception", th);
    }

    public AbstractXMPPConnection(ConnectionConfiguration connectionConfiguration) {
        this.saslAuthentication = new SASLAuthentication(this, connectionConfiguration);
        this.config = connectionConfiguration;
        this.cspConfiguration = connectionConfiguration.getCspConfiguration();
        this.mediaDirectory = connectionConfiguration.getMediaDirectory();
        this.fileUploadAddress = connectionConfiguration.getFileUploadAddress();
        buildNonzaCallback().listenFor(SaslNonza.Challenge.class, new NonzaCallback.NonzaListener() {
            @Override
            public final void accept(Nonza nonza) {
                AbstractXMPPConnection.this.lambda$new$2((SaslNonza.Challenge) nonza);
            }
        }).listenFor(SaslNonza.Success.class, new NonzaCallback.NonzaListener() {
            @Override
            public final void accept(Nonza nonza) {
                AbstractXMPPConnection.this.lambda$new$3((SaslNonza.Success) nonza);
            }
        }).listenFor(SaslNonza.SASLFailure.class, new NonzaCallback.NonzaListener() {
            @Override
            public final void accept(Nonza nonza) {
                AbstractXMPPConnection.this.lambda$new$4((SaslNonza.SASLFailure) nonza);
            }
        }).install();
        SmackDebuggerFactory debuggerFactory = connectionConfiguration.getDebuggerFactory();
        if (debuggerFactory != null) {
            this.debugger = debuggerFactory.create(this);
        } else {
            this.debugger = null;
        }
        Iterator<ConnectionCreationListener> it = XMPPConnectionRegistry.getConnectionCreationListeners().iterator();
        while (it.hasNext()) {
            it.next().connectionCreated(this);
        }
        this.stanzaFactory = new StanzaFactory(connectionConfiguration.constructStanzaIdSource());
    }

    public void lambda$new$2(SaslNonza.Challenge challenge) throws IOException {
        try {
            this.saslAuthentication.challengeReceived(challenge);
        } catch (InterruptedException | SmackException e) {
            this.saslAuthentication.authenticationFailed(e);
        }
    }

    public void lambda$new$3(SaslNonza.Success success) throws IOException {
        try {
            this.saslAuthentication.authenticated(success);
        } catch (InterruptedException | SmackException.NotConnectedException | SmackException.SmackSaslException e) {
            this.saslAuthentication.authenticationFailed(e);
        }
    }

    public void lambda$new$4(SaslNonza.SASLFailure sASLFailure) throws IOException {
        this.saslAuthentication.authenticationFailed(sASLFailure);
    }

    private static <MPB extends MessageOrPresenceBuilder<MP, MPB>, MP extends MessageOrPresence<MPB>> void addInterceptor(Map<Consumer<MPB>, GenericInterceptorWrapper<MPB, MP>> map, Consumer<MPB> consumer, Predicate<MP> predicate) {
        Objects.requireNonNull(consumer, "Interceptor must not be null");
        GenericInterceptorWrapper<MPB, MP> genericInterceptorWrapper = new GenericInterceptorWrapper<>(consumer, predicate);
        synchronized (map) {
            map.put(consumer, genericInterceptorWrapper);
        }
    }

    private static <MPB extends MessageOrPresenceBuilder<MP, MPB>, MP extends MessageOrPresence<MPB>> void removeInterceptor(Map<Consumer<MPB>, GenericInterceptorWrapper<MPB, MP>> map, Consumer<MPB> consumer) {
        synchronized (map) {
            map.remove(consumer);
        }
    }

    private static <MPB extends MessageOrPresenceBuilder<MP, MPB>, MP extends MessageOrPresence<MPB>> MP fireMessageOrPresenceInterceptors(MP mp, Map<Consumer<MPB>, GenericInterceptorWrapper<MPB, MP>> map) {
        LinkedList linkedList = new LinkedList();
        synchronized (map) {
            for (GenericInterceptorWrapper<MPB, MP> genericInterceptorWrapper : map.values()) {
                if (genericInterceptorWrapper.filterMatches(mp)) {
                    linkedList.add(genericInterceptorWrapper.getInterceptor());
                }
            }
        }
        if (linkedList.isEmpty()) {
            return mp;
        }
        MessageOrPresenceBuilder asBuilder = mp.asBuilder();
        Iterator it = linkedList.iterator();
        while (it.hasNext()) {
            ((Consumer) it.next()).accept(asBuilder);
        }
        return (MP) asBuilder.build();
    }

    private static void extractMatchingListeners(Stanza stanza, Map<StanzaListener, ListenerWrapper> map, Collection<StanzaListener> collection) {
        synchronized (map) {
            for (ListenerWrapper listenerWrapper : map.values()) {
                if (listenerWrapper.filterMatches(stanza)) {
                    collection.add(listenerWrapper.getListener());
                }
            }
        }
    }

    public static void asyncGo(Runnable runnable) {
        CACHED_EXECUTOR_SERVICE.execute(runnable);
    }

    public static ScheduledAction schedule(Runnable runnable, long j, TimeUnit timeUnit) {
        return SMACK_REACTOR.schedule(runnable, j, timeUnit, ScheduledAction.Kind.NonBlocking);
    }

    @Override
    public void addBackgroundListener(BackgroundListener backgroundListener) {
        this.backgroundListeners.add(backgroundListener);
    }

    public void removeBackgroundListener(BackgroundListener backgroundListener) {
        this.backgroundListeners.remove(backgroundListener);
    }

    @Override
    public LinkedList<BackgroundListener> getBackgroundListeners() {
        return this.backgroundListeners;
    }

    public ConnectionConfiguration getConfiguration() {
        return this.config;
    }

    @Override
    public DomainBareJid getXMPPServiceDomain() {
        DomainBareJid domainBareJid = this.xmppServiceDomain;
        return domainBareJid != null ? domainBareJid : this.config.getXMPPServiceDomain();
    }

    @Override
    public String getHost() {
        return this.host;
    }

    @Override
    public int getPort() {
        UInt16 uInt16 = this.port;
        if (uInt16 == null) {
            return -1;
        }
        return uInt16.intValue();
    }

    @Override
    public boolean trySendStanza(Stanza stanza) throws SmackException.NotConnectedException {
        try {
            sendStanza(stanza);
            return true;
        } catch (InterruptedException e) {
            LOGGER.log(Level.FINER, "Thread blocked in fallback implementation of trySendStanza(Stanza) was interrupted", (Throwable) e);
            return false;
        }
    }

    @Override
    public boolean trySendStanza(Stanza stanza, long j, TimeUnit timeUnit) throws SmackException.NotConnectedException, InterruptedException {
        sendStanza(stanza);
        return true;
    }

    public void initState() {
        this.currentSmackException = null;
        this.currentXmppException = null;
        this.tlsHandled = false;
        this.lastFeaturesReceived = false;
        this.saslFeatureReceived = false;
    }

    public synchronized AbstractXMPPConnection connect() throws SmackException, IOException, XMPPException, InterruptedException {
        throwAlreadyConnectedExceptionIfAppropriate();
        callConnectionConnectingListener();
        initState();
        this.closingStreamReceived = false;
        this.streamId = null;
        try {
            connectInternal();
            if (!isSecureConnection() && getConfiguration().getSecurityMode() == ConnectionConfiguration.SecurityMode.required) {
                throw new SmackException.SecurityRequiredByClientException();
            }
            callConnectionConnectedListener();
        } catch (IOException | InterruptedException | SmackException e) {
            instantShutdown();
            throw e;
        }
        return this;
    }

    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);
    }

    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.requireNotNullNorEmpty(charSequence, "Username must not be null nor 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);
    }

    @Override
    public final boolean isConnected() {
        return this.connected;
    }

    @Override
    public final boolean isAuthenticated() {
        return this.authenticated;
    }

    @Override
    public final EntityFullJid getUser() {
        return this.user;
    }

    @Override
    public String getStreamId() {
        if (isConnected()) {
            return this.streamId;
        }
        return null;
    }

    protected final void throwCurrentConnectionException() throws SmackException, XMPPException {
        SmackException smackException = this.currentSmackException;
        if (smackException != null) {
            throw smackException;
        }
        XMPPException xMPPException = this.currentXmppException;
        if (xMPPException != null) {
            throw xMPPException;
        }
        throw new AssertionError("No current connection exception set, although throwCurrentException() was called");
    }

    protected final boolean hasCurrentConnectionException() {
        return (this.currentSmackException == null && this.currentXmppException == null) ? false : true;
    }

    public final void setCurrentConnectionExceptionAndNotify(Exception exc) {
        if (exc instanceof SmackException) {
            this.currentSmackException = (SmackException) exc;
        } else if (exc instanceof XMPPException) {
            this.currentXmppException = (XMPPException) exc;
        } else {
            this.currentSmackException = new SmackException.SmackWrappedException(exc);
        }
        notifyWaitingThreads();
    }

    public final void notifyWaitingThreads() {
        synchronized (this.internalMonitor) {
            this.internalMonitor.notifyAll();
        }
    }

    public final boolean waitFor(Supplier<Boolean> supplier) throws InterruptedException {
        long currentTimeMillis = System.currentTimeMillis() + getReplyTimeout();
        synchronized (this.internalMonitor) {
            while (!supplier.get().booleanValue()) {
                long currentTimeMillis2 = System.currentTimeMillis();
                if (currentTimeMillis2 >= currentTimeMillis) {
                    return false;
                }
                this.internalMonitor.wait(currentTimeMillis - currentTimeMillis2);
            }
            return true;
        }
    }

    public Boolean lambda$waitForConditionOrConnectionException$5(Supplier supplier) {
        return Boolean.valueOf(((Boolean) supplier.get()).booleanValue() || hasCurrentConnectionException());
    }

    protected final boolean waitForConditionOrConnectionException(final Supplier<Boolean> supplier) throws InterruptedException {
        return waitFor(new Supplier() {
            @Override
            public final Object get() {
                Boolean lambda$waitForConditionOrConnectionException$5;
                lambda$waitForConditionOrConnectionException$5 = AbstractXMPPConnection.this.lambda$waitForConditionOrConnectionException$5(supplier);
                return lambda$waitForConditionOrConnectionException$5;
            }
        });
    }

    public final void waitForConditionOrConnectionException(Supplier<Boolean> supplier, String str) throws InterruptedException, SmackException.NoResponseException {
        if (!waitForConditionOrConnectionException(supplier)) {
            throw SmackException.NoResponseException.newWith(this, str);
        }
    }

    public final void waitForConditionOrThrowConnectionException(Supplier<Boolean> supplier, String str) throws InterruptedException, SmackException, XMPPException {
        waitForConditionOrConnectionException(supplier, str);
        if (hasCurrentConnectionException()) {
            throwCurrentConnectionException();
        }
    }

    public Resourcepart bindResourceAndEstablishSession(Resourcepart resourcepart) throws SmackException, InterruptedException, XMPPException {
        LOGGER.finer("Waiting for last features to be received before continuing with resource binding");
        waitForConditionOrThrowConnectionException(new Supplier() {
            @Override
            public final Object get() {
                Boolean lambda$bindResourceAndEstablishSession$6;
                lambda$bindResourceAndEstablishSession$6 = AbstractXMPPConnection.this.lambda$bindResourceAndEstablishSession$6();
                return lambda$bindResourceAndEstablishSession$6;
            }
        }, "last stream features received from server");
        if (!hasFeature(Bind.ELEMENT, Bind.NAMESPACE)) {
            throw new SmackException.ResourceBindingNotOfferedException();
        }
        Bind newSet = Bind.newSet(resourcepart);
        Bind bind = (Bind) createStanzaCollectorAndSend(new StanzaIdFilter(newSet), newSet).nextResultOrThrow();
        EntityFullJid jid = bind.getJid();
        this.user = jid;
        this.xmppServiceDomain = jid.asDomainBareJid();
        Session.Feature feature = (Session.Feature) getFeature(Session.Feature.class);
        if (feature != null && !feature.isOptional()) {
            Session session = new Session();
            createStanzaCollectorAndSend(new StanzaIdFilter(session), session).nextResultOrThrow();
        }
        return bind.getJid().getResourcepart();
    }

    public Boolean lambda$bindResourceAndEstablishSession$6() {
        return Boolean.valueOf(this.lastFeaturesReceived);
    }

    public void afterSuccessfulLogin(boolean z) throws SmackException.NotConnectedException, InterruptedException {
        if (!z) {
            this.authenticatedConnectionInitiallyEstablishedTimestamp = System.currentTimeMillis();
        }
        this.authenticated = true;
        SmackDebugger smackDebugger = this.debugger;
        if (smackDebugger != null) {
            smackDebugger.userHasLogged(this.user);
        }
        callConnectionAuthenticatedListener(z);
        if (!this.config.isSendPresence() || z) {
            return;
        }
        sendStanza(getStanzaFactory().buildPresenceStanza().ofType(Presence.Type.available).build());
    }

    @Override
    public final boolean isAnonymous() {
        return isAuthenticated() && SASLAnonymous.NAME.equals(getUsedSaslMechansism());
    }

    public final String getUsedSaslMechansism() {
        return this.saslAuthentication.getNameOfLastUsedSaslMechansism();
    }

    protected Lock getConnectionLock() {
        return this.connectionLock;
    }

    protected void throwNotConnectedExceptionIfAppropriate() throws SmackException.NotConnectedException {
        throwNotConnectedExceptionIfAppropriate(null);
    }

    protected void throwNotConnectedExceptionIfAppropriate(String str) throws SmackException.NotConnectedException {
        if (!isConnected()) {
            throw new SmackException.NotConnectedException(str);
        }
    }

    protected void throwAlreadyConnectedExceptionIfAppropriate() throws SmackException.AlreadyConnectedException {
        if (isConnected()) {
            throw new SmackException.AlreadyConnectedException();
        }
    }

    protected void throwAlreadyLoggedInExceptionIfAppropriate() throws SmackException.AlreadyLoggedInException {
        if (isAuthenticated()) {
            throw new SmackException.AlreadyLoggedInException();
        }
    }

    @Override
    public final StanzaFactory getStanzaFactory() {
        return this.stanzaFactory;
    }

    @Override
    public final void sendStanza(Stanza stanza) throws SmackException.NotConnectedException, InterruptedException {
        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(null);
        } else if (i == 2) {
            stanza.setFrom(getUser());
        }
        sendStanzaInternal(firePacketInterceptors(stanza));
    }

    public final SASLMechanism authenticate(String str, String str2, EntityBareJid entityBareJid, SSLSession sSLSession) throws XMPPException.XMPPErrorException, SASLErrorException, SmackException.SmackSaslException, SmackException.NotConnectedException, SmackException.NoResponseException, IOException, InterruptedException, SmackException.SmackWrappedException {
        SASLMechanism authenticate = this.saslAuthentication.authenticate(str, str2, entityBareJid, sSLSession);
        afterSaslAuthenticationSuccess();
        return authenticate;
    }

    protected void afterSaslAuthenticationSuccess() throws SmackException.NotConnectedException, InterruptedException, SmackException.SmackWrappedException {
        sendStreamOpen();
    }

    public final boolean isSaslAuthenticated() {
        return this.saslAuthentication.authenticationSuccessful();
    }

    public void disconnect() {
        try {
            disconnect(isAuthenticated() ? ((PresenceBuilder) getStanzaFactory().buildPresenceStanza().ofType(Presence.Type.unavailable).addExtension(new DisconectExtension())).build() : null);
        } catch (SmackException.NotConnectedException e) {
            LOGGER.log(Level.FINEST, "Connection is already disconnected", (Throwable) e);
        }
    }

    public synchronized void disconnect(Presence presence) throws SmackException.NotConnectedException {
        if (presence != null) {
            try {
                sendStanza(presence);
            } catch (InterruptedException e) {
                LOGGER.log(Level.FINE, "Was interrupted while sending unavailable presence. Continuing to disconnect the connection", (Throwable) e);
            }
        }
        shutdown();
        callConnectionClosedListener();
    }

    public final void notifyConnectionError(final Exception exc) {
        synchronized (this.notifyConnectionErrorMonitor) {
            if (!isConnected()) {
                LOGGER.log(Level.INFO, "Connection was already disconnected when attempting to handle " + exc, (Throwable) exc);
                return;
            }
            setCurrentConnectionExceptionAndNotify(exc);
            instantShutdown();
            Iterator<StanzaCollector> it = this.collectors.iterator();
            while (it.hasNext()) {
                it.next().notifyConnectionError(exc);
            }
            Async.go(new Runnable() {
                @Override
                public final void run() {
                    AbstractXMPPConnection.this.lambda$notifyConnectionError$7(exc);
                }
            }, this + " callConnectionClosedOnErrorListener()");
        }
    }

    public Boolean lambda$waitForClosingStreamTagFromServer$8() {
        return Boolean.valueOf(this.closingStreamReceived);
    }

    public final boolean waitForClosingStreamTagFromServer() {
        try {
            waitForConditionOrThrowConnectionException(new Supplier() {
                @Override
                public final Object get() {
                    Boolean lambda$waitForClosingStreamTagFromServer$8;
                    lambda$waitForClosingStreamTagFromServer$8 = AbstractXMPPConnection.this.lambda$waitForClosingStreamTagFromServer$8();
                    return lambda$waitForClosingStreamTagFromServer$8;
                }
            }, "closing stream tag from the server");
            return true;
        } catch (InterruptedException | SmackException e) {
            LOGGER.log(Level.INFO, "Exception while waiting for closing stream element from the server " + this, e);
            return false;
        }
    }

    @Override
    public void addConnectionListener(ConnectionListener connectionListener) {
        if (connectionListener == null) {
            return;
        }
        this.connectionListeners.add(connectionListener);
    }

    @Override
    public void removeConnectionListener(ConnectionListener connectionListener) {
        this.connectionListeners.remove(connectionListener);
    }

    @Override
    public <I extends IQ> I sendIqRequestAndWaitForResponse(IQ iq) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
        return (I) createStanzaCollectorAndSend(iq).nextResultOrThrow();
    }

    @Override
    public StanzaCollector createStanzaCollectorAndSend(IQ iq) throws SmackException.NotConnectedException, InterruptedException {
        return createStanzaCollectorAndSend(new IQReplyFilter(iq, this), iq);
    }

    @Override
    public StanzaCollector createStanzaCollectorAndSend(StanzaFilter stanzaFilter, Stanza stanza) throws SmackException.NotConnectedException, InterruptedException {
        StanzaCollector createStanzaCollector = createStanzaCollector(StanzaCollector.newConfiguration().setStanzaFilter(stanzaFilter).setRequest(stanza));
        try {
            sendStanza(stanza);
            return createStanzaCollector;
        } catch (InterruptedException | RuntimeException | SmackException.NotConnectedException e) {
            createStanzaCollector.cancel();
            throw e;
        }
    }

    @Override
    public StanzaCollector createStanzaCollector(StanzaFilter stanzaFilter) {
        return createStanzaCollector(StanzaCollector.newConfiguration().setStanzaFilter(stanzaFilter));
    }

    @Override
    public StanzaCollector createStanzaCollector(StanzaCollector.Configuration configuration) {
        StanzaCollector stanzaCollector = new StanzaCollector(this, configuration);
        this.collectors.add(stanzaCollector);
        return stanzaCollector;
    }

    @Override
    public void removeStanzaCollector(StanzaCollector stanzaCollector) {
        this.collectors.remove(stanzaCollector);
    }

    @Override
    public final void addStanzaListener(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
        java.util.Objects.requireNonNull(stanzaListener, "Given stanza listener must not be null");
        ListenerWrapper listenerWrapper = new ListenerWrapper(stanzaListener, stanzaFilter);
        synchronized (this.recvListeners) {
            this.recvListeners.put(stanzaListener, listenerWrapper);
        }
    }

    @Override
    public final boolean removeStanzaListener(StanzaListener stanzaListener) {
        boolean z;
        synchronized (this.recvListeners) {
            z = this.recvListeners.remove(stanzaListener) != null;
        }
        return z;
    }

    @Override
    public void addSyncStanzaListener(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
        java.util.Objects.requireNonNull(stanzaListener, "Packet listener is null.");
        ListenerWrapper listenerWrapper = new ListenerWrapper(stanzaListener, stanzaFilter);
        synchronized (this.syncRecvListeners) {
            this.syncRecvListeners.put(stanzaListener, listenerWrapper);
        }
    }

    @Override
    public boolean removeSyncStanzaListener(StanzaListener stanzaListener) {
        boolean z;
        synchronized (this.syncRecvListeners) {
            z = this.syncRecvListeners.remove(stanzaListener) != null;
        }
        return z;
    }

    @Override
    public void addAsyncStanzaListener(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
        java.util.Objects.requireNonNull(stanzaListener, "Packet listener is null.");
        ListenerWrapper listenerWrapper = new ListenerWrapper(stanzaListener, stanzaFilter);
        synchronized (this.asyncRecvListeners) {
            this.asyncRecvListeners.put(stanzaListener, listenerWrapper);
        }
    }

    @Override
    public boolean removeAsyncStanzaListener(StanzaListener stanzaListener) {
        boolean z;
        synchronized (this.asyncRecvListeners) {
            z = this.asyncRecvListeners.remove(stanzaListener) != null;
        }
        return z;
    }

    @Override
    public void addStanzaSendingListener(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
        java.util.Objects.requireNonNull(stanzaListener, "Packet listener is null.");
        ListenerWrapper listenerWrapper = new ListenerWrapper(stanzaListener, stanzaFilter);
        synchronized (this.sendListeners) {
            this.sendListeners.put(stanzaListener, listenerWrapper);
        }
    }

    @Override
    public void removeStanzaSendingListener(StanzaListener stanzaListener) {
        synchronized (this.sendListeners) {
            this.sendListeners.remove(stanzaListener);
        }
    }

    public void firePacketSendingListeners(TopLevelStreamElement topLevelStreamElement) {
        SmackDebugger smackDebugger = this.debugger;
        if (smackDebugger != null) {
            smackDebugger.onOutgoingStreamElement(topLevelStreamElement);
        }
        if (topLevelStreamElement instanceof Stanza) {
            final Stanza stanza = (Stanza) topLevelStreamElement;
            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() {
                    Iterator it = linkedList.iterator();
                    while (it.hasNext()) {
                        try {
                            ((StanzaListener) it.next()).processStanza(stanza);
                        } catch (Exception e) {
                            AbstractXMPPConnection.LOGGER.log(Level.WARNING, "Sending listener threw exception", (Throwable) e);
                        }
                    }
                }
            });
        }
    }

    @Override
    @Deprecated
    public void addStanzaInterceptor(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
        java.util.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 removeStanzaInterceptor(StanzaListener stanzaListener) {
        synchronized (this.interceptors) {
            this.interceptors.remove(stanzaListener);
        }
    }

    @Override
    public void addMessageInterceptor(Consumer<MessageBuilder> consumer, Predicate<Message> predicate) {
        addInterceptor(this.messageInterceptors, consumer, predicate);
    }

    @Override
    public void removeMessageInterceptor(Consumer<MessageBuilder> consumer) {
        removeInterceptor(this.messageInterceptors, consumer);
    }

    @Override
    public void addPresenceInterceptor(Consumer<PresenceBuilder> consumer, Predicate<Presence> predicate) {
        addInterceptor(this.presenceInterceptors, consumer, predicate);
    }

    @Override
    public void removePresenceInterceptor(Consumer<PresenceBuilder> consumer) {
        removeInterceptor(this.presenceInterceptors, consumer);
    }

    private Stanza firePacketInterceptors(Stanza stanza) {
        LinkedList linkedList = new LinkedList();
        synchronized (this.interceptors) {
            for (InterceptorWrapper interceptorWrapper : this.interceptors.values()) {
                if (interceptorWrapper.filterMatches(stanza)) {
                    linkedList.add(interceptorWrapper.getInterceptor());
                }
            }
        }
        Iterator it = linkedList.iterator();
        while (it.hasNext()) {
            try {
                ((StanzaListener) it.next()).processStanza(stanza);
            } catch (Exception e) {
                LOGGER.log(Level.SEVERE, "Packet interceptor threw exception", (Throwable) e);
            }
        }
        if (stanza instanceof Message) {
            return fireMessageOrPresenceInterceptors((Message) stanza, this.messageInterceptors);
        }
        return stanza instanceof Presence ? fireMessageOrPresenceInterceptors((Presence) stanza, this.presenceInterceptors) : stanza;
    }

    public void initDebugger() {
        Reader reader = this.reader;
        if (reader == null || this.writer == null) {
            throw new NullPointerException("Reader or writer isn't initialized.");
        }
        SmackDebugger smackDebugger = this.debugger;
        if (smackDebugger != null) {
            this.reader = smackDebugger.newConnectionReader(reader);
            this.writer = this.debugger.newConnectionWriter(this.writer);
        }
    }

    @Override
    public long getReplyTimeout() {
        return this.replyTimeout;
    }

    @Override
    public void setReplyTimeout(long j) {
        if (Long.MAX_VALUE - System.currentTimeMillis() < j) {
            throw new IllegalArgumentException("Extremely long reply timeout");
        }
        this.replyTimeout = j;
    }

    public void setUnknownIqRequestReplyMode(SmackConfiguration.UnknownIqRequestReplyMode unknownIqRequestReplyMode) {
        this.unknownIqRequestReplyMode = (SmackConfiguration.UnknownIqRequestReplyMode) Objects.requireNonNull(unknownIqRequestReplyMode, "Mode must not be null");
    }

    public final NonzaCallback.Builder buildNonzaCallback() {
        return new NonzaCallback.Builder(this);
    }

    public <SN extends Nonza, FN extends Nonza> SN sendAndWaitForResponse(Nonza nonza, Class<SN> cls, Class<FN> cls2) throws SmackException.NoResponseException, SmackException.NotConnectedException, InterruptedException, XMPPException.FailedNonzaException {
        return (SN) NonzaCallback.sendAndWaitForResponse(buildNonzaCallback(), nonza, cls, cls2);
    }

    public final void parseAndProcessNonza(XmlPullParser xmlPullParser) throws IOException, XmlPullParserException, SmackParsingException {
        ArrayList newListWith;
        ParserUtils.assertAtStartTag(xmlPullParser);
        int depth = xmlPullParser.getDepth();
        QName qName = new QName(xmlPullParser.getNamespace(), xmlPullParser.getName());
        NonzaProvider<? extends Nonza> nonzaProvider = ProviderManager.getNonzaProvider(qName);
        if (nonzaProvider == null) {
            LOGGER.severe("Unknown nonza: " + qName);
            ParserUtils.forwardToEndTagOfDepth(xmlPullParser, depth);
            return;
        }
        synchronized (this.nonzaCallbacksMap) {
            newListWith = CollectionUtil.newListWith(this.nonzaCallbacksMap.getAll(qName));
        }
        if (newListWith == null) {
            LOGGER.info("No nonza callback for " + qName);
            ParserUtils.forwardToEndTagOfDepth(xmlPullParser, depth);
            return;
        }
        Nonza nonza = (Nonza) nonzaProvider.parse(xmlPullParser, this.incomingStreamXmlEnvironment);
        Iterator it = newListWith.iterator();
        while (it.hasNext()) {
            ((NonzaCallback) it.next()).onNonzaReceived(nonza);
        }
    }

    public void parseAndProcessStanza(XmlPullParser xmlPullParser) throws XmlPullParserException, IOException, InterruptedException {
        Stanza stanza;
        ParserUtils.assertAtStartTag(xmlPullParser);
        int depth = xmlPullParser.getDepth();
        try {
            stanza = PacketParserUtils.parseStanza(xmlPullParser, this.incomingStreamXmlEnvironment);
        } catch (IOException | IllegalArgumentException | SmackParsingException | XmlPullParserException e) {
            UnparseableStanza unparseableStanza = new UnparseableStanza(PacketParserUtils.parseContentDepth(xmlPullParser, depth), e);
            ParsingExceptionCallback parsingExceptionCallback = getParsingExceptionCallback();
            if (parsingExceptionCallback != null) {
                parsingExceptionCallback.handleUnparsableStanza(unparseableStanza);
            }
            stanza = null;
        }
        ParserUtils.assertAtEndTag(xmlPullParser);
        if (stanza != null) {
            processStanza(stanza);
        }
    }

    protected void processStanza(Stanza stanza) throws InterruptedException {
        SmackDebugger smackDebugger = this.debugger;
        if (smackDebugger != null) {
            smackDebugger.onIncomingStreamElement(stanza);
        }
        this.lastStanzaReceived = System.currentTimeMillis();
        invokeStanzaCollectorsAndNotifyRecvListeners(stanza);
    }

    protected void invokeStanzaCollectorsAndNotifyRecvListeners(final Stanza stanza) {
        final IQRequestHandler iQRequestHandler;
        StanzaError.Condition condition;
        if (stanza instanceof IQ) {
            final IQ iq = (IQ) stanza;
            if (iq.isRequestIQ()) {
                QName childElementQName = iq.getChildElementQName();
                int i = AnonymousClass10.$SwitchMap$org$jivesoftware$smack$packet$IQ$Type[iq.getType().ordinal()];
                if (i == 1) {
                    synchronized (this.setIqRequestHandler) {
                        iQRequestHandler = this.setIqRequestHandler.get(childElementQName);
                    }
                } else if (i == 2) {
                    synchronized (this.getIqRequestHandler) {
                        iQRequestHandler = this.getIqRequestHandler.get(childElementQName);
                    }
                } else {
                    throw new IllegalStateException("Should only encounter IQ type 'get' or 'set'");
                }
                if (iQRequestHandler == null) {
                    int i2 = AnonymousClass10.$SwitchMap$org$jivesoftware$smack$SmackConfiguration$UnknownIqRequestReplyMode[this.unknownIqRequestReplyMode.ordinal()];
                    if (i2 != 1) {
                        if (i2 == 2) {
                            condition = StanzaError.Condition.feature_not_implemented;
                        } else if (i2 == 3) {
                            condition = StanzaError.Condition.service_unavailable;
                        } else {
                            throw new AssertionError();
                        }
                        final ErrorIQ createErrorResponse = IQ.createErrorResponse(iq, StanzaError.getBuilder(condition).build());
                        asyncGo(new Runnable() {
                            @Override
                            public final void run() {
                                AbstractXMPPConnection.this.lambda$invokeStanzaCollectorsAndNotifyRecvListeners$9(createErrorResponse);
                            }
                        });
                        return;
                    }
                    return;
                }
                Executor executor = null;
                int i3 = AnonymousClass10.$SwitchMap$org$jivesoftware$smack$iqrequest$IQRequestHandler$Mode[iQRequestHandler.getMode().ordinal()];
                if (i3 == 1) {
                    executor = ASYNC_BUT_ORDERED.asExecutorFor(this);
                } else if (i3 == 2) {
                    executor = new Executor() {
                        @Override
                        public final void execute(Runnable runnable) {
                            AbstractXMPPConnection.this.asyncGoLimited(runnable);
                        }
                    };
                }
                executor.execute(new Runnable() {
                    static final boolean $assertionsDisabled = false;

                    @Override
                    public void run() {
                        IQ handleIQRequest = iQRequestHandler.handleIQRequest(iq);
                        if (handleIQRequest == null) {
                            return;
                        }
                        handleIQRequest.setTo(iq.getFrom());
                        handleIQRequest.setStanzaId(iq.getStanzaId());
                        try {
                            AbstractXMPPConnection.this.sendStanza(handleIQRequest);
                        } catch (InterruptedException | SmackException.NotConnectedException e) {
                            AbstractXMPPConnection.LOGGER.log(Level.WARNING, "Exception while sending response to IQ request", e);
                        }
                    }
                });
                return;
            }
        }
        final LinkedList<StanzaListener> linkedList = new LinkedList();
        extractMatchingListeners(stanza, this.asyncRecvListeners, linkedList);
        for (final StanzaListener stanzaListener : linkedList) {
            asyncGoLimited(new Runnable() {
                @Override
                public void run() {
                    try {
                        stanzaListener.processStanza(stanza);
                    } catch (Exception e) {
                        AbstractXMPPConnection.LOGGER.log(Level.SEVERE, "Exception in async packet listener", (Throwable) e);
                    }
                }
            });
        }
        Iterator<StanzaCollector> it = this.collectors.iterator();
        while (it.hasNext()) {
            it.next().processStanza(stanza);
        }
        linkedList.clear();
        extractMatchingListeners(stanza, this.recvListeners, linkedList);
        for (final StanzaListener stanzaListener2 : linkedList) {
            this.inOrderListeners.performAsyncButOrdered(stanzaListener2, new Runnable() {
                @Override
                public final void run() {
                    AbstractXMPPConnection.lambda$invokeStanzaCollectorsAndNotifyRecvListeners$10(StanzaListener.this, stanza);
                }
            });
        }
        linkedList.clear();
        extractMatchingListeners(stanza, this.syncRecvListeners, linkedList);
        ASYNC_BUT_ORDERED.performAsyncButOrdered(this, new Runnable() {
            @Override
            public void run() {
                Iterator it2 = linkedList.iterator();
                synchronized (AbstractXMPPConnection.this.syncRecvListeners) {
                    while (it2.hasNext()) {
                        if (!AbstractXMPPConnection.this.syncRecvListeners.containsKey((StanzaListener) it2.next())) {
                            it2.remove();
                        }
                    }
                }
                Iterator it3 = linkedList.iterator();
                while (it3.hasNext()) {
                    try {
                        ((StanzaListener) it3.next()).processStanza(stanza);
                    } catch (SmackException.NotConnectedException e) {
                        AbstractXMPPConnection.LOGGER.log(Level.WARNING, "Got not connected exception, aborting", (Throwable) e);
                        return;
                    } catch (Exception e2) {
                        AbstractXMPPConnection.LOGGER.log(Level.SEVERE, "Exception in packet listener", (Throwable) e2);
                    }
                }
            }
        });
    }

    public void lambda$invokeStanzaCollectorsAndNotifyRecvListeners$9(ErrorIQ errorIQ) {
        try {
            sendStanza(errorIQ);
        } catch (InterruptedException | SmackException.NotConnectedException e) {
            LOGGER.log(Level.WARNING, "Exception while sending error IQ to unkown IQ request", e);
        }
    }

    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 void lambda$invokeStanzaCollectorsAndNotifyRecvListeners$10(StanzaListener stanzaListener, Stanza stanza) {
        try {
            stanzaListener.processStanza(stanza);
        } catch (SmackException.NotConnectedException e) {
            LOGGER.log(Level.WARNING, "Got not connected exception, aborting", (Throwable) e);
        } catch (Exception e2) {
            LOGGER.log(Level.SEVERE, "Exception in packet listener", (Throwable) e2);
        }
    }

    public void setWasAuthenticated() {
        if (this.wasAuthenticated) {
            return;
        }
        this.wasAuthenticated = this.authenticated;
    }

    protected void callConnectionConnectingListener() {
        Iterator<ConnectionListener> it = this.connectionListeners.iterator();
        while (it.hasNext()) {
            it.next().connecting(this);
        }
    }

    protected void callConnectionConnectedListener() {
        Iterator<ConnectionListener> it = this.connectionListeners.iterator();
        while (it.hasNext()) {
            it.next().connected(this);
        }
    }

    protected 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);
            }
        }
    }

    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 lambda$notifyConnectionError$7(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.log(Level.WARNING, "Connection " + this + " closed with error", (Throwable) exc);
        }
        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);
            }
        }
    }

    @Override
    public CSPConfiguration getCspConfiguration() {
        return this.cspConfiguration;
    }

    @Override
    public String getMediaDirectory() {
        return this.mediaDirectory;
    }

    @Override
    public String getFileUploadAddress() {
        return this.fileUploadAddress;
    }

    @Override
    public int getConnectionCounter() {
        return this.connectionCounterValue;
    }

    @Override
    public XMPPConnection.FromMode getFromMode() {
        return this.fromMode;
    }

    @Override
    public void setFromMode(XMPPConnection.FromMode fromMode) {
        this.fromMode = fromMode;
    }

    public final void parseFeatures(XmlPullParser xmlPullParser) throws XmlPullParserException, IOException, SmackParsingException {
        this.streamFeatures.clear();
        int depth = xmlPullParser.getDepth();
        while (true) {
            XmlPullParser.Event next = xmlPullParser.next();
            if (next == XmlPullParser.Event.START_ELEMENT && xmlPullParser.getDepth() == depth + 1) {
                FullyQualifiedElement fullyQualifiedElement = null;
                String name = xmlPullParser.getName();
                String namespace = xmlPullParser.getNamespace();
                name.hashCode();
                char c = 65535;
                switch (name.hashCode()) {
                    case -676919238:
                        if (name.equals(Mechanisms.ELEMENT)) {
                            c = 0;
                            break;
                        }
                        break;
                    case 3023933:
                        if (name.equals(Bind.ELEMENT)) {
                            c = 1;
                            break;
                        }
                        break;
                    case 1316817241:
                        if (name.equals(StartTls.ELEMENT)) {
                            c = 2;
                            break;
                        }
                        break;
                    case 1431984486:
                        if (name.equals(Compress.Feature.ELEMENT)) {
                            c = 3;
                            break;
                        }
                        break;
                    case 1984987798:
                        if (name.equals(Session.ELEMENT)) {
                            c = 4;
                            break;
                        }
                        break;
                }
            } else if (next == XmlPullParser.Event.END_ELEMENT && xmlPullParser.getDepth() == depth) {
                return;
            }
        }
    }

    public final void parseFeaturesAndNotify(XmlPullParser xmlPullParser) throws Exception {
        parseFeatures(xmlPullParser);
        if (hasFeature(Mechanisms.ELEMENT, "urn:ietf:params:xml:ns:xmpp-sasl") && (!hasFeature(StartTls.ELEMENT, "urn:ietf:params:xml:ns:xmpp-tls") || this.config.getSecurityMode() == ConnectionConfiguration.SecurityMode.disabled)) {
            this.saslFeatureReceived = true;
            this.tlsHandled = true;
            notifyWaitingThreads();
        }
        if (hasFeature(Bind.ELEMENT, Bind.NAMESPACE) && (!hasFeature(Compress.Feature.ELEMENT, "http://jabber.org/protocol/compress") || !this.config.isCompressionEnabled())) {
            this.lastFeaturesReceived = true;
            notifyWaitingThreads();
        }
        afterFeaturesReceived();
    }

    @Override
    public <F extends FullyQualifiedElement> F getFeature(QName qName) {
        return (F) this.streamFeatures.get(qName);
    }

    @Override
    public boolean hasFeature(QName qName) {
        return this.streamFeatures.containsKey(qName);
    }

    protected void addStreamFeature(FullyQualifiedElement fullyQualifiedElement) {
        this.streamFeatures.put(fullyQualifiedElement.getQName(), fullyQualifiedElement);
    }

    @Override
    public SmackFuture<IQ, Exception> sendIqRequestAsync(IQ iq) {
        return sendIqRequestAsync(iq, getReplyTimeout());
    }

    @Override
    public SmackFuture<IQ, Exception> sendIqRequestAsync(IQ iq, long j) {
        return sendAsync(iq, new IQReplyFilter(iq, this), j);
    }

    @Override
    public <S extends Stanza> SmackFuture<S, Exception> sendAsync(S s, StanzaFilter stanzaFilter) {
        return sendAsync(s, stanzaFilter, getReplyTimeout());
    }

    @Override
    public <S extends Stanza> SmackFuture<S, Exception> sendAsync(S s, final StanzaFilter stanzaFilter, long j) {
        Objects.requireNonNull(s, "stanza must not be null");
        Objects.requireNonNull(stanzaFilter, "replyFilter must not be null");
        final SmackFuture.InternalSmackFuture internalSmackFuture = new SmackFuture.InternalSmackFuture();
        final StanzaListener stanzaListener = new StanzaListener() {
            @Override
            public void processStanza(Stanza stanza) throws SmackException.NotConnectedException, InterruptedException {
                if (AbstractXMPPConnection.this.removeAsyncStanzaListener(this)) {
                    try {
                        XMPPException.XMPPErrorException.ifHasErrorThenThrow(stanza);
                        internalSmackFuture.setResult(stanza);
                    } catch (XMPPException.XMPPErrorException e) {
                        internalSmackFuture.setException(e);
                    }
                }
            }
        };
        schedule(new Runnable() {
            @Override
            public void run() {
                SmackException newWith;
                if (AbstractXMPPConnection.this.removeAsyncStanzaListener(stanzaListener)) {
                    if (!AbstractXMPPConnection.this.isConnected()) {
                        newWith = new SmackException.NotConnectedException(AbstractXMPPConnection.this, stanzaFilter);
                    } else {
                        newWith = SmackException.NoResponseException.newWith(AbstractXMPPConnection.this, stanzaFilter);
                    }
                    internalSmackFuture.setException(newWith);
                }
            }
        }, j, TimeUnit.MILLISECONDS);
        addAsyncStanzaListener(stanzaListener, stanzaFilter);
        try {
            sendStanza(s);
        } catch (InterruptedException | SmackException.NotConnectedException e) {
            internalSmackFuture.setException(e);
        }
        return internalSmackFuture;
    }

    @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);
        schedule(new Runnable() {
            @Override
            public void run() {
                AbstractXMPPConnection.this.removeSyncStanzaListener(stanzaListener2);
            }
        }, getReplyTimeout(), TimeUnit.MILLISECONDS);
    }

    @Override
    public IQRequestHandler registerIQRequestHandler(IQRequestHandler iQRequestHandler) {
        IQRequestHandler put;
        IQRequestHandler put2;
        QName qName = iQRequestHandler.getQName();
        int i = AnonymousClass10.$SwitchMap$org$jivesoftware$smack$packet$IQ$Type[iQRequestHandler.getType().ordinal()];
        if (i == 1) {
            synchronized (this.setIqRequestHandler) {
                put = this.setIqRequestHandler.put(qName, iQRequestHandler);
            }
            return put;
        }
        if (i == 2) {
            synchronized (this.getIqRequestHandler) {
                put2 = this.getIqRequestHandler.put(qName, iQRequestHandler);
            }
            return put2;
        }
        throw new IllegalArgumentException("Only IQ type of 'get' and 'set' allowed");
    }

    @Override
    public final IQRequestHandler unregisterIQRequestHandler(IQRequestHandler iQRequestHandler) {
        return unregisterIQRequestHandler(iQRequestHandler.getElement(), iQRequestHandler.getNamespace(), iQRequestHandler.getType());
    }

    @Override
    public IQRequestHandler unregisterIQRequestHandler(String str, String str2, IQ.Type type) {
        IQRequestHandler remove;
        IQRequestHandler remove2;
        QName qName = new QName(str2, str);
        int i = AnonymousClass10.$SwitchMap$org$jivesoftware$smack$packet$IQ$Type[type.ordinal()];
        if (i == 1) {
            synchronized (this.setIqRequestHandler) {
                remove = this.setIqRequestHandler.remove(qName);
            }
            return remove;
        }
        if (i == 2) {
            synchronized (this.getIqRequestHandler) {
                remove2 = this.getIqRequestHandler.remove(qName);
            }
            return remove2;
        }
        throw new IllegalArgumentException("Only IQ type of 'get' and 'set' allowed");
    }

    @Override
    public long getLastStanzaReceived() {
        return this.lastStanzaReceived;
    }

    public final long getAuthenticatedConnectionInitiallyEstablishedTimestamp() {
        return this.authenticatedConnectionInitiallyEstablishedTimestamp;
    }

    public ParsingExceptionCallback getParsingExceptionCallback() {
        return this.parsingExceptionCallback;
    }

    public void setParsingExceptionCallback(ParsingExceptionCallback parsingExceptionCallback) {
        this.parsingExceptionCallback = parsingExceptionCallback;
    }

    public final String toString() {
        EntityFullJid user = getUser();
        return getClass().getSimpleName() + '[' + (user == null ? "not-authenticated" : user.toString()) + "] (" + getConnectionCounter() + ')';
    }

    public void asyncGoLimited(final Runnable runnable) {
        Runnable runnable2 = new Runnable() {
            @Override
            public void run() {
                runnable.run();
                synchronized (AbstractXMPPConnection.this.deferredAsyncRunnables) {
                    Runnable runnable3 = (Runnable) AbstractXMPPConnection.this.deferredAsyncRunnables.poll();
                    if (runnable3 == null) {
                        AbstractXMPPConnection.access$510(AbstractXMPPConnection.this);
                    } else {
                        AbstractXMPPConnection.access$610(AbstractXMPPConnection.this);
                        AbstractXMPPConnection.asyncGo(runnable3);
                    }
                }
            }
        };
        synchronized (this.deferredAsyncRunnables) {
            int i = this.currentAsyncRunnables;
            if (i < this.maxAsyncRunnables) {
                this.currentAsyncRunnables = i + 1;
                asyncGo(runnable2);
            } else {
                this.deferredAsyncRunnablesCount++;
                this.deferredAsyncRunnables.add(runnable2);
            }
            int i2 = this.deferredAsyncRunnablesCount;
            if (i2 >= 100 && this.deferredAsyncRunnablesCountPrevious < 100) {
                LOGGER.log(Level.WARNING, "High watermark of 100 simultaneous executing runnables reached");
            } else if (i2 >= 20 && this.deferredAsyncRunnablesCountPrevious < 20) {
                LOGGER.log(Level.INFO, "20 simultaneous executing runnables reached");
            }
            this.deferredAsyncRunnablesCountPrevious = i2;
        }
    }

    public void setMaxAsyncOperations(int i) {
        if (i < 1) {
            throw new IllegalArgumentException("Max async operations must be greater than 0");
        }
        synchronized (this.deferredAsyncRunnables) {
            this.maxAsyncRunnables = i;
        }
    }

    public final SmackReactor getReactor() {
        return SMACK_REACTOR;
    }

    public void onStreamOpen(XmlPullParser xmlPullParser) {
        if ("jabber:client".equals(xmlPullParser.getNamespace(null))) {
            this.streamId = xmlPullParser.getAttributeValue("", "id");
            this.incomingStreamXmlEnvironment = XmlEnvironment.from(xmlPullParser);
            String attributeValue = xmlPullParser.getAttributeValue("", "from");
            if (attributeValue == null) {
                return;
            }
            try {
                DomainBareJid domainBareFrom = JidCreate.domainBareFrom(attributeValue);
                DomainBareJid xMPPServiceDomain = this.config.getXMPPServiceDomain();
                if (xMPPServiceDomain.equals((CharSequence) domainBareFrom)) {
                    return;
                }
                LOGGER.warning("Domain reported by server '" + ((Object) domainBareFrom) + "' does not match configured domain '" + ((Object) xMPPServiceDomain) + "'");
            } catch (XmppStringprepException e) {
                LOGGER.log(Level.WARNING, "XMPP service domain '" + attributeValue + "' as reported by server could not be transformed to a valid JID", (Throwable) e);
            }
        }
    }

    public final void sendStreamOpen() throws SmackException.NotConnectedException, InterruptedException {
        DomainBareJid xMPPServiceDomain = getXMPPServiceDomain();
        CharSequence username = this.config.getUsername();
        AbstractStreamOpen streamOpen = getStreamOpen(xMPPServiceDomain, username != null ? XmppStringUtils.completeJidFrom(username, xMPPServiceDomain) : null, getStreamId(), this.config.getXmlLang());
        sendNonza(streamOpen);
        updateOutgoingStreamXmlEnvironmentOnStreamOpen(streamOpen);
    }

    protected AbstractStreamOpen getStreamOpen(CharSequence charSequence, CharSequence charSequence2, String str, String str2) {
        return new StreamOpen(charSequence, charSequence2, str, str2);
    }

    public void updateOutgoingStreamXmlEnvironmentOnStreamOpen(AbstractStreamOpen abstractStreamOpen) {
        XmlEnvironment.Builder builder = XmlEnvironment.builder();
        builder.with(abstractStreamOpen);
        this.outgoingStreamXmlEnvironment = builder.build();
    }

    public final SmackTlsContext getSmackTlsContext() {
        return this.config.smackTlsContext;
    }

    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;
        }
    }

    @Deprecated
    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 final class GenericInterceptorWrapper<MPB extends MessageOrPresenceBuilder<MP, MPB>, MP extends MessageOrPresence<MPB>> {
        private final Predicate<MP> stanzaFilter;
        private final Consumer<MPB> stanzaInterceptor;

        private GenericInterceptorWrapper(Consumer<MPB> consumer, Predicate<MP> predicate) {
            this.stanzaInterceptor = consumer;
            this.stanzaFilter = predicate;
        }

        public boolean filterMatches(MP mp) {
            Predicate<MP> predicate = this.stanzaFilter;
            return predicate == null || predicate.test(mp);
        }

        public Consumer<MPB> getInterceptor() {
            return this.stanzaInterceptor;
        }
    }
}