def getEventBody(self):
        payload = bytearray()

        payload.extend(Proto.build_fixed_int(2, self.binlog_version))
        payload.extend(Proto.build_fixed_str(50, self.mysql_server_version))
        payload.extend(Proto.build_fixed_int(4, self.timestamp))
        payload.extend(Proto.build_fixed_int(1, self.header_length))
        payload.extend(self.event_type_header_length)

        return payload
Example #2
0
    def getPayload(self):
        payload = bytearray()

        if self.hasCapabilityFlag(Flags.CLIENT_PROTOCOL_41):
            payload.extend(Proto.build_fixed_int(4, self.capabilityFlags))
            payload.extend(Proto.build_fixed_int(4, self.maxPacketSize))
            payload.extend(Proto.build_fixed_int(1, self.characterSet))
            payload.extend(Proto.build_filler(23))
            payload.extend(Proto.build_null_str(self.username))

            if self.hasCapabilityFlag(
                    Flags.CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA):
                payload.extend(Proto.build_lenenc_int(len(self.authResponse)))
                payload.extend(
                    Proto.build_fixed_str(len(self.authResponse),
                                          self.authResponse))
            elif self.hasCapabilityFlag(Flags.CLIENT_SECURE_CONNECTION):
                payload.extend(Proto.build_lenenc_int(len(self.authResponse)))
                payload.extend(
                    Proto.build_fixed_str(len(self.authResponse),
                                          self.authResponse))
            else:
                payload.extend(Proto.build_null_str(self.authResponse))

            if self.hasCapabilityFlag(Flags.CLIENT_CONNECT_WITH_DB):
                payload.extend(Proto.build_null_str(self.schema))

            if self.hasCapabilityFlag(Flags.CLIENT_PLUGIN_AUTH):
                payload.extend(Proto.build_null_str(self.pluginName))

            if self.hasCapabilityFlag(Flags.CLIENT_CONNECT_ATTRS):
                attributes = bytearray()
                for k, v in self.clientAttributes.items():
                    attributes.extend(Proto.build_lenenc_str(k))
                    attributes.extend(Proto.build_lenenc_str(v))
                payload.extend(Proto.build_lenenc_int(len(attributes)))
                payload.extend(attributes)

        else:
            payload.extend(Proto.build_fixed_int(2, self.capabilityFlags))
            payload.extend(Proto.build_fixed_int(3, self.maxPacketSize))
            payload.extend(Proto.build_null_str(self.username))
            if self.hasCapabilityFlag(Flags.CLIENT_CONNECT_WITH_DB):
                payload.extend(Proto.build_null_str(self.authResponse))
                payload.extend(Proto.build_null_str(self.schema))
            else:
                payload.extend(Proto.build_eop_str(self.authResponse))

        return payload
Example #3
0
    def toPacket(self):
        """
        Convert a Packet object to a byte array stream
        """
        payload = self.getPayload()

        # Size is payload + packet size + sequence id
        size = len(payload)

        packet = bytearray(size + 4)

        packet[0:2] = Proto.build_fixed_int(3, size)
        packet[3] = Proto.build_fixed_int(1, self.sequenceId)[0]
        packet[4:] = payload

        return packet
    def getPayload(self):
        payload = bytearray()

        payload.extend(Proto.build_fixed_int(1, self.protocolVersion))
        payload.extend(Proto.build_null_str(self.serverVersion))
        payload.extend(Proto.build_fixed_int(4, self.connectionId))
        payload.extend(Proto.build_fixed_str(8, self.challenge1))
        payload.extend(Proto.build_filler(1))
        payload.extend(Proto.build_fixed_int(2, self.capabilityFlags >> 16))
        payload.extend(Proto.build_fixed_int(1, self.characterSet))
        payload.extend(Proto.build_fixed_int(2, self.statusFlags))
        payload.extend(Proto.build_fixed_int(2, self.capabilityFlags & 0xffff))

        if self.hasCapabilityFlag(Flags.CLIENT_PLUGIN_AUTH):
            payload.extend(Proto.build_fixed_int(1, self.authPluginDataLength))
        else:
            payload.extend(Proto.build_filler(1))

        payload.extend(Proto.build_filler(10))

        if self.hasCapabilityFlag(Flags.CLIENT_SECURE_CONNECTION):
            payload.extend(Proto.build_fixed_str(
                max(13, self.authPluginDataLength - 8),
                           self.challenge2))
        if self.hasCapabilityFlag(Flags.CLIENT_PLUGIN_AUTH):
            payload.extend(Proto.build_null_str(self.authPluginName))

        return payload
Example #5
0
    def getPayload(self):
        payload = bytearray()

        payload.extend(Proto.build_byte(Flags.ERR))
        payload.extend(Proto.build_fixed_int(2, self.errorCode))
        payload.extend(Proto.build_byte(ord('#')))
        payload.extend(Proto.build_fixed_str(5, self.sqlState))
        payload.extend(Proto.build_eop_str(self.errorMessage))

        return payload
Example #6
0
    def getPayload(self):

        # 1 0xef kPacketMagicNum
        # 8 log_pos
        # n binlog_filename

        payload = bytearray()
        payload.extend(Proto.build_byte(0xef))
        payload.extend(Proto.build_fixed_int(8, self.binlog_pos))
        payload.extend(Proto.build_eop_str(self.binlog_filename))

        return payload
Example #7
0
    def getPayload(self):
        payload = bytearray()

        payload.extend(b'\x00')  # OK
        payload.extend(Proto.build_fixed_int(4, self.timestamp))
        payload.extend(Proto.build_fixed_int(1, self.event_type))
        payload.extend(Proto.build_fixed_int(4, self.server_id))
        payload.extend(Proto.build_fixed_int(4, len(self.getEventBody())))
        payload.extend(Proto.build_fixed_int(4, self.log_pos))
        payload.extend(Proto.build_fixed_int(2, self.flags))
        payload.extend(self.getEventBody())

        return payload