1
0
mirror of https://github.com/amitbet/vncproxy.git synced 2025-05-05 06:06:21 +00:00

general refactoring + fixed setcursorpseudo

This commit is contained in:
amit bezalel 2017-07-20 02:01:40 +03:00
parent 662e8393e9
commit 2d87ae5773
38 changed files with 1082 additions and 1381 deletions

View File

@ -1,6 +1,8 @@
<component name="libraryTable">
<library name="GOPATH &lt;vncproxy&gt;">
<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$/../gopkg.in" />
<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/srf" />
<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>
<JAVADOC />
<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$/../gopkg.in" />
<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/srf" />
<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>
<excluded>
<root url="file://$PROJECT_DIR$" />

File diff suppressed because it is too large Load Diff

View File

@ -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 {

View File

@ -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")
}
}
}

View File

@ -1,6 +0,0 @@
package client
// Color represents a single color in a color map.
type Color struct {
R, G, B uint16
}

View File

@ -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
}

View File

@ -30,27 +30,6 @@ type Color struct {
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
type ClientMessage interface {
Type() ClientMessageType

30
common/conn-interfaces.go Normal file
View 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
}

View File

@ -6,16 +6,16 @@ import (
"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.
type Encoding interface {
type IEncoding interface {
// The number that uniquely identifies this encoding type.
Type() int32
WriteTo(w io.Writer) (n int, err error)
// 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.
Read(*PixelFormat, *Rectangle, *RfbReadHelper) (Encoding, error)
Read(*PixelFormat, *Rectangle, *RfbReadHelper) (IEncoding, error)
}
// EncodingType represents a known VNC encoding type.

View File

@ -1,18 +1,18 @@
package common
import (
"fmt"
)
// Rectangle represents a rectangle of pixel data.
type Rectangle struct {
X uint16
Y uint16
Width uint16
Height uint16
Enc Encoding
}
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())
}
package common
import (
"fmt"
)
// Rectangle represents a rectangle of pixel data.
type Rectangle struct {
X uint16
Y uint16
Width uint16
Height uint16
Enc IEncoding
}
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())
}

View File

@ -4,12 +4,6 @@ import (
"io"
)
type IClientConn interface {
CurrentPixelFormat() *PixelFormat
CurrentColorMap() *ColorMap
Encodings() []Encoding
}
type ServerMessage interface {
Type() uint8
String() string

View File

@ -27,7 +27,7 @@ func (z *CopyRectEncoding) WriteTo(w io.Writer) (n int, err error) {
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.copyRectSrcY, _ = r.ReadUint16()
return z, nil

View File

@ -36,7 +36,7 @@ func (z *CoRREEncoding) WriteTo(w io.Writer) (n int, err error) {
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)
numOfSubrectangles, err := r.ReadUint32()
if err != nil {

View File

@ -15,7 +15,7 @@ func (pe *EncCursorPseudo) Type() int32 {
func (z *EncCursorPseudo) WriteTo(w io.Writer) (n int, err error) {
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 {
return pe, nil
}

View File

@ -1,84 +1,84 @@
package encodings
import (
"io"
"vncproxy/common"
"vncproxy/logger"
)
const (
HextileRaw = 1
HextileBackgroundSpecified = 2
HextileForegroundSpecified = 4
HextileAnySubrects = 8
HextileSubrectsColoured = 16
)
type HextileEncoding struct {
//Colors []Color
bytes []byte
}
func (z *HextileEncoding) Type() int32 {
return 5
}
func (z *HextileEncoding) WriteTo(w io.Writer) (n int, err error) {
return w.Write(z.bytes)
}
func (z *HextileEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
bytesPerPixel := int(pixelFmt.BPP) / 8
r.StartByteCollection()
defer func() {
z.bytes = r.EndByteCollection()
}()
for ty := rect.Y; ty < rect.Y+rect.Height; ty += 16 {
th := 16
if rect.Y+rect.Height-ty < 16 {
th = int(rect.Y) + int(rect.Height) - int(ty)
}
for tx := rect.X; tx < rect.X+rect.Width; tx += 16 {
tw := 16
if rect.X+rect.Width-tx < 16 {
tw = int(rect.X) + int(rect.Width) - int(tx)
}
//handle Hextile Subrect(tx, ty, tw, th):
subencoding, err := r.ReadUint8()
if err != nil {
logger.Errorf("HextileEncoding.Read: error in hextile reader: %v", err)
return nil, err
}
if (subencoding & HextileRaw) != 0 {
r.ReadBytes(tw * th * bytesPerPixel)
continue
}
if (subencoding & HextileBackgroundSpecified) != 0 {
r.ReadBytes(int(bytesPerPixel))
}
if (subencoding & HextileForegroundSpecified) != 0 {
r.ReadBytes(int(bytesPerPixel))
}
if (subencoding & HextileAnySubrects) == 0 {
//logger.Debug("hextile reader: no Subrects")
continue
}
nSubrects, err := r.ReadUint8()
if err != nil {
return nil, err
}
bufsize := int(nSubrects) * 2
if (subencoding & HextileSubrectsColoured) != 0 {
bufsize += int(nSubrects) * int(bytesPerPixel)
}
r.ReadBytes(bufsize)
}
}
return z, nil
}
package encodings
import (
"io"
"vncproxy/common"
"vncproxy/logger"
)
const (
HextileRaw = 1
HextileBackgroundSpecified = 2
HextileForegroundSpecified = 4
HextileAnySubrects = 8
HextileSubrectsColoured = 16
)
type HextileEncoding struct {
//Colors []Color
bytes []byte
}
func (z *HextileEncoding) Type() int32 {
return 5
}
func (z *HextileEncoding) WriteTo(w io.Writer) (n int, err error) {
return w.Write(z.bytes)
}
func (z *HextileEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
bytesPerPixel := int(pixelFmt.BPP) / 8
r.StartByteCollection()
defer func() {
z.bytes = r.EndByteCollection()
}()
for ty := rect.Y; ty < rect.Y+rect.Height; ty += 16 {
th := 16
if rect.Y+rect.Height-ty < 16 {
th = int(rect.Y) + int(rect.Height) - int(ty)
}
for tx := rect.X; tx < rect.X+rect.Width; tx += 16 {
tw := 16
if rect.X+rect.Width-tx < 16 {
tw = int(rect.X) + int(rect.Width) - int(tx)
}
//handle Hextile Subrect(tx, ty, tw, th):
subencoding, err := r.ReadUint8()
if err != nil {
logger.Errorf("HextileEncoding.Read: error in hextile reader: %v", err)
return nil, err
}
if (subencoding & HextileRaw) != 0 {
r.ReadBytes(tw * th * bytesPerPixel)
continue
}
if (subencoding & HextileBackgroundSpecified) != 0 {
r.ReadBytes(int(bytesPerPixel))
}
if (subencoding & HextileForegroundSpecified) != 0 {
r.ReadBytes(int(bytesPerPixel))
}
if (subencoding & HextileAnySubrects) == 0 {
//logger.Debug("hextile reader: no Subrects")
continue
}
nSubrects, err := r.ReadUint8()
if err != nil {
return nil, err
}
bufsize := int(nSubrects) * 2
if (subencoding & HextileSubrectsColoured) != 0 {
bufsize += int(nSubrects) * int(bytesPerPixel)
}
r.ReadBytes(bufsize)
}
}
return z, nil
}

View File

@ -15,6 +15,6 @@ func (pe *PseudoEncoding) Type() int32 {
func (z *PseudoEncoding) WriteTo(w io.Writer) (n int, err error) {
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
}

View File

@ -17,7 +17,7 @@ func (*RawEncoding) Type() int32 {
func (z *RawEncoding) WriteTo(w io.Writer) (n int, err error) {
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)

View File

@ -1,59 +1,59 @@
package encodings
import (
"encoding/binary"
"io"
"vncproxy/common"
)
type RREEncoding struct {
//Colors []Color
numSubRects uint32
backgroundColor []byte
subRectData []byte
}
func (z *RREEncoding) WriteTo(w io.Writer) (n int, err error) {
binary.Write(w, binary.BigEndian, z.numSubRects)
if err != nil {
return 0, err
}
w.Write(z.backgroundColor)
if err != nil {
return 0, err
}
w.Write(z.subRectData)
if err != nil {
return 0, err
}
b := len(z.backgroundColor) + len(z.subRectData) + 4
return b, nil
}
func (z *RREEncoding) Type() int32 {
return 2
}
func (z *RREEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
bytesPerPixel := int(pixelFmt.BPP / 8)
numOfSubrectangles, err := r.ReadUint32()
if err != nil {
return nil, err
}
z.numSubRects = numOfSubrectangles
//read whole-rect background color
z.backgroundColor, err = r.ReadBytes(bytesPerPixel)
if err != nil {
return nil, err
}
//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
if err != nil {
return nil, err
}
return z, nil
}
package encodings
import (
"encoding/binary"
"io"
"vncproxy/common"
)
type RREEncoding struct {
//Colors []Color
numSubRects uint32
backgroundColor []byte
subRectData []byte
}
func (z *RREEncoding) WriteTo(w io.Writer) (n int, err error) {
binary.Write(w, binary.BigEndian, z.numSubRects)
if err != nil {
return 0, err
}
w.Write(z.backgroundColor)
if err != nil {
return 0, err
}
w.Write(z.subRectData)
if err != nil {
return 0, err
}
b := len(z.backgroundColor) + len(z.subRectData) + 4
return b, nil
}
func (z *RREEncoding) Type() int32 {
return 2
}
func (z *RREEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
bytesPerPixel := int(pixelFmt.BPP / 8)
numOfSubrectangles, err := r.ReadUint32()
if err != nil {
return nil, err
}
z.numSubRects = numOfSubrectangles
//read whole-rect background color
z.backgroundColor, err = r.ReadBytes(bytesPerPixel)
if err != nil {
return nil, err
}
//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
if err != nil {
return nil, err
}
return z, nil
}

View File

@ -25,7 +25,6 @@ type TightEncoding struct {
bytes []byte
}
func (*TightEncoding) Type() int32 { return int32(common.EncTight) }
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)
r.StartByteCollection()

View File

@ -17,7 +17,7 @@ func (z *TightPngEncoding) WriteTo(w io.Writer) (n int, err error) {
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)
r.StartByteCollection()
defer func() {

View File

@ -1,38 +1,38 @@
package encodings
import (
"bytes"
"encoding/binary"
"io"
"vncproxy/common"
)
type ZLibEncoding struct {
bytes []byte
}
func (z *ZLibEncoding) Type() int32 {
return 6
}
func (z *ZLibEncoding) WriteTo(w io.Writer) (n int, err error) {
return w.Write(z.bytes)
}
func (z *ZLibEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
//conn := common.RfbReadHelper{Reader:r}
//conn := &DataSource{conn: conn.c, PixelFormat: conn.PixelFormat}
//bytesPerPixel := c.PixelFormat.BPP / 8
bytes := &bytes.Buffer{}
len, err := r.ReadUint32()
if err != nil {
return nil, err
}
binary.Write(bytes, binary.BigEndian, len)
bts, err := r.ReadBytes(int(len))
if err != nil {
return nil, err
}
StoreBytes(bytes, bts)
z.bytes = bytes.Bytes()
return z, nil
}
package encodings
import (
"bytes"
"encoding/binary"
"io"
"vncproxy/common"
)
type ZLibEncoding struct {
bytes []byte
}
func (z *ZLibEncoding) Type() int32 {
return 6
}
func (z *ZLibEncoding) WriteTo(w io.Writer) (n int, err error) {
return w.Write(z.bytes)
}
func (z *ZLibEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
//conn := common.RfbReadHelper{Reader:r}
//conn := &DataSource{conn: conn.c, PixelFormat: conn.PixelFormat}
//bytesPerPixel := c.PixelFormat.BPP / 8
bytes := &bytes.Buffer{}
len, err := r.ReadUint32()
if err != nil {
return nil, err
}
binary.Write(bytes, binary.BigEndian, len)
bts, err := r.ReadBytes(int(len))
if err != nil {
return nil, err
}
StoreBytes(bytes, bts)
z.bytes = bytes.Bytes()
return z, nil
}

View File

@ -1,38 +1,38 @@
package encodings
import (
"bytes"
"encoding/binary"
"io"
"vncproxy/common"
)
type ZRLEEncoding struct {
bytes []byte
}
func (z *ZRLEEncoding) Type() int32 {
return 16
}
func (z *ZRLEEncoding) WriteTo(w io.Writer) (n int, err error) {
return w.Write(z.bytes)
}
func (z *ZRLEEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
bytes := &bytes.Buffer{}
len, err := r.ReadUint32()
if err != nil {
return nil, err
}
binary.Write(bytes, binary.BigEndian, len)
bts, err := r.ReadBytes(int(len))
if err != nil {
return nil, err
}
StoreBytes(bytes, bts)
z.bytes = bytes.Bytes()
return z, nil
}
package encodings
import (
"bytes"
"encoding/binary"
"io"
"vncproxy/common"
)
type ZRLEEncoding struct {
bytes []byte
}
func (z *ZRLEEncoding) Type() int32 {
return 16
}
func (z *ZRLEEncoding) WriteTo(w io.Writer) (n int, err error) {
return w.Write(z.bytes)
}
func (z *ZRLEEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
bytes := &bytes.Buffer{}
len, err := r.ReadUint32()
if err != nil {
return nil, err
}
binary.Write(bytes, binary.BigEndian, len)
bts, err := r.ReadBytes(int(len))
if err != nil {
return nil, err
}
StoreBytes(bytes, bts)
z.bytes = bytes.Bytes()
return z, nil
}

View File

@ -47,7 +47,7 @@ func main() {
// if err != nil {
// logger.Errorf("error requesting fb update: %s", err)
// }
encs := []common.Encoding{
encs := []common.IEncoding{
&encodings.TightEncoding{},
//&encodings.TightPngEncoding{},
//rre := encodings.RREEncoding{},

View File

@ -21,12 +21,12 @@ type FBSPlayListener struct {
func NewFBSPlayListener(conn *server.ServerConn, r *FbsReader) *FBSPlayListener {
h := &FBSPlayListener{Conn: conn, Fbs: r}
cm := client.BellMessage(0)
cm := client.MsgBell(0)
h.serverMessageMap = make(map[uint8]common.ServerMessage)
h.serverMessageMap[0] = &client.FramebufferUpdateMessage{}
h.serverMessageMap[1] = &client.SetColorMapEntriesMessage{}
h.serverMessageMap[0] = &client.MsgFramebufferUpdate{}
h.serverMessageMap[1] = &client.MsgSetColorMapEntries{}
h.serverMessageMap[2] = &cm
h.serverMessageMap[3] = &client.ServerCutTextMessage{}
h.serverMessageMap[3] = &client.MsgServerCutText{}
return h
}
@ -45,7 +45,7 @@ func (handler *FBSPlayListener) Consume(seg *common.RfbSegment) error {
}
handler.sendFbsMessage()
}
// server.FramebufferUpdateRequest:
// server.MsgFramebufferUpdateRequest:
}
return nil
}

View File

@ -15,12 +15,13 @@ type FbsReader struct {
buffer bytes.Buffer
currentTimestamp int
pixelFormat *common.PixelFormat
encodings []common.Encoding
encodings []common.IEncoding
}
func (fbs *FbsReader) Read(p []byte) (n int, err error) {
if fbs.buffer.Len() < len(p) {
seg, err := fbs.ReadSegment()
if err != nil {
logger.Error("FBSReader.Read: error reading FBSsegment: ", 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) 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) {
@ -43,7 +44,7 @@ func NewFbsReader(fbsFile string) (*FbsReader, error) {
return nil, err
}
return &FbsReader{reader: reader,
encodings: []common.Encoding{
encodings: []common.IEncoding{
&encodings.CopyRectEncoding{},
&encodings.ZLibEncoding{},
&encodings.ZRLEEncoding{},
@ -51,6 +52,7 @@ func NewFbsReader(fbsFile string) (*FbsReader, error) {
&encodings.HextileEncoding{},
&encodings.TightEncoding{},
&encodings.TightPngEncoding{},
&encodings.EncCursorPseudo{},
&encodings.RawEncoding{},
&encodings.RREEncoding{},
},
@ -71,7 +73,7 @@ func (fbs *FbsReader) ReadStartSession() (*common.ServerInit, error) {
bytes := make([]byte, 12)
_, err := reader.Read(bytes)
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
}
@ -80,27 +82,27 @@ func (fbs *FbsReader) ReadStartSession() (*common.ServerInit, error) {
bytes = make([]byte, 12)
_, err = fbs.Read(bytes)
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
}
//push sec type and fb dimensions
binary.Read(fbs, binary.BigEndian, &SecTypeNone)
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
binary.Read(fbs, binary.BigEndian, &framebufferWidth)
if err != nil {
logger.Error("error reading rbs init - FBWidth: ", err)
logger.Error("FbsReader.ReadStartSession: error reading rbs init - FBWidth: ", err)
return nil, err
}
initMsg.FBWidth = framebufferWidth
binary.Read(fbs, binary.BigEndian, &framebufferHeight)
if err != nil {
logger.Error("error reading rbs init - FBHeight: ", err)
logger.Error("FbsReader.ReadStartSession: error reading rbs init - FBHeight: ", err)
return nil, err
}
initMsg.FBHeight = framebufferHeight
@ -109,7 +111,7 @@ func (fbs *FbsReader) ReadStartSession() (*common.ServerInit, error) {
pixelFormat := &common.PixelFormat{}
binary.Read(fbs, binary.BigEndian, pixelFormat)
if err != nil {
logger.Error("error reading rbs init - Pixelformat: ", err)
logger.Error("FbsReader.ReadStartSession: error reading rbs init - Pixelformat: ", err)
return nil, err
}
initMsg.PixelFormat = *pixelFormat
@ -122,7 +124,7 @@ func (fbs *FbsReader) ReadStartSession() (*common.ServerInit, error) {
var desknameLen uint32
binary.Read(fbs, binary.BigEndian, &desknameLen)
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
}
initMsg.NameLength = desknameLen
@ -130,7 +132,7 @@ func (fbs *FbsReader) ReadStartSession() (*common.ServerInit, error) {
bytes = make([]byte, desknameLen)
fbs.Read(bytes)
if err != nil {
logger.Error("error reading rbs init - desktopName: ", err)
logger.Error("FbsReader.ReadStartSession: error reading rbs init - desktopName: ", err)
return nil, err
}
@ -146,7 +148,7 @@ func (fbs *FbsReader) ReadSegment() (*FbsSegment, error) {
//read length
err := binary.Read(reader, binary.BigEndian, &bytesLen)
if err != nil {
logger.Error("error reading rbs file: ", err)
logger.Error("FbsReader.ReadStartSession: read len, error reading rbs file: ", err)
return nil, err
}
@ -156,7 +158,7 @@ func (fbs *FbsReader) ReadSegment() (*FbsSegment, error) {
bytes := make([]byte, paddedSize)
_, err = reader.Read(bytes)
if err != nil {
logger.Error("error reading rbs file: ", err)
logger.Error("FbsReader.ReadSegment: read bytes, error reading rbs file: ", err)
return nil, err
}
@ -167,7 +169,7 @@ func (fbs *FbsReader) ReadSegment() (*FbsSegment, error) {
var timeSinceStart uint32
binary.Read(reader, binary.BigEndian, &timeSinceStart)
if err != nil {
logger.Error("error reading rbs file: ", err)
logger.Error("FbsReader.ReadSegment: read timestamp, error reading rbs file: ", err)
return nil, err
}

View File

@ -1,7 +1,6 @@
package player
import (
"testing"
"time"
"vncproxy/common"
@ -10,9 +9,7 @@ import (
"vncproxy/server"
)
func loadFbsFile(filename string, conn *server.ServerConn) (*FbsReader, error) {
func connectFbsFile(filename string, conn *server.ServerConn) (*FbsReader, error) {
fbs, err := NewFbsReader(filename)
if err != nil {
logger.Error("failed to open fbs reader:", err)
@ -37,10 +34,23 @@ func TestServer(t *testing.T) {
//chServer := make(chan common.ClientMessage)
//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{
//SecurityHandlers: []SecurityHandler{&ServerAuthNone{}, &ServerAuthVNC{}},
SecurityHandlers: []server.SecurityHandler{&server.ServerAuthNone{}},
Encodings: []common.Encoding{&encodings.RawEncoding{}, &encodings.TightEncoding{}, &encodings.CopyRectEncoding{}},
Encodings: encs,
PixelFormat: common.NewPixelFormat(32),
ClientMessages: server.DefaultClientMessages,
DesktopName: []byte("workDesk"),
@ -51,7 +61,7 @@ func TestServer(t *testing.T) {
cfg.NewConnHandler = func(cfg *server.ServerConfig, conn *server.ServerConn) error {
//fbs, err := loadFbsFile("/Users/amitbet/Dropbox/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 {
logger.Error("TestServer.NewConnHandler: Error in loading FBS: ", err)

View File

@ -24,7 +24,7 @@ func (cc *ClientUpdater) Consume(seg *common.RfbSegment) error {
case common.SetPixelFormatMsgType:
// update pixel format
logger.Debugf("ClientUpdater.Consume: updating pixel format")
pixFmtMsg := clientMsg.(*server.SetPixelFormat)
pixFmtMsg := clientMsg.(*server.MsgSetPixelFormat)
cc.conn.PixelFormat = pixFmtMsg.PF
}

View File

@ -115,7 +115,7 @@ func (vp *VncProxy) newServerConnHandler(cfg *server.ServerConfig, sconn *server
return err
}
encs := []common.Encoding{
encs := []common.IEncoding{
&encodings.RawEncoding{},
&encodings.TightEncoding{},
&encodings.EncCursorPseudo{},
@ -128,7 +128,7 @@ func (vp *VncProxy) newServerConnHandler(cfg *server.ServerConfig, sconn *server
&encodings.HextileEncoding{},
}
cconn.Encs = encs
//err = cconn.SetEncodings(encs)
//err = cconn.MsgSetEncodings(encs)
if err != nil {
logger.Errorf("Proxy.newServerConnHandler error connecting to client: %s", err)
return err
@ -148,7 +148,7 @@ func (vp *VncProxy) StartListening() {
}
cfg := &server.ServerConfig{
SecurityHandlers: secHandlers,
Encodings: []common.Encoding{&encodings.RawEncoding{}, &encodings.TightEncoding{}, &encodings.CopyRectEncoding{}},
Encodings: []common.IEncoding{&encodings.RawEncoding{}, &encodings.TightEncoding{}, &encodings.CopyRectEncoding{}},
PixelFormat: common.NewPixelFormat(32),
ClientMessages: server.DefaultClientMessages,
DesktopName: []byte("workDesk"),

View File

@ -6,13 +6,6 @@ import (
"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.
type Key uint32
@ -21,11 +14,18 @@ type Key uint32
// Keys is a slice of Key values.
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
}
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 {
return err
}
@ -43,27 +43,27 @@ func (msg *SetPixelFormat) Write(c io.Writer) error {
return nil
}
func (*SetPixelFormat) Read(c io.Reader) (common.ClientMessage, error) {
msg := SetPixelFormat{}
func (*MsgSetPixelFormat) Read(c io.Reader) (common.ClientMessage, error) {
msg := MsgSetPixelFormat{}
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
return nil, err
}
return &msg, nil
}
// SetEncodings holds the wire format message, sans encoding-type field.
type SetEncodings struct {
// MsgSetEncodings holds the wire format message, sans encoding-type field.
type MsgSetEncodings struct {
_ [1]byte // padding
EncNum uint16 // number-of-encodings
Encodings []common.EncodingType
}
func (*SetEncodings) Type() common.ClientMessageType {
func (*MsgSetEncodings) Type() common.ClientMessageType {
return common.SetEncodingsMsgType
}
func (*SetEncodings) Read(c io.Reader) (common.ClientMessage, error) {
msg := SetEncodings{}
func (*MsgSetEncodings) Read(c io.Reader) (common.ClientMessage, error) {
msg := MsgSetEncodings{}
var pad [1]byte
if err := binary.Read(c, binary.BigEndian, &pad); err != nil {
return nil, err
@ -79,11 +79,11 @@ func (*SetEncodings) Read(c io.Reader) (common.ClientMessage, error) {
}
msg.Encodings = append(msg.Encodings, enc)
}
c.(common.ServerConn).SetEncodings(msg.Encodings)
c.(common.IServerConn).SetEncodings(msg.Encodings)
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 {
return err
}
@ -107,26 +107,26 @@ func (msg *SetEncodings) Write(c io.Writer) error {
return nil
}
// FramebufferUpdateRequest holds the wire format message.
type FramebufferUpdateRequest struct {
// MsgFramebufferUpdateRequest holds the wire format message.
type MsgFramebufferUpdateRequest struct {
Inc uint8 // incremental
X, Y uint16 // x-, y-position
Width, Height uint16 // width, height
}
func (*FramebufferUpdateRequest) Type() common.ClientMessageType {
func (*MsgFramebufferUpdateRequest) Type() common.ClientMessageType {
return common.FramebufferUpdateRequestMsgType
}
func (*FramebufferUpdateRequest) Read(c io.Reader) (common.ClientMessage, error) {
msg := FramebufferUpdateRequest{}
func (*MsgFramebufferUpdateRequest) Read(c io.Reader) (common.ClientMessage, error) {
msg := MsgFramebufferUpdateRequest{}
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
return nil, err
}
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 {
return err
}
@ -136,26 +136,26 @@ func (msg *FramebufferUpdateRequest) Write(c io.Writer) error {
return nil
}
// KeyEvent holds the wire format message.
type KeyEvent struct {
// MsgKeyEvent holds the wire format message.
type MsgKeyEvent struct {
Down uint8 // down-flag
_ [2]byte // padding
Key Key // key
}
func (*KeyEvent) Type() common.ClientMessageType {
func (*MsgKeyEvent) Type() common.ClientMessageType {
return common.KeyEventMsgType
}
func (*KeyEvent) Read(c io.Reader) (common.ClientMessage, error) {
msg := KeyEvent{}
func (*MsgKeyEvent) Read(c io.Reader) (common.ClientMessage, error) {
msg := MsgKeyEvent{}
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
return nil, err
}
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 {
return err
}
@ -166,24 +166,24 @@ func (msg *KeyEvent) Write(c io.Writer) error {
}
// PointerEventMessage holds the wire format message.
type PointerEvent struct {
type MsgPointerEvent struct {
Mask uint8 // button-mask
X, Y uint16 // x-, y-position
}
func (*PointerEvent) Type() common.ClientMessageType {
func (*MsgPointerEvent) Type() common.ClientMessageType {
return common.PointerEventMsgType
}
func (*PointerEvent) Read(c io.Reader) (common.ClientMessage, error) {
msg := PointerEvent{}
func (*MsgPointerEvent) Read(c io.Reader) (common.ClientMessage, error) {
msg := MsgPointerEvent{}
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
return nil, err
}
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 {
return err
}
@ -193,14 +193,14 @@ func (msg *PointerEvent) Write(c io.Writer) error {
return nil
}
type ClientFence struct {
type MsgClientFence struct {
}
func (*ClientFence) Type() common.ClientMessageType {
func (*MsgClientFence) Type() common.ClientMessageType {
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)
c.Read(bytes)
if _, err := c.Read(bytes); err != nil {
@ -223,23 +223,23 @@ func (cf *ClientFence) Read(c io.Reader) (common.ClientMessage, error) {
return cf, nil
}
func (msg *ClientFence) Write(c io.Writer) error {
func (msg *MsgClientFence) Write(c io.Writer) error {
panic("not implemented!")
}
// ClientCutText holds the wire format message, sans the text field.
type ClientCutText struct {
// MsgClientCutText holds the wire format message, sans the text field.
type MsgClientCutText struct {
_ [3]byte // padding
Length uint32 // length
Text []byte
}
func (*ClientCutText) Type() common.ClientMessageType {
func (*MsgClientCutText) Type() common.ClientMessageType {
return common.ClientCutTextMsgType
}
func (*ClientCutText) Read(c io.Reader) (common.ClientMessage, error) {
msg := ClientCutText{}
func (*MsgClientCutText) Read(c io.Reader) (common.ClientMessage, error) {
msg := MsgClientCutText{}
var pad [3]byte
if err := binary.Read(c, binary.BigEndian, &pad); err != nil {
return nil, err
@ -256,7 +256,7 @@ func (*ClientCutText) Read(c io.Reader) (common.ClientMessage, error) {
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 {
return err
}

View File

@ -49,7 +49,7 @@ const (
type SecurityHandler interface {
Type() SecurityType
SubType() SecuritySubType
Auth(common.ServerConn) error
Auth(common.IServerConn) error
}
// type ClientAuthNone struct{}
@ -62,7 +62,7 @@ type SecurityHandler interface {
// return SecSubTypeUnknown
// }
// func (*ClientAuthNone) Auth(conn common.ServerConn) error {
// func (*ClientAuthNone) Auth(conn common.IServerConn) error {
// return nil
// }
@ -73,7 +73,7 @@ func (*ServerAuthNone) Type() SecurityType {
return SecTypeNone
}
func (*ServerAuthNone) Auth(c common.ServerConn) error {
func (*ServerAuthNone) Auth(c common.IServerConn) error {
return nil
}
@ -95,7 +95,7 @@ func (*ServerAuthNone) SubType() SecuritySubType {
// 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 {
// return err
// }
@ -198,7 +198,7 @@ func (*ServerAuthVNC) SubType() SecuritySubType {
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)))
rand.Read(buf[:16]) // Random 16 bytes in buf
sndsz, err := c.Write(buf[:16])
@ -290,7 +290,7 @@ func fixDesKey(key string) []byte {
// return SecSubTypeUnknown
// }
// func (auth *ClientAuthVNC) Auth(c common.ServerConn) error {
// func (auth *ClientAuthVNC) Auth(c common.IServerConn) error {
// if len(auth.Password) == 0 {
// return fmt.Errorf("Security Handshake failed; no password provided for VNCAuth.")
// }

View File

@ -18,15 +18,14 @@ type ServerConn struct {
// If the pixel format uses a color map, then this is the color
// map that is used. This should not be modified directly, since
// the data comes from the server.
// Definition in §5 - Representation of Pixel Data.
colorMap *common.ColorMap
// Name associated with the desktop, sent from the server.
desktopName string
// Encodings supported by the client. This should not be modified
// directly. Instead, SetEncodings() should be used.
encodings []common.Encoding
// directly. Instead, MsgSetEncodings() should be used.
encodings []common.IEncoding
// Height of the frame buffer in pixels, sent to the client.
fbHeight uint16
@ -47,7 +46,7 @@ type ServerConn struct {
quit chan struct{}
}
// func (c *ServerConn) UnreadByte() error {
// func (c *IServerConn) UnreadByte() error {
// return c.br.UnreadByte()
// }
@ -79,7 +78,7 @@ func (c *ServerConn) Conn() io.ReadWriter {
}
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 {
encodings[enc.Type()] = enc
}
@ -129,7 +128,7 @@ func (c *ServerConn) SetPixelFormat(pf *common.PixelFormat) error {
c.pixelFormat = pf
return nil
}
func (c *ServerConn) Encodings() []common.Encoding {
func (c *ServerConn) Encodings() []common.IEncoding {
return c.encodings
}
func (c *ServerConn) Width() uint16 {
@ -169,12 +168,12 @@ func (c *ServerConn) handle() error {
default:
var messageType common.ClientMessageType
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
}
msg, ok := clientMessages[messageType]
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)
@ -184,7 +183,7 @@ func (c *ServerConn) handle() error {
case common.SetPixelFormatMsgType:
// update pixel format
logger.Debugf("ClientUpdater.Consume: updating pixel format")
pixFmtMsg := parsedMsg.(*SetPixelFormat)
pixFmtMsg := parsedMsg.(*MsgSetPixelFormat)
c.SetPixelFormat(&pixFmtMsg.PF)
if pixFmtMsg.PF.TrueColor != 0 {
c.SetColorMap(&common.ColorMap{})
@ -197,7 +196,7 @@ func (c *ServerConn) handle() error {
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
//// if parsedMsg.Type() == common.SetEncodingsMsgType{
//// c.cfg.Encodings
@ -209,7 +208,7 @@ func (c *ServerConn) handle() error {
}
err = c.Listeners.Consume(seg)
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
}
}

View File

@ -9,12 +9,12 @@ import (
)
var DefaultClientMessages = []common.ClientMessage{
&SetPixelFormat{},
&SetEncodings{},
&FramebufferUpdateRequest{},
&KeyEvent{},
&PointerEvent{},
&ClientCutText{},
&MsgSetPixelFormat{},
&MsgSetEncodings{},
&MsgFramebufferUpdateRequest{},
&MsgKeyEvent{},
&MsgPointerEvent{},
&MsgClientCutText{},
}
// FramebufferUpdate holds a FramebufferUpdate wire format message.
@ -28,7 +28,7 @@ type ServerHandler func(*ServerConfig, *ServerConn) error
type ServerConfig struct {
SecurityHandlers []SecurityHandler
Encodings []common.Encoding
Encodings []common.IEncoding
PixelFormat *common.PixelFormat
ColorMap *common.ColorMap
ClientMessages []common.ClientMessage

View File

@ -20,13 +20,13 @@ func TestServer(t *testing.T) {
cfg := &ServerConfig{
//SecurityHandlers: []SecurityHandler{&ServerAuthNone{}, &ServerAuthVNC{}},
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),
ClientMessages: DefaultClientMessages,
DesktopName: []byte("workDesk"),
Height: uint16(768),
Width: uint16(1024),
NewConnHandler: newServerConnHandler,
ClientMessages: DefaultClientMessages,
DesktopName: []byte("workDesk"),
Height: uint16(768),
Width: uint16(1024),
NewConnHandler: newServerConnHandler,
}
url := "http://localhost:8091/"
go WsServe(url, cfg)

View File

@ -15,17 +15,9 @@ type WsServer struct {
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) {
//http.Handle("/", websocket.Handler(EchoHandler))
if urlStr == "" {
urlStr = "/"
}
@ -34,17 +26,6 @@ func (wsServer *WsServer) Listen(urlStr string, handlerFunc WsHandler) {
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(
func(ws *websocket.Conn) {
path := ws.Request().URL.Path

View File

@ -1 +0,0 @@
package server

View File

@ -163,7 +163,7 @@ func (r *Recorder) HandleRfbSegment(data *common.RfbSegment) error {
switch clientMsg.Type() {
case common.SetPixelFormatMsgType:
clientMsg := data.Message.(*server.SetPixelFormat)
clientMsg := data.Message.(*server.MsgSetPixelFormat)
logger.Debugf("Recorder.HandleRfbSegment: client message %v", *clientMsg)
r.serverInitMessage.PixelFormat = clientMsg.PF
default: