package okhttp3; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.GregorianCalendar; import java.util.List; import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; import okhttp3.internal.Util; import okhttp3.internal.http.HttpDate; /* loaded from: classes2.dex */ public final class Cookie { private final String domain; private final long expiresAt; private final boolean hostOnly; private final boolean httpOnly; private final String name; private final String path; private final boolean persistent; private final boolean secure; private final String value; private static final Pattern YEAR_PATTERN = Pattern.compile("(\\d{2,4})[^\\d]*"); private static final Pattern MONTH_PATTERN = Pattern.compile("(?i)(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec).*"); private static final Pattern DAY_OF_MONTH_PATTERN = Pattern.compile("(\\d{1,2})[^\\d]*"); private static final Pattern TIME_PATTERN = Pattern.compile("(\\d{1,2}):(\\d{1,2}):(\\d{1,2})[^\\d]*"); public static final class Builder { String domain; boolean hostOnly; boolean httpOnly; String name; boolean persistent; boolean secure; String value; long expiresAt = HttpDate.MAX_DATE; String path = "/"; public Cookie build() { return new Cookie(this); } public Builder domain(String str) { return domain(str, false); } public Builder expiresAt(long j) { if (j <= 0) { j = Long.MIN_VALUE; } if (j > HttpDate.MAX_DATE) { j = 253402300799999L; } this.expiresAt = j; this.persistent = true; return this; } public Builder hostOnlyDomain(String str) { return domain(str, true); } public Builder httpOnly() { this.httpOnly = true; return this; } public Builder name(String str) { if (str == null) { throw new NullPointerException("name == null"); } if (!str.trim().equals(str)) { throw new IllegalArgumentException("name is not trimmed"); } this.name = str; return this; } public Builder path(String str) { if (!str.startsWith("/")) { throw new IllegalArgumentException("path must start with '/'"); } this.path = str; return this; } public Builder secure() { this.secure = true; return this; } public Builder value(String str) { if (str == null) { throw new NullPointerException("value == null"); } if (!str.trim().equals(str)) { throw new IllegalArgumentException("value is not trimmed"); } this.value = str; return this; } private Builder domain(String str, boolean z) { if (str == null) { throw new NullPointerException("domain == null"); } String canonicalizeHost = Util.canonicalizeHost(str); if (canonicalizeHost != null) { this.domain = canonicalizeHost; this.hostOnly = z; return this; } throw new IllegalArgumentException("unexpected domain: " + str); } } private Cookie(String str, String str2, long j, String str3, String str4, boolean z, boolean z2, boolean z3, boolean z4) { this.name = str; this.value = str2; this.expiresAt = j; this.domain = str3; this.path = str4; this.secure = z; this.httpOnly = z2; this.hostOnly = z3; this.persistent = z4; } private static int dateCharacterOffset(String str, int i, int i2, boolean z) { while (i < i2) { char charAt = str.charAt(i); if (((charAt < ' ' && charAt != '\t') || charAt >= 127 || (charAt >= '0' && charAt <= '9') || ((charAt >= 'a' && charAt <= 'z') || ((charAt >= 'A' && charAt <= 'Z') || charAt == ':'))) == (!z)) { return i; } i++; } return i2; } private static boolean domainMatch(String str, String str2) { if (str.equals(str2)) { return true; } return str.endsWith(str2) && str.charAt((str.length() - str2.length()) - 1) == '.' && !Util.verifyAsIpAddress(str); } public static Cookie parse(HttpUrl httpUrl, String str) { return parse(System.currentTimeMillis(), httpUrl, str); } public static List parseAll(HttpUrl httpUrl, Headers headers) { List values = headers.values("Set-Cookie"); int size = values.size(); ArrayList arrayList = null; for (int i = 0; i < size; i++) { Cookie parse = parse(httpUrl, values.get(i)); if (parse != null) { if (arrayList == null) { arrayList = new ArrayList(); } arrayList.add(parse); } } return arrayList != null ? Collections.unmodifiableList(arrayList) : Collections.emptyList(); } private static String parseDomain(String str) { if (str.endsWith(".")) { throw new IllegalArgumentException(); } if (str.startsWith(".")) { str = str.substring(1); } String canonicalizeHost = Util.canonicalizeHost(str); if (canonicalizeHost != null) { return canonicalizeHost; } throw new IllegalArgumentException(); } private static long parseExpires(String str, int i, int i2) { int dateCharacterOffset = dateCharacterOffset(str, i, i2, false); Matcher matcher = TIME_PATTERN.matcher(str); int i3 = -1; int i4 = -1; int i5 = -1; int i6 = -1; int i7 = -1; int i8 = -1; while (dateCharacterOffset < i2) { int dateCharacterOffset2 = dateCharacterOffset(str, dateCharacterOffset + 1, i2, true); matcher.region(dateCharacterOffset, dateCharacterOffset2); if (i4 == -1 && matcher.usePattern(TIME_PATTERN).matches()) { int parseInt = Integer.parseInt(matcher.group(1)); int parseInt2 = Integer.parseInt(matcher.group(2)); i8 = Integer.parseInt(matcher.group(3)); i7 = parseInt2; i4 = parseInt; } else if (i5 == -1 && matcher.usePattern(DAY_OF_MONTH_PATTERN).matches()) { i5 = Integer.parseInt(matcher.group(1)); } else if (i6 == -1 && matcher.usePattern(MONTH_PATTERN).matches()) { i6 = MONTH_PATTERN.pattern().indexOf(matcher.group(1).toLowerCase(Locale.US)) / 4; } else if (i3 == -1 && matcher.usePattern(YEAR_PATTERN).matches()) { i3 = Integer.parseInt(matcher.group(1)); } dateCharacterOffset = dateCharacterOffset(str, dateCharacterOffset2 + 1, i2, false); } if (i3 >= 70 && i3 <= 99) { i3 += 1900; } if (i3 >= 0 && i3 <= 69) { i3 += 2000; } if (i3 < 1601) { throw new IllegalArgumentException(); } if (i6 == -1) { throw new IllegalArgumentException(); } if (i5 < 1 || i5 > 31) { throw new IllegalArgumentException(); } if (i4 < 0 || i4 > 23) { throw new IllegalArgumentException(); } if (i7 < 0 || i7 > 59) { throw new IllegalArgumentException(); } if (i8 < 0 || i8 > 59) { throw new IllegalArgumentException(); } GregorianCalendar gregorianCalendar = new GregorianCalendar(Util.UTC); gregorianCalendar.setLenient(false); gregorianCalendar.set(1, i3); gregorianCalendar.set(2, i6 - 1); gregorianCalendar.set(5, i5); gregorianCalendar.set(11, i4); gregorianCalendar.set(12, i7); gregorianCalendar.set(13, i8); gregorianCalendar.set(14, 0); return gregorianCalendar.getTimeInMillis(); } private static long parseMaxAge(String str) { try { long parseLong = Long.parseLong(str); if (parseLong <= 0) { return Long.MIN_VALUE; } return parseLong; } catch (NumberFormatException e) { if (str.matches("-?\\d+")) { return str.startsWith("-") ? Long.MIN_VALUE : Long.MAX_VALUE; } throw e; } } private static boolean pathMatch(HttpUrl httpUrl, String str) { String encodedPath = httpUrl.encodedPath(); if (encodedPath.equals(str)) { return true; } if (encodedPath.startsWith(str)) { return str.endsWith("/") || encodedPath.charAt(str.length()) == '/'; } return false; } public String domain() { return this.domain; } public boolean equals(Object obj) { if (!(obj instanceof Cookie)) { return false; } Cookie cookie = (Cookie) obj; return cookie.name.equals(this.name) && cookie.value.equals(this.value) && cookie.domain.equals(this.domain) && cookie.path.equals(this.path) && cookie.expiresAt == this.expiresAt && cookie.secure == this.secure && cookie.httpOnly == this.httpOnly && cookie.persistent == this.persistent && cookie.hostOnly == this.hostOnly; } public long expiresAt() { return this.expiresAt; } public int hashCode() { int hashCode = (((((((527 + this.name.hashCode()) * 31) + this.value.hashCode()) * 31) + this.domain.hashCode()) * 31) + this.path.hashCode()) * 31; long j = this.expiresAt; return ((((((((hashCode + ((int) (j ^ (j >>> 32)))) * 31) + (!this.secure ? 1 : 0)) * 31) + (!this.httpOnly ? 1 : 0)) * 31) + (!this.persistent ? 1 : 0)) * 31) + (!this.hostOnly ? 1 : 0); } public boolean hostOnly() { return this.hostOnly; } public boolean httpOnly() { return this.httpOnly; } public boolean matches(HttpUrl httpUrl) { if ((this.hostOnly ? httpUrl.host().equals(this.domain) : domainMatch(httpUrl.host(), this.domain)) && pathMatch(httpUrl, this.path)) { return !this.secure || httpUrl.isHttps(); } return false; } public String name() { return this.name; } public String path() { return this.path; } public boolean persistent() { return this.persistent; } public boolean secure() { return this.secure; } public String toString() { return toString(false); } public String value() { return this.value; } /* JADX WARN: Removed duplicated region for block: B:55:0x00f4 */ /* JADX WARN: Removed duplicated region for block: B:70:0x0131 */ /* JADX WARN: Removed duplicated region for block: B:72:0x00f7 */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ static okhttp3.Cookie parse(long r24, okhttp3.HttpUrl r26, java.lang.String r27) { /* Method dump skipped, instructions count: 328 To view this dump change 'Code comments level' option to 'DEBUG' */ throw new UnsupportedOperationException("Method not decompiled: okhttp3.Cookie.parse(long, okhttp3.HttpUrl, java.lang.String):okhttp3.Cookie"); } String toString(boolean z) { StringBuilder sb = new StringBuilder(); sb.append(this.name); sb.append('='); sb.append(this.value); if (this.persistent) { if (this.expiresAt == Long.MIN_VALUE) { sb.append("; max-age=0"); } else { sb.append("; expires="); sb.append(HttpDate.format(new Date(this.expiresAt))); } } if (!this.hostOnly) { sb.append("; domain="); if (z) { sb.append("."); } sb.append(this.domain); } sb.append("; path="); sb.append(this.path); if (this.secure) { sb.append("; secure"); } if (this.httpOnly) { sb.append("; httponly"); } return sb.toString(); } Cookie(Builder builder) { String str = builder.name; if (str != null) { String str2 = builder.value; if (str2 != null) { String str3 = builder.domain; if (str3 != null) { this.name = str; this.value = str2; this.expiresAt = builder.expiresAt; this.domain = str3; this.path = builder.path; this.secure = builder.secure; this.httpOnly = builder.httpOnly; this.persistent = builder.persistent; this.hostOnly = builder.hostOnly; return; } throw new NullPointerException("builder.domain == null"); } throw new NullPointerException("builder.value == null"); } throw new NullPointerException("builder.name == null"); } }