package g.i0.i;

import com.ifpdos.sdk.httpd.binder.aidl.RequestLine;
import com.seewo.libmcuservice.constant.IMcuConstants;
import com.seewo.vcommons.constants.Platform;
import com.seewo.vcommons.mstar.MKeyEvent;
import g.i0.i.r;
import h.x;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Logger;

/* JADX INFO: loaded from: classes.dex */
public final class d {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final c[] f6264a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final Map<h.i, Integer> f6265b;

    public static final class a {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public final h.h f6267b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public final int f6268c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        public int f6269d;

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public final List<c> f6266a = new ArrayList();

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        public c[] f6270e = new c[8];

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public int f6271f = 7;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        public int f6272g = 0;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        public int f6273h = 0;

        public a(int i2, x xVar) {
            this.f6268c = i2;
            this.f6269d = i2;
            Logger logger = h.p.f6564a;
            this.f6267b = new h.s(xVar);
        }

        public final void a() {
            Arrays.fill(this.f6270e, (Object) null);
            this.f6271f = this.f6270e.length - 1;
            this.f6272g = 0;
            this.f6273h = 0;
        }

        public final int b(int i2) {
            return this.f6271f + 1 + i2;
        }

        public final int c(int i2) {
            int i3;
            int i4 = 0;
            if (i2 > 0) {
                int length = this.f6270e.length;
                while (true) {
                    length--;
                    i3 = this.f6271f;
                    if (length < i3 || i2 <= 0) {
                        break;
                    }
                    c[] cVarArr = this.f6270e;
                    i2 -= cVarArr[length].f6263i;
                    this.f6273h -= cVarArr[length].f6263i;
                    this.f6272g--;
                    i4++;
                }
                c[] cVarArr2 = this.f6270e;
                System.arraycopy(cVarArr2, i3 + 1, cVarArr2, i3 + 1 + i4, this.f6272g);
                this.f6271f += i4;
            }
            return i4;
        }

        public final h.i d(int i2) throws IOException {
            c cVar;
            if (!(i2 >= 0 && i2 <= d.f6264a.length - 1)) {
                int iB = b(i2 - d.f6264a.length);
                if (iB >= 0) {
                    c[] cVarArr = this.f6270e;
                    if (iB < cVarArr.length) {
                        cVar = cVarArr[iB];
                    }
                }
                StringBuilder sbC = a.b.c.a.a.C("Header index too large ");
                sbC.append(i2 + 1);
                throw new IOException(sbC.toString());
            }
            cVar = d.f6264a[i2];
            return cVar.f6261g;
        }

        public final void e(int i2, c cVar) {
            this.f6266a.add(cVar);
            int i3 = cVar.f6263i;
            if (i2 != -1) {
                i3 -= this.f6270e[(this.f6271f + 1) + i2].f6263i;
            }
            int i4 = this.f6269d;
            if (i3 > i4) {
                a();
                return;
            }
            int iC = c((this.f6273h + i3) - i4);
            if (i2 == -1) {
                int i5 = this.f6272g + 1;
                c[] cVarArr = this.f6270e;
                if (i5 > cVarArr.length) {
                    c[] cVarArr2 = new c[cVarArr.length * 2];
                    System.arraycopy(cVarArr, 0, cVarArr2, cVarArr.length, cVarArr.length);
                    this.f6271f = this.f6270e.length - 1;
                    this.f6270e = cVarArr2;
                }
                int i6 = this.f6271f;
                this.f6271f = i6 - 1;
                this.f6270e[i6] = cVar;
                this.f6272g++;
            } else {
                this.f6270e[this.f6271f + 1 + i2 + iC + i2] = cVar;
            }
            this.f6273h += i3;
        }

        public h.i f() {
            int iJ = this.f6267b.J() & IMcuConstants.DEFAULT_VALUE;
            boolean z = (iJ & 128) == 128;
            int iG = g(iJ, 127);
            if (!z) {
                return this.f6267b.k(iG);
            }
            r rVar = r.f6384c;
            byte[] bArrS = this.f6267b.s(iG);
            Objects.requireNonNull(rVar);
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            int i2 = 0;
            r.a aVar = rVar.f6385d;
            int i3 = 0;
            for (byte b2 : bArrS) {
                i3 = (i3 << 8) | (b2 & IMcuConstants.DEFAULT_VALUE);
                i2 += 8;
                while (i2 >= 8) {
                    int i4 = i2 - 8;
                    aVar = aVar.f6386a[(i3 >>> i4) & MKeyEvent.KEYCODE_SLEEP];
                    if (aVar.f6386a == null) {
                        byteArrayOutputStream.write(aVar.f6387b);
                        i2 -= aVar.f6388c;
                        aVar = rVar.f6385d;
                    } else {
                        i2 = i4;
                    }
                }
            }
            while (i2 > 0) {
                r.a aVar2 = aVar.f6386a[(i3 << (8 - i2)) & MKeyEvent.KEYCODE_SLEEP];
                if (aVar2.f6386a != null || aVar2.f6388c > i2) {
                    break;
                }
                byteArrayOutputStream.write(aVar2.f6387b);
                i2 -= aVar2.f6388c;
                aVar = rVar.f6385d;
            }
            return h.i.h(byteArrayOutputStream.toByteArray());
        }

