001: /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
002: /*
003: Copyright (c) 2005-2008 ymnk, JCraft,Inc. All rights reserved.
004:
005: Redistribution and use in source and binary forms, with or without
006: modification, are permitted provided that the following conditions are met:
007:
008: 1. Redistributions of source code must retain the above copyright notice,
009: this list of conditions and the following disclaimer.
010:
011: 2. Redistributions in binary form must reproduce the above copyright
012: notice, this list of conditions and the following disclaimer in
013: the documentation and/or other materials provided with the distribution.
014:
015: 3. The names of the authors may not be used to endorse or promote products
016: derived from this software without specific prior written permission.
017:
018: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
019: INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
020: FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
021: INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
022: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
023: LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
024: OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
027: EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: */
029:
030: package com.jcraft.jsch;
031:
032: public class ChannelSubsystem extends ChannelSession {
033: boolean xforwading = false;
034: boolean pty = false;
035: boolean want_reply = true;
036: String subsystem = "";
037:
038: public void setXForwarding(boolean foo) {
039: xforwading = true;
040: }
041:
042: public void setPty(boolean foo) {
043: pty = foo;
044: }
045:
046: public void setWantReply(boolean foo) {
047: want_reply = foo;
048: }
049:
050: public void setSubsystem(String foo) {
051: subsystem = foo;
052: }
053:
054: public void start() throws JSchException {
055: try {
056: Request request;
057: if (xforwading) {
058: request = new RequestX11();
059: request.request(session, this );
060: }
061: if (pty) {
062: request = new RequestPtyReq();
063: request.request(session, this );
064: }
065: request = new RequestSubsystem();
066: ((RequestSubsystem) request).request(session, this ,
067: subsystem, want_reply);
068: } catch (Exception e) {
069: if (e instanceof JSchException) {
070: throw (JSchException) e;
071: }
072: if (e instanceof Throwable)
073: throw new JSchException("ChannelSubsystem",
074: (Throwable) e);
075: throw new JSchException("ChannelSubsystem");
076: }
077: if (io.in != null) {
078: thread = new Thread(this );
079: thread.setName("Subsystem for " + session.host);
080: if (session.daemon_thread) {
081: thread.setDaemon(session.daemon_thread);
082: }
083: thread.start();
084: }
085: }
086:
087: //public void finalize() throws Throwable{ super.finalize(); }
088: public void init() {
089: io.setInputStream(session.in);
090: io.setOutputStream(session.out);
091: }
092:
093: public void setErrStream(java.io.OutputStream out) {
094: setExtOutputStream(out);
095: }
096:
097: public java.io.InputStream getErrStream()
098: throws java.io.IOException {
099: return getExtInputStream();
100: }
101: }
|