incubator-ftpserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r609446 [1/5] - in /incubator/ftpserver/trunk: core/ core/src/main/java/org/apache/ftpserver/ core/src/main/java/org/apache/ftpserver/command/ core/src/main/java/org/apache/ftpserver/ftplet/ core/src/main/java/org/apache/ftpserver/interface...
Date Sun, 06 Jan 2008 22:24:34 GMT
Author: ngn
Date: Sun Jan  6 14:24:29 2008
New Revision: 609446

URL: http://svn.apache.org/viewvc?rev=609446&view=rev
Log:
A very crude refactoring into MINA 2.0 and a pure-MINA design. Still lots of work to do but now it compiles and passes some of the tests.

Added:
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpHandler.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/interfaces/FtpIoSession.java
    incubator/ftpserver/trunk/core/src/test/resources/client.jks
      - copied unchanged from r607121, incubator/ftpserver/trunk/core/src/test/java/client.jks
    incubator/ftpserver/trunk/core/src/test/resources/ftpserver.jks
      - copied unchanged from r607121, incubator/ftpserver/trunk/core/src/test/java/ftpserver.jks
Removed:
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpWriter.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/FtpProtocolHandler.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/io/
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/mina/MinaConnection.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/mina/MinaFtpProtocolHandler.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/mina/MinaFtpResponseOutput.java
    incubator/ftpserver/trunk/core/src/test/java/client.jks
    incubator/ftpserver/trunk/core/src/test/java/ftpserver.jks
    incubator/ftpserver/trunk/core/src/test/java/log4j.properties
    incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/ssl/IOCipherSuitesTest.java
    incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/ssl/IOClientAuthTest.java
    incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/ssl/IOExplicitSSLTest.java
    incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/ssl/IOExplicitTLSTest.java
    incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/ssl/IOImplicitClientAuthTest.java
    incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/ssl/IOImplicitSSLTest.java
    incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/ssl/IOImplicitTLSTest.java
    incubator/ftpserver/trunk/core/src/test/java/users.gen
    incubator/ftpserver/trunk/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/FtpReplyOutput.java
Modified:
    incubator/ftpserver/trunk/core/pom.xml
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpServer.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpSessionImpl.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpStatisticsImpl.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/IODataConnection.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/IODataConnectionFactory.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/PassivePorts.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/ABOR.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/ACCT.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/APPE.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/AUTH.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/CDUP.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/CWD.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/DELE.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/EPRT.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/EPSV.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/FEAT.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/HELP.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/LANG.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/LIST.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/MD5.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/MDTM.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/MKD.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/MLSD.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/MLST.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/MODE.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/NLST.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/NOOP.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/OPTS.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/OPTS_MLST.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/OPTS_UTF8.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/PASS.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/PASV.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/PBSZ.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/PORT.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/PROT.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/PWD.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/QUIT.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/REIN.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/REST.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/RETR.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/RMD.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/RNFR.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/RNTO.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SITE.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SITE_DESCUSER.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SITE_HELP.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SITE_STAT.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SITE_WHO.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SITE_ZONE.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SIZE.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/STAT.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/STOR.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/STOU.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/STRU.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SYST.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/TYPE.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/USER.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ftplet/DefaultFtpletContainer.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ftplet/IsolatingFtpSession.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/interfaces/Command.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/interfaces/FileObserver.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/interfaces/ServerFtpStatistics.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/AbstractConnection.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/ConnectionManagerImpl.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/mina/FtpResponseEncoder.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/mina/FtpServerProtocolCodecFactory.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/mina/MinaListener.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/util/FtpReplyUtil.java
    incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/util/IoUtils.java
    incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/ConfigurableFtpServerContextTest.java
    incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/ClientTestTemplate.java
    incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/HelpTest.java
    incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/ftplet/FtpLetContainerTestTemplate.java
    incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/ftplet/FtpLetReturnDefaultTest.java
    incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/ftplet/FtpLetReturnDisconnectTest.java
    incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/ftplet/FtpLetReturnSkipTest.java
    incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/ftplet/MockFtplet.java
    incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/ftplet/MockFtpletCallback.java
    incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/interfaces/ServerFtpStatisticsTestTemplate.java
    incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/ssl/SSLTestTemplate.java
    incubator/ftpserver/trunk/core/src/test/resources/users.gen
    incubator/ftpserver/trunk/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/DataConnection.java
    incubator/ftpserver/trunk/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/DefaultFtplet.java
    incubator/ftpserver/trunk/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/FtpSession.java
    incubator/ftpserver/trunk/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/Ftplet.java

Modified: incubator/ftpserver/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/pom.xml?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/pom.xml (original)
+++ incubator/ftpserver/trunk/core/pom.xml Sun Jan  6 14:24:29 2008
@@ -48,11 +48,8 @@
       <artifactId>mina-core</artifactId>
       <version>${mina-version}</version>
     </dependency>
-    <dependency>
-      <groupId>org.apache.mina</groupId>
-      <artifactId>mina-filter-ssl</artifactId>
-      <version>${mina-version}</version>
-    </dependency>
+
+    <!-- Test dependencies -->
     <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-log4j12</artifactId>
@@ -78,7 +75,6 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-      <!-- Currently has to built from source as no up-to-date binary is available -->
       <groupId>commons-net</groupId>
       <artifactId>commons-net</artifactId>
       <version>2.0.0-SNAPSHOT</version>

Added: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpHandler.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpHandler.java?rev=609446&view=auto
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpHandler.java (added)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpHandler.java Sun Jan  6 14:24:29 2008
@@ -0,0 +1,109 @@
+package org.apache.ftpserver;
+
+import java.io.IOException;
+
+import org.apache.ftpserver.ftplet.FtpReply;
+import org.apache.ftpserver.ftplet.FtpRequest;
+import org.apache.ftpserver.interfaces.Command;
+import org.apache.ftpserver.interfaces.CommandFactory;
+import org.apache.ftpserver.interfaces.FtpIoSession;
+import org.apache.ftpserver.interfaces.FtpServerContext;
+import org.apache.ftpserver.interfaces.ServerFtpStatistics;
+import org.apache.ftpserver.listener.Listener;
+import org.apache.ftpserver.util.FtpReplyUtil;
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class FtpHandler extends IoHandlerAdapter
+{
+	
+	
+	
+	private final Logger LOG = LoggerFactory.getLogger(FtpHandler.class);
+	
+	private FtpServerContext context;
+	private Listener listener;
+	
+	
+    public FtpHandler(FtpServerContext context, Listener listener) {
+		this.context = context;
+		this.listener = listener;
+	}
+
+	public void sessionCreated(IoSession session) throws Exception {
+    	FtpIoSession ftpSession = new FtpIoSession(session, context);
+    	ftpSession.setListener(listener);
+    }
+
+    public void sessionOpened(IoSession session) throws Exception {
+    	FtpIoSession ftpSession = new FtpIoSession(session, context);
+    	
+    	session.write(FtpReplyUtil.translate(ftpSession,  null, context, FtpReply.REPLY_220_SERVICE_READY, null, null));
+    }
+
+    public void sessionClosed(IoSession session) throws Exception {
+    	FtpIoSession ftpSession = new FtpIoSession(session, context);
+    	
+    	ServerFtpStatistics stats = ((ServerFtpStatistics)context.getFtpStatistics());
+    	
+    	if(stats != null) {
+    		stats.setLogout(ftpSession);
+    	}
+    }
+
+	
+    @Override
+    public void exceptionCaught( IoSession session, Throwable cause ) throws Exception
+    {
+        cause.printStackTrace();
+        session.closeOnFlush();
+    }
+
+    @Override
+    public void messageReceived( IoSession session, Object message ) throws Exception
+    {
+    	FtpRequest request = new FtpRequestImpl(message.toString());
+
+    	FtpIoSession ftpSession = new FtpIoSession(session, context);
+    	
+        try {
+            String commandName = request.getCommand();
+            CommandFactory commandFactory = context.getCommandFactory();
+            Command command = commandFactory.getCommand(commandName);
+            
+            
+            if(command != null) {
+                command.execute(ftpSession, context, request);
+            }
+            else {
+                session.write(FtpReplyUtil.translate(ftpSession, request, context, FtpReply.REPLY_502_COMMAND_NOT_IMPLEMENTED, "not.implemented", null));
+            }
+        }
+        catch(Exception ex) {
+            
+            // send error reply
+            try { 
+                session.write(FtpReplyUtil.translate(ftpSession, request, context, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, null, null));
+            }
+            catch(Exception ex1) {
+            }
+            
+            if (ex instanceof java.io.IOException) {
+               throw (IOException)ex;
+            }
+            else {
+                LOG.warn("RequestHandler.service()", ex);
+            }
+        }
+
+    }
+
+    @Override
+    public void sessionIdle( IoSession session, IdleStatus status ) throws Exception
+    {
+        session.closeOnFlush();
+    }
+}
\ No newline at end of file

Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpServer.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpServer.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpServer.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpServer.java Sun Jan  6 14:24:29 2008
@@ -68,8 +68,7 @@
 
         started = true;
         
-        System.out.println("Server ready :: Apache FTP Server");
-        LOG.info("------- Apache FTP Server started ------");
+        LOG.info("FTP server started");
 
     }
     

Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpSessionImpl.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpSessionImpl.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpSessionImpl.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpSessionImpl.java Sun Jan  6 14:24:29 2008
@@ -20,257 +20,121 @@
 package org.apache.ftpserver;
 
 import java.net.InetAddress;
+import java.net.InetSocketAddress;
 import java.security.cert.Certificate;
 import java.util.Date;
-import java.util.HashMap;
 
+import org.apache.ftpserver.ftplet.DataConnectionFactory;
 import org.apache.ftpserver.ftplet.DataType;
 import org.apache.ftpserver.ftplet.FileObject;
 import org.apache.ftpserver.ftplet.FileSystemView;
-import org.apache.ftpserver.ftplet.DataConnectionFactory;
-import org.apache.ftpserver.ftplet.FtpRequest;
+import org.apache.ftpserver.ftplet.FtpSession;
 import org.apache.ftpserver.ftplet.Structure;
 import org.apache.ftpserver.ftplet.User;
-import org.apache.ftpserver.interfaces.FtpServerContext;
-import org.apache.ftpserver.interfaces.FtpServerSession;
-import org.apache.ftpserver.listener.Listener;
+import org.apache.ftpserver.interfaces.FtpIoSession;
 
 /**
  * FTP session
  */
-public class FtpSessionImpl implements FtpServerSession {
-
-    
-    /**
-     * Contains user name between USER and PASS commands
-     */
-    private String userArgument;
-    private User user;
-    private HashMap attributeMap;
-    private InetAddress remoteAddr;
-    private InetAddress serverAddr;
-    private int serverPort;
-    private String language;
-    private Certificate[] clientCertificates;
-    
-    private int maxIdleTime = 0;
-    private long connectionTime = 0L;
-    private long loginTime = 0L;
-    private long lastAccessTime = 0L;
-    
-    private IODataConnectionFactory dataConnection;
-    private FileSystemView fileSystemView;
-    
-    private FileObject renameFrom;
-    private long fileOffset;
-    private FtpRequest request;
-    
-    private DataType dataType    = DataType.ASCII;
-    private Structure structure  = Structure.FILE;
-    private FtpServerContext serverContext;
-    private Listener listener;
-    private int failedLogins;
-    
-    public Listener getListener() {
-        return listener;
-    }
-
-    public void setListener(Listener listener) {
-        this.listener = listener;
-    }
+public class FtpSessionImpl implements FtpSession {
 
+	private FtpIoSession ioSession;
+	
     /**
      * Default constructor.
      */
-    public FtpSessionImpl(FtpServerContext serverContext) {
-        this.serverContext = serverContext;
-        attributeMap = new HashMap();
-        userArgument = null;
-        user = null;
-        connectionTime = System.currentTimeMillis();
+    public FtpSessionImpl(FtpIoSession ioSession) {
+        this.ioSession = ioSession;
     } 
     
     /**
-     * Set client address.
-     */
-    public void setClientAddress(InetAddress addr) {
-        remoteAddr = addr;
-    }
-
-    /**
-     * Set FTP data connection.
-     */
-    public void setFtpDataConnection(IODataConnectionFactory dataCon) {
-        dataConnection = dataCon;
-    }
-    
-    /**
-     * Reset temporary state variables.
-     */
-    public void resetState() {
-        renameFrom = null;
-        fileOffset = 0L;
-    }
-    
-    /**
-     * Reinitialize request.
-     */
-    public void reinitialize() {
-        userArgument = null;
-        user = null;
-        loginTime = 0L;
-        fileSystemView = null;
-        renameFrom = null;
-        fileOffset = 0L;
-    }
-
-    
-    /**
-     * Set login attribute & user file system view.
-     */
-    public void setLogin(FileSystemView userFsView) {
-        loginTime = System.currentTimeMillis();
-        fileSystemView = userFsView;
-    }
-    
-    /**
-     * Set logout.
-     */
-    public void setLogout() {
-        loginTime = 0L;
-    }
-    
-    /**
-     * Update last access time.
-     */
-    public void updateLastAccessTime() {
-        lastAccessTime = System.currentTimeMillis();
-    }
-    
-    /**
      * Is logged-in
      */
     public boolean isLoggedIn() {
-        return (loginTime != 0L);
+        return ioSession.isLoggedIn();
     }
     
     /**
      * Get FTP data connection.
      */
     public DataConnectionFactory getDataConnection() {
-        return dataConnection;
+        return ioSession.getDataConnection();
     }
 
     /**
-     * Get FTP data connection.
-     */
-    public ServerDataConnectionFactory getServerDataConnection() {
-        return dataConnection;
-    }
-    
-    /**
      * Get file system view.
      */
     public FileSystemView getFileSystemView() {
-        return fileSystemView;
+        return ioSession.getFileSystemView();
     }
     
     /**
      * Get connection time.
      */
     public Date getConnectionTime() {
-        return new Date(connectionTime);
+        return new Date(ioSession.getCreationTime());
     }
     
     /**
      * Get the login time.
      */
     public Date getLoginTime() {
-        return new Date(loginTime);
+        return ioSession.getLoginTime();
     }
     
     /**
      * Get last access time.
      */
     public Date getLastAccessTime() {
-        return new Date(lastAccessTime);
+        return ioSession.getLastAccessTime();
     }
     
     /**
      * Get file offset.
      */
     public long getFileOffset() {
-        return fileOffset;
-    }
-    
-    /**
-     * Set the file offset.
-     */
-    public void setFileOffset(long offset) {
-        fileOffset = offset;
+        return ioSession.getFileOffset();
     }
     
     /**
      * Get rename from file object.
      */
     public FileObject getRenameFrom() {
-        return renameFrom;
+        return ioSession.getRenameFrom();
     }
     
     /**
-     * Set rename from.
-     */
-    public void setRenameFrom(FileObject file) {
-        renameFrom = file;
-    }
-
-    /**
      * Returns user name entered in USER command
      * 
      * @return user name entered in USER command
      */
     public String getUserArgument() {
-        return userArgument;
-    }
-
-    /**
-     * Set user name entered from USER command
-     */
-    public void setUserArgument(String tmpUserName) {
-        this.userArgument = tmpUserName;
+        return ioSession.getUserArgument();
     }
 
-    
     /**
      * Get language.
      */
     public String getLanguage() {
-        return language;
-    }
-    
-    /**
-     * Set language.
-     */
-    public void setLanguage(String language) {
-        this.language = language;
+        return ioSession.getLanguage();
     }
     
     /**
      * Get user.
      */
     public User getUser() {
-        return user;
-    }
-    
-    public void setUser(User user) {
-	this.user = user;
+        return ioSession.getUser();
     }
     
     /**
      * Get remote address
      */
     public InetAddress getClientAddress() {
-        return remoteAddr;
+        if(ioSession.getRemoteAddress() instanceof InetSocketAddress) {
+        	return ((InetSocketAddress)ioSession.getRemoteAddress()).getAddress();
+        } else {
+        	return null;
+        }
     }
     
 
@@ -279,130 +143,75 @@
      * Get attribute
      */
     public Object getAttribute(String name) {
-        return attributeMap.get(name);
+    	if(name.startsWith(FtpIoSession.ATTRIBUTE_PREFIX)) {
+    		throw new IllegalArgumentException("Illegal lookup of internal attribute");
+    	}
+    	
+        return ioSession.getAttribute(name);
     }
     
     /**
      * Set attribute.
      */
     public void setAttribute(String name, Object value) {
-        attributeMap.put(name, value);
-    }
-    
-    /**
-     * Remove attribute.
-     */
-    public void removeAttribute(String name) {
-        attributeMap.remove(name);
-    }
-    
-    /**
-     * Remove all attributes.
-     */
-    public void clear() {
-        attributeMap.clear();
-    }
-    
-    /**
-     * It checks the request timeout.
-     * Compares the last access time with the specified time.
-     */
-    public boolean isTimeout(long currTime) {
-         boolean bActive = true;
-         int maxIdleTime = getMaxIdleTime();
-         if(maxIdleTime > 0) {
-             long currIdleTimeMillis = currTime - lastAccessTime;
-             long maxIdleTimeMillis = maxIdleTime * 1000L;
-             bActive = currIdleTimeMillis <= maxIdleTimeMillis;
-         }
-         return !bActive;
-    }
+    	if(name.startsWith(FtpIoSession.ATTRIBUTE_PREFIX)) {
+    		throw new IllegalArgumentException("Illegal setting of internal attribute");
+    	}
 
-    /**
-     * Check request timeout.
-     */
-    public boolean isTimeout() {
-        return isTimeout(System.currentTimeMillis());
+    	setAttribute(name, value);
     }
-
+    
     public int getMaxIdleTime() {
-        return this.maxIdleTime;
+        return ioSession.getMaxIdleTime();
     }
 
-    public void setMaxIdleTime(int maxIdleTimeSec) {
-        this.maxIdleTime = maxIdleTimeSec;
+    public void setMaxIdleTime(int maxIdleTime) {
+        ioSession.setMaxIdleTime(maxIdleTime);
     }
 
-    public FtpRequest getCurrentRequest() {
-        return request;
-    }
-    
-    public void setCurrentRequest(FtpRequest request) {
-        this.request = request;
-    }
-    
-    
     /**
      * Get the data type.
      */
     public DataType getDataType() {
-        return dataType;
+        return ioSession.getDataType();
     }
     
     /**
-     * Set the data type.
-     */
-    public void setDataType(DataType type) {
-        dataType = type;
-    }
-
-    /**
      * Get structure.
      */
     public Structure getStructure() {
-        return structure;
-    }
-    
-    /**
-     * Set structure
-     */
-    public void setStructure(Structure stru) {
-        structure = stru;
+        return ioSession.getStructure();
     }
     
     public Certificate[] getClientCertificates() {
-        return clientCertificates;
+        return ioSession.getClientCertificates();
     }
     
-    public void setClientCertificates(Certificate[] certificates) {
-        this.clientCertificates = certificates;
-    }
-
     public InetAddress getServerAddress() {
-        return serverAddr;
-    }
-
-    public void setServerAddress(InetAddress adress) {
-        this.serverAddr = adress;
-    }
-
-    public FtpServerContext getServerContext() {
-        return serverContext;
+        if(ioSession.getLocalAddress() instanceof InetSocketAddress) {
+        	return ((InetSocketAddress)ioSession.getLocalAddress()).getAddress();
+        } else {
+        	return null;
+        }
     }
 
     public int getServerPort() {
-        return serverPort;
-    }
-
-    public void setServerPort(int serverPort) {
-        this.serverPort = serverPort;
+        if(ioSession.getLocalAddress() instanceof InetSocketAddress) {
+        	return ((InetSocketAddress)ioSession.getLocalAddress()).getPort();
+        } else {
+        	return 0;
+        }
     }
 
     public int getFailedLogins() {
-        return failedLogins;
+        return ioSession.getFailedLogins();
     }
 
-    public void increaseFailedLogins() {
-        this.failedLogins++;
-    }
+	public void removeAttribute(String name) {
+    	if(name.startsWith(FtpIoSession.ATTRIBUTE_PREFIX)) {
+    		throw new IllegalArgumentException("Illegal removal of internal attribute");
+    	}
+		
+		removeAttribute(name);
+	}
 }

Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpStatisticsImpl.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpStatisticsImpl.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpStatisticsImpl.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/FtpStatisticsImpl.java Sun Jan  6 14:24:29 2008
@@ -20,6 +20,7 @@
 package org.apache.ftpserver;
 
 import java.net.InetAddress;
+import java.net.InetSocketAddress;
 import java.util.Date;
 import java.util.Hashtable;
 
@@ -29,9 +30,9 @@
 import org.apache.ftpserver.ftplet.FtpException;
 import org.apache.ftpserver.ftplet.User;
 import org.apache.ftpserver.interfaces.FileObserver;
+import org.apache.ftpserver.interfaces.FtpIoSession;
 import org.apache.ftpserver.interfaces.ServerFtpStatistics;
 import org.apache.ftpserver.interfaces.StatisticsObserver;
-import org.apache.ftpserver.listener.Connection;
 
 /**
  * This is ftp statistice implementation.
@@ -67,7 +68,7 @@
      *The user login information. The structure of the hashtable: 
      * userLoginTable {user.getName ==> Hashtable {IP_address String ==> Login_Number}}
      */
-    Hashtable userLoginTable = new Hashtable();
+    Hashtable<String, Hashtable<String, Integer>> userLoginTable = new Hashtable<String, Hashtable<String, Integer>>();
     
     public static final String LOGIN_NUMBER = "login_number";
     
@@ -209,7 +210,7 @@
      * Get the login number for the specific user
      */
     public int getCurrentUserLoginNumber(User user) {
-      Hashtable statisticsTable = (Hashtable) userLoginTable.get(user.getName());
+      Hashtable<String, Integer> statisticsTable = userLoginTable.get(user.getName());
       if(statisticsTable == null){//not found the login user's statistics info
         return 0;
       } else{
@@ -228,7 +229,7 @@
      * @param ipAddress the ip address of the remote user
      */
     public int getCurrentUserLoginNumber(User user, InetAddress ipAddress) {
-      Hashtable statisticsTable = (Hashtable) userLoginTable.get(user.getName());
+      Hashtable<String, Integer> statisticsTable = userLoginTable.get(user.getName());
       if(statisticsTable == null){//not found the login user's statistics info
         return 0;
       } else{
@@ -247,140 +248,155 @@
     /**
      * Increment upload count.
      */
-    public void setUpload(Connection connection, FileObject file, long size) {
+    public void setUpload(FtpIoSession session, FileObject file, long size) {
         ++uploadCount;
         bytesUpload += size;
-        notifyUpload(connection, file, size);
+        notifyUpload(session, file, size);
     }
      
     /**
      * Increment download count.
      */
-    public void setDownload(Connection connection, FileObject file, long size) {
+    public void setDownload(FtpIoSession session, FileObject file, long size) {
         ++downloadCount;
         bytesDownload += size;
-        notifyDownload(connection, file, size);
+        notifyDownload(session, file, size);
     }
      
     /**
      * Increment delete count.
      */
-    public void setDelete(Connection connection, FileObject file) {
+    public void setDelete(FtpIoSession session, FileObject file) {
         ++deleteCount;
-        notifyDelete(connection, file);
+        notifyDelete(session, file);
     }
      
     /**
      * Increment make directory count.
      */
-    public void setMkdir(Connection connection, FileObject file) {
+    public void setMkdir(FtpIoSession session, FileObject file) {
         ++mkdirCount;
-        notifyMkdir(connection, file);
+        notifyMkdir(session, file);
     }
     
     /**
      * Increment remove directory count.
      */
-    public void setRmdir(Connection connection, FileObject file) {
+    public void setRmdir(FtpIoSession session, FileObject file) {
         ++rmdirCount;
-        notifyRmdir(connection, file);
+        notifyRmdir(session, file);
     }
     
     /**
      * Increment open connection count.
      */
-    public void setOpenConnection(Connection connection) {
+    public void setOpenConnection(FtpIoSession session) {
         ++currConnections;
         ++totalConnections;
-        notifyOpenConnection(connection);
+        notifyOpenConnection(session);
     }
     
     /**
      * Decrement open connection count.
      */
-    public void setCloseConnection(Connection connection) {
+    public void setCloseConnection(FtpIoSession session) {
         if(currConnections > 0) {
             --currConnections;
         }
-        notifyCloseConnection(connection);
+        notifyCloseConnection(session);
     }
     
     /**
      * New login.
      */
-    public void setLogin(Connection connection) {
+    public void setLogin(FtpIoSession session) {
         ++currLogins;
         ++totalLogins;
-        User user = connection.getSession().getUser();
+        User user = session.getUser();
         if( "anonymous".equals(user.getName()) ) {
             ++currAnonLogins;
             ++totalAnonLogins;
         }
         
         synchronized(user){//thread safety is needed. Since the login occurrs at low frequency, this overhead is endurable
-          Hashtable statisticsTable = (Hashtable) userLoginTable.get(user.getName());
+          Hashtable<String, Integer> statisticsTable = userLoginTable.get(user.getName());
           if(statisticsTable == null){
             //the hash table that records the login information of the user and its ip address.
             //structure: IP_Address String ==> login_number
-            statisticsTable = new Hashtable();
+            statisticsTable = new Hashtable<String, Integer>();
             userLoginTable.put(user.getName(), statisticsTable);
             //new login, put 1 in the login number
             statisticsTable.put(LOGIN_NUMBER, new Integer(1));
-            statisticsTable.put(connection.getSession().getClientAddress().getHostAddress(), new Integer(1));
-          } else{
-            Integer loginNumber = (Integer) statisticsTable.get(LOGIN_NUMBER);
+            if(session.getRemoteAddress() instanceof InetSocketAddress) {
+            	String address = ((InetSocketAddress)session.getRemoteAddress()).getAddress().getHostAddress();
+            	statisticsTable.put(address, new Integer(1));
+            }
+        } else{
+            Integer loginNumber = statisticsTable.get(LOGIN_NUMBER);
             statisticsTable.put(LOGIN_NUMBER, new Integer(loginNumber.intValue() + 1));
-            Integer loginNumberPerIP = (Integer) statisticsTable.get(connection.getSession().getClientAddress().getHostAddress());
             
-            if(loginNumberPerIP == null) {
-                //new connection from this ip
-              statisticsTable.put(connection.getSession().getClientAddress().getHostAddress(), new Integer(1));
-            } else{//this ip has connections already
-              statisticsTable.put(connection.getSession().getClientAddress().getHostAddress(), new Integer(loginNumberPerIP.intValue() + 1));
+            if(session.getRemoteAddress() instanceof InetSocketAddress) {
+            	String address = ((InetSocketAddress)session.getRemoteAddress()).getAddress().getHostAddress();
+            	Integer loginNumberPerIP = statisticsTable.get(address);
+
+            	if(loginNumberPerIP == null) {
+            		//new connection from this ip
+            		statisticsTable.put(address, new Integer(1));
+            	} else{//this ip has connections already
+            		statisticsTable.put(address, new Integer(loginNumberPerIP.intValue() + 1));
+            	}
             }
+            
           }
         }
         
-        notifyLogin(connection);
+        notifyLogin(session);
     }
     
     /**
      * Increment failed login count.
      */
-    public void setLoginFail(Connection connection) {
+    public void setLoginFail(FtpIoSession session) {
         ++totalFailedLogins;
-        notifyLoginFail(connection);
+        notifyLoginFail(session);
     }
     
     /**
      * User logout
      */
-    public void setLogout(Connection connection) {
+    public void setLogout(FtpIoSession session) {
         --currLogins;
-        User user = connection.getSession().getUser();
+        User user = session.getUser();
         if( "anonymous".equals(user.getName()) ) {
             --currAnonLogins;
         }
         
         synchronized(user){
-          Hashtable statisticsTable = (Hashtable) userLoginTable.get(user.getName());
-          Integer loginNumber = (Integer) statisticsTable.get(LOGIN_NUMBER);
+          Hashtable<String, Integer> statisticsTable = userLoginTable.get(user.getName());
+          Integer loginNumber = statisticsTable.get(LOGIN_NUMBER);
           statisticsTable.put(LOGIN_NUMBER, new Integer(loginNumber.intValue() - 1));
-          Integer loginNumberPerIP = (Integer) statisticsTable.get(connection.getSession().getClientAddress().getHostAddress());
           
-          if(loginNumberPerIP != null){
-            //this should always be true
-            if(loginNumberPerIP.intValue() <= 1){
-                //the last login from this ip, remove this ip address
-                statisticsTable.remove(connection.getSession().getClientAddress().getHostAddress());
-            } else{
-                //this ip has other logins, reduce the number
-                statisticsTable.put(connection.getSession().getClientAddress().getHostAddress(), new Integer(loginNumberPerIP.intValue() - 1));
-            }
-          } 
+          
+          if(session.getRemoteAddress() instanceof InetSocketAddress) {
+        	  String address = ((InetSocketAddress)session.getRemoteAddress()).getAddress().getHostAddress();
+
+        	  Integer loginNumberPerIP = statisticsTable.get(address);
+        	  
+        	  if(loginNumberPerIP != null){
+        		  //this should always be true
+        		  if(loginNumberPerIP.intValue() <= 1){
+        			  //the last login from this ip, remove this ip address
+        			  statisticsTable.remove(address);
+        		  } else{
+        			  //this ip has other logins, reduce the number
+        			  statisticsTable.put(address, new Integer(loginNumberPerIP.intValue() - 1));
+        		  }
+        	  } 
+          }
+          
         }
         
-        notifyLogout(connection);
+        notifyLogout(session);
     }
     
     
@@ -389,7 +405,7 @@
     /**               
      * Observer upload notification.
      */
-    private void notifyUpload(Connection connection, FileObject file, long size) {
+    private void notifyUpload(FtpIoSession session, FileObject file, long size) {
         StatisticsObserver observer = this.observer;
         if (observer != null) {
             observer.notifyUpload();
@@ -397,14 +413,14 @@
 
         FileObserver fileObserver = this.fileObserver;
         if (fileObserver != null) {
-            fileObserver.notifyUpload(connection, file, size);
+            fileObserver.notifyUpload(session, file, size);
         }
     }
     
     /**               
      * Observer download notification.
      */
-    private void notifyDownload(Connection connection, FileObject file, long size) {
+    private void notifyDownload(FtpIoSession session, FileObject file, long size) {
         StatisticsObserver observer = this.observer;
         if (observer != null) {
             observer.notifyDownload();
@@ -412,14 +428,14 @@
 
         FileObserver fileObserver = this.fileObserver;
         if (fileObserver != null) {
-            fileObserver.notifyDownload(connection, file, size);
+            fileObserver.notifyDownload(session, file, size);
         }
     }
     
     /**               
      * Observer delete notification.
      */
-    private void notifyDelete(Connection connection, FileObject file) {
+    private void notifyDelete(FtpIoSession session, FileObject file) {
         StatisticsObserver observer = this.observer;
         if (observer != null) {
             observer.notifyDelete();
@@ -427,14 +443,14 @@
 
         FileObserver fileObserver = this.fileObserver;
         if (fileObserver != null) {
-            fileObserver.notifyDelete(connection, file);
+            fileObserver.notifyDelete(session, file);
         }
     }
     
     /**               
      * Observer make directory notification.
      */
-    private void notifyMkdir(Connection connection, FileObject file) {
+    private void notifyMkdir(FtpIoSession session, FileObject file) {
         StatisticsObserver observer = this.observer;
         if (observer != null) {
             observer.notifyMkdir();
@@ -442,14 +458,14 @@
 
         FileObserver fileObserver = this.fileObserver;
         if (fileObserver != null) {
-            fileObserver.notifyMkdir(connection, file);
+            fileObserver.notifyMkdir(session, file);
         }
     }
     
     /**               
      * Observer remove directory notification.
      */
-    private void notifyRmdir(Connection connection, FileObject file) {
+    private void notifyRmdir(FtpIoSession session, FileObject file) {
         StatisticsObserver observer = this.observer;
         if (observer != null) {
             observer.notifyRmdir();
@@ -457,14 +473,14 @@
 
         FileObserver fileObserver = this.fileObserver;
         if (fileObserver != null) {
-            fileObserver.notifyRmdir(connection, file);
+            fileObserver.notifyRmdir(session, file);
         }
     }
     
     /**
      * Observer open connection notification.
      */
-    private void notifyOpenConnection(Connection connection) {
+    private void notifyOpenConnection(FtpIoSession session) {
         StatisticsObserver observer = this.observer;
         if (observer != null) {
             observer.notifyOpenConnection();
@@ -474,7 +490,7 @@
     /**
      * Observer close connection notification.
      */
-    private void notifyCloseConnection(Connection connection) {
+    private void notifyCloseConnection(FtpIoSession session) {
         StatisticsObserver observer = this.observer;
         if (observer != null) {
             observer.notifyCloseConnection();
@@ -484,12 +500,12 @@
     /**
      * Observer login notification.
      */
-    private void notifyLogin(Connection connection) {
+    private void notifyLogin(FtpIoSession session) {
         StatisticsObserver observer = this.observer;
         if (observer != null) {
             
             // is anonymous login
-            User user = connection.getSession().getUser();
+            User user = session.getUser();
             boolean anonymous = false;
             if(user != null) {
                 String login = user.getName();
@@ -502,21 +518,24 @@
     /**
      * Observer failed login notification.
      */
-    private void notifyLoginFail(Connection connection) {
+    private void notifyLoginFail(FtpIoSession session) {
         StatisticsObserver observer = this.observer;
         if (observer != null) {
-            observer.notifyLoginFail(connection.getSession().getClientAddress());
+        	if(session.getRemoteAddress() instanceof InetSocketAddress) {
+        		observer.notifyLoginFail(((InetSocketAddress)session.getRemoteAddress()).getAddress());
+        		
+        	}
         }
     }
     
     /**
      * Observer logout notification.
      */
-    private void notifyLogout(Connection connection) {
+    private void notifyLogout(FtpIoSession session) {
         StatisticsObserver observer = this.observer;
         if (observer != null) {
             // is anonymous login
-            User user = connection.getSession().getUser();
+            User user = session.getUser();
             boolean anonymous = false;
             if(user != null) {
                 String login = user.getName();

Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/IODataConnection.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/IODataConnection.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/IODataConnection.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/IODataConnection.java Sun Jan  6 14:24:29 2008
@@ -30,8 +30,9 @@
 import java.util.zip.DeflaterOutputStream;
 import java.util.zip.InflaterInputStream;
 
-import org.apache.ftpserver.ftplet.DataType;
 import org.apache.ftpserver.ftplet.DataConnection;
+import org.apache.ftpserver.ftplet.DataType;
+import org.apache.ftpserver.interfaces.FtpIoSession;
 import org.apache.ftpserver.usermanager.TransferRateRequest;
 import org.apache.ftpserver.util.IoUtils;
 
@@ -43,11 +44,11 @@
 public
 class IODataConnection implements DataConnection {
     
-    private FtpSessionImpl session;
+    private FtpIoSession session;
     private Socket socket;
     private ServerDataConnectionFactory factory;
     
-    public IODataConnection(Socket socket, FtpSessionImpl session, ServerDataConnectionFactory factory) {
+    public IODataConnection(Socket socket, FtpIoSession session, ServerDataConnectionFactory factory) {
         this.session = session;
         this.socket = socket;
         this.factory = factory;

Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/IODataConnectionFactory.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/IODataConnectionFactory.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/IODataConnectionFactory.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/IODataConnectionFactory.java Sun Jan  6 14:24:29 2008
@@ -35,6 +35,7 @@
 import org.apache.ftpserver.ftplet.DataConnection;
 import org.apache.ftpserver.ftplet.FtpException;
 import org.apache.ftpserver.interfaces.DataConnectionConfig;
+import org.apache.ftpserver.interfaces.FtpIoSession;
 import org.apache.ftpserver.interfaces.FtpServerContext;
 import org.apache.ftpserver.ssl.ClientAuth;
 import org.apache.ftpserver.ssl.Ssl;
@@ -66,9 +67,9 @@
 
     InetAddress serverControlAddress;
 
-    FtpSessionImpl session;
+    FtpIoSession session;
     
-    public IODataConnectionFactory(FtpServerContext serverContext, FtpSessionImpl session) {
+    public IODataConnectionFactory(FtpServerContext serverContext, FtpIoSession session) {
         this.session = session;
         this.serverContext = serverContext;
         
@@ -151,9 +152,11 @@
         try {
             DataConnectionConfig dataCfg = session.getListener().getDataConnectionConfig();
             address = dataCfg.getPassiveAddress();
+            System.out.println("!!!!!!!!!!!!!" + address);
             if(address == null) {
                 address = serverControlAddress;
             }
+            System.out.println("!!!!!!!!!!!!!" + address);
             if(secure) {
                 Ssl ssl = dataCfg.getSSL();
                 if(ssl == null) {

Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/PassivePorts.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/PassivePorts.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/PassivePorts.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/PassivePorts.java Sun Jan  6 14:24:29 2008
@@ -46,7 +46,7 @@
      *   invalid (e.g. not an integer or too large for a port number) 
      */
     public static PassivePorts parse(String portsString) {
-        List passivePortsList = new ArrayList();
+        List<Integer> passivePortsList = new ArrayList<Integer>();
         
         boolean inRange = false;
         Integer lastPort = new Integer(1);

Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/ABOR.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/ABOR.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/ABOR.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/ABOR.java Sun Jan  6 14:24:29 2008
@@ -21,11 +21,10 @@
 
 import java.io.IOException;
 
-import org.apache.ftpserver.FtpSessionImpl;
 import org.apache.ftpserver.ftplet.FtpReply;
-import org.apache.ftpserver.ftplet.FtpReplyOutput;
 import org.apache.ftpserver.ftplet.FtpRequest;
-import org.apache.ftpserver.listener.Connection;
+import org.apache.ftpserver.interfaces.FtpIoSession;
+import org.apache.ftpserver.interfaces.FtpServerContext;
 import org.apache.ftpserver.util.FtpReplyUtil;
 
 /**
@@ -46,16 +45,15 @@
     /**
      * Execute command
      */
-    public void execute(Connection connection,
-                        FtpRequest request, 
-                        FtpSessionImpl session, 
-                        FtpReplyOutput out) throws IOException {
+    public void execute(FtpIoSession session, 
+    		FtpServerContext context,
+            FtpRequest request) throws IOException {
         
         // reset state variables
         session.resetState();
         
         // and abort any data connection
         session.getDataConnection().closeDataConnection();
-        out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_226_CLOSING_DATA_CONNECTION, "ABOR", null));
+        session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_226_CLOSING_DATA_CONNECTION, "ABOR", null));
     }   
 }

Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/ACCT.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/ACCT.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/ACCT.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/ACCT.java Sun Jan  6 14:24:29 2008
@@ -21,11 +21,10 @@
 
 import java.io.IOException;
 
-import org.apache.ftpserver.FtpSessionImpl;
 import org.apache.ftpserver.ftplet.FtpReply;
-import org.apache.ftpserver.ftplet.FtpReplyOutput;
 import org.apache.ftpserver.ftplet.FtpRequest;
-import org.apache.ftpserver.listener.Connection;
+import org.apache.ftpserver.interfaces.FtpIoSession;
+import org.apache.ftpserver.interfaces.FtpServerContext;
 import org.apache.ftpserver.util.FtpReplyUtil;
 
 /**
@@ -40,16 +39,15 @@
     /**
      * Execute command.
      */
-    public void execute(Connection connection,
-                        FtpRequest request,
-                        FtpSessionImpl session, 
-                        FtpReplyOutput out) throws IOException {
+    public void execute(FtpIoSession session,
+                        FtpServerContext context,
+                        FtpRequest request) throws IOException {
         
         // reset state variables
         session.resetState();
         
         // and abort any data connection
-        out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_202_COMMAND_NOT_IMPLEMENTED, "ACCT", null));
+        session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_202_COMMAND_NOT_IMPLEMENTED, "ACCT", null));
     }   
 }
 

Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/APPE.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/APPE.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/APPE.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/APPE.java Sun Jan  6 14:24:29 2008
@@ -32,13 +32,12 @@
 import org.apache.ftpserver.ftplet.DataConnection;
 import org.apache.ftpserver.ftplet.FtpException;
 import org.apache.ftpserver.ftplet.FtpReply;
-import org.apache.ftpserver.ftplet.FtpReplyOutput;
 import org.apache.ftpserver.ftplet.FtpRequest;
 import org.apache.ftpserver.ftplet.Ftplet;
 import org.apache.ftpserver.ftplet.FtpletEnum;
+import org.apache.ftpserver.interfaces.FtpIoSession;
 import org.apache.ftpserver.interfaces.FtpServerContext;
 import org.apache.ftpserver.interfaces.ServerFtpStatistics;
-import org.apache.ftpserver.listener.Connection;
 import org.apache.ftpserver.util.FtpReplyUtil;
 import org.apache.ftpserver.util.IoUtils;
 import org.slf4j.Logger;
@@ -62,21 +61,19 @@
     /**
      * Execute command.
      */
-    public void execute(Connection connection,
-                        FtpRequest request, 
-                        FtpSessionImpl session, 
-                        FtpReplyOutput out) throws IOException, FtpException {
+    public void execute(FtpIoSession session,
+                        FtpServerContext context, 
+                        FtpRequest request) throws IOException, FtpException {
         
         try {
         
             // reset state variables
             session.resetState();
-            FtpServerContext serverContext = connection.getServerContext();
             
             // argument check
             String fileName = request.getArgument();
             if(fileName == null) {
-                out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "APPE", null));
+                session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "APPE", null));
                 return;  
             }
             
@@ -85,16 +82,16 @@
             if (connFactory instanceof IODataConnectionFactory) {
                 InetAddress address = ((IODataConnectionFactory)connFactory).getInetAddress();
                 if (address == null) {
-                    out.write(new DefaultFtpReply(FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS, "PORT or PASV must be issued first"));
+                	session.write(new DefaultFtpReply(FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS, "PORT or PASV must be issued first"));
                     return;
                 }
             }
             
             // call Ftplet.onAppendStart() method
-            Ftplet ftpletContainer = serverContext.getFtpletContainer();
+            Ftplet ftpletContainer = context.getFtpletContainer();
             FtpletEnum ftpletRet;
             try {
-                ftpletRet = ftpletContainer.onAppendStart(session, request, out);
+                ftpletRet = ftpletContainer.onAppendStart(session.getFtpletSession(), request);
             } catch(Exception e) {
                 LOG.debug("Ftplet container threw exception", e);
                 ftpletRet = FtpletEnum.RET_DISCONNECT;
@@ -103,7 +100,7 @@
                 return;
             }
             else if(ftpletRet == FtpletEnum.RET_DISCONNECT) {
-                serverContext.getConnectionManager().closeConnection(connection);
+                session.closeOnFlush();
                 return;
             }
             
@@ -116,32 +113,32 @@
                 LOG.debug("File system threw exception", e);
             }
             if(file == null) {
-                out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "APPE.invalid", fileName));
+                session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "APPE.invalid", fileName));
                 return;
             }
             fileName = file.getFullName();
             
             // check file existance
             if(file.doesExist() && !file.isFile()) {
-                out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "APPE.invalid", fileName));
+                session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "APPE.invalid", fileName));
                 return;
             }
             
             // check permission
             if( !file.hasWritePermission()) {
-                out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "APPE.permission", fileName));
+            	session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "APPE.permission", fileName));
                 return;
             }
             
             // get data connection
-            out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_150_FILE_STATUS_OKAY, "APPE", fileName));
+            session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_150_FILE_STATUS_OKAY, "APPE", fileName));
             
             DataConnection dataConnection;
             try {
                 dataConnection = session.getDataConnection().openConnection();
             } catch (Exception e) {
                 LOG.debug("Exception when getting data input stream", e);
-                out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_425_CANT_OPEN_DATA_CONNECTION, "APPE", fileName));
+                session.write(FtpReplyUtil.translate(session,request,  context, FtpReply.REPLY_425_CANT_OPEN_DATA_CONNECTION, "APPE", fileName));
                 return;
             }
              
@@ -168,18 +165,18 @@
                 LOG.info("File upload : " + userName + " - " + fileName);
                 
                 // notify the statistics component
-                ServerFtpStatistics ftpStat = (ServerFtpStatistics)serverContext.getFtpStatistics();
-                ftpStat.setUpload(connection, file, transSz);
+                ServerFtpStatistics ftpStat = (ServerFtpStatistics)context.getFtpStatistics();
+                ftpStat.setUpload(session, file, transSz);
             }
             catch(SocketException e) {
                 LOG.debug("SocketException during file upload", e);
                 failure = true;
-                out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_426_CONNECTION_CLOSED_TRANSFER_ABORTED, "APPE", fileName));
+                session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_426_CONNECTION_CLOSED_TRANSFER_ABORTED, "APPE", fileName));
             }
             catch(IOException e) {
                 LOG.debug("IOException during file upload", e);
                 failure = true;
-                out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_551_REQUESTED_ACTION_ABORTED_PAGE_TYPE_UNKNOWN, "APPE", fileName));
+                session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_551_REQUESTED_ACTION_ABORTED_PAGE_TYPE_UNKNOWN, "APPE", fileName));
             }
             finally {
                 IoUtils.close(os);
@@ -187,17 +184,17 @@
             
             // if data transfer ok - send transfer complete message
             if(!failure) {
-                out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_226_CLOSING_DATA_CONNECTION, "APPE", fileName));
+                session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_226_CLOSING_DATA_CONNECTION, "APPE", fileName));
                 
                 // call Ftplet.onAppendEnd() method
                 try {
-                    ftpletRet = ftpletContainer.onAppendEnd(session, request, out);
+                    ftpletRet = ftpletContainer.onAppendEnd(session.getFtpletSession(), request);
                 } catch(Exception e) {
                     LOG.debug("Ftplet container threw exception", e);
                     ftpletRet = FtpletEnum.RET_DISCONNECT;
                 }
                 if(ftpletRet == FtpletEnum.RET_DISCONNECT) {
-                    serverContext.getConnectionManager().closeConnection(connection);
+                    session.closeOnFlush();
                     return;
                 }
 

Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/AUTH.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/AUTH.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/AUTH.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/AUTH.java Sun Jan  6 14:24:29 2008
@@ -20,14 +20,17 @@
 package org.apache.ftpserver.command;
 
 import java.io.IOException;
+import java.security.GeneralSecurityException;
 
-import org.apache.ftpserver.FtpSessionImpl;
 import org.apache.ftpserver.ftplet.FtpException;
 import org.apache.ftpserver.ftplet.FtpReply;
-import org.apache.ftpserver.ftplet.FtpReplyOutput;
 import org.apache.ftpserver.ftplet.FtpRequest;
-import org.apache.ftpserver.listener.Connection;
+import org.apache.ftpserver.interfaces.FtpIoSession;
+import org.apache.ftpserver.interfaces.FtpServerContext;
+import org.apache.ftpserver.ssl.ClientAuth;
+import org.apache.ftpserver.ssl.Ssl;
 import org.apache.ftpserver.util.FtpReplyUtil;
+import org.apache.mina.filter.ssl.SslFilter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -42,23 +45,22 @@
     /**
      * Execute command
      */
-    public void execute(Connection connection,
-                        FtpRequest request, 
-                        FtpSessionImpl session, 
-                        FtpReplyOutput out) throws IOException, FtpException {
+    public void execute(FtpIoSession session,
+                        FtpServerContext context, 
+                        FtpRequest request) throws IOException, FtpException {
         
         // reset state variables
         session.resetState();
         
         // argument check
         if(!request.hasArgument()) {
-            out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "AUTH", null));
+            session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "AUTH", null));
             return;  
         }
         
         // check SSL configuration
         if(session.getListener().getSsl() == null) {
-            out.write(FtpReplyUtil.translate(session, 431, "AUTH", null));
+            session.write(FtpReplyUtil.translate(session, request, context, 431, "AUTH", null));
             return;
         }
         
@@ -66,9 +68,8 @@
         String authType = request.getArgument().toUpperCase();
         if(authType.equals("SSL")) {
             try {
-                connection.beforeSecureControlChannel(session, "SSL");
-                out.write(FtpReplyUtil.translate(session, 234, "AUTH.SSL", null));
-                connection.afterSecureControlChannel(session, "SSL");
+                secureSession(session, "SSL");
+                session.write(FtpReplyUtil.translate(session, request, context, 234, "AUTH.SSL", null));
             } catch(FtpException ex) {
                 throw ex;
             } catch(Exception ex) {
@@ -78,9 +79,8 @@
         }
         else if(authType.equals("TLS")) {
             try {
-                connection.beforeSecureControlChannel(session, "TLS");
-                out.write(FtpReplyUtil.translate(session, 234, "AUTH.TLS", null));
-                connection.afterSecureControlChannel(session, "TLS");
+                secureSession(session, "TLS");
+                session.write(FtpReplyUtil.translate(session, request, context, 234, "AUTH.TLS", null));
             } catch(FtpException ex) {
                 throw ex;
             } catch(Exception ex) {
@@ -89,7 +89,30 @@
             }
         }
         else {
-            out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_502_COMMAND_NOT_IMPLEMENTED, "AUTH", null));
+            session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_502_COMMAND_NOT_IMPLEMENTED, "AUTH", null));
+        }
+    }
+    
+    private void secureSession(FtpIoSession session, String type) throws GeneralSecurityException, FtpException {
+        Ssl ssl = session.getListener().getSsl();
+        
+        if(ssl != null) {
+            session.setAttribute(SslFilter.DISABLE_ENCRYPTION_ONCE);
+            
+            SslFilter sslFilter = new SslFilter( ssl.getSSLContext() );
+            if(ssl.getClientAuth() == ClientAuth.NEED) {
+                sslFilter.setNeedClientAuth(true);
+            } else if(ssl.getClientAuth() == ClientAuth.WANT) {
+                sslFilter.setWantClientAuth(true);
+            }
+            
+            if(ssl.getEnabledCipherSuites() != null) {
+                sslFilter.setEnabledCipherSuites(ssl.getEnabledCipherSuites());
+            }
+            session.getFilterChain().addFirst("sslSessionFilter", sslFilter);
+
+        } else {
+            throw new FtpException("Socket factory SSL not configured");
         }
     }
 }

Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/CDUP.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/CDUP.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/CDUP.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/CDUP.java Sun Jan  6 14:24:29 2008
@@ -21,13 +21,12 @@
 
 import java.io.IOException;
 
-import org.apache.ftpserver.FtpSessionImpl;
 import org.apache.ftpserver.ftplet.FileSystemView;
 import org.apache.ftpserver.ftplet.FtpException;
 import org.apache.ftpserver.ftplet.FtpReply;
-import org.apache.ftpserver.ftplet.FtpReplyOutput;
 import org.apache.ftpserver.ftplet.FtpRequest;
-import org.apache.ftpserver.listener.Connection;
+import org.apache.ftpserver.interfaces.FtpIoSession;
+import org.apache.ftpserver.interfaces.FtpServerContext;
 import org.apache.ftpserver.util.FtpReplyUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -49,10 +48,9 @@
     /**
      * Execute command.
      */
-    public void execute(Connection connection, 
-                        FtpRequest request, 
-                        FtpSessionImpl session, 
-                        FtpReplyOutput out) throws IOException, FtpException {
+    public void execute(FtpIoSession session, 
+                        FtpServerContext context, 
+                        FtpRequest request) throws IOException, FtpException {
         
         // reset state variables
         session.resetState();
@@ -68,10 +66,10 @@
         }
         if(success) {
             String dirName = fsview.getCurrentDirectory().getFullName();
-            out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_250_REQUESTED_FILE_ACTION_OKAY, "CDUP", dirName));
+            session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_250_REQUESTED_FILE_ACTION_OKAY, "CDUP", dirName));
         }
         else {
-            out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "CDUP", null));
+            session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "CDUP", null));
         }
     }
 }

Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/CWD.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/CWD.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/CWD.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/CWD.java Sun Jan  6 14:24:29 2008
@@ -21,13 +21,12 @@
 
 import java.io.IOException;
 
-import org.apache.ftpserver.FtpSessionImpl;
 import org.apache.ftpserver.ftplet.FileSystemView;
 import org.apache.ftpserver.ftplet.FtpException;
 import org.apache.ftpserver.ftplet.FtpReply;
-import org.apache.ftpserver.ftplet.FtpReplyOutput;
 import org.apache.ftpserver.ftplet.FtpRequest;
-import org.apache.ftpserver.listener.Connection;
+import org.apache.ftpserver.interfaces.FtpIoSession;
+import org.apache.ftpserver.interfaces.FtpServerContext;
 import org.apache.ftpserver.util.FtpReplyUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -49,10 +48,9 @@
     /**
      * Execute command
      */
-    public void execute(Connection connection, 
-                        FtpRequest request, 
-                        FtpSessionImpl session, 
-                        FtpReplyOutput out) throws IOException, FtpException {
+    public void execute(FtpIoSession session, 
+                        FtpServerContext context, 
+                        FtpRequest request) throws IOException, FtpException {
         
         // reset state variables
         session.resetState();
@@ -74,10 +72,10 @@
         }
         if(success) {
             dirName = fsview.getCurrentDirectory().getFullName();
-            out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_250_REQUESTED_FILE_ACTION_OKAY, "CWD", dirName));
+            session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_250_REQUESTED_FILE_ACTION_OKAY, "CWD", dirName));
         }
         else {
-            out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "CWD", null));
+            session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "CWD", null));
         }
     }
 }

Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/DELE.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/DELE.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/DELE.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/DELE.java Sun Jan  6 14:24:29 2008
@@ -25,13 +25,12 @@
 import org.apache.ftpserver.ftplet.FileObject;
 import org.apache.ftpserver.ftplet.FtpException;
 import org.apache.ftpserver.ftplet.FtpReply;
-import org.apache.ftpserver.ftplet.FtpReplyOutput;
 import org.apache.ftpserver.ftplet.FtpRequest;
 import org.apache.ftpserver.ftplet.Ftplet;
 import org.apache.ftpserver.ftplet.FtpletEnum;
+import org.apache.ftpserver.interfaces.FtpIoSession;
 import org.apache.ftpserver.interfaces.FtpServerContext;
 import org.apache.ftpserver.interfaces.ServerFtpStatistics;
-import org.apache.ftpserver.listener.Connection;
 import org.apache.ftpserver.util.FtpReplyUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -50,37 +49,35 @@
     /**
      * Execute command.
      */
-    public void execute(Connection connection,
-                        FtpRequest request, 
-                        FtpSessionImpl session, 
-                        FtpReplyOutput out) throws IOException, FtpException {
+    public void execute(FtpIoSession session,
+                        FtpServerContext context, 
+                        FtpRequest request) throws IOException, FtpException {
         
         // reset state variables
         session.resetState(); 
-        FtpServerContext serverContext = connection.getServerContext();
         
         // argument check
         String fileName = request.getArgument();
         if(fileName == null) {
-            out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "DELE", null));
+            session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "DELE", null));
             return;  
         }
         
         // call Ftplet.onDeleteStart() method
-        Ftplet ftpletContainer = serverContext.getFtpletContainer();
+        Ftplet ftpletContainer = context.getFtpletContainer();
         FtpletEnum ftpletRet;
         try {
-            ftpletRet = ftpletContainer.onDeleteStart(session, request, out);
+            ftpletRet = ftpletContainer.onDeleteStart(session.getFtpletSession(), request);
         } catch(Exception e) {
             LOG.debug("Ftplet container threw exception", e);
             ftpletRet = FtpletEnum.RET_DISCONNECT;
         }
         if(ftpletRet == FtpletEnum.RET_SKIP) {
-            out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN, "DELE", fileName));
+        	session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN, "DELE", fileName));
             return;
         }
         else if(ftpletRet == FtpletEnum.RET_DISCONNECT) {
-            serverContext.getConnectionManager().closeConnection(connection);
+            session.closeOnFlush();
             return;
         }
 
@@ -94,7 +91,7 @@
             LOG.debug("Could not get file " + fileName, ex);
         }
         if(file == null) {
-            out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "DELE.invalid", fileName));
+            session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "DELE.invalid", fileName));
             return;
         }
 
@@ -102,13 +99,13 @@
         fileName = file.getFullName();
 
         if( !file.hasDeletePermission() ) {
-            out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN, "DELE.permission", fileName));
+            session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN, "DELE.permission", fileName));
             return;
         }
         
         // now delete
         if(file.delete()) {
-            out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_250_REQUESTED_FILE_ACTION_OKAY, "DELE", fileName)); 
+        	session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_250_REQUESTED_FILE_ACTION_OKAY, "DELE", fileName)); 
             
             // log message
             String userName = session.getUser().getName();
@@ -116,24 +113,24 @@
             LOG.info("File delete : " + userName + " - " + fileName);
             
             // notify statistics object
-            ServerFtpStatistics ftpStat = (ServerFtpStatistics)serverContext.getFtpStatistics();
-            ftpStat.setDelete(connection, file);
+            ServerFtpStatistics ftpStat = (ServerFtpStatistics)context.getFtpStatistics();
+            ftpStat.setDelete(session, file);
             
             // call Ftplet.onDeleteEnd() method
             try{
-                ftpletRet = ftpletContainer.onDeleteEnd(session, request, out);
+                ftpletRet = ftpletContainer.onDeleteEnd(session.getFtpletSession(), request);
             } catch(Exception e) {
                 LOG.debug("Ftplet container threw exception", e);
                 ftpletRet = FtpletEnum.RET_DISCONNECT;
             }
             if(ftpletRet == FtpletEnum.RET_DISCONNECT) {
-                serverContext.getConnectionManager().closeConnection(connection);
+                session.closeOnFlush();
                 return;
             }
 
         }
         else {
-            out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN, "DELE", fileName));
+            session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN, "DELE", fileName));
         }
     }
 

Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/EPRT.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/EPRT.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/EPRT.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/EPRT.java Sun Jan  6 14:24:29 2008
@@ -24,12 +24,11 @@
 import java.net.InetSocketAddress;
 import java.net.UnknownHostException;
 
-import org.apache.ftpserver.FtpSessionImpl;
 import org.apache.ftpserver.ftplet.FtpReply;
-import org.apache.ftpserver.ftplet.FtpReplyOutput;
 import org.apache.ftpserver.ftplet.FtpRequest;
 import org.apache.ftpserver.interfaces.DataConnectionConfig;
-import org.apache.ftpserver.listener.Connection;
+import org.apache.ftpserver.interfaces.FtpIoSession;
+import org.apache.ftpserver.interfaces.FtpServerContext;
 import org.apache.ftpserver.util.FtpReplyUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -50,10 +49,9 @@
     /**
      * Execute command.
      */
-    public void execute(Connection connection,
-                        FtpRequest request, 
-                        FtpSessionImpl session, 
-                        FtpReplyOutput out) throws IOException {
+    public void execute(FtpIoSession session,
+                        FtpServerContext context, 
+                        FtpRequest request) throws IOException {
         
         // reset state variables
         session.resetState();
@@ -61,14 +59,14 @@
         // argument check
         String arg = request.getArgument();
         if(arg == null) {
-            out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "EPRT", null));
+            session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "EPRT", null));
             return;  
         }
         
         // is port enabled
         DataConnectionConfig dataCfg = session.getListener().getDataConnectionConfig();
         if(!dataCfg.isActiveEnabled()) {
-            out.write(FtpReplyUtil.translate(session, 510, "EPRT.disabled", null));
+            session.write(FtpReplyUtil.translate(session, request, context, 510, "EPRT.disabled", null));
             return;
         }
         
@@ -83,7 +81,7 @@
         }
         catch(Exception ex) {
             LOG.debug("Exception parsing host and port: " + arg, ex);
-            out.write(FtpReplyUtil.translate(session, 510, "EPRT", null));
+            session.write(FtpReplyUtil.translate(session, request, context, 510, "EPRT", null));
             return;
         }
         
@@ -94,17 +92,19 @@
         }
         catch(UnknownHostException ex) {
             LOG.debug("Unknown host: " + host, ex);
-            out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_553_REQUESTED_ACTION_NOT_TAKEN_FILE_NAME_NOT_ALLOWED, "EPRT.host", null));
+            session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_553_REQUESTED_ACTION_NOT_TAKEN_FILE_NAME_NOT_ALLOWED, "EPRT.host", null));
             return;
         }
         
         // check IP
         if(dataCfg.isActiveIpCheck()) {
-            InetAddress clientAddr = session.getClientAddress();
-            if(!dataAddr.equals(clientAddr)) {
-                out.write(FtpReplyUtil.translate(session, 510, "EPRT.mismatch", null));
-                return;
-            }
+        	if(session.getRemoteAddress() instanceof InetSocketAddress) {
+	            InetAddress clientAddr = ((InetSocketAddress)session.getRemoteAddress()).getAddress();
+	            if(!dataAddr.equals(clientAddr)) {
+	                session.write(FtpReplyUtil.translate(session, request, context, 510, "EPRT.mismatch", null));
+	                return;
+	            }
+        	}
         }
         
         // get data server port
@@ -114,11 +114,11 @@
         }
         catch(NumberFormatException ex) {
             LOG.debug("Invalid port: " + port, ex);
-            out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_552_REQUESTED_FILE_ACTION_ABORTED_EXCEEDED_STORAGE, "EPRT.invalid", null)); 
+            session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_552_REQUESTED_FILE_ACTION_ABORTED_EXCEEDED_STORAGE, "EPRT.invalid", null)); 
             return; 
         }
         
-        session.getServerDataConnection().initActiveDataConnection(new InetSocketAddress(dataAddr, dataPort));
-        out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_200_COMMAND_OKAY, "EPRT", null));
+        session.getDataConnection().initActiveDataConnection(new InetSocketAddress(dataAddr, dataPort));
+        session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_200_COMMAND_OKAY, "EPRT", null));
     }
 }

Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/EPSV.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/EPSV.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/EPSV.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/EPSV.java Sun Jan  6 14:24:29 2008
@@ -23,12 +23,11 @@
 import java.net.InetSocketAddress;
 
 import org.apache.ftpserver.DataConnectionException;
-import org.apache.ftpserver.FtpSessionImpl;
 import org.apache.ftpserver.ServerDataConnectionFactory;
 import org.apache.ftpserver.ftplet.FtpReply;
-import org.apache.ftpserver.ftplet.FtpReplyOutput;
 import org.apache.ftpserver.ftplet.FtpRequest;
-import org.apache.ftpserver.listener.Connection;
+import org.apache.ftpserver.interfaces.FtpIoSession;
+import org.apache.ftpserver.interfaces.FtpServerContext;
 import org.apache.ftpserver.util.FtpReplyUtil;
 
 /**
@@ -49,16 +48,15 @@
     /**
      * Execute command.
      */
-    public void execute(Connection connection,
-                        FtpRequest request,
-                        FtpSessionImpl session, 
-                        FtpReplyOutput out) throws IOException {
+    public void execute(FtpIoSession session,
+                        FtpServerContext context,
+                        FtpRequest request) throws IOException {
         
         // reset state variables
         session.resetState();
         
         // set data connection
-        ServerDataConnectionFactory dataCon = session.getServerDataConnection();
+        ServerDataConnectionFactory dataCon = session.getDataConnection();
         
         try {
             InetSocketAddress dataConAddress = dataCon.initPassiveDataConnection();
@@ -67,10 +65,10 @@
             
             // send connection info to client
             String portStr = "|||" + servPort + '|';
-            out.write(FtpReplyUtil.translate(session, 229, "EPSV", portStr));
+            session.write(FtpReplyUtil.translate(session, request, context, 229, "EPSV", portStr));
         
         } catch(DataConnectionException e) {
-            out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_425_CANT_OPEN_DATA_CONNECTION, "EPSV", null));
+            session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_425_CANT_OPEN_DATA_CONNECTION, "EPSV", null));
             return;   
         }
     }

Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/FEAT.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/FEAT.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/FEAT.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/FEAT.java Sun Jan  6 14:24:29 2008
@@ -21,12 +21,11 @@
 
 import java.io.IOException;
 
-import org.apache.ftpserver.FtpSessionImpl;
 import org.apache.ftpserver.ftplet.FtpException;
 import org.apache.ftpserver.ftplet.FtpReply;
-import org.apache.ftpserver.ftplet.FtpReplyOutput;
 import org.apache.ftpserver.ftplet.FtpRequest;
-import org.apache.ftpserver.listener.Connection;
+import org.apache.ftpserver.interfaces.FtpIoSession;
+import org.apache.ftpserver.interfaces.FtpServerContext;
 import org.apache.ftpserver.util.FtpReplyUtil;
 
 /**
@@ -38,14 +37,13 @@
 public 
 class FEAT extends AbstractCommand {
 
-    public void execute(Connection connection,
-                        FtpRequest request, 
-                        FtpSessionImpl session, 
-                        FtpReplyOutput out) throws IOException, FtpException {
+    public void execute(FtpIoSession session,
+                        FtpServerContext context, 
+                        FtpRequest request) throws IOException, FtpException {
 
         // reset state variables
         session.resetState();
         
-        out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_211_SYSTEM_STATUS_REPLY, "FEAT", null));
+        session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_211_SYSTEM_STATUS_REPLY, "FEAT", null));
     }
 }

Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/HELP.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/HELP.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/HELP.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/HELP.java Sun Jan  6 14:24:29 2008
@@ -21,12 +21,11 @@
 
 import java.io.IOException;
 
-import org.apache.ftpserver.FtpSessionImpl;
 import org.apache.ftpserver.ftplet.FtpReply;
-import org.apache.ftpserver.ftplet.FtpReplyOutput;
 import org.apache.ftpserver.ftplet.FtpRequest;
+import org.apache.ftpserver.interfaces.FtpIoSession;
+import org.apache.ftpserver.interfaces.FtpServerContext;
 import org.apache.ftpserver.interfaces.MessageResource;
-import org.apache.ftpserver.listener.Connection;
 import org.apache.ftpserver.util.FtpReplyUtil;
 
 /**
@@ -44,26 +43,25 @@
     /**
      * Execute command.
      */
-    public void execute(Connection connection,
-                        FtpRequest request, 
-                        FtpSessionImpl session, 
-                        FtpReplyOutput out) throws IOException {
+    public void execute(FtpIoSession session,
+                        FtpServerContext context, 
+                        FtpRequest request) throws IOException {
         
         // reset state variables
         session.resetState();
         
         // print global help
         if(!request.hasArgument()) {
-            out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_214_HELP_MESSAGE, null, null));
+            session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_214_HELP_MESSAGE, null, null));
             return;
         }
         
         // print command specific help if available
         String ftpCmd = request.getArgument().toUpperCase();
-        MessageResource resource = connection.getServerContext().getMessageResource();
+        MessageResource resource = context.getMessageResource();
         if(resource.getMessage(FtpReply.REPLY_214_HELP_MESSAGE, ftpCmd, session.getLanguage()) == null) {
             ftpCmd = null;
         }
-        out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_214_HELP_MESSAGE, ftpCmd, null));
+        session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_214_HELP_MESSAGE, ftpCmd, null));
     }
 }



Mime
View raw message