        public int g(int i2, int i3) {
            int i4 = i2 & i3;
            if (i4 < i3) {
                return i4;
            }
            int i5 = 0;
            while (true) {
                int iJ = this.f6267b.J() & IMcuConstants.DEFAULT_VALUE;
                if ((iJ & 128) == 0) {
                    return i3 + (iJ << i5);
                }
                i3 += (iJ & 127) << i5;
                i5 += 7;
            }
        }
    }

    public static final class b {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public final h.f f6274a;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public boolean f6276c;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public int f6275b = Platform.UNKNOWN;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        public c[] f6278e = new c[8];

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public int f6279f = 7;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        public int f6280g = 0;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        public int f6281h = 0;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        public int f6277d = 4096;

        public b(h.f fVar) {
            this.f6274a = fVar;
        }

        public final void a() {
            Arrays.fill(this.f6278e, (Object) null);
            this.f6279f = this.f6278e.length - 1;
            this.f6280g = 0;
            this.f6281h = 0;
        }

        public final int b(int i2) {
            int i3;
            int i4 = 0;
            if (i2 > 0) {
                int length = this.f6278e.length;
                while (true) {
                    length--;
                    i3 = this.f6279f;
                    if (length < i3 || i2 <= 0) {
                        break;
                    }
                    c[] cVarArr = this.f6278e;
                    i2 -= cVarArr[length].f6263i;
                    this.f6281h -= cVarArr[length].f6263i;
                    this.f6280g--;
                    i4++;
                }
                c[] cVarArr2 = this.f6278e;
                System.arraycopy(cVarArr2, i3 + 1, cVarArr2, i3 + 1 + i4, this.f6280g);
                c[] cVarArr3 = this.f6278e;
                int i5 = this.f6279f;
                Arrays.fill(cVarArr3, i5 + 1, i5 + 1 + i4, (Object) null);
                this.f6279f += i4;
            }
            return i4;
        }

        public final void c(c cVar) {
            int i2 = cVar.f6263i;
            int i3 = this.f6277d;
            if (i2 > i3) {
                a();
                return;
            }
            b((this.f6281h + i2) - i3);
            int i4 = this.f6280g + 1;
            c[] cVarArr = this.f6278e;
            if (i4 > cVarArr.length) {
                c[] cVarArr2 = new c[cVarArr.length * 2];
                System.arraycopy(cVarArr, 0, cVarArr2, cVarArr.length, cVarArr.length);
                this.f6279f = this.f6278e.length - 1;
                this.f6278e = cVarArr2;
            }
            int i5 = this.f6279f;
            this.f6279f = i5 - 1;
            this.f6278e[i5] = cVar;
            this.f6280g++;
            this.f6281h += i2;
        }

        public void d(h.i iVar) {
            Objects.requireNonNull(r.f6384c);
            long j2 = 0;
            long j3 = 0;
            for (int i2 = 0; i2 < iVar.k(); i2++) {
                j3 += (long) r.f6383b[iVar.f(i2) & IMcuConstants.DEFAULT_VALUE];
            }
            if (((int) ((j3 + 7) >> 3)) < iVar.k()) {
                h.f fVar = new h.f();
                Objects.requireNonNull(r.f6384c);
                int i3 = 0;
                for (int i4 = 0; i4 < iVar.k(); i4++) {
                    int iF = iVar.f(i4) & IMcuConstants.DEFAULT_VALUE;
                    int i5 = r.f6382a[iF];
                    byte b2 = r.f6383b[iF];
                    j2 = (j2 << b2) | ((long) i5);
                    i3 += b2;
                    while (i3 >= 8) {
                        i3 -= 8;
                        fVar.r((int) (j2 >> i3));
                    }
                }
                if (i3 > 0) {
                    fVar.r((int) ((j2 << (8 - i3)) | ((long) (MKeyEvent.KEYCODE_SLEEP >>> i3))));
                }
                iVar = fVar.Q();
                f(iVar.f6547d.length, 127, 128);
            } else {
                f(iVar.k(), 127, 0);
            }
            this.f6274a.W(iVar);
        }

        /* JADX WARN: Removed duplicated region for block: B:22:0x0069  */
        /* JADX WARN: Removed duplicated region for block: B:26:0x0070  */
        /* JADX WARN: Removed duplicated region for block: B:37:0x00a7  */
        /* JADX WARN: Removed duplicated region for block: B:38:0x00af  */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct add '--show-bad-code' argument
        */
        public void e(java.util.List<g.i0.i.c> r14) {
            /*
                Method dump skipped, instruction units count: 237
                To view this dump add '--comments-level debug' option
            */
            throw new UnsupportedOperationException("Method not decompiled: g.i0.i.d.b.e(java.util.List):void");
        }

        public void f(int i2, int i3, int i4) {
            int i5;
            h.f fVar;
            if (i2 < i3) {
                fVar = this.f6274a;
                i5 = i2 | i4;
            } else {
                this.f6274a.Z(i4 | i3);
                i5 = i2 - i3;
                while (i5 >= 128) {
                    this.f6274a.Z(128 | (i5 & 127));
                    i5 >>>= 7;
                }
                fVar = this.f6274a;
            }
            fVar.Z(i5);
        }
    }

    static {
        c cVar = new c(c.f6260f, "");
        int i2 = 0;
        h.i iVar = c.f6257c;
        h.i iVar2 = c.f6258d;
        h.i iVar3 = c.f6259e;
        h.i iVar4 = c.f6256b;
        c[] cVarArr = {cVar, new c(iVar, RequestLine.METHOD_GET), new c(iVar, RequestLine.METHOD_POST), new c(iVar2, "/"), new c(iVar2, "/index.html"), new c(iVar3, "http"), new c(iVar3, "https"), new c(iVar4, "200"), new c(iVar4, "204"), new c(iVar4, "206"), new c(iVar4, "304"), new c(iVar4, "400"), new c(iVar4, "404"), new c(iVar4, "500"), new c("accept-charset", ""), new c("accept-encoding", "gzip, deflate"), new c("accept-language", ""), new c("accept-ranges", ""), new c("accept", ""), new c("access-control-allow-origin", ""), new c("age", ""), new c("allow", ""), new c("authorization", ""), new c("cache-control", ""), new c("content-disposition", ""), new c("content-encoding", ""), new c("content-language", ""), new c("content-length", ""), new c("content-location", ""), new c("content-range", ""), new c("content-type", ""), new c("cookie", ""), new c("date", ""), new c("etag", ""), new c("expect", ""), new c("expires", ""), new c("from", ""), new c("host", ""), new c("if-match", ""), new c("if-modified-since", ""), new c("if-none-match", ""), new c("if-range", ""), new c("if-unmodified-since", ""), new c("last-modified", ""), new c("link", ""), new c("location", ""), new c("max-forwards", ""), new c("proxy-authenticate", ""), new c("proxy-authorization", ""), new c("range", ""), new c("referer", ""), new c("refresh", ""), new c("retry-after", ""), new c("server", ""), new c("set-cookie", ""), new c("strict-transport-security", ""), new c("transfer-encoding", ""), new c("user-agent", ""), new c("vary", ""), new c("via", ""), new c("www-authenticate", "")};
        f6264a = cVarArr;
        LinkedHashMap linkedHashMap = new LinkedHashMap(cVarArr.length);
        while (true) {
            c[] cVarArr2 = f6264a;
            if (i2 >= cVarArr2.length) {
                f6265b = Collections.unmodifiableMap(linkedHashMap);
                return;
            } else {
                if (!linkedHashMap.containsKey(cVarArr2[i2].f6261g)) {
                    linkedHashMap.put(cVarArr2[i2].f6261g, Integer.valueOf(i2));
                }
                i2++;
            }
        }
    }

    public static h.i a(h.i iVar) {
        int iK = iVar.k();
        for (int i2 = 0; i2 < iK; i2++) {
            byte bF = iVar.f(i2);
            if (bF >= 65 && bF <= 90) {
                StringBuilder sbC = a.b.c.a.a.C("PROTOCOL_ERROR response malformed: mixed case name: ");
                sbC.append(iVar.o());
                throw new IOException(sbC.toString());
            }
        }
        return iVar;
    }
}
