/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4398880
* @summary FTP URL processing modified to conform to RFC 1738
*/
public class FtpURL {
/**
* A class that simulates, on a separate, an FTP server.
*/
private int port;
private boolean done = false;
private boolean portEnabled = true;
private boolean pasvEnabled = true;
private boolean list = false;
/**
* This Inner class will handle ONE client at a time.
* That's where 99% of the protocol handling is done.
*/
private class FtpServerHandler {
"NOOP", "RETR", "PASV", "PORT", "LIST", "REIN",
"QUIT", "STOR", "NLST", "RNFR", "RNTO" };
/**
* Parses a line to match it with one of the supported FTP commands.
* Returns the command number.
*/
return ERROR;
if (blank < 0)
if (blank < 3)
return ERROR;
else
if (s.equalsIgnoreCase(cmds[i]))
return i+1;
}
return ERROR;
}
}
protected boolean isPasvSet() {
try {
} catch (IOException ex) {
}
}
return true;
return false;
}
/**
* Open the data socket with the client. This can be the
* result of a "PASV" or "PORT" command.
*/
try {
if (isPasvSet()) {
return s.getOutputStream();
}
data_port = 0;
return s.getOutputStream();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
try {
if (isPasvSet()) {
return s.getInputStream();
}
data_port = 0;
return s.getInputStream();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* Handles the protocol exchange with the client.
*/
public void run() {
boolean done = false;
int res;
boolean logged = false;
boolean waitpass = false;
try {
return;
}
synchronized (FtpServer.this) {
while (!done) {
try {
continue;
}
switch (res) {
case ERROR:
break;
case USER:
logged = true;
} else {
waitpass = true;
}
} else {
}
break;
case PASS:
logged = true;
waitpass = false;
} else
break;
case QUIT:
done = true;
break;
case TYPE:
break;
case CWD:
else
break;
case CDUP:
break;
case PWD:
break;
case PASV:
if (!pasvEnabled) {
continue;
}
try {
} catch (IOException ssex) {
}
break;
case PORT:
if (!portEnabled) {
continue;
}
int i=0, j=4;
while (j>0) {
if (i < 0)
break;
j--;
}
if (j != 0) {
continue;
}
try {
data_port = 0;
}
break;
case RETR:
{
list = false;
} else
}
break;
case NLST:
case LIST:
{
list = true;
try {
} catch (Exception e) {}
} else
}
break;
case STOR:
{
int val;
do {
} while (val != -1);
} else
}
break;
}
} catch (IOException ioe) {
try {
}
done = true;
}
}
}
}
}
try {
} catch (IOException e) {
}
}
public FtpServer() {
this(21);
}
public int getPort() {
return server.getLocalPort();
return 0;
}
/**
* A way to tell the server that it can stop.
*/
synchronized public void terminate() {
done = true;
}
portEnabled = ok;
}
pasvEnabled = ok;
}
return username;
}
return password;
}
return cwd;
}
return filename;
}
return type;
}
synchronized boolean getList() {
notify ();
return list;
}
/*
* All we got to do here is create a ServerSocket and wait for connections.
* When a connection happens, we just have to create a thread that will
* handle it.
*/
public void run() {
try {
for (int i=0; i<2; i++) {
}
} catch(Exception e) {
} finally {
}
}
}
}
try {
// Now let's check the URL handler
String s;
do {
} while (s != null);
throw new RuntimeException("Inccorect username received");
throw new RuntimeException("Inccorect password received");
throw new RuntimeException("Inccorect directory received");
throw new RuntimeException("Inccorect username received");
throw new RuntimeException("Incorrect type received");
// We're done!
// Second URL test
// Now let's check the URL handler
do {
} while (s != null);
throw new RuntimeException(";type=d didn't generate a NLST");
throw new RuntimeException("password should be null!");
throw new RuntimeException("Incorrect filename received");
throw new RuntimeException("Incorrect pwd received");
// We're done!
} catch (Exception e) {
} finally {
}
}
}