19d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair/*
29d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Copyright 2007 the original author or authors.
39d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *
49d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Licensed under the Apache License, Version 2.0 (the "License");
59d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * you may not use this file except in compliance with the License.
69d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * You may obtain a copy of the License at
79d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *
89d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *      http://www.apache.org/licenses/LICENSE-2.0
99d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *
109d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Unless required by applicable law or agreed to in writing, software
119d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * distributed under the License is distributed on an "AS IS" BASIS,
129d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * See the License for the specific language governing permissions and
149d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * limitations under the License.
159d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */
169d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairpackage org.mockftpserver.core.session;
179d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
189d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport java.net.InetAddress;
199d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport java.util.Set;
209d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
219d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair/**
229d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Represents an FTP session state and behavior
239d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *
249d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * @version $Revision$ - $Date$
259d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *
269d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * @author Chris Mair
279d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */
289d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairpublic interface Session extends Runnable {
299d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
309d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
319d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Close the session, closing the underlying sockets
329d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
339d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void close();
349d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
359d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
369d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Send the specified reply code and text across the control connection.
379d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     *
389d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @param replyCode - the reply code
399d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @param replyText - the reply text to send; may be null
409d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
419d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void sendReply(int replyCode, String replyText);
429d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
439d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
449d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Open the data connection, attaching to the predefined port number on the client
459d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
469d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void openDataConnection();
479d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
489d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
499d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Close the data connection
509d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
519d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void closeDataConnection();
529d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
539d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
549d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Switch to passive mode
559d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @return the local port to be connected to by clients for data transfers
569d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
579d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public int switchToPassiveMode();
589d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
599d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
609d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Write the specified data using the data connection
619d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     *
629d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @param data - the data to write
639d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @param numBytes - the number of bytes from data to send
649d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
659d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void sendData(byte[] data, int numBytes);
669d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
679d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
689d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Read data from the client across the data connection
699d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     *
709d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @return the data that was read
719d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
729d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public byte[] readData();
739d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
749d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
759d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Return the InetAddress representing the client host for this session
769d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @return the client host
779d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
789d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public InetAddress getClientHost();
799d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
809d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
819d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Return the InetAddress representing the server host for this session
829d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @return the server host
839d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
849d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public InetAddress getServerHost();
859d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
869d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
879d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @param clientHost - the client host for the data connection
889d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
899d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void setClientDataHost(InetAddress clientHost);
909d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
919d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
929d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @param clientDataPort - the port number on the client side for the data connection
939d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
949d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void setClientDataPort(int clientDataPort);
959d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
969d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
979d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Return the attribute value for the specified name. Return null if no attribute value
989d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * exists for that name or if the attribute value is null.
999d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @param name - the attribute name; may not be null
1009d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @return the value of the attribute stored under name; may be null
1019d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @throws AssertFailedException - if name is null
1029d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
1039d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public Object getAttribute(String name);
1049d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
1059d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
1069d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Store the value under the specified attribute name.
1079d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @param name - the attribute name; may not be null
1089d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @param value - the attribute value; may be null
1099d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @throws AssertFailedException - if name is null
1109d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
1119d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void setAttribute(String name, Object value);
1129d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
1139d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
1149d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Remove the attribute value for the specified name. Do nothing if no attribute
1159d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * value is stored for the specified name.
1169d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @param name - the attribute name; may not be null
1179d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @throws AssertFailedException - if name is null
1189d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
1199d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void removeAttribute(String name);
1209d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
1219d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
1229d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Return the Set of names under which attributes have been stored on this session.
1239d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Returns an empty Set if no attribute values are stored.
1249d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @return the Set of attribute names
1259d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
1269d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public Set getAttributeNames();
1279d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
1289d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair}