1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.waarp.ftp.core.control;
19
20 import io.netty.channel.Channel;
21 import org.waarp.common.command.exception.CommandAbstractException;
22 import org.waarp.common.file.Restart;
23 import org.waarp.common.file.filesystembased.FilesystemBasedOptsMLSxImpl;
24 import org.waarp.ftp.core.command.AbstractCommand;
25 import org.waarp.ftp.core.command.FtpCommandCode;
26 import org.waarp.ftp.core.data.FtpTransfer;
27 import org.waarp.ftp.core.file.FtpAuth;
28 import org.waarp.ftp.core.file.FtpDir;
29 import org.waarp.ftp.core.session.FtpSession;
30
31
32
33
34
35
36
37 public abstract class BusinessHandler {
38
39
40
41 private NetworkHandler networkHandler = null;
42
43
44
45
46 private FtpSession session = null;
47
48
49
50
51 public BusinessHandler() {
52
53 }
54
55
56
57
58
59
60
61 public void setNetworkHandler(NetworkHandler networkHandler) {
62 this.networkHandler = networkHandler;
63 session = this.networkHandler.getFtpSession();
64 }
65
66
67
68
69 public NetworkHandler getNetworkHandler() {
70 return networkHandler;
71 }
72
73
74
75
76
77
78 public FtpSession getFtpSession() {
79 return session;
80 }
81
82
83
84
85
86
87 public abstract FtpAuth getBusinessNewAuth();
88
89
90
91
92
93
94 public abstract FtpDir getBusinessNewDir();
95
96
97
98
99
100
101 public abstract Restart getBusinessNewRestart();
102
103
104
105
106
107
108
109 public abstract String getHelpMessage(String arg);
110
111
112
113
114
115 public abstract String getFeatMessage();
116
117 protected String getSslFeatMessage() {
118 StringBuilder builder = new StringBuilder().append("AUTH TLS\n").append("AUTH SSL\n")
119 .append("CCC\n").append("PROT P\n").append("PROT C");
120 return builder.toString();
121 }
122
123
124
125
126
127
128 protected String getDefaultFeatMessage() {
129 StringBuilder builder = new StringBuilder();
130 builder.append(FtpCommandCode.MDTM.name()).append('\n')
131 .append(FtpCommandCode.MLSD.name()).append(getFtpSession().getDir().getOptsMLSx().getFeat())
132 .append('\n')
133 .append(FtpCommandCode.MLST.name()).append(getFtpSession().getDir().getOptsMLSx().getFeat())
134 .append('\n')
135 .append(FtpCommandCode.SIZE.name()).append('\n')
136 .append(FtpCommandCode.XCUP.name()).append('\n')
137 .append(FtpCommandCode.XCWD.name()).append('\n')
138 .append(FtpCommandCode.XMKD.name()).append('\n')
139 .append(FtpCommandCode.XPWD.name()).append('\n')
140 .append(FtpCommandCode.XRMD.name()).append('\n')
141 .append(FtpCommandCode.PASV.name()).append('\n')
142 .append(FtpCommandCode.ALLO.name()).append('\n')
143 .append(FtpCommandCode.EPRT.name()).append('\n')
144 .append(FtpCommandCode.EPSV.name()).append('\n')
145 .append(FtpCommandCode.XCRC.name()).append(" \"filename\"").append('\n')
146 .append(FtpCommandCode.XMD5.name()).append(" \"filename\"").append('\n')
147 .append(FtpCommandCode.XSHA1.name()).append(" \"filename\"").append('\n')
148 .append(FtpCommandCode.SITE.name()).append(' ').append(FtpCommandCode.XCRC.name())
149
150 .append('\n')
151 .append(FtpCommandCode.SITE.name()).append(' ').append(FtpCommandCode.XMD5.name())
152
153 .append('\n')
154 .append(FtpCommandCode.SITE.name()).append(' ').append(FtpCommandCode.XSHA1.name())
155
156 .append('\n')
157 .append("LAN EN*").append('\n')
158 .append(FtpCommandCode.REST.name()).append(" STREAM\n");
159
160 return builder.toString();
161 }
162
163
164
165
166
167
168 public abstract String getOptsMessage(String[] args)
169 throws CommandAbstractException;
170
171
172
173
174
175
176
177
178 public abstract AbstractCommand getSpecializedSiteCommand(FtpSession session, String line);
179
180
181
182
183
184
185 protected String getMLSxOptsMessage(String[] args) {
186 String[] properties = new String[0];
187 if (args.length >= 2) {
188 properties = args[1].split(";");
189 }
190
191 FilesystemBasedOptsMLSxImpl optsMLSx = (FilesystemBasedOptsMLSxImpl) getFtpSession()
192 .getDir().getOptsMLSx();
193 optsMLSx.setOptsModify((byte) 0);
194 optsMLSx.setOptsPerm((byte) 0);
195 optsMLSx.setOptsSize((byte) 0);
196 optsMLSx.setOptsType((byte) 0);
197 for (int i = 0; i < properties.length; i++) {
198 if (properties[i].toLowerCase() == "modify") {
199 optsMLSx.setOptsModify((byte) 1);
200 } else if (properties[i].toLowerCase() == "perm") {
201 optsMLSx.setOptsPerm((byte) 1);
202 } else if (properties[i].toLowerCase() == "size") {
203 optsMLSx.setOptsSize((byte) 1);
204 } else if (properties[i].toLowerCase() == "type") {
205 optsMLSx.setOptsType((byte) 1);
206 }
207 }
208 return args[0] + " " + FtpCommandCode.OPTS.name() + optsMLSx.getFeat();
209 }
210
211
212
213
214
215
216
217 public abstract void executeChannelClosed();
218
219
220
221
222 protected abstract void cleanSession();
223
224
225
226
227
228 public void clear() {
229 cleanSession();
230 }
231
232
233
234
235
236
237
238 public abstract void executeChannelConnected(Channel channel);
239
240
241
242
243
244
245 public abstract void exceptionLocalCaught(Throwable e);
246
247
248
249
250
251
252
253 public abstract void beforeRunCommand() throws CommandAbstractException;
254
255
256
257
258
259
260
261
262 public abstract void afterRunCommandOk() throws CommandAbstractException;
263
264
265
266
267
268
269
270
271 public abstract void afterRunCommandKo(CommandAbstractException e);
272
273
274
275
276
277
278
279
280
281 public abstract void afterTransferDoneBeforeAnswer(FtpTransfer transfer)
282 throws CommandAbstractException;
283 }