1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package net.sf.hermesftp.common;
26
27 import java.io.BufferedReader;
28 import java.io.IOException;
29 import java.io.PrintWriter;
30 import java.net.Socket;
31 import java.util.Date;
32 import java.util.Map;
33
34 import net.sf.hermesftp.cmd.SocketProvider;
35 import net.sf.hermesftp.exception.FtpQuotaException;
36 import net.sf.hermesftp.usermanager.UserManager;
37 import net.sf.hermesftp.usermanager.model.UserData;
38
39 /***
40 * This class servers as a means of transportation for data shared by a single FTP session.
41 * Instances of the <code>FtpSessionContextImpl</code> class are passed to each of the commands
42 * while executing a FTP command sequence. The command objects read connection settings and other
43 * options from the context. In turn data that may concern the general state of the FTP session can
44 * be stored in the context.
45 *
46 * @author Lars Behnke
47 */
48 public interface FtpSessionContext {
49
50 /***
51 * Returns a sesson attribute.
52 *
53 * @param name Name of the attribute.
54 * @return Value of the attribute.
55 */
56 Object getAttribute(String name);
57
58 /***
59 * Sets a session attribute.
60 *
61 * @param name Name of the attribute.
62 * @param value Value of the attribute.
63 */
64 void setAttribute(String name, Object value);
65
66 /***
67 * @return The static server options as read from the configuration file.
68 */
69 FtpServerOptions getOptions();
70
71 /***
72 * Returns the value of an server option.
73 *
74 * @param key The option name.
75 * @return The value.
76 */
77 String getOption(String key);
78
79 /***
80 * Gets the user's password.
81 *
82 * @return The user's password.
83 */
84 String getPassword();
85
86 /***
87 * Sets the user's password.
88 *
89 * @param password The users password.
90 */
91 void setPassword(String password);
92
93 /***
94 * Gets the current remote directory.
95 *
96 * @return The remote directory.
97 */
98 String getRemoteDir();
99
100 /***
101 * Gets the relative path, with respect to the FTP root path.
102 *
103 * @return The path.
104 */
105 String getRemoteRelDir();
106
107 /***
108 * Sets the remote directory of the user's session.
109 *
110 * @param remoteDir The directory to set.
111 */
112 void setRemoteDir(String remoteDir);
113
114 /***
115 * Returns the login name of the user.
116 *
117 * @return The name.
118 */
119 String getUser();
120
121 /***
122 * Sets the login name of the user.
123 *
124 * @param user The user name.
125 */
126 void setUser(String user);
127
128 /***
129 * Returns the instance that listens to session events.
130 *
131 * @return The session listener.
132 */
133 FtpEventListener getEventListener();
134
135 /***
136 * Returns a named resource from a resource bundle.
137 *
138 * @param id The name of the resource.
139 * @return The resource.
140 */
141 String getRes(String id);
142
143 /***
144 * Checks whether user was successfully authenticated.
145 *
146 * @return True, user is authenticated.
147 */
148 boolean isAuthenticated();
149
150 /***
151 * Returns the current data type (ASCII, BINARY, EPBCDIC).
152 *
153 * @return The data type.
154 */
155 int getDataType();
156
157 /***
158 * Sets the current data type.
159 *
160 * @param dataType The data type.
161 */
162 void setDataType(int dataType);
163
164 /***
165 * Returns the transmission mode (Stream, Block, Compressed).
166 *
167 * @return The transmission mode.
168 */
169 int getTransmissionMode();
170
171 /***
172 * Sets the transmission mode (Stream, Block, Compressed).
173 *
174 * @param mode The transmission mode.
175 */
176 void setTransmissionMode(int mode);
177
178 /***
179 * Returns the storage structure (File, Record).
180 *
181 * @return The storage structure.
182 */
183 int getStorageStructure();
184
185 /***
186 * Sets the storage structure (File, Record).
187 *
188 * @param struct The storage structure..
189 */
190 void setStorageStructure(int struct);
191
192 /***
193 * Returns the object that provides the socket that is used for file transfer.
194 *
195 * @return The socket provider.
196 */
197 SocketProvider getDataSocketProvider();
198
199 /***
200 * Sets the provider that provides the socket that is used in file transfer.
201 *
202 * @param provider The socket provider.
203 */
204 void setDataSocketProvider(SocketProvider provider);
205
206 /***
207 * Returns the client communication socket.
208 *
209 * @return The socket.
210 */
211 Socket getClientSocket();
212
213 /***
214 * Sets the client communication socket.
215 *
216 * @param clientSocket The socket.
217 * @throws IOException Thrown if socket is invalid.
218 */
219 void setClientSocket(Socket clientSocket) throws IOException;
220
221 /***
222 * Returns the writer that is used to respond to client requests.
223 *
224 * @return Response writer.
225 */
226 PrintWriter getClientResponseWriter();
227
228 /***
229 * Returns the Reader that is used to read client commands.
230 *
231 * @return The reader.
232 */
233 BufferedReader getClientCmdReader();
234
235 /***
236 * Gets the user's permission on the passed path.
237 *
238 * @param path The path to check the permission on.
239 * @return The permission value.
240 */
241 int getPermission(String path);
242
243 /***
244 * Returns the user manager.
245 *
246 * @return The user manager.
247 */
248 UserManager getUserManager();
249
250 /***
251 * Returns the charset to be used for text output.
252 *
253 * @return The name of the charset.
254 */
255 String getCharset();
256
257 /***
258 * Returns the next available port from a user defined list of passive ports. If no port list
259 * was configured, 0 is returned. The port 0 makes a the system decide which port to use.
260 *
261 * @return The port for passive data transfer.
262 */
263 Integer getNextPassivePort();
264
265 /***
266 * @return True, if successful.
267 */
268 boolean authenticate();
269
270 /***
271 * Returns data about the current user.
272 *
273 * @return The user data.
274 */
275 UserData getUserData();
276
277 /***
278 * Resets the user's credentials and unflags the authentication.
279 */
280 void resetCredentials();
281
282 /***
283 * Closes all sockets involved in current session.
284 */
285 void closeSockets();
286
287 /***
288 * Date/time the session context was created.
289 *
290 * @param time The creation time.
291 */
292 void setCreationTime(Date time);
293
294 /***
295 * Date/time the session context was created.
296 *
297 * @return The creation time.
298 */
299 Date getCreationTime();
300
301 /***
302 * Returns the session statistics.
303 *
304 * @return The statistics.
305 */
306 Map<String, Long> getSessionStatistics();
307
308 /***
309 * Updates incremental statistics such as number of files downloaded, bytes transferred etc.
310 *
311 * @param countKey Name of the statistics.
312 * @param value Value.
313 * @throws FtpQuotaException Thrown if a limit has been exceeded.
314 */
315 void updateIncrementalStat(String countKey, long value) throws FtpQuotaException;
316
317 /***
318 * Updates the upload/download transfer rate taking the passed value into account.
319 *
320 * @param avgKey The name of the statistic.
321 * @param value The value
322 */
323 void updateAverageStat(String avgKey, int value);
324
325 /***
326 * Returns the maximum transfer rate (download stream) in KB/s.
327 *
328 * @return The rate.
329 */
330 int getMaxDownloadRate();
331
332 /***
333 * Returns the maximum transfer rate (upload stream) in KB/s.
334 *
335 * @return The rate.
336 */
337 int getMaxUploadRate();
338
339 }