(SocketFactory socket_factory, String host, int port, int timeout)
| 66 | this.passwd=passwd; |
| 67 | } |
| 68 | public void connect(SocketFactory socket_factory, String host, int port, int timeout) throws JSchException{ |
| 69 | try{ |
| 70 | if(socket_factory==null){ |
| 71 | socket=Util.createSocket(proxy_host, proxy_port, timeout); |
| 72 | in=socket.getInputStream(); |
| 73 | out=socket.getOutputStream(); |
| 74 | } |
| 75 | else{ |
| 76 | socket=socket_factory.createSocket(proxy_host, proxy_port); |
| 77 | in=socket_factory.getInputStream(socket); |
| 78 | out=socket_factory.getOutputStream(socket); |
| 79 | } |
| 80 | if(timeout>0){ |
| 81 | socket.setSoTimeout(timeout); |
| 82 | } |
| 83 | socket.setTcpNoDelay(true); |
| 84 | |
| 85 | out.write(Util.str2byte("CONNECT "+host+":"+port+" HTTP/1.0\r\n")); |
| 86 | |
| 87 | if(user!=null && passwd!=null){ |
| 88 | byte[] code=Util.str2byte(user+":"+passwd); |
| 89 | code=Util.toBase64(code, 0, code.length); |
| 90 | out.write(Util.str2byte("Proxy-Authorization: Basic ")); |
| 91 | out.write(code); |
| 92 | out.write(Util.str2byte("\r\n")); |
| 93 | } |
| 94 | |
| 95 | out.write(Util.str2byte("\r\n")); |
| 96 | out.flush(); |
| 97 | |
| 98 | int foo=0; |
| 99 | |
| 100 | StringBuffer sb=new StringBuffer(); |
| 101 | while(foo>=0){ |
| 102 | foo=in.read(); if(foo!=13){sb.append((char)foo); continue;} |
| 103 | foo=in.read(); if(foo!=10){continue;} |
| 104 | break; |
| 105 | } |
| 106 | if(foo<0){ |
| 107 | throw new IOException(); |
| 108 | } |
| 109 | |
| 110 | String response=sb.toString(); |
| 111 | String reason="Unknow reason"; |
| 112 | int code=-1; |
| 113 | try{ |
| 114 | foo=response.indexOf(' '); |
| 115 | int bar=response.indexOf(' ', foo+1); |
| 116 | code=Integer.parseInt(response.substring(foo+1, bar)); |
| 117 | reason=response.substring(bar+1); |
| 118 | } |
| 119 | catch(Exception e){ |
| 120 | } |
| 121 | if(code!=200){ |
| 122 | throw new IOException("proxy error: "+reason); |
| 123 | } |
| 124 | |
| 125 | /* |
nothing calls this directly
no test coverage detected