Class: MysqlPR::Protocol::InitialPacket

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql-pr/protocol.rb

Overview

Initial packet

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ InitialPacket

Returns a new instance of InitialPacket.



825
826
827
828
# File 'lib/mysql-pr/protocol.rb', line 825

def initialize(*args)
  @protocol_version, @server_version, @thread_id, @server_capabilities,
    @server_charset, @server_status, @scramble_buff, @auth_plugin_name = args
end

Instance Attribute Details

#auth_plugin_nameObject (readonly)

Returns the value of attribute auth_plugin_name.



822
823
824
# File 'lib/mysql-pr/protocol.rb', line 822

def auth_plugin_name
  @auth_plugin_name
end

#protocol_versionObject (readonly)

Returns the value of attribute protocol_version.



822
823
824
# File 'lib/mysql-pr/protocol.rb', line 822

def protocol_version
  @protocol_version
end

#scramble_buffObject (readonly)

Returns the value of attribute scramble_buff.



822
823
824
# File 'lib/mysql-pr/protocol.rb', line 822

def scramble_buff
  @scramble_buff
end

#server_capabilitiesObject (readonly)

Returns the value of attribute server_capabilities.



822
823
824
# File 'lib/mysql-pr/protocol.rb', line 822

def server_capabilities
  @server_capabilities
end

#server_charsetObject (readonly)

Returns the value of attribute server_charset.



822
823
824
# File 'lib/mysql-pr/protocol.rb', line 822

def server_charset
  @server_charset
end

#server_statusObject (readonly)

Returns the value of attribute server_status.



822
823
824
# File 'lib/mysql-pr/protocol.rb', line 822

def server_status
  @server_status
end

#server_versionObject (readonly)

Returns the value of attribute server_version.



822
823
824
# File 'lib/mysql-pr/protocol.rb', line 822

def server_version
  @server_version
end

#thread_idObject (readonly)

Returns the value of attribute thread_id.



822
823
824
# File 'lib/mysql-pr/protocol.rb', line 822

def thread_id
  @thread_id
end

Class Method Details

.parse(pkt) ⇒ Object

Raises:



791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
# File 'lib/mysql-pr/protocol.rb', line 791

def self.parse(pkt)
  protocol_version = pkt.utiny
  server_version = pkt.string
  thread_id = pkt.ulong
  scramble_buff = pkt.read(8)
  f0 = pkt.utiny
  server_capabilities = pkt.ushort
  server_charset = pkt.utiny
  server_status = pkt.ushort
  server_capabilities_upper = pkt.ushort
  auth_plugin_data_length = pkt.utiny
  pkt.read(10) # reserved
  # Read rest of scramble (12 bytes for caching_sha2_password, or variable)
  rest_scramble_len = [auth_plugin_data_length - 8, 12].max
  rest_scramble_buff = pkt.read(rest_scramble_len)
  # Remove trailing null if present
  rest_scramble_buff = rest_scramble_buff.sub(/\x00+\z/, "")
  auth_plugin_name = begin
    pkt.string
  rescue StandardError
    "mysql_native_password"
  end
  raise ProtocolError, "unsupported version: #{protocol_version}" unless protocol_version == VERSION
  raise ProtocolError, "invalid packet: f0=#{f0}" unless f0.zero?

  scramble_buff.concat rest_scramble_buff
  server_capabilities |= (server_capabilities_upper << 16)
  new protocol_version, server_version, thread_id, server_capabilities, server_charset, server_status,
      scramble_buff, auth_plugin_name
end