mysql

package
v0.0.0-...-63a5f98 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package mysql provides facilities for decoding and inspecting MySQL wire protocol information.

Index

Constants

This section is empty.

Variables

View Source
var ErrHandshakeDecode = fmt.Errorf("handshake decode")
View Source
var ErrHandshakeTruncated = fmt.Errorf("%w: truncated payload or not a mysql handshake", ErrHandshakeDecode)
View Source
var ErrPacketDecode = fmt.Errorf("packet decode")

Functions

This section is empty.

Types

type Capability

type Capability uint32

Capability is a capability composite flag field. Each bit represents an optional feature of the protocol. Both the client and server send these.

const (
	CapabilityLongPassword               Capability = 1 << 0
	CapabilityFoundRows                  Capability = 1 << 1
	CapabilityLongFlag                   Capability = 1 << 2
	CapabilityConnectWithDB              Capability = 1 << 3
	CapabilityNoSchema                   Capability = 1 << 4
	CapabilityCompress                   Capability = 1 << 5
	CapabilityODBC                       Capability = 1 << 6
	CapabilityLocalFiles                 Capability = 1 << 7
	CapabilityIgnoreSpace                Capability = 1 << 8
	CapabilityProtocol41                 Capability = 1 << 9
	CapabilityInteractive                Capability = 1 << 10
	CapabilitySSL                        Capability = 1 << 11
	CapabilityIgnoreSigPipe              Capability = 1 << 12
	CapabilityTransactions               Capability = 1 << 13
	CapabilityReserved                   Capability = 1 << 14
	CapabilityReserved2                  Capability = 1 << 15
	CapabilityMultiStatements            Capability = 1 << 16
	CapabilityMultiResults               Capability = 1 << 17
	CapabilityPSMultiResults             Capability = 1 << 18
	CapabilityPluginAuth                 Capability = 1 << 19
	CapabilityConnectAttrs               Capability = 1 << 20
	CapabilityPluginAuthLenEncClientData Capability = 1 << 21
	CapabilityCanHandleExpiredPasswords  Capability = 1 << 22
	CapabilitySessionTrack               Capability = 1 << 23
	CapabilityDeprecateEOF               Capability = 1 << 24
	CapabilityOptionalResultSetMetadata  Capability = 1 << 25
	CapabilitySSLVerifyServerCert        Capability = 1 << 30
	CapabilityRememberOptions            Capability = 1 << 31
)

Capability Flags

func (Capability) Has

func (c Capability) Has(cap Capability) bool

Has determines if the Capability contains the given Capability flag.

func (Capability) MarshalJSON

func (c Capability) MarshalJSON() ([]byte, error)

type Handshake

type Handshake interface {
	// GetProtoVersion returns the MySQL Protocol Version.
	GetProtoVersion() uint8
}

func DecodeHandshake

func DecodeHandshake(payload []byte) (Handshake, error)

DecodeHandshake attempts to read and decode the given series of bytes as a MySQL Handshake payload. If decoding is successful, a Handshake representing the actual underlying handshake message will be returned.

See https://dev.mysql.com/doc/internals/en/connection-phase.html

type HandshakeV10

type HandshakeV10 struct {
	// ServerVersion contains the human readable server version.
	ServerVersion string `json:"server_version"`

	// ThreadID is the connection ID.
	ThreadID uint32 `json:"thread_id"`

	// AuthPluginData contains scramble data used by authentication plugins.
	AuthPluginData []byte `json:"auth_plugin_data"`

	// CharacterSet contains the server's charset id.
	CharacterSet uint8 `json:"character_set"`

	// CapabilityFlags is a composite flag field used by the client and server
	// to communicate supported functions and features.
	CapabilityFlags Capability `json:"capability_flags"`

	// ServerStatusFlags is a composite flag field used to communicate the current
	// status of the server.
	ServerStatusFlags ServerStatus `json:"server_status_flags"`

	// AuthPluginName is the name (if any) of the auth plugin which the authentication scramble data belongs to.
	AuthPluginName string `json:"auth_plugin_name,omitempty"`
}

HandshakeV10 represents the MySQL initial handshake packet for protocol version 10. This payload is sent from the server to the client at the start of the conversation.

See https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::Handshake

func (*HandshakeV10) GetProtoVersion

func (*HandshakeV10) GetProtoVersion() uint8

GetProtoVersion returns the MySQL Protocol Version this Handshake implements. Always 10.

type HandshakeV9

type HandshakeV9 struct {
	// ServerVersion contains the human readable server version.
	ServerVersion string `json:"server_version"`

	// ThreadID is the connection ID.
	ThreadID uint32 `json:"thread_id"`

	// Scramble is the authentication data for the Old Password Authentication method.
	Scramble []byte `json:"scramble"`
}

HandshakeV9 represents the MySQL initial handshake packet for protocol version 9. This payload is sent from the server to the client at the start of the conversation.

See https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::Handshake

func (*HandshakeV9) GetProtoVersion

func (*HandshakeV9) GetProtoVersion() uint8

GetProtoVersion returns the MySQL Protocol Version this Handshake implements. Always 9.

type Packet

type Packet struct {
	// SequenceID is the packet's sequence ID.
	SequenceID uint8

	// Payload of the packet.
	Payload []byte
}

Packet represents the basic MySQL packet. See https://dev.mysql.com/doc/internals/en/mysql-packet.html

func ReadPacket

func ReadPacket(r io.Reader) (*Packet, error)

ReadPacket attempts to read a MySQL packet from the given reader and produce the packet's payload.

type ServerStatus

type ServerStatus uint16

ServerStatus is a server status composite flag field.

const (
	ServerStatusInTrans           ServerStatus = 1 << 0
	ServerStatusAutoCommit        ServerStatus = 1 << 1
	ServerStatusMoreResultsExist  ServerStatus = 1 << 3
	ServerStatusNoGoodIndexUsed   ServerStatus = 1 << 4
	ServerStatusNoIndexUsed       ServerStatus = 1 << 5
	ServerStatusCursorExists      ServerStatus = 1 << 6
	ServerStatusLastRowSent       ServerStatus = 1 << 7
	ServerStatusDBDropped         ServerStatus = 1 << 8
	ServerStatusNoBacklashEscapes ServerStatus = 1 << 9
	ServerStatusMetadataChanged   ServerStatus = 1 << 10
	ServerStatusQuerySlow         ServerStatus = 1 << 11
	ServerStatusPSOutParams       ServerStatus = 1 << 12
	ServerStatusInTransReadOnly   ServerStatus = 1 << 13
	ServerStatusStateChanged      ServerStatus = 1 << 14
)

ServerStatus Flags

func (ServerStatus) Has

func (s ServerStatus) Has(status ServerStatus) bool

Has determines if the ServerStatus contains the given ServerStatus flag.

func (ServerStatus) MarshalJSON

func (s ServerStatus) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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