/*
* 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.
*/
/*
*
* run from MarkResetTest.sh
*/
public class MarkResetTest {
/**
* A class that simulates, on a separate, an FTP server.
*/
private int port;
private boolean done = false;
private boolean pasvEnabled = true;
private boolean portEnabled = true;
private boolean extendedEnabled = true;
/**
* This Inner class will handle ONE client at a time.
* That's where 99% of the protocol handling is done.
*/
"TYPE", "RETR", "PASV",
"PORT", "QUIT", "EPSV"};
/**
* 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 {
client.getInputStream()));
return;
}
while (!done) {
try {
continue;
}
switch (res) {
case ERROR:
"': command not understood.");
break;
case USER:
waitpass = true;
} else {
}
break;
case PASS:
"access restrictions apply.");
logged = true;
waitpass = false;
} else
break;
case QUIT:
done = true;
break;
case TYPE:
break;
case CWD:
break;
case EPSV:
if (!extendedEnabled || !pasvEnabled) {
"use PORT instead.");
continue;
}
continue;
}
try {
} catch (IOException ssex) {
" Connection refused.");
}
break;
case PASV:
if (!pasvEnabled) {
"use PORT instead.");
continue;
}
try {
// Parenthesis are optional, so let's be
// nasty and don't put them
" 127,0,0,1," +
} catch (IOException ssex) {
"Connection refused.");
}
break;
case PORT:
if (!portEnabled) {
"use PASV instead");
continue;
}
int i = 0, j = 4;
while (j > 0) {
if (i < 0)
break;
j--;
}
if (j != 0) {
" command not understood.");
continue;
}
try {
data_port = 0;
" command not understood.");
}
break;
case RETR:
{
"' No such file or directory.");
break;
}
" for " + arg +
getHostAddress() + ") (" +
int c;
int len = 0;
len++;
}
} else {
" connection: Connection refused.");
}
}
break;
}
} catch (IOException ioe) {
try {
}
done = true;
}
}
}
}
}
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;
}
/*
* All we got to do here is create a ServerSocket and wait for a
* connection. When a connection happens, we just have to create
* a thread that will handle it.
*/
public void run() {
try {
} catch (Exception e) {
}
}
}
}
public MarkResetTest() {
try {
int port = 0;
while (port == 0) {
}
filename);
/**
* guessContentTypeFromStream method calls mark and reset methods
* on the given stream. Make sure that calling
* guessContentTypeFromStream repeatedly does not affect
* reading from the stream afterwards
*/
" several times..");
for (int i = 0; i < 5; i++) {
}
int len = 0;
int c;
len++;
}
// We're done!
// Did we pass ?
throw new Exception("Failed to read the file correctly");
}
} catch (Exception e) {
e.printStackTrace();
try {
}
}
}
}