You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by ng...@apache.org on 2011/05/11 11:53:05 UTC

svn commit: r1101808 - in /mina/ftpserver/trunk/core/src: main/java/org/apache/ftpserver/command/impl/OPTS_MLST.java test/java/org/apache/ftpserver/clienttests/ListTest.java

Author: ngn
Date: Wed May 11 09:53:05 2011
New Revision: 1101808

URL: http://svn.apache.org/viewvc?rev=1101808&view=rev
Log:
Fixing bug where FtpServer returned an error if an unknown fact was used in OPTS MLST. Also, correctly handling the case if only file names (no facts) are wished by the client (FTPSERVER-412)

Modified:
    mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/OPTS_MLST.java
    mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/ListTest.java

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/OPTS_MLST.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/OPTS_MLST.java?rev=1101808&r1=1101807&r2=1101808&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/OPTS_MLST.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/OPTS_MLST.java Wed May 11 09:53:05 2011
@@ -20,6 +20,8 @@
 package org.apache.ftpserver.command.impl;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.StringTokenizer;
 
 import org.apache.ftpserver.command.AbstractCommand;
@@ -55,22 +57,23 @@ public class OPTS_MLST extends AbstractC
 
         // get the listing types
         String argument = request.getArgument();
+
+        String listTypes;
+        String types[];
         int spIndex = argument.indexOf(' ');
         if (spIndex == -1) {
-            session.write(LocalizedFtpReply.translate(session, request, context,
-                    FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS, "OPTS.MLST",
-                    null));
-            return;
-        }
-        String listTypes = argument.substring(spIndex + 1);
-
-        // parse all the type tokens
-        StringTokenizer st = new StringTokenizer(listTypes, ";");
-        String types[] = new String[st.countTokens()];
-        for (int i = 0; i < types.length; ++i) {
-            types[i] = st.nextToken();
+            types = new String[0];
+            listTypes = "";
+        } else {
+            listTypes = argument.substring(spIndex + 1);
+    
+            // parse all the type tokens
+            StringTokenizer st = new StringTokenizer(listTypes, ";");
+            types = new String[st.countTokens()];
+            for (int i = 0; i < types.length; ++i) {
+                types[i] = st.nextToken();
+            }
         }
-
         // set the list types
         String[] validatedTypes = validateSelectedTypes(types);
         if (validatedTypes != null) {
@@ -88,26 +91,20 @@ public class OPTS_MLST extends AbstractC
 
         // ignore null types
         if (types == null) {
-            return null;
+            return new String[0];
         }
 
+        List<String> selectedTypes = new ArrayList<String>();
         // check all the types
         for (int i = 0; i < types.length; ++i) {
-            boolean bMatch = false;
             for (int j = 0; j < AVAILABLE_TYPES.length; ++j) {
                 if (AVAILABLE_TYPES[j].equalsIgnoreCase(types[i])) {
-                    bMatch = true;
+                    selectedTypes.add(AVAILABLE_TYPES[j]);
                     break;
                 }
             }
-            if (!bMatch) {
-                return null;
-            }
         }
 
-        // set the user types
-        String[] selectedTypes = new String[types.length];
-        System.arraycopy(types, 0, selectedTypes, 0, types.length);
-        return selectedTypes;
+        return selectedTypes.toArray(new String[0]);
     }
 }

Modified: mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/ListTest.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/ListTest.java?rev=1101808&r1=1101807&r2=1101808&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/ListTest.java (original)
+++ mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/ListTest.java Wed May 11 09:53:05 2011
@@ -232,13 +232,51 @@ public class ListTest extends ClientTest
                 + TEST_FILE1.getName(), reply[1]);
     }
 
-    public void testOPTSMLSTInvalidType() throws Exception {
+    /**
+     * "Facts requested that are not
+     * supported, or that are inappropriate to the file or directory being
+     * listed should simply be omitted from the MLSx output."
+     * 
+     * http://tools.ietf.org/html/rfc3659#section-7.9
+     */
+    public void testOPTSMLSTUnknownFact() throws Exception {
         TEST_FILE1.createNewFile();
 
-        assertTrue(FTPReply.isNegativePermanent(client
+        assertTrue(FTPReply.isPositiveCompletion(client
                 .sendCommand("OPTS MLST Foo;Size")));
+        
+        assertTrue(FTPReply.isPositiveCompletion(client.sendCommand("MLST "
+                + TEST_FILE1.getName())));
+        
+        String[] reply = client.getReplyString().split("\\r\\n");
+        
+        assertEquals("Size=0; "
+                + TEST_FILE1.getName(), reply[1]);
+    }
+
+    /**
+     * "Facts requested that are not
+     * supported, or that are inappropriate to the file or directory being
+     * listed should simply be omitted from the MLSx output."
+     * 
+     * http://tools.ietf.org/html/rfc3659#section-7.9
+     */
+    public void testOPTSMLSTNoFacts() throws Exception {
+        TEST_FILE1.createNewFile();
+
+        assertTrue(FTPReply.isPositiveCompletion(client
+                .sendCommand("OPTS MLST")));
+        
+        assertTrue(FTPReply.isPositiveCompletion(client.sendCommand("MLST "
+                + TEST_FILE1.getName())));
+        
+        String[] reply = client.getReplyString().split("\\r\\n");
+        
+        assertEquals(" "
+                + TEST_FILE1.getName(), reply[1]);
     }
 
+    
     private FTPFile getFile(FTPFile[] files, String name) {
         for (int i = 0; i < files.length; i++) {
             FTPFile file = files[i];