forked from mitchellh/go-vnc
-
Notifications
You must be signed in to change notification settings - Fork 16
/
initialization.go
91 lines (74 loc) · 2.09 KB
/
initialization.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Implementation of RFC 6143 §7.3 Initialization Messages.
package vnc
import (
"io"
"github.com/golang/glog"
"github.com/kward/go-vnc/logging"
"github.com/kward/go-vnc/rfbflags"
)
// clientInit implements §7.3.1 ClientInit.
func (c *ClientConn) clientInit() error {
if logging.V(logging.FnDeclLevel) {
glog.Info(logging.FnName())
}
sharedFlag := rfbflags.BoolToRFBFlag(!c.config.Exclusive)
if logging.V(logging.ResultLevel) {
glog.Infof("sharedFlag: %d", sharedFlag)
}
if err := c.send(sharedFlag); err != nil {
return err
}
// TODO(kward)20170226): VENUE responds with some sort of shared flag
// response, which includes the VENUE name and IPs. Handle this?
return nil
}
// ServerInit message sent after server receives a ClientInit message.
// https://tools.ietf.org/html/rfc6143#section-7.3.2
type ServerInit struct {
FBWidth, FBHeight uint16
PixelFormat PixelFormat
NameLength uint32
// Name is of variable length, and must be read separately.
}
const serverInitLen = 24 // Not including Name.
// Verify that interfaces are honored.
var _ Unmarshaler = (*ServerInit)(nil)
// Read implements
func (m *ServerInit) Read(r io.Reader) error {
buf := make([]byte, serverInitLen)
if _, err := io.ReadAtLeast(r, buf, serverInitLen); err != nil {
return err
}
return m.Unmarshal(buf)
}
func (m *ServerInit) Unmarshal(data []byte) error {
buf := NewBuffer(data)
var msg ServerInit
if err := buf.Read(&msg); err != nil {
return err
}
*m = msg
return nil
}
// serverInit implements §7.3.2 ServerInit.
func (c *ClientConn) serverInit() error {
if logging.V(logging.FnDeclLevel) {
glog.Info(logging.FnName())
}
var msg ServerInit
if err := msg.Read(c.c); err != nil {
return Errorf("failure reading ServerInit message; %v", err)
}
if logging.V(logging.ResultLevel) {
glog.Infof("ServerInit message: %v", msg)
}
c.setFramebufferWidth(msg.FBWidth)
c.setFramebufferHeight(msg.FBHeight)
c.pixelFormat = msg.PixelFormat
name := make([]uint8, msg.NameLength)
if err := c.receive(&name); err != nil {
return err
}
c.setDesktopName(string(name))
return nil
}