LEFT | RIGHT |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package ssh | 5 package ssh |
6 | 6 |
7 // A Terminal is capable of parsing and generating virtual terminal | 7 // A Terminal is capable of parsing and generating virtual terminal |
8 // data from an SSH client. | 8 // data from an SSH client. |
9 type Terminal interface { | 9 type Terminal interface { |
10 ReadLine() (line string, err error) | 10 ReadLine() (line string, err error) |
(...skipping 30 matching lines...) Expand all Loading... |
41 } | 41 } |
42 return | 42 return |
43 } | 43 } |
44 | 44 |
45 func (ss *ServerTerminal) Write(buf []byte) (n int, err error) { | 45 func (ss *ServerTerminal) Write(buf []byte) (n int, err error) { |
46 return ss.Term.Write(buf) | 46 return ss.Term.Write(buf) |
47 } | 47 } |
48 | 48 |
49 // ReadLine returns a line of input from the terminal. | 49 // ReadLine returns a line of input from the terminal. |
50 func (ss *ServerTerminal) ReadLine() (line string, err error) { | 50 func (ss *ServerTerminal) ReadLine() (line string, err error) { |
51 » return ss.Term.ReadLine() | 51 » for { |
52 } | 52 » » if line, err = ss.Term.ReadLine(); err == nil { |
| 53 » » » return |
| 54 » » } |
| 55 » » req, ok := err.(ChannelRequest) |
| 56 » » if !ok { |
| 57 » » » return |
| 58 » » } |
53 | 59 |
54 func (ss *ServerTerminal) HandleRequests() { | 60 » » ok = false |
55 » for req := range ss.Channel.IncomingRequests() { | |
56 » » ok := false | |
57 switch req.Request { | 61 switch req.Request { |
58 case "pty-req": | 62 case "pty-req": |
59 var width, height int | 63 var width, height int |
60 width, height, ok = parsePtyRequest(req.Payload) | 64 width, height, ok = parsePtyRequest(req.Payload) |
61 ss.Term.SetSize(width, height) | 65 ss.Term.SetSize(width, height) |
62 case "shell": | 66 case "shell": |
63 ok = true | 67 ok = true |
64 if len(req.Payload) > 0 { | 68 if len(req.Payload) > 0 { |
65 // We don't accept any commands, only the defaul
t shell. | 69 // We don't accept any commands, only the defaul
t shell. |
66 ok = false | 70 ok = false |
67 } | 71 } |
68 case "env": | 72 case "env": |
69 ok = true | 73 ok = true |
70 } | 74 } |
71 if req.WantReply { | 75 if req.WantReply { |
72 ss.Channel.AckRequest(ok) | 76 ss.Channel.AckRequest(ok) |
73 } | 77 } |
74 } | 78 } |
| 79 panic("unreachable") |
75 } | 80 } |
LEFT | RIGHT |