CarrotChat v2.8.80.240429版本的 MD5 值为:fdf98761f01e715a89df24b85b0d206e

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


package org.jivesoftware.smack;

import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.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.SmackConfiguration;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.StanzaCollector;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.compress.packet.Compress;
import org.jivesoftware.smack.compression.XMPPInputOutputStream;
import org.jivesoftware.smack.debugger.SmackDebugger;
import org.jivesoftware.smack.filter.IQReplyFilter;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.filter.StanzaIdFilter;
import org.jivesoftware.smack.iqrequest.IQRequestHandler;
import org.jivesoftware.smack.packet.Bind;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Mechanisms;
import org.jivesoftware.smack.packet.Nonza;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Session;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.StartTls;
import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.sasl.core.SASLAnonymous;
import org.jivesoftware.smack.util.BoundedThreadPoolExecutor;
import org.jivesoftware.smack.util.DNSUtil;
import org.jivesoftware.smack.util.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.DNSResolver;
import org.jivesoftware.smack.util.dns.HostAddress;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.EntityFullJid;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.parts.Resourcepart;
import org.jxmpp.util.XmppStringUtils;
import org.xmlpull.v1.XmlPullParser;

public abstract class AbstractXMPPConnection implements XMPPConnection {
    static final boolean $assertionsDisabled = false;
    private static final Logger LOGGER = Logger.getLogger(AbstractXMPPConnection.class.getName());
    private static final AtomicInteger connectionCounter = new AtomicInteger(0);
    protected XMPPInputOutputStream compressionHandler;
    protected final ConnectionConfiguration config;
    protected String host;
    protected List<HostAddress> hostAddresses;
    private long lastStanzaReceived;
    protected int port;
    protected Reader reader;
    protected final SASLAuthentication saslAuthentication;
    protected String streamId;
    private String usedPassword;
    private Resourcepart usedResource;
    private String usedUsername;
    protected EntityFullJid user;
    protected Writer writer;
    private DomainBareJid xmppServiceDomain;
    protected final Set<ConnectionListener> connectionListeners = new CopyOnWriteArraySet();
    private final Collection<StanzaCollector> collectors = new ConcurrentLinkedQueue();
    private final Map<StanzaListener, ListenerWrapper> syncRecvListeners = new LinkedHashMap();
    private final Map<StanzaListener, ListenerWrapper> asyncRecvListeners = new LinkedHashMap();
    private final Map<StanzaListener, ListenerWrapper> sendListeners = new HashMap();
    private final Map<StanzaListener, InterceptorWrapper> interceptors = new HashMap();
    protected final Lock connectionLock = new ReentrantLock();
    protected final Map<String, ExtensionElement> streamFeatures = new HashMap();
    protected boolean connected = false;
    private long replyTimeout = SmackConfiguration.getDefaultReplyTimeout();
    protected SmackDebugger debugger = null;
    protected final SynchronizationPoint<SmackException> tlsHandled = new SynchronizationPoint<>(this, "establishing TLS");
    protected final SynchronizationPoint<Exception> lastFeaturesReceived = new SynchronizationPoint<>(this, "last stream features received from server");
    protected final SynchronizationPoint<XMPPException> saslFeatureReceived = new SynchronizationPoint<>(this, "SASL mechanisms stream feature from server");
    protected final int connectionCounterValue = connectionCounter.getAndIncrement();
    private XMPPConnection.FromMode fromMode = XMPPConnection.FromMode.OMITTED;
    private ParsingExceptionCallback parsingExceptionCallback = SmackConfiguration.getDefaultParsingExceptionCallback();
    private final BoundedThreadPoolExecutor executorService = new BoundedThreadPoolExecutor(1, 1, 0, TimeUnit.SECONDS, 100, new SmackExecutorThreadFactory(this, "Incoming Processor"));
    private final ScheduledExecutorService removeCallbacksService = Executors.newSingleThreadScheduledExecutor(new SmackExecutorThreadFactory(this, "Remove Callbacks"));
    private final ExecutorService cachedExecutorService = Executors.newCachedThreadPool(new SmackExecutorThreadFactory(this, "Cached Executor"));
    private final ExecutorService singleThreadedExecutorService = Executors.newSingleThreadExecutor(new SmackExecutorThreadFactory(this, "Single Threaded Executor"));
    protected boolean authenticated = false;
    protected boolean wasAuthenticated = false;
    private final Map<String, IQRequestHandler> setIqRequestHandler = new HashMap();
    private final Map<String, IQRequestHandler> getIqRequestHandler = new HashMap();
    private SmackConfiguration.UnknownIqRequestReplyMode unknownIqRequestReplyMode = SmackConfiguration.getUnknownIqRequestReplyMode();

