Files
MaxScale/query_classifier/test/canonical_tests/canonizer.c
Markus Makela a4caac55c8 Fixes to Coverity errors:
72662
72702
72724
73397
73410
73414
73422
75424
75748
75789
75938
75939

Also includes a fix to a bug caused by a previous Coverity error change in canonizer.c
2014-11-07 11:52:40 +02:00

82 lines
1.6 KiB
C

#include <my_config.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <query_classifier.h>
#include <buffer.h>
#include <mysql.h>
static char* server_options[] = {
"MariaDB Corporation MaxScale",
"--datadir=./",
"--language=./",
"--skip-innodb",
"--default-storage-engine=myisam",
NULL
};
const int num_elements = (sizeof(server_options) / sizeof(char *)) - 1;
static char* server_groups[] = {
"embedded",
"server",
"server",
NULL
};
int main(int argc, char** argv)
{
unsigned int psize;
GWBUF* qbuff;
char *tok;
char readbuff[4092];
FILE* infile;
FILE* outfile;
if(argc != 3){
printf("Usage: canonizer <input file> <output file>\n");
return 1;
}
if(mysql_library_init(num_elements, server_options, server_groups)){
printf("Embedded server init failed.\n");
return 1;
}
infile = fopen(argv[1],"rb");
outfile = fopen(argv[2],"wb");
if(infile == NULL || outfile == NULL){
printf("Opening files failed.\n");
return 1;
}
while(!feof(infile))
{
fgets(readbuff,4092,infile);
psize = strlen(readbuff);
if(psize < 0 || psize > 4092){
continue;
}
qbuff = gwbuf_alloc(psize + 7);
*(qbuff->sbuf->data + 0) = (unsigned char)psize;
*(qbuff->sbuf->data + 1) = (unsigned char)(psize>>8);
*(qbuff->sbuf->data + 2) = (unsigned char)(psize>>16);
*(qbuff->sbuf->data + 4) = 0x03;
memcpy(qbuff->start + 5,readbuff,psize + 1);
parse_query(qbuff);
tok = skygw_get_canonical(qbuff);
fprintf(outfile,"%s\n",tok);
free(tok);
gwbuf_free(qbuff);
}
fclose(infile);
fclose(outfile);
mysql_library_end();
return 0;
}