49
50
uint8_t len= 0, fn_len= 0;
51
drizzle_result_st *result;
53
// Hack in 5.6 to say that client support checksums
54
result= drizzle_query_str(con, "SET @master_binlog_checksum='NONE'", ret_ptr);
55
drizzle_result_free(result);
56
if (*ret_ptr != DRIZZLE_RETURN_OK)
297
307
con->buffer_size-= 27;
298
308
con->packet_size-= 27;
299
309
binlog_event->data= (uint8_t*)realloc(binlog_event->data, binlog_event->length);
300
memcpy(binlog_event->data, con->buffer_ptr, binlog_event->length);
310
/* 5.6.1 or higher is automatic checksums on */
311
if (binlog_event->type == DRIZZLE_EVENT_TYPE_FORMAT_DESCRIPTION)
313
if (strncmp((const char*)con->buffer_ptr + 2, DRIZZLE_BINLOG_CHECKSUM_VERSION, strlen(DRIZZLE_BINLOG_CHECKSUM_VERSION)) <= 0)
315
con->result->binlog_checksums= true;
318
/* A checksum is basically a CRC32 at the end of the event data (4 bytes) */
319
if (con->result->binlog_checksums)
321
memcpy(binlog_event->data, con->buffer_ptr, binlog_event->length - DRIZZLE_BINLOG_CRC32_LEN);
325
memcpy(binlog_event->data, con->buffer_ptr, binlog_event->length);
301
327
con->buffer_ptr+= binlog_event->length;
302
328
con->buffer_size-= binlog_event->length;
303
329
con->packet_size-= binlog_event->length;
330
/* Remove the CRC32 from the event length */
331
if (con->result->binlog_checksums)
333
binlog_event->length-= DRIZZLE_BINLOG_CRC32_LEN;
337
/* Check if checksum is correct
338
* each event is checksummed individually, the checksum is the last 4 bytes
339
* of the binary log event
341
if (con->result->binlog_checksums)
344
memcpy(&binlog_event->checksum, binlog_event->raw_data + (binlog_event->raw_length - DRIZZLE_BINLOG_CRC32_LEN), DRIZZLE_BINLOG_CRC32_LEN);
345
event_crc= crc32(0, binlog_event->raw_data, (binlog_event->raw_length - DRIZZLE_BINLOG_CRC32_LEN));
346
if (event_crc != binlog_event->checksum)
348
drizzle_set_error(con, __func__, "CRC doesn't match: 0x%lX, 0x%lX", event_crc, binlog_event->checksum);
349
return DRIZZLE_RETURN_BINLOG_CRC;
305
353
if (con->packet_size != 0)
307
355
drizzle_set_error(con, "drizzle_state_binlog_read",