KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > drftpd > master > command > plugins > Misc


1 /*
2  * This file is part of DrFTPD, Distributed FTP Daemon.
3  *
4  * DrFTPD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * DrFTPD is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with DrFTPD; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package net.sf.drftpd.master.command.plugins;
19
20 import java.io.PrintWriter JavaDoc;
21 import java.util.Date JavaDoc;
22 import java.util.Iterator JavaDoc;
23
24 import net.sf.drftpd.master.BaseFtpConnection;
25 import net.sf.drftpd.master.FtpReply;
26 import net.sf.drftpd.master.command.CommandManager;
27 import net.sf.drftpd.master.command.CommandManagerFactory;
28 import net.sf.drftpd.slave.SlaveImpl;
29
30 import org.drftpd.commands.CommandHandler;
31 import org.drftpd.commands.CommandHandlerFactory;
32 import org.drftpd.commands.UnhandledCommandException;
33
34 /**
35  * @version $Id: Misc.java,v 1.8.2.1 2004/06/19 23:37:26 mog Exp $
36  */

37 public class Misc implements CommandHandlerFactory, CommandHandler {
38     /**
39      * <code>ABOR &lt;CRLF&gt;</code><br>
40      *
41      * This command tells the server to abort the previous FTP
42      * service command and any associated transfer of data.
43      * No action is to be taken if the previous command
44      * has been completed (including data transfer). The control
45      * connection is not to be closed by the server, but the data
46      * connection must be closed.
47      * Current implementation does not do anything. As here data
48      * transfers are not multi-threaded.
49      */

50     private FtpReply doABOR(BaseFtpConnection conn) {
51         return FtpReply.RESPONSE_226_CLOSING_DATA_CONNECTION;
52     }
53
54     // LIST;NLST;RETR;STOR
55
private FtpReply doFEAT(BaseFtpConnection conn) {
56         PrintWriter JavaDoc out = conn.getControlWriter();
57         out.print("211-Extensions supported:\r\n");
58         for (Iterator JavaDoc iter = conn.getCommandManager().getCommandHandlersMap().values().iterator(); iter.hasNext();) {
59             CommandHandler hnd = (CommandHandler) iter.next();
60             String JavaDoc feat[] = hnd.getFeatReplies();
61             if(feat == null) continue;
62             for (int i = 0; i < feat.length; i++) {
63                 out.print(" "+feat[i]+"\r\n");
64             }
65         }
66 // + " CLNT\r\n"
67
// + " MDTM\r\n"
68
// + " PRET\r\n"
69
// + " SIZE\r\n"
70
// + " XCRC\r\n"
71
out.print("211 End\r\n");
72         return null;
73     }
74
75     /**
76      * <code>HELP [&lt;SP&gt; <string>] &lt;CRLF&gt;</code><br>
77      *
78      * This command shall cause the server to send helpful
79      * information regarding its implementation status over the
80      * control connection to the user. The command may take an
81      * argument (e.g., any command name) and return more specific
82      * information as a response.
83      */

84     //TODO implement HELP, SITE HELP would be good too.
85
// public FtpReply doHELP(BaseFtpConnection conn) {
86
//
87
// print global help
88
// if (!request.hasArgument()) {
89
// FtpReply response = new FtpReply(214);
90
// response.addComment("The following commands are recognized.");
91
//out.write(ftpStatus.getResponse(214, null, user, null));
92
// Method methods[] = this.getClass().getDeclaredMethods();
93
// for (int i = 0; i < methods.length; i++) {
94
// Method method = methods[i];
95
// Class parameterTypes[] = method.getParameterTypes();
96
// if (parameterTypes.length == 2
97
// && parameterTypes[0] == FtpRequest.class
98
// && parameterTypes[1] == PrintWriter.class) {
99
// String commandName =
100
// method.getName().substring(2).replace('_', ' ');
101
// response.addComment(commandName);
102
// }
103
// }
104
// out.print(response);
105
// return;
106
// }
107
//
108
// // print command specific help
109
// String ftpCmd = request.getArgument().toUpperCase();
110
// String args[] = null;
111
// FtpRequest tempRequest = new FtpRequest(ftpCmd);
112
// out.write(ftpStatus.getResponse(214, tempRequest, user, args));
113
// return;
114
// }
115

116     private FtpReply doSITE_STAT(BaseFtpConnection conn) {
117         if (conn.getRequest().hasArgument()) {
118             return FtpReply.RESPONSE_504_COMMAND_NOT_IMPLEMENTED_FOR_PARM;
119         }
120         FtpReply response = (FtpReply) FtpReply.RESPONSE_200_COMMAND_OK.clone();
121         
122         response.addComment(conn.status());
123         return response;
124     }
125
126     private FtpReply doSITE_TIME(BaseFtpConnection conn) {
127         if (conn.getRequest().hasArgument()) {
128             return FtpReply.RESPONSE_501_SYNTAX_ERROR;
129         }
130         return new FtpReply(200, "Server time is: " + new Date JavaDoc());
131     }
132
133     private FtpReply doSITE_VERS(BaseFtpConnection conn) {
134         return new FtpReply(200, SlaveImpl.VERSION);
135     }
136
137     public FtpReply execute(BaseFtpConnection conn) throws UnhandledCommandException {
138         String JavaDoc cmd = conn.getRequest().getCommand();
139         if("ABOR".equals(cmd)) return doABOR(conn);
140         if("FEAT".equals(cmd)) return doFEAT(conn);
141         if("SITE STAT".equals(cmd)) return doSITE_STAT(conn);
142         if("SITE TIME".equals(cmd)) return doSITE_TIME(conn);
143         if("SITE VERS".equals(cmd)) return doSITE_VERS(conn);
144         throw UnhandledCommandException.create(Misc.class, conn.getRequest());
145     }
146
147     public CommandHandler initialize(BaseFtpConnection conn, CommandManager initializer) {
148         return this;
149     }
150
151     public String JavaDoc[] getFeatReplies() {
152         return null;
153     }
154
155     public void load(CommandManagerFactory initializer) {}
156     public void unload() {}
157
158 }
159
Popular Tags