/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.objectmodel.EntityType
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.util.GoidUpgradeMapper
 *  com.l7tech.util.ResourceUtils
 *  org.jetbrains.annotations.NotNull
 */
package com.l7tech.server.log.syslog;

import com.l7tech.objectmodel.EntityType;
import com.l7tech.objectmodel.Goid;
import com.l7tech.server.ServerConfig;
import com.l7tech.server.log.syslog.ManagedSyslog;
import com.l7tech.server.log.syslog.Syslog;
import com.l7tech.server.log.syslog.SyslogConfig;
import com.l7tech.server.log.syslog.SyslogConnectionListener;
import com.l7tech.server.log.syslog.SyslogProtocol;
import com.l7tech.server.log.syslog.b;
import com.l7tech.server.log.syslog.c;
import com.l7tech.server.log.syslog.impl.MinaManagedSyslog;
import com.l7tech.util.GoidUpgradeMapper;
import com.l7tech.util.ResourceUtils;
import java.io.Closeable;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jetbrains.annotations.NotNull;

public class SyslogManager
implements Closeable {
    private static final Logger a;
    private static final int b = 1024;
    static final String c;
    private static final int d = 512;
    private static final int e = 65527;
    private static final String f;
    private final b g;
    private final Object h;
    private final Map<c, ManagedSyslog> i;
    private final ServerConfig j;
    private static final String[] t;

    public SyslogManager(@NotNull ServerConfig serverConfig) {
        if (serverConfig == null) {
            SyslogManager.a(0);
        }
        this.g = new b();
        this.h = new Object();
        this.i = new HashMap<c, ManagedSyslog>();
        this.j = serverConfig;
    }

    /*
     * Loose catch block
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    public Syslog getSyslog(SyslogProtocol syslogProtocol, String[][] stringArray, String string, String string2, int n2, String string3, String string4, String string5, String string6, String string7) {
        String string8;
        Goid goid;
        block22: {
            block21: {
                block20: {
                    try {
                        if (syslogProtocol == null) {
                            throw new IllegalArgumentException(t[13]);
                        }
                    }
                    catch (IllegalArgumentException illegalArgumentException) {
                        throw SyslogManager.a(illegalArgumentException);
                    }
                    if (stringArray == null) throw new IllegalArgumentException(t[10]);
                    try {
                        if (stringArray.length != 0) break block20;
                        throw new IllegalArgumentException(t[10]);
                        catch (IllegalArgumentException illegalArgumentException) {
                            throw SyslogManager.a(illegalArgumentException);
                        }
                    }
                    catch (IllegalArgumentException illegalArgumentException) {
                        throw SyslogManager.a(illegalArgumentException);
                    }
                }
                try {
                    if (string3 == null) {
                        throw new IllegalArgumentException(t[7]);
                    }
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw SyslogManager.a(illegalArgumentException);
                }
                if (n2 < 0) throw new IllegalArgumentException(t[14] + n2);
                try {
                    if (n2 <= 124) break block21;
                    throw new IllegalArgumentException(t[14] + n2);
                    catch (IllegalArgumentException illegalArgumentException) {
                        throw SyslogManager.a(illegalArgumentException);
                    }
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw SyslogManager.a(illegalArgumentException);
                }
            }
            goid = null;
            try {
                if (!SyslogProtocol.SSL.equals((Object)syslogProtocol) || string7 == null) break block22;
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw SyslogManager.a(illegalArgumentException);
            }
            try {
                goid = GoidUpgradeMapper.mapId((EntityType)EntityType.SSG_KEYSTORE, (String)string7);
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw new IllegalArgumentException(t[21] + string7);
            }
        }
        try {
            string8 = SyslogProtocol.UDP == syslogProtocol ? "" : string5;
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw SyslogManager.a(illegalArgumentException);
        }
        String string9 = string8;
        SocketAddress[] socketAddressArray = this.a(stringArray);
        return this.a(syslogProtocol, socketAddressArray, string, string2, n2, string3, string4, string9, string6, goid);
    }

    public void setConnectionListener(SyslogConnectionListener syslogConnectionListener) {
        this.g.a.set(syslogConnectionListener);
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    @Override
    public void close() {
        Object object = this.h;
        synchronized (object) {
            Iterator<ManagedSyslog> iterator = this.i.values().iterator();
            while (iterator.hasNext()) {
                ManagedSyslog managedSyslog = iterator.next();
                iterator.remove();
                ResourceUtils.closeQuietly((Closeable)managedSyslog);
            }
        }
    }

    Syslog a(SyslogProtocol syslogProtocol, SocketAddress[] socketAddressArray, String string, String string2, int n2, String string3, String string4, String string5, String string6, Goid goid) {
        ManagedSyslog managedSyslog = this.a(syslogProtocol, socketAddressArray, string6, goid);
        return managedSyslog.getSylog(new ManagedSyslog.SyslogFormat(string, string2, string4, string5, this.b(), this.c()), n2, string3);
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    void a(ManagedSyslog managedSyslog) {
        try {
            if (managedSyslog == null) {
                throw new IllegalArgumentException(t[4]);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw SyslogManager.a(illegalArgumentException);
        }
        Object object = this.h;
        synchronized (object) {
            if (!managedSyslog.c()) {
                this.i.values().remove(managedSyslog);
                ResourceUtils.closeQuietly((Closeable)managedSyslog);
            }
        }
    }

    SyslogConnectionListener a() {
        return this.g;
    }

    private int b() {
        int n2 = this.j.getIntProperty(f, 1024);
        if (n2 < 512) {
            n2 = 512;
        }
        if (n2 > 65527) {
            n2 = 65527;
        }
        return n2;
    }

    private SimpleDateFormat c() {
        String[] stringArray = t;
        String string = this.j.getProperty(stringArray[22], stringArray[9]);
        try {
            return new SimpleDateFormat(string);
        }
        catch (IllegalArgumentException | NullPointerException runtimeException) {
            stringArray = t;
            a.log(Level.WARNING, stringArray[3], runtimeException);
            return new SimpleDateFormat(stringArray[11]);
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    private ManagedSyslog a(SyslogProtocol syslogProtocol, SocketAddress[] socketAddressArray, String string, Goid goid) {
        ManagedSyslog managedSyslog;
        try {
            if (syslogProtocol == null) {
                throw new IllegalArgumentException(t[0]);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw SyslogManager.a(illegalArgumentException);
        }
        Object object = this.h;
        synchronized (object) {
            c c10 = new c(syslogProtocol, socketAddressArray);
            managedSyslog = this.i.get(c10);
            if (managedSyslog == null) {
                MinaManagedSyslog minaManagedSyslog = new MinaManagedSyslog(new SyslogConfig.Builder().setProtocol(syslogProtocol).setAddresses(socketAddressArray).setSslKeystoreAlias(string).setSslKeystoreId(goid).setQueueSize(this.getLogQueueSize()).setConnectTimeOut(this.getConnectionTimeOut()).setMaxReconnectAttempts(this.getMaxReconnectionAttempts()).setReconnectInterval(this.getReconnectSleepTime()).setDropRatePercent(this.getDropRatePercent()).setValidateExtendedKeyUsage(this.j.getBooleanProperty(t[20], false)).createSyslogConfig());
                minaManagedSyslog.init(this);
                this.i.put(c10, minaManagedSyslog);
                managedSyslog = minaManagedSyslog;
            }
            managedSyslog.a();
        }
        return managedSyslog;
    }

    /*
     * Loose catch block
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    private InetSocketAddress[] a(String[][] stringArray) {
        InetSocketAddress[] inetSocketAddressArray = new InetSocketAddress[stringArray.length];
        int n2 = 0;
        int n3 = 0;
        while (true) {
            block12: {
                block11: {
                    if (n3 >= stringArray.length) return inetSocketAddressArray;
                    try {
                        if (stringArray[n3][0] != null) break block11;
                        throw new IllegalArgumentException(t[23]);
                        catch (NumberFormatException numberFormatException) {
                            throw SyslogManager.a(numberFormatException);
                        }
                    }
                    catch (NumberFormatException numberFormatException) {
                        throw SyslogManager.a(numberFormatException);
                    }
                }
                try {
                    n2 = Integer.valueOf(stringArray[n3][1]);
                    if (n2 < 1) throw new IllegalArgumentException(t[15] + n2);
                    try {
                        if (n2 <= 65535) break block12;
                        throw new IllegalArgumentException(t[15] + n2);
                        catch (NumberFormatException numberFormatException) {
                            throw SyslogManager.a(numberFormatException);
                        }
                    }
                    catch (NumberFormatException numberFormatException) {
                        throw SyslogManager.a(numberFormatException);
                    }
                }
                catch (NumberFormatException numberFormatException) {
                    throw new IllegalArgumentException(t[5] + n2);
                }
            }
            inetSocketAddressArray[n3] = new InetSocketAddress(stringArray[n3][0], n2);
            ++n3;
        }
    }

    protected int getLogQueueSize() {
        return this.a(t[19]);
    }

    protected int getConnectionTimeOut() {
        return this.a(t[1]);
    }

    protected int getMaxReconnectionAttempts() {
        return this.a(t[16]);
    }

    protected int getReconnectSleepTime() {
        return this.a(t[6]);
    }

    protected int getDropRatePercent() {
        return this.a(t[2]);
    }

    private int a(String string) {
        int n2 = this.j.getIntProperty(string, Integer.parseInt(this.j.getClusterPropertyDefaults().get(string)));
        try {
            if (a.isLoggable(Level.CONFIG)) {
                a.config(t[8] + string + t[17] + n2);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw SyslogManager.a(illegalArgumentException);
        }
        return n2;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[27];
                var3_1 = 0;
                var2_2 = "\u0003h\n\t\u001ag\u0011\u001f:\b\b\u0006p^\u001du\u0011]\u0017a^\u001do\t\u0011\u0015\u0000c\u0016\u0011\u001acP\u0010u\u000b\u0013\u0010g\n's\b\u0018\u001aq\n\u0016\u0000c\u0016\u0011\u001acP\u0017h\n\r'e\n\u0016J\u0000\u000f\u0016a\u0010\u0007P&t\u0000\u0005\u0005a\u001d\u0007\u007f\u0001]\u0016q\r\u0007u\b]&m\u0013\u0003v\u00009\u0014p\u001b5u\u0017\u0010\u0014p^\u0005{\t\b\u0010*^&i\f\u0013\u0012$Y>W(]\u0011$6; \b\u0010Ow\r]I6.R$\u001f\u0000:\u0001\u0018\u0013e\u000b\u001fnK\u0017\u0000c\u0016\u0011\u001ac^\u001eo\u0016\tUj\u0011\u0007:\u0007\u0018Uj\u000b\u001fv\u0014\u001at\u0013\u001c\u0019m\u001aSi\u001c\u000e\u0019k\u0019Sj\n\u000f\u0001$\u0018\u0000c\u0016\u0011\u001acP\u0001\u007f\u0006\u0012\u001bj\u001b\u0010n,\u0013\u0001a\f\u0005{\t\u0015\u001bu\u0016\tUi\u000b\u0000nE\u0013\u001ap^\u0011\u007fE\u0013\u0000h\u0012\u0010 c\u0016\u0011\u001ac^\u0003h\n\r\u0010v\n\n:\u0012>W(]\u0011$6; \b\u0010Ow\r]I6.%\u0000c\u0016\u0011\u001ac6\u001ci\u0011\u000eUi\u000b\u0000nE\u0013\u001ap^\u0011\u007fE\u0013\u0000h\u0012Su\u0017]\u0010i\u000e\u0007c\u0012>W(]\u0011$6; \b\u0010Ow\r]I6.\u0006Os\u000b\u0014\u0001:\u0019\u0003h\n\t\u001ag\u0011\u001f:\b\b\u0006p^\u001du\u0011]\u0017a^\u001do\t\u0011\u0011\u001at\u0013\u001c\u0019m\u001aS|\u0004\u001e\u001ch\u0017\u0007cE\u0014\u001at\u0013\u001c\u0019m\u001aSi\u001c\u000e\u0019k\u0019Sj\n\u000f\u0001$\u0018\u0000c\u0016\u0011\u001acP\u0001\u007f\u0006\u0012\u001bj\u001b\u0010n$\t\u0001a\u0013\u0003n\u0016\u000bSs\u0016]\u0006a\nSn\n]\f\u0000\u007f\u0017\u000b\u0010v=\u001ct\u0003\u0014\u0012\u0010\u0000c\u0016\u0011\u001acP\u0002o\u0000\b\u0010W\u0017\t\u007f#\u0000c\u0016\u0011\u001acP\u0000i\tS\u0003e\u0012\u001a~\u0004\t\u0010A\u0006\u0007\u007f\u000b\u0019\u0010`5\u0016c0\u000e\u0014c\u001b  I)]>a\u0007\u0000n\n\u000f\u0010$7\u0017:\b\b\u0006p^\u0011\u007fE\u0013\u0000i\u001b\u0001s\u0006]\u0010\u0000c\u0016\u0011\u001ac:\u0012n\u0000;\u001av\u0013\u0012n\u0013\u0000c\u0016\u0011\u001ac^\u001bu\u0016\tUm\rSt\u0010\u0011\u0019*\u0010u\bR\u00193\n\u0016y\rR\u0006a\f\u0005\u007f\u0017R\u0019k\u0019\\i\u001c\u000e\u0019k\u0019\\I\u001c\u000e\u0019k\u0019>{\u000b\u001c\u0012a\f";
                var4_3 = "\u0003h\n\t\u001ag\u0011\u001f:\b\b\u0006p^\u001du\u0011]\u0017a^\u001do\t\u0011\u0015\u0000c\u0016\u0011\u001acP\u0010u\u000b\u0013\u0010g\n's\b\u0018\u001aq\n\u0016\u0000c\u0016\u0011\u001acP\u0017h\n\r'e\n\u0016J\u0000\u000f\u0016a\u0010\u0007P&t\u0000\u0005\u0005a\u001d\u0007\u007f\u0001]\u0016q\r\u0007u\b]&m\u0013\u0003v\u00009\u0014p\u001b5u\u0017\u0010\u0014p^\u0005{\t\b\u0010*^&i\f\u0013\u0012$Y>W(]\u0011$6; \b\u0010Ow\r]I6.R$\u001f\u0000:\u0001\u0018\u0013e\u000b\u001fnK\u0017\u0000c\u0016\u0011\u001ac^\u001eo\u0016\tUj\u0011\u0007:\u0007\u0018Uj\u000b\u001fv\u0014\u001at\u0013\u001c\u0019m\u001aSi\u001c\u000e\u0019k\u0019Sj\n\u000f\u0001$\u0018\u0000c\u0016\u0011\u001acP\u0001\u007f\u0006\u0012\u001bj\u001b\u0010n,\u0013\u0001a\f\u0005{\t\u0015\u001bu\u0016\tUi\u000b\u0000nE\u0013\u001ap^\u0011\u007fE\u0013\u0000h\u0012\u0010 c\u0016\u0011\u001ac^\u0003h\n\r\u0010v\n\n:\u0012>W(]\u0011$6; \b\u0010Ow\r]I6.%\u0000c\u0016\u0011\u001ac6\u001ci\u0011\u000eUi\u000b\u0000nE\u0013\u001ap^\u0011\u007fE\u0013\u0000h\u0012Su\u0017]\u0010i\u000e\u0007c\u0012>W(]\u0011$6; \b\u0010Ow\r]I6.\u0006Os\u000b\u0014\u0001:\u0019\u0003h\n\t\u001ag\u0011\u001f:\b\b\u0006p^\u001du\u0011]\u0017a^\u001do\t\u0011\u0011\u001at\u0013\u001c\u0019m\u001aS|\u0004\u001e\u001ch\u0017\u0007cE\u0014\u001at\u0013\u001c\u0019m\u001aSi\u001c\u000e\u0019k\u0019Sj\n\u000f\u0001$\u0018\u0000c\u0016\u0011\u001acP\u0001\u007f\u0006\u0012\u001bj\u001b\u0010n$\t\u0001a\u0013\u0003n\u0016\u000bSs\u0016]\u0006a\nSn\n]\f\u0000\u007f\u0017\u000b\u0010v=\u001ct\u0003\u0014\u0012\u0010\u0000c\u0016\u0011\u001acP\u0002o\u0000\b\u0010W\u0017\t\u007f#\u0000c\u0016\u0011\u001acP\u0000i\tS\u0003e\u0012\u001a~\u0004\t\u0010A\u0006\u0007\u007f\u000b\u0019\u0010`5\u0016c0\u000e\u0014c\u001b  I)]>a\u0007\u0000n\n\u000f\u0010$7\u0017:\b\b\u0006p^\u0011\u007fE\u0013\u0000i\u001b\u0001s\u0006]\u0010\u0000c\u0016\u0011\u001ac:\u0012n\u0000;\u001av\u0013\u0012n\u0013\u0000c\u0016\u0011\u001ac^\u001bu\u0016\tUm\rSt\u0010\u0011\u0019*\u0010u\bR\u00193\n\u0016y\rR\u0006a\f\u0005\u007f\u0017R\u0019k\u0019\\i\u001c\u000e\u0019k\u0019\\I\u001c\u000e\u0019k\u0019>{\u000b\u001c\u0012a\f".length();
                var1_4 = 25;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = SyslogManager.a(v0, SyslogManager.b(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "%\u007f\u0015\u001f\u000fv\u0007\u0010-\u0014\u0005\u00103)*b\u0006$\u0017\u007f\u0005D}\u0013\u0018\u0003~\f\u0010h\u0000JE6\u001aC-\u001d\fB6\u001aJ(\u0001J\u000ff\u001a\u0010-\u001c\u0005\u00163\u000b\u0001-\u001c\u001f\u000e\u007f\nJ`\u0013\u0012.v\u0007\u0003y\u001a";
                    var4_3 = "%\u007f\u0015\u001f\u000fv\u0007\u0010-\u0014\u0005\u00103)*b\u0006$\u0017\u007f\u0005D}\u0013\u0018\u0003~\f\u0010h\u0000JE6\u001aC-\u001d\fB6\u001aJ(\u0001J\u000ff\u001a\u0010-\u001c\u0005\u00163\u000b\u0001-\u001c\u001f\u000e\u007f\nJ`\u0013\u0012.v\u0007\u0003y\u001a".length();
                    var1_4 = 62;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 8;
                        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++] = SyslogManager.a(v0, SyslogManager.b(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;
            }
        }
        SyslogManager.t = var5;
        SyslogManager.c = SyslogManager.t[11];
        SyslogManager.a = Logger.getLogger(SyslogManager.class.getName());
        SyslogManager.f = SyslogManager.class.getPackage().getName() + SyslogManager.t[26];
    }

    private static /* synthetic */ void a(int n2) {
        String[] stringArray = t;
        throw new IllegalArgumentException(String.format(stringArray[25], stringArray[18], stringArray[24], stringArray[12]));
    }

    private static IllegalArgumentException a(IllegalArgumentException illegalArgumentException) {
        return illegalArgumentException;
    }

    private static char[] b(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x61);
        }
        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 -> 108;
                    case 1 -> 5;
                    case 2 -> 122;
                    case 3 -> 98;
                    case 4 -> 106;
                    case 5 -> 27;
                    default -> 97;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