    public static class AnonymousClass10 {
        static final int[] $SwitchMap$org$jivesoftware$smack$SmackConfiguration$UnknownIqRequestReplyMode;
        static final int[] $SwitchMap$org$jivesoftware$smack$XMPPConnection$FromMode;
        static final int[] $SwitchMap$org$jivesoftware$smack$iqrequest$IQRequestHandler$Mode;
        static final int[] $SwitchMap$org$jivesoftware$smack$packet$IQ$Type;

        static {
            int[] iArr = new int[IQRequestHandler.Mode.values().length];
            $SwitchMap$org$jivesoftware$smack$iqrequest$IQRequestHandler$Mode = iArr;
            try {
                iArr[IQRequestHandler.Mode.sync.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                $SwitchMap$org$jivesoftware$smack$iqrequest$IQRequestHandler$Mode[IQRequestHandler.Mode.async.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            int[] iArr2 = new int[SmackConfiguration.UnknownIqRequestReplyMode.values().length];
            $SwitchMap$org$jivesoftware$smack$SmackConfiguration$UnknownIqRequestReplyMode = iArr2;
            try {
                iArr2[SmackConfiguration.UnknownIqRequestReplyMode.doNotReply.ordinal()] = 1;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                $SwitchMap$org$jivesoftware$smack$SmackConfiguration$UnknownIqRequestReplyMode[SmackConfiguration.UnknownIqRequestReplyMode.replyFeatureNotImplemented.ordinal()] = 2;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                $SwitchMap$org$jivesoftware$smack$SmackConfiguration$UnknownIqRequestReplyMode[SmackConfiguration.UnknownIqRequestReplyMode.replyServiceUnavailable.ordinal()] = 3;
            } catch (NoSuchFieldError unused5) {
            }
            int[] iArr3 = new int[IQ.Type.values().length];
            $SwitchMap$org$jivesoftware$smack$packet$IQ$Type = iArr3;
            try {
                iArr3[IQ.Type.set.ordinal()] = 1;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                $SwitchMap$org$jivesoftware$smack$packet$IQ$Type[IQ.Type.get.ordinal()] = 2;
            } catch (NoSuchFieldError unused7) {
            }
            int[] iArr4 = new int[XMPPConnection.FromMode.values().length];
            $SwitchMap$org$jivesoftware$smack$XMPPConnection$FromMode = iArr4;
            try {
                iArr4[XMPPConnection.FromMode.OMITTED.ordinal()] = 1;
            } catch (NoSuchFieldError unused8) {
            }
            try {
                $SwitchMap$org$jivesoftware$smack$XMPPConnection$FromMode[XMPPConnection.FromMode.USER.ordinal()] = 2;
            } catch (NoSuchFieldError unused9) {
            }
            try {
                $SwitchMap$org$jivesoftware$smack$XMPPConnection$FromMode[XMPPConnection.FromMode.UNCHANGED.ordinal()] = 3;
            } catch (NoSuchFieldError unused10) {
            }
        }
    }

    public static class InterceptorWrapper {
        private final StanzaFilter packetFilter;
        private final StanzaListener packetInterceptor;

        public InterceptorWrapper(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
            this.packetInterceptor = stanzaListener;
            this.packetFilter = stanzaFilter;
        }

        public boolean filterMatches(Stanza stanza) {
            StanzaFilter stanzaFilter = this.packetFilter;
            if (stanzaFilter != null && !stanzaFilter.accept(stanza)) {
                return false;
            }
            return true;
        }

        public StanzaListener getInterceptor() {
            return this.packetInterceptor;
        }
    }

    public static class ListenerWrapper {
        private final StanzaFilter packetFilter;
        private final StanzaListener packetListener;

        public ListenerWrapper(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
            this.packetListener = stanzaListener;
            this.packetFilter = stanzaFilter;
        }

        public boolean filterMatches(Stanza stanza) {
            StanzaFilter stanzaFilter = this.packetFilter;
            if (stanzaFilter != null && !stanzaFilter.accept(stanza)) {
                return false;
            }
            return true;
        }

        public StanzaListener getListener() {
            return this.packetListener;
        }
    }

    static {
        SmackConfiguration.getVersion();
    }

    public AbstractXMPPConnection(ConnectionConfiguration connectionConfiguration) {
        this.saslAuthentication = new SASLAuthentication(this, connectionConfiguration);
        this.config = connectionConfiguration;
        Iterator<ConnectionCreationListener> it = XMPPConnectionRegistry.getConnectionCreationListeners().iterator();
        while (it.hasNext()) {
            it.next().connectionCreated(this);
        }
    }

    private void 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 e10) {
                LOGGER.log(Level.SEVERE, "Packet interceptor threw exception", (Throwable) e10);
            }
        }
    }

