~jan-kneschke/mysql-proxy/packet-tracking-assertions

« back to all changes in this revision

Viewing changes to src/network-mysqld-packet.c

  • Committer: jan at mysql
  • Date: 2010-09-17 14:24:37 UTC
  • Revision ID: jan@mysql.com-20100917142437-jo520btg67whvatk
replaced g_error() and g_assert() by proper error-handling and a debug-message

Show diffs side-by-side

added added

removed removed

Lines of Context:
281
281
        return (udata->state == PARSE_COM_QUERY_LOCAL_INFILE_DATA) ? TRUE : FALSE;
282
282
}
283
283
 
 
284
/**
 
285
 * init the tracking structure for COM_STMT_PREPARE OK packets 
 
286
 */
284
287
network_mysqld_com_stmt_prepare_result_t *network_mysqld_com_stmt_prepare_result_new() {
285
288
        network_mysqld_com_stmt_prepare_result_t *udata;
286
289
 
290
293
        return udata;
291
294
}
292
295
 
 
296
/**
 
297
 * free the tracking structure for COM_STMT_PREPARE OK packets 
 
298
 */
293
299
void network_mysqld_com_stmt_prepare_result_free(network_mysqld_com_stmt_prepare_result_t *udata) {
294
300
        if (!udata) return;
295
301
 
296
302
        g_free(udata);
297
303
}
298
304
 
 
305
/**
 
306
 * track if we have received all the packets of the COM_STMT_PREPARE OK packet 
 
307
 *
 
308
 * @return -1 on error, 1 if all packets received, 0 if not
 
309
 */
299
310
int network_mysqld_proto_get_com_stmt_prepare_result(
300
311
                network_packet *packet, 
301
312
                network_mysqld_com_stmt_prepare_result_t *udata) {
305
316
 
306
317
        err = err || network_mysqld_proto_get_int8(packet, &status);
307
318
 
308
 
        if (udata->first_packet == 1) {
 
319
        if (udata->first_packet) {
309
320
                udata->first_packet = 0;
310
321
 
311
322
                switch (status) {
312
323
                case MYSQLD_PACKET_OK:
313
 
                        g_assert(packet->data->len == 12 + NET_HEADER_SIZE); 
 
324
                        if (packet->data->len == 12 + NET_HEADER_SIZE) {
 
325
                                err = -1;
 
326
                                break;
 
327
                        }       
314
328
 
315
329
                        /* the header contains the number of EOFs we expect to see
316
330
                         * - no params -> 0
335
349
                        is_finished = 1;
336
350
                        break;
337
351
                default:
338
 
                        g_error("%s.%d: COM_STMT_PREPARE should either get a (OK|ERR), got %02x",
 
352
                        err = -1;
 
353
 
 
354
                        g_debug("%s.%d: COM_STMT_PREPARE should either get a (OK|ERR), got %02x",
339
355
                                        __FILE__, __LINE__,
340
356
                                        status);
341
357
                        break;
345
361
                case MYSQLD_PACKET_OK:
346
362
                case MYSQLD_PACKET_NULL:
347
363
                case MYSQLD_PACKET_ERR:
348
 
                        g_error("%s.%d: COM_STMT_PREPARE should not be (OK|ERR|NULL), got: %02x",
 
364
                        g_debug("%s.%d: COM_STMT_PREPARE should not be (OK|ERR|NULL), got: %02x",
349
365
                                        __FILE__, __LINE__,
350
366
                                        status);
 
367
                        err = -1;
351
368
                        break;
352
369
                case MYSQLD_PACKET_EOF:
353
370
                        if (--udata->want_eofs == 0) {
529
546
                        is_finished = 1;
530
547
                        break;
531
548
                default:
532
 
                        g_error("%s.%d: COM_(0x%02x) should be (ERR|OK), got %02x",
 
549
                        g_debug("%s.%d: COM_(0x%02x) should be (ERR|OK), got %02x",
533
550
                                        __FILE__, __LINE__,
534
551
                                        con->parse.command, status);
 
552
                        err = -1;
535
553
                        break;
536
554
                }
537
555
                break;
554
572
                        is_finished = 1;
555
573
                        break;
556
574
                default:
557
 
                        g_error("%s.%d: COM_(0x%02x) should be (ERR|OK), got 0x%02x",
 
575
                        g_debug("%s.%d: COM_(0x%02x) should be (ERR|OK), got 0x%02x",
558
576
                                        __FILE__, __LINE__,
559
577
                                        con->parse.command, (guint8)status);
 
578
                        err = -1;
560
579
                        break;
561
580
                }
562
581
                break;
572
591
                        is_finished = 1;
573
592
                        break;
574
593
                default:
575
 
                        g_error("%s.%d: COM_(0x%02x) should be EOF, got x%02x",
 
594
                        g_debug("%s.%d: COM_(0x%02x) should be EOF, got x%02x",
576
595
                                        __FILE__, __LINE__,
577
596
                                        con->parse.command, (guint8)status);
 
597
                        err = -1;
578
598
                        break;
579
599
                }
580
600
                break;
591
611
                        break;
592
612
                case MYSQLD_PACKET_NULL:
593
613
                case MYSQLD_PACKET_OK:
594
 
                        g_error("%s.%d: COM_(0x%02x) should not be (OK|ERR|NULL), got: %02x",
 
614
                        g_debug("%s.%d: COM_(0x%02x) should not be (OK|ERR|NULL), got: %02x",
595
615
                                        __FILE__, __LINE__,
596
616
                                        con->parse.command, status);
597
617
 
 
618
                        err = -1;
598
619
                        break;
599
620
                default:
600
621
                        break;