mirror of
https://github.com/amitbet/vncproxy.git
synced 2025-09-23 18:38:38 +00:00
general refactoring + fixed setcursorpseudo
This commit is contained in:
@@ -27,7 +27,7 @@ type ClientAuth interface {
|
||||
type ClientConn struct {
|
||||
conn io.ReadWriteCloser
|
||||
|
||||
//c net.ServerConn
|
||||
//c net.IServerConn
|
||||
config *ClientConfig
|
||||
|
||||
// If the pixel format uses a color map, then this is the color
|
||||
@@ -37,7 +37,7 @@ type ClientConn struct {
|
||||
|
||||
// Encodings supported by the client. This should not be modified
|
||||
// directly. Instead, SetEncodings should be used.
|
||||
Encs []common.Encoding
|
||||
Encs []common.IEncoding
|
||||
|
||||
// Width of the frame buffer in pixels, sent from the server.
|
||||
FrameBufferWidth uint16
|
||||
@@ -100,7 +100,7 @@ func (c *ClientConn) Close() error {
|
||||
return c.conn.Close()
|
||||
}
|
||||
|
||||
func (c *ClientConn) Encodings() []common.Encoding {
|
||||
func (c *ClientConn) Encodings() []common.IEncoding {
|
||||
return c.Encs
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ func (c *ClientConn) PointerEvent(mask ButtonMask, x, y uint16) error {
|
||||
// given should not be modified.
|
||||
//
|
||||
// See RFC 6143 Section 7.5.2
|
||||
func (c *ClientConn) SetEncodings(encs []common.Encoding) error {
|
||||
func (c *ClientConn) SetEncodings(encs []common.IEncoding) error {
|
||||
data := make([]interface{}, 3+len(encs))
|
||||
data[0] = uint8(2)
|
||||
data[1] = uint8(0)
|
||||
@@ -470,10 +470,10 @@ func (c *ClientConn) mainLoop() {
|
||||
typeMap := make(map[uint8]common.ServerMessage)
|
||||
|
||||
defaultMessages := []common.ServerMessage{
|
||||
new(FramebufferUpdateMessage),
|
||||
new(SetColorMapEntriesMessage),
|
||||
new(BellMessage),
|
||||
new(ServerCutTextMessage),
|
||||
new(MsgFramebufferUpdate),
|
||||
new(MsgSetColorMapEntries),
|
||||
new(MsgBell),
|
||||
new(MsgServerCutText),
|
||||
}
|
||||
|
||||
for _, msg := range defaultMessages {
|
||||
|
@@ -1,18 +1,18 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"net"
|
||||
"time"
|
||||
"bytes"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type fakeNetConnection struct {
|
||||
DataToSend []byte
|
||||
Test *testing.T
|
||||
Test *testing.T
|
||||
ExpectData []byte
|
||||
Finished bool
|
||||
Matched bool
|
||||
Finished bool
|
||||
Matched bool
|
||||
}
|
||||
|
||||
func (fc fakeNetConnection) Read(b []byte) (n int, err error) {
|
||||
@@ -32,12 +32,12 @@ func (fc *fakeNetConnection) Write(b []byte) (n int, err error) {
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
func (fc *fakeNetConnection) Close() error { return nil; }
|
||||
func (fc *fakeNetConnection) LocalAddr() net.Addr { return nil; }
|
||||
func (fc *fakeNetConnection) RemoteAddr() net.Addr { return nil; }
|
||||
func (fc *fakeNetConnection) SetDeadline(t time.Time) error { return nil; }
|
||||
func (fc *fakeNetConnection) SetReadDeadline(t time.Time) error { return nil; }
|
||||
func (fc *fakeNetConnection) SetWriteDeadline(t time.Time) error { return nil; }
|
||||
func (fc *fakeNetConnection) Close() error { return nil }
|
||||
func (fc *fakeNetConnection) LocalAddr() net.Addr { return nil }
|
||||
func (fc *fakeNetConnection) RemoteAddr() net.Addr { return nil }
|
||||
func (fc *fakeNetConnection) SetDeadline(t time.Time) error { return nil }
|
||||
func (fc *fakeNetConnection) SetReadDeadline(t time.Time) error { return nil }
|
||||
func (fc *fakeNetConnection) SetWriteDeadline(t time.Time) error { return nil }
|
||||
|
||||
func TestClientAuthNone_Impl(t *testing.T) {
|
||||
var raw interface{}
|
||||
@@ -97,7 +97,7 @@ func TestClientAuthPasswordSuccess_Impl(t *testing.T) {
|
||||
conn := &fakeNetConnection{DataToSend: randomValue, ExpectData: expectedResponse, Test: t}
|
||||
err := raw.Handshake(conn)
|
||||
|
||||
if (err != nil) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ func TestClientAuthPasswordReject_Impl(t *testing.T) {
|
||||
conn := &fakeNetConnection{DataToSend: randomValue, ExpectData: expectedResponse, Test: t}
|
||||
err := raw.Handshake(conn)
|
||||
|
||||
if (err != nil) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -166,4 +166,4 @@ func TestClientAuthPasswordReject_Impl(t *testing.T) {
|
||||
if !conn.Finished {
|
||||
t.Fatal("PasswordAuth didn't complete properly")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +0,0 @@
|
||||
package client
|
||||
|
||||
// Color represents a single color in a color map.
|
||||
type Color struct {
|
||||
R, G, B uint16
|
||||
}
|
@@ -12,14 +12,14 @@ import (
|
||||
listeners "vncproxy/tee-listeners"
|
||||
)
|
||||
|
||||
// FramebufferUpdateMessage consists of a sequence of rectangles of
|
||||
// MsgFramebufferUpdate consists of a sequence of rectangles of
|
||||
// pixel data that the client should put into its framebuffer.
|
||||
type FramebufferUpdateMessage struct {
|
||||
type MsgFramebufferUpdate struct {
|
||||
Rectangles []common.Rectangle
|
||||
}
|
||||
|
||||
func (m *FramebufferUpdateMessage) String() string {
|
||||
str := fmt.Sprintf("FramebufferUpdateMessage (type=%d) Rects: ", m.Type())
|
||||
func (m *MsgFramebufferUpdate) String() string {
|
||||
str := fmt.Sprintf("MsgFramebufferUpdate (type=%d) Rects: ", m.Type())
|
||||
for _, rect := range m.Rectangles {
|
||||
str += rect.String() + "\n"
|
||||
//if this is the last rect, break the loop
|
||||
@@ -30,19 +30,19 @@ func (m *FramebufferUpdateMessage) String() string {
|
||||
return str
|
||||
}
|
||||
|
||||
func (*FramebufferUpdateMessage) Type() uint8 {
|
||||
func (*MsgFramebufferUpdate) Type() uint8 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (fbm *FramebufferUpdateMessage) CopyTo(r io.Reader, w io.Writer, c common.IClientConn) error {
|
||||
func (fbm *MsgFramebufferUpdate) CopyTo(r io.Reader, w io.Writer, c common.IClientConn) error {
|
||||
reader := common.NewRfbReadHelper(r)
|
||||
writeTo := &listeners.WriteTo{w, "FramebufferUpdateMessage.CopyTo"}
|
||||
writeTo := &listeners.WriteTo{w, "MsgFramebufferUpdate.CopyTo"}
|
||||
reader.Listeners.AddListener(writeTo)
|
||||
_, err := fbm.Read(c, reader)
|
||||
return err
|
||||
}
|
||||
|
||||
func (fbm *FramebufferUpdateMessage) Read(c common.IClientConn, r *common.RfbReadHelper) (common.ServerMessage, error) {
|
||||
func (fbm *MsgFramebufferUpdate) Read(c common.IClientConn, r *common.RfbReadHelper) (common.ServerMessage, error) {
|
||||
|
||||
// Read off the padding
|
||||
var padding [1]byte
|
||||
@@ -56,7 +56,7 @@ func (fbm *FramebufferUpdateMessage) Read(c common.IClientConn, r *common.RfbRea
|
||||
}
|
||||
|
||||
// Build the map of encodings supported
|
||||
encMap := make(map[int32]common.Encoding)
|
||||
encMap := make(map[int32]common.IEncoding)
|
||||
for _, enc := range c.Encodings() {
|
||||
encMap[enc.Type()] = enc
|
||||
}
|
||||
@@ -64,11 +64,11 @@ func (fbm *FramebufferUpdateMessage) Read(c common.IClientConn, r *common.RfbRea
|
||||
// We must always support the raw encoding
|
||||
rawEnc := new(encodings.RawEncoding)
|
||||
encMap[rawEnc.Type()] = rawEnc
|
||||
logger.Infof("FrameBufferUpdateMessage.Read: numrects= %d", numRects)
|
||||
logger.Infof("MsgFramebufferUpdate.Read: numrects= %d", numRects)
|
||||
|
||||
rects := make([]common.Rectangle, numRects)
|
||||
for i := uint16(0); i < numRects; i++ {
|
||||
logger.Debugf("FrameBufferUpdateMessage.Read: ###############rect################: %d", i)
|
||||
logger.Debugf("MsgFramebufferUpdate.Read: ###############rect################: %d", i)
|
||||
|
||||
var encodingTypeInt int32
|
||||
r.SendRectSeparator(-1)
|
||||
@@ -91,7 +91,7 @@ func (fbm *FramebufferUpdateMessage) Read(c common.IClientConn, r *common.RfbRea
|
||||
|
||||
encType := common.EncodingType(encodingTypeInt)
|
||||
|
||||
logger.Infof("FrameBufferUpdateMessage.Read: rect# %d, rect hdr data: enctype=%s, data: %s", i, encType, string(jBytes))
|
||||
logger.Infof("MsgFramebufferUpdate.Read: rect# %d, rect hdr data: enctype=%s, data: %s", i, encType, string(jBytes))
|
||||
enc, supported := encMap[encodingTypeInt]
|
||||
if supported {
|
||||
var err error
|
||||
@@ -108,49 +108,49 @@ func (fbm *FramebufferUpdateMessage) Read(c common.IClientConn, r *common.RfbRea
|
||||
break
|
||||
}
|
||||
} else {
|
||||
logger.Errorf("FrameBufferUpdateMessage.Read: unsupported encoding type: %d, %s", encodingTypeInt, encType)
|
||||
return nil, fmt.Errorf("FrameBufferUpdateMessage.Read: unsupported encoding type: %d, %s", encodingTypeInt, encType)
|
||||
logger.Errorf("MsgFramebufferUpdate.Read: unsupported encoding type: %d, %s", encodingTypeInt, encType)
|
||||
return nil, fmt.Errorf("MsgFramebufferUpdate.Read: unsupported encoding type: %d, %s", encodingTypeInt, encType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &FramebufferUpdateMessage{rects}, nil
|
||||
return &MsgFramebufferUpdate{rects}, nil
|
||||
}
|
||||
|
||||
// SetColorMapEntriesMessage is sent by the server to set values into
|
||||
// MsgSetColorMapEntries is sent by the server to set values into
|
||||
// the color map. This message will automatically update the color map
|
||||
// for the associated connection, but contains the color change data
|
||||
// if the consumer wants to read it.
|
||||
//
|
||||
// See RFC 6143 Section 7.6.2
|
||||
type SetColorMapEntriesMessage struct {
|
||||
type MsgSetColorMapEntries struct {
|
||||
FirstColor uint16
|
||||
Colors []common.Color
|
||||
}
|
||||
|
||||
func (fbm *SetColorMapEntriesMessage) CopyTo(r io.Reader, w io.Writer, c common.IClientConn) error {
|
||||
func (fbm *MsgSetColorMapEntries) CopyTo(r io.Reader, w io.Writer, c common.IClientConn) error {
|
||||
reader := &common.RfbReadHelper{Reader: r}
|
||||
writeTo := &listeners.WriteTo{w, "SetColorMapEntriesMessage.CopyTo"}
|
||||
writeTo := &listeners.WriteTo{w, "MsgSetColorMapEntries.CopyTo"}
|
||||
reader.Listeners.AddListener(writeTo)
|
||||
_, err := fbm.Read(c, reader)
|
||||
return err
|
||||
}
|
||||
func (m *SetColorMapEntriesMessage) String() string {
|
||||
return fmt.Sprintf("SetColorMapEntriesMessage (type=%d) first:%d colors: %v: ", m.Type(), m.FirstColor, m.Colors)
|
||||
func (m *MsgSetColorMapEntries) String() string {
|
||||
return fmt.Sprintf("MsgSetColorMapEntries (type=%d) first:%d colors: %v: ", m.Type(), m.FirstColor, m.Colors)
|
||||
}
|
||||
|
||||
func (*SetColorMapEntriesMessage) Type() uint8 {
|
||||
func (*MsgSetColorMapEntries) Type() uint8 {
|
||||
return 1
|
||||
}
|
||||
|
||||
func (*SetColorMapEntriesMessage) Read(c common.IClientConn, r *common.RfbReadHelper) (common.ServerMessage, error) {
|
||||
func (*MsgSetColorMapEntries) Read(c common.IClientConn, r *common.RfbReadHelper) (common.ServerMessage, error) {
|
||||
// Read off the padding
|
||||
var padding [1]byte
|
||||
if _, err := io.ReadFull(r, padding[:]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result SetColorMapEntriesMessage
|
||||
var result MsgSetColorMapEntries
|
||||
if err := binary.Read(r, binary.BigEndian, &result.FirstColor); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -186,37 +186,37 @@ func (*SetColorMapEntriesMessage) Read(c common.IClientConn, r *common.RfbReadHe
|
||||
// Bell signals that an audible bell should be made on the client.
|
||||
//
|
||||
// See RFC 6143 Section 7.6.3
|
||||
type BellMessage byte
|
||||
type MsgBell byte
|
||||
|
||||
func (fbm *BellMessage) CopyTo(r io.Reader, w io.Writer, c common.IClientConn) error {
|
||||
func (fbm *MsgBell) CopyTo(r io.Reader, w io.Writer, c common.IClientConn) error {
|
||||
return nil
|
||||
}
|
||||
func (m *BellMessage) String() string {
|
||||
return fmt.Sprintf("BellMessage (type=%d)", m.Type())
|
||||
func (m *MsgBell) String() string {
|
||||
return fmt.Sprintf("MsgBell (type=%d)", m.Type())
|
||||
}
|
||||
|
||||
func (*BellMessage) Type() uint8 {
|
||||
func (*MsgBell) Type() uint8 {
|
||||
return 2
|
||||
}
|
||||
|
||||
func (*BellMessage) Read(common.IClientConn, *common.RfbReadHelper) (common.ServerMessage, error) {
|
||||
return new(BellMessage), nil
|
||||
func (*MsgBell) Read(common.IClientConn, *common.RfbReadHelper) (common.ServerMessage, error) {
|
||||
return new(MsgBell), nil
|
||||
}
|
||||
|
||||
type ServerFenceMessage byte
|
||||
type MsgServerFence byte
|
||||
|
||||
func (fbm *ServerFenceMessage) CopyTo(r io.Reader, w io.Writer, c common.IClientConn) error {
|
||||
func (fbm *MsgServerFence) CopyTo(r io.Reader, w io.Writer, c common.IClientConn) error {
|
||||
return nil
|
||||
}
|
||||
func (m *ServerFenceMessage) String() string {
|
||||
return fmt.Sprintf("ServerFenceMessage (type=%d)", m.Type())
|
||||
func (m *MsgServerFence) String() string {
|
||||
return fmt.Sprintf("MsgServerFence (type=%d)", m.Type())
|
||||
}
|
||||
|
||||
func (*ServerFenceMessage) Type() uint8 {
|
||||
func (*MsgServerFence) Type() uint8 {
|
||||
return uint8(common.ServerFence)
|
||||
}
|
||||
|
||||
func (sf *ServerFenceMessage) Read(info common.IClientConn, c *common.RfbReadHelper) (common.ServerMessage, error) {
|
||||
func (sf *MsgServerFence) Read(info common.IClientConn, c *common.RfbReadHelper) (common.ServerMessage, error) {
|
||||
bytes := make([]byte, 3)
|
||||
c.Read(bytes)
|
||||
if _, err := c.Read(bytes); err != nil {
|
||||
@@ -239,29 +239,29 @@ func (sf *ServerFenceMessage) Read(info common.IClientConn, c *common.RfbReadHel
|
||||
return sf, nil
|
||||
}
|
||||
|
||||
// ServerCutTextMessage indicates the server has new text in the cut buffer.
|
||||
// MsgServerCutText indicates the server has new text in the cut buffer.
|
||||
//
|
||||
// See RFC 6143 Section 7.6.4
|
||||
type ServerCutTextMessage struct {
|
||||
type MsgServerCutText struct {
|
||||
Text string
|
||||
}
|
||||
|
||||
func (fbm *ServerCutTextMessage) CopyTo(r io.Reader, w io.Writer, c common.IClientConn) error {
|
||||
func (fbm *MsgServerCutText) CopyTo(r io.Reader, w io.Writer, c common.IClientConn) error {
|
||||
reader := &common.RfbReadHelper{Reader: r}
|
||||
writeTo := &listeners.WriteTo{w, "ServerCutTextMessage.CopyTo"}
|
||||
writeTo := &listeners.WriteTo{w, "MsgServerCutText.CopyTo"}
|
||||
reader.Listeners.AddListener(writeTo)
|
||||
_, err := fbm.Read(c, reader)
|
||||
return err
|
||||
}
|
||||
func (m *ServerCutTextMessage) String() string {
|
||||
return fmt.Sprintf("ServerCutTextMessage (type=%d)", m.Type())
|
||||
func (m *MsgServerCutText) String() string {
|
||||
return fmt.Sprintf("MsgServerCutText (type=%d)", m.Type())
|
||||
}
|
||||
|
||||
func (*ServerCutTextMessage) Type() uint8 {
|
||||
func (*MsgServerCutText) Type() uint8 {
|
||||
return 3
|
||||
}
|
||||
|
||||
func (*ServerCutTextMessage) Read(conn common.IClientConn, r *common.RfbReadHelper) (common.ServerMessage, error) {
|
||||
func (*MsgServerCutText) Read(conn common.IClientConn, r *common.RfbReadHelper) (common.ServerMessage, error) {
|
||||
//reader := common.RfbReadHelper{Reader: r}
|
||||
|
||||
// Read off the padding
|
||||
@@ -278,5 +278,5 @@ func (*ServerCutTextMessage) Read(conn common.IClientConn, r *common.RfbReadHelp
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ServerCutTextMessage{string(textBytes)}, nil
|
||||
return &MsgServerCutText{string(textBytes)}, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user