/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.http.GenericHttpClientFactory
 *  com.l7tech.common.http.GenericHttpHeader
 *  com.l7tech.common.http.GenericHttpRequest
 *  com.l7tech.common.http.GenericHttpRequestParams
 *  com.l7tech.common.http.GenericHttpResponse
 *  com.l7tech.common.http.HttpConstants
 *  com.l7tech.common.http.HttpHeader
 *  com.l7tech.common.http.HttpHeaders
 *  com.l7tech.common.http.HttpMethod
 *  com.l7tech.util.ConfigFactory
 *  org.apache.commons.collections.map.LRUMap
 */
package com.l7tech.server.url;

import com.l7tech.common.http.GenericHttpClientFactory;
import com.l7tech.common.http.GenericHttpHeader;
import com.l7tech.common.http.GenericHttpRequest;
import com.l7tech.common.http.GenericHttpRequestParams;
import com.l7tech.common.http.GenericHttpResponse;
import com.l7tech.common.http.HttpConstants;
import com.l7tech.common.http.HttpHeader;
import com.l7tech.common.http.HttpHeaders;
import com.l7tech.common.http.HttpMethod;
import com.l7tech.server.url.AbstractUrlObjectCache;
import com.l7tech.server.url.b;
import com.l7tech.util.ConfigFactory;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.collections.map.LRUMap;

public class HttpObjectCache<UT>
extends AbstractUrlObjectCache<UT> {
    public static final int DEFAULT_DOWNLOAD_LIMIT = 0xA00000;
    private static final Logger c;
    private static final String d;
    private static final String e;
    private static final boolean f;
    private static final boolean g;
    protected final GenericHttpClientFactory httpClientFactory;
    protected final AbstractUrlObjectCache.UserObjectFactory<UT> userObjectFactory;
    protected final LRUMap cache;
    private final String h;
    private final int i;
    private final Lock j;
    private static final String[] l;

    public HttpObjectCache(String string, int n2, long l2, long l3, GenericHttpClientFactory genericHttpClientFactory, AbstractUrlObjectCache.UserObjectFactory<UT> userObjectFactory, AbstractUrlObjectCache.WaitMode waitMode, String string2) {
        this(string, n2, l2, l3, genericHttpClientFactory, userObjectFactory, waitMode, string2, 0xA00000);
    }

    public HttpObjectCache(String string, int n2, long l2, long l3, GenericHttpClientFactory genericHttpClientFactory, AbstractUrlObjectCache.UserObjectFactory<UT> userObjectFactory, AbstractUrlObjectCache.WaitMode waitMode, String string2, int n3) {
        block4: {
            super(string, l2, l3, waitMode);
            this.j = new ReentrantLock();
            this.httpClientFactory = genericHttpClientFactory;
            this.userObjectFactory = userObjectFactory;
            try {
                try {
                    this.cache = n2 <= 0 ? null : new LRUMap(n2);
                    this.h = string2;
                    this.i = n3;
                    if (genericHttpClientFactory != null && userObjectFactory != null) break block4;
                }
                catch (NullPointerException nullPointerException) {
                    throw HttpObjectCache.b(nullPointerException);
                }
                throw new NullPointerException();
            }
            catch (NullPointerException nullPointerException) {
                throw HttpObjectCache.b(nullPointerException);
            }
        }
    }

    @Override
    protected Lock getReadLock() {
        return this.j;
    }

    @Override
    protected Lock getWriteLock() {
        return this.j;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    @Override
    protected AbstractUrlObjectCache.AbstractCacheEntry<UT> cacheGet(String string) {
        if (this.cache != null) {
            LRUMap lRUMap = this.cache;
            synchronized (lRUMap) {
                return (AbstractUrlObjectCache.AbstractCacheEntry)this.cache.get((Object)string);
            }
        }
        return null;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    @Override
    protected void cachePut(String string, AbstractUrlObjectCache.AbstractCacheEntry<UT> abstractCacheEntry) {
        if (this.cache != null) {
            LRUMap lRUMap = this.cache;
            synchronized (lRUMap) {
                this.cache.put((Object)string, abstractCacheEntry);
            }
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    @Override
    protected AbstractUrlObjectCache.AbstractCacheEntry<UT> cacheRemove(String string) {
        if (this.cache != null) {
            LRUMap lRUMap = this.cache;
            synchronized (lRUMap) {
                return (AbstractUrlObjectCache.AbstractCacheEntry)this.cache.remove((Object)string);
            }
        }
        return null;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    @Override
    protected Iterator<AbstractUrlObjectCache.AbstractCacheEntry<UT>> cacheIterator() {
        if (this.cache != null) {
            LRUMap lRUMap = this.cache;
            synchronized (lRUMap) {
                return new ArrayList(this.cache.values()).iterator();
            }
        }
        return null;
    }

    /*
     * Loose catch block
     */
    @Override
    protected AbstractUrlObjectCache.DatedUserObject<UT> doGet(String string, String string2, long l2, String string3) throws IOException {
        block44: {
            UT UT;
            String string4;
            String string5;
            GenericHttpResponse genericHttpResponse;
            GenericHttpRequest genericHttpRequest;
            block45: {
                GenericHttpRequestParams genericHttpRequestParams;
                block42: {
                    AbstractUrlObjectCache.DatedUserObject<Object> datedUserObject;
                    genericHttpRequest = null;
                    genericHttpResponse = null;
                    try {
                        String string6;
                        Object UT2;
                        AbstractUrlObjectCache.DatedUserObject<Object> datedUserObject2;
                        AbstractUrlObjectCache.DatedUserObject<Object> datedUserObject3;
                        block43: {
                            block41: {
                                Object object;
                                block39: {
                                    block46: {
                                        block40: {
                                            genericHttpRequestParams = new GenericHttpRequestParams(new URL(string));
                                            try {
                                                if (!f) break block39;
                                                if (string2 == null) break block40;
                                            }
                                            catch (IOException iOException) {
                                                throw HttpObjectCache.b(iOException);
                                            }
                                            object = new GenericHttpHeader(HttpConstants.HEADER_IF_MODIFIED_SINCE, string2);
                                            break block46;
                                        }
                                        object = l2 > 0L ? GenericHttpHeader.makeDateHeader((String)HttpConstants.HEADER_IF_MODIFIED_SINCE, (Date)new Date(l2)) : null;
                                    }
                                    try {
                                        if (object != null) {
                                            genericHttpRequestParams.replaceExtraHeader((HttpHeader)object);
                                        }
                                    }
                                    catch (IOException iOException) {
                                        throw HttpObjectCache.b(iOException);
                                    }
                                }
                                try {
                                    if (!g || string3 == null) break block41;
                                }
                                catch (IOException iOException) {
                                    throw HttpObjectCache.b(iOException);
                                }
                                object = new GenericHttpHeader(HttpConstants.HEADER_IF_NONE_MATCH, string3);
                                genericHttpRequestParams.replaceExtraHeader((HttpHeader)object);
                            }
                            genericHttpRequest = this.httpClientFactory.createHttpClient().createRequest(HttpMethod.GET, genericHttpRequestParams);
                            genericHttpResponse = genericHttpRequest.getResponse();
                            int n2 = genericHttpResponse.getStatus();
                            c.log(Level.FINER, () -> {
                                String[] stringArray = l;
                                return stringArray[2] + string + stringArray[4] + n2;
                            });
                            HttpHeaders httpHeaders = genericHttpResponse.getHeaders();
                            string5 = httpHeaders.getFirstValue(HttpConstants.HEADER_LAST_MODIFIED);
                            string4 = httpHeaders.getFirstValue(HttpConstants.HEADER_ETAG);
                            if (n2 != 304) break block42;
                            try {
                                block47: {
                                    if (!c.isLoggable(Level.FINER)) break block43;
                                    break block47;
                                    catch (IOException iOException) {
                                        throw HttpObjectCache.b(iOException);
                                    }
                                }
                                c.finer(l[6] + string + "'");
                            }
                            catch (IOException iOException) {
                                throw HttpObjectCache.b(iOException);
                            }
                        }
                        try {
                            AbstractUrlObjectCache.DatedUserObject<Object> datedUserObject4;
                            datedUserObject3 = datedUserObject4;
                            datedUserObject2 = datedUserObject4;
                            UT2 = null;
                            string6 = string5 != null ? string5 : string2;
                        }
                        catch (IOException iOException) {
                            throw HttpObjectCache.b(iOException);
                        }
                        datedUserObject3(UT2, string6, string4);
                        datedUserObject = datedUserObject2;
                    }
                    catch (Throwable throwable) {
                        try {
                            if (genericHttpResponse != null) {
                                genericHttpResponse.close();
                            }
                        }
                        catch (IOException iOException) {
                            throw HttpObjectCache.b(iOException);
                        }
                        try {
                            if (genericHttpRequest != null) {
                                genericHttpRequest.close();
                            }
                        }
                        catch (IOException iOException) {
                            throw HttpObjectCache.b(iOException);
                        }
                        throw throwable;
                    }
                    try {
                        if (genericHttpResponse != null) {
                            genericHttpResponse.close();
                        }
                    }
                    catch (IOException iOException) {
                        throw HttpObjectCache.b(iOException);
                    }
                    try {
                        if (genericHttpRequest != null) {
                            genericHttpRequest.close();
                        }
                    }
                    catch (IOException iOException) {
                        throw HttpObjectCache.b(iOException);
                    }
                    return datedUserObject;
                }
                GenericHttpResponse genericHttpResponse2 = genericHttpResponse;
                int n3 = ConfigFactory.getIntProperty((String)this.h, (int)this.i);
                UT = this.userObjectFactory.createUserObject(genericHttpRequestParams.getTargetUrl().toExternalForm(), new b(this, genericHttpResponse2, n3));
                if (UT == null) break block44;
                try {
                    block48: {
                        if (!c.isLoggable(Level.FINER)) break block45;
                        break block48;
                        catch (IOException iOException) {
                            throw HttpObjectCache.b(iOException);
                        }
                    }
                    c.finer(l[3] + string + "'");
                }
                catch (IOException iOException) {
                    throw HttpObjectCache.b(iOException);
                }
            }
            AbstractUrlObjectCache.DatedUserObject<UT> datedUserObject = new AbstractUrlObjectCache.DatedUserObject<UT>(UT, string5, string4);
            try {
                if (genericHttpResponse != null) {
                    genericHttpResponse.close();
                }
            }
            catch (IOException iOException) {
                throw HttpObjectCache.b(iOException);
            }
            try {
                if (genericHttpRequest != null) {
                    genericHttpRequest.close();
                }
            }
            catch (IOException iOException) {
                throw HttpObjectCache.b(iOException);
            }
            return datedUserObject;
        }
        throw new IOException(l[1]);
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[9];
                var3_1 = 0;
                var2_2 = "5\u0017&0~pP3\u001b#0a\"V \u001d90g5Hx\u0010?jb\u0004E5\u0010.[|&F:\u001d\u000eJs !\u0004\u001d8n})W3X%qfgE5\u001b.nf\"@v\u001e$l2$E5\u0010\"pu\u001e\u0004\u001d8n})W3X8js3Q%X(qv\"\u00040\u00179>G\u0015hv_ \u0012\u0017<p~(E2\u001d/>|\"Sv\u0017)tw$Pv\u001e9q\u007fgq\u00044k9\u0004qXq>15\u0017&0~pP3\u001b#0a\"V \u001d90g5Hx\u0010?jb\u0004E5\u0010.[|&F:\u001d\u0007\u007fa3i9\u001c\"x{\"@\"\u0005\u001d9hw5\u0004$\u001d;q`3Wv\u0016$>q/E8\u001f.>t(Vv-\u0019R2`";
                var4_3 = "5\u0017&0~pP3\u001b#0a\"V \u001d90g5Hx\u0010?jb\u0004E5\u0010.[|&F:\u001d\u000eJs !\u0004\u001d8n})W3X%qfgE5\u001b.nf\"@v\u001e$l2$E5\u0010\"pu\u001e\u0004\u001d8n})W3X8js3Q%X(qv\"\u00040\u00179>G\u0015hv_ \u0012\u0017<p~(E2\u001d/>|\"Sv\u0017)tw$Pv\u001e9q\u007fgq\u00044k9\u0004qXq>15\u0017&0~pP3\u001b#0a\"V \u001d90g5Hx\u0010?jb\u0004E5\u0010.[|&F:\u001d\u0007\u007fa3i9\u001c\"x{\"@\"\u0005\u001d9hw5\u0004$\u001d;q`3Wv\u0016$>q/E8\u001f.>t(Vv-\u0019R2`".length();
                var1_4 = 41;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = HttpObjectCache.b(v0, HttpObjectCache.b(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "+\t8.`nN-\u0005=.\u007f<H>\u0003'.y+Vf\u000e!t|\u001a[+\u000e0Eb8X$\u0003\u0010Tm>1+\t8.`nN-\u0005=.\u007f<H>\u0003'.y+Vf\u000e!t|\u001a[+\u000e0Eb8X$\u0003\u0019a\u007f-w'\u0002<fe<^";
                    var4_3 = "+\t8.`nN-\u0005=.\u007f<H>\u0003'.y+Vf\u000e!t|\u001a[+\u000e0Eb8X$\u0003\u0010Tm>1+\t8.`nN-\u0005=.\u007f<H>\u0003'.y+Vf\u000e!t|\u001a[+\u000e0Eb8X$\u0003\u0019a\u007f-w'\u0002<fe<^".length();
                    var1_4 = 41;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 45;
                        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++] = HttpObjectCache.b(v0, HttpObjectCache.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;
            }
        }
        HttpObjectCache.l = var5;
        HttpObjectCache.d = HttpObjectCache.l[5];
        HttpObjectCache.e = HttpObjectCache.l[7];
        HttpObjectCache.c = Logger.getLogger(HttpObjectCache.class.getName());
        var0_6 = HttpObjectCache.l;
        HttpObjectCache.f = ConfigFactory.getBooleanProperty((String)var0_6[8], (boolean)true);
        HttpObjectCache.g = ConfigFactory.getBooleanProperty((String)var0_6[0], (boolean)true);
    }

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

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

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String b(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 -> 101;
                    case 1 -> 75;
                    case 2 -> 120;
                    case 3 -> 45;
                    case 4 -> 33;
                    case 5 -> 116;
                    default -> 23;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

