forked from aprice/telnet
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathttype.go
47 lines (35 loc) · 1.47 KB
/
ttype.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package options
import "github.com/PatrickRudolph/telnet"
// TerminalType Telnet Option - https://tools.ietf.org/html/rfc857
// TerminalTypeOption enables NAWS negotiation on a Server.
func TerminalTypeOption(c *telnet.Connection) telnet.Negotiator {
return &TerminalTypeHandler{client: false}
}
// TerminalTypeHandler negotiates TerminalType for a specific connection.
type TerminalTypeHandler struct {
client bool
}
// OptionCode returns with the code used to negotiate TerminalType modes.
func (e *TerminalTypeHandler) OptionCode() byte {
return telnet.TeloptTTYPE
}
// Offer is called when a new connection is initiated. It offers the handler
// an opportunity to advertise or request an option.
func (e *TerminalTypeHandler) Offer(c *telnet.Connection) {
if !e.client {
c.Conn.Write([]byte{telnet.IAC, telnet.WILL, e.OptionCode()})
}
}
// HandleDo is called when an IAC DO command is received for this option,
// indicating the client is requesting the option to be enabled.
func (e *TerminalTypeHandler) HandleDo(c *telnet.Connection) {
}
// HandleWill is called when an IAC WILL command is received for this
// option, indicating the client is willing to enable this option.
func (e *TerminalTypeHandler) HandleWill(c *telnet.Connection) {
}
// HandleSB is called when a subnegotiation command is received for this
// option. body contains the bytes between `IAC SB <OptionCode>` and `IAC
// SE`.
func (e *TerminalTypeHandler) HandleSB(c *telnet.Connection, body []byte) {
}