/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.mime.ContentTypeHeader
 *  com.l7tech.common.mime.MimeHeader
 *  com.l7tech.common.mime.NoSuchPartException
 *  com.l7tech.common.mime.PartInfo
 *  com.l7tech.policy.variable.Syntax$SyntaxErrorHandler
 *  com.l7tech.util.ConfigFactory
 *  com.l7tech.util.IOUtils
 *  com.l7tech.util.ResourceUtils
 */
package com.l7tech.server.policy.variable;

import com.l7tech.common.mime.ContentTypeHeader;
import com.l7tech.common.mime.MimeHeader;
import com.l7tech.common.mime.NoSuchPartException;
import com.l7tech.common.mime.PartInfo;
import com.l7tech.policy.variable.Syntax;
import com.l7tech.server.policy.variable.ExpandVariables;
import com.l7tech.util.ConfigFactory;
import com.l7tech.util.IOUtils;
import com.l7tech.util.ResourceUtils;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;

class fh
implements ExpandVariables.Selector<PartInfo> {
    private static final String a;
    private static final String b;
    private static final String c;
    private static final String d;
    private static final int e = 0x100000;
    private static final String[] f;

    fh() {
    }

    @Override
    public ExpandVariables.Selector.Selection select(String string, PartInfo partInfo, String string2, Syntax.SyntaxErrorHandler syntaxErrorHandler, boolean bl2) {
        ExpandVariables.Selector.Selection selection;
        String[] stringArray;
        String string3 = string2.toLowerCase();
        if (string3.equals((stringArray = f)[9])) {
            selection = this.a(partInfo, syntaxErrorHandler, bl2);
        } else {
            stringArray = f;
            if (string3.equals(stringArray[12])) {
                selection = this.a(partInfo);
            } else {
                stringArray = f;
                if (string3.startsWith(stringArray[10])) {
                    selection = this.a(this.a(string, stringArray[0]), partInfo, string2.substring(stringArray[0].length()), syntaxErrorHandler, bl2);
                } else {
                    stringArray = f;
                    if (string3.equals(stringArray[1])) {
                        selection = this.b(string, partInfo, string2, syntaxErrorHandler, bl2);
                    } else {
                        if (bl2) {
                            stringArray = f;
                            String string4 = syntaxErrorHandler.handleBadVariable(string2 + stringArray[13] + string);
                            throw new IllegalArgumentException(string4);
                        }
                        syntaxErrorHandler.handleBadVariable(string2 + f[4] + string);
                        selection = null;
                    }
                }
            }
        }
        return selection;
    }

    @Override
    public Class<PartInfo> getContextObjectClass() {
        return PartInfo.class;
    }

    private static int a() {
        return ConfigFactory.getIntProperty((String)f[5], (int)0x100000);
    }

    private String a(String string, String string2) {
        Object object = string + "." + string2;
        if (((String)object).endsWith(".")) {
            object = ((String)object).substring(0, ((String)object).length() - 1);
        }
        return object;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Loose catch block
     */
    private ExpandVariables.Selector.Selection a(PartInfo partInfo, Syntax.SyntaxErrorHandler syntaxErrorHandler, boolean bl2) {
        ExpandVariables.Selector.Selection selection;
        InputStream inputStream;
        block16: {
            inputStream = null;
            ContentTypeHeader contentTypeHeader = partInfo.getContentType();
            if (!contentTypeHeader.isTextualContentType()) break block16;
            inputStream = partInfo.getInputStream(false);
            byte[] byArray = IOUtils.slurpStream((InputStream)inputStream, (int)fh.a());
            ExpandVariables.Selector.Selection selection2 = new ExpandVariables.Selector.Selection(new String(byArray, contentTypeHeader.getEncoding()));
            ResourceUtils.closeQuietly((Closeable)inputStream);
            return selection2;
        }
        try {
            String[] stringArray = f;
            String string = syntaxErrorHandler.handleBadVariable(stringArray[11]);
            try {
                if (bl2) {
                    throw new IllegalArgumentException(string);
                }
            }
            catch (NoSuchPartException noSuchPartException) {
                throw fh.a((Exception)((Object)noSuchPartException));
            }
            selection = null;
        }
        catch (NoSuchPartException noSuchPartException) {
            String[] stringArray = f;
            String string = syntaxErrorHandler.handleBadVariable(stringArray[3]);
            try {
                if (bl2) {
                    throw new IllegalArgumentException(string);
                }
            }
            catch (NoSuchPartException noSuchPartException2) {
                throw fh.a((Exception)((Object)noSuchPartException2));
            }
            ExpandVariables.Selector.Selection selection3 = null;
            ResourceUtils.closeQuietly((Closeable)inputStream);
            return selection3;
        }
        catch (IOException iOException) {
            String string = syntaxErrorHandler.handleBadVariable(f[6]);
            try {
                if (bl2) {
                    throw new IllegalArgumentException(string);
                }
            }
            catch (NoSuchPartException noSuchPartException) {
                throw fh.a((Exception)((Object)noSuchPartException));
            }
            ExpandVariables.Selector.Selection selection4 = null;
            {
                catch (Throwable throwable) {
                    ResourceUtils.closeQuietly(inputStream);
                    throw throwable;
                }
            }
            ResourceUtils.closeQuietly((Closeable)inputStream);
            return selection4;
        }
        ResourceUtils.closeQuietly((Closeable)inputStream);
        return selection;
    }

    private ExpandVariables.Selector.Selection a(PartInfo partInfo) {
        return new ExpandVariables.Selector.Selection(partInfo.getContentType().getFullValue());
    }

    private ExpandVariables.Selector.Selection a(String string, PartInfo partInfo, String string2, Syntax.SyntaxErrorHandler syntaxErrorHandler, boolean bl2) {
        MimeHeader mimeHeader = partInfo.getHeader(string2);
        try {
            if (mimeHeader != null) {
                return new ExpandVariables.Selector.Selection(mimeHeader.getFullValue());
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw fh.a(illegalArgumentException);
        }
        String string3 = syntaxErrorHandler.handleBadVariable(string2 + f[4] + string);
        try {
            if (bl2) {
                throw new IllegalArgumentException(string3);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw fh.a(illegalArgumentException);
        }
        return null;
    }

    private ExpandVariables.Selector.Selection b(String string, PartInfo partInfo, String string2, Syntax.SyntaxErrorHandler syntaxErrorHandler, boolean bl2) {
        ExpandVariables.Selector.Selection selection;
        block7: {
            selection = null;
            String string3 = null;
            try {
                selection = new ExpandVariables.Selector.Selection(partInfo.getActualContentLength());
            }
            catch (IOException iOException) {
                String[] stringArray = f;
                string3 = syntaxErrorHandler.handleBadVariable(string2 + stringArray[4] + string, (Throwable)iOException);
            }
            catch (NoSuchPartException noSuchPartException) {
                String[] stringArray = f;
                string3 = syntaxErrorHandler.handleBadVariable(string2 + stringArray[4] + string, (Throwable)noSuchPartException);
            }
            try {
                try {
                    if (!bl2 || string3 == null) break block7;
                }
                catch (IOException iOException) {
                    throw fh.a(iOException);
                }
                throw new IllegalArgumentException(f[7] + string3);
            }
            catch (IOException iOException) {
                throw fh.a(iOException);
            }
        }
        ExpandVariables.Selector.Selection selection2 = selection;
        return selection2;
    }

    private static Exception a(Exception exception) {
        return exception;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[15];
                var3_1 = 0;
                var2_2 = "3\u0003q\u00188`Q\u0004(\u000fj\u0019\u00049\tt\u0005\u0012\u000b\u0007b\b}|\u0010/Fq\n<{\u0013:\u0004|\u0019\u0004{\u000f~\\\u0018/\u0003}\f1s\u000b>H`\u001d/f=4\u0002i1<j,2\u001cu\u0013\u000b\u0007b\b}q\u001e5\b\u007f\b}p\u001a{\u0014u\u001d9!\u000e\bq\u001e1w_/\t0\u00188f\u001a)\u000by\u001282\u000f:\u0014d\\1w\u0011<\u0012xF}\u000b8\t~\b8|\u000b/\u001f`\u0019\u00049\tt\u0005\u00073\u0003q\u00188`Q\u0010\u000b\u0007b\b}{\f{\b\u007f\b}f\u001a#\u0012\u000b8\t~\b8|\u000b/\u001f`\u0019";
                var4_3 = "3\u0003q\u00188`Q\u0004(\u000fj\u0019\u00049\tt\u0005\u0012\u000b\u0007b\b}|\u0010/Fq\n<{\u0013:\u0004|\u0019\u0004{\u000f~\\\u0018/\u0003}\f1s\u000b>H`\u001d/f=4\u0002i1<j,2\u001cu\u0013\u000b\u0007b\b}q\u001e5\b\u007f\b}p\u001a{\u0014u\u001d9!\u000e\bq\u001e1w_/\t0\u00188f\u001a)\u000by\u001282\u000f:\u0014d\\1w\u0011<\u0012xF}\u000b8\t~\b8|\u000b/\u001f`\u0019\u00049\tt\u0005\u00073\u0003q\u00188`Q\u0010\u000b\u0007b\b}{\f{\b\u007f\b}f\u001a#\u0012\u000b8\t~\b8|\u000b/\u001f`\u0019".length();
                var1_4 = 7;
                var0_5 = -1;
lbl7:
                // 2 sources

                while (true) {
                    v0 = 64;
                    v1 = ++var0_5;
                    v2 = var2_2.substring(v1, v1 + var1_4);
                    v3 = -1;
                    break block9;
                    break;
                }
lbl13:
                // 1 sources

                while (true) {
                    var5[var3_1++] = fh.a(v0, fh.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "6B3\u0011\u0004eB'T";
                    var4_3 = "6B3\u0011\u0004eB'T".length();
                    var1_4 = 4;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 13;
                        v4 = ++var0_5;
                        v2 = var2_2.substring(v4, v4 + var1_4);
                        v3 = 0;
                        break block9;
                        break;
                    }
                    break;
                }
lbl28:
                // 1 sources

                while (true) {
                    var5[var3_1++] = fh.a(v0, fh.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    break block10;
                    break;
                }
            }
            switch (v3) {
                default: {
                    ** continue;
                }
                ** case 0:
lbl39:
                // 1 sources

                ** continue;
            }
        }
        fh.f = var5;
        fh.c = fh.f[0];
        fh.a = fh.f[2];
        fh.b = fh.f[8];
        fh.d = fh.f[14];
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x3F);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 27;
                    case 1 -> 38;
                    case 2 -> 80;
                    case 3 -> 60;
                    case 4 -> 29;
                    case 5 -> 82;
                    default -> 63;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

