/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.mime.NoSuchPartException
 *  com.l7tech.gateway.common.audit.Audit
 *  com.l7tech.message.Message
 *  com.l7tech.message.MimeKnob
 *  com.l7tech.policy.assertion.AssertionStatus
 *  com.l7tech.policy.variable.NoSuchVariableException
 *  com.l7tech.policy.variable.Syntax
 *  com.l7tech.util.Config
 *  com.l7tech.util.IOUtils
 *  org.springframework.beans.BeansException
 *  org.springframework.context.ApplicationContext
 *  org.springframework.context.ApplicationContextAware
 */
package com.l7tech.server.log;

import com.l7tech.common.mime.NoSuchPartException;
import com.l7tech.gateway.common.audit.Audit;
import com.l7tech.message.Message;
import com.l7tech.message.MimeKnob;
import com.l7tech.policy.assertion.AssertionStatus;
import com.l7tech.policy.variable.NoSuchVariableException;
import com.l7tech.policy.variable.Syntax;
import com.l7tech.server.audit.Auditor;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.server.policy.variable.ExpandVariables;
import com.l7tech.server.util.SoapFaultManager;
import com.l7tech.util.Config;
import com.l7tech.util.IOUtils;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class TrafficLogger
implements ApplicationContextAware,
PropertyChangeListener {
    public static final String SERVCFG_DETAIL;
    public static final String SERVCFG_ADDREQ;
    public static final String SERVCFG_ADDRES;
    public static final String SERVCFG_SELECTIVE;
    public static final String CONTEXT_VAR_SELECT;
    private static final Logger a;
    private static final Logger b;
    private final Config c;
    private final SoapFaultManager d;
    private final AtomicBoolean e = new AtomicBoolean(false);
    private Auditor f;
    private final ReentrantReadWriteLock g = new ReentrantReadWriteLock();
    private String h = m[0];
    private String[] i = Syntax.getReferencedNames((String)this.h);
    private boolean j = false;
    private boolean k = false;
    private boolean l = false;
    private static final String[] m;

    public TrafficLogger(Config config, SoapFaultManager soapFaultManager) {
        this.c = config;
        this.d = soapFaultManager;
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        try {
            if (this.f == null) {
                this.f = new Auditor(this, applicationContext, a);
            }
        }
        catch (BeansException beansException) {
            throw TrafficLogger.a((Exception)((Object)beansException));
        }
    }

    @Override
    public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
        a.log(Level.CONFIG, m[12], new Object[]{propertyChangeEvent.getPropertyName(), propertyChangeEvent.getOldValue(), propertyChangeEvent.getNewValue()});
        this.a();
    }

    public void setEnabled(boolean bl2) {
        block4: {
            boolean bl3 = this.e.getAndSet(bl2);
            try {
                try {
                    if (bl3 || !bl2) break block4;
                }
                catch (BeansException beansException) {
                    throw TrafficLogger.a((Exception)((Object)beansException));
                }
                this.a();
            }
            catch (BeansException beansException) {
                throw TrafficLogger.a((Exception)((Object)beansException));
            }
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public void log(PolicyEnforcementContext policyEnforcementContext) {
        StringBuilder stringBuilder;
        block27: {
            String string;
            block28: {
                String[] stringArray;
                block26: {
                    block25: {
                        boolean bl2;
                        boolean bl3;
                        block24: {
                            String string2;
                            block23: {
                                String[] stringArray2;
                                block22: {
                                    boolean bl4;
                                    try {
                                        if (!this.e.get()) {
                                            return;
                                        }
                                    }
                                    catch (NoSuchVariableException noSuchVariableException) {
                                        throw TrafficLogger.a((Exception)((Object)noSuchVariableException));
                                    }
                                    ReentrantReadWriteLock.ReadLock readLock = this.g.readLock();
                                    readLock.lock();
                                    try {
                                        string2 = this.h;
                                        stringArray2 = this.i;
                                        bl3 = this.j;
                                        bl2 = this.k;
                                        bl4 = this.l;
                                    }
                                    finally {
                                        readLock.unlock();
                                    }
                                    boolean bl5 = false;
                                    try {
                                        stringArray = m;
                                        bl5 = Boolean.parseBoolean((String)policyEnforcementContext.getVariable(stringArray[9]));
                                    }
                                    catch (NoSuchVariableException noSuchVariableException) {
                                        // empty catch block
                                    }
                                    try {
                                        try {
                                            if (!bl4 || bl5) break block22;
                                        }
                                        catch (NoSuchVariableException noSuchVariableException) {
                                            throw TrafficLogger.a((Exception)((Object)noSuchVariableException));
                                        }
                                        return;
                                    }
                                    catch (NoSuchVariableException noSuchVariableException) {
                                        throw TrafficLogger.a((Exception)((Object)noSuchVariableException));
                                    }
                                }
                                stringBuilder = new StringBuilder();
                                try {
                                    if (stringArray2.length <= 0) break block23;
                                    stringBuilder.append(ExpandVariables.process(string2, policyEnforcementContext.getVariableMap(stringArray2, (Audit)this.f), (Audit)this.f));
                                    break block24;
                                }
                                catch (NoSuchVariableException noSuchVariableException) {
                                    throw TrafficLogger.a((Exception)((Object)noSuchVariableException));
                                }
                            }
                            stringBuilder.append(string2);
                        }
                        if (bl3) {
                            stringArray = m;
                            string = this.a(policyEnforcementContext.getRequest(), stringArray[7]);
                            if (string == null) {
                                string = stringArray[5];
                            }
                            stringBuilder.append(" ").append(string);
                        }
                        if (!bl2) break block27;
                        Message message = policyEnforcementContext.getResponse();
                        try {
                            if (!message.isInitialized() || message.getKnob(MimeKnob.class) == null) break block25;
                        }
                        catch (NoSuchVariableException noSuchVariableException) {
                            throw TrafficLogger.a((Exception)((Object)noSuchVariableException));
                        }
                        stringArray = m;
                        string = this.a(message, stringArray[10]);
                        break block28;
                    }
                    AssertionStatus assertionStatus = policyEnforcementContext.getPolicyResult();
                    try {
                        if (assertionStatus == null || assertionStatus == AssertionStatus.NONE) break block26;
                    }
                    catch (NoSuchVariableException noSuchVariableException) {
                        throw TrafficLogger.a((Exception)((Object)noSuchVariableException));
                    }
                    string = this.d.constructReturningFault(policyEnforcementContext.getFaultlevel(), policyEnforcementContext).getContent();
                    break block28;
                }
                stringArray = m;
                string = stringArray[17];
            }
            if (string == null) {
                string = m[19];
            }
            stringBuilder.append(" ").append(string);
        }
        b.info(stringBuilder.toString());
    }

    private String a(Message message, String string) {
        String string2;
        block5: {
            string2 = null;
            try {
                try {
                    if (!message.isInitialized() || message.getKnob(MimeKnob.class) == null) break block5;
                }
                catch (IOException iOException) {
                    throw TrafficLogger.a(iOException);
                }
                byte[] byArray = IOUtils.slurpStream((InputStream)message.getMimeKnob().getFirstPart().getInputStream(false));
                Charset charset = message.getMimeKnob().getFirstPart().getContentType().getEncoding();
                string2 = new String(byArray, charset);
            }
            catch (IOException iOException) {
                String[] stringArray = m;
                a.log(Level.WARNING, stringArray[11] + string + stringArray[14], iOException);
            }
            catch (NoSuchPartException noSuchPartException) {
                String[] stringArray = m;
                a.log(Level.WARNING, stringArray[6] + string + stringArray[4], noSuchPartException);
            }
        }
        return string2;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    private void a() {
        try {
            if (a.isLoggable(Level.CONFIG)) {
                a.log(Level.CONFIG, m[13]);
            }
        }
        catch (BeansException beansException) {
            throw TrafficLogger.a((Exception)((Object)beansException));
        }
        String[] stringArray = m;
        String string = this.c.getProperty(stringArray[1]);
        boolean bl2 = this.c.getBooleanProperty(stringArray[2], false);
        boolean bl3 = this.c.getBooleanProperty(stringArray[21], false);
        boolean bl4 = this.c.getBooleanProperty(stringArray[16], false);
        ReentrantReadWriteLock.WriteLock writeLock = this.g.writeLock();
        writeLock.lock();
        try {
            this.j = bl2;
            this.k = bl3;
            this.h = string;
            this.l = bl4;
            this.i = Syntax.getReferencedNames((String)this.h);
            if (this.i == null) {
                this.i = new String[0];
            }
        }
        finally {
            writeLock.unlock();
        }
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[23];
                var3_1 = 0;
                var2_2 = "\u0012p\u00168~+rE\u007fJ)f3rK'Dyt,rG~\u0001.{pdYj\u0014sa?zSx\u0014<l;j\u001a+@&};fCn\u0017)!-xW{J2\u007f;eW\u007f\r2a0v[n\u0019q/zlDn\u0017-`0dS%\f){.9E\u007f\u0005)z-j\u0013By\u0005;i7tzd\u0003:j,SS\u007f\u00054c\u0016By\u0005;i7tzd\u0003:j,ESh\u000b/k\frG\u0016By\u0005;i7tzd\u0003:j,DSg\u0001>{7aS\t\u0016h\u000b3{;yBx\u001edn\u0015(j-c\u0016h\u000b3{;yBxD3`*7W}\u00054c?uZn\u000eud\u00111k~yY\u007fD:j*7\u0007Dn\u0015(j-c\u0016By\u0005;i7tzd\u0003:j,ESh\u000b/k\frE\u0014By\u0005;i7tZd\u0003:j,9En\b8l*\bDn\u0017-`0dS\u000eud\u00111k~yY\u007fD:j*7<fy\u000b-j,cO+\u001fmr~t^j\n:j:,\u0016d\b9/(vZ~\u0001g/y0M:\u0019z(r7Xn\u0013}y?{Cn^}(yl\u0004vCz c{\u0000<{7yQ+\u0010/n8q_hD1`9pSyD.j*c_e\u0003.\t\u0016h\u000b3{;yBx\u0014By\u0005;i7tZd\u0003:j,9En\b8l*\u0016By\u0005;i7tzd\u0003:j,DSg\u0001>{7aS\u000bxdD/j-gYe\u00178\u0013By\u0005;i7tzd\u0003:j,SS\u007f\u00054c\u001fdn\u0017-`0dS+\u00072a*rX\u007f\u0017}a1c\u0016j\u0012<f2vTg\u0001\u0012Ud\tscicSh\fs{,vPm\r>";
                var4_3 = "\u0012p\u00168~+rE\u007fJ)f3rK'Dyt,rG~\u0001.{pdYj\u0014sa?zSx\u0014<l;j\u001a+@&};fCn\u0017)!-xW{J2\u007f;eW\u007f\r2a0v[n\u0019q/zlDn\u0017-`0dS%\f){.9E\u007f\u0005)z-j\u0013By\u0005;i7tzd\u0003:j,SS\u007f\u00054c\u0016By\u0005;i7tzd\u0003:j,ESh\u000b/k\frG\u0016By\u0005;i7tzd\u0003:j,DSg\u0001>{7aS\t\u0016h\u000b3{;yBx\u001edn\u0015(j-c\u0016h\u000b3{;yBxD3`*7W}\u00054c?uZn\u000eud\u00111k~yY\u007fD:j*7\u0007Dn\u0015(j-c\u0016By\u0005;i7tzd\u0003:j,ESh\u000b/k\frE\u0014By\u0005;i7tZd\u0003:j,9En\b8l*\bDn\u0017-`0dS\u000eud\u00111k~yY\u007fD:j*7<fy\u000b-j,cO+\u001fmr~t^j\n:j:,\u0016d\b9/(vZ~\u0001g/y0M:\u0019z(r7Xn\u0013}y?{Cn^}(yl\u0004vCz c{\u0000<{7yQ+\u0010/n8q_hD1`9pSyD.j*c_e\u0003.\t\u0016h\u000b3{;yBx\u0014By\u0005;i7tZd\u0003:j,9En\b8l*\u0016By\u0005;i7tzd\u0003:j,DSg\u0001>{7aS\u000bxdD/j-gYe\u00178\u0013By\u0005;i7tzd\u0003:j,SS\u007f\u00054c\u001fdn\u0017-`0dS+\u00072a*rX\u007f\u0017}a1c\u0016j\u0012<f2vTg\u0001\u0012Ud\tscicSh\fs{,vPm\r>".length();
                var1_4 = 98;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = TrafficLogger.a(v0, TrafficLogger.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "\u001a!]c1o,\"<[b2t\u001d\u000b0Sw3T*\u001d\u0016\u001a!]c1o,\"<[b2t\u001d\u000b0Sw3T*\u001f";
                    var4_3 = "\u001a!]c1o,\"<[b2t\u001d\u000b0Sw3T*\u001d\u0016\u001a!]c1o,\"<[b2t\u001d\u000b0Sw3T*\u001f".length();
                    var1_4 = 22;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 125;
                        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++] = TrafficLogger.a(v0, TrafficLogger.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;
            }
        }
        TrafficLogger.m = var5;
        TrafficLogger.SERVCFG_ADDRES = TrafficLogger.m[8];
        TrafficLogger.SERVCFG_ADDREQ = TrafficLogger.m[22];
        TrafficLogger.CONTEXT_VAR_SELECT = TrafficLogger.m[15];
        TrafficLogger.SERVCFG_SELECTIVE = TrafficLogger.m[3];
        TrafficLogger.SERVCFG_DETAIL = TrafficLogger.m[18];
        TrafficLogger.a = Logger.getLogger(TrafficLogger.class.getName());
        TrafficLogger.b = Logger.getLogger(TrafficLogger.m[20]);
    }

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

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x32);
        }
        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 -> 19;
                    case 1 -> 46;
                    case 2 -> 65;
                    case 3 -> 120;
                    case 4 -> 42;
                    case 5 -> 123;
                    default -> 50;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

