/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.mime.ContentTypeHeader
 *  com.l7tech.gateway.common.transport.SsgConnector
 *  com.l7tech.objectmodel.EntityType
 *  com.l7tech.objectmodel.Goid
 *  org.apache.ftpserver.ConnectionConfig
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.l7tech.server.transport.ftp;

import com.l7tech.common.mime.ContentTypeHeader;
import com.l7tech.gateway.common.transport.SsgConnector;
import com.l7tech.objectmodel.EntityType;
import com.l7tech.objectmodel.Goid;
import com.l7tech.server.MessageProcessor;
import com.l7tech.server.StashManagerFactory;
import com.l7tech.server.transport.ListenerException;
import com.l7tech.server.transport.ftp.ExtendedCommandsFtpRequestProcessor;
import com.l7tech.server.transport.ftp.FtpRequestProcessor;
import com.l7tech.server.transport.ftp.UploadOnlyFtpRequestProcessor;
import com.l7tech.server.util.EventChannel;
import com.l7tech.server.util.SoapFaultManager;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.apache.ftpserver.ConnectionConfig;
import org.springframework.beans.factory.annotation.Autowired;

public class FtpRequestProcessorFactory {
    @Autowired
    private MessageProcessor a;
    @Autowired
    private SoapFaultManager b;
    @Autowired
    private StashManagerFactory c;
    @Autowired
    private EventChannel d;
    private static final String[] e;

    /*
     * Loose catch block
     */
    public FtpRequestProcessor create(SsgConnector ssgConnector, ConnectionConfig connectionConfig) throws ListenerException {
        Goid goid;
        boolean bl2;
        block10: {
            bl2 = ssgConnector.getBooleanProperty(SsgConnector.PROP_SUPPORT_EXTENDED_FTP_COMMANDS);
            goid = ssgConnector.getGoidProperty(EntityType.SERVICE, SsgConnector.PROP_HARDWIRED_SERVICE_ID, null);
            if (null != goid) break block10;
            try {
                block11: {
                    if (!bl2) break block10;
                    break block11;
                    catch (IOException iOException) {
                        throw FtpRequestProcessorFactory.a(iOException);
                    }
                }
                throw new ListenerException(e[1]);
            }
            catch (IOException iOException) {
                throw FtpRequestProcessorFactory.a(iOException);
            }
        }
        String string = ssgConnector.getProperty(SsgConnector.PROP_OVERRIDE_CONTENT_TYPE);
        ContentTypeHeader contentTypeHeader = null;
        try {
            if (string != null) {
                contentTypeHeader = ContentTypeHeader.parseValue((String)string);
            }
        }
        catch (IOException iOException) {
            String[] stringArray = e;
            throw new ListenerException(stringArray[0] + string + stringArray[2]);
        }
        ExecutorService executorService = this.a(connectionConfig);
        long l2 = ssgConnector.getLongProperty(SsgConnector.PROP_REQUEST_SIZE_LIMIT, -1L);
        try {
            if (bl2) {
                return new ExtendedCommandsFtpRequestProcessor(this.a, this.b, this.c, this.d, executorService, contentTypeHeader, goid, ssgConnector, l2);
            }
        }
        catch (IOException iOException) {
            throw FtpRequestProcessorFactory.a(iOException);
        }
        return new UploadOnlyFtpRequestProcessor(this.a, this.b, this.c, this.d, executorService, contentTypeHeader, goid, ssgConnector, l2);
    }

    private ExecutorService a(ConnectionConfig connectionConfig) {
        int n2 = connectionConfig.getMaxThreads();
        return new ThreadPoolExecutor(1, n2, 300L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(n2), new ThreadPoolExecutor.AbortPolicy());
    }

    private static IOException a(IOException iOException) {
        return iOException;
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[3];
        int n2 = 0;
        String string = "q >\u0000!#.P!\u007f\u00119'|Pn\u00196\u001dfbM=+\u0007##|\u001en6\f;'bM*\u007f\r;#|V';\u0006((.G!1\u0016((z\u0004:&\u0012(f)@q >\u0000!#.P!\u007f\u00119'|Pn\u00196\u001dfbM=+\u0007##|\u001en1\rm5kV86\u0001(f}T+<\u000b+/k@n9\r?fbM=+\u0007##|\n\u0002\u0003`";
        int n3 = "q >\u0000!#.P!\u007f\u00119'|Pn\u00196\u001dfbM=+\u0007##|\u001en6\f;'bM*\u007f\r;#|V';\u0006((.G!1\u0016((z\u0004:&\u0012(f)@q >\u0000!#.P!\u007f\u00119'|Pn\u00196\u001dfbM=+\u0007##|\u001en1\rm5kV86\u0001(f}T+<\u000b+/k@n9\r?fbM=+\u0007##|\n\u0002\u0003`".length();
        int n4 = 63;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = FtpRequestProcessorFactory.a(115, FtpRequestProcessorFactory.a(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                e = stringArray;
                return;
            }
            n4 = string.charAt(n5);
        }
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x7D);
        }
        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 -> 87;
                    case 1 -> 61;
                    case 2 -> 44;
                    case 3 -> 17;
                    case 4 -> 62;
                    case 5 -> 53;
                    default -> 125;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

