package p447.p448.p453;

import java.io.EOFException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import okhttp3.internal.publicsuffix.PublicSuffixDatabase;
import p138.p176.p177.p242.p246.p251.C4303;
import p402.p403.C6563;
import p402.p403.C6564;
import p402.p411.p413.C6635;
import p402.p420.C6695;
import p402.p420.C6703;
import p447.C6875;
import p447.C6884;
import p447.C6905;
import p447.C6908;
import p447.C6933;
import p447.InterfaceC6886;
import p447.p448.C6943;
import p447.p448.p457.C7069;
import p461.C7103;
import p461.C7108;

/* JADX INFO: renamed from: ސ.ޣ.ޅ.ނ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C6985 {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static final C7108 f20328 = C7108.f20634.m10457("\"\\");

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public static final C7108 f20329 = C7108.f20634.m10457("\t ,=");

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static final String m10258(C7103 c7103) {
        long jMo10424 = c7103.mo10424(f20329);
        if (jMo10424 == -1) {
            jMo10424 = c7103.f20630;
        }
        if (jMo10424 != 0) {
            return c7103.mo10411(jMo10424);
        }
        return null;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static final List<C6875> m10259(C6905 c6905, String str) {
        if (c6905 == null) {
            C6635.m9824("$this$parseChallenges");
            throw null;
        }
        if (str == null) {
            C6635.m9824("headerName");
            throw null;
        }
        ArrayList arrayList = new ArrayList();
        int size = c6905.size();
        for (int i = 0; i < size; i++) {
            if (C6703.m9905(str, c6905.m10068(i), true)) {
                C7103 c7103 = new C7103();
                c7103.mo10414(c6905.m10070(i));
                try {
                    m10261(c7103, arrayList);
                } catch (EOFException e) {
                    if (C7069.f20588 == null) {
                        throw null;
                    }
                    C7069.f20586.m10381("Unable to parse challenge", 5, e);
                }
            }
        }
        return arrayList;
    }

    /* JADX WARN: Code restructure failed: missing block: B:127:0x01fd, code lost:
    
        if (okhttp3.internal.publicsuffix.PublicSuffixDatabase.f2198.m1484(r3) == null) goto L128;
     */
    /* JADX WARN: Removed duplicated region for block: B:40:0x0097  */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final void m10260(InterfaceC6886 interfaceC6886, C6908 c6908, C6905 c6905) {
        List listUnmodifiableList;
        List<C6884> listUnmodifiableList2;
        C6884 c6884;
        String str;
        if (interfaceC6886 == null) {
            C6635.m9824("$this$receiveHeaders");
            throw null;
        }
        if (c6908 == null) {
            C6635.m9824("url");
            throw null;
        }
        if (c6905 == null) {
            C6635.m9824("headers");
            throw null;
        }
        if (interfaceC6886 == InterfaceC6886.f19986) {
            return;
        }
        C6884.C6885 c6885 = C6884.f19976;
        if (c6885 == null) {
            throw null;
        }
        int size = c6905.size();
        int i = 0;
        ArrayList arrayList = null;
        for (int i2 = 0; i2 < size; i2++) {
            if (C6703.m9905("Set-Cookie", c6905.m10068(i2), true)) {
                if (arrayList == null) {
                    arrayList = new ArrayList(2);
                }
                arrayList.add(c6905.m10070(i2));
            }
        }
        if (arrayList != null) {
            listUnmodifiableList = Collections.unmodifiableList(arrayList);
            C6635.m9823((Object) listUnmodifiableList, "Collections.unmodifiableList(result)");
        } else {
            listUnmodifiableList = C6563.f19343;
        }
        List list = listUnmodifiableList;
        int size2 = list.size();
        int i3 = 0;
        ArrayList arrayList2 = null;
        while (i3 < size2) {
            String str2 = (String) list.get(i3);
            if (str2 == null) {
                C6635.m9824("setCookie");
                throw null;
            }
            long jCurrentTimeMillis = System.currentTimeMillis();
            char c = ';';
            int iM10144 = C6943.m10144(str2, ';', i, i, 6);
            char c2 = '=';
            int iM10143 = C6943.m10143(str2, '=', i, iM10144);
            if (iM10143 == iM10144) {
                c6884 = null;
            } else {
                String strM10178 = C6943.m10178(str2, i, iM10143);
                if (!(strM10178.length() == 0) && C6943.m10172(strM10178) == -1) {
                    String strM101782 = C6943.m10178(str2, iM10143 + 1, iM10144);
                    if (C6943.m10172(strM101782) == -1) {
                        int i4 = iM10144 + 1;
                        int length = str2.length();
                        long j = 253402300799999L;
                        long jM10046 = 253402300799999L;
                        long j2 = -1;
                        boolean z = false;
                        boolean z2 = false;
                        boolean z3 = false;
                        boolean z4 = true;
                        String str3 = null;
                        String str4 = null;
                        while (true) {
                            if (i4 < length) {
                                int iM101432 = C6943.m10143(str2, c, i4, length);
                                int iM101433 = C6943.m10143(str2, c2, i4, iM101432);
                                String strM101783 = C6943.m10178(str2, i4, iM101433);
                                String strM101784 = iM101433 < iM101432 ? C6943.m10178(str2, iM101433 + 1, iM101432) : "";
                                if (C6703.m9905(strM101783, "expires", true)) {
                                    try {
                                        jM10046 = c6885.m10046(strM101784, 0, strM101784.length());
                                        z3 = true;
                                    } catch (NumberFormatException | IllegalArgumentException unused) {
                                    }
                                } else if (C6703.m9905(strM101783, "max-age", true)) {
                                    try {
                                        long j3 = Long.parseLong(strM101784);
                                        j2 = j3 > 0 ? j3 : Long.MIN_VALUE;
                                    } catch (NumberFormatException e) {
                                        if (!new C6695("-?\\d+").m9854(strM101784)) {
                                            throw e;
                                        }
                                        j2 = C6703.m9899(strM101784, "-", false, 2) ? Long.MIN_VALUE : Long.MAX_VALUE;
                                    }
                                    z3 = true;
                                } else if (C6703.m9905(strM101783, "domain", true)) {
                                    if (!(!C6703.m9885(strM101784, ".", false, 2))) {
                                        throw new IllegalArgumentException("Failed requirement.".toString());
                                    }
                                    String strM7203 = C4303.m7203(C6703.m9867(strM101784, "."));
                                    if (strM7203 == null) {
                                        throw new IllegalArgumentException();
                                    }
                                    str3 = strM7203;
                                    z4 = false;
                                } else if (C6703.m9905(strM101783, "path", true)) {
                                    str4 = strM101784;
                                } else if (C6703.m9905(strM101783, "secure", true)) {
                                    z = true;
                                } else if (C6703.m9905(strM101783, "httponly", true)) {
                                    z2 = true;
                                }
                                i4 = iM101432 + 1;
                                c2 = '=';
                                c = ';';
                            } else {
                                if (j2 == Long.MIN_VALUE) {
                                    j = Long.MIN_VALUE;
                                } else if (j2 != -1) {
                                    long j4 = jCurrentTimeMillis + (j2 <= 9223372036854775L ? j2 * ((long) 1000) : Long.MAX_VALUE);
                                    if (j4 >= jCurrentTimeMillis && j4 <= 253402300799999L) {
                                        j = j4;
                                    }
                                } else {
                                    j = jM10046;
                                }
                                String str5 = c6908.f20017;
                                String str6 = str3;
                                if (str6 == null) {
                                    str6 = str5;
                                } else if (C6635.m9825((Object) str5, (Object) str6) || (C6703.m9885(str5, str6, false, 2) && str5.charAt((str5.length() - str6.length()) - 1) == '.' && !C6943.m10167(str5))) {
                                }
                                if (str5.length() != str6.length()) {
                                    if (PublicSuffixDatabase.f2199 == null) {
                                        throw null;
                                    }
                                }
                                String strSubstring = "/";
                                String str7 = str4;
                                if (str7 == null || !C6703.m9899(str7, "/", false, 2)) {
                                    String strM10081 = c6908.m10081();
                                    int iM9886 = C6703.m9886((CharSequence) strM10081, '/', 0, false, 6);
                                    if (iM9886 != 0) {
                                        strSubstring = strM10081.substring(0, iM9886);
                                        C6635.m9823((Object) strSubstring, "(this as java.lang.Strin…ing(startIndex, endIndex)");
                                    }
                                    str = strSubstring;
                                } else {
                                    str = str7;
                                }
                                c6884 = new C6884(strM10178, strM101782, j, str6, str, z, z2, z3, z4, null);
                            }
                        }
                    }
                }
                c6884 = null;
            }
            if (c6884 != null) {
                if (arrayList2 == null) {
                    arrayList2 = new ArrayList();
                }
                arrayList2.add(c6884);
            }
            i3++;
            i = 0;
        }
        if (arrayList2 != null) {
            listUnmodifiableList2 = Collections.unmodifiableList(arrayList2);
            C6635.m9823((Object) listUnmodifiableList2, "Collections.unmodifiableList(cookies)");
        } else {
            listUnmodifiableList2 = C6563.f19343;
        }
        if (listUnmodifiableList2.isEmpty()) {
            return;
        }
        interfaceC6886.mo10048(c6908, listUnmodifiableList2);
    }

    /* JADX WARN: Code restructure failed: missing block: B:111:0x00f0, code lost:
    
        continue;
     */
    /* JADX WARN: Code restructure failed: missing block: B:112:0x00f0, code lost:
    
        continue;
     */
    /* JADX WARN: Code restructure failed: missing block: B:20:0x0045, code lost:
    
        r5 = p138.p139.p143.p144.C2803.m4889(r5);
     */
    /* JADX WARN: Code restructure failed: missing block: B:21:0x004d, code lost:
    
        if (r7 < 0) goto L23;
     */
    /* JADX WARN: Code restructure failed: missing block: B:22:0x004f, code lost:
    
        r8 = true;
     */
    /* JADX WARN: Code restructure failed: missing block: B:23:0x0051, code lost:
    
        r8 = false;
     */
    /* JADX WARN: Code restructure failed: missing block: B:24:0x0052, code lost:
    
        if (r8 == false) goto L98;
     */
    /* JADX WARN: Code restructure failed: missing block: B:25:0x0054, code lost:
    
        if (r7 == 0) goto L41;
     */
    /* JADX WARN: Code restructure failed: missing block: B:26:0x0056, code lost:
    
        if (r7 == 1) goto L40;
     */
    /* JADX WARN: Code restructure failed: missing block: B:27:0x0058, code lost:
    
        r8 = "=".length();
     */
    /* JADX WARN: Code restructure failed: missing block: B:28:0x005c, code lost:
    
        if (r8 == 0) goto L41;
     */
    /* JADX WARN: Code restructure failed: missing block: B:29:0x005e, code lost:
    
        if (r8 == 1) goto L36;
     */
    /* JADX WARN: Code restructure failed: missing block: B:30:0x0060, code lost:
    
        r8 = new java.lang.StringBuilder("=".length() * r7);
     */
    /* JADX WARN: Code restructure failed: missing block: B:31:0x006b, code lost:
    
        if (1 > r7) goto L35;
     */
    /* JADX WARN: Code restructure failed: missing block: B:32:0x006d, code lost:
    
        r8.append((java.lang.CharSequence) "=");
     */
    /* JADX WARN: Code restructure failed: missing block: B:33:0x0070, code lost:
    
        if (r10 == r7) goto L113;
     */
    /* JADX WARN: Code restructure failed: missing block: B:34:0x0072, code lost:
    
        r10 = r10 + 1;
     */
    /* JADX WARN: Code restructure failed: missing block: B:35:0x0075, code lost:
    
        r6 = r8.toString();
        p402.p411.p413.C6635.m9823((java.lang.Object) r6, "sb.toString()");
     */
    /* JADX WARN: Code restructure failed: missing block: B:36:0x007f, code lost:
    
        r6 = "=".charAt(0);
        r8 = new char[r7];
     */
    /* JADX WARN: Code restructure failed: missing block: B:37:0x0085, code lost:
    
        if (r9 >= r7) goto L114;
     */
    /* JADX WARN: Code restructure failed: missing block: B:38:0x0087, code lost:
    
        r8[r9] = r6;
        r9 = r9 + 1;
     */
    /* JADX WARN: Code restructure failed: missing block: B:39:0x008c, code lost:
    
        r6 = new java.lang.String(r8);
     */
    /* JADX WARN: Code restructure failed: missing block: B:40:0x0092, code lost:
    
        r6 = "=".toString();
     */
    /* JADX WARN: Code restructure failed: missing block: B:41:0x0097, code lost:
    
        r6 = "";
     */
    /* JADX WARN: Code restructure failed: missing block: B:44:0x00d1, code lost:
    
        throw new java.lang.IllegalArgumentException(("Count 'n' must be non-negative, but was " + r7 + '.').toString());
     */
    /* JADX WARN: Code restructure failed: missing block: B:77:0x0148, code lost:
    
        r1 = r3;
        r3 = r2;
     */
    /* JADX WARN: Removed duplicated region for block: B:53:0x00fb  */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final void m10261(C7103 c7103, List<C6875> list) {
        LinkedHashMap linkedHashMap;
        String str;
        String strM10258;
        StringBuilder sbM4889;
        String string;
        List<C6875> list2 = list;
        String strM102582 = null;
        while (true) {
            String strM10437 = strM102582;
            while (true) {
                if (strM102582 == null) {
                    m10263(c7103);
                    strM102582 = m10258(c7103);
                    if (strM102582 == null) {
                        return;
                    }
                }
                boolean zM10263 = m10263(c7103);
                String strM102583 = m10258(c7103);
                if (strM102583 != null) {
                    byte b = (byte) 61;
                    int iM10150 = C6943.m10150(c7103, b);
                    boolean zM102632 = m10263(c7103);
                    int i = 0;
                    int i2 = 1;
                    if (!zM10263 && (zM102632 || c7103.mo10436())) {
                        break;
                    }
                    linkedHashMap = new LinkedHashMap();
                    int iM101502 = C6943.m10150(c7103, b) + iM10150;
                    while (true) {
                        if (strM102583 == null) {
                            strM102583 = m10258(c7103);
                            if (m10263(c7103)) {
                                break;
                            }
                            iM101502 = C6943.m10150(c7103, b);
                            if (iM101502 != 0) {
                                break;
                            }
                            if (iM101502 > 1 || m10263(c7103)) {
                                return;
                            }
                            byte b2 = (byte) 34;
                            if (!c7103.mo10436() && c7103.m10433(0L) == b2) {
                                if (!(c7103.readByte() == b2)) {
                                    throw new IllegalArgumentException("Failed requirement.".toString());
                                }
                                C7103 c71032 = new C7103();
                                while (true) {
                                    long jMo10424 = c7103.mo10424(f20328);
                                    if (jMo10424 == -1) {
                                        break;
                                    }
                                    if (c7103.m10433(jMo10424) == b2) {
                                        c71032.mo10205(c7103, jMo10424);
                                        c7103.readByte();
                                        strM10437 = c71032.m10437();
                                        break;
                                    }
                                    str = strM102582;
                                    if (c7103.f20630 == jMo10424 + 1) {
                                        strM10258 = null;
                                        break;
                                    }
                                    c71032.mo10205(c7103, jMo10424);
                                    c7103.readByte();
                                    c71032.mo10205(c7103, 1L);
                                    strM102582 = str;
                                    strM10437 = null;
                                }
                            } else {
                                str = strM102582;
                                strM10258 = m10258(c7103);
                            }
                            if (strM10258 == null || ((String) linkedHashMap.put(strM102583, strM10258)) != null) {
                                return;
                            }
                            if (!m10263(c7103) && !c7103.mo10436()) {
                                return;
                            }
                            strM102583 = null;
                            strM102582 = str;
                            strM10437 = null;
                            list2 = list;
                        } else if (iM101502 != 0) {
                        }
                    }
                } else {
                    if (c7103.mo10436()) {
                        list2.add(new C6875(strM102582, C6564.f19344));
                        return;
                    }
                    return;
                }
                list2.add(new C6875(strM102582, linkedHashMap));
                strM102582 = strM102583;
            }
            sbM4889.append(string);
            Map mapSingletonMap = Collections.singletonMap(strM10437, sbM4889.toString());
            C6635.m9823((Object) mapSingletonMap, "Collections.singletonMap…ek + \"=\".repeat(eqCount))");
            list2.add(new C6875(strM102582, mapSingletonMap));
            strM102582 = strM10437;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static final boolean m10262(C6933 c6933) {
        if (c6933 == null) {
            C6635.m9824("$this$promisesBody");
            throw null;
        }
        if (C6635.m9825((Object) c6933.f20146.f20129, (Object) "HEAD")) {
            return false;
        }
        int i = c6933.f20149;
        return (((i >= 100 && i < 200) || i == 204 || i == 304) && C6943.m10155(c6933) == -1 && !C6703.m9905("chunked", C6933.m10126(c6933, "Transfer-Encoding", null, 2), true)) ? false : true;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public static final boolean m10263(C7103 c7103) {
        boolean z = false;
        while (!c7103.mo10436()) {
            byte bM10433 = c7103.m10433(0L);
            if (bM10433 == 9 || bM10433 == 32) {
                c7103.readByte();
            } else {
                if (bM10433 != 44) {
                    break;
                }
                c7103.readByte();
                z = true;
            }
        }
        return z;
    }
}
