avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ran...@apache.org
Subject cvs commit: jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver FtpDataConnection.java
Date Thu, 10 Oct 2002 16:02:56 GMT
rana_b      2002/10/10 09:02:56

  Modified:    ftpserver/src/java/org/apache/avalon/ftpserver
                        FtpDataConnection.java
  Log:
  PASV bug fixed
  
  Revision  Changes    Path
  1.7       +60 -61    jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/FtpDataConnection.java
  
  Index: FtpDataConnection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/FtpDataConnection.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FtpDataConnection.java	31 Mar 2002 16:41:13 -0000	1.6
  +++ FtpDataConnection.java	10 Oct 2002 16:02:56 -0000	1.7
  @@ -1,3 +1,4 @@
  +//$Id$
   /*
    * Copyright (C) The Apache Software Foundation. All rights reserved.
    *
  @@ -11,6 +12,8 @@
   import java.net.Socket;
   import java.net.ServerSocket;
   import java.net.InetAddress;
  +import java.io.IOException;
  +
   
   /**
    * We can get the ftp data connection using this class.
  @@ -23,6 +26,7 @@
       private FtpConfig    mConfig  = null;
       private Socket       mDataSoc = null;
       private ServerSocket mServSoc = null;
  +    
       private InetAddress  mAddress = null;
       private int          miPort   = 0;
       
  @@ -38,12 +42,11 @@
           mConfig = cfg;
       }
       
  +    
       /**
  -     * Reset all the member variables. Close all sockets.
  +     * Close data socket.
        */
  -    public void reset() {
  -        
  -        // close data socket
  +    public void closeDataSocket() {
           if(mDataSoc != null) {
               try { 
                   mDataSoc.close(); 
  @@ -53,24 +56,6 @@
               }
               mDataSoc = null;
           }
  -        
  -        // close server socket
  -        if(mServSoc != null) {
  -            try { 
  -                mServSoc.close(); 
  -            } 
  -            catch(Exception ex) {
  -                mConfig.getLogger().warn("FtpDataConnection.reset()", ex);
  -            }
  -            mServSoc = null;
  -        }
  -        
  -        // reset other variables
  -        mAddress = null;
  -        miPort   = 0;
  -        
  -        mbPort   = false;
  -        mbPasv   = false;
       }
        
        
  @@ -78,48 +63,41 @@
        * Port command.
        */
       public void setPortCommand(InetAddress addr, int port) {
  -        reset();
  +        closeDataSocket();
           mbPort = true;
  +        mbPasv = false;
           mAddress = addr;
           miPort = port;
       } 
       
  +    
       /**
        * Passive command. It returns the success flag.
        */
       public boolean setPasvCommand() {
           boolean bRet = false;
  +        closeDataSocket(); 
  +        
           try {
  -          reset();
  +            
  +            // open passive server socket if not done already      
  +            if (mServSoc == null)  {
  +                mServSoc = new ServerSocket(getPassivePort(), 1, mConfig.getSelfAddress());
  +            }  
  +            
             mAddress = mConfig.getSelfAddress();
  -          mServSoc = new ServerSocket(0, 1, mAddress);
  -          mServSoc.setSoTimeout(60000);
             miPort = mServSoc.getLocalPort();
  +            
  +          mbPort = false;
             mbPasv = true;
             bRet = true;
           }
           catch(Exception ex) {
  +            mServSoc = null;
               mConfig.getLogger().warn("FtpDataConnection.setPasvCommand()", ex);
           }
           return bRet;
       }
  -    
  -    /**
  -     * Listen for passive socket connection. It returns the success flag.
  -     */
  -    public boolean listenPasvConnection() {
  -        boolean bRet = false;
  -        mDataSoc = null;
  -        try {
  -            mDataSoc = mServSoc.accept();
  -            mDataSoc.setSoTimeout(60000);
  -            bRet = true;
  -        }
  -        catch(Exception ex) {
  -            mConfig.getLogger().warn("FtpDataConnection.listenPasvConnection()", ex);
  -        }
  -        return bRet;
  -    }
        
        
       /**
  @@ -129,6 +107,7 @@
           return mAddress;
       }
        
  +     
       /**
        * Get port number.
        */
  @@ -136,37 +115,57 @@
           return miPort;
       }
        
  +     
       /**
        * Get the data socket. In case of error returns null.
        */
       public Socket getDataSocket() {
          
  +        // close data connecton if not done already
  +        closeDataSocket();
  +       
           // get socket depending on the selection
  -        if(mbPort) {
  -            try {
  -                mDataSoc = new Socket(mAddress, miPort); 
  -                mDataSoc.setSoTimeout(60000);                  
  +        try {
  +            if(mbPort) {
  +                mDataSoc = new Socket(mAddress, miPort);                  
               }
  -            catch(Exception ex) {
  -                mConfig.getLogger().warn("FtpDataConnection.getDataSocket()", ex);
  -                mDataSoc = null;
  +            else if(mbPasv) {
  +                mDataSoc = mServSoc.accept();
               }
           }
  -        else if(!mbPasv) {
  -            if (mDataSoc != null) {
  -                try { 
  -                    mDataSoc.close(); 
  -                } 
  -                catch(Exception ex) {
  -                    mConfig.getLogger().warn("FtpDataConnection.getDataSocket()", ex);
  -                }
  -                mDataSoc = null;
  -            }
  +        catch(Exception ex) {
  +            mConfig.getLogger().warn("FtpDataConnection.getDataSocket()", ex);
  +            mDataSoc = null;
           }
           
  -        // result check
           return mDataSoc;
       }
  +
       
  +   /**
  +     * Get the passive port. Later we shall use only predefined 
  +     * port range for passive connection.
  +     */
  +    private int getPassivePort() {
  +        return 0;
  +    }
  +    
  +    
  +    /**
  +     * Dispose data connection
  +     */ 
  +    public void dispose() {
  +        closeDataSocket();
  +        if (mServSoc != null) {
  +            try {
  +               mServSoc.close();
  +            }
  +            catch(Exception ex) {
  +                mConfig.getLogger().warn("FtpDataConnection.dispose()", ex);
  +            }
  +            mServSoc = null;
  +        }
  +    }
  +
   }
       
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message