package e1;

import i1.AbstractC0547a;
import i1.g;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.StringTokenizer;
import l1.C0622e;

/* JADX INFO: renamed from: e1.b, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public class C0454b {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private static int[] f3809c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private static InetAddress f3810d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private static C0622e f3811e = C0622e.a();

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    Object f3812a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    String f3813b;

    /* JADX INFO: renamed from: e1.b$a */
    static class a extends Thread {

        /* JADX INFO: renamed from: H, reason: collision with root package name */
        InetAddress f3814H;

        /* JADX INFO: renamed from: I, reason: collision with root package name */
        UnknownHostException f3815I;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        C0070b f3816b;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        String f3817g;

        /* JADX INFO: renamed from: r, reason: collision with root package name */
        String f3818r;

        /* JADX INFO: renamed from: x, reason: collision with root package name */
        int f3819x;

        /* JADX INFO: renamed from: y, reason: collision with root package name */
        g f3820y;

        a(C0070b c0070b, String str, int i2, String str2, InetAddress inetAddress) {
            super("JCIFS-QueryThread: " + str);
            this.f3820y = null;
            this.f3816b = c0070b;
            this.f3817g = str;
            this.f3819x = i2;
            this.f3818r = str2;
            this.f3814H = inetAddress;
        }

        @Override // java.lang.Thread, java.lang.Runnable
        public void run() {
            try {
                try {
                    try {
                        this.f3820y = g.l(this.f3817g, this.f3819x, this.f3818r, this.f3814H);
                        synchronized (this.f3816b) {
                            r1.f3821a--;
                            this.f3816b.notify();
                        }
                    } catch (Exception e2) {
                        this.f3815I = new UnknownHostException(e2.getMessage());
                        synchronized (this.f3816b) {
                            r1.f3821a--;
                            this.f3816b.notify();
                        }
                    }
                } catch (UnknownHostException e3) {
                    this.f3815I = e3;
                    synchronized (this.f3816b) {
                        r1.f3821a--;
                        this.f3816b.notify();
                    }
                }
            } catch (Throwable th) {
                synchronized (this.f3816b) {
                    r2.f3821a--;
                    this.f3816b.notify();
                    throw th;
                }
            }
        }
    }

    /* JADX INFO: renamed from: e1.b$b, reason: collision with other inner class name */
    static class C0070b {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        int f3821a;

        C0070b(int i2) {
            this.f3821a = i2;
        }
    }

    static {
        int i2;
        String strG = AbstractC0453a.g("jcifs.resolveOrder");
        InetAddress inetAddressT = g.t();
        try {
            f3810d = AbstractC0453a.b("jcifs.netbios.baddr", InetAddress.getByName("255.255.255.255"));
        } catch (UnknownHostException unused) {
        }
        if (strG == null || strG.length() == 0) {
            if (inetAddressT == null) {
                f3809c = new int[]{3, 2, 1};
                return;
            } else {
                f3809c = new int[]{3, 0, 2, 1};
                return;
            }
        }
        int[] iArr = new int[4];
        StringTokenizer stringTokenizer = new StringTokenizer(strG, ",");
        int i3 = 0;
        while (stringTokenizer.hasMoreTokens()) {
            String strTrim = stringTokenizer.nextToken().trim();
            if (strTrim.equalsIgnoreCase("LMHOSTS")) {
                i2 = i3 + 1;
                iArr[i3] = 3;
            } else if (strTrim.equalsIgnoreCase("WINS")) {
                if (inetAddressT != null) {
                    i2 = i3 + 1;
                    iArr[i3] = 0;
                } else if (C0622e.f5384g > 1) {
                    f3811e.println("UniAddress resolveOrder specifies WINS however the jcifs.netbios.wins property has not been set");
                }
            } else if (strTrim.equalsIgnoreCase("BCAST")) {
                i2 = i3 + 1;
                iArr[i3] = 1;
            } else if (strTrim.equalsIgnoreCase("DNS")) {
                i2 = i3 + 1;
                iArr[i3] = 2;
            } else if (C0622e.f5384g > 1) {
                f3811e.println("unknown resolver method: " + strTrim);
            }
            i3 = i2;
        }
        int[] iArr2 = new int[i3];
        f3809c = iArr2;
        System.arraycopy(iArr, 0, iArr2, 0, i3);
    }

    public C0454b(Object obj) {
        if (obj == null) {
            throw new IllegalArgumentException();
        }
        this.f3812a = obj;
    }

    public static C0454b[] c(String str, boolean z2) throws UnknownHostException {
        int i2;
        g gVarJ;
        if (str == null || str.length() == 0) {
            throw new UnknownHostException();
        }
        if (i(str)) {
            return new C0454b[]{new C0454b(g.j(str))};
        }
        int i3 = 0;
        while (true) {
            int[] iArr = f3809c;
            if (i3 >= iArr.length) {
                throw new UnknownHostException(str);
            }
            try {
                i2 = iArr[i3];
            } catch (IOException unused) {
            }
            if (i2 == 0) {
                if (str != "\u0001\u0002__MSBROWSE__\u0002" && str.length() <= 15) {
                    gVarJ = z2 ? j(str, g.t()) : g.l(str, 32, null, g.t());
                }
                i3++;
            } else if (i2 != 1) {
                if (i2 == 2) {
                    if (h(str)) {
                        throw new UnknownHostException(str);
                    }
                    InetAddress[] allByName = InetAddress.getAllByName(str);
                    C0454b[] c0454bArr = new C0454b[allByName.length];
                    for (int i4 = 0; i4 < allByName.length; i4++) {
                        c0454bArr[i4] = new C0454b(allByName[i4]);
                    }
                    return c0454bArr;
                }
                if (i2 != 3) {
                    throw new UnknownHostException(str);
                }
                gVarJ = AbstractC0547a.b(str);
                if (gVarJ != null) {
                    break;
                }
                i3++;
            } else if (str.length() > 15) {
                i3++;
            } else {
                gVarJ = z2 ? j(str, f3810d) : g.l(str, 32, null, f3810d);
            }
        }
        return new C0454b[]{new C0454b(gVarJ)};
    }

    public static C0454b d(String str) {
        return e(str, false);
    }

    public static C0454b e(String str, boolean z2) {
        return c(str, z2)[0];
    }

    static boolean h(String str) {
        for (int i2 = 0; i2 < str.length(); i2++) {
            if (!Character.isDigit(str.charAt(i2))) {
                return false;
            }
        }
        return true;
    }

    static boolean i(String str) {
        if (Character.isDigit(str.charAt(0))) {
            int length = str.length();
            char[] charArray = str.toCharArray();
            int i2 = 0;
            int i3 = 0;
            while (i2 < length) {
                int i4 = i2 + 1;
                if (!Character.isDigit(charArray[i2])) {
                    break;
                }
                if (i4 == length && i3 == 3) {
                    return true;
                }
                if (i4 >= length || charArray[i4] != '.') {
                    i2 = i4;
                } else {
                    i3++;
                    i2 += 2;
                }
            }
        }
        return false;
    }

    static g j(String str, InetAddress inetAddress) throws UnknownHostException {
        C0070b c0070b = new C0070b(2);
        a aVar = new a(c0070b, str, g.w(inetAddress) ? 27 : 29, null, inetAddress);
        a aVar2 = new a(c0070b, str, 32, null, inetAddress);
        aVar.setDaemon(true);
        aVar2.setDaemon(true);
        try {
            synchronized (c0070b) {
                try {
                    aVar.start();
                    aVar2.start();
                    while (c0070b.f3821a > 0 && aVar.f3820y == null && aVar2.f3820y == null) {
                        c0070b.wait();
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
            g gVar = aVar.f3820y;
            if (gVar != null) {
                return gVar;
            }
            g gVar2 = aVar2.f3820y;
            if (gVar2 != null) {
                return gVar2;
            }
            throw aVar.f3815I;
        } catch (InterruptedException unused) {
            throw new UnknownHostException(str);
        }
    }

    public String a() {
        Object obj = this.f3812a;
        if (obj instanceof g) {
            return ((g) obj).h();
        }
        String hostName = ((InetAddress) obj).getHostName();
        this.f3813b = hostName;
        if (i(hostName)) {
            this.f3813b = "*SMBSERVER     ";
        } else {
            int iIndexOf = this.f3813b.indexOf(46);
            if (iIndexOf > 1 && iIndexOf < 15) {
                this.f3813b = this.f3813b.substring(0, iIndexOf).toUpperCase();
            } else if (this.f3813b.length() > 15) {
                this.f3813b = "*SMBSERVER     ";
            } else {
                this.f3813b = this.f3813b.toUpperCase();
            }
        }
        return this.f3813b;
    }

    public Object b() {
        return this.f3812a;
    }

    public boolean equals(Object obj) {
        return (obj instanceof C0454b) && this.f3812a.equals(((C0454b) obj).f3812a);
    }

    public String f() {
        Object obj = this.f3812a;
        return obj instanceof g ? ((g) obj).n() : ((InetAddress) obj).getHostAddress();
    }

    public String g() {
        Object obj = this.f3812a;
        return obj instanceof g ? ((g) obj).o() : ((InetAddress) obj).getHostName();
    }

    public int hashCode() {
        return this.f3812a.hashCode();
    }

    public String k() {
        Object obj = this.f3812a;
        if (obj instanceof g) {
            return ((g) obj).x();
        }
        if (this.f3813b == "*SMBSERVER     ") {
            return null;
        }
        this.f3813b = "*SMBSERVER     ";
        return "*SMBSERVER     ";
    }

    public String toString() {
        return this.f3812a.toString();
    }
}
