plugin

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2026 License: GPL-3.0 Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package plugin is the virtual channel framework.

A virtual channel is a named byte stream multiplexed over the RDP connection and framed in chunks of at most CHANNEL_CHUNK_LENGTH bytes. Channels registers a ChannelTransport under the name it reports, reassembles the chunks of each channel separately, and hands each complete message to that transport's Process method.

Most callers never use this package directly: the concrete channels built on it are plugin/cliprdr (clipboard), plugin/drdynvc (dynamic channels) and plugin/rdpgfx (graphics). Implement ChannelTransport to add another.

The exported names here mirror the C virtual channel API that FreeRDP and Windows implement, which is why they keep its capitalisation.

This package used to import "C" while using no C, which made cgo a requirement for the whole module for no reason: the RDP client imports this package, so CGO_ENABLED=0 dropped channel.go entirely and the build failed with "undefined: plugin.CHANNEL_OPTION_INITIALIZED". The stray import is gone and the module builds without cgo now, which is what a library should do.

Index

Constants

View Source
const (
	CHANNEL_RC_OK                         = 0
	CHANNEL_RC_ALREADY_INITIALIZED        = 1
	CHANNEL_RC_NOT_INITIALIZED            = 2
	CHANNEL_RC_ALREADY_CONNECTED          = 3
	CHANNEL_RC_NOT_CONNECTED              = 4
	CHANNEL_RC_TOO_MANY_CHANNELS          = 5
	CHANNEL_RC_BAD_CHANNEL                = 6
	CHANNEL_RC_BAD_CHANNEL_HANDLE         = 7
	CHANNEL_RC_NO_BUFFER                  = 8
	CHANNEL_RC_BAD_INIT_HANDLE            = 9
	CHANNEL_RC_NOT_OPEN                   = 10
	CHANNEL_RC_BAD_PROC                   = 11
	CHANNEL_RC_NO_MEMORY                  = 12
	CHANNEL_RC_UNKNOWN_CHANNEL_NAME       = 13
	CHANNEL_RC_ALREADY_OPEN               = 14
	CHANNEL_RC_NOT_IN_VIRTUALCHANNELENTRY = 15
	CHANNEL_RC_NULL_DATA                  = 16
	CHANNEL_RC_ZERO_LENGTH                = 17
	CHANNEL_RC_INVALID_INSTANCE           = 18
	CHANNEL_RC_UNSUPPORTED_VERSION        = 19
	CHANNEL_RC_INITIALIZATION_ERROR       = 20
)

The return codes of the FreeRDP virtual channel API. They are defined here to match that API's values rather than for use in this library: nothing in the build returns one. See the note on ChannelEntryPointsEx.

View Source
const (
	CHANNEL_EVENT_INITIALIZED          = 0
	CHANNEL_EVENT_CONNECTED            = 1
	CHANNEL_EVENT_V1_CONNECTED         = 2
	CHANNEL_EVENT_DISCONNECTED         = 3
	CHANNEL_EVENT_TERMINATED           = 4
	CHANNEL_EVENT_REMOTE_CONTROL_START = 5
	CHANNEL_EVENT_REMOTE_CONTROL_STOP  = 6
	CHANNEL_EVENT_ATTACHED             = 7
	CHANNEL_EVENT_DETACHED             = 8
	CHANNEL_EVENT_DATA_RECEIVED        = 10
	CHANNEL_EVENT_WRITE_COMPLETE       = 11
	CHANNEL_EVENT_WRITE_CANCELLED      = 12
)

The events a virtual channel is told about. DATA_RECEIVED and WRITE_COMPLETE are what a channel implementation acts on; the others describe the life of the session, including the two remote control events and the attached and detached pair, which this library never sends.

View Source
const (
	CHANNEL_OPTION_INITIALIZED               = 0x80000000
	CHANNEL_OPTION_ENCRYPT_RDP               = 0x40000000
	CHANNEL_OPTION_ENCRYPT_SC                = 0x20000000
	CHANNEL_OPTION_ENCRYPT_CS                = 0x10000000
	CHANNEL_OPTION_PRI_HIGH                  = 0x08000000
	CHANNEL_OPTION_PRI_MED                   = 0x04000000
	CHANNEL_OPTION_PRI_LOW                   = 0x02000000
	CHANNEL_OPTION_COMPRESS_RDP              = 0x00800000
	CHANNEL_OPTION_COMPRESS                  = 0x00400000
	CHANNEL_OPTION_SHOW_PROTOCOL             = 0x00200000
	CHANNEL_OPTION_REMOTE_CONTROL_PERSISTENT = 0x00100000
)

The channel options, which are the same values as gcc.ChannelOptions: a channel is asked for with these flags in the Connect-Initial and they are what the server reads. The duplication is deliberate, because this package does not depend on the protocol packages, and the two must be kept in step by hand.

View Source
const (
	CLIPRDR_SVC_CHANNEL_NAME = "cliprdr" // clipboard
	DRDYNVC_SVC_CHANNEL_NAME = "drdynvc" // dynamic virtual channels
	DISP_SVC_CHANNEL_NAME    = "disp"    // display control
)

Static channel names. Only the ones this library actually speaks are here: a name with nothing behind it invites advertising a channel and then refusing to answer it, which is worse than not asking for it.

View Source
const (
	CHANNEL_CHUNK_LENGTH       = 1600
	CHANNEL_FLAG_FIRST         = 0x01
	CHANNEL_FLAG_LAST          = 0x02
	CHANNEL_FLAG_SHOW_PROTOCOL = 0x10
)

The chunking of a channel message. A channel write is cut into chunks of at most CHANNEL_CHUNK_LENGTH, each with a header saying the total length of the whole message and which chunks it is, and the receiver puts them back together.

The flags are the position of the chunk: FIRST begins a message and LAST ends one, and a message that fits in a single chunk carries both. SHOW_PROTOCOL asks for the header to be visible to the channel rather than being removed before delivery.

View Source
const (
	RDPGFX_DVC_CHANNEL_NAME = "Microsoft::Windows::RDS::Graphics" // graphics
)

RDPGFX_DVC_CHANNEL_NAME is the dynamic virtual channel the graphics protocol runs on. It is the name the server knows it by, so it is not a local choice.

View Source
const (
	VIRTUAL_CHANNEL_VERSION_WIN2000 = 1
)

VIRTUAL_CHANNEL_VERSION_WIN2000 is the version to request in the FreeRDP channel API. It is the only version defined, so asking for anything else is the same as asking for this.

Variables

This section is empty.

Functions

This section is empty.

Types

type CHANNEL_INIT_EVENT_EX_FN

type CHANNEL_INIT_EVENT_EX_FN func(lpUserParam interface{},
	pInitHandle interface{}, event uint, pData uintptr, dataLength uint)

CHANNEL_INIT_EVENT_EX_FN is the callback a channel registers to be told about the life of the session: initialised, connected, disconnected and terminated.

type CHANNEL_OPEN_EVENT_EX_FN

type CHANNEL_OPEN_EVENT_EX_FN func(lpUserParam uintptr,
	openHandle uint32, event uint,
	pData uintptr, dataLength uint32, totalLength uint32, dataFlags uint32)

CHANNEL_OPEN_EVENT_EX_FN is the callback a channel registers when it is opened. It is what delivers data to it, as a pointer and a length rather than a slice, which is the shape the Windows API uses.

type ChannelClient

type ChannelClient struct {
	ChannelDef
	// contains filtered or unexported fields
}

ChannelClient is a registered channel: its definition and the plugin behind it.

type ChannelDef

type ChannelDef struct {
	Name    string
	Options uint32
}

ChannelDef is a channel as it is asked for: the name and the options.

type ChannelEntryPointsEx

type ChannelEntryPointsEx struct {
	CbSize                 uint32
	ProtocolVersion        uint32
	PVirtualChannelInitEx  VIRTUALCHANNELINITEX
	PVirtualChannelOpenEx  VIRTUALCHANNELOPENEX
	PVirtualChannelCloseEx VIRTUALCHANNELCLOSEEX
	PVirtualChannelWriteEx VIRTUALCHANNELWRITEEX
}

ChannelEntryPointsEx is the FreeRDP virtual channel entry points, which is how a Windows channel plugin is handed the functions it calls back into.

Nothing in the build uses this: its only consumer is the addins port in plugin/addins.go, which is switched off with //go:build ignore because it needs Windows and defines the same functions with LazyDLL. It is kept because the port is unfinished rather than abandoned, and the whole API in this file is here for the same reason.

func NewChannelEntryPointsEx

func NewChannelEntryPointsEx() *ChannelEntryPointsEx

NewChannelEntryPointsEx returns entry points with the size and protocol version filled in, which is what a caller has to set before handing them to a plugin.

The size is computed rather than written, so that adding a function pointer to the structure does not leave the field disagreeing with it.

type ChannelTransport

type ChannelTransport interface {
	GetType() (string, uint32)
	Sender(core.ChannelSender)
	Process(s []byte)
}

ChannelTransport is what a plugin implements to be a channel: its name and options, where to send, and what to do with what arrives.

It is the interface this library actually uses, and it is small on purpose. The FreeRDP API above describes the same idea in the shape a Windows plugin needs; this is the shape a Go one does.

