package o; import com.google.common.primitives.UnsignedBytes; import io.grpc.internal.GrpcUtil; import java.net.IDN; import java.net.InetAddress; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Locale; import okhttp3.HttpUrl; /* renamed from: o.fNg, reason: case insensitive filesystem */ /* loaded from: classes5.dex */ public final class C12994fNg { private static final char[] a = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; public final int b; private final String c; public final String d; private final String e; private final String f; private final List g; private final String h; private final String i; private final List j; static int d(char c) { if (c >= '0' && c <= '9') { return c - '0'; } if (c >= 'a' && c <= 'f') { return c - 'W'; } if (c < 'A' || c > 'F') { return -1; } return c - '7'; } /* synthetic */ C12994fNg(IeS ieS, byte b) { this(ieS); } private C12994fNg(IeS ieS) { this.f = ieS.j; String str = ieS.a; this.h = b(str, 0, str.length(), false); String str2 = ieS.e; this.c = b(str2, 0, str2.length(), false); this.d = ieS.i; int i = ieS.g; if (i == -1) { String str3 = ieS.j; if (str3.equals("http")) { i = 80; } else { i = str3.equals("https") ? GrpcUtil.DEFAULT_PORT_SSL : -1; } } this.b = i; this.j = a(ieS.d, false); String str4 = null; this.g = ieS.b != null ? a(ieS.b, true) : null; if (ieS.c != null) { String str5 = ieS.c; str4 = b(str5, 0, str5.length(), false); } this.e = str4; this.i = ieS.toString(); } public final URL e() { try { return new URL(this.i); } catch (MalformedURLException e) { throw new RuntimeException(e); } } public static int e(String str) { if (str.equals("http")) { return 80; } if (str.equals("https")) { return GrpcUtil.DEFAULT_PORT_SSL; } return -1; } static void c(StringBuilder sb, List list) { int size = list.size(); for (int i = 0; i < size; i++) { sb.append('/'); sb.append(list.get(i)); } } static void e(StringBuilder sb, List list) { int size = list.size(); for (int i = 0; i < size; i += 2) { String str = list.get(i); String str2 = list.get(i + 1); if (i > 0) { sb.append('&'); } sb.append(str); if (str2 != null) { sb.append('='); sb.append(str2); } } } public static C12994fNg b(String str) { int i; int i2; int i3; C12994fNg c12994fNg; IeS.EnumC0111IeS enumC0111IeS; char charAt; Object obj; int i4; char c; char c2; int c3; char c4; int i5; int i6; String str2; int i7; char charAt2; IeS ieS = new IeS(); int length = str.length(); int i8 = 0; while (true) { if (i8 >= length) { i = length; break; } char charAt3 = str.charAt(i8); if (charAt3 != '\t' && charAt3 != '\n' && charAt3 != '\f' && charAt3 != '\r' && charAt3 != ' ') { i = i8; break; } i8++; } char c5 = 65535; int length2 = str.length() - 1; while (true) { i2 = 1; if (length2 < i) { i3 = i; break; } char charAt4 = str.charAt(length2); if (charAt4 != '\t' && charAt4 != '\n' && charAt4 != '\f' && charAt4 != '\r' && charAt4 != ' ') { i3 = length2 + 1; break; } length2--; } if (i3 - i >= 2 && (((charAt = str.charAt(i)) >= 'a' && charAt <= 'z') || (charAt >= 'A' && charAt <= 'Z'))) { int i9 = i; while (true) { i9 += i2; if (i9 >= i3) { break; } char charAt5 = str.charAt(i9); if ((charAt5 >= 'a' && charAt5 <= 'z') || ((charAt5 >= 'A' && charAt5 <= 'Z') || ((charAt5 >= '0' && charAt5 <= '9') || charAt5 == '+' || charAt5 == '-' || charAt5 == '.'))) { c5 = c5; i2 = i2; } else if (charAt5 == ':' && i9 != c5) { String str3 = "http"; if (str.regionMatches(true, i, "https:", 0, 6)) { ieS.j = "https"; i4 = i + 6; obj = "https"; } else { obj = "https"; if (str.regionMatches(true, i, "http:", 0, 5)) { ieS.j = "http"; i4 = i + 5; } else { c12994fNg = null; enumC0111IeS = IeS.EnumC0111IeS.UNSUPPORTED_SCHEME; } } int i10 = i4; int i11 = 0; while (true) { c = '/'; c2 = '\\'; if (i10 >= i3 || !((charAt2 = str.charAt(i10)) == '\\' || charAt2 == '/')) { break; } i11++; i10++; } int i12 = i4 + i11; int i13 = 0; int i14 = 0; while (true) { c3 = c(str, i12, i3, "@/\\?#"); char charAt6 = c3 != i3 ? str.charAt(c3) : c5; c4 = '?'; if (charAt6 == c5 || charAt6 == '#' || charAt6 == c || charAt6 == c2 || charAt6 == '?') { break; } if (charAt6 == '@') { if (i13 == 0) { int c6 = c(str, i12, c3, ":"); i7 = c3; str2 = str3; String e = e(str, i12, c6, " \"':;<=>@[]^`{}|/\\?#", true, false, true); if (i14 != 0) { StringBuilder sb = new StringBuilder(); sb.append(ieS.a); sb.append("%40"); sb.append(e); e = sb.toString(); } ieS.a = e; if (c6 != i7) { ieS.e = e(str, c6 + 1, i7, " \"':;<=>@[]^`{}|/\\?#", true, false, true); i13 = i2; } i14 = i2; } else { i7 = c3; str2 = str3; StringBuilder sb2 = new StringBuilder(); sb2.append(ieS.e); sb2.append("%40"); sb2.append(e(str, i12, i7, " \"':;<=>@[]^`{}|/\\?#", true, false, true)); ieS.e = sb2.toString(); } i12 = i7 + 1; } else { str2 = str3; } str3 = str2; c2 = '\\'; c = '/'; c5 = 65535; i2 = 1; } int i15 = c3; String str4 = str3; int i16 = i12; while (true) { if (i16 < i15) { char charAt7 = str.charAt(i16); if (charAt7 == ':') { break; } if (charAt7 != '[') { i6 = 1; } else { i6 = 1; do { i16++; if (i16 < i15) { } } while (str.charAt(i16) != ']'); } i16 += i6; } else { i16 = i15; break; } } int i17 = i16 + 1; if (i17 < i15) { ieS.i = IeS.b(str, i12, i16); int d = IeS.d(str, i17, i15); ieS.g = d; if (d == -1) { enumC0111IeS = IeS.EnumC0111IeS.INVALID_PORT; c12994fNg = null; } } else { ieS.i = IeS.b(str, i12, i16); String str5 = ieS.j; if (str5.equals(str4)) { i5 = 80; } else { i5 = str5.equals(obj) ? GrpcUtil.DEFAULT_PORT_SSL : -1; } ieS.g = i5; } if (ieS.i == null) { enumC0111IeS = IeS.EnumC0111IeS.INVALID_HOST; c12994fNg = null; } else { int c7 = c(str, i15, i3, "?#"); if (i15 != c7) { char charAt8 = str.charAt(i15); if (charAt8 == '/' || charAt8 == '\\') { ieS.d.clear(); ieS.d.add(""); i15++; } else { List list = ieS.d; list.set(list.size() - 1, ""); } loop7: while (true) { int i18 = i15; while (i18 < c7) { int c8 = c(str, i18, c7, "/\\"); boolean z = c8 < c7; char c9 = c4; String e2 = e(str, i18, c8, HttpUrl.PATH_SEGMENT_ENCODE_SET, true, false, true); if (!e2.equals(".") && !e2.equalsIgnoreCase("%2e")) { if (e2.equals("..") || e2.equalsIgnoreCase("%2e.") || e2.equalsIgnoreCase(".%2e") || e2.equalsIgnoreCase("%2e%2e")) { List list2 = ieS.d; if (list2.remove(list2.size() - 1).isEmpty() && !ieS.d.isEmpty()) { List list3 = ieS.d; list3.set(list3.size() - 1, ""); } else { ieS.d.add(""); } } else { List list4 = ieS.d; if (list4.get(list4.size() - 1).isEmpty()) { List list5 = ieS.d; list5.set(list5.size() - 1, e2); } else { ieS.d.add(e2); } if (z) { ieS.d.add(""); } } } if (z) { c4 = c9; i15 = c8 + 1; } else { i18 = c8; c4 = c9; } } break loop7; } } char c10 = c4; if (c7 >= i3 || str.charAt(c7) != c10) { c12994fNg = null; } else { int c11 = c(str, c7, i3, "#"); String e3 = e(str, c7 + 1, c11, HttpUrl.QUERY_ENCODE_SET, true, true, true); ArrayList arrayList = new ArrayList(); int i19 = 0; while (i19 <= e3.length()) { int indexOf = e3.indexOf(38, i19); if (indexOf == -1) { indexOf = e3.length(); } int indexOf2 = e3.indexOf(61, i19); if (indexOf2 == -1 || indexOf2 > indexOf) { arrayList.add(e3.substring(i19, indexOf)); arrayList.add(null); } else { arrayList.add(e3.substring(i19, indexOf2)); arrayList.add(e3.substring(indexOf2 + 1, indexOf)); } i19 = indexOf + 1; } c12994fNg = null; ieS.b = arrayList; c7 = c11; } if (c7 < i3 && str.charAt(c7) == '#') { ieS.c = e(str, c7 + 1, i3, "", true, false, false); } enumC0111IeS = IeS.EnumC0111IeS.SUCCESS; } } } } c12994fNg = null; enumC0111IeS = IeS.EnumC0111IeS.MISSING_SCHEME; return enumC0111IeS == IeS.EnumC0111IeS.SUCCESS ? ieS.e() : c12994fNg; } public final boolean equals(Object obj) { return (obj instanceof C12994fNg) && ((C12994fNg) obj).i.equals(this.i); } public final int hashCode() { return this.i.hashCode(); } /* renamed from: o.fNg$IeS */ /* loaded from: classes5.dex */ public static final class IeS { List b; String c; final List d; public String i; public String j; String a = ""; String e = ""; public int g = -1; /* renamed from: o.fNg$IeS$IeS, reason: collision with other inner class name */ /* loaded from: classes5.dex */ enum EnumC0111IeS { SUCCESS, MISSING_SCHEME, UNSUPPORTED_SCHEME, INVALID_PORT, INVALID_HOST } public IeS() { ArrayList arrayList = new ArrayList(); this.d = arrayList; arrayList.add(""); } public final C12994fNg e() { if (this.j == null) { throw new IllegalStateException("scheme == null"); } if (this.i == null) { throw new IllegalStateException("host == null"); } return new C12994fNg(this, (byte) 0); } public final String toString() { StringBuilder sb = new StringBuilder(); sb.append(this.j); sb.append("://"); if (!this.a.isEmpty() || !this.e.isEmpty()) { sb.append(this.a); if (!this.e.isEmpty()) { sb.append(':'); sb.append(this.e); } sb.append('@'); } if (this.i.indexOf(58) != -1) { sb.append('['); sb.append(this.i); sb.append(']'); } else { sb.append(this.i); } int i = this.g; if (i == -1) { i = C12994fNg.e(this.j); } if (i != C12994fNg.e(this.j)) { sb.append(':'); sb.append(i); } C12994fNg.c(sb, this.d); if (this.b != null) { sb.append('?'); C12994fNg.e(sb, this.b); } if (this.c != null) { sb.append('#'); sb.append(this.c); } return sb.toString(); } public static String b(String str, int i, int i2) { String b = C12994fNg.b(str, i, i2, false); if (b.startsWith("[") && b.endsWith("]")) { InetAddress a = a(b, 1, b.length() - 1); if (a == null) { return null; } byte[] address = a.getAddress(); if (address.length == 16) { return c(address); } throw new AssertionError(); } return e(b); } /* JADX WARN: Code restructure failed: missing block: B:25:0x00bd, code lost: return null; */ /* JADX WARN: Removed duplicated region for block: B:15:0x0097 */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ private static java.net.InetAddress a(java.lang.String r16, int r17, int r18) { /* Method dump skipped, instructions count: 219 To view this dump add '--comments-level debug' option */ throw new UnsupportedOperationException("Method not decompiled: o.C12994fNg.IeS.a(java.lang.String, int, int):java.net.InetAddress"); } private static String e(String str) { try { String lowerCase = IDN.toASCII(str).toLowerCase(Locale.US); if (lowerCase.isEmpty()) { return null; } for (int i = 0; i < lowerCase.length(); i++) { char charAt = lowerCase.charAt(i); if (charAt <= 31 || charAt >= 127 || " #%/:?@[\\]".indexOf(charAt) != -1) { return null; } } return lowerCase; } catch (IllegalArgumentException unused) { return null; } } private static String c(byte[] bArr) { int i = -1; int i2 = 0; int i3 = 0; int i4 = 0; while (i3 < bArr.length) { int i5 = i3; while (i5 < 16 && bArr[i5] == 0 && bArr[i5 + 1] == 0) { i5 += 2; } int i6 = i5 - i3; if (i6 > i4) { i = i3; i4 = i6; } i3 = i5 + 2; } C15111ghZ c15111ghZ = new C15111ghZ(); while (i2 < bArr.length) { if (i2 == i) { c15111ghZ.b(58); i2 += i4; if (i2 == 16) { c15111ghZ.b(58); } } else { if (i2 > 0) { c15111ghZ.b(58); } c15111ghZ.l(((bArr[i2] & UnsignedBytes.MAX_VALUE) << 8) | (bArr[i2 + 1] & UnsignedBytes.MAX_VALUE)); i2 += 2; } } return c15111ghZ.b(c15111ghZ.c, gdP.a); } static int d(String str, int i, int i2) { try { int parseInt = Integer.parseInt(C12994fNg.e(str, i, i2, "", false, false, true)); if (parseInt <= 0 || parseInt > 65535) { return -1; } return parseInt; } catch (NumberFormatException unused) { return -1; } } } private static List a(List list, boolean z) { ArrayList arrayList = new ArrayList(list.size()); Iterator it = list.iterator(); while (it.hasNext()) { String next = it.next(); arrayList.add(next != null ? b(next, 0, next.length(), z) : null); } return Collections.unmodifiableList(arrayList); } static String b(String str, int i, int i2, boolean z) { int i3; int i4 = i; while (i4 < i2) { char charAt = str.charAt(i4); if (charAt == '%' || (charAt == '+' && z)) { C15111ghZ c15111ghZ = new C15111ghZ(); c15111ghZ.c(str, i, i4); while (i4 < i2) { int codePointAt = str.codePointAt(i4); if (codePointAt == 37 && (i3 = i4 + 2) < i2) { int d = d(str.charAt(i4 + 1)); int d2 = d(str.charAt(i3)); if (d != -1 && d2 != -1) { c15111ghZ.b((d << 4) + d2); i4 = i3; } c15111ghZ.i(codePointAt); } else { if (codePointAt == 43 && z) { c15111ghZ.b(32); } c15111ghZ.i(codePointAt); } i4 += Character.charCount(codePointAt); } return c15111ghZ.b(c15111ghZ.c, gdP.a); } i4++; } return str.substring(i, i2); } static String e(String str, int i, int i2, String str2, boolean z, boolean z2, boolean z3) { int i3 = i; while (i3 < i2) { int codePointAt = str.codePointAt(i3); if (codePointAt >= 32 && codePointAt != 127 && ((codePointAt < 128 || !z3) && str2.indexOf(codePointAt) == -1 && ((codePointAt != 37 || z) && (codePointAt != 43 || !z2)))) { i3 += Character.charCount(codePointAt); } else { C15111ghZ c15111ghZ = new C15111ghZ(); c15111ghZ.c(str, i, i3); C15111ghZ c15111ghZ2 = null; while (i3 < i2) { int codePointAt2 = str.codePointAt(i3); if (!z || (codePointAt2 != 9 && codePointAt2 != 10 && codePointAt2 != 12 && codePointAt2 != 13)) { if (codePointAt2 == 43 && z2) { String str3 = z ? "+" : "%2B"; C14957gcv.e(str3, ""); c15111ghZ.c(str3, 0, str3.length()); } else if (codePointAt2 < 32 || codePointAt2 == 127 || ((codePointAt2 >= 128 && z3) || str2.indexOf(codePointAt2) != -1 || (codePointAt2 == 37 && !z))) { if (c15111ghZ2 == null) { c15111ghZ2 = new C15111ghZ(); } c15111ghZ2.i(codePointAt2); while (c15111ghZ2.c != 0) { byte f = c15111ghZ2.f(); c15111ghZ.b(37); char[] cArr = a; c15111ghZ.b((int) cArr[((f & UnsignedBytes.MAX_VALUE) >> 4) & 15]); c15111ghZ.b((int) cArr[f & 15]); } } else { c15111ghZ.i(codePointAt2); } } i3 += Character.charCount(codePointAt2); } return c15111ghZ.b(c15111ghZ.c, gdP.a); } } return str.substring(i, i2); } private static /* synthetic */ int c(String str, int i, int i2, String str2) { while (i < i2) { if (str2.indexOf(str.charAt(i)) != -1) { return i; } i++; } return i2; } public final String toString() { return this.i; } }