43
drizzle_result_st *drizzle_start_binlog(drizzle_st *con,
46
uint32_t start_position,
47
bool verify_checksums,
48
drizzle_return_t *ret_ptr)
43
drizzle_binlog_st *drizzle_binlog_init(drizzle_st *con,
44
drizzle_binlog_fn *binlog_fn,
45
drizzle_binlog_error_fn *error_fn,
47
bool verify_checksums)
54
drizzle_binlog_st *binlog= new (std::nothrow) drizzle_binlog_st;
57
drizzle_set_error(con, __func__, "error allocating binlog struct");
61
binlog->binlog_fn= binlog_fn;
62
binlog->error_fn= error_fn;
63
binlog->binlog_context= context;
64
binlog->verify_checksums= verify_checksums;
69
void drizzle_binlog_free(drizzle_binlog_st *binlog)
74
drizzle_return_t drizzle_binlog_start(drizzle_binlog_st *binlog,
77
uint32_t start_position)
50
79
unsigned char data[128];
51
80
unsigned char *ptr;
52
81
uint8_t len= 0, fn_len= 0;
53
82
drizzle_result_st *result;
88
return DRIZZLE_RETURN_INVALID_ARGUMENT;
55
93
// Hack in 5.6 to say that client support checksums
56
result= drizzle_query(con, "SET @master_binlog_checksum='NONE'", 0, ret_ptr);
94
result= drizzle_query(con, "SET @master_binlog_checksum='NONE'", 0, &ret);
57
95
drizzle_result_free(result);
58
if (*ret_ptr != DRIZZLE_RETURN_OK)
96
if (ret != DRIZZLE_RETURN_OK)
98
136
result= drizzle_command_write(con, NULL, DRIZZLE_COMMAND_BINLOG_DUMP,
99
data, len, len, ret_ptr);
100
result->binlog_event= new (std::nothrow) drizzle_binlog_st;
101
result->binlog_event->verify_checksums= verify_checksums;
137
data, len, len, &ret);
105
drizzle_return_t drizzle_binlog_get_next_event(drizzle_result_st *result)
140
if (ret != DRIZZLE_RETURN_OK)
109
return DRIZZLE_RETURN_INVALID_ARGUMENT;
112
144
result->push_state(drizzle_state_binlog_read);
113
145
result->push_state(drizzle_state_packet_read);
115
return drizzle_state_loop(result->con);
146
return drizzle_state_loop(con);
118
uint32_t drizzle_binlog_event_timestamp(drizzle_result_st *result)
149
uint32_t drizzle_binlog_event_timestamp(drizzle_binlog_event_st *event)
120
if ((result == NULL) || (result->binlog_event == NULL))
125
return result->binlog_event->timestamp;
156
return event->timestamp;
128
drizzle_binlog_event_types_t drizzle_binlog_event_type(drizzle_result_st *result)
159
drizzle_binlog_event_types_t drizzle_binlog_event_type(drizzle_binlog_event_st *event)
130
if ((result == NULL) || (result->binlog_event == NULL))
132
163
return drizzle_binlog_event_types_t();
135
return result->binlog_event->type;
138
uint32_t drizzle_binlog_event_server_id(drizzle_result_st *result)
140
if ((result == NULL) || (result->binlog_event == NULL))
145
return result->binlog_event->server_id;
148
uint32_t drizzle_binlog_event_length(drizzle_result_st *result)
150
if ((result == NULL) || (result->binlog_event == NULL))
155
return result->binlog_event->length;
158
uint32_t drizzle_binlog_event_next_pos(drizzle_result_st *result)
160
if ((result == NULL) || (result->binlog_event == NULL))
165
return result->binlog_event->next_pos;
168
uint16_t drizzle_binlog_event_flags(drizzle_result_st *result)
170
if ((result == NULL) || (result->binlog_event == NULL))
175
return result->binlog_event->flags;
178
uint16_t drizzle_binlog_event_extra_flags(drizzle_result_st *result)
180
if ((result == NULL) || (result->binlog_event == NULL))
185
return result->binlog_event->extra_flags;
188
const unsigned char *drizzle_binlog_event_data(drizzle_result_st *result)
190
if ((result == NULL) || (result->binlog_event == NULL))
195
return result->binlog_event->data;
198
const unsigned char *drizzle_binlog_event_raw_data(drizzle_result_st *result)
200
if ((result == NULL) || (result->binlog_event == NULL))
205
return result->binlog_event->raw_data;
208
uint32_t drizzle_binlog_event_raw_length(drizzle_result_st *result)
210
if ((result == NULL) || (result->binlog_event == NULL))
215
return result->binlog_event->raw_length;
169
uint32_t drizzle_binlog_event_server_id(drizzle_binlog_event_st *event)
176
return event->server_id;
179
uint32_t drizzle_binlog_event_length(drizzle_binlog_event_st *event)
186
return event->length;
189
uint32_t drizzle_binlog_event_next_pos(drizzle_binlog_event_st *event)
196
return event->next_pos;
199
uint16_t drizzle_binlog_event_flags(drizzle_binlog_event_st *event)
209
uint16_t drizzle_binlog_event_extra_flags(drizzle_binlog_event_st *event)
216
return event->extra_flags;
219
const unsigned char *drizzle_binlog_event_data(drizzle_binlog_event_st *event)
229
const unsigned char *drizzle_binlog_event_raw_data(drizzle_binlog_event_st *event)
236
return event->raw_data;
239
uint32_t drizzle_binlog_event_raw_length(drizzle_binlog_event_st *event)
246
return event->raw_length;
218
249
drizzle_return_t drizzle_state_binlog_read(drizzle_st *con)
220
drizzle_binlog_st *binlog_event;
251
drizzle_binlog_event_st *binlog_event;
224
255
return DRIZZLE_RETURN_INVALID_ARGUMENT;
227
binlog_event= con->result->binlog_event;
258
binlog_event= &con->binlog->event;
229
260
if (con->packet_size != 0 && con->buffer_size < con->packet_size)
330
364
* each event is checksummed individually, the checksum is the last 4 bytes
331
365
* of the binary log event
333
if (con->result->binlog_checksums)
367
if (con->binlog->has_checksums)
335
369
uint32_t event_crc;
336
370
memcpy(&binlog_event->checksum, binlog_event->raw_data + (binlog_event->raw_length - DRIZZLE_BINLOG_CRC32_LEN), DRIZZLE_BINLOG_CRC32_LEN);
337
if (binlog_event->verify_checksums)
371
if (con->binlog->verify_checksums)
339
373
event_crc= crc32(0, binlog_event->raw_data, (binlog_event->raw_length - DRIZZLE_BINLOG_CRC32_LEN));
340
374
if (event_crc != binlog_event->checksum)
342
376
drizzle_set_error(con, __func__, "CRC doesn't match: 0x%lX, 0x%lX", event_crc, binlog_event->checksum);
377
con->binlog->error_fn(DRIZZLE_RETURN_BINLOG_CRC, con->binlog->binlog_context);
343
378
return DRIZZLE_RETURN_BINLOG_CRC;
350
385
drizzle_set_error(con, "drizzle_state_binlog_read",
351
386
"unexpected data after packet:%zu", con->buffer_size);
387
con->binlog->error_fn(DRIZZLE_RETURN_UNEXPECTED_DATA, con->binlog->binlog_context);
352
388
return DRIZZLE_RETURN_UNEXPECTED_DATA;
354
390
con->pop_state();
393
con->binlog->binlog_fn(&con->binlog->event, con->binlog->binlog_context);
394
con->push_state(drizzle_state_binlog_read);
395
con->push_state(drizzle_state_packet_read);
356
397
return DRIZZLE_RETURN_OK;