// Path: src/com/zlab/datFM/swiftp/Defaults.java
// public class Defaults {
// 	protected static int inputBufferSize = 256;
// 	public static int dataChunkSize = 65536;  // do file I/O in 64k chunks
// 	protected static int sessionMonitorScrollBack = 10;
// 	protected static int serverLogScrollBack = 10;
// 	protected static int uiLogLevel = Defaults.release ? Log.INFO : Log.DEBUG;
// 	protected static int consoleLogLevel = Defaults.release ? Log.INFO : Log.DEBUG;
// 	protected static String settingsName = "SwiFTP";
// 	protected static String username = "ftp";
// 	protected static String password = "ftp";
// 	protected static int portNumber = 2121;
// //	protected static int ipRetrievalAttempts = 5;
// 	public static final int tcpConnectionBacklog = 5;
// 	public static final String chrootDir = "/";
// 	public static final boolean acceptWifi = true;
// 	public static final boolean acceptNet = false; // don't incur bandwidth charges
// 	public static final boolean stayAwake = true;
// 	public static final int REMOTE_PROXY_PORT = 2222;
// 	public static final String STRING_ENCODING = "UTF-8";
// 	public static final int SO_TIMEOUT_MS = 30000; // socket timeout millis
// 	// FTP control sessions should start out in ASCII, according to the RFC.
// 	// However, many clients don't turn on UTF-8 even though they support it,
// 	// so we just turn it on by default.
// 	public static final String SESSION_ENCODING = "UTF-8";
// 
// 	// This is a flag that should be true for public builds and false for dev builds
// 	public static final boolean release = true;
// 
// 	// Try to fix the transfer stall bug, reopen the destination file periodically
// 	//public static final boolean do_reopen_hack = false;
// 	//public static final int bytes_between_reopen = 4000000;
// 
// 	// Try to fix the transfer stall bug, flush the file periodically
// 	//public static final boolean do_flush_hack = false;
// 	//public static final int bytes_between_flush = 500000;
// 
// 	public static final boolean do_mediascanner_notify = true;
// 
// 
// //	public static int getIpRetrievalAttempts() {
// //		return ipRetrievalAttempts;
// //	}
// 
// //	public static void setIpRetrievalAttempts(int ipRetrievalAttempts) {
// //		Defaults.ipRetrievalAttempts = ipRetrievalAttempts;
// //	}
// 
// 	public static int getPortNumber() {
// 		return portNumber;
// 	}
// 
// 	public static void setPortNumber(int portNumber) {
// 		Defaults.portNumber = portNumber;
// 	}
// 
// 	public static String getSettingsName() {
// 		return settingsName;
// 	}
// 
// 	public static void setSettingsName(String settingsName) {
// 		Defaults.settingsName = settingsName;
// 	}
// 
// 	public static int getSettingsMode() {
// 		return settingsMode;
// 	}
// 
// 	public static void setSettingsMode(int settingsMode) {
// 		Defaults.settingsMode = settingsMode;
// 	}
// 
// 	public static void setServerLogScrollBack(int serverLogScrollBack) {
// 		Defaults.serverLogScrollBack = serverLogScrollBack;
// 	}
// 
// 	protected static int settingsMode = Context.MODE_WORLD_WRITEABLE;
// 
// 	public static int getUiLogLevel() {
// 		return uiLogLevel;
// 	}
// 
// 	public static void setUiLogLevel(int uiLogLevel) {
// 		Defaults.uiLogLevel = uiLogLevel;
// 	}
// 
// 	public static int getInputBufferSize() {
// 		return inputBufferSize;
// 	}
// 
// 	public static void setInputBufferSize(int inputBufferSize) {
// 		Defaults.inputBufferSize = inputBufferSize;
// 	}
// 
// 	public static int getDataChunkSize() {
// 		return dataChunkSize;
// 	}
// 
// 	public static void setDataChunkSize(int dataChunkSize) {
// 		Defaults.dataChunkSize = dataChunkSize;
// 	}
// 
// 	public static int getSessionMonitorScrollBack() {
// 		return sessionMonitorScrollBack;
// 	}
// 
// 	public static void setSessionMonitorScrollBack(
// 			int sessionMonitorScrollBack)
// 	{
// 		Defaults.sessionMonitorScrollBack = sessionMonitorScrollBack;
// 	}
// 
// 	public static int getServerLogScrollBack() {
// 		return serverLogScrollBack;
// 	}
// 
// 	public static void setLogScrollBack(int serverLogScrollBack) {
// 		Defaults.serverLogScrollBack = serverLogScrollBack;
// 	}
// 
// 	public static int getConsoleLogLevel() {
// 		return consoleLogLevel;
// 	}
// 
// 	public static void setConsoleLogLevel(int consoleLogLevel) {
// 		Defaults.consoleLogLevel = consoleLogLevel;
// 	}
// 
// 
// }


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import android.util.Log;
import com.zlab.datFM.swiftp.Defaults;
        Log.d(TAG, "RETR executing");
        String param = getParameter(input);
        File fileToRetr;
        String errString = null;

        mainblock: {
            fileToRetr = inputPathToChrootedFile(sessionThread.getWorkingDir(), param);
            if (violatesChroot(fileToRetr)) {
                errString = "550 Invalid name or chroot violation\r\n";
                break mainblock;
            } else if (fileToRetr.isDirectory()) {
                Log.d(TAG, "Ignoring RETR for directory");
                errString = "550 Can't RETR a directory\r\n";
                break mainblock;
            } else if (!fileToRetr.exists()) {
                Log.d(TAG, "Can't RETR nonexistent file: " + fileToRetr.getAbsolutePath());
                errString = "550 File does not exist\r\n";
                break mainblock;
            } else if (!fileToRetr.canRead()) {
                Log.i(TAG, "Failed RETR permission (canRead() is false)");
                errString = "550 No read permissions\r\n";
                break mainblock;
            } /*
               * else if(!sessionThread.isBinaryMode()) { myLog.l(Log.INFO,
               * "Failed RETR in text mode"); errString =
               * "550 Text mode RETR not supported\r\n"; break mainblock; }
               */
            FileInputStream in = null;
            try {
                in = new FileInputStream(fileToRetr);
// Path: src/com/zlab/datFM/swiftp/Defaults.java
// public class Defaults {
// 	protected static int inputBufferSize = 256;
// 	public static int dataChunkSize = 65536;  // do file I/O in 64k chunks
// 	protected static int sessionMonitorScrollBack = 10;
// 	protected static int serverLogScrollBack = 10;
// 	protected static int uiLogLevel = Defaults.release ? Log.INFO : Log.DEBUG;
// 	protected static int consoleLogLevel = Defaults.release ? Log.INFO : Log.DEBUG;
// 	protected static String settingsName = "SwiFTP";
// 	protected static String username = "ftp";
// 	protected static String password = "ftp";
// 	protected static int portNumber = 2121;
// //	protected static int ipRetrievalAttempts = 5;
// 	public static final int tcpConnectionBacklog = 5;
// 	public static final String chrootDir = "/";
// 	public static final boolean acceptWifi = true;
// 	public static final boolean acceptNet = false; // don't incur bandwidth charges
// 	public static final boolean stayAwake = true;
// 	public static final int REMOTE_PROXY_PORT = 2222;
// 	public static final String STRING_ENCODING = "UTF-8";
// 	public static final int SO_TIMEOUT_MS = 30000; // socket timeout millis
// 	// FTP control sessions should start out in ASCII, according to the RFC.
// 	// However, many clients don't turn on UTF-8 even though they support it,
// 	// so we just turn it on by default.
// 	public static final String SESSION_ENCODING = "UTF-8";
// 
// 	// This is a flag that should be true for public builds and false for dev builds
// 	public static final boolean release = true;
// 
// 	// Try to fix the transfer stall bug, reopen the destination file periodically
// 	//public static final boolean do_reopen_hack = false;
// 	//public static final int bytes_between_reopen = 4000000;
// 
// 	// Try to fix the transfer stall bug, flush the file periodically
// 	//public static final boolean do_flush_hack = false;
// 	//public static final int bytes_between_flush = 500000;
// 
// 	public static final boolean do_mediascanner_notify = true;
// 
// 
// //	public static int getIpRetrievalAttempts() {
// //		return ipRetrievalAttempts;
// //	}
// 
// //	public static void setIpRetrievalAttempts(int ipRetrievalAttempts) {
// //		Defaults.ipRetrievalAttempts = ipRetrievalAttempts;
// //	}
// 
// 	public static int getPortNumber() {
// 		return portNumber;
// 	}
// 
// 	public static void setPortNumber(int portNumber) {
// 		Defaults.portNumber = portNumber;
// 	}
// 
// 	public static String getSettingsName() {
// 		return settingsName;
// 	}
// 
// 	public static void setSettingsName(String settingsName) {
// 		Defaults.settingsName = settingsName;
// 	}
// 
// 	public static int getSettingsMode() {
// 		return settingsMode;
// 	}
// 
// 	public static void setSettingsMode(int settingsMode) {
// 		Defaults.settingsMode = settingsMode;
// 	}
// 
// 	public static void setServerLogScrollBack(int serverLogScrollBack) {
// 		Defaults.serverLogScrollBack = serverLogScrollBack;
// 	}
// 
// 	protected static int settingsMode = Context.MODE_WORLD_WRITEABLE;
// 
// 	public static int getUiLogLevel() {
// 		return uiLogLevel;
// 	}
// 
// 	public static void setUiLogLevel(int uiLogLevel) {
// 		Defaults.uiLogLevel = uiLogLevel;
// 	}
// 
// 	public static int getInputBufferSize() {
// 		return inputBufferSize;
// 	}
// 
// 	public static void setInputBufferSize(int inputBufferSize) {
// 		Defaults.inputBufferSize = inputBufferSize;
// 	}
// 
// 	public static int getDataChunkSize() {
// 		return dataChunkSize;
// 	}
// 
// 	public static void setDataChunkSize(int dataChunkSize) {
// 		Defaults.dataChunkSize = dataChunkSize;
// 	}
// 
// 	public static int getSessionMonitorScrollBack() {
// 		return sessionMonitorScrollBack;
// 	}
// 
// 	public static void setSessionMonitorScrollBack(
// 			int sessionMonitorScrollBack)
// 	{
// 		Defaults.sessionMonitorScrollBack = sessionMonitorScrollBack;
// 	}
// 
// 	public static int getServerLogScrollBack() {
// 		return serverLogScrollBack;
// 	}
// 
// 	public static void setLogScrollBack(int serverLogScrollBack) {
// 		Defaults.serverLogScrollBack = serverLogScrollBack;
// 	}
// 
// 	public static int getConsoleLogLevel() {
// 		return consoleLogLevel;
// 	}
// 
// 	public static void setConsoleLogLevel(int consoleLogLevel) {
// 		Defaults.consoleLogLevel = consoleLogLevel;
// 	}
// 
// 
// }


// Path: src/com/zlab/datFM/swiftp/server/CmdRETR.java
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import android.util.Log;
import com.zlab.datFM.swiftp.Defaults;

        Log.d(TAG, "RETR executing");
        String param = getParameter(input);
        File fileToRetr;
        String errString = null;

        mainblock: {
            fileToRetr = inputPathToChrootedFile(sessionThread.getWorkingDir(), param);
            if (violatesChroot(fileToRetr)) {
                errString = "550 Invalid name or chroot violation\r\n";
                break mainblock;
            } else if (fileToRetr.isDirectory()) {
                Log.d(TAG, "Ignoring RETR for directory");
                errString = "550 Can't RETR a directory\r\n";
                break mainblock;
            } else if (!fileToRetr.exists()) {
                Log.d(TAG, "Can't RETR nonexistent file: " + fileToRetr.getAbsolutePath());
                errString = "550 File does not exist\r\n";
                break mainblock;
            } else if (!fileToRetr.canRead()) {
                Log.i(TAG, "Failed RETR permission (canRead() is false)");
                errString = "550 No read permissions\r\n";
                break mainblock;
            } /*
               * else if(!sessionThread.isBinaryMode()) { myLog.l(Log.INFO,
               * "Failed RETR in text mode"); errString =
               * "550 Text mode RETR not supported\r\n"; break mainblock; }
               */
            FileInputStream in = null;
            try {
                in = new FileInputStream(fileToRetr);
                byte[] buffer = new byte[Defaults.getDataChunkSize()];