⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 session.cs

📁 Fireball.CodeEditor is an source code editor control derived from the best compona SyntaxBox Control
💻 CS
📖 第 1 页 / 共 4 页
字号:
							channel._eof_remote=true;
							channel.setRecipient(0);
							break;
						case SSH_MSG_CHANNEL_REQUEST:
							buf.getInt();
							buf.getShort();
							i=buf.getInt();
							foo=buf.getString();
							bool reply=(buf.getByte()!=0);
							channel=Channel.getChannel(i, this);
							if(channel!=null)
							{
								byte reply_type=(byte)SSH_MSG_CHANNEL_FAILURE;
								if((new String(foo)).equals("exit-status"))
								{
									i=buf.getInt();             // exit-status
									channel.setExitStatus(i);
									//	    System.Console.WriteLine("exit-stauts: "+i);
									//          channel.close();
									reply_type=(byte)SSH_MSG_CHANNEL_SUCCESS;
								}
								if(reply)
								{
									packet.reset();
									buf.putByte(reply_type);
									buf.putInt(channel.getRecipient());
									write(packet);
								}
							}
							else
							{
							}
							break;
						case SSH_MSG_CHANNEL_OPEN:
							buf.getInt();
							buf.getShort();
							foo=buf.getString();
							String ctyp=new String(foo);
							//System.Console.WriteLine("type="+ctyp);
							if(!new String("forwarded-tcpip").equals(ctyp) &&
								!(new String("x11").equals(ctyp) && x11_forwarding))
							{
								System.Console.WriteLine("Session.run: CHANNEL OPEN "+ctyp);
								throw new IOException("Session.run: CHANNEL OPEN "+ctyp);
							}
							else
							{
								channel=Channel.getChannel(ctyp);
								addChannel(channel);
								channel.getData(buf);
								channel.init();

								packet.reset();
								buf.putByte((byte)SSH_MSG_CHANNEL_OPEN_CONFIRMATION);
								buf.putInt(channel.getRecipient());
								buf.putInt(channel.id);
								buf.putInt(channel.lwsize);
								buf.putInt(channel.lmpsize);
								write(packet);
								Thread tmp=new Thread(channel);
								tmp.setName("Channel "+ctyp+" "+host);
								tmp.start();
								break;
							}
						case SSH_MSG_CHANNEL_SUCCESS:
							buf.getInt();
							buf.getShort();
							i=buf.getInt();
							channel=Channel.getChannel(i, this);
							if(channel==null)
							{
								break;
							}
							channel.reply=1;
							break;
						case SSH_MSG_CHANNEL_FAILURE:
							buf.getInt();
							buf.getShort();
							i=buf.getInt();
							channel=Channel.getChannel(i, this);
							if(channel==null)
							{
								break;
							}
							channel.reply=0;
							break;
						case SSH_MSG_GLOBAL_REQUEST:
							buf.getInt();
							buf.getShort();
							foo=buf.getString();       // request name
							reply=(buf.getByte()!=0);
							if(reply)
							{
								packet.reset();
								buf.putByte((byte)SSH_MSG_REQUEST_FAILURE);
								write(packet);
							}
							break;
						case SSH_MSG_REQUEST_FAILURE:
						case SSH_MSG_REQUEST_SUCCESS:
							Thread t=grr.getThread();
							if(t!=null)
							{
								grr.setReply(msgType==SSH_MSG_REQUEST_SUCCESS? 1 : 0);
								t.interrupt();
							}
							break;
						default:
							System.Console.WriteLine("Session.run: unsupported type "+msgType);
							throw new IOException("Unknown SSH message type "+msgType);
					}
				}
			}
			catch(Exception e)
			{
				//System.Console.WriteLine("# Session.run");
				//e.printStackTrace();
			}
			try
			{
				disconnect();
			}
			catch(NullReferenceException e)
			{
				//System.Console.WriteLine("@1");
				//e.printStackTrace();
			}
			catch(Exception e)
			{
				//System.Console.WriteLine("@2");
				//e.printStackTrace();
			}
			_isConnected=false;
		}

		/*
		public void finalize() throws Throwable{
		  disconnect();
		  jsch=null;
		}
		*/

		public void disconnect()
		{
			if(!_isConnected) return;

			//System.Console.WriteLine(this+": disconnect");
			//Thread.dumpStack();
			/*
			for(int i=0; i<Channel.pool.size(); i++){
			  try{
				Channel c=((Channel)(Channel.pool.elementAt(i)));
			if(c.session==this) c.eof();
			  }
			  catch(Exception e){
			  }
			}
			*/

			Channel.disconnect(this);

			_isConnected=false;

			PortWatcher.delPort(this);
			ChannelForwardedTCPIP.delPort(this);

			lock(connectThread)
			{
				connectThread.yield();
				connectThread.interrupt();
				connectThread=null;
			}
			thread=null;
			try
			{
				if(io!=null)
				{
					if(io.ins!=null) io.ins.Close();
					if(io.outs!=null) io.outs.Close();
					if(io.outs_ext!=null) io.outs_ext.Close();
				}
				if(proxy==null)
				{
					if(socket!=null)
						socket.close();
				}
				else
				{
					lock(proxy)
					{
						proxy.close();
					}
					proxy=null;
				}
			}
			catch(Exception e)
			{
				//      e.printStackTrace();
			}
			io=null;
			socket=null;
			//    lock(jsch.pool){
			//      jsch.pool.removeElement(this);
			//    }

			jsch.removeSession(this);

			//System.gc();
		}

		public void setPortForwardingL(int lport, String host, int rport) 
		{
			setPortForwardingL("127.0.0.1", lport, host,rport);
		}
		public void setPortForwardingL(String boundaddress, int lport, String host, int rport) 
		{
			setPortForwardingL(boundaddress, lport, host, rport, null);
		}
		public void setPortForwardingL(String boundaddress, int lport, String host, int rport, ServerSocketFactory ssf) 
		{
			PortWatcher pw=PortWatcher.addPort(this, boundaddress, lport, host, rport, ssf);
			Thread tmp=new Thread(pw);
			tmp.setName("PortWatcher Thread for "+host);
			tmp.start();
		}
		public void delPortForwardingL(int lport) 
		{
			delPortForwardingL("127.0.0.1", lport);
		}
		public void delPortForwardingL(String boundaddress, int lport) 
		{
			PortWatcher.delPort(this, boundaddress, lport);
		}
		public String[] getPortForwardingL() 
		{
			return PortWatcher.getPortForwarding(this);
		}

		public void setPortForwardingR(int rport, String host, int lport) 
		{
			setPortForwardingR(rport, host, lport, (SocketFactory)null);
		}
		public void setPortForwardingR(int rport, String host, int lport, SocketFactory sf) 
		{
			ChannelForwardedTCPIP.addPort(this, rport, host, lport, sf);
			setPortForwarding(rport);
		}

		public void setPortForwardingR(int rport, String daemon) 
		{
			setPortForwardingR(rport, daemon, null);
		}
		public void setPortForwardingR(int rport, String daemon, System.Object[] arg) 
		{
			ChannelForwardedTCPIP.addPort(this, rport, daemon, arg);
			setPortForwarding(rport);
		}

		private class GlobalRequestReply
		{
			private Thread thread=null;
			private int reply=-1;
			internal void setThread(Thread thread)
			{
				this.thread=thread;
				this.reply=-1;
			}
			internal Thread getThread(){ return thread; }
			internal void setReply(int reply){ this.reply=reply; }
			internal int getReply(){ return this.reply; }
		}
		private GlobalRequestReply grr=new GlobalRequestReply();
		private void setPortForwarding(int rport) 
		{
			lock(grr)
			{
				Buffer buf=new Buffer(100); // ??
				Packet packet=new Packet(buf);

				try
				{
					// byte SSH_MSG_GLOBAL_REQUEST 80
					// String "tcpip-forward"
					// bool want_reply
					// String  address_to_bind
					// uint32  port number to bind
					packet.reset();
					buf.putByte((byte) SSH_MSG_GLOBAL_REQUEST);
					buf.putString( new String( "tcpip-forward" ).getBytes());
					//      buf.putByte((byte)0);
					buf.putByte((byte)1);
					buf.putString(new String("0.0.0.0").getBytes());
					buf.putInt(rport);
					write(packet);
				}
				catch(Exception e)
				{
					throw new JSchException(e.ToString());
				}

				grr.setThread(Thread.currentThread());
				try{ Thread.Sleep(10000);}
				catch(Exception e)
				{
				}
				int reply=grr.getReply();
				grr.setThread(null);
				if(reply==0)
				{
					throw new JSchException("remote port forwarding failed for listen port "+rport);
				}
			}
		}
		public void delPortForwardingR(int rport) 
		{
			ChannelForwardedTCPIP.delPort(this, rport);
		}

		internal void addChannel(Channel channel)
		{
			channel.session=this;
		}
		public String getConfig(object name)
		{
			System.Object foo=null;
			if(config!=null)
			{
				foo=config.get(name);
				if(foo is String) return (String)foo;
				if(foo is string) return (string)foo;
			}
			foo=jsch.getConfig(name.ToString());
			if(foo is string) return (string)foo;
			if(foo is String) return (String)foo;
			return null;
		}
		//  public Channel getChannel(){ return channel; }
		public void setProxy(Proxy proxy){ this.proxy=proxy; }
		public void setHost(String host){ this.host=host; }
		public void setPort(int port){ this.port=port; }
		internal void setUserName(String foo){ this.username=foo; }
		public void setPassword(String foo){ this.password=foo; }
		public void setUserInfo(UserInfo userinfo){ this.userinfo=userinfo; }
		public void setInputStream(Stream In){ this.In=In; }
		public void setOutputStream(Stream Out){ this.Out=Out; }
		public void setX11Host(String host){ ChannelX11.setHost(host); }
		public void setX11Port(int port){ ChannelX11.setPort(port); }
		public void setX11Cookie(String cookie){ ChannelX11.setCookie(cookie); }

		public void setConfig(System.Collections.Hashtable foo)
		{
			setConfig( new Hashtable( foo ) );
		}

		public void setConfig(Hashtable foo)
		{
			if(config==null) config=new Hashtable();
			for(Enumeration e=foo.keys() ; e.hasMoreElements() ;) 
			{
				object key=e.nextElement();
				config.put(key, (foo.get(key)));
			}
		}
		public void setSocketFactory(SocketFactory foo){ socket_factory=foo;}
		public bool isConnected(){ return _isConnected; }
		public int getTimeout(){ return timeout; }
		public void setTimeout(int foo)  
		{
			if(socket==null)
			{
				if(foo<0)
				{
					throw new JSchException("invalid timeout value");
				}
				this.timeout=foo;
				return;
			}
			try
			{
				socket.setSoTimeout(foo);
				timeout=foo;
			}
			catch(Exception e)
			{
				throw new JSchException(e.ToString());
			}
		}
		public String getServerVersion()
		{
			return new String(V_S);
		}
		public String getClientVersion()
		{
			return new String(V_C);
		}
		public void setClientVersion(String cv)
		{
			V_C=cv.getBytes();
		}

		public void sendIgnore() 
		{
			Buffer buf=new Buffer();
			Packet packet=new Packet(buf);
			packet.reset();
			buf.putByte((byte)SSH_MSG_IGNORE);
			write(packet);
		}

		private HostKey hostkey=null;
		public HostKey getHostKey(){ return hostkey; }
		public String getHost(){return host;}
		public int getPort(){return port;}

		public String getMac()
		{
			String mac="";
			if(s2cmac!=null)
				mac = s2cmac.getName();
			return mac;

		}
		public String getCipher()
		{
			String cipher="";
			if(s2ccipher!=null)
				cipher= s2ccipher.ToString();
			return cipher;
		}

		public int BufferLength
		{
			get{return this.buf.buffer.Length;}
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -