001: /*
002: * This file is part of DrFTPD, Distributed FTP Daemon.
003: *
004: * DrFTPD is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * DrFTPD is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with DrFTPD; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018: package net.sf.drftpd.master;
019:
020: import java.io.Serializable;
021:
022: /**
023: * Ftp command request class. We can access command, line and argument using
024: * <code>{CMD}, {ARG}</code> within ftp status file. This represents
025: * single Ftp request.
026: *
027: * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
028: * @version $Id: FtpRequest.java 690 2004-08-03 20:14:12Z zubov $
029: */
030: public class FtpRequest implements Serializable {
031: private String line = null;
032: private String command = null;
033: private String argument = null;
034:
035: /**
036: * Constructor.
037: *
038: * @param commandLine ftp input command line.
039: */
040: public FtpRequest(String commandLine) {
041: line = commandLine.trim();
042: parse();
043: }
044:
045: /**
046: * Parse the ftp command line.
047: */
048: private void parse() {
049: int spInd = line.indexOf(' ');
050:
051: if (spInd != -1) {
052: command = line.substring(0, spInd).toUpperCase();
053: argument = line.substring(spInd + 1);
054:
055: if (command.equals("SITE")) {
056: spInd = line.indexOf(' ', spInd + 1);
057:
058: if (spInd != -1) {
059: command = line.substring(0, spInd).toUpperCase();
060: argument = line.substring(spInd + 1);
061: } else {
062: command = line.toUpperCase();
063: argument = null;
064: }
065: }
066: } else {
067: command = line.toUpperCase();
068: argument = null;
069: }
070:
071: // if ((command.length() > 0) && (command.charAt(0) == 'X')) {
072: // command = command.substring(1);
073: // }
074: }
075:
076: /**
077: * Get the ftp command.
078: */
079: public String getCommand() {
080: return command;
081: }
082:
083: /**
084: * Get ftp input argument.
085: */
086: public String getArgument() {
087: if (argument == null) {
088: throw new IllegalStateException();
089: }
090:
091: return argument;
092: }
093:
094: /**
095: * Get the ftp request line.
096: */
097: public String getCommandLine() {
098: return line;
099: }
100:
101: /**
102: * Has argument.
103: */
104: public boolean hasArgument() {
105: return argument != null;
106: }
107: }
|