mirror of
https://github.com/amitbet/vncproxy.git
synced 2025-08-22 15:25:43 +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"
|
||||
)
|
||||
|
||||
// ClientMessageType ...
|
||||
type ClientMessageType uint8
|
||||
|
||||
//go:generate stringer -type=ClientMessageType
|
||||
@ -29,6 +30,7 @@ type Color struct {
|
||||
R, G, B uint16
|
||||
}
|
||||
|
||||
// ColorMap ...
|
||||
type ColorMap [256]Color
|
||||
|
||||
// ClientMessage is the interface
|
||||
@ -38,6 +40,7 @@ type ClientMessage interface {
|
||||
Write(io.Writer) error
|
||||
}
|
||||
|
||||
// String ...
|
||||
func (cmt ClientMessageType) String() string {
|
||||
switch cmt {
|
||||
case SetPixelFormatMsgType:
|
||||
|
@ -2,6 +2,7 @@ package common
|
||||
|
||||
import "io"
|
||||
|
||||
//IServerConn ...
|
||||
type IServerConn interface {
|
||||
io.ReadWriter
|
||||
//IServerConn() io.ReadWriter
|
||||
@ -23,6 +24,7 @@ type IServerConn interface {
|
||||
// Write([]byte) (int, error)
|
||||
}
|
||||
|
||||
//IClientConn ...
|
||||
type IClientConn interface {
|
||||
CurrentPixelFormat() *PixelFormat
|
||||
//CurrentColorMap() *ColorMap
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
type IEncoding interface {
|
||||
// The number that uniquely identifies this encoding type.
|
||||
Type() int32
|
||||
//WriteTo ...
|
||||
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 IEncoding implementation that contains
|
||||
@ -143,6 +144,7 @@ func (enct EncodingType) String() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
//EncodingType ...
|
||||
const (
|
||||
EncRaw EncodingType = 0
|
||||
EncCopyRect EncodingType = 1
|
||||
@ -220,17 +222,18 @@ type PixelFormat struct {
|
||||
BlueShift uint8
|
||||
}
|
||||
|
||||
func (format *PixelFormat) WriteTo(w io.Writer) error {
|
||||
//WriteTo ...
|
||||
func (format *PixelFormat) WriteTo(w io.Writer) (int64, error) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
// Byte 1
|
||||
if err := binary.Write(&buf, binary.BigEndian, format.BPP); err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// Byte 2
|
||||
if err := binary.Write(&buf, binary.BigEndian, format.Depth); err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var boolByte byte
|
||||
@ -242,7 +245,7 @@ func (format *PixelFormat) WriteTo(w io.Writer) error {
|
||||
|
||||
// Byte 3 (BigEndian)
|
||||
if err := binary.Write(&buf, binary.BigEndian, boolByte); err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if format.TrueColor == 1 {
|
||||
@ -253,41 +256,42 @@ func (format *PixelFormat) WriteTo(w io.Writer) error {
|
||||
|
||||
// Byte 4 (TrueColor)
|
||||
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
|
||||
// structure with the color values.
|
||||
if format.TrueColor == 1 {
|
||||
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 {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
|
||||
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 {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
|
||||
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 {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
w.Write(buf.Bytes()[0:16])
|
||||
return nil
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// NewPixelFormat ...
|
||||
func NewPixelFormat(bpp uint8) *PixelFormat {
|
||||
bigEndian := 0
|
||||
// rgbMax := uint16(math.Exp2(float64(bpp))) - 1
|
||||
|
@ -1,13 +1,16 @@
|
||||
package common
|
||||
|
||||
//MultiListener ...
|
||||
type MultiListener struct {
|
||||
listeners []SegmentConsumer
|
||||
}
|
||||
|
||||
//AddListener ...
|
||||
func (m *MultiListener) AddListener(listener SegmentConsumer) {
|
||||
m.listeners = append(m.listeners, listener)
|
||||
}
|
||||
|
||||
//Consume ...
|
||||
func (m *MultiListener) Consume(seg *RfbSegment) error {
|
||||
for _, li := range m.listeners {
|
||||
|
||||
|
@ -8,8 +8,10 @@ import (
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
)
|
||||
|
||||
//TightMinToCompress ...
|
||||
var TightMinToCompress = 12
|
||||
|
||||
//SegmentType ...
|
||||
const (
|
||||
SegmentBytes SegmentType = iota
|
||||
SegmentMessageStart
|
||||
@ -21,6 +23,7 @@ const (
|
||||
SegmentMessageEnd
|
||||
)
|
||||
|
||||
//SegmentType ...
|
||||
type SegmentType int
|
||||
|
||||
func (seg SegmentType) String() string {
|
||||
@ -46,6 +49,7 @@ func (seg SegmentType) String() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
//RfbSegment ...
|
||||
type RfbSegment struct {
|
||||
Bytes []byte
|
||||
SegmentType SegmentType
|
||||
@ -53,49 +57,59 @@ type RfbSegment struct {
|
||||
Message interface{}
|
||||
}
|
||||
|
||||
//SegmentConsumer ...
|
||||
type SegmentConsumer interface {
|
||||
Consume(*RfbSegment) error
|
||||
}
|
||||
|
||||
//RfbReadHelper ...
|
||||
type RfbReadHelper struct {
|
||||
io.Reader
|
||||
Listeners *MultiListener
|
||||
savedBytes *bytes.Buffer
|
||||
}
|
||||
|
||||
//NewRfbReadHelper ...
|
||||
func NewRfbReadHelper(r io.Reader) *RfbReadHelper {
|
||||
return &RfbReadHelper{Reader: r, Listeners: &MultiListener{}}
|
||||
}
|
||||
|
||||
//StartByteCollection ...
|
||||
func (r *RfbReadHelper) StartByteCollection() {
|
||||
r.savedBytes = &bytes.Buffer{}
|
||||
}
|
||||
|
||||
//EndByteCollection ...
|
||||
func (r *RfbReadHelper) EndByteCollection() []byte {
|
||||
bts := r.savedBytes.Bytes()
|
||||
r.savedBytes = nil
|
||||
return bts
|
||||
}
|
||||
|
||||
//ReadDiscrete ...
|
||||
func (r *RfbReadHelper) ReadDiscrete(p []byte) (int, error) {
|
||||
return r.Read(p)
|
||||
}
|
||||
|
||||
//SendRectSeparator ...
|
||||
func (r *RfbReadHelper) SendRectSeparator(upcomingRectType int) error {
|
||||
seg := &RfbSegment{SegmentType: SegmentRectSeparator, UpcomingObjectType: upcomingRectType}
|
||||
return r.Listeners.Consume(seg)
|
||||
}
|
||||
|
||||
//SendMessageStart ...
|
||||
func (r *RfbReadHelper) SendMessageStart(upcomingMessageType ServerMessageType) error {
|
||||
seg := &RfbSegment{SegmentType: SegmentMessageStart, UpcomingObjectType: int(upcomingMessageType)}
|
||||
return r.Listeners.Consume(seg)
|
||||
}
|
||||
|
||||
//SendMessageEnd ...
|
||||
func (r *RfbReadHelper) SendMessageEnd(messageType ServerMessageType) error {
|
||||
seg := &RfbSegment{SegmentType: SegmentMessageEnd, UpcomingObjectType: int(messageType)}
|
||||
return r.Listeners.Consume(seg)
|
||||
}
|
||||
|
||||
//PublishBytes ...
|
||||
func (r *RfbReadHelper) PublishBytes(p []byte) error {
|
||||
seg := &RfbSegment{Bytes: p, SegmentType: SegmentBytes}
|
||||
return r.Listeners.Consume(seg)
|
||||
@ -135,6 +149,7 @@ func (r *RfbReadHelper) Read(p []byte) (n int, err error) {
|
||||
return readLen, err
|
||||
}
|
||||
|
||||
//ReadBytes ...
|
||||
func (r *RfbReadHelper) ReadBytes(count int) ([]byte, error) {
|
||||
buff := make([]byte, count)
|
||||
|
||||
@ -157,6 +172,7 @@ func (r *RfbReadHelper) ReadBytes(count int) ([]byte, error) {
|
||||
return buff, nil
|
||||
}
|
||||
|
||||
//ReadUint8 ...
|
||||
func (r *RfbReadHelper) ReadUint8() (uint8, error) {
|
||||
var myUint uint8
|
||||
if err := binary.Read(r, binary.BigEndian, &myUint); err != nil {
|
||||
@ -165,6 +181,8 @@ func (r *RfbReadHelper) ReadUint8() (uint8, error) {
|
||||
|
||||
return myUint, nil
|
||||
}
|
||||
|
||||
//ReadUint16 ...
|
||||
func (r *RfbReadHelper) ReadUint16() (uint16, error) {
|
||||
var myUint uint16
|
||||
if err := binary.Read(r, binary.BigEndian, &myUint); err != nil {
|
||||
@ -173,6 +191,8 @@ func (r *RfbReadHelper) ReadUint16() (uint16, error) {
|
||||
|
||||
return myUint, nil
|
||||
}
|
||||
|
||||
//ReadUint32 ...
|
||||
func (r *RfbReadHelper) ReadUint32() (uint32, error) {
|
||||
var myUint uint32
|
||||
if err := binary.Read(r, binary.BigEndian, &myUint); err != nil {
|
||||
@ -181,6 +201,8 @@ func (r *RfbReadHelper) ReadUint32() (uint32, error) {
|
||||
|
||||
return myUint, nil
|
||||
}
|
||||
|
||||
//ReadCompactLen ...
|
||||
func (r *RfbReadHelper) ReadCompactLen() (int, error) {
|
||||
var err error
|
||||
part, err := r.ReadUint8()
|
||||
@ -204,6 +226,7 @@ func (r *RfbReadHelper) ReadCompactLen() (int, error) {
|
||||
return int(len), err
|
||||
}
|
||||
|
||||
//ReadTightData ...
|
||||
func (r *RfbReadHelper) ReadTightData(dataSize int) ([]byte, error) {
|
||||
if int(dataSize) < TightMinToCompress {
|
||||
return r.ReadBytes(int(dataSize))
|
||||
|
@ -4,14 +4,18 @@ import (
|
||||
"io"
|
||||
)
|
||||
|
||||
//ServerMessage ...
|
||||
type ServerMessage interface {
|
||||
Type() uint8
|
||||
String() string
|
||||
CopyTo(r io.Reader, w io.Writer, c IClientConn) error
|
||||
Read(IClientConn, *RfbReadHelper) (ServerMessage, error)
|
||||
}
|
||||
|
||||
//ServerMessageType ...
|
||||
type ServerMessageType int8
|
||||
|
||||
//ServerMessageType ...
|
||||
const (
|
||||
FramebufferUpdate ServerMessageType = iota
|
||||
SetColourMapEntries
|
||||
@ -34,6 +38,7 @@ func (typ ServerMessageType) String() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
//ServerInit ...
|
||||
type ServerInit struct {
|
||||
FBWidth, FBHeight uint16
|
||||
PixelFormat PixelFormat
|
||||
|
@ -6,15 +6,19 @@ import (
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
)
|
||||
|
||||
//CopyRectEncoding ..
|
||||
type CopyRectEncoding struct {
|
||||
//Colors []Color
|
||||
copyRectSrcX uint16
|
||||
copyRectSrcY uint16
|
||||
}
|
||||
|
||||
//Type ..
|
||||
func (z *CopyRectEncoding) Type() int32 {
|
||||
return 1
|
||||
}
|
||||
|
||||
//WriteTo ..
|
||||
func (z *CopyRectEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
binary.Write(w, binary.BigEndian, z.copyRectSrcX)
|
||||
if err != nil {
|
||||
@ -27,6 +31,7 @@ func (z *CopyRectEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
return 4, nil
|
||||
}
|
||||
|
||||
//Read ...
|
||||
func (z *CopyRectEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||
z.copyRectSrcX, _ = r.ReadUint16()
|
||||
z.copyRectSrcY, _ = r.ReadUint16()
|
||||
|
@ -6,16 +6,19 @@ import (
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
)
|
||||
|
||||
//CoRREEncoding ..
|
||||
type CoRREEncoding struct {
|
||||
numSubRects uint32
|
||||
backgroundColor []byte
|
||||
subRectData []byte
|
||||
}
|
||||
|
||||
//Type ...
|
||||
func (z *CoRREEncoding) Type() int32 {
|
||||
return 4
|
||||
}
|
||||
|
||||
//WriteTo ...
|
||||
func (z *CoRREEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
binary.Write(w, binary.BigEndian, z.numSubRects)
|
||||
if err != nil {
|
||||
|
@ -6,15 +6,21 @@ import (
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
)
|
||||
|
||||
//EncCursorPseudo ...
|
||||
type EncCursorPseudo struct {
|
||||
}
|
||||
|
||||
//Type ...
|
||||
func (pe *EncCursorPseudo) Type() int32 {
|
||||
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
|
||||
}
|
||||
|
||||
//Read ...
|
||||
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
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
)
|
||||
|
||||
//Hextile ...
|
||||
const (
|
||||
HextileRaw = 1
|
||||
HextileBackgroundSpecified = 2
|
||||
@ -14,17 +15,23 @@ const (
|
||||
HextileSubrectsColoured = 16
|
||||
)
|
||||
|
||||
//HextileEncoding ...
|
||||
type HextileEncoding struct {
|
||||
//Colors []Color
|
||||
bytes []byte
|
||||
}
|
||||
|
||||
//Type ...
|
||||
func (z *HextileEncoding) Type() int32 {
|
||||
return 5
|
||||
}
|
||||
|
||||
//WriteTo ...
|
||||
func (z *HextileEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
return w.Write(z.bytes)
|
||||
}
|
||||
|
||||
//Read ...
|
||||
func (z *HextileEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||
bytesPerPixel := int(pixelFmt.BPP) / 8
|
||||
|
||||
|
@ -6,17 +6,23 @@ import (
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
)
|
||||
|
||||
//EncLedStatePseudo ...
|
||||
type EncLedStatePseudo struct {
|
||||
LedState uint8
|
||||
}
|
||||
|
||||
//Type ...
|
||||
func (pe *EncLedStatePseudo) Type() int32 {
|
||||
return int32(common.EncLedStatePseudo)
|
||||
}
|
||||
|
||||
//WriteTo ...
|
||||
func (pe *EncLedStatePseudo) WriteTo(w io.Writer) (n int, err error) {
|
||||
w.Write([]byte{pe.LedState})
|
||||
return 1, nil
|
||||
}
|
||||
|
||||
//Read ...
|
||||
func (pe *EncLedStatePseudo) Read(pf *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||
if rect.Width*rect.Height == 0 {
|
||||
return pe, nil
|
||||
|
@ -5,16 +5,22 @@ import (
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
)
|
||||
|
||||
//PseudoEncoding ...
|
||||
type PseudoEncoding struct {
|
||||
Typ int32
|
||||
}
|
||||
|
||||
//Type ...
|
||||
func (pe *PseudoEncoding) Type() int32 {
|
||||
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
|
||||
}
|
||||
|
||||
//Read ...
|
||||
func (pe *PseudoEncoding) Read(*common.PixelFormat, *common.Rectangle, *common.RfbReadHelper) (common.IEncoding, error) {
|
||||
return pe, nil
|
||||
}
|
||||
|
@ -11,13 +11,18 @@ type RawEncoding struct {
|
||||
bytes []byte
|
||||
}
|
||||
|
||||
func (*RawEncoding) Type() int32 {
|
||||
//Type ...
|
||||
func (z *RawEncoding) Type() int32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
//WriteTo ...
|
||||
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.IEncoding, error) {
|
||||
|
||||
//Read ...
|
||||
func (z *RawEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||
|
||||
bytesPerPixel := int(pixelFmt.BPP / 8)
|
||||
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
)
|
||||
|
||||
//RREEncoding ...
|
||||
type RREEncoding struct {
|
||||
//Colors []Color
|
||||
numSubRects uint32
|
||||
@ -13,6 +14,7 @@ type RREEncoding struct {
|
||||
subRectData []byte
|
||||
}
|
||||
|
||||
//WriteTo ...
|
||||
func (z *RREEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
binary.Write(w, binary.BigEndian, z.numSubRects)
|
||||
if err != nil {
|
||||
@ -33,9 +35,12 @@ func (z *RREEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
return b, nil
|
||||
}
|
||||
|
||||
//Type ...
|
||||
func (z *RREEncoding) Type() int32 {
|
||||
return 2
|
||||
}
|
||||
|
||||
//Read ...
|
||||
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()
|
||||
|
@ -8,8 +8,10 @@ import (
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
)
|
||||
|
||||
//TightMinToCompress ....
|
||||
var TightMinToCompress int = 12
|
||||
|
||||
//Tight ...
|
||||
const (
|
||||
TightExplicitFilter = 0x04
|
||||
TightFill = 0x08
|
||||
@ -21,11 +23,13 @@ const (
|
||||
TightFilterGradient = 0x02
|
||||
)
|
||||
|
||||
//TightEncoding ...
|
||||
type TightEncoding struct {
|
||||
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 {
|
||||
bytesPerPixel := int(pf.BPP / 8)
|
||||
@ -39,10 +43,12 @@ func calcTightBytePerPixel(pf *common.PixelFormat) int {
|
||||
return bytesPerPixelTight
|
||||
}
|
||||
|
||||
//WriteTo ...
|
||||
func (z *TightEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
return w.Write(z.bytes)
|
||||
}
|
||||
|
||||
//StoreBytes ...
|
||||
func StoreBytes(bytes *bytes.Buffer, data []byte) {
|
||||
_, err := bytes.Write(data)
|
||||
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)
|
||||
|
||||
r.StartByteCollection()
|
||||
defer func() {
|
||||
t.bytes = r.EndByteCollection()
|
||||
z.bytes = r.EndByteCollection()
|
||||
}()
|
||||
|
||||
compctl, err := r.ReadUint8()
|
||||
@ -80,7 +86,7 @@ func (t *TightEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangl
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return t, nil
|
||||
return z, nil
|
||||
case TightJpeg:
|
||||
if pixelFmt.BPP == 8 {
|
||||
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 t, nil
|
||||
return z, nil
|
||||
default:
|
||||
|
||||
if compType > TightJpeg {
|
||||
@ -106,18 +112,18 @@ func (t *TightEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangl
|
||||
|
||||
handleTightFilters(compctl, pixelFmt, rect, r)
|
||||
|
||||
return t, nil
|
||||
return z, nil
|
||||
}
|
||||
}
|
||||
|
||||
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 err error
|
||||
|
||||
if (subencoding & FILTER_ID_MASK) > 0 { // filter byte presence
|
||||
if (subencoding & FilterIDMask) > 0 { // filter byte presence
|
||||
filterid, err = r.ReadUint8()
|
||||
|
||||
if err != nil {
|
||||
|
@ -7,21 +7,25 @@ import (
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
)
|
||||
|
||||
//TightPngEncoding ...
|
||||
type TightPngEncoding struct {
|
||||
bytes []byte
|
||||
}
|
||||
|
||||
//WriteTo ...
|
||||
func (z *TightPngEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
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)
|
||||
r.StartByteCollection()
|
||||
defer func() {
|
||||
t.bytes = r.EndByteCollection()
|
||||
z.bytes = r.EndByteCollection()
|
||||
}()
|
||||
|
||||
//var subencoding uint8
|
||||
@ -42,7 +46,7 @@ func (t *TightPngEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Recta
|
||||
_, err = r.ReadBytes(len)
|
||||
|
||||
if err != nil {
|
||||
return t, err
|
||||
return z, err
|
||||
}
|
||||
|
||||
case TightFill:
|
||||
@ -50,5 +54,5 @@ func (t *TightPngEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Recta
|
||||
default:
|
||||
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"
|
||||
)
|
||||
|
||||
// ZLibEncoding ..
|
||||
type ZLibEncoding struct {
|
||||
bytes []byte
|
||||
}
|
||||
|
||||
// Type ..
|
||||
func (z *ZLibEncoding) Type() int32 {
|
||||
return 6
|
||||
}
|
||||
|
||||
// WriteTo ...
|
||||
func (z *ZLibEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
return w.Write(z.bytes)
|
||||
}
|
||||
|
||||
//Read ...
|
||||
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}
|
||||
|
@ -7,18 +7,22 @@ import (
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
)
|
||||
|
||||
//ZRLEEncoding ...
|
||||
type ZRLEEncoding struct {
|
||||
bytes []byte
|
||||
}
|
||||
|
||||
//Type ...
|
||||
func (z *ZRLEEncoding) Type() int32 {
|
||||
return 16
|
||||
}
|
||||
|
||||
//WriteTo ...
|
||||
func (z *ZRLEEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
return w.Write(z.bytes)
|
||||
}
|
||||
|
||||
//Read ...
|
||||
func (z *ZRLEEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||
|
||||
bytes := &bytes.Buffer{}
|
||||
|
@ -2,6 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
)
|
||||
@ -21,10 +22,12 @@ type MsgSetPixelFormat struct {
|
||||
_ [3]byte // padding after pixel format
|
||||
}
|
||||
|
||||
func (*MsgSetPixelFormat) Type() common.ClientMessageType {
|
||||
//Type ...
|
||||
func (msg *MsgSetPixelFormat) Type() common.ClientMessageType {
|
||||
return common.SetPixelFormatMsgType
|
||||
}
|
||||
|
||||
//Write ...
|
||||
func (msg *MsgSetPixelFormat) Write(c io.Writer) error {
|
||||
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
|
||||
return err
|
||||
@ -58,6 +61,7 @@ type MsgSetEncodings struct {
|
||||
Encodings []common.EncodingType
|
||||
}
|
||||
|
||||
//Type ...
|
||||
func (*MsgSetEncodings) Type() common.ClientMessageType {
|
||||
return common.SetEncodingsMsgType
|
||||
}
|
||||
@ -114,10 +118,12 @@ type MsgFramebufferUpdateRequest struct {
|
||||
Width, Height uint16 // width, height
|
||||
}
|
||||
|
||||
//Type ...
|
||||
func (*MsgFramebufferUpdateRequest) Type() common.ClientMessageType {
|
||||
return common.FramebufferUpdateRequestMsgType
|
||||
}
|
||||
|
||||
//Read ...
|
||||
func (*MsgFramebufferUpdateRequest) Read(c io.Reader) (common.ClientMessage, error) {
|
||||
msg := MsgFramebufferUpdateRequest{}
|
||||
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
|
||||
}
|
||||
|
||||
//Write ...
|
||||
func (msg *MsgFramebufferUpdateRequest) Write(c io.Writer) error {
|
||||
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
|
||||
return err
|
||||
@ -143,6 +150,7 @@ type MsgKeyEvent struct {
|
||||
Key Key // key
|
||||
}
|
||||
|
||||
//Type ...
|
||||
func (*MsgKeyEvent) Type() common.ClientMessageType {
|
||||
return common.KeyEventMsgType
|
||||
}
|
||||
@ -165,7 +173,7 @@ func (msg *MsgKeyEvent) Write(c io.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// MsgKeyEvent holds the wire format message.
|
||||
// MsgQEMUExtKeyEvent holds the wire format message.
|
||||
type MsgQEMUExtKeyEvent struct {
|
||||
SubmessageType uint8 // submessage type
|
||||
DownFlag uint16 // down-flag
|
||||
@ -173,10 +181,12 @@ type MsgQEMUExtKeyEvent struct {
|
||||
KeyCode uint32 // scan code
|
||||
}
|
||||
|
||||
//Type ...
|
||||
func (*MsgQEMUExtKeyEvent) Type() common.ClientMessageType {
|
||||
return common.QEMUExtendedKeyEventMsgType
|
||||
}
|
||||
|
||||
//Read ...
|
||||
func (*MsgQEMUExtKeyEvent) Read(c io.Reader) (common.ClientMessage, error) {
|
||||
msg := MsgKeyEvent{}
|
||||
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
|
||||
}
|
||||
|
||||
//Write ...
|
||||
func (msg *MsgQEMUExtKeyEvent) Write(c io.Writer) error {
|
||||
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
|
||||
return err
|
||||
@ -195,16 +206,18 @@ func (msg *MsgQEMUExtKeyEvent) Write(c io.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// PointerEventMessage holds the wire format message.
|
||||
// MsgPointerEvent holds the wire format message.
|
||||
type MsgPointerEvent struct {
|
||||
Mask uint8 // button-mask
|
||||
X, Y uint16 // x-, y-position
|
||||
}
|
||||
|
||||
//Type ...
|
||||
func (*MsgPointerEvent) Type() common.ClientMessageType {
|
||||
return common.PointerEventMsgType
|
||||
}
|
||||
|
||||
//Read ...
|
||||
func (*MsgPointerEvent) Read(c io.Reader) (common.ClientMessage, error) {
|
||||
msg := MsgPointerEvent{}
|
||||
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
|
||||
@ -223,13 +236,16 @@ func (msg *MsgPointerEvent) Write(c io.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//MsgClientFence ...
|
||||
type MsgClientFence struct {
|
||||
}
|
||||
|
||||
//Type ...
|
||||
func (*MsgClientFence) Type() common.ClientMessageType {
|
||||
return common.ClientFenceMsgType
|
||||
}
|
||||
|
||||
//Read ...
|
||||
func (cf *MsgClientFence) Read(c io.Reader) (common.ClientMessage, error) {
|
||||
bytes := make([]byte, 3)
|
||||
c.Read(bytes)
|
||||
@ -253,8 +269,9 @@ func (cf *MsgClientFence) Read(c io.Reader) (common.ClientMessage, error) {
|
||||
return cf, nil
|
||||
}
|
||||
|
||||
func (msg *MsgClientFence) Write(c io.Writer) error {
|
||||
panic("not implemented!")
|
||||
//Write ...
|
||||
func (cf *MsgClientFence) Write(c io.Writer) error {
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
// MsgClientCutText holds the wire format message, sans the text field.
|
||||
@ -264,10 +281,12 @@ type MsgClientCutText struct {
|
||||
Text []byte
|
||||
}
|
||||
|
||||
//Type ...
|
||||
func (*MsgClientCutText) Type() common.ClientMessageType {
|
||||
return common.ClientCutTextMsgType
|
||||
}
|
||||
|
||||
//Read ...
|
||||
func (*MsgClientCutText) Read(c io.Reader) (common.ClientMessage, error) {
|
||||
msg := MsgClientCutText{}
|
||||
var pad [3]byte
|
||||
|
@ -9,14 +9,17 @@ import (
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
)
|
||||
|
||||
//ProtoVersionLength ...
|
||||
const ProtoVersionLength = 12
|
||||
|
||||
//ProtoVersion ...
|
||||
const (
|
||||
ProtoVersionUnknown = ""
|
||||
ProtoVersion33 = "RFB 003.003\n"
|
||||
ProtoVersion38 = "RFB 003.008\n"
|
||||
)
|
||||
|
||||
//ParseProtoVersion ...
|
||||
func ParseProtoVersion(pv []byte) (uint, uint, error) {
|
||||
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)
|
||||
if l != 2 {
|
||||
return 0, 0, fmt.Errorf("error parsing ProtocolVersion.")
|
||||
return 0, 0, fmt.Errorf("error parsing ProtocolVersion")
|
||||
}
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
@ -35,6 +38,7 @@ func ParseProtoVersion(pv []byte) (uint, uint, error) {
|
||||
return major, minor, nil
|
||||
}
|
||||
|
||||
//ServerVersionHandler ...
|
||||
func ServerVersionHandler(cfg *ServerConfig, c *ServerConn) error {
|
||||
var version [ProtoVersionLength]byte
|
||||
if err := binary.Write(c, binary.BigEndian, []byte(ProtoVersion38)); err != nil {
|
||||
@ -143,7 +147,7 @@ func ServerServerInitHandler(cfg *ServerConfig, c *ServerConn) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := srvInit.PixelFormat.WriteTo(c); err != nil {
|
||||
if _, err := srvInit.PixelFormat.WriteTo(c); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := binary.Write(c, binary.BigEndian, srvInit.NameLength); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user