type Channels

type Channels struct {
	emission.Emitter
	// contains filtered or unexported fields
}

Channels is the set of static virtual channels in a session. It reads the channel messages out of the data path, puts chunked messages back together, and hands each one to the plugin that registered the channel it was for.

The reassembly buffers are per channel and not shared, because a chunked message on one channel must not be corrupted by a message arriving on another.

func NewChannels

func NewChannels(t core.Transport) *Channels

NewChannels returns an empty set of channels, which listens for the transport's "channel" event. A plugin is added with Register, and nothing is sent until one is.

func (*Channels) Register

func (c *Channels) Register(t ChannelTransport)

Register adds a plugin as a channel. The name and options come from the plugin, and the plugin is given this set as its sender so that it can write back.

Registering the same name twice is refused with a warning rather than replacing the first registration: a channel that was silently taken over by a second one would be very hard to see. This is also where the channel is asked for, since the options that go in the Connect-Initial are read from here.

func (*Channels) SendToChannel

func (c *Channels) SendToChannel(channel string, s []byte) (int, error)

SendToChannel cuts a message into chunks and sends it on a channel.

Every chunk carries the total length of the message and its own position, so a message longer than CHANNEL_CHUNK_LENGTH arrives in pieces the receiver joins back together. The flag for showing the header is copied from the channel's options, because a channel that asked for it expects the header to be part of the data.

The count returned is the number of payload bytes sent, not counting the eight byte chunk headers. It used to return zero always, because it returned the very variable the loop counted down, and it used to discard the sender's error, so a caller had no way at all to tell whether a message had gone anywhere. A failure part way through a chunked message returns the bytes sent before it, which is what tells a caller that the message was partly delivered.

func (*Channels) SetChannelSender

func (c *Channels) SetChannelSender(f core.ChannelSender)

SetChannelSender sets what outgoing channel traffic is written through. It is set by the security layer once the connection is up, and a send before that has nowhere to go.

type VIRTUALCHANNELCLOSEEX

type VIRTUALCHANNELCLOSEEX func(pInitHandle interface{}, openHandle uint32) uint

VIRTUALCHANNELCLOSEEX closes an open channel.

type VIRTUALCHANNELENTRYEX

type VIRTUALCHANNELENTRYEX func(pEntryPointsEx *ChannelEntryPointsEx,
	pInitHandle interface{}) error

VIRTUALCHANNELENTRYEX is the function a plugin exports, which the client calls once to hand over the entry points. Its name is fixed by the API rather than chosen, which is why it is exported here and why it cannot be renamed.

type VIRTUALCHANNELINITEX

type VIRTUALCHANNELINITEX func(lpUserParam interface{}, clientContext interface{},
	pInitHandle interface{}, pChannel []ChannelDef,
	channelCount int, versionRequested uint32,
	pChannelInitEventProcEx CHANNEL_INIT_EVENT_EX_FN) uint

VIRTUALCHANNELINITEX registers the channels a plugin wants, and the callback it wants called for session events.

type VIRTUALCHANNELOPENEX

type VIRTUALCHANNELOPENEX func(pInitHandle interface{}, pOpenHandle *uint32,
	pChannelName string,
	pChannelOpenEventProcEx *CHANNEL_OPEN_EVENT_EX_FN) uint

VIRTUALCHANNELOPENEX opens one of the registered channels and returns a handle for it, which the other calls take.

type VIRTUALCHANNELWRITEEX

type VIRTUALCHANNELWRITEEX func(pInitHandle interface{}, openHandle uint32, pData interface{},
	dataLength uint32, pUserData interface{}) uint

VIRTUALCHANNELWRITEEX writes to an open channel.

Directories

Path Synopsis
Package cliprdr implements the clipboard virtual channel: text and files, in both directions.
Package cliprdr implements the clipboard virtual channel: text and files, in both directions.
Package disp implements the display control dynamic virtual channel (MS-RDPEDISP), which is how a client asks the server to change the desktop size while a session is running.
Package disp implements the display control dynamic virtual channel (MS-RDPEDISP), which is how a client asks the server to change the desktop size while a session is running.
Package drdynvc implements the dynamic virtual channel channel (MS-RDPEDYC).
Package drdynvc implements the dynamic virtual channel channel (MS-RDPEDYC).
Package rdpgfx implements the RDP Graphics Pipeline Extension channel (MS-RDPEGFX), the modern drawing path where a server composites surfaces and sends them as compressed bitmaps.
Package rdpgfx implements the RDP Graphics Pipeline Extension channel (MS-RDPEGFX), the modern drawing path where a server composites surfaces and sends them as compressed bitmaps.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL