package defpackage;

import com.hierynomus.protocol.transport.TransportException;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.net.Socket;
import java.util.ArrayList;
import java.util.concurrent.locks.ReentrantLock;
import javax.net.SocketFactory;

/* renamed from: ᵹˏˎ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C5036 {

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public Serializable f18818;

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public Object f18819;

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public Object f18820;

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public Object f18821;

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public Object f18822;

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final /* synthetic */ int f18823;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public int f18824;

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public Object f18825;

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public Object f18826;

    public C5036(int i) {
        this.f18823 = i;
        switch (i) {
            case 2:
                this.f18826 = "";
                this.f18818 = "";
                this.f18824 = -1;
                this.f18819 = AbstractC2240.m5911("");
                break;
        }
    }

    public C5036(SocketFactory socketFactory, int i, C1601 c1601) {
        this.f18823 = 0;
        this.f18821 = AbstractC1385.m4255(C5036.class);
        this.f18818 = new ReentrantLock();
        new C4601();
        this.f18824 = i;
        this.f18820 = socketFactory;
        this.f18826 = c1601;
    }

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public static ArrayList m10498(String str) {
        ArrayList arrayList = new ArrayList();
        int i = 0;
        while (i <= str.length()) {
            int iM5058 = AbstractC1789.m5058(str, '&', i, 4);
            if (iM5058 == -1) {
                iM5058 = str.length();
            }
            int iM50582 = AbstractC1789.m5058(str, '=', i, 4);
            if (iM50582 == -1 || iM50582 > iM5058) {
                arrayList.add(str.substring(i, iM5058));
                arrayList.add(null);
            } else {
                arrayList.add(str.substring(i, iM50582));
                arrayList.add(str.substring(iM50582 + 1, iM5058));
            }
            i = iM5058 + 1;
        }
        return arrayList;
    }

    /* JADX WARN: Removed duplicated region for block: B:38:0x00ab  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public java.lang.String toString() {
        /*
            Method dump skipped, instructions count: 406
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.C5036.toString():java.lang.String");
    }

    /* JADX WARN: Removed duplicated region for block: B:4:0x002a  */
    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void m10499(defpackage.C1489 r20, java.lang.String r21) {
        /*
            Method dump skipped, instructions count: 915
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.C5036.m10499(ˋᵔˊ, java.lang.String):void");
    }

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public void m10500(ᵢˇᵭ r7) {
        InterfaceC0567 interfaceC0567 = (InterfaceC0567) this.f18821;
        interfaceC0567.mo2392(r7, "Acquiring write lock to send packet << {} >>");
        ReentrantLock reentrantLock = (ReentrantLock) this.f18818;
        reentrantLock.lock();
        try {
            if (!m10505()) {
                throw new TransportException(String.format("Cannot write %s as transport is disconnected", r7));
            }
            try {
                interfaceC0567.mo2409(r7, "Writing packet {}");
                Object obj = ((C1601) this.f18826).f6352;
                C3702 c3702 = new C3702();
                r7.m9326(c3702);
                m10504(c3702.m9341());
                ((BufferedOutputStream) this.f18825).write(c3702.f16315, c3702.f16314, c3702.m9341());
                ((BufferedOutputStream) this.f18825).flush();
                interfaceC0567.mo2392(r7, "Packet {} sent, lock released.");
            } catch (IOException e) {
                throw new TransportException(e);
            }
        } finally {
            reentrantLock.unlock();
        }
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public int m10501() {
        int i = this.f18824;
        if (i != -1) {
            return i;
        }
        String str = (String) this.f18821;
        if (str.equals("http")) {
            return 80;
        }
        return str.equals("https") ? 443 : -1;
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public C1489 m10502() {
        ArrayList arrayList;
        String str = (String) this.f18821;
        if (str == null) {
            ᵹˉᵞ.ᵳٴᵶ("scheme == null");
            return null;
        }
        String str2 = ᵙᵛᵯ.ᵡⁱᵥ(0, 0, 7, (String) this.f18826);
        String str3 = ᵙᵛᵯ.ᵡⁱᵥ(0, 0, 7, (String) this.f18818);
        String str4 = (String) this.f18820;
        if (str4 == null) {
            ᵹˉᵞ.ᵳٴᵶ("host == null");
            return null;
        }
        int iM10501 = m10501();
        ArrayList arrayList2 = (ArrayList) this.f18819;
        ArrayList arrayList3 = new ArrayList(AbstractC3869.m8517(arrayList2, 10));
        int size = arrayList2.size();
        int i = 0;
        while (i < size) {
            Object obj = arrayList2.get(i);
            i++;
            arrayList3.add(ᵙᵛᵯ.ᵡⁱᵥ(0, 0, 7, (String) obj));
        }
        ArrayList arrayList4 = (ArrayList) this.f18825;
        if (arrayList4 != null) {
            ArrayList arrayList5 = new ArrayList(AbstractC3869.m8517(arrayList4, 10));
            int size2 = arrayList4.size();
            int i2 = 0;
            while (i2 < size2) {
                Object obj2 = arrayList4.get(i2);
                i2++;
                String str5 = (String) obj2;
                arrayList5.add(str5 != null ? ᵙᵛᵯ.ᵡⁱᵥ(0, 0, 3, str5) : null);
            }
            arrayList = arrayList5;
        } else {
            arrayList = null;
        }
        String str6 = (String) this.f18822;
        return new C1489(str, str2, str3, str4, iM10501, arrayList3, arrayList, str6 != null ? ᵙᵛᵯ.ᵡⁱᵥ(0, 0, 7, str6) : null, toString());
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public void m10503() {
        ReentrantLock reentrantLock = (ReentrantLock) this.f18818;
        reentrantLock.lock();
        try {
            if (!m10505()) {
                reentrantLock.unlock();
                return;
            }
            RunnableC1914 runnableC1914 = (RunnableC1914) this.f18822;
            runnableC1914.getClass();
            RunnableC1914.f7709.mo2406("Stopping PacketReader...");
            runnableC1914.f7714.set(true);
            runnableC1914.f7713.interrupt();
            if (((Socket) this.f18819).getInputStream() != null) {
                ((Socket) this.f18819).getInputStream().close();
            }
            BufferedOutputStream bufferedOutputStream = (BufferedOutputStream) this.f18825;
            if (bufferedOutputStream != null) {
                bufferedOutputStream.close();
                this.f18825 = null;
            }
            Socket socket = (Socket) this.f18819;
            if (socket != null) {
                socket.close();
                this.f18819 = null;
            }
            reentrantLock.unlock();
        } catch (Throwable th) {
            reentrantLock.unlock();
            throw th;
        }
    }

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public void m10504(int i) throws IOException {
        ((BufferedOutputStream) this.f18825).write(0);
        ((BufferedOutputStream) this.f18825).write((byte) (i >> 16));
        ((BufferedOutputStream) this.f18825).write((byte) (i >> 8));
        ((BufferedOutputStream) this.f18825).write((byte) (i & 255));
    }

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public boolean m10505() {
        Socket socket = (Socket) this.f18819;
        return (socket == null || !socket.isConnected() || ((Socket) this.f18819).isClosed()) ? false : true;
    }
}
