1 | /******************************************************************************
|
---|
2 | *
|
---|
3 | * Copyright (c) 1998,99 by Mindbright Technology AB, Stockholm, Sweden.
|
---|
4 | * www.mindbright.se, [email protected]
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | *****************************************************************************
|
---|
17 | * $Author: mats $
|
---|
18 | * $Date: 2000/03/07 16:44:34 $
|
---|
19 | * $Name: rel1-2-1 $
|
---|
20 | *****************************************************************************/
|
---|
21 | package mindbright.ssh;
|
---|
22 |
|
---|
23 | public abstract class SSHChannel extends Thread {
|
---|
24 |
|
---|
25 | protected int channelId;
|
---|
26 | protected SSHChannelListener listener;
|
---|
27 |
|
---|
28 | public SSHChannel(int channelId) {
|
---|
29 | super();
|
---|
30 | this.channelId = channelId;
|
---|
31 | this.listener = null;
|
---|
32 | }
|
---|
33 |
|
---|
34 | public void setSSHChannelListener(SSHChannelListener listener) {
|
---|
35 | this.listener = listener;
|
---|
36 | }
|
---|
37 |
|
---|
38 | public int getId() {
|
---|
39 | return channelId;
|
---|
40 | }
|
---|
41 |
|
---|
42 | public abstract void serviceLoop() throws Exception;
|
---|
43 |
|
---|
44 | public void close() {
|
---|
45 | }
|
---|
46 |
|
---|
47 | public void run() {
|
---|
48 |
|
---|
49 | if(SSH.NETSCAPE_SECURITY_MODEL) {
|
---|
50 | try {
|
---|
51 | netscape.security.PrivilegeManager.enablePrivilege("TerminalEmulator");
|
---|
52 | } catch (netscape.security.ForbiddenTargetException e) {
|
---|
53 | // !!! A pity, we could have done so much fun... :-)
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | try {
|
---|
58 | serviceLoop();
|
---|
59 | } catch (Exception e) {
|
---|
60 |
|
---|
61 | if(SSH.DEBUGMORE) {
|
---|
62 | System.out.println("--- channel exit (exception is not an error):");
|
---|
63 | e.printStackTrace();
|
---|
64 | System.out.println("---");
|
---|
65 | }
|
---|
66 |
|
---|
67 | close();
|
---|
68 | if(listener != null)
|
---|
69 | listener.close(this);
|
---|
70 |
|
---|
71 | } catch (ThreadDeath death) {
|
---|
72 | SSH.logExtra("Channel killed " + channelId);
|
---|
73 | throw death;
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | }
|
---|