1bda3441225e0607b5ced8b538123fd7c7a417910chrismair/*
2bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Copyright 2007 the original author or authors.
3bda3441225e0607b5ced8b538123fd7c7a417910chrismair *
4bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Licensed under the Apache License, Version 2.0 (the "License");
5bda3441225e0607b5ced8b538123fd7c7a417910chrismair * you may not use this file except in compliance with the License.
6bda3441225e0607b5ced8b538123fd7c7a417910chrismair * You may obtain a copy of the License at
7bda3441225e0607b5ced8b538123fd7c7a417910chrismair *
8bda3441225e0607b5ced8b538123fd7c7a417910chrismair *      http://www.apache.org/licenses/LICENSE-2.0
9bda3441225e0607b5ced8b538123fd7c7a417910chrismair *
10bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Unless required by applicable law or agreed to in writing, software
11bda3441225e0607b5ced8b538123fd7c7a417910chrismair * distributed under the License is distributed on an "AS IS" BASIS,
12bda3441225e0607b5ced8b538123fd7c7a417910chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13bda3441225e0607b5ced8b538123fd7c7a417910chrismair * See the License for the specific language governing permissions and
14bda3441225e0607b5ced8b538123fd7c7a417910chrismair * limitations under the License.
15bda3441225e0607b5ced8b538123fd7c7a417910chrismair */
16bda3441225e0607b5ced8b538123fd7c7a417910chrismairpackage org.mockftpserver.core.session;
17bda3441225e0607b5ced8b538123fd7c7a417910chrismair
18bda3441225e0607b5ced8b538123fd7c7a417910chrismairimport java.net.InetAddress;
19bda3441225e0607b5ced8b538123fd7c7a417910chrismairimport java.util.Set;
20bda3441225e0607b5ced8b538123fd7c7a417910chrismair
21bda3441225e0607b5ced8b538123fd7c7a417910chrismair/**
22bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Represents an FTP session state and behavior
23bda3441225e0607b5ced8b538123fd7c7a417910chrismair *
24bda3441225e0607b5ced8b538123fd7c7a417910chrismair * @version $Revision$ - $Date$
25bda3441225e0607b5ced8b538123fd7c7a417910chrismair *
26bda3441225e0607b5ced8b538123fd7c7a417910chrismair * @author Chris Mair
27bda3441225e0607b5ced8b538123fd7c7a417910chrismair */
28bda3441225e0607b5ced8b538123fd7c7a417910chrismairpublic interface Session extends Runnable {
29bda3441225e0607b5ced8b538123fd7c7a417910chrismair
30bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
31bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Close the session, closing the underlying sockets
32bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
33bda3441225e0607b5ced8b538123fd7c7a417910chrismair    public void close();
34bda3441225e0607b5ced8b538123fd7c7a417910chrismair
35bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
36bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Send the specified reply code and text across the control connection.
37bda3441225e0607b5ced8b538123fd7c7a417910chrismair     *
38bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @param replyCode - the reply code
39bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @param replyText - the reply text to send; may be null
40bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
41bda3441225e0607b5ced8b538123fd7c7a417910chrismair    public void sendReply(int replyCode, String replyText);
42bda3441225e0607b5ced8b538123fd7c7a417910chrismair
43bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
44bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Open the data connection, attaching to the predefined port number on the client
45bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
46bda3441225e0607b5ced8b538123fd7c7a417910chrismair    public void openDataConnection();
47bda3441225e0607b5ced8b538123fd7c7a417910chrismair
48bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
49bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Close the data connection
50bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
51bda3441225e0607b5ced8b538123fd7c7a417910chrismair    public void closeDataConnection();
52bda3441225e0607b5ced8b538123fd7c7a417910chrismair
53bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
54bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Switch to passive mode
55bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @return the local port to be connected to by clients for data transfers
56bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
57bda3441225e0607b5ced8b538123fd7c7a417910chrismair    public int switchToPassiveMode();
58bda3441225e0607b5ced8b538123fd7c7a417910chrismair
59bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
60bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Write the specified data using the data connection
61bda3441225e0607b5ced8b538123fd7c7a417910chrismair     *
62bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @param data - the data to write
63bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @param numBytes - the number of bytes from data to send
64bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
65bda3441225e0607b5ced8b538123fd7c7a417910chrismair    public void sendData(byte[] data, int numBytes);
66bda3441225e0607b5ced8b538123fd7c7a417910chrismair
67bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
68bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Read data from the client across the data connection
69bda3441225e0607b5ced8b538123fd7c7a417910chrismair     *
70bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @return the data that was read
71bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
72bda3441225e0607b5ced8b538123fd7c7a417910chrismair    public byte[] readData();
73bda3441225e0607b5ced8b538123fd7c7a417910chrismair
74bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
75bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Read and return (up to) numBytes of data from the client across the data connection
76bda3441225e0607b5ced8b538123fd7c7a417910chrismair     *
77bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @return the data that was read; the byte[] will be up to numBytes bytes long
78bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
79bda3441225e0607b5ced8b538123fd7c7a417910chrismair    public byte[] readData(int numBytes);
80bda3441225e0607b5ced8b538123fd7c7a417910chrismair
81bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
82bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Return the InetAddress representing the client host for this session
83bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @return the client host
84bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
85bda3441225e0607b5ced8b538123fd7c7a417910chrismair    public InetAddress getClientHost();
86bda3441225e0607b5ced8b538123fd7c7a417910chrismair
87bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
88bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Return the InetAddress representing the server host for this session
89bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @return the server host
90bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
91bda3441225e0607b5ced8b538123fd7c7a417910chrismair    public InetAddress getServerHost();
92bda3441225e0607b5ced8b538123fd7c7a417910chrismair
93bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
94bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @param clientHost - the client host for the data connection
95bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
96bda3441225e0607b5ced8b538123fd7c7a417910chrismair    public void setClientDataHost(InetAddress clientHost);
97bda3441225e0607b5ced8b538123fd7c7a417910chrismair
98bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
99bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @param clientDataPort - the port number on the client side for the data connection
100bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
101bda3441225e0607b5ced8b538123fd7c7a417910chrismair    public void setClientDataPort(int clientDataPort);
102bda3441225e0607b5ced8b538123fd7c7a417910chrismair
103bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
104bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Return the attribute value for the specified name. Return null if no attribute value
105bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * exists for that name or if the attribute value is null.
106bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @param name - the attribute name; may not be null
107bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @return the value of the attribute stored under name; may be null
108bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @throws AssertFailedException - if name is null
109bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
110bda3441225e0607b5ced8b538123fd7c7a417910chrismair    public Object getAttribute(String name);
111bda3441225e0607b5ced8b538123fd7c7a417910chrismair
112bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
113bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Store the value under the specified attribute name.
114bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @param name - the attribute name; may not be null
115bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @param value - the attribute value; may be null
116bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @throws AssertFailedException - if name is null
117bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
118bda3441225e0607b5ced8b538123fd7c7a417910chrismair    public void setAttribute(String name, Object value);
119bda3441225e0607b5ced8b538123fd7c7a417910chrismair
120bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
121bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Remove the attribute value for the specified name. Do nothing if no attribute
122bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * value is stored for the specified name.
123bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @param name - the attribute name; may not be null
124bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @throws AssertFailedException - if name is null
125bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
126bda3441225e0607b5ced8b538123fd7c7a417910chrismair    public void removeAttribute(String name);
127bda3441225e0607b5ced8b538123fd7c7a417910chrismair
128bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
129bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Return the Set of names under which attributes have been stored on this session.
130bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Returns an empty Set if no attribute values are stored.
131bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @return the Set of attribute names
132bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
133bda3441225e0607b5ced8b538123fd7c7a417910chrismair    public Set getAttributeNames();
134bda3441225e0607b5ced8b538123fd7c7a417910chrismair
135bda3441225e0607b5ced8b538123fd7c7a417910chrismair}