mirror of
https://github.com/amitbet/vncproxy.git
synced 2025-06-01 10:45:37 +00:00
general refactoring + fixed setcursorpseudo
This commit is contained in:
parent
662e8393e9
commit
2d87ae5773
@ -1,6 +1,8 @@
|
|||||||
<component name="libraryTable">
|
<component name="libraryTable">
|
||||||
<library name="GOPATH <vncproxy>">
|
<library name="GOPATH <vncproxy>">
|
||||||
<CLASSES>
|
<CLASSES>
|
||||||
|
<root url="file://$PROJECT_DIR$/../srf.storage" />
|
||||||
|
<root url="file://$USER_HOME$/srf/experience.center.opb/src/sourcegraph.com" />
|
||||||
<root url="file://$PROJECT_DIR$/../elastictrail" />
|
<root url="file://$PROJECT_DIR$/../elastictrail" />
|
||||||
<root url="file://$PROJECT_DIR$/../gopkg.in" />
|
<root url="file://$PROJECT_DIR$/../gopkg.in" />
|
||||||
<root url="file://$PROJECT_DIR$/../vncproxy1" />
|
<root url="file://$PROJECT_DIR$/../vncproxy1" />
|
||||||
@ -18,11 +20,11 @@
|
|||||||
<root url="file://$USER_HOME$/srf/experience.center.opb/src/golang.org" />
|
<root url="file://$USER_HOME$/srf/experience.center.opb/src/golang.org" />
|
||||||
<root url="file://$USER_HOME$/srf/experience.center.opb/src/srf" />
|
<root url="file://$USER_HOME$/srf/experience.center.opb/src/srf" />
|
||||||
<root url="file://$USER_HOME$/srf/experience.center.opb/src/version" />
|
<root url="file://$USER_HOME$/srf/experience.center.opb/src/version" />
|
||||||
<root url="file://$PROJECT_DIR$/../srf.storage" />
|
|
||||||
<root url="file://$USER_HOME$/srf/experience.center.opb/src/sourcegraph.com" />
|
|
||||||
</CLASSES>
|
</CLASSES>
|
||||||
<JAVADOC />
|
<JAVADOC />
|
||||||
<SOURCES>
|
<SOURCES>
|
||||||
|
<root url="file://$PROJECT_DIR$/../srf.storage" />
|
||||||
|
<root url="file://$USER_HOME$/srf/experience.center.opb/src/sourcegraph.com" />
|
||||||
<root url="file://$PROJECT_DIR$/../elastictrail" />
|
<root url="file://$PROJECT_DIR$/../elastictrail" />
|
||||||
<root url="file://$PROJECT_DIR$/../gopkg.in" />
|
<root url="file://$PROJECT_DIR$/../gopkg.in" />
|
||||||
<root url="file://$PROJECT_DIR$/../vncproxy1" />
|
<root url="file://$PROJECT_DIR$/../vncproxy1" />
|
||||||
@ -40,8 +42,6 @@
|
|||||||
<root url="file://$USER_HOME$/srf/experience.center.opb/src/golang.org" />
|
<root url="file://$USER_HOME$/srf/experience.center.opb/src/golang.org" />
|
||||||
<root url="file://$USER_HOME$/srf/experience.center.opb/src/srf" />
|
<root url="file://$USER_HOME$/srf/experience.center.opb/src/srf" />
|
||||||
<root url="file://$USER_HOME$/srf/experience.center.opb/src/version" />
|
<root url="file://$USER_HOME$/srf/experience.center.opb/src/version" />
|
||||||
<root url="file://$PROJECT_DIR$/../srf.storage" />
|
|
||||||
<root url="file://$USER_HOME$/srf/experience.center.opb/src/sourcegraph.com" />
|
|
||||||
</SOURCES>
|
</SOURCES>
|
||||||
<excluded>
|
<excluded>
|
||||||
<root url="file://$PROJECT_DIR$" />
|
<root url="file://$PROJECT_DIR$" />
|
||||||
|
1512
.idea/workspace.xml
1512
.idea/workspace.xml
File diff suppressed because it is too large
Load Diff
@ -27,7 +27,7 @@ type ClientAuth interface {
|
|||||||
type ClientConn struct {
|
type ClientConn struct {
|
||||||
conn io.ReadWriteCloser
|
conn io.ReadWriteCloser
|
||||||
|
|
||||||
//c net.ServerConn
|
//c net.IServerConn
|
||||||
config *ClientConfig
|
config *ClientConfig
|
||||||
|
|
||||||
// If the pixel format uses a color map, then this is the color
|
// 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
|
// Encodings supported by the client. This should not be modified
|
||||||
// directly. Instead, SetEncodings should be used.
|
// directly. Instead, SetEncodings should be used.
|
||||||
Encs []common.Encoding
|
Encs []common.IEncoding
|
||||||
|
|
||||||
// Width of the frame buffer in pixels, sent from the server.
|
// Width of the frame buffer in pixels, sent from the server.
|
||||||
FrameBufferWidth uint16
|
FrameBufferWidth uint16
|
||||||
@ -100,7 +100,7 @@ func (c *ClientConn) Close() error {
|
|||||||
return c.conn.Close()
|
return c.conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientConn) Encodings() []common.Encoding {
|
func (c *ClientConn) Encodings() []common.IEncoding {
|
||||||
return c.Encs
|
return c.Encs
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,7 +258,7 @@ func (c *ClientConn) PointerEvent(mask ButtonMask, x, y uint16) error {
|
|||||||
// given should not be modified.
|
// given should not be modified.
|
||||||
//
|
//
|
||||||
// See RFC 6143 Section 7.5.2
|
// 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 := make([]interface{}, 3+len(encs))
|
||||||
data[0] = uint8(2)
|
data[0] = uint8(2)
|
||||||
data[1] = uint8(0)
|
data[1] = uint8(0)
|
||||||
@ -470,10 +470,10 @@ func (c *ClientConn) mainLoop() {
|
|||||||
typeMap := make(map[uint8]common.ServerMessage)
|
typeMap := make(map[uint8]common.ServerMessage)
|
||||||
|
|
||||||
defaultMessages := []common.ServerMessage{
|
defaultMessages := []common.ServerMessage{
|
||||||
new(FramebufferUpdateMessage),
|
new(MsgFramebufferUpdate),
|
||||||
new(SetColorMapEntriesMessage),
|
new(MsgSetColorMapEntries),
|
||||||
new(BellMessage),
|
new(MsgBell),
|
||||||
new(ServerCutTextMessage),
|
new(MsgServerCutText),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, msg := range defaultMessages {
|
for _, msg := range defaultMessages {
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
"net"
|
|
||||||
"time"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"net"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type fakeNetConnection struct {
|
type fakeNetConnection struct {
|
||||||
DataToSend []byte
|
DataToSend []byte
|
||||||
Test *testing.T
|
Test *testing.T
|
||||||
ExpectData []byte
|
ExpectData []byte
|
||||||
Finished bool
|
Finished bool
|
||||||
Matched bool
|
Matched bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fc fakeNetConnection) Read(b []byte) (n int, err error) {
|
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
|
return len(b), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fc *fakeNetConnection) Close() error { return nil; }
|
func (fc *fakeNetConnection) Close() error { return nil }
|
||||||
func (fc *fakeNetConnection) LocalAddr() net.Addr { return nil; }
|
func (fc *fakeNetConnection) LocalAddr() net.Addr { return nil }
|
||||||
func (fc *fakeNetConnection) RemoteAddr() 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) SetDeadline(t time.Time) error { return nil }
|
||||||
func (fc *fakeNetConnection) SetReadDeadline(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) SetWriteDeadline(t time.Time) error { return nil }
|
||||||
|
|
||||||
func TestClientAuthNone_Impl(t *testing.T) {
|
func TestClientAuthNone_Impl(t *testing.T) {
|
||||||
var raw interface{}
|
var raw interface{}
|
||||||
@ -97,7 +97,7 @@ func TestClientAuthPasswordSuccess_Impl(t *testing.T) {
|
|||||||
conn := &fakeNetConnection{DataToSend: randomValue, ExpectData: expectedResponse, Test: t}
|
conn := &fakeNetConnection{DataToSend: randomValue, ExpectData: expectedResponse, Test: t}
|
||||||
err := raw.Handshake(conn)
|
err := raw.Handshake(conn)
|
||||||
|
|
||||||
if (err != nil) {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +155,7 @@ func TestClientAuthPasswordReject_Impl(t *testing.T) {
|
|||||||
conn := &fakeNetConnection{DataToSend: randomValue, ExpectData: expectedResponse, Test: t}
|
conn := &fakeNetConnection{DataToSend: randomValue, ExpectData: expectedResponse, Test: t}
|
||||||
err := raw.Handshake(conn)
|
err := raw.Handshake(conn)
|
||||||
|
|
||||||
if (err != nil) {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,4 +166,4 @@ func TestClientAuthPasswordReject_Impl(t *testing.T) {
|
|||||||
if !conn.Finished {
|
if !conn.Finished {
|
||||||
t.Fatal("PasswordAuth didn't complete properly")
|
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"
|
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.
|
// pixel data that the client should put into its framebuffer.
|
||||||
type FramebufferUpdateMessage struct {
|
type MsgFramebufferUpdate struct {
|
||||||
Rectangles []common.Rectangle
|
Rectangles []common.Rectangle
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *FramebufferUpdateMessage) String() string {
|
func (m *MsgFramebufferUpdate) String() string {
|
||||||
str := fmt.Sprintf("FramebufferUpdateMessage (type=%d) Rects: ", m.Type())
|
str := fmt.Sprintf("MsgFramebufferUpdate (type=%d) Rects: ", m.Type())
|
||||||
for _, rect := range m.Rectangles {
|
for _, rect := range m.Rectangles {
|
||||||
str += rect.String() + "\n"
|
str += rect.String() + "\n"
|
||||||
//if this is the last rect, break the loop
|
//if this is the last rect, break the loop
|
||||||
@ -30,19 +30,19 @@ func (m *FramebufferUpdateMessage) String() string {
|
|||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*FramebufferUpdateMessage) Type() uint8 {
|
func (*MsgFramebufferUpdate) Type() uint8 {
|
||||||
return 0
|
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)
|
reader := common.NewRfbReadHelper(r)
|
||||||
writeTo := &listeners.WriteTo{w, "FramebufferUpdateMessage.CopyTo"}
|
writeTo := &listeners.WriteTo{w, "MsgFramebufferUpdate.CopyTo"}
|
||||||
reader.Listeners.AddListener(writeTo)
|
reader.Listeners.AddListener(writeTo)
|
||||||
_, err := fbm.Read(c, reader)
|
_, err := fbm.Read(c, reader)
|
||||||
return err
|
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
|
// Read off the padding
|
||||||
var padding [1]byte
|
var padding [1]byte
|
||||||
@ -56,7 +56,7 @@ func (fbm *FramebufferUpdateMessage) Read(c common.IClientConn, r *common.RfbRea
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build the map of encodings supported
|
// Build the map of encodings supported
|
||||||
encMap := make(map[int32]common.Encoding)
|
encMap := make(map[int32]common.IEncoding)
|
||||||
for _, enc := range c.Encodings() {
|
for _, enc := range c.Encodings() {
|
||||||
encMap[enc.Type()] = enc
|
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
|
// We must always support the raw encoding
|
||||||
rawEnc := new(encodings.RawEncoding)
|
rawEnc := new(encodings.RawEncoding)
|
||||||
encMap[rawEnc.Type()] = rawEnc
|
encMap[rawEnc.Type()] = rawEnc
|
||||||
logger.Infof("FrameBufferUpdateMessage.Read: numrects= %d", numRects)
|
logger.Infof("MsgFramebufferUpdate.Read: numrects= %d", numRects)
|
||||||
|
|
||||||
rects := make([]common.Rectangle, numRects)
|
rects := make([]common.Rectangle, numRects)
|
||||||
for i := uint16(0); i < numRects; i++ {
|
for i := uint16(0); i < numRects; i++ {
|
||||||
logger.Debugf("FrameBufferUpdateMessage.Read: ###############rect################: %d", i)
|
logger.Debugf("MsgFramebufferUpdate.Read: ###############rect################: %d", i)
|
||||||
|
|
||||||
var encodingTypeInt int32
|
var encodingTypeInt int32
|
||||||
r.SendRectSeparator(-1)
|
r.SendRectSeparator(-1)
|
||||||
@ -91,7 +91,7 @@ func (fbm *FramebufferUpdateMessage) Read(c common.IClientConn, r *common.RfbRea
|
|||||||
|
|
||||||
encType := common.EncodingType(encodingTypeInt)
|
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]
|
enc, supported := encMap[encodingTypeInt]
|
||||||
if supported {
|
if supported {
|
||||||
var err error
|
var err error
|
||||||
@ -108,49 +108,49 @@ func (fbm *FramebufferUpdateMessage) Read(c common.IClientConn, r *common.RfbRea
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.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("FrameBufferUpdateMessage.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
|
// the color map. This message will automatically update the color map
|
||||||
// for the associated connection, but contains the color change data
|
// for the associated connection, but contains the color change data
|
||||||
// if the consumer wants to read it.
|
// if the consumer wants to read it.
|
||||||
//
|
//
|
||||||
// See RFC 6143 Section 7.6.2
|
// See RFC 6143 Section 7.6.2
|
||||||
type SetColorMapEntriesMessage struct {
|
type MsgSetColorMapEntries struct {
|
||||||
FirstColor uint16
|
FirstColor uint16
|
||||||
Colors []common.Color
|
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}
|
reader := &common.RfbReadHelper{Reader: r}
|
||||||
writeTo := &listeners.WriteTo{w, "SetColorMapEntriesMessage.CopyTo"}
|
writeTo := &listeners.WriteTo{w, "MsgSetColorMapEntries.CopyTo"}
|
||||||
reader.Listeners.AddListener(writeTo)
|
reader.Listeners.AddListener(writeTo)
|
||||||
_, err := fbm.Read(c, reader)
|
_, err := fbm.Read(c, reader)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
func (m *SetColorMapEntriesMessage) String() string {
|
func (m *MsgSetColorMapEntries) String() string {
|
||||||
return fmt.Sprintf("SetColorMapEntriesMessage (type=%d) first:%d colors: %v: ", m.Type(), m.FirstColor, m.Colors)
|
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
|
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
|
// Read off the padding
|
||||||
var padding [1]byte
|
var padding [1]byte
|
||||||
if _, err := io.ReadFull(r, padding[:]); err != nil {
|
if _, err := io.ReadFull(r, padding[:]); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var result SetColorMapEntriesMessage
|
var result MsgSetColorMapEntries
|
||||||
if err := binary.Read(r, binary.BigEndian, &result.FirstColor); err != nil {
|
if err := binary.Read(r, binary.BigEndian, &result.FirstColor); err != nil {
|
||||||
return nil, err
|
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.
|
// Bell signals that an audible bell should be made on the client.
|
||||||
//
|
//
|
||||||
// See RFC 6143 Section 7.6.3
|
// 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
|
return nil
|
||||||
}
|
}
|
||||||
func (m *BellMessage) String() string {
|
func (m *MsgBell) String() string {
|
||||||
return fmt.Sprintf("BellMessage (type=%d)", m.Type())
|
return fmt.Sprintf("MsgBell (type=%d)", m.Type())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*BellMessage) Type() uint8 {
|
func (*MsgBell) Type() uint8 {
|
||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*BellMessage) Read(common.IClientConn, *common.RfbReadHelper) (common.ServerMessage, error) {
|
func (*MsgBell) Read(common.IClientConn, *common.RfbReadHelper) (common.ServerMessage, error) {
|
||||||
return new(BellMessage), nil
|
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
|
return nil
|
||||||
}
|
}
|
||||||
func (m *ServerFenceMessage) String() string {
|
func (m *MsgServerFence) String() string {
|
||||||
return fmt.Sprintf("ServerFenceMessage (type=%d)", m.Type())
|
return fmt.Sprintf("MsgServerFence (type=%d)", m.Type())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*ServerFenceMessage) Type() uint8 {
|
func (*MsgServerFence) Type() uint8 {
|
||||||
return uint8(common.ServerFence)
|
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)
|
bytes := make([]byte, 3)
|
||||||
c.Read(bytes)
|
c.Read(bytes)
|
||||||
if _, err := c.Read(bytes); err != nil {
|
if _, err := c.Read(bytes); err != nil {
|
||||||
@ -239,29 +239,29 @@ func (sf *ServerFenceMessage) Read(info common.IClientConn, c *common.RfbReadHel
|
|||||||
return sf, nil
|
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
|
// See RFC 6143 Section 7.6.4
|
||||||
type ServerCutTextMessage struct {
|
type MsgServerCutText struct {
|
||||||
Text string
|
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}
|
reader := &common.RfbReadHelper{Reader: r}
|
||||||
writeTo := &listeners.WriteTo{w, "ServerCutTextMessage.CopyTo"}
|
writeTo := &listeners.WriteTo{w, "MsgServerCutText.CopyTo"}
|
||||||
reader.Listeners.AddListener(writeTo)
|
reader.Listeners.AddListener(writeTo)
|
||||||
_, err := fbm.Read(c, reader)
|
_, err := fbm.Read(c, reader)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
func (m *ServerCutTextMessage) String() string {
|
func (m *MsgServerCutText) String() string {
|
||||||
return fmt.Sprintf("ServerCutTextMessage (type=%d)", m.Type())
|
return fmt.Sprintf("MsgServerCutText (type=%d)", m.Type())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*ServerCutTextMessage) Type() uint8 {
|
func (*MsgServerCutText) Type() uint8 {
|
||||||
return 3
|
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}
|
//reader := common.RfbReadHelper{Reader: r}
|
||||||
|
|
||||||
// Read off the padding
|
// Read off the padding
|
||||||
@ -278,5 +278,5 @@ func (*ServerCutTextMessage) Read(conn common.IClientConn, r *common.RfbReadHelp
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ServerCutTextMessage{string(textBytes)}, nil
|
return &MsgServerCutText{string(textBytes)}, nil
|
||||||
}
|
}
|
||||||
|
@ -30,27 +30,6 @@ type Color struct {
|
|||||||
|
|
||||||
type ColorMap [256]Color
|
type ColorMap [256]Color
|
||||||
|
|
||||||
type ServerConn interface {
|
|
||||||
io.ReadWriter
|
|
||||||
//ServerConn() io.ReadWriter
|
|
||||||
Protocol() string
|
|
||||||
CurrentPixelFormat() *PixelFormat
|
|
||||||
SetPixelFormat(*PixelFormat) error
|
|
||||||
//ColorMap() *ColorMap
|
|
||||||
SetColorMap(*ColorMap)
|
|
||||||
Encodings() []Encoding
|
|
||||||
SetEncodings([]EncodingType) error
|
|
||||||
Width() uint16
|
|
||||||
Height() uint16
|
|
||||||
SetWidth(uint16)
|
|
||||||
SetHeight(uint16)
|
|
||||||
DesktopName() string
|
|
||||||
SetDesktopName(string)
|
|
||||||
//Flush() error
|
|
||||||
SetProtoVersion(string)
|
|
||||||
// Write([]byte) (int, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClientMessage is the interface
|
// ClientMessage is the interface
|
||||||
type ClientMessage interface {
|
type ClientMessage interface {
|
||||||
Type() ClientMessageType
|
Type() ClientMessageType
|
30
common/conn-interfaces.go
Normal file
30
common/conn-interfaces.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import "io"
|
||||||
|
|
||||||
|
type IServerConn interface {
|
||||||
|
io.ReadWriter
|
||||||
|
//IServerConn() io.ReadWriter
|
||||||
|
Protocol() string
|
||||||
|
CurrentPixelFormat() *PixelFormat
|
||||||
|
SetPixelFormat(*PixelFormat) error
|
||||||
|
//ColorMap() *ColorMap
|
||||||
|
SetColorMap(*ColorMap)
|
||||||
|
Encodings() []IEncoding
|
||||||
|
SetEncodings([]EncodingType) error
|
||||||
|
Width() uint16
|
||||||
|
Height() uint16
|
||||||
|
SetWidth(uint16)
|
||||||
|
SetHeight(uint16)
|
||||||
|
DesktopName() string
|
||||||
|
SetDesktopName(string)
|
||||||
|
//Flush() error
|
||||||
|
SetProtoVersion(string)
|
||||||
|
// Write([]byte) (int, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type IClientConn interface {
|
||||||
|
CurrentPixelFormat() *PixelFormat
|
||||||
|
CurrentColorMap() *ColorMap
|
||||||
|
Encodings() []IEncoding
|
||||||
|
}
|
@ -6,16 +6,16 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
// An Encoding implements a method for encoding pixel data that is
|
// An IEncoding implements a method for encoding pixel data that is
|
||||||
// sent by the server to the client.
|
// sent by the server to the client.
|
||||||
type Encoding interface {
|
type IEncoding interface {
|
||||||
// The number that uniquely identifies this encoding type.
|
// The number that uniquely identifies this encoding type.
|
||||||
Type() int32
|
Type() int32
|
||||||
WriteTo(w io.Writer) (n int, err error)
|
WriteTo(w io.Writer) (n int, err error)
|
||||||
// Read reads the contents of the encoded pixel data from the reader.
|
// Read reads the contents of the encoded pixel data from the reader.
|
||||||
// This should return a new Encoding implementation that contains
|
// This should return a new IEncoding implementation that contains
|
||||||
// the proper data.
|
// the proper data.
|
||||||
Read(*PixelFormat, *Rectangle, *RfbReadHelper) (Encoding, error)
|
Read(*PixelFormat, *Rectangle, *RfbReadHelper) (IEncoding, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EncodingType represents a known VNC encoding type.
|
// EncodingType represents a known VNC encoding type.
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Rectangle represents a rectangle of pixel data.
|
// Rectangle represents a rectangle of pixel data.
|
||||||
type Rectangle struct {
|
type Rectangle struct {
|
||||||
X uint16
|
X uint16
|
||||||
Y uint16
|
Y uint16
|
||||||
Width uint16
|
Width uint16
|
||||||
Height uint16
|
Height uint16
|
||||||
Enc Encoding
|
Enc IEncoding
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Rectangle) String() string {
|
func (r *Rectangle) String() string {
|
||||||
return fmt.Sprintf("(%d,%d) (width: %d, height: %d), Enc= %d", r.X, r.Y, r.Width, r.Height, r.Enc.Type())
|
return fmt.Sprintf("(%d,%d) (width: %d, height: %d), Enc= %d", r.X, r.Y, r.Width, r.Height, r.Enc.Type())
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IClientConn interface {
|
|
||||||
CurrentPixelFormat() *PixelFormat
|
|
||||||
CurrentColorMap() *ColorMap
|
|
||||||
Encodings() []Encoding
|
|
||||||
}
|
|
||||||
|
|
||||||
type ServerMessage interface {
|
type ServerMessage interface {
|
||||||
Type() uint8
|
Type() uint8
|
||||||
String() string
|
String() string
|
@ -27,7 +27,7 @@ func (z *CopyRectEncoding) WriteTo(w io.Writer) (n int, err error) {
|
|||||||
return 4, nil
|
return 4, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *CopyRectEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
func (z *CopyRectEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||||
z.copyRectSrcX, _ = r.ReadUint16()
|
z.copyRectSrcX, _ = r.ReadUint16()
|
||||||
z.copyRectSrcY, _ = r.ReadUint16()
|
z.copyRectSrcY, _ = r.ReadUint16()
|
||||||
return z, nil
|
return z, nil
|
||||||
|
@ -36,7 +36,7 @@ func (z *CoRREEncoding) WriteTo(w io.Writer) (n int, err error) {
|
|||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *CoRREEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
func (z *CoRREEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||||
bytesPerPixel := int(pixelFmt.BPP / 8)
|
bytesPerPixel := int(pixelFmt.BPP / 8)
|
||||||
numOfSubrectangles, err := r.ReadUint32()
|
numOfSubrectangles, err := r.ReadUint32()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -15,7 +15,7 @@ func (pe *EncCursorPseudo) Type() int32 {
|
|||||||
func (z *EncCursorPseudo) WriteTo(w io.Writer) (n int, err error) {
|
func (z *EncCursorPseudo) WriteTo(w io.Writer) (n int, err error) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
func (pe *EncCursorPseudo) Read(pf *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
func (pe *EncCursorPseudo) Read(pf *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||||
if rect.Width*rect.Height == 0 {
|
if rect.Width*rect.Height == 0 {
|
||||||
return pe, nil
|
return pe, nil
|
||||||
}
|
}
|
||||||
|
@ -1,84 +1,84 @@
|
|||||||
package encodings
|
package encodings
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"vncproxy/common"
|
"vncproxy/common"
|
||||||
"vncproxy/logger"
|
"vncproxy/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
HextileRaw = 1
|
HextileRaw = 1
|
||||||
HextileBackgroundSpecified = 2
|
HextileBackgroundSpecified = 2
|
||||||
HextileForegroundSpecified = 4
|
HextileForegroundSpecified = 4
|
||||||
HextileAnySubrects = 8
|
HextileAnySubrects = 8
|
||||||
HextileSubrectsColoured = 16
|
HextileSubrectsColoured = 16
|
||||||
)
|
)
|
||||||
|
|
||||||
type HextileEncoding struct {
|
type HextileEncoding struct {
|
||||||
//Colors []Color
|
//Colors []Color
|
||||||
bytes []byte
|
bytes []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *HextileEncoding) Type() int32 {
|
func (z *HextileEncoding) Type() int32 {
|
||||||
return 5
|
return 5
|
||||||
}
|
}
|
||||||
func (z *HextileEncoding) WriteTo(w io.Writer) (n int, err error) {
|
func (z *HextileEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||||
return w.Write(z.bytes)
|
return w.Write(z.bytes)
|
||||||
}
|
}
|
||||||
func (z *HextileEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
func (z *HextileEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||||
bytesPerPixel := int(pixelFmt.BPP) / 8
|
bytesPerPixel := int(pixelFmt.BPP) / 8
|
||||||
|
|
||||||
r.StartByteCollection()
|
r.StartByteCollection()
|
||||||
defer func() {
|
defer func() {
|
||||||
z.bytes = r.EndByteCollection()
|
z.bytes = r.EndByteCollection()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for ty := rect.Y; ty < rect.Y+rect.Height; ty += 16 {
|
for ty := rect.Y; ty < rect.Y+rect.Height; ty += 16 {
|
||||||
th := 16
|
th := 16
|
||||||
if rect.Y+rect.Height-ty < 16 {
|
if rect.Y+rect.Height-ty < 16 {
|
||||||
th = int(rect.Y) + int(rect.Height) - int(ty)
|
th = int(rect.Y) + int(rect.Height) - int(ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
for tx := rect.X; tx < rect.X+rect.Width; tx += 16 {
|
for tx := rect.X; tx < rect.X+rect.Width; tx += 16 {
|
||||||
tw := 16
|
tw := 16
|
||||||
if rect.X+rect.Width-tx < 16 {
|
if rect.X+rect.Width-tx < 16 {
|
||||||
tw = int(rect.X) + int(rect.Width) - int(tx)
|
tw = int(rect.X) + int(rect.Width) - int(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
//handle Hextile Subrect(tx, ty, tw, th):
|
//handle Hextile Subrect(tx, ty, tw, th):
|
||||||
subencoding, err := r.ReadUint8()
|
subencoding, err := r.ReadUint8()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("HextileEncoding.Read: error in hextile reader: %v", err)
|
logger.Errorf("HextileEncoding.Read: error in hextile reader: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subencoding & HextileRaw) != 0 {
|
if (subencoding & HextileRaw) != 0 {
|
||||||
r.ReadBytes(tw * th * bytesPerPixel)
|
r.ReadBytes(tw * th * bytesPerPixel)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (subencoding & HextileBackgroundSpecified) != 0 {
|
if (subencoding & HextileBackgroundSpecified) != 0 {
|
||||||
r.ReadBytes(int(bytesPerPixel))
|
r.ReadBytes(int(bytesPerPixel))
|
||||||
}
|
}
|
||||||
if (subencoding & HextileForegroundSpecified) != 0 {
|
if (subencoding & HextileForegroundSpecified) != 0 {
|
||||||
r.ReadBytes(int(bytesPerPixel))
|
r.ReadBytes(int(bytesPerPixel))
|
||||||
}
|
}
|
||||||
if (subencoding & HextileAnySubrects) == 0 {
|
if (subencoding & HextileAnySubrects) == 0 {
|
||||||
//logger.Debug("hextile reader: no Subrects")
|
//logger.Debug("hextile reader: no Subrects")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
nSubrects, err := r.ReadUint8()
|
nSubrects, err := r.ReadUint8()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
bufsize := int(nSubrects) * 2
|
bufsize := int(nSubrects) * 2
|
||||||
if (subencoding & HextileSubrectsColoured) != 0 {
|
if (subencoding & HextileSubrectsColoured) != 0 {
|
||||||
bufsize += int(nSubrects) * int(bytesPerPixel)
|
bufsize += int(nSubrects) * int(bytesPerPixel)
|
||||||
}
|
}
|
||||||
r.ReadBytes(bufsize)
|
r.ReadBytes(bufsize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return z, nil
|
return z, nil
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,6 @@ func (pe *PseudoEncoding) Type() int32 {
|
|||||||
func (z *PseudoEncoding) WriteTo(w io.Writer) (n int, err error) {
|
func (z *PseudoEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
func (pe *PseudoEncoding) Read(*common.PixelFormat, *common.Rectangle, *common.RfbReadHelper) (common.Encoding, error) {
|
func (pe *PseudoEncoding) Read(*common.PixelFormat, *common.Rectangle, *common.RfbReadHelper) (common.IEncoding, error) {
|
||||||
return pe, nil
|
return pe, nil
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ func (*RawEncoding) Type() int32 {
|
|||||||
func (z *RawEncoding) WriteTo(w io.Writer) (n int, err error) {
|
func (z *RawEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||||
return w.Write(z.bytes)
|
return w.Write(z.bytes)
|
||||||
}
|
}
|
||||||
func (*RawEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
func (*RawEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||||
|
|
||||||
bytesPerPixel := int(pixelFmt.BPP / 8)
|
bytesPerPixel := int(pixelFmt.BPP / 8)
|
||||||
|
|
||||||
|
@ -1,59 +1,59 @@
|
|||||||
package encodings
|
package encodings
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"io"
|
"io"
|
||||||
"vncproxy/common"
|
"vncproxy/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RREEncoding struct {
|
type RREEncoding struct {
|
||||||
//Colors []Color
|
//Colors []Color
|
||||||
numSubRects uint32
|
numSubRects uint32
|
||||||
backgroundColor []byte
|
backgroundColor []byte
|
||||||
subRectData []byte
|
subRectData []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *RREEncoding) WriteTo(w io.Writer) (n int, err error) {
|
func (z *RREEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||||
binary.Write(w, binary.BigEndian, z.numSubRects)
|
binary.Write(w, binary.BigEndian, z.numSubRects)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Write(z.backgroundColor)
|
w.Write(z.backgroundColor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Write(z.subRectData)
|
w.Write(z.subRectData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
b := len(z.backgroundColor) + len(z.subRectData) + 4
|
b := len(z.backgroundColor) + len(z.subRectData) + 4
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *RREEncoding) Type() int32 {
|
func (z *RREEncoding) Type() int32 {
|
||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
func (z *RREEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
func (z *RREEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||||
bytesPerPixel := int(pixelFmt.BPP / 8)
|
bytesPerPixel := int(pixelFmt.BPP / 8)
|
||||||
numOfSubrectangles, err := r.ReadUint32()
|
numOfSubrectangles, err := r.ReadUint32()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
z.numSubRects = numOfSubrectangles
|
z.numSubRects = numOfSubrectangles
|
||||||
|
|
||||||
//read whole-rect background color
|
//read whole-rect background color
|
||||||
z.backgroundColor, err = r.ReadBytes(bytesPerPixel)
|
z.backgroundColor, err = r.ReadBytes(bytesPerPixel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//read all individual rects (color=bytesPerPixel + x=16b + y=16b + w=16b + h=16b)
|
//read all individual rects (color=bytesPerPixel + x=16b + y=16b + w=16b + h=16b)
|
||||||
z.subRectData, err = r.ReadBytes(int(numOfSubrectangles) * (bytesPerPixel + 8)) // x+y+w+h=8 bytes
|
z.subRectData, err = r.ReadBytes(int(numOfSubrectangles) * (bytesPerPixel + 8)) // x+y+w+h=8 bytes
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return z, nil
|
return z, nil
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ type TightEncoding struct {
|
|||||||
bytes []byte
|
bytes []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (*TightEncoding) Type() int32 { return int32(common.EncTight) }
|
func (*TightEncoding) Type() int32 { return int32(common.EncTight) }
|
||||||
|
|
||||||
func calcTightBytePerPixel(pf *common.PixelFormat) int {
|
func calcTightBytePerPixel(pf *common.PixelFormat) int {
|
||||||
@ -51,7 +50,7 @@ func StoreBytes(bytes *bytes.Buffer, data []byte) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TightEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
func (t *TightEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||||
bytesPixel := calcTightBytePerPixel(pixelFmt)
|
bytesPixel := calcTightBytePerPixel(pixelFmt)
|
||||||
|
|
||||||
r.StartByteCollection()
|
r.StartByteCollection()
|
||||||
|
@ -17,7 +17,7 @@ func (z *TightPngEncoding) WriteTo(w io.Writer) (n int, err error) {
|
|||||||
|
|
||||||
func (*TightPngEncoding) Type() int32 { return int32(common.EncTightPng) }
|
func (*TightPngEncoding) Type() int32 { return int32(common.EncTightPng) }
|
||||||
|
|
||||||
func (t *TightPngEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
func (t *TightPngEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||||
bytesPixel := calcTightBytePerPixel(pixelFmt)
|
bytesPixel := calcTightBytePerPixel(pixelFmt)
|
||||||
r.StartByteCollection()
|
r.StartByteCollection()
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -1,38 +1,38 @@
|
|||||||
package encodings
|
package encodings
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"io"
|
"io"
|
||||||
"vncproxy/common"
|
"vncproxy/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ZLibEncoding struct {
|
type ZLibEncoding struct {
|
||||||
bytes []byte
|
bytes []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *ZLibEncoding) Type() int32 {
|
func (z *ZLibEncoding) Type() int32 {
|
||||||
return 6
|
return 6
|
||||||
}
|
}
|
||||||
func (z *ZLibEncoding) WriteTo(w io.Writer) (n int, err error) {
|
func (z *ZLibEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||||
return w.Write(z.bytes)
|
return w.Write(z.bytes)
|
||||||
}
|
}
|
||||||
func (z *ZLibEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
func (z *ZLibEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||||
//conn := common.RfbReadHelper{Reader:r}
|
//conn := common.RfbReadHelper{Reader:r}
|
||||||
//conn := &DataSource{conn: conn.c, PixelFormat: conn.PixelFormat}
|
//conn := &DataSource{conn: conn.c, PixelFormat: conn.PixelFormat}
|
||||||
//bytesPerPixel := c.PixelFormat.BPP / 8
|
//bytesPerPixel := c.PixelFormat.BPP / 8
|
||||||
bytes := &bytes.Buffer{}
|
bytes := &bytes.Buffer{}
|
||||||
len, err := r.ReadUint32()
|
len, err := r.ReadUint32()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
binary.Write(bytes, binary.BigEndian, len)
|
binary.Write(bytes, binary.BigEndian, len)
|
||||||
bts, err := r.ReadBytes(int(len))
|
bts, err := r.ReadBytes(int(len))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
StoreBytes(bytes, bts)
|
StoreBytes(bytes, bts)
|
||||||
z.bytes = bytes.Bytes()
|
z.bytes = bytes.Bytes()
|
||||||
return z, nil
|
return z, nil
|
||||||
}
|
}
|
||||||
|
@ -1,38 +1,38 @@
|
|||||||
package encodings
|
package encodings
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"io"
|
"io"
|
||||||
"vncproxy/common"
|
"vncproxy/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ZRLEEncoding struct {
|
type ZRLEEncoding struct {
|
||||||
bytes []byte
|
bytes []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *ZRLEEncoding) Type() int32 {
|
func (z *ZRLEEncoding) Type() int32 {
|
||||||
return 16
|
return 16
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *ZRLEEncoding) WriteTo(w io.Writer) (n int, err error) {
|
func (z *ZRLEEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||||
return w.Write(z.bytes)
|
return w.Write(z.bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *ZRLEEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
func (z *ZRLEEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||||
|
|
||||||
bytes := &bytes.Buffer{}
|
bytes := &bytes.Buffer{}
|
||||||
len, err := r.ReadUint32()
|
len, err := r.ReadUint32()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
binary.Write(bytes, binary.BigEndian, len)
|
binary.Write(bytes, binary.BigEndian, len)
|
||||||
bts, err := r.ReadBytes(int(len))
|
bts, err := r.ReadBytes(int(len))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
StoreBytes(bytes, bts)
|
StoreBytes(bytes, bts)
|
||||||
z.bytes = bytes.Bytes()
|
z.bytes = bytes.Bytes()
|
||||||
return z, nil
|
return z, nil
|
||||||
}
|
}
|
||||||
|
2
main.go
2
main.go
@ -47,7 +47,7 @@ func main() {
|
|||||||
// if err != nil {
|
// if err != nil {
|
||||||
// logger.Errorf("error requesting fb update: %s", err)
|
// logger.Errorf("error requesting fb update: %s", err)
|
||||||
// }
|
// }
|
||||||
encs := []common.Encoding{
|
encs := []common.IEncoding{
|
||||||
&encodings.TightEncoding{},
|
&encodings.TightEncoding{},
|
||||||
//&encodings.TightPngEncoding{},
|
//&encodings.TightPngEncoding{},
|
||||||
//rre := encodings.RREEncoding{},
|
//rre := encodings.RREEncoding{},
|
||||||
|
@ -21,12 +21,12 @@ type FBSPlayListener struct {
|
|||||||
|
|
||||||
func NewFBSPlayListener(conn *server.ServerConn, r *FbsReader) *FBSPlayListener {
|
func NewFBSPlayListener(conn *server.ServerConn, r *FbsReader) *FBSPlayListener {
|
||||||
h := &FBSPlayListener{Conn: conn, Fbs: r}
|
h := &FBSPlayListener{Conn: conn, Fbs: r}
|
||||||
cm := client.BellMessage(0)
|
cm := client.MsgBell(0)
|
||||||
h.serverMessageMap = make(map[uint8]common.ServerMessage)
|
h.serverMessageMap = make(map[uint8]common.ServerMessage)
|
||||||
h.serverMessageMap[0] = &client.FramebufferUpdateMessage{}
|
h.serverMessageMap[0] = &client.MsgFramebufferUpdate{}
|
||||||
h.serverMessageMap[1] = &client.SetColorMapEntriesMessage{}
|
h.serverMessageMap[1] = &client.MsgSetColorMapEntries{}
|
||||||
h.serverMessageMap[2] = &cm
|
h.serverMessageMap[2] = &cm
|
||||||
h.serverMessageMap[3] = &client.ServerCutTextMessage{}
|
h.serverMessageMap[3] = &client.MsgServerCutText{}
|
||||||
|
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ func (handler *FBSPlayListener) Consume(seg *common.RfbSegment) error {
|
|||||||
}
|
}
|
||||||
handler.sendFbsMessage()
|
handler.sendFbsMessage()
|
||||||
}
|
}
|
||||||
// server.FramebufferUpdateRequest:
|
// server.MsgFramebufferUpdateRequest:
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,13 @@ type FbsReader struct {
|
|||||||
buffer bytes.Buffer
|
buffer bytes.Buffer
|
||||||
currentTimestamp int
|
currentTimestamp int
|
||||||
pixelFormat *common.PixelFormat
|
pixelFormat *common.PixelFormat
|
||||||
encodings []common.Encoding
|
encodings []common.IEncoding
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fbs *FbsReader) Read(p []byte) (n int, err error) {
|
func (fbs *FbsReader) Read(p []byte) (n int, err error) {
|
||||||
if fbs.buffer.Len() < len(p) {
|
if fbs.buffer.Len() < len(p) {
|
||||||
seg, err := fbs.ReadSegment()
|
seg, err := fbs.ReadSegment()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("FBSReader.Read: error reading FBSsegment: ", err)
|
logger.Error("FBSReader.Read: error reading FBSsegment: ", err)
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -33,7 +34,7 @@ func (fbs *FbsReader) Read(p []byte) (n int, err error) {
|
|||||||
|
|
||||||
func (fbs *FbsReader) CurrentPixelFormat() *common.PixelFormat { return fbs.pixelFormat }
|
func (fbs *FbsReader) CurrentPixelFormat() *common.PixelFormat { return fbs.pixelFormat }
|
||||||
func (fbs *FbsReader) CurrentColorMap() *common.ColorMap { return &common.ColorMap{} }
|
func (fbs *FbsReader) CurrentColorMap() *common.ColorMap { return &common.ColorMap{} }
|
||||||
func (fbs *FbsReader) Encodings() []common.Encoding { return fbs.encodings }
|
func (fbs *FbsReader) Encodings() []common.IEncoding { return fbs.encodings }
|
||||||
|
|
||||||
func NewFbsReader(fbsFile string) (*FbsReader, error) {
|
func NewFbsReader(fbsFile string) (*FbsReader, error) {
|
||||||
|
|
||||||
@ -43,7 +44,7 @@ func NewFbsReader(fbsFile string) (*FbsReader, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &FbsReader{reader: reader,
|
return &FbsReader{reader: reader,
|
||||||
encodings: []common.Encoding{
|
encodings: []common.IEncoding{
|
||||||
&encodings.CopyRectEncoding{},
|
&encodings.CopyRectEncoding{},
|
||||||
&encodings.ZLibEncoding{},
|
&encodings.ZLibEncoding{},
|
||||||
&encodings.ZRLEEncoding{},
|
&encodings.ZRLEEncoding{},
|
||||||
@ -51,6 +52,7 @@ func NewFbsReader(fbsFile string) (*FbsReader, error) {
|
|||||||
&encodings.HextileEncoding{},
|
&encodings.HextileEncoding{},
|
||||||
&encodings.TightEncoding{},
|
&encodings.TightEncoding{},
|
||||||
&encodings.TightPngEncoding{},
|
&encodings.TightPngEncoding{},
|
||||||
|
&encodings.EncCursorPseudo{},
|
||||||
&encodings.RawEncoding{},
|
&encodings.RawEncoding{},
|
||||||
&encodings.RREEncoding{},
|
&encodings.RREEncoding{},
|
||||||
},
|
},
|
||||||
@ -71,7 +73,7 @@ func (fbs *FbsReader) ReadStartSession() (*common.ServerInit, error) {
|
|||||||
bytes := make([]byte, 12)
|
bytes := make([]byte, 12)
|
||||||
_, err := reader.Read(bytes)
|
_, err := reader.Read(bytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("error reading rbs init message - FBS file Version:", err)
|
logger.Error("FbsReader.ReadStartSession: error reading rbs init message - FBS file Version:", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,27 +82,27 @@ func (fbs *FbsReader) ReadStartSession() (*common.ServerInit, error) {
|
|||||||
bytes = make([]byte, 12)
|
bytes = make([]byte, 12)
|
||||||
_, err = fbs.Read(bytes)
|
_, err = fbs.Read(bytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("error reading rbs init - RFB Version: ", err)
|
logger.Error("FbsReader.ReadStartSession: error reading rbs init - RFB Version: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//push sec type and fb dimensions
|
//push sec type and fb dimensions
|
||||||
binary.Read(fbs, binary.BigEndian, &SecTypeNone)
|
binary.Read(fbs, binary.BigEndian, &SecTypeNone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("error reading rbs init - SecType: ", err)
|
logger.Error("FbsReader.ReadStartSession: error reading rbs init - SecType: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//read frame buffer width, height
|
//read frame buffer width, height
|
||||||
binary.Read(fbs, binary.BigEndian, &framebufferWidth)
|
binary.Read(fbs, binary.BigEndian, &framebufferWidth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("error reading rbs init - FBWidth: ", err)
|
logger.Error("FbsReader.ReadStartSession: error reading rbs init - FBWidth: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
initMsg.FBWidth = framebufferWidth
|
initMsg.FBWidth = framebufferWidth
|
||||||
|
|
||||||
binary.Read(fbs, binary.BigEndian, &framebufferHeight)
|
binary.Read(fbs, binary.BigEndian, &framebufferHeight)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("error reading rbs init - FBHeight: ", err)
|
logger.Error("FbsReader.ReadStartSession: error reading rbs init - FBHeight: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
initMsg.FBHeight = framebufferHeight
|
initMsg.FBHeight = framebufferHeight
|
||||||
@ -109,7 +111,7 @@ func (fbs *FbsReader) ReadStartSession() (*common.ServerInit, error) {
|
|||||||
pixelFormat := &common.PixelFormat{}
|
pixelFormat := &common.PixelFormat{}
|
||||||
binary.Read(fbs, binary.BigEndian, pixelFormat)
|
binary.Read(fbs, binary.BigEndian, pixelFormat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("error reading rbs init - Pixelformat: ", err)
|
logger.Error("FbsReader.ReadStartSession: error reading rbs init - Pixelformat: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
initMsg.PixelFormat = *pixelFormat
|
initMsg.PixelFormat = *pixelFormat
|
||||||
@ -122,7 +124,7 @@ func (fbs *FbsReader) ReadStartSession() (*common.ServerInit, error) {
|
|||||||
var desknameLen uint32
|
var desknameLen uint32
|
||||||
binary.Read(fbs, binary.BigEndian, &desknameLen)
|
binary.Read(fbs, binary.BigEndian, &desknameLen)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("error reading rbs init - deskname Len: ", err)
|
logger.Error("FbsReader.ReadStartSession: error reading rbs init - deskname Len: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
initMsg.NameLength = desknameLen
|
initMsg.NameLength = desknameLen
|
||||||
@ -130,7 +132,7 @@ func (fbs *FbsReader) ReadStartSession() (*common.ServerInit, error) {
|
|||||||
bytes = make([]byte, desknameLen)
|
bytes = make([]byte, desknameLen)
|
||||||
fbs.Read(bytes)
|
fbs.Read(bytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("error reading rbs init - desktopName: ", err)
|
logger.Error("FbsReader.ReadStartSession: error reading rbs init - desktopName: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +148,7 @@ func (fbs *FbsReader) ReadSegment() (*FbsSegment, error) {
|
|||||||
//read length
|
//read length
|
||||||
err := binary.Read(reader, binary.BigEndian, &bytesLen)
|
err := binary.Read(reader, binary.BigEndian, &bytesLen)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("error reading rbs file: ", err)
|
logger.Error("FbsReader.ReadStartSession: read len, error reading rbs file: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +158,7 @@ func (fbs *FbsReader) ReadSegment() (*FbsSegment, error) {
|
|||||||
bytes := make([]byte, paddedSize)
|
bytes := make([]byte, paddedSize)
|
||||||
_, err = reader.Read(bytes)
|
_, err = reader.Read(bytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("error reading rbs file: ", err)
|
logger.Error("FbsReader.ReadSegment: read bytes, error reading rbs file: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +169,7 @@ func (fbs *FbsReader) ReadSegment() (*FbsSegment, error) {
|
|||||||
var timeSinceStart uint32
|
var timeSinceStart uint32
|
||||||
binary.Read(reader, binary.BigEndian, &timeSinceStart)
|
binary.Read(reader, binary.BigEndian, &timeSinceStart)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("error reading rbs file: ", err)
|
logger.Error("FbsReader.ReadSegment: read timestamp, error reading rbs file: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package player
|
package player
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
"vncproxy/common"
|
"vncproxy/common"
|
||||||
@ -10,9 +9,7 @@ import (
|
|||||||
"vncproxy/server"
|
"vncproxy/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func connectFbsFile(filename string, conn *server.ServerConn) (*FbsReader, error) {
|
||||||
|
|
||||||
func loadFbsFile(filename string, conn *server.ServerConn) (*FbsReader, error) {
|
|
||||||
fbs, err := NewFbsReader(filename)
|
fbs, err := NewFbsReader(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("failed to open fbs reader:", err)
|
logger.Error("failed to open fbs reader:", err)
|
||||||
@ -37,10 +34,23 @@ func TestServer(t *testing.T) {
|
|||||||
//chServer := make(chan common.ClientMessage)
|
//chServer := make(chan common.ClientMessage)
|
||||||
//chClient := make(chan common.ServerMessage)
|
//chClient := make(chan common.ServerMessage)
|
||||||
|
|
||||||
|
encs := []common.IEncoding{
|
||||||
|
&encodings.RawEncoding{},
|
||||||
|
&encodings.TightEncoding{},
|
||||||
|
&encodings.EncCursorPseudo{},
|
||||||
|
//encodings.TightPngEncoding{},
|
||||||
|
&encodings.RREEncoding{},
|
||||||
|
&encodings.ZLibEncoding{},
|
||||||
|
&encodings.ZRLEEncoding{},
|
||||||
|
&encodings.CopyRectEncoding{},
|
||||||
|
&encodings.CoRREEncoding{},
|
||||||
|
&encodings.HextileEncoding{},
|
||||||
|
}
|
||||||
|
|
||||||
cfg := &server.ServerConfig{
|
cfg := &server.ServerConfig{
|
||||||
//SecurityHandlers: []SecurityHandler{&ServerAuthNone{}, &ServerAuthVNC{}},
|
//SecurityHandlers: []SecurityHandler{&ServerAuthNone{}, &ServerAuthVNC{}},
|
||||||
SecurityHandlers: []server.SecurityHandler{&server.ServerAuthNone{}},
|
SecurityHandlers: []server.SecurityHandler{&server.ServerAuthNone{}},
|
||||||
Encodings: []common.Encoding{&encodings.RawEncoding{}, &encodings.TightEncoding{}, &encodings.CopyRectEncoding{}},
|
Encodings: encs,
|
||||||
PixelFormat: common.NewPixelFormat(32),
|
PixelFormat: common.NewPixelFormat(32),
|
||||||
ClientMessages: server.DefaultClientMessages,
|
ClientMessages: server.DefaultClientMessages,
|
||||||
DesktopName: []byte("workDesk"),
|
DesktopName: []byte("workDesk"),
|
||||||
@ -51,7 +61,7 @@ func TestServer(t *testing.T) {
|
|||||||
cfg.NewConnHandler = func(cfg *server.ServerConfig, conn *server.ServerConn) error {
|
cfg.NewConnHandler = func(cfg *server.ServerConfig, conn *server.ServerConn) error {
|
||||||
//fbs, err := loadFbsFile("/Users/amitbet/Dropbox/recording.rbs", conn)
|
//fbs, err := loadFbsFile("/Users/amitbet/Dropbox/recording.rbs", conn)
|
||||||
//fbs, err := loadFbsFile("/Users/amitbet/vncRec/recording.rbs", conn)
|
//fbs, err := loadFbsFile("/Users/amitbet/vncRec/recording.rbs", conn)
|
||||||
fbs, err := loadFbsFile("/Users/amitbet/vncRec/recording1500411789.rbs", conn)
|
fbs, err := connectFbsFile("/Users/amitbet/vncRec/recording1500503851.rbs", conn)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("TestServer.NewConnHandler: Error in loading FBS: ", err)
|
logger.Error("TestServer.NewConnHandler: Error in loading FBS: ", err)
|
||||||
|
@ -24,7 +24,7 @@ func (cc *ClientUpdater) Consume(seg *common.RfbSegment) error {
|
|||||||
case common.SetPixelFormatMsgType:
|
case common.SetPixelFormatMsgType:
|
||||||
// update pixel format
|
// update pixel format
|
||||||
logger.Debugf("ClientUpdater.Consume: updating pixel format")
|
logger.Debugf("ClientUpdater.Consume: updating pixel format")
|
||||||
pixFmtMsg := clientMsg.(*server.SetPixelFormat)
|
pixFmtMsg := clientMsg.(*server.MsgSetPixelFormat)
|
||||||
cc.conn.PixelFormat = pixFmtMsg.PF
|
cc.conn.PixelFormat = pixFmtMsg.PF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ func (vp *VncProxy) newServerConnHandler(cfg *server.ServerConfig, sconn *server
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
encs := []common.Encoding{
|
encs := []common.IEncoding{
|
||||||
&encodings.RawEncoding{},
|
&encodings.RawEncoding{},
|
||||||
&encodings.TightEncoding{},
|
&encodings.TightEncoding{},
|
||||||
&encodings.EncCursorPseudo{},
|
&encodings.EncCursorPseudo{},
|
||||||
@ -128,7 +128,7 @@ func (vp *VncProxy) newServerConnHandler(cfg *server.ServerConfig, sconn *server
|
|||||||
&encodings.HextileEncoding{},
|
&encodings.HextileEncoding{},
|
||||||
}
|
}
|
||||||
cconn.Encs = encs
|
cconn.Encs = encs
|
||||||
//err = cconn.SetEncodings(encs)
|
//err = cconn.MsgSetEncodings(encs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("Proxy.newServerConnHandler error connecting to client: %s", err)
|
logger.Errorf("Proxy.newServerConnHandler error connecting to client: %s", err)
|
||||||
return err
|
return err
|
||||||
@ -148,7 +148,7 @@ func (vp *VncProxy) StartListening() {
|
|||||||
}
|
}
|
||||||
cfg := &server.ServerConfig{
|
cfg := &server.ServerConfig{
|
||||||
SecurityHandlers: secHandlers,
|
SecurityHandlers: secHandlers,
|
||||||
Encodings: []common.Encoding{&encodings.RawEncoding{}, &encodings.TightEncoding{}, &encodings.CopyRectEncoding{}},
|
Encodings: []common.IEncoding{&encodings.RawEncoding{}, &encodings.TightEncoding{}, &encodings.CopyRectEncoding{}},
|
||||||
PixelFormat: common.NewPixelFormat(32),
|
PixelFormat: common.NewPixelFormat(32),
|
||||||
ClientMessages: server.DefaultClientMessages,
|
ClientMessages: server.DefaultClientMessages,
|
||||||
DesktopName: []byte("workDesk"),
|
DesktopName: []byte("workDesk"),
|
||||||
|
@ -6,13 +6,6 @@ import (
|
|||||||
"vncproxy/common"
|
"vncproxy/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetPixelFormat holds the wire format message.
|
|
||||||
type SetPixelFormat struct {
|
|
||||||
_ [3]byte // padding
|
|
||||||
PF common.PixelFormat // pixel-format
|
|
||||||
_ [3]byte // padding after pixel format
|
|
||||||
}
|
|
||||||
|
|
||||||
// Key represents a VNC key press.
|
// Key represents a VNC key press.
|
||||||
type Key uint32
|
type Key uint32
|
||||||
|
|
||||||
@ -21,11 +14,18 @@ type Key uint32
|
|||||||
// Keys is a slice of Key values.
|
// Keys is a slice of Key values.
|
||||||
type Keys []Key
|
type Keys []Key
|
||||||
|
|
||||||
func (*SetPixelFormat) Type() common.ClientMessageType {
|
// MsgSetPixelFormat holds the wire format message.
|
||||||
|
type MsgSetPixelFormat struct {
|
||||||
|
_ [3]byte // padding
|
||||||
|
PF common.PixelFormat // pixel-format
|
||||||
|
_ [3]byte // padding after pixel format
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*MsgSetPixelFormat) Type() common.ClientMessageType {
|
||||||
return common.SetPixelFormatMsgType
|
return common.SetPixelFormatMsgType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *SetPixelFormat) Write(c io.Writer) error {
|
func (msg *MsgSetPixelFormat) Write(c io.Writer) error {
|
||||||
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
|
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -43,27 +43,27 @@ func (msg *SetPixelFormat) Write(c io.Writer) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*SetPixelFormat) Read(c io.Reader) (common.ClientMessage, error) {
|
func (*MsgSetPixelFormat) Read(c io.Reader) (common.ClientMessage, error) {
|
||||||
msg := SetPixelFormat{}
|
msg := MsgSetPixelFormat{}
|
||||||
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
|
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &msg, nil
|
return &msg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetEncodings holds the wire format message, sans encoding-type field.
|
// MsgSetEncodings holds the wire format message, sans encoding-type field.
|
||||||
type SetEncodings struct {
|
type MsgSetEncodings struct {
|
||||||
_ [1]byte // padding
|
_ [1]byte // padding
|
||||||
EncNum uint16 // number-of-encodings
|
EncNum uint16 // number-of-encodings
|
||||||
Encodings []common.EncodingType
|
Encodings []common.EncodingType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*SetEncodings) Type() common.ClientMessageType {
|
func (*MsgSetEncodings) Type() common.ClientMessageType {
|
||||||
return common.SetEncodingsMsgType
|
return common.SetEncodingsMsgType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*SetEncodings) Read(c io.Reader) (common.ClientMessage, error) {
|
func (*MsgSetEncodings) Read(c io.Reader) (common.ClientMessage, error) {
|
||||||
msg := SetEncodings{}
|
msg := MsgSetEncodings{}
|
||||||
var pad [1]byte
|
var pad [1]byte
|
||||||
if err := binary.Read(c, binary.BigEndian, &pad); err != nil {
|
if err := binary.Read(c, binary.BigEndian, &pad); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -79,11 +79,11 @@ func (*SetEncodings) Read(c io.Reader) (common.ClientMessage, error) {
|
|||||||
}
|
}
|
||||||
msg.Encodings = append(msg.Encodings, enc)
|
msg.Encodings = append(msg.Encodings, enc)
|
||||||
}
|
}
|
||||||
c.(common.ServerConn).SetEncodings(msg.Encodings)
|
c.(common.IServerConn).SetEncodings(msg.Encodings)
|
||||||
return &msg, nil
|
return &msg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *SetEncodings) Write(c io.Writer) error {
|
func (msg *MsgSetEncodings) Write(c io.Writer) error {
|
||||||
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
|
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -107,26 +107,26 @@ func (msg *SetEncodings) Write(c io.Writer) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FramebufferUpdateRequest holds the wire format message.
|
// MsgFramebufferUpdateRequest holds the wire format message.
|
||||||
type FramebufferUpdateRequest struct {
|
type MsgFramebufferUpdateRequest struct {
|
||||||
Inc uint8 // incremental
|
Inc uint8 // incremental
|
||||||
X, Y uint16 // x-, y-position
|
X, Y uint16 // x-, y-position
|
||||||
Width, Height uint16 // width, height
|
Width, Height uint16 // width, height
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*FramebufferUpdateRequest) Type() common.ClientMessageType {
|
func (*MsgFramebufferUpdateRequest) Type() common.ClientMessageType {
|
||||||
return common.FramebufferUpdateRequestMsgType
|
return common.FramebufferUpdateRequestMsgType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*FramebufferUpdateRequest) Read(c io.Reader) (common.ClientMessage, error) {
|
func (*MsgFramebufferUpdateRequest) Read(c io.Reader) (common.ClientMessage, error) {
|
||||||
msg := FramebufferUpdateRequest{}
|
msg := MsgFramebufferUpdateRequest{}
|
||||||
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
|
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &msg, nil
|
return &msg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *FramebufferUpdateRequest) Write(c io.Writer) error {
|
func (msg *MsgFramebufferUpdateRequest) Write(c io.Writer) error {
|
||||||
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
|
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -136,26 +136,26 @@ func (msg *FramebufferUpdateRequest) Write(c io.Writer) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// KeyEvent holds the wire format message.
|
// MsgKeyEvent holds the wire format message.
|
||||||
type KeyEvent struct {
|
type MsgKeyEvent struct {
|
||||||
Down uint8 // down-flag
|
Down uint8 // down-flag
|
||||||
_ [2]byte // padding
|
_ [2]byte // padding
|
||||||
Key Key // key
|
Key Key // key
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*KeyEvent) Type() common.ClientMessageType {
|
func (*MsgKeyEvent) Type() common.ClientMessageType {
|
||||||
return common.KeyEventMsgType
|
return common.KeyEventMsgType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*KeyEvent) Read(c io.Reader) (common.ClientMessage, error) {
|
func (*MsgKeyEvent) Read(c io.Reader) (common.ClientMessage, error) {
|
||||||
msg := KeyEvent{}
|
msg := MsgKeyEvent{}
|
||||||
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
|
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &msg, nil
|
return &msg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *KeyEvent) Write(c io.Writer) error {
|
func (msg *MsgKeyEvent) Write(c io.Writer) error {
|
||||||
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
|
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -166,24 +166,24 @@ func (msg *KeyEvent) Write(c io.Writer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PointerEventMessage holds the wire format message.
|
// PointerEventMessage holds the wire format message.
|
||||||
type PointerEvent struct {
|
type MsgPointerEvent struct {
|
||||||
Mask uint8 // button-mask
|
Mask uint8 // button-mask
|
||||||
X, Y uint16 // x-, y-position
|
X, Y uint16 // x-, y-position
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*PointerEvent) Type() common.ClientMessageType {
|
func (*MsgPointerEvent) Type() common.ClientMessageType {
|
||||||
return common.PointerEventMsgType
|
return common.PointerEventMsgType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*PointerEvent) Read(c io.Reader) (common.ClientMessage, error) {
|
func (*MsgPointerEvent) Read(c io.Reader) (common.ClientMessage, error) {
|
||||||
msg := PointerEvent{}
|
msg := MsgPointerEvent{}
|
||||||
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
|
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &msg, nil
|
return &msg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *PointerEvent) Write(c io.Writer) error {
|
func (msg *MsgPointerEvent) Write(c io.Writer) error {
|
||||||
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
|
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -193,14 +193,14 @@ func (msg *PointerEvent) Write(c io.Writer) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type ClientFence struct {
|
type MsgClientFence struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*ClientFence) Type() common.ClientMessageType {
|
func (*MsgClientFence) Type() common.ClientMessageType {
|
||||||
return common.ClientFenceMsgType
|
return common.ClientFenceMsgType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cf *ClientFence) Read(c io.Reader) (common.ClientMessage, error) {
|
func (cf *MsgClientFence) Read(c io.Reader) (common.ClientMessage, error) {
|
||||||
bytes := make([]byte, 3)
|
bytes := make([]byte, 3)
|
||||||
c.Read(bytes)
|
c.Read(bytes)
|
||||||
if _, err := c.Read(bytes); err != nil {
|
if _, err := c.Read(bytes); err != nil {
|
||||||
@ -223,23 +223,23 @@ func (cf *ClientFence) Read(c io.Reader) (common.ClientMessage, error) {
|
|||||||
return cf, nil
|
return cf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *ClientFence) Write(c io.Writer) error {
|
func (msg *MsgClientFence) Write(c io.Writer) error {
|
||||||
panic("not implemented!")
|
panic("not implemented!")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientCutText holds the wire format message, sans the text field.
|
// MsgClientCutText holds the wire format message, sans the text field.
|
||||||
type ClientCutText struct {
|
type MsgClientCutText struct {
|
||||||
_ [3]byte // padding
|
_ [3]byte // padding
|
||||||
Length uint32 // length
|
Length uint32 // length
|
||||||
Text []byte
|
Text []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*ClientCutText) Type() common.ClientMessageType {
|
func (*MsgClientCutText) Type() common.ClientMessageType {
|
||||||
return common.ClientCutTextMsgType
|
return common.ClientCutTextMsgType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*ClientCutText) Read(c io.Reader) (common.ClientMessage, error) {
|
func (*MsgClientCutText) Read(c io.Reader) (common.ClientMessage, error) {
|
||||||
msg := ClientCutText{}
|
msg := MsgClientCutText{}
|
||||||
var pad [3]byte
|
var pad [3]byte
|
||||||
if err := binary.Read(c, binary.BigEndian, &pad); err != nil {
|
if err := binary.Read(c, binary.BigEndian, &pad); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -256,7 +256,7 @@ func (*ClientCutText) Read(c io.Reader) (common.ClientMessage, error) {
|
|||||||
return &msg, nil
|
return &msg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *ClientCutText) Write(c io.Writer) error {
|
func (msg *MsgClientCutText) Write(c io.Writer) error {
|
||||||
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
|
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ const (
|
|||||||
type SecurityHandler interface {
|
type SecurityHandler interface {
|
||||||
Type() SecurityType
|
Type() SecurityType
|
||||||
SubType() SecuritySubType
|
SubType() SecuritySubType
|
||||||
Auth(common.ServerConn) error
|
Auth(common.IServerConn) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// type ClientAuthNone struct{}
|
// type ClientAuthNone struct{}
|
||||||
@ -62,7 +62,7 @@ type SecurityHandler interface {
|
|||||||
// return SecSubTypeUnknown
|
// return SecSubTypeUnknown
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// func (*ClientAuthNone) Auth(conn common.ServerConn) error {
|
// func (*ClientAuthNone) Auth(conn common.IServerConn) error {
|
||||||
// return nil
|
// return nil
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ func (*ServerAuthNone) Type() SecurityType {
|
|||||||
return SecTypeNone
|
return SecTypeNone
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*ServerAuthNone) Auth(c common.ServerConn) error {
|
func (*ServerAuthNone) Auth(c common.IServerConn) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ func (*ServerAuthNone) SubType() SecuritySubType {
|
|||||||
// Password []byte
|
// Password []byte
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// func (auth *ClientAuthVeNCrypt02Plain) Auth(c common.ServerConn) error {
|
// func (auth *ClientAuthVeNCrypt02Plain) Auth(c common.IServerConn) error {
|
||||||
// if err := binary.Write(c, binary.BigEndian, []uint8{0, 2}); err != nil {
|
// if err := binary.Write(c, binary.BigEndian, []uint8{0, 2}); err != nil {
|
||||||
// return err
|
// return err
|
||||||
// }
|
// }
|
||||||
@ -198,7 +198,7 @@ func (*ServerAuthVNC) SubType() SecuritySubType {
|
|||||||
|
|
||||||
const AUTH_FAIL = "Authentication Failure"
|
const AUTH_FAIL = "Authentication Failure"
|
||||||
|
|
||||||
func (auth *ServerAuthVNC) Auth(c common.ServerConn) error {
|
func (auth *ServerAuthVNC) Auth(c common.IServerConn) error {
|
||||||
buf := make([]byte, 8+len([]byte(AUTH_FAIL)))
|
buf := make([]byte, 8+len([]byte(AUTH_FAIL)))
|
||||||
rand.Read(buf[:16]) // Random 16 bytes in buf
|
rand.Read(buf[:16]) // Random 16 bytes in buf
|
||||||
sndsz, err := c.Write(buf[:16])
|
sndsz, err := c.Write(buf[:16])
|
||||||
@ -290,7 +290,7 @@ func fixDesKey(key string) []byte {
|
|||||||
// return SecSubTypeUnknown
|
// return SecSubTypeUnknown
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// func (auth *ClientAuthVNC) Auth(c common.ServerConn) error {
|
// func (auth *ClientAuthVNC) Auth(c common.IServerConn) error {
|
||||||
// if len(auth.Password) == 0 {
|
// if len(auth.Password) == 0 {
|
||||||
// return fmt.Errorf("Security Handshake failed; no password provided for VNCAuth.")
|
// return fmt.Errorf("Security Handshake failed; no password provided for VNCAuth.")
|
||||||
// }
|
// }
|
||||||
|
@ -18,15 +18,14 @@ type ServerConn struct {
|
|||||||
// If the pixel format uses a color map, then this is the color
|
// If the pixel format uses a color map, then this is the color
|
||||||
// map that is used. This should not be modified directly, since
|
// map that is used. This should not be modified directly, since
|
||||||
// the data comes from the server.
|
// the data comes from the server.
|
||||||
// Definition in §5 - Representation of Pixel Data.
|
|
||||||
colorMap *common.ColorMap
|
colorMap *common.ColorMap
|
||||||
|
|
||||||
// Name associated with the desktop, sent from the server.
|
// Name associated with the desktop, sent from the server.
|
||||||
desktopName string
|
desktopName string
|
||||||
|
|
||||||
// Encodings supported by the client. This should not be modified
|
// Encodings supported by the client. This should not be modified
|
||||||
// directly. Instead, SetEncodings() should be used.
|
// directly. Instead, MsgSetEncodings() should be used.
|
||||||
encodings []common.Encoding
|
encodings []common.IEncoding
|
||||||
|
|
||||||
// Height of the frame buffer in pixels, sent to the client.
|
// Height of the frame buffer in pixels, sent to the client.
|
||||||
fbHeight uint16
|
fbHeight uint16
|
||||||
@ -47,7 +46,7 @@ type ServerConn struct {
|
|||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (c *ServerConn) UnreadByte() error {
|
// func (c *IServerConn) UnreadByte() error {
|
||||||
// return c.br.UnreadByte()
|
// return c.br.UnreadByte()
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@ -79,7 +78,7 @@ func (c *ServerConn) Conn() io.ReadWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ServerConn) SetEncodings(encs []common.EncodingType) error {
|
func (c *ServerConn) SetEncodings(encs []common.EncodingType) error {
|
||||||
encodings := make(map[int32]common.Encoding)
|
encodings := make(map[int32]common.IEncoding)
|
||||||
for _, enc := range c.cfg.Encodings {
|
for _, enc := range c.cfg.Encodings {
|
||||||
encodings[enc.Type()] = enc
|
encodings[enc.Type()] = enc
|
||||||
}
|
}
|
||||||
@ -129,7 +128,7 @@ func (c *ServerConn) SetPixelFormat(pf *common.PixelFormat) error {
|
|||||||
c.pixelFormat = pf
|
c.pixelFormat = pf
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (c *ServerConn) Encodings() []common.Encoding {
|
func (c *ServerConn) Encodings() []common.IEncoding {
|
||||||
return c.encodings
|
return c.encodings
|
||||||
}
|
}
|
||||||
func (c *ServerConn) Width() uint16 {
|
func (c *ServerConn) Width() uint16 {
|
||||||
@ -169,12 +168,12 @@ func (c *ServerConn) handle() error {
|
|||||||
default:
|
default:
|
||||||
var messageType common.ClientMessageType
|
var messageType common.ClientMessageType
|
||||||
if err := binary.Read(c, binary.BigEndian, &messageType); err != nil {
|
if err := binary.Read(c, binary.BigEndian, &messageType); err != nil {
|
||||||
logger.Errorf("ServerConn.handle error: %v", err)
|
logger.Errorf("IServerConn.handle error: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
msg, ok := clientMessages[messageType]
|
msg, ok := clientMessages[messageType]
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("ServerConn.Handle: unsupported message-type: %v", messageType)
|
return fmt.Errorf("IServerConn.Handle: unsupported message-type: %v", messageType)
|
||||||
}
|
}
|
||||||
|
|
||||||
parsedMsg, err := msg.Read(c)
|
parsedMsg, err := msg.Read(c)
|
||||||
@ -184,7 +183,7 @@ func (c *ServerConn) handle() error {
|
|||||||
case common.SetPixelFormatMsgType:
|
case common.SetPixelFormatMsgType:
|
||||||
// update pixel format
|
// update pixel format
|
||||||
logger.Debugf("ClientUpdater.Consume: updating pixel format")
|
logger.Debugf("ClientUpdater.Consume: updating pixel format")
|
||||||
pixFmtMsg := parsedMsg.(*SetPixelFormat)
|
pixFmtMsg := parsedMsg.(*MsgSetPixelFormat)
|
||||||
c.SetPixelFormat(&pixFmtMsg.PF)
|
c.SetPixelFormat(&pixFmtMsg.PF)
|
||||||
if pixFmtMsg.PF.TrueColor != 0 {
|
if pixFmtMsg.PF.TrueColor != 0 {
|
||||||
c.SetColorMap(&common.ColorMap{})
|
c.SetColorMap(&common.ColorMap{})
|
||||||
@ -197,7 +196,7 @@ func (c *ServerConn) handle() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Infof("ServerConn.Handle got ClientMessage: %s, %v", parsedMsg.Type(), parsedMsg)
|
logger.Infof("IServerConn.Handle got ClientMessage: %s, %v", parsedMsg.Type(), parsedMsg)
|
||||||
//TODO: treat set encodings by allowing only supported encoding in proxy configurations
|
//TODO: treat set encodings by allowing only supported encoding in proxy configurations
|
||||||
//// if parsedMsg.Type() == common.SetEncodingsMsgType{
|
//// if parsedMsg.Type() == common.SetEncodingsMsgType{
|
||||||
//// c.cfg.Encodings
|
//// c.cfg.Encodings
|
||||||
@ -209,7 +208,7 @@ func (c *ServerConn) handle() error {
|
|||||||
}
|
}
|
||||||
err = c.Listeners.Consume(seg)
|
err = c.Listeners.Consume(seg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("ServerConn.Handle: listener consume err %s", err.Error())
|
logger.Errorf("IServerConn.Handle: listener consume err %s", err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var DefaultClientMessages = []common.ClientMessage{
|
var DefaultClientMessages = []common.ClientMessage{
|
||||||
&SetPixelFormat{},
|
&MsgSetPixelFormat{},
|
||||||
&SetEncodings{},
|
&MsgSetEncodings{},
|
||||||
&FramebufferUpdateRequest{},
|
&MsgFramebufferUpdateRequest{},
|
||||||
&KeyEvent{},
|
&MsgKeyEvent{},
|
||||||
&PointerEvent{},
|
&MsgPointerEvent{},
|
||||||
&ClientCutText{},
|
&MsgClientCutText{},
|
||||||
}
|
}
|
||||||
|
|
||||||
// FramebufferUpdate holds a FramebufferUpdate wire format message.
|
// FramebufferUpdate holds a FramebufferUpdate wire format message.
|
||||||
@ -28,7 +28,7 @@ type ServerHandler func(*ServerConfig, *ServerConn) error
|
|||||||
|
|
||||||
type ServerConfig struct {
|
type ServerConfig struct {
|
||||||
SecurityHandlers []SecurityHandler
|
SecurityHandlers []SecurityHandler
|
||||||
Encodings []common.Encoding
|
Encodings []common.IEncoding
|
||||||
PixelFormat *common.PixelFormat
|
PixelFormat *common.PixelFormat
|
||||||
ColorMap *common.ColorMap
|
ColorMap *common.ColorMap
|
||||||
ClientMessages []common.ClientMessage
|
ClientMessages []common.ClientMessage
|
||||||
|
@ -20,13 +20,13 @@ func TestServer(t *testing.T) {
|
|||||||
cfg := &ServerConfig{
|
cfg := &ServerConfig{
|
||||||
//SecurityHandlers: []SecurityHandler{&ServerAuthNone{}, &ServerAuthVNC{}},
|
//SecurityHandlers: []SecurityHandler{&ServerAuthNone{}, &ServerAuthVNC{}},
|
||||||
SecurityHandlers: []SecurityHandler{&ServerAuthVNC{"Ch_#!T@8"}},
|
SecurityHandlers: []SecurityHandler{&ServerAuthVNC{"Ch_#!T@8"}},
|
||||||
Encodings: []common.Encoding{&encodings.RawEncoding{}, &encodings.TightEncoding{}, &encodings.CopyRectEncoding{}},
|
Encodings: []common.IEncoding{&encodings.RawEncoding{}, &encodings.TightEncoding{}, &encodings.CopyRectEncoding{}},
|
||||||
PixelFormat: common.NewPixelFormat(32),
|
PixelFormat: common.NewPixelFormat(32),
|
||||||
ClientMessages: DefaultClientMessages,
|
ClientMessages: DefaultClientMessages,
|
||||||
DesktopName: []byte("workDesk"),
|
DesktopName: []byte("workDesk"),
|
||||||
Height: uint16(768),
|
Height: uint16(768),
|
||||||
Width: uint16(1024),
|
Width: uint16(1024),
|
||||||
NewConnHandler: newServerConnHandler,
|
NewConnHandler: newServerConnHandler,
|
||||||
}
|
}
|
||||||
url := "http://localhost:8091/"
|
url := "http://localhost:8091/"
|
||||||
go WsServe(url, cfg)
|
go WsServe(url, cfg)
|
||||||
|
@ -15,17 +15,9 @@ type WsServer struct {
|
|||||||
|
|
||||||
type WsHandler func(io.ReadWriter, *ServerConfig, string)
|
type WsHandler func(io.ReadWriter, *ServerConfig, string)
|
||||||
|
|
||||||
// func checkOrigin(config *websocket.Config, req *http.Request) (err error) {
|
|
||||||
// config.Origin, err = websocket.Origin(config, req)
|
|
||||||
// if err == nil && config.Origin == nil {
|
|
||||||
// return fmt.Errorf("null origin")
|
|
||||||
// }
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
|
|
||||||
// This example demonstrates a trivial echo server.
|
|
||||||
func (wsServer *WsServer) Listen(urlStr string, handlerFunc WsHandler) {
|
func (wsServer *WsServer) Listen(urlStr string, handlerFunc WsHandler) {
|
||||||
//http.Handle("/", websocket.Handler(EchoHandler))
|
|
||||||
if urlStr == "" {
|
if urlStr == "" {
|
||||||
urlStr = "/"
|
urlStr = "/"
|
||||||
}
|
}
|
||||||
@ -34,17 +26,6 @@ func (wsServer *WsServer) Listen(urlStr string, handlerFunc WsHandler) {
|
|||||||
logger.Errorf("error while parsing url: ", err)
|
logger.Errorf("error while parsing url: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// http.HandleFunc(url.Path,
|
|
||||||
// func(w http.ResponseWriter, req *http.Request) {
|
|
||||||
// sessionId := req.URL.Query().Get("sessionId")
|
|
||||||
// s := websocket.Server{Handshake: checkOrigin, Handler: websocket.Handler(
|
|
||||||
// func(ws *websocket.ServerConn) {
|
|
||||||
// ws.PayloadType = websocket.BinaryFrame
|
|
||||||
// handlerFunc(ws, wsServer.cfg, sessionId)
|
|
||||||
// })}
|
|
||||||
// s.ServeHTTP(w, req)
|
|
||||||
// })
|
|
||||||
|
|
||||||
http.Handle(url.Path, websocket.Handler(
|
http.Handle(url.Path, websocket.Handler(
|
||||||
func(ws *websocket.Conn) {
|
func(ws *websocket.Conn) {
|
||||||
path := ws.Request().URL.Path
|
path := ws.Request().URL.Path
|
||||||
|
@ -1 +0,0 @@
|
|||||||
package server
|
|
@ -163,7 +163,7 @@ func (r *Recorder) HandleRfbSegment(data *common.RfbSegment) error {
|
|||||||
|
|
||||||
switch clientMsg.Type() {
|
switch clientMsg.Type() {
|
||||||
case common.SetPixelFormatMsgType:
|
case common.SetPixelFormatMsgType:
|
||||||
clientMsg := data.Message.(*server.SetPixelFormat)
|
clientMsg := data.Message.(*server.MsgSetPixelFormat)
|
||||||
logger.Debugf("Recorder.HandleRfbSegment: client message %v", *clientMsg)
|
logger.Debugf("Recorder.HandleRfbSegment: client message %v", *clientMsg)
|
||||||
r.serverInitMessage.PixelFormat = clientMsg.PF
|
r.serverInitMessage.PixelFormat = clientMsg.PF
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user