mirror of
https://github.com/amitbet/vncproxy.git
synced 2025-08-23 15:48:27 +00:00
Merge d9b834fb05
into ea8f9b5109
This commit is contained in:
commit
ce9a6ba51c
48
build
Executable file
48
build
Executable file
@ -0,0 +1,48 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
sum="sha1sum"
|
||||||
|
|
||||||
|
# VERSION=`date -u +%Y%m%d`
|
||||||
|
VERSION="v1.02"
|
||||||
|
LDFLAGS="-X main.VERSION=$VERSION -s -w"
|
||||||
|
GCFLAGS=""
|
||||||
|
|
||||||
|
if ! hash sha1sum 2>/dev/null; then
|
||||||
|
if ! hash shasum 2>/dev/null; then
|
||||||
|
echo "I can't see 'sha1sum' or 'shasum'"
|
||||||
|
echo "Please install one of them!"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
sum="shasum"
|
||||||
|
fi
|
||||||
|
|
||||||
|
UPX=false
|
||||||
|
if hash upx 2>/dev/null; then
|
||||||
|
UPX=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
OSES=( linux darwin windows )
|
||||||
|
ARCHS=(amd64 386 )
|
||||||
|
for os in ${OSES[@]}; do
|
||||||
|
for arch in ${ARCHS[@]}; do
|
||||||
|
suffix=""
|
||||||
|
if [ "$os" == "windows" ]
|
||||||
|
then
|
||||||
|
suffix=".exe"
|
||||||
|
fi
|
||||||
|
|
||||||
|
env CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -ldflags "$LDFLAGS" -gcflags "$GCFLAGS" -o ./dist/${os}_${arch}/recorder${suffix} ./recorder/cmd
|
||||||
|
env CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -ldflags "$LDFLAGS" -gcflags "$GCFLAGS" -o ./dist/${os}_${arch}/player${suffix} ./player/cmd
|
||||||
|
env CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -ldflags "$LDFLAGS" -gcflags "$GCFLAGS" -o ./dist/${os}_${arch}/proxy${suffix} ./proxy/cmd
|
||||||
|
|
||||||
|
if $UPX; then upx -9 client_${os}_${arch}${suffix} server_${os}_${arch}${suffix};fi
|
||||||
|
# tar -zcf ./dist/vncproxy-${os}-${arch}-$VERSION.tar.gz ./dist/${os}_${arch}/proxy${suffix} ./dist/${os}_${arch}/player${suffix} ./dist/${os}_${arch}/recorder${suffix}
|
||||||
|
cd dist/${os}_${arch}/
|
||||||
|
zip -D -q -r ../vncproxy-${os}-${arch}-$VERSION.zip proxy${suffix} player${suffix} recorder${suffix}
|
||||||
|
cd ../..
|
||||||
|
$sum ./dist/vncproxy-${os}-${arch}-$VERSION.zip
|
||||||
|
done
|
||||||
|
done
|
@ -4,6 +4,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ClientMessageType ...
|
||||||
type ClientMessageType uint8
|
type ClientMessageType uint8
|
||||||
|
|
||||||
//go:generate stringer -type=ClientMessageType
|
//go:generate stringer -type=ClientMessageType
|
||||||
@ -29,6 +30,7 @@ type Color struct {
|
|||||||
R, G, B uint16
|
R, G, B uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ColorMap ...
|
||||||
type ColorMap [256]Color
|
type ColorMap [256]Color
|
||||||
|
|
||||||
// ClientMessage is the interface
|
// ClientMessage is the interface
|
||||||
@ -38,6 +40,7 @@ type ClientMessage interface {
|
|||||||
Write(io.Writer) error
|
Write(io.Writer) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String ...
|
||||||
func (cmt ClientMessageType) String() string {
|
func (cmt ClientMessageType) String() string {
|
||||||
switch cmt {
|
switch cmt {
|
||||||
case SetPixelFormatMsgType:
|
case SetPixelFormatMsgType:
|
||||||
|
@ -2,6 +2,7 @@ package common
|
|||||||
|
|
||||||
import "io"
|
import "io"
|
||||||
|
|
||||||
|
//IServerConn ...
|
||||||
type IServerConn interface {
|
type IServerConn interface {
|
||||||
io.ReadWriter
|
io.ReadWriter
|
||||||
//IServerConn() io.ReadWriter
|
//IServerConn() io.ReadWriter
|
||||||
@ -23,6 +24,7 @@ type IServerConn interface {
|
|||||||
// Write([]byte) (int, error)
|
// Write([]byte) (int, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//IClientConn ...
|
||||||
type IClientConn interface {
|
type IClientConn interface {
|
||||||
CurrentPixelFormat() *PixelFormat
|
CurrentPixelFormat() *PixelFormat
|
||||||
//CurrentColorMap() *ColorMap
|
//CurrentColorMap() *ColorMap
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
type IEncoding 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 ...
|
||||||
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 IEncoding implementation that contains
|
// This should return a new IEncoding implementation that contains
|
||||||
@ -143,6 +144,7 @@ func (enct EncodingType) String() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//EncodingType ...
|
||||||
const (
|
const (
|
||||||
EncRaw EncodingType = 0
|
EncRaw EncodingType = 0
|
||||||
EncCopyRect EncodingType = 1
|
EncCopyRect EncodingType = 1
|
||||||
@ -220,17 +222,18 @@ type PixelFormat struct {
|
|||||||
BlueShift uint8
|
BlueShift uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
func (format *PixelFormat) WriteTo(w io.Writer) error {
|
//WriteTo ...
|
||||||
|
func (format *PixelFormat) WriteTo(w io.Writer) (int64, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
|
||||||
// Byte 1
|
// Byte 1
|
||||||
if err := binary.Write(&buf, binary.BigEndian, format.BPP); err != nil {
|
if err := binary.Write(&buf, binary.BigEndian, format.BPP); err != nil {
|
||||||
return err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Byte 2
|
// Byte 2
|
||||||
if err := binary.Write(&buf, binary.BigEndian, format.Depth); err != nil {
|
if err := binary.Write(&buf, binary.BigEndian, format.Depth); err != nil {
|
||||||
return err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var boolByte byte
|
var boolByte byte
|
||||||
@ -242,7 +245,7 @@ func (format *PixelFormat) WriteTo(w io.Writer) error {
|
|||||||
|
|
||||||
// Byte 3 (BigEndian)
|
// Byte 3 (BigEndian)
|
||||||
if err := binary.Write(&buf, binary.BigEndian, boolByte); err != nil {
|
if err := binary.Write(&buf, binary.BigEndian, boolByte); err != nil {
|
||||||
return err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if format.TrueColor == 1 {
|
if format.TrueColor == 1 {
|
||||||
@ -253,41 +256,42 @@ func (format *PixelFormat) WriteTo(w io.Writer) error {
|
|||||||
|
|
||||||
// Byte 4 (TrueColor)
|
// Byte 4 (TrueColor)
|
||||||
if err := binary.Write(&buf, binary.BigEndian, boolByte); err != nil {
|
if err := binary.Write(&buf, binary.BigEndian, boolByte); err != nil {
|
||||||
return err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have true color enabled then we have to fill in the rest of the
|
// If we have true color enabled then we have to fill in the rest of the
|
||||||
// structure with the color values.
|
// structure with the color values.
|
||||||
if format.TrueColor == 1 {
|
if format.TrueColor == 1 {
|
||||||
if err := binary.Write(&buf, binary.BigEndian, format.RedMax); err != nil {
|
if err := binary.Write(&buf, binary.BigEndian, format.RedMax); err != nil {
|
||||||
return err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := binary.Write(&buf, binary.BigEndian, format.GreenMax); err != nil {
|
if err := binary.Write(&buf, binary.BigEndian, format.GreenMax); err != nil {
|
||||||
return err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := binary.Write(&buf, binary.BigEndian, format.BlueMax); err != nil {
|
if err := binary.Write(&buf, binary.BigEndian, format.BlueMax); err != nil {
|
||||||
return err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := binary.Write(&buf, binary.BigEndian, format.RedShift); err != nil {
|
if err := binary.Write(&buf, binary.BigEndian, format.RedShift); err != nil {
|
||||||
return err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := binary.Write(&buf, binary.BigEndian, format.GreenShift); err != nil {
|
if err := binary.Write(&buf, binary.BigEndian, format.GreenShift); err != nil {
|
||||||
return err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := binary.Write(&buf, binary.BigEndian, format.BlueShift); err != nil {
|
if err := binary.Write(&buf, binary.BigEndian, format.BlueShift); err != nil {
|
||||||
return err
|
return 0, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Write(buf.Bytes()[0:16])
|
w.Write(buf.Bytes()[0:16])
|
||||||
return nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewPixelFormat ...
|
||||||
func NewPixelFormat(bpp uint8) *PixelFormat {
|
func NewPixelFormat(bpp uint8) *PixelFormat {
|
||||||
bigEndian := 0
|
bigEndian := 0
|
||||||
// rgbMax := uint16(math.Exp2(float64(bpp))) - 1
|
// rgbMax := uint16(math.Exp2(float64(bpp))) - 1
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
|
//MultiListener ...
|
||||||
type MultiListener struct {
|
type MultiListener struct {
|
||||||
listeners []SegmentConsumer
|
listeners []SegmentConsumer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//AddListener ...
|
||||||
func (m *MultiListener) AddListener(listener SegmentConsumer) {
|
func (m *MultiListener) AddListener(listener SegmentConsumer) {
|
||||||
m.listeners = append(m.listeners, listener)
|
m.listeners = append(m.listeners, listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Consume ...
|
||||||
func (m *MultiListener) Consume(seg *RfbSegment) error {
|
func (m *MultiListener) Consume(seg *RfbSegment) error {
|
||||||
for _, li := range m.listeners {
|
for _, li := range m.listeners {
|
||||||
|
|
||||||
|
@ -8,8 +8,10 @@ import (
|
|||||||
"github.com/amitbet/vncproxy/logger"
|
"github.com/amitbet/vncproxy/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//TightMinToCompress ...
|
||||||
var TightMinToCompress = 12
|
var TightMinToCompress = 12
|
||||||
|
|
||||||
|
//SegmentType ...
|
||||||
const (
|
const (
|
||||||
SegmentBytes SegmentType = iota
|
SegmentBytes SegmentType = iota
|
||||||
SegmentMessageStart
|
SegmentMessageStart
|
||||||
@ -21,6 +23,7 @@ const (
|
|||||||
SegmentMessageEnd
|
SegmentMessageEnd
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//SegmentType ...
|
||||||
type SegmentType int
|
type SegmentType int
|
||||||
|
|
||||||
func (seg SegmentType) String() string {
|
func (seg SegmentType) String() string {
|
||||||
@ -46,6 +49,7 @@ func (seg SegmentType) String() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//RfbSegment ...
|
||||||
type RfbSegment struct {
|
type RfbSegment struct {
|
||||||
Bytes []byte
|
Bytes []byte
|
||||||
SegmentType SegmentType
|
SegmentType SegmentType
|
||||||
@ -53,49 +57,59 @@ type RfbSegment struct {
|
|||||||
Message interface{}
|
Message interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SegmentConsumer ...
|
||||||
type SegmentConsumer interface {
|
type SegmentConsumer interface {
|
||||||
Consume(*RfbSegment) error
|
Consume(*RfbSegment) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//RfbReadHelper ...
|
||||||
type RfbReadHelper struct {
|
type RfbReadHelper struct {
|
||||||
io.Reader
|
io.Reader
|
||||||
Listeners *MultiListener
|
Listeners *MultiListener
|
||||||
savedBytes *bytes.Buffer
|
savedBytes *bytes.Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//NewRfbReadHelper ...
|
||||||
func NewRfbReadHelper(r io.Reader) *RfbReadHelper {
|
func NewRfbReadHelper(r io.Reader) *RfbReadHelper {
|
||||||
return &RfbReadHelper{Reader: r, Listeners: &MultiListener{}}
|
return &RfbReadHelper{Reader: r, Listeners: &MultiListener{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//StartByteCollection ...
|
||||||
func (r *RfbReadHelper) StartByteCollection() {
|
func (r *RfbReadHelper) StartByteCollection() {
|
||||||
r.savedBytes = &bytes.Buffer{}
|
r.savedBytes = &bytes.Buffer{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//EndByteCollection ...
|
||||||
func (r *RfbReadHelper) EndByteCollection() []byte {
|
func (r *RfbReadHelper) EndByteCollection() []byte {
|
||||||
bts := r.savedBytes.Bytes()
|
bts := r.savedBytes.Bytes()
|
||||||
r.savedBytes = nil
|
r.savedBytes = nil
|
||||||
return bts
|
return bts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ReadDiscrete ...
|
||||||
func (r *RfbReadHelper) ReadDiscrete(p []byte) (int, error) {
|
func (r *RfbReadHelper) ReadDiscrete(p []byte) (int, error) {
|
||||||
return r.Read(p)
|
return r.Read(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SendRectSeparator ...
|
||||||
func (r *RfbReadHelper) SendRectSeparator(upcomingRectType int) error {
|
func (r *RfbReadHelper) SendRectSeparator(upcomingRectType int) error {
|
||||||
seg := &RfbSegment{SegmentType: SegmentRectSeparator, UpcomingObjectType: upcomingRectType}
|
seg := &RfbSegment{SegmentType: SegmentRectSeparator, UpcomingObjectType: upcomingRectType}
|
||||||
return r.Listeners.Consume(seg)
|
return r.Listeners.Consume(seg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SendMessageStart ...
|
||||||
func (r *RfbReadHelper) SendMessageStart(upcomingMessageType ServerMessageType) error {
|
func (r *RfbReadHelper) SendMessageStart(upcomingMessageType ServerMessageType) error {
|
||||||
seg := &RfbSegment{SegmentType: SegmentMessageStart, UpcomingObjectType: int(upcomingMessageType)}
|
seg := &RfbSegment{SegmentType: SegmentMessageStart, UpcomingObjectType: int(upcomingMessageType)}
|
||||||
return r.Listeners.Consume(seg)
|
return r.Listeners.Consume(seg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SendMessageEnd ...
|
||||||
func (r *RfbReadHelper) SendMessageEnd(messageType ServerMessageType) error {
|
func (r *RfbReadHelper) SendMessageEnd(messageType ServerMessageType) error {
|
||||||
seg := &RfbSegment{SegmentType: SegmentMessageEnd, UpcomingObjectType: int(messageType)}
|
seg := &RfbSegment{SegmentType: SegmentMessageEnd, UpcomingObjectType: int(messageType)}
|
||||||
return r.Listeners.Consume(seg)
|
return r.Listeners.Consume(seg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//PublishBytes ...
|
||||||
func (r *RfbReadHelper) PublishBytes(p []byte) error {
|
func (r *RfbReadHelper) PublishBytes(p []byte) error {
|
||||||
seg := &RfbSegment{Bytes: p, SegmentType: SegmentBytes}
|
seg := &RfbSegment{Bytes: p, SegmentType: SegmentBytes}
|
||||||
return r.Listeners.Consume(seg)
|
return r.Listeners.Consume(seg)
|
||||||
@ -135,6 +149,7 @@ func (r *RfbReadHelper) Read(p []byte) (n int, err error) {
|
|||||||
return readLen, err
|
return readLen, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ReadBytes ...
|
||||||
func (r *RfbReadHelper) ReadBytes(count int) ([]byte, error) {
|
func (r *RfbReadHelper) ReadBytes(count int) ([]byte, error) {
|
||||||
buff := make([]byte, count)
|
buff := make([]byte, count)
|
||||||
|
|
||||||
@ -157,6 +172,7 @@ func (r *RfbReadHelper) ReadBytes(count int) ([]byte, error) {
|
|||||||
return buff, nil
|
return buff, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ReadUint8 ...
|
||||||
func (r *RfbReadHelper) ReadUint8() (uint8, error) {
|
func (r *RfbReadHelper) ReadUint8() (uint8, error) {
|
||||||
var myUint uint8
|
var myUint uint8
|
||||||
if err := binary.Read(r, binary.BigEndian, &myUint); err != nil {
|
if err := binary.Read(r, binary.BigEndian, &myUint); err != nil {
|
||||||
@ -165,6 +181,8 @@ func (r *RfbReadHelper) ReadUint8() (uint8, error) {
|
|||||||
|
|
||||||
return myUint, nil
|
return myUint, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ReadUint16 ...
|
||||||
func (r *RfbReadHelper) ReadUint16() (uint16, error) {
|
func (r *RfbReadHelper) ReadUint16() (uint16, error) {
|
||||||
var myUint uint16
|
var myUint uint16
|
||||||
if err := binary.Read(r, binary.BigEndian, &myUint); err != nil {
|
if err := binary.Read(r, binary.BigEndian, &myUint); err != nil {
|
||||||
@ -173,6 +191,8 @@ func (r *RfbReadHelper) ReadUint16() (uint16, error) {
|
|||||||
|
|
||||||
return myUint, nil
|
return myUint, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ReadUint32 ...
|
||||||
func (r *RfbReadHelper) ReadUint32() (uint32, error) {
|
func (r *RfbReadHelper) ReadUint32() (uint32, error) {
|
||||||
var myUint uint32
|
var myUint uint32
|
||||||
if err := binary.Read(r, binary.BigEndian, &myUint); err != nil {
|
if err := binary.Read(r, binary.BigEndian, &myUint); err != nil {
|
||||||
@ -181,6 +201,8 @@ func (r *RfbReadHelper) ReadUint32() (uint32, error) {
|
|||||||
|
|
||||||
return myUint, nil
|
return myUint, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ReadCompactLen ...
|
||||||
func (r *RfbReadHelper) ReadCompactLen() (int, error) {
|
func (r *RfbReadHelper) ReadCompactLen() (int, error) {
|
||||||
var err error
|
var err error
|
||||||
part, err := r.ReadUint8()
|
part, err := r.ReadUint8()
|
||||||
@ -204,6 +226,7 @@ func (r *RfbReadHelper) ReadCompactLen() (int, error) {
|
|||||||
return int(len), err
|
return int(len), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ReadTightData ...
|
||||||
func (r *RfbReadHelper) ReadTightData(dataSize int) ([]byte, error) {
|
func (r *RfbReadHelper) ReadTightData(dataSize int) ([]byte, error) {
|
||||||
if int(dataSize) < TightMinToCompress {
|
if int(dataSize) < TightMinToCompress {
|
||||||
return r.ReadBytes(int(dataSize))
|
return r.ReadBytes(int(dataSize))
|
||||||
|
@ -4,14 +4,18 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//ServerMessage ...
|
||||||
type ServerMessage interface {
|
type ServerMessage interface {
|
||||||
Type() uint8
|
Type() uint8
|
||||||
String() string
|
String() string
|
||||||
CopyTo(r io.Reader, w io.Writer, c IClientConn) error
|
CopyTo(r io.Reader, w io.Writer, c IClientConn) error
|
||||||
Read(IClientConn, *RfbReadHelper) (ServerMessage, error)
|
Read(IClientConn, *RfbReadHelper) (ServerMessage, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ServerMessageType ...
|
||||||
type ServerMessageType int8
|
type ServerMessageType int8
|
||||||
|
|
||||||
|
//ServerMessageType ...
|
||||||
const (
|
const (
|
||||||
FramebufferUpdate ServerMessageType = iota
|
FramebufferUpdate ServerMessageType = iota
|
||||||
SetColourMapEntries
|
SetColourMapEntries
|
||||||
@ -34,6 +38,7 @@ func (typ ServerMessageType) String() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ServerInit ...
|
||||||
type ServerInit struct {
|
type ServerInit struct {
|
||||||
FBWidth, FBHeight uint16
|
FBWidth, FBHeight uint16
|
||||||
PixelFormat PixelFormat
|
PixelFormat PixelFormat
|
||||||
|
@ -6,15 +6,19 @@ import (
|
|||||||
"github.com/amitbet/vncproxy/common"
|
"github.com/amitbet/vncproxy/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//CopyRectEncoding ..
|
||||||
type CopyRectEncoding struct {
|
type CopyRectEncoding struct {
|
||||||
//Colors []Color
|
//Colors []Color
|
||||||
copyRectSrcX uint16
|
copyRectSrcX uint16
|
||||||
copyRectSrcY uint16
|
copyRectSrcY uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Type ..
|
||||||
func (z *CopyRectEncoding) Type() int32 {
|
func (z *CopyRectEncoding) Type() int32 {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//WriteTo ..
|
||||||
func (z *CopyRectEncoding) WriteTo(w io.Writer) (n int, err error) {
|
func (z *CopyRectEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||||
binary.Write(w, binary.BigEndian, z.copyRectSrcX)
|
binary.Write(w, binary.BigEndian, z.copyRectSrcX)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -27,6 +31,7 @@ func (z *CopyRectEncoding) WriteTo(w io.Writer) (n int, err error) {
|
|||||||
return 4, nil
|
return 4, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Read ...
|
||||||
func (z *CopyRectEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, 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()
|
||||||
|
@ -6,16 +6,19 @@ import (
|
|||||||
"github.com/amitbet/vncproxy/common"
|
"github.com/amitbet/vncproxy/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//CoRREEncoding ..
|
||||||
type CoRREEncoding struct {
|
type CoRREEncoding struct {
|
||||||
numSubRects uint32
|
numSubRects uint32
|
||||||
backgroundColor []byte
|
backgroundColor []byte
|
||||||
subRectData []byte
|
subRectData []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Type ...
|
||||||
func (z *CoRREEncoding) Type() int32 {
|
func (z *CoRREEncoding) Type() int32 {
|
||||||
return 4
|
return 4
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//WriteTo ...
|
||||||
func (z *CoRREEncoding) WriteTo(w io.Writer) (n int, err error) {
|
func (z *CoRREEncoding) 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 {
|
||||||
|
@ -6,15 +6,21 @@ import (
|
|||||||
"github.com/amitbet/vncproxy/common"
|
"github.com/amitbet/vncproxy/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//EncCursorPseudo ...
|
||||||
type EncCursorPseudo struct {
|
type EncCursorPseudo struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Type ...
|
||||||
func (pe *EncCursorPseudo) Type() int32 {
|
func (pe *EncCursorPseudo) Type() int32 {
|
||||||
return int32(common.EncCursorPseudo)
|
return int32(common.EncCursorPseudo)
|
||||||
}
|
}
|
||||||
func (z *EncCursorPseudo) WriteTo(w io.Writer) (n int, err error) {
|
|
||||||
|
//WriteTo ...
|
||||||
|
func (pe *EncCursorPseudo) WriteTo(w io.Writer) (n int, err error) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Read ...
|
||||||
func (pe *EncCursorPseudo) Read(pf *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, 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
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/amitbet/vncproxy/logger"
|
"github.com/amitbet/vncproxy/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//Hextile ...
|
||||||
const (
|
const (
|
||||||
HextileRaw = 1
|
HextileRaw = 1
|
||||||
HextileBackgroundSpecified = 2
|
HextileBackgroundSpecified = 2
|
||||||
@ -14,17 +15,23 @@ const (
|
|||||||
HextileSubrectsColoured = 16
|
HextileSubrectsColoured = 16
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//HextileEncoding ...
|
||||||
type HextileEncoding struct {
|
type HextileEncoding struct {
|
||||||
//Colors []Color
|
//Colors []Color
|
||||||
bytes []byte
|
bytes []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Type ...
|
||||||
func (z *HextileEncoding) Type() int32 {
|
func (z *HextileEncoding) Type() int32 {
|
||||||
return 5
|
return 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//WriteTo ...
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Read ...
|
||||||
func (z *HextileEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, 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
|
||||||
|
|
||||||
|
@ -6,17 +6,23 @@ import (
|
|||||||
"github.com/amitbet/vncproxy/logger"
|
"github.com/amitbet/vncproxy/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//EncLedStatePseudo ...
|
||||||
type EncLedStatePseudo struct {
|
type EncLedStatePseudo struct {
|
||||||
LedState uint8
|
LedState uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Type ...
|
||||||
func (pe *EncLedStatePseudo) Type() int32 {
|
func (pe *EncLedStatePseudo) Type() int32 {
|
||||||
return int32(common.EncLedStatePseudo)
|
return int32(common.EncLedStatePseudo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//WriteTo ...
|
||||||
func (pe *EncLedStatePseudo) WriteTo(w io.Writer) (n int, err error) {
|
func (pe *EncLedStatePseudo) WriteTo(w io.Writer) (n int, err error) {
|
||||||
w.Write([]byte{pe.LedState})
|
w.Write([]byte{pe.LedState})
|
||||||
return 1, nil
|
return 1, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Read ...
|
||||||
func (pe *EncLedStatePseudo) Read(pf *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
func (pe *EncLedStatePseudo) 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
|
||||||
|
@ -5,16 +5,22 @@ import (
|
|||||||
"github.com/amitbet/vncproxy/common"
|
"github.com/amitbet/vncproxy/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//PseudoEncoding ...
|
||||||
type PseudoEncoding struct {
|
type PseudoEncoding struct {
|
||||||
Typ int32
|
Typ int32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Type ...
|
||||||
func (pe *PseudoEncoding) Type() int32 {
|
func (pe *PseudoEncoding) Type() int32 {
|
||||||
return pe.Typ
|
return pe.Typ
|
||||||
}
|
}
|
||||||
func (z *PseudoEncoding) WriteTo(w io.Writer) (n int, err error) {
|
|
||||||
|
//WriteTo ...
|
||||||
|
func (pe *PseudoEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Read ...
|
||||||
func (pe *PseudoEncoding) Read(*common.PixelFormat, *common.Rectangle, *common.RfbReadHelper) (common.IEncoding, error) {
|
func (pe *PseudoEncoding) Read(*common.PixelFormat, *common.Rectangle, *common.RfbReadHelper) (common.IEncoding, error) {
|
||||||
return pe, nil
|
return pe, nil
|
||||||
}
|
}
|
||||||
|
@ -11,13 +11,18 @@ type RawEncoding struct {
|
|||||||
bytes []byte
|
bytes []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*RawEncoding) Type() int32 {
|
//Type ...
|
||||||
|
func (z *RawEncoding) Type() int32 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//WriteTo ...
|
||||||
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.IEncoding, error) {
|
|
||||||
|
//Read ...
|
||||||
|
func (z *RawEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||||
|
|
||||||
bytesPerPixel := int(pixelFmt.BPP / 8)
|
bytesPerPixel := int(pixelFmt.BPP / 8)
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/amitbet/vncproxy/common"
|
"github.com/amitbet/vncproxy/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//RREEncoding ...
|
||||||
type RREEncoding struct {
|
type RREEncoding struct {
|
||||||
//Colors []Color
|
//Colors []Color
|
||||||
numSubRects uint32
|
numSubRects uint32
|
||||||
@ -13,6 +14,7 @@ type RREEncoding struct {
|
|||||||
subRectData []byte
|
subRectData []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//WriteTo ...
|
||||||
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 {
|
||||||
@ -33,9 +35,12 @@ func (z *RREEncoding) WriteTo(w io.Writer) (n int, err error) {
|
|||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Type ...
|
||||||
func (z *RREEncoding) Type() int32 {
|
func (z *RREEncoding) Type() int32 {
|
||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Read ...
|
||||||
func (z *RREEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, 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()
|
||||||
|
@ -8,8 +8,10 @@ import (
|
|||||||
"github.com/amitbet/vncproxy/logger"
|
"github.com/amitbet/vncproxy/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//TightMinToCompress ....
|
||||||
var TightMinToCompress int = 12
|
var TightMinToCompress int = 12
|
||||||
|
|
||||||
|
//Tight ...
|
||||||
const (
|
const (
|
||||||
TightExplicitFilter = 0x04
|
TightExplicitFilter = 0x04
|
||||||
TightFill = 0x08
|
TightFill = 0x08
|
||||||
@ -21,11 +23,13 @@ const (
|
|||||||
TightFilterGradient = 0x02
|
TightFilterGradient = 0x02
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//TightEncoding ...
|
||||||
type TightEncoding struct {
|
type TightEncoding struct {
|
||||||
bytes []byte
|
bytes []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*TightEncoding) Type() int32 { return int32(common.EncTight) }
|
//Type ...
|
||||||
|
func (z *TightEncoding) Type() int32 { return int32(common.EncTight) }
|
||||||
|
|
||||||
func calcTightBytePerPixel(pf *common.PixelFormat) int {
|
func calcTightBytePerPixel(pf *common.PixelFormat) int {
|
||||||
bytesPerPixel := int(pf.BPP / 8)
|
bytesPerPixel := int(pf.BPP / 8)
|
||||||
@ -39,10 +43,12 @@ func calcTightBytePerPixel(pf *common.PixelFormat) int {
|
|||||||
return bytesPerPixelTight
|
return bytesPerPixelTight
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//WriteTo ...
|
||||||
func (z *TightEncoding) WriteTo(w io.Writer) (n int, err error) {
|
func (z *TightEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||||
return w.Write(z.bytes)
|
return w.Write(z.bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//StoreBytes ...
|
||||||
func StoreBytes(bytes *bytes.Buffer, data []byte) {
|
func StoreBytes(bytes *bytes.Buffer, data []byte) {
|
||||||
_, err := bytes.Write(data)
|
_, err := bytes.Write(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -50,12 +56,12 @@ func StoreBytes(bytes *bytes.Buffer, data []byte) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TightEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
func (z *TightEncoding) 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() {
|
||||||
t.bytes = r.EndByteCollection()
|
z.bytes = r.EndByteCollection()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
compctl, err := r.ReadUint8()
|
compctl, err := r.ReadUint8()
|
||||||
@ -80,7 +86,7 @@ func (t *TightEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangl
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return t, nil
|
return z, nil
|
||||||
case TightJpeg:
|
case TightJpeg:
|
||||||
if pixelFmt.BPP == 8 {
|
if pixelFmt.BPP == 8 {
|
||||||
return nil, errors.New("Tight encoding: JPEG is not supported in 8 bpp mode")
|
return nil, errors.New("Tight encoding: JPEG is not supported in 8 bpp mode")
|
||||||
@ -97,7 +103,7 @@ func (t *TightEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangl
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return t, nil
|
return z, nil
|
||||||
default:
|
default:
|
||||||
|
|
||||||
if compType > TightJpeg {
|
if compType > TightJpeg {
|
||||||
@ -106,18 +112,18 @@ func (t *TightEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangl
|
|||||||
|
|
||||||
handleTightFilters(compctl, pixelFmt, rect, r)
|
handleTightFilters(compctl, pixelFmt, rect, r)
|
||||||
|
|
||||||
return t, nil
|
return z, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleTightFilters(subencoding uint8, pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) {
|
func handleTightFilters(subencoding uint8, pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) {
|
||||||
|
|
||||||
var FILTER_ID_MASK uint8 = 0x40
|
var FilterIDMask uint8 = 0x40
|
||||||
|
|
||||||
var filterid uint8
|
var filterid uint8
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if (subencoding & FILTER_ID_MASK) > 0 { // filter byte presence
|
if (subencoding & FilterIDMask) > 0 { // filter byte presence
|
||||||
filterid, err = r.ReadUint8()
|
filterid, err = r.ReadUint8()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -7,21 +7,25 @@ import (
|
|||||||
"github.com/amitbet/vncproxy/logger"
|
"github.com/amitbet/vncproxy/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//TightPngEncoding ...
|
||||||
type TightPngEncoding struct {
|
type TightPngEncoding struct {
|
||||||
bytes []byte
|
bytes []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//WriteTo ...
|
||||||
func (z *TightPngEncoding) WriteTo(w io.Writer) (n int, err error) {
|
func (z *TightPngEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||||
return w.Write(z.bytes)
|
return w.Write(z.bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*TightPngEncoding) Type() int32 { return int32(common.EncTightPng) }
|
//Type ...
|
||||||
|
func (z *TightPngEncoding) Type() int32 { return int32(common.EncTightPng) }
|
||||||
|
|
||||||
func (t *TightPngEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
//Read ...
|
||||||
|
func (z *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() {
|
||||||
t.bytes = r.EndByteCollection()
|
z.bytes = r.EndByteCollection()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
//var subencoding uint8
|
//var subencoding uint8
|
||||||
@ -42,7 +46,7 @@ func (t *TightPngEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Recta
|
|||||||
_, err = r.ReadBytes(len)
|
_, err = r.ReadBytes(len)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return t, err
|
return z, err
|
||||||
}
|
}
|
||||||
|
|
||||||
case TightFill:
|
case TightFill:
|
||||||
@ -50,5 +54,5 @@ func (t *TightPngEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Recta
|
|||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown tight compression %d", compType)
|
return nil, fmt.Errorf("unknown tight compression %d", compType)
|
||||||
}
|
}
|
||||||
return t, nil
|
return z, nil
|
||||||
}
|
}
|
||||||
|
@ -7,16 +7,22 @@ import (
|
|||||||
"github.com/amitbet/vncproxy/common"
|
"github.com/amitbet/vncproxy/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ZLibEncoding ..
|
||||||
type ZLibEncoding struct {
|
type ZLibEncoding struct {
|
||||||
bytes []byte
|
bytes []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Type ..
|
||||||
func (z *ZLibEncoding) Type() int32 {
|
func (z *ZLibEncoding) Type() int32 {
|
||||||
return 6
|
return 6
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WriteTo ...
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Read ...
|
||||||
func (z *ZLibEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, 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}
|
||||||
|
@ -7,18 +7,22 @@ import (
|
|||||||
"github.com/amitbet/vncproxy/common"
|
"github.com/amitbet/vncproxy/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//ZRLEEncoding ...
|
||||||
type ZRLEEncoding struct {
|
type ZRLEEncoding struct {
|
||||||
bytes []byte
|
bytes []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Type ...
|
||||||
func (z *ZRLEEncoding) Type() int32 {
|
func (z *ZRLEEncoding) Type() int32 {
|
||||||
return 16
|
return 16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//WriteTo ...
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Read ...
|
||||||
func (z *ZRLEEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
func (z *ZRLEEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||||
|
|
||||||
bytes := &bytes.Buffer{}
|
bytes := &bytes.Buffer{}
|
||||||
|
@ -2,6 +2,7 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"github.com/amitbet/vncproxy/common"
|
"github.com/amitbet/vncproxy/common"
|
||||||
)
|
)
|
||||||
@ -21,10 +22,12 @@ type MsgSetPixelFormat struct {
|
|||||||
_ [3]byte // padding after pixel format
|
_ [3]byte // padding after pixel format
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*MsgSetPixelFormat) Type() common.ClientMessageType {
|
//Type ...
|
||||||
|
func (msg *MsgSetPixelFormat) Type() common.ClientMessageType {
|
||||||
return common.SetPixelFormatMsgType
|
return common.SetPixelFormatMsgType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Write ...
|
||||||
func (msg *MsgSetPixelFormat) 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
|
||||||
@ -58,6 +61,7 @@ type MsgSetEncodings struct {
|
|||||||
Encodings []common.EncodingType
|
Encodings []common.EncodingType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Type ...
|
||||||
func (*MsgSetEncodings) Type() common.ClientMessageType {
|
func (*MsgSetEncodings) Type() common.ClientMessageType {
|
||||||
return common.SetEncodingsMsgType
|
return common.SetEncodingsMsgType
|
||||||
}
|
}
|
||||||
@ -114,10 +118,12 @@ type MsgFramebufferUpdateRequest struct {
|
|||||||
Width, Height uint16 // width, height
|
Width, Height uint16 // width, height
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Type ...
|
||||||
func (*MsgFramebufferUpdateRequest) Type() common.ClientMessageType {
|
func (*MsgFramebufferUpdateRequest) Type() common.ClientMessageType {
|
||||||
return common.FramebufferUpdateRequestMsgType
|
return common.FramebufferUpdateRequestMsgType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Read ...
|
||||||
func (*MsgFramebufferUpdateRequest) Read(c io.Reader) (common.ClientMessage, error) {
|
func (*MsgFramebufferUpdateRequest) Read(c io.Reader) (common.ClientMessage, error) {
|
||||||
msg := MsgFramebufferUpdateRequest{}
|
msg := MsgFramebufferUpdateRequest{}
|
||||||
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
|
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
|
||||||
@ -126,6 +132,7 @@ func (*MsgFramebufferUpdateRequest) Read(c io.Reader) (common.ClientMessage, err
|
|||||||
return &msg, nil
|
return &msg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Write ...
|
||||||
func (msg *MsgFramebufferUpdateRequest) 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
|
||||||
@ -143,6 +150,7 @@ type MsgKeyEvent struct {
|
|||||||
Key Key // key
|
Key Key // key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Type ...
|
||||||
func (*MsgKeyEvent) Type() common.ClientMessageType {
|
func (*MsgKeyEvent) Type() common.ClientMessageType {
|
||||||
return common.KeyEventMsgType
|
return common.KeyEventMsgType
|
||||||
}
|
}
|
||||||
@ -165,7 +173,7 @@ func (msg *MsgKeyEvent) Write(c io.Writer) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MsgKeyEvent holds the wire format message.
|
// MsgQEMUExtKeyEvent holds the wire format message.
|
||||||
type MsgQEMUExtKeyEvent struct {
|
type MsgQEMUExtKeyEvent struct {
|
||||||
SubmessageType uint8 // submessage type
|
SubmessageType uint8 // submessage type
|
||||||
DownFlag uint16 // down-flag
|
DownFlag uint16 // down-flag
|
||||||
@ -173,10 +181,12 @@ type MsgQEMUExtKeyEvent struct {
|
|||||||
KeyCode uint32 // scan code
|
KeyCode uint32 // scan code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Type ...
|
||||||
func (*MsgQEMUExtKeyEvent) Type() common.ClientMessageType {
|
func (*MsgQEMUExtKeyEvent) Type() common.ClientMessageType {
|
||||||
return common.QEMUExtendedKeyEventMsgType
|
return common.QEMUExtendedKeyEventMsgType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Read ...
|
||||||
func (*MsgQEMUExtKeyEvent) Read(c io.Reader) (common.ClientMessage, error) {
|
func (*MsgQEMUExtKeyEvent) Read(c io.Reader) (common.ClientMessage, error) {
|
||||||
msg := MsgKeyEvent{}
|
msg := MsgKeyEvent{}
|
||||||
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
|
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
|
||||||
@ -185,6 +195,7 @@ func (*MsgQEMUExtKeyEvent) Read(c io.Reader) (common.ClientMessage, error) {
|
|||||||
return &msg, nil
|
return &msg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Write ...
|
||||||
func (msg *MsgQEMUExtKeyEvent) Write(c io.Writer) error {
|
func (msg *MsgQEMUExtKeyEvent) 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
|
||||||
@ -195,16 +206,18 @@ func (msg *MsgQEMUExtKeyEvent) Write(c io.Writer) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PointerEventMessage holds the wire format message.
|
// MsgPointerEvent holds the wire format message.
|
||||||
type MsgPointerEvent struct {
|
type MsgPointerEvent struct {
|
||||||
Mask uint8 // button-mask
|
Mask uint8 // button-mask
|
||||||
X, Y uint16 // x-, y-position
|
X, Y uint16 // x-, y-position
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Type ...
|
||||||
func (*MsgPointerEvent) Type() common.ClientMessageType {
|
func (*MsgPointerEvent) Type() common.ClientMessageType {
|
||||||
return common.PointerEventMsgType
|
return common.PointerEventMsgType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Read ...
|
||||||
func (*MsgPointerEvent) Read(c io.Reader) (common.ClientMessage, error) {
|
func (*MsgPointerEvent) Read(c io.Reader) (common.ClientMessage, error) {
|
||||||
msg := MsgPointerEvent{}
|
msg := MsgPointerEvent{}
|
||||||
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
|
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
|
||||||
@ -223,13 +236,16 @@ func (msg *MsgPointerEvent) Write(c io.Writer) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//MsgClientFence ...
|
||||||
type MsgClientFence struct {
|
type MsgClientFence struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Type ...
|
||||||
func (*MsgClientFence) Type() common.ClientMessageType {
|
func (*MsgClientFence) Type() common.ClientMessageType {
|
||||||
return common.ClientFenceMsgType
|
return common.ClientFenceMsgType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Read ...
|
||||||
func (cf *MsgClientFence) 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)
|
||||||
@ -253,8 +269,9 @@ func (cf *MsgClientFence) Read(c io.Reader) (common.ClientMessage, error) {
|
|||||||
return cf, nil
|
return cf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *MsgClientFence) Write(c io.Writer) error {
|
//Write ...
|
||||||
panic("not implemented!")
|
func (cf *MsgClientFence) Write(c io.Writer) error {
|
||||||
|
return fmt.Errorf("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
// MsgClientCutText holds the wire format message, sans the text field.
|
// MsgClientCutText holds the wire format message, sans the text field.
|
||||||
@ -264,10 +281,12 @@ type MsgClientCutText struct {
|
|||||||
Text []byte
|
Text []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Type ...
|
||||||
func (*MsgClientCutText) Type() common.ClientMessageType {
|
func (*MsgClientCutText) Type() common.ClientMessageType {
|
||||||
return common.ClientCutTextMsgType
|
return common.ClientCutTextMsgType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Read ...
|
||||||
func (*MsgClientCutText) Read(c io.Reader) (common.ClientMessage, error) {
|
func (*MsgClientCutText) Read(c io.Reader) (common.ClientMessage, error) {
|
||||||
msg := MsgClientCutText{}
|
msg := MsgClientCutText{}
|
||||||
var pad [3]byte
|
var pad [3]byte
|
||||||
|
@ -9,14 +9,17 @@ import (
|
|||||||
"github.com/amitbet/vncproxy/logger"
|
"github.com/amitbet/vncproxy/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//ProtoVersionLength ...
|
||||||
const ProtoVersionLength = 12
|
const ProtoVersionLength = 12
|
||||||
|
|
||||||
|
//ProtoVersion ...
|
||||||
const (
|
const (
|
||||||
ProtoVersionUnknown = ""
|
ProtoVersionUnknown = ""
|
||||||
ProtoVersion33 = "RFB 003.003\n"
|
ProtoVersion33 = "RFB 003.003\n"
|
||||||
ProtoVersion38 = "RFB 003.008\n"
|
ProtoVersion38 = "RFB 003.008\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//ParseProtoVersion ...
|
||||||
func ParseProtoVersion(pv []byte) (uint, uint, error) {
|
func ParseProtoVersion(pv []byte) (uint, uint, error) {
|
||||||
var major, minor uint
|
var major, minor uint
|
||||||
|
|
||||||
@ -26,7 +29,7 @@ func ParseProtoVersion(pv []byte) (uint, uint, error) {
|
|||||||
|
|
||||||
l, err := fmt.Sscanf(string(pv), "RFB %d.%d\n", &major, &minor)
|
l, err := fmt.Sscanf(string(pv), "RFB %d.%d\n", &major, &minor)
|
||||||
if l != 2 {
|
if l != 2 {
|
||||||
return 0, 0, fmt.Errorf("error parsing ProtocolVersion.")
|
return 0, 0, fmt.Errorf("error parsing ProtocolVersion")
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
@ -35,6 +38,7 @@ func ParseProtoVersion(pv []byte) (uint, uint, error) {
|
|||||||
return major, minor, nil
|
return major, minor, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ServerVersionHandler ...
|
||||||
func ServerVersionHandler(cfg *ServerConfig, c *ServerConn) error {
|
func ServerVersionHandler(cfg *ServerConfig, c *ServerConn) error {
|
||||||
var version [ProtoVersionLength]byte
|
var version [ProtoVersionLength]byte
|
||||||
if err := binary.Write(c, binary.BigEndian, []byte(ProtoVersion38)); err != nil {
|
if err := binary.Write(c, binary.BigEndian, []byte(ProtoVersion38)); err != nil {
|
||||||
@ -143,7 +147,7 @@ func ServerServerInitHandler(cfg *ServerConfig, c *ServerConn) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := srvInit.PixelFormat.WriteTo(c); err != nil {
|
if _, err := srvInit.PixelFormat.WriteTo(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := binary.Write(c, binary.BigEndian, srvInit.NameLength); err != nil {
|
if err := binary.Write(c, binary.BigEndian, srvInit.NameLength); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user