1 /*
2 * SSHTools - Java SSH2 API
3 *
4 * Copyright (C) 2002-2003 Lee David Painter and Contributors.
5 *
6 * Contributions made by:
7 *
8 * Brett Smith
9 * Richard Pernavas
10 * Erwin Bolwidt
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 */
26 package com.sshtools.common.ui;
27
28 import com.sshtools.common.configuration.SshToolsConnectionProfile;
29
30 import com.sshtools.j2ssh.SftpClient;
31 import com.sshtools.j2ssh.SshEventAdapter;
32 import com.sshtools.j2ssh.connection.Channel;
33 import com.sshtools.j2ssh.connection.ChannelFactory;
34 import com.sshtools.j2ssh.forwarding.ForwardingClient;
35 import com.sshtools.j2ssh.session.SessionChannelClient;
36
37 import java.io.IOException;
38
39
40 /**
41 * <p>This interface is used by the Session Provider framework to abstract
42 * the SshClient connection away from the session provider. This restricts
43 * the session to performing operations that are allowed by the controlling
44 * application. For instance, the provider cannot simply diconnect the
45 * connection, since the SshClient's disconnect method is not exposed, instead
46 * a <code>requestDisconnect</code> method is provided allowing the controlling
47 * application to simply ignore a disconnect since it may have other sessions
48 * open.
49 * </p>
50 *
51 * <p>
52 * Most of the methods of this interface will simply be required to call the
53 * identical method on SshClient.
54 * </p>
55 *
56 * @author Lee David Painter
57 * @version $Revision: 1.11 $
58 */
59 public interface SessionManager {
60 /**
61 * Opens a session on the managed connection.
62 *
63 * @return
64 *
65 * @throws IOException
66 */
67 public SessionChannelClient openSession() throws IOException;
68
69 /**
70 * The session can call this method to apply any changes to the profile it
71 * may have made.
72 *
73 * @param profile
74 */
75 public void applyProfileChanges(SshToolsConnectionProfile profile);
76
77 /**
78 * Opens an SftpClient on the managed connection.
79 *
80 * @return
81 *
82 * @throws IOException
83 */
84 public SftpClient openSftpClient() throws IOException;
85
86 /**
87 * Opens a channel on the managed connection.
88 *
89 * @param channel
90 *
91 * @return
92 *
93 * @throws IOException
94 */
95 public boolean openChannel(Channel channel) throws IOException;
96
97 /**
98 * Determine if the managed connection is still connected.
99 *
100 * @return
101 */
102 public boolean isConnected();
103
104 /**
105 * Called when a session wants to disconnect the connection. The manager
106 * implementation should ideally not diconnect unless no other sessions
107 * are open.
108 *
109 * @return
110 */
111 public boolean requestDisconnect();
112
113 /**
114 * Gets the managed connections port forwarding client.
115 *
116 * @return
117 */
118 public ForwardingClient getForwardingClient();
119
120 /**
121 * Send a global request
122 *
123 * @param requestname
124 * @param wantreply
125 * @param requestdata
126 *
127 * @return
128 *
129 * @throws IOException
130 */
131 public byte[] sendGlobalRequest(String requestname, boolean wantreply,
132 byte[] requestdata) throws IOException;
133
134 /**
135 * Add an event handler to the managed connection
136 *
137 * @param eventHandler
138 */
139 public void addEventHandler(SshEventAdapter eventHandler);
140
141 /**
142 * Gets the identification string supplied by the server.
143 *
144 * @return
145 */
146 public String getServerId();
147
148 /**
149 * Returns the guessed EOL setting of the remote computer
150 * @return
151 */
152 public int getRemoteEOL();
153
154 /**
155 * Adds a channel factory to the managed connection.
156 *
157 * @param channelType
158 * @param cf
159 *
160 * @throws IOException
161 */
162 public void allowChannelOpen(String channelType, ChannelFactory cf)
163 throws IOException;
164
165 /**
166 * Get the current profile attached to the session.
167 *
168 * @return
169 */
170 public SshToolsConnectionProfile getProfile();
171 }