    @Deprecated
    public static void setReplyToUnknownIqDefault(boolean z10) {
        SmackConfiguration.UnknownIqRequestReplyMode unknownIqRequestReplyMode;
        if (z10) {
            unknownIqRequestReplyMode = SmackConfiguration.UnknownIqRequestReplyMode.replyServiceUnavailable;
        } else {
            unknownIqRequestReplyMode = SmackConfiguration.UnknownIqRequestReplyMode.doNotReply;
        }
        SmackConfiguration.setUnknownIqRequestReplyMode(unknownIqRequestReplyMode);
    }

    @Override
    public void addAsyncStanzaListener(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
        if (stanzaListener != null) {
            ListenerWrapper listenerWrapper = new ListenerWrapper(stanzaListener, stanzaFilter);
            synchronized (this.asyncRecvListeners) {
                this.asyncRecvListeners.put(stanzaListener, listenerWrapper);
            }
            return;
        }
        throw new NullPointerException("Packet listener is null.");
    }

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

    @Override
    public void addOneTimeSyncCallback(final StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
        final StanzaListener stanzaListener2 = new StanzaListener() {
            @Override
            public void processStanza(Stanza stanza) throws SmackException.NotConnectedException, InterruptedException, SmackException.NotLoggedInException {
                try {
                    stanzaListener.processStanza(stanza);
                } finally {
                    AbstractXMPPConnection.this.removeSyncStanzaListener(this);
                }
            }
        };
        addSyncStanzaListener(stanzaListener2, stanzaFilter);
        this.removeCallbacksService.schedule(new Runnable() {
            @Override
            public void run() {
                AbstractXMPPConnection.this.removeSyncStanzaListener(stanzaListener2);
            }
        }, getReplyTimeout(), TimeUnit.MILLISECONDS);
    }

    @Override
    public void addPacketInterceptor(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
        if (stanzaListener != null) {
            InterceptorWrapper interceptorWrapper = new InterceptorWrapper(stanzaListener, stanzaFilter);
            synchronized (this.interceptors) {
                this.interceptors.put(stanzaListener, interceptorWrapper);
            }
            return;
        }
        throw new NullPointerException("Packet interceptor is null.");
    }

    @Override
    @Deprecated
    public void addPacketListener(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
        addAsyncStanzaListener(stanzaListener, stanzaFilter);
    }

    @Override
    public void addPacketSendingListener(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
        if (stanzaListener != null) {
            ListenerWrapper listenerWrapper = new ListenerWrapper(stanzaListener, stanzaFilter);
            synchronized (this.sendListeners) {
                this.sendListeners.put(stanzaListener, listenerWrapper);
            }
            return;
        }
        throw new NullPointerException("Packet listener is null.");
    }

    protected void addStreamFeature(ExtensionElement extensionElement) {
        this.streamFeatures.put(XmppStringUtils.generateKey(extensionElement.getElementName(), extensionElement.getNamespace()), extensionElement);
    }

    @Override
    public void addSyncStanzaListener(StanzaListener stanzaListener, StanzaFilter stanzaFilter) {
        if (stanzaListener != null) {
            ListenerWrapper listenerWrapper = new ListenerWrapper(stanzaListener, stanzaFilter);
            synchronized (this.syncRecvListeners) {
                this.syncRecvListeners.put(stanzaListener, listenerWrapper);
            }
            return;
        }
        throw new NullPointerException("Packet listener is null.");
    }

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

    public void afterSuccessfulLogin(boolean z10) throws SmackException.NotConnectedException, InterruptedException {
        SmackDebugger smackDebugger;
        this.authenticated = true;
        if (this.config.isDebuggerEnabled() && (smackDebugger = this.debugger) != null) {
            smackDebugger.userHasLogged(this.user);
        }
        callConnectionAuthenticatedListener(z10);
        if (this.config.isSendPresence() && !z10) {
            sendStanza(new Presence(Presence.Type.available));
        }
    }

    public final void asyncGo(Runnable runnable) {
        this.cachedExecutorService.execute(runnable);
    }

    public void bindResourceAndEstablishSession(Resourcepart resourcepart) throws XMPPException.XMPPErrorException, SmackException, InterruptedException {
        LOGGER.finer("Waiting for last features to be received before continuing with resource binding");
        this.lastFeaturesReceived.checkIfSuccessOrWait();
        if (hasFeature(Bind.ELEMENT, Bind.NAMESPACE)) {
            Bind newSet = Bind.newSet(resourcepart);
            EntityFullJid jid = ((Bind) createStanzaCollectorAndSend(new StanzaIdFilter(newSet), newSet).nextResultOrThrow()).getJid();
            this.user = jid;
            this.xmppServiceDomain = jid.asDomainBareJid();
            Session.Feature feature = (Session.Feature) getFeature(Session.ELEMENT, Session.NAMESPACE);
            boolean isLegacySessionDisabled = getConfiguration().isLegacySessionDisabled();
            if (feature != null && !feature.isOptional() && !isLegacySessionDisabled) {
                Session session = new Session();
                createStanzaCollectorAndSend(new StanzaIdFilter(session), session).nextResultOrThrow();
                return;
            }
            return;
        }
        throw new SmackException.ResourceBindingNotOfferedException();
    }

    protected void callConnectionAuthenticatedListener(boolean z10) {
        Iterator<ConnectionListener> it = this.connectionListeners.iterator();
        while (it.hasNext()) {
            try {
                it.next().authenticated(this, z10);
            } catch (Exception e10) {
                LOGGER.log(Level.SEVERE, "Exception in authenticated listener", (Throwable) e10);
            }
        }
    }

    void callConnectionClosedListener() {
        Iterator<ConnectionListener> it = this.connectionListeners.iterator();
        while (it.hasNext()) {
            try {
                it.next().connectionClosed();
            } catch (Exception e10) {
                LOGGER.log(Level.SEVERE, "Error in listener while closing connection", (Throwable) e10);
            }
        }
    }

    public void callConnectionClosedOnErrorListener(Exception exc) {
        boolean z10;
        if ((exc instanceof XMPPException.StreamErrorException) && ((XMPPException.StreamErrorException) exc).getStreamError().getCondition() == StreamError.Condition.not_authorized && this.wasAuthenticated) {
            z10 = 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 {
            z10 = true;
        }
        if (z10) {
            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 e10) {
                LOGGER.log(Level.SEVERE, "Error in listener while closing connection", (Throwable) e10);
            }
        }
    }

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

    public synchronized AbstractXMPPConnection connect() throws SmackException, IOException, XMPPException, InterruptedException {
        throwAlreadyConnectedExceptionIfAppropriate();
        this.saslAuthentication.init();
        this.saslFeatureReceived.init();
        this.lastFeaturesReceived.init();
        this.tlsHandled.init();
        this.streamId = null;
        connectInternal();
        this.tlsHandled.checkIfSuccessOrWaitOrThrow();
        this.saslFeatureReceived.checkIfSuccessOrWaitOrThrow();
        if (!isSecureConnection() && getConfiguration().getSecurityMode() == ConnectionConfiguration.SecurityMode.required) {
            shutdown();
            throw new SmackException.SecurityRequiredByClientException();
        }
        this.connected = true;
        callConnectionConnectedListener();
        return this;
    }

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

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

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

    public void disconnect() {
        try {
            disconnect(new Presence(Presence.Type.unavailable));
        } catch (SmackException.NotConnectedException e10) {
            LOGGER.log(Level.FINEST, "Connection is already disconnected", (Throwable) e10);
        }
    }

    protected void finalize() throws Throwable {
        LOGGER.fine("finalizing " + this + ": Shutting down executor services");
        try {
            this.executorService.shutdownNow();
            this.cachedExecutorService.shutdown();
            this.removeCallbacksService.shutdownNow();
            this.singleThreadedExecutorService.shutdownNow();
        } finally {
            try {
            } finally {
            }
        }
    }

    public void firePacketSendingListeners(final Stanza stanza) {
        final LinkedList linkedList = new LinkedList();
        synchronized (this.sendListeners) {
            for (ListenerWrapper listenerWrapper : this.sendListeners.values()) {
                if (listenerWrapper.filterMatches(stanza)) {
                    linkedList.add(listenerWrapper.getListener());
                }
            }
        }
        if (linkedList.isEmpty()) {
            return;
        }
        asyncGo(new Runnable() {
            @Override
            public void run() {
                Iterator it = linkedList.iterator();
                while (it.hasNext()) {
                    try {
                        ((StanzaListener) it.next()).processStanza(stanza);
                    } catch (Exception e10) {
                        AbstractXMPPConnection.LOGGER.log(Level.WARNING, "Sending listener threw exception", (Throwable) e10);
                    }
                }
            }
        });
    }

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

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

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

    @Override
    public <F extends ExtensionElement> F getFeature(String str, String str2) {
        return (F) this.streamFeatures.get(XmppStringUtils.generateKey(str, str2));
    }

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

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

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

    @Override
    public long getPacketReplyTimeout() {
        return getReplyTimeout();
    }

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

    @Override
    public int getPort() {
        return this.port;
    }

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

    public SASLAuthentication getSASLAuthentication() {
        return this.saslAuthentication;
    }

    @Override
    public DomainBareJid getServiceName() {
        return getXMPPServiceDomain();
    }

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

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

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

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

    @Override
    public boolean hasFeature(String str, String str2) {
        if (getFeature(str, str2) != null) {
            return true;
        }
        return false;
    }

    public void initDebugger() {
        if (this.reader != null && this.writer != null) {
            if (this.config.isDebuggerEnabled()) {
                if (this.debugger == null) {
                    this.debugger = SmackConfiguration.createDebugger(this, this.writer, this.reader);
                }
                SmackDebugger smackDebugger = this.debugger;
                if (smackDebugger == null) {
                    LOGGER.severe("Debugging enabled but could not find debugger class");
                    return;
                } else {
                    this.reader = smackDebugger.newConnectionReader(this.reader);
                    this.writer = this.debugger.newConnectionWriter(this.writer);
                    return;
                }
            }
            return;
        }
        throw new NullPointerException("Reader or writer isn't initialized.");
    }

    protected void invokeStanzaCollectorsAndNotifyRecvListeners(final Stanza stanza) {
        final IQRequestHandler iQRequestHandler;
        XMPPError.Condition condition;
        if (stanza instanceof IQ) {
            final IQ iq = (IQ) stanza;
            IQ.Type type = iq.getType();
            int[] iArr = AnonymousClass10.$SwitchMap$org$jivesoftware$smack$packet$IQ$Type;
            int i10 = iArr[type.ordinal()];
            if (i10 == 1 || i10 == 2) {
                String generateKey = XmppStringUtils.generateKey(iq.getChildElementName(), iq.getChildElementNamespace());
                int i11 = iArr[type.ordinal()];
                if (i11 != 1) {
                    if (i11 == 2) {
                        synchronized (this.getIqRequestHandler) {
                            iQRequestHandler = this.getIqRequestHandler.get(generateKey);
                        }
                    } else {
                        throw new IllegalStateException("Should only encounter IQ type 'get' or 'set'");
                    }
                } else {
                    synchronized (this.setIqRequestHandler) {
                        iQRequestHandler = this.setIqRequestHandler.get(generateKey);
                    }
                }
                if (iQRequestHandler == null) {
                    int i12 = AnonymousClass10.$SwitchMap$org$jivesoftware$smack$SmackConfiguration$UnknownIqRequestReplyMode[this.unknownIqRequestReplyMode.ordinal()];
                    if (i12 != 1) {
                        if (i12 != 2) {
                            if (i12 == 3) {
                                condition = XMPPError.Condition.service_unavailable;
                            } else {
                                throw new AssertionError();
                            }
                        } else {
                            condition = XMPPError.Condition.feature_not_implemented;
                        }
                        try {
                            sendStanza(IQ.createErrorResponse(iq, XMPPError.getBuilder(condition)));
                        } catch (InterruptedException | SmackException.NotConnectedException e10) {
                            LOGGER.log(Level.WARNING, "Exception while sending error IQ to unkown IQ request", e10);
                        }
                    } else {
                        return;
                    }
                } else {
                    ExecutorService executorService = null;
                    int i13 = AnonymousClass10.$SwitchMap$org$jivesoftware$smack$iqrequest$IQRequestHandler$Mode[iQRequestHandler.getMode().ordinal()];
                    if (i13 != 1) {
                        if (i13 == 2) {
                            executorService = this.cachedExecutorService;
                        }
                    } else {
                        executorService = this.singleThreadedExecutorService;
                    }
                    executorService.execute(new Runnable() {
                        @Override
                        public void run() {
                            IQ handleIQRequest = iQRequestHandler.handleIQRequest(iq);
                            if (handleIQRequest == null) {
                                return;
                            }
                            try {
                                AbstractXMPPConnection.this.sendStanza(handleIQRequest);
                            } catch (InterruptedException | SmackException.NotConnectedException e11) {
                                AbstractXMPPConnection.LOGGER.log(Level.WARNING, "Exception while sending response to IQ request", e11);
                            }
                        }
                    });
                    return;
                }
            }
        }
        final LinkedList<StanzaListener> linkedList = new LinkedList();
        synchronized (this.asyncRecvListeners) {
            for (ListenerWrapper listenerWrapper : this.asyncRecvListeners.values()) {
                if (listenerWrapper.filterMatches(stanza)) {
                    linkedList.add(listenerWrapper.getListener());
                }
            }
        }
        for (final StanzaListener stanzaListener : linkedList) {
            asyncGo(new Runnable() {
                @Override
                public void run() {
                    try {
                        stanzaListener.processStanza(stanza);
                    } catch (Exception e11) {
                        AbstractXMPPConnection.LOGGER.log(Level.SEVERE, "Exception in async packet listener", (Throwable) e11);
                    }
                }
            });
        }
        Iterator<StanzaCollector> it = this.collectors.iterator();
        while (it.hasNext()) {
            it.next().processStanza(stanza);
        }
        linkedList.clear();
        synchronized (this.syncRecvListeners) {
            for (ListenerWrapper listenerWrapper2 : this.syncRecvListeners.values()) {
                if (listenerWrapper2.filterMatches(stanza)) {
                    linkedList.add(listenerWrapper2.getListener());
                }
            }
        }
        this.singleThreadedExecutorService.execute(new Runnable() {
            @Override
            public void run() {
                Iterator it2 = linkedList.iterator();
                while (it2.hasNext()) {
                    try {
                        ((StanzaListener) it2.next()).processStanza(stanza);
                    } catch (SmackException.NotConnectedException e11) {
                        AbstractXMPPConnection.LOGGER.log(Level.WARNING, "Got not connected exception, aborting", (Throwable) e11);
                        return;
                    } catch (Exception e12) {
                        AbstractXMPPConnection.LOGGER.log(Level.SEVERE, "Exception in packet listener", (Throwable) e12);
                    }
                }
            }
        });
    }

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

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

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

    @Override
    public abstract boolean isSecureConnection();

    @Override
    public abstract boolean isUsingCompression();

    public synchronized void login() throws XMPPException, SmackException, IOException, InterruptedException {
        CharSequence charSequence = this.usedUsername;
        if (charSequence == null) {
            charSequence = this.config.getUsername();
        }
        String str = this.usedPassword;
        if (str == null) {
            str = this.config.getPassword();
        }
        Resourcepart resourcepart = this.usedResource;
        if (resourcepart == null) {
            resourcepart = this.config.getResource();
        }
        login(charSequence, str, resourcepart);
    }

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

    @Deprecated
    protected void notifyReconnection() {
        Iterator<ConnectionListener> it = this.connectionListeners.iterator();
        while (it.hasNext()) {
            try {
                it.next().reconnectionSuccessful();
            } catch (Exception e10) {
                LOGGER.log(Level.WARNING, "notifyReconnection()", (Throwable) e10);
            }
        }
    }

    public void parseAndProcessStanza(XmlPullParser xmlPullParser) throws Exception {
        Stanza stanza;
        ParserUtils.assertAtStartTag(xmlPullParser);
        int depth = xmlPullParser.getDepth();
        try {
            stanza = PacketParserUtils.parseStanza(xmlPullParser);
        } catch (Exception e10) {
            UnparseableStanza unparseableStanza = new UnparseableStanza(PacketParserUtils.parseContentDepth(xmlPullParser, depth), e10);
            ParsingExceptionCallback parsingExceptionCallback = getParsingExceptionCallback();
            if (parsingExceptionCallback != null) {
                parsingExceptionCallback.handleUnparsableStanza(unparseableStanza);
            }
            stanza = null;
        }
        ParserUtils.assertAtEndTag(xmlPullParser);
        if (stanza != null) {
            processStanza(stanza);
        }
    }

    public final void parseFeatures(XmlPullParser xmlPullParser) throws Exception {
        this.streamFeatures.clear();
        int depth = xmlPullParser.getDepth();
        while (true) {
            int next = xmlPullParser.next();
            char c10 = 3;
            if (next == 2 && xmlPullParser.getDepth() == depth + 1) {
                ExtensionElement extensionElement = null;
                String name = xmlPullParser.getName();
                String namespace = xmlPullParser.getNamespace();
                name.hashCode();
                switch (name.hashCode()) {
                    case -676919238:
                        if (name.equals(Mechanisms.ELEMENT)) {
                            c10 = 0;
                            break;
                        }
                        break;
                    case 3023933:
                        if (name.equals(Bind.ELEMENT)) {
                            c10 = 1;
                            break;
                        }
                        break;
                    case 1316817241:
                        if (name.equals(StartTls.ELEMENT)) {
                            c10 = 2;
                            break;
                        }
                        break;
                    case 1431984486:
                        break;
                    case 1984987798:
                        if (name.equals(Session.ELEMENT)) {
                            c10 = 4;
                            break;
                        }
                        break;
                }
                c10 = 65535;
                switch (c10) {
                    case 0:
                        extensionElement = new Mechanisms(PacketParserUtils.parseMechanisms(xmlPullParser));
                        break;
                    case 1:
                        extensionElement = Bind.Feature.INSTANCE;
                        break;
                    case 2:
                        extensionElement = PacketParserUtils.parseStartTlsFeature(xmlPullParser);
                        break;
                    case 3:
                        extensionElement = PacketParserUtils.parseCompressionFeature(xmlPullParser);
                        break;
                    case 4:
                        extensionElement = PacketParserUtils.parseSessionFeature(xmlPullParser);
                        break;
                    default:
                        ExtensionElementProvider<ExtensionElement> streamFeatureProvider = ProviderManager.getStreamFeatureProvider(name, namespace);
                        if (streamFeatureProvider != null) {
                            extensionElement = (ExtensionElement) streamFeatureProvider.parse(xmlPullParser);
                            break;
                        }
                        break;
                }
                if (extensionElement != null) {
                    addStreamFeature(extensionElement);
                }
            } else if (next == 3 && xmlPullParser.getDepth() == depth) {
                if (hasFeature(Mechanisms.ELEMENT, "urn:ietf:params:xml:ns:xmpp-sasl") && (!hasFeature(StartTls.ELEMENT, StartTls.NAMESPACE) || this.config.getSecurityMode() == ConnectionConfiguration.SecurityMode.disabled)) {
                    this.tlsHandled.reportSuccess();
                    this.saslFeatureReceived.reportSuccess();
                }
                if (hasFeature(Bind.ELEMENT, Bind.NAMESPACE) && (!hasFeature(Compress.Feature.ELEMENT, "http://jabber.org/protocol/compress") || !this.config.isCompressionEnabled())) {
                    this.lastFeaturesReceived.reportSuccess();
                }
                afterFeaturesReceived();
                return;
            }
        }
    }

    public List<HostAddress> populateHostAddresses() {
        LinkedList linkedList = new LinkedList();
        ConnectionConfiguration connectionConfiguration = this.config;
        if (connectionConfiguration.hostAddress != null) {
            this.hostAddresses = new ArrayList(1);
            ConnectionConfiguration connectionConfiguration2 = this.config;
            this.hostAddresses.add(new HostAddress(connectionConfiguration2.port, connectionConfiguration2.hostAddress));
        } else if (connectionConfiguration.host != null) {
            this.hostAddresses = new ArrayList(1);
            DNSResolver dNSResolver = DNSUtil.getDNSResolver();
            ConnectionConfiguration connectionConfiguration3 = this.config;
            HostAddress lookupHostAddress = dNSResolver.lookupHostAddress(connectionConfiguration3.host, connectionConfiguration3.port, linkedList, connectionConfiguration3.getDnssecMode());
            if (lookupHostAddress != null) {
                this.hostAddresses.add(lookupHostAddress);
            }
        } else {
            this.hostAddresses = DNSUtil.resolveXMPPServiceDomain(connectionConfiguration.getXMPPServiceDomain().toString(), linkedList, this.config.getDnssecMode());
        }
        return linkedList;
    }

    protected void processStanza(final Stanza stanza) throws InterruptedException {
        this.lastStanzaReceived = System.currentTimeMillis();
        this.executorService.executeBlocking(new Runnable() {
            @Override
            public void run() {
                AbstractXMPPConnection.this.invokeStanzaCollectorsAndNotifyRecvListeners(stanza);
            }
        });
    }

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

    @Override
    public boolean removeAsyncStanzaListener(StanzaListener stanzaListener) {
        boolean z10;
        synchronized (this.asyncRecvListeners) {
            if (this.asyncRecvListeners.remove(stanzaListener) != null) {
                z10 = true;
            } else {
                z10 = false;
            }
        }
        return z10;
    }

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

    @Override
    public void removePacketInterceptor(StanzaListener stanzaListener) {
        synchronized (this.interceptors) {
            this.interceptors.remove(stanzaListener);
        }
    }

    @Override
    @Deprecated
    public boolean removePacketListener(StanzaListener stanzaListener) {
        return removeAsyncStanzaListener(stanzaListener);
    }

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

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

    @Override
    public boolean removeSyncStanzaListener(StanzaListener stanzaListener) {
        boolean z10;
        synchronized (this.syncRecvListeners) {
            if (this.syncRecvListeners.remove(stanzaListener) != null) {
                z10 = true;
            } else {
                z10 = false;
            }
        }
        return z10;
    }

    public final ScheduledFuture<?> schedule(Runnable runnable, long j10, TimeUnit timeUnit) {
        return this.removeCallbacksService.schedule(runnable, j10, timeUnit);
    }

    @Override
    public void sendIqWithResponseCallback(IQ iq, StanzaListener stanzaListener) throws SmackException.NotConnectedException, InterruptedException {
        sendIqWithResponseCallback(iq, stanzaListener, null);
    }

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

    @Override
    @Deprecated
    public void sendPacket(Stanza stanza) throws SmackException.NotConnectedException, InterruptedException {
        sendStanza(stanza);
    }

    @Override
    public void sendStanza(Stanza stanza) throws SmackException.NotConnectedException, InterruptedException {
        Objects.requireNonNull(stanza, "Stanza must not be null");
        throwNotConnectedExceptionIfAppropriate();
        int i10 = AnonymousClass10.$SwitchMap$org$jivesoftware$smack$XMPPConnection$FromMode[this.fromMode.ordinal()];
        if (i10 != 1) {
            if (i10 == 2) {
                stanza.setFrom(getUser());
            }
        } else {
            stanza.setFrom((Jid) null);
        }
        firePacketInterceptors(stanza);
        sendStanzaInternal(stanza);
    }

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

    @Override
    public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter stanzaFilter, StanzaListener stanzaListener) throws SmackException.NotConnectedException, InterruptedException {
        sendStanzaWithResponseCallback(stanza, stanzaFilter, stanzaListener, null);
    }

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

    @Override
    public void setPacketReplyTimeout(long j10) {
        setReplyTimeout(j10);
    }

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

    @Override
    public void setReplyTimeout(long j10) {
        this.replyTimeout = j10;
    }

    @Deprecated
    public void setReplyToUnknownIq(boolean z10) {
        SmackConfiguration.UnknownIqRequestReplyMode unknownIqRequestReplyMode;
        if (z10) {
            unknownIqRequestReplyMode = SmackConfiguration.UnknownIqRequestReplyMode.replyServiceUnavailable;
        } else {
            unknownIqRequestReplyMode = SmackConfiguration.UnknownIqRequestReplyMode.doNotReply;
        }
        this.unknownIqRequestReplyMode = unknownIqRequestReplyMode;
    }

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

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

    protected abstract void shutdown();

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

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

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

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

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

    @Override
    public void sendIqWithResponseCallback(IQ iq, StanzaListener stanzaListener, ExceptionCallback exceptionCallback) throws SmackException.NotConnectedException, InterruptedException {
        sendIqWithResponseCallback(iq, stanzaListener, exceptionCallback, getReplyTimeout());
    }

    @Override
    public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter stanzaFilter, StanzaListener stanzaListener, ExceptionCallback exceptionCallback) throws SmackException.NotConnectedException, InterruptedException {
        sendStanzaWithResponseCallback(stanza, stanzaFilter, stanzaListener, exceptionCallback, getReplyTimeout());
    }

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

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

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

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

    @Override
    public void sendIqWithResponseCallback(IQ iq, StanzaListener stanzaListener, ExceptionCallback exceptionCallback, long j10) throws SmackException.NotConnectedException, InterruptedException {
        sendStanzaWithResponseCallback(iq, new IQReplyFilter(iq, this), stanzaListener, exceptionCallback, j10);
    }

    @Override
    public void sendStanzaWithResponseCallback(Stanza stanza, final StanzaFilter stanzaFilter, final StanzaListener stanzaListener, final ExceptionCallback exceptionCallback, long j10) throws SmackException.NotConnectedException, InterruptedException {
        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 processStanza(Stanza stanza2) throws SmackException.NotConnectedException, InterruptedException, SmackException.NotLoggedInException {
                if (!AbstractXMPPConnection.this.removeAsyncStanzaListener(this)) {
                    return;
                }
                try {
                    XMPPException.XMPPErrorException.ifHasErrorThenThrow(stanza2);
                    stanzaListener.processStanza(stanza2);
                } catch (XMPPException.XMPPErrorException e10) {
                    ExceptionCallback exceptionCallback2 = exceptionCallback;
                    if (exceptionCallback2 != null) {
                        exceptionCallback2.processException(e10);
                    }
                }
            }
        };
        this.removeCallbacksService.schedule(new Runnable() {
            @Override
            public void run() {
                Exception newWith;
                if (AbstractXMPPConnection.this.removeAsyncStanzaListener(stanzaListener2) && exceptionCallback != null) {
                    if (!AbstractXMPPConnection.this.isConnected()) {
                        newWith = new SmackException.NotConnectedException(AbstractXMPPConnection.this, stanzaFilter);
                    } else {
                        newWith = SmackException.NoResponseException.newWith(AbstractXMPPConnection.this, stanzaFilter);
                    }
                    exceptionCallback.processException(newWith);
                }
            }
        }, j10, TimeUnit.MILLISECONDS);
        addAsyncStanzaListener(stanzaListener2, stanzaFilter);
        sendStanza(stanza);
    }

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

    public synchronized void login(CharSequence charSequence, String str) throws XMPPException, SmackException, IOException, InterruptedException {
        login(charSequence, str, this.config.getResource());
    }

    public synchronized void login(CharSequence charSequence, String str, Resourcepart resourcepart) throws XMPPException, SmackException, IOException, InterruptedException {
        if (!this.config.allowNullOrEmptyUsername) {
            StringUtils.requireNotNullOrEmpty(charSequence, "Username must not be null or empty");
        }
        throwNotConnectedExceptionIfAppropriate("Did you call connect() before login()?");
        throwAlreadyLoggedInExceptionIfAppropriate();
        String charSequence2 = charSequence != null ? charSequence.toString() : null;
        this.usedUsername = charSequence2;
        this.usedPassword = str;
        this.usedResource = resourcepart;
        loginInternal(charSequence2, str, resourcepart);
    }
}