Revert to 54d389e329a860add1f609508c676761521a8ad0 due to erroneous fix.

This commit is contained in:
VilhoRaatikka
2014-11-03 08:57:02 +02:00
parent fb02e44e7e
commit b15ac9c019

View File

@ -1,4 +1,3 @@
#include <my_config.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
@ -8,7 +7,7 @@
#include <mysql.h> #include <mysql.h>
static char* server_options[] = { static char* server_options[] = {
"MariaDB Corporation MaxScale", "SkySQL Gateway",
"--datadir=./", "--datadir=./",
"--language=./", "--language=./",
"--skip-innodb", "--skip-innodb",
@ -25,108 +24,98 @@ static char* server_groups[] = {
NULL NULL
}; };
/**
* @return 0 if succeed, 1 if failed
*/
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
int fdin;
int fdout; int fdin,fdout,i=0,fnamelen,fsz,lines = 0;
int fsz; unsigned int psize;
int i; GWBUF** qbuff;
int bsz = 4; char *qin, *outnm, *buffer, *tok;
int z=0;
unsigned int psize; if(argc != 3){
GWBUF** qbuff; printf("Usage: canonizer <input file> <output file>\n");
char *qin; return 1;
char *buffer; }
char *tok;
bool failed;
if (argc != 3) bool failed = mysql_library_init(num_elements, server_options, server_groups);
{
printf("Usage: canonizer <input file> <output file>\n"); if(failed){
return 1; printf("Embedded server init failed.\n");
} return 1;
failed = mysql_library_init(num_elements, server_options, server_groups); }
if (failed) fnamelen = strlen(argv[1]) + 16;
{ fdin = open(argv[1],O_RDONLY);
printf("Embedded server init failed.\n"); fsz = lseek(fdin,0,SEEK_END);
return 1; lseek(fdin,0,SEEK_SET);
}
fdin = open(argv[1],O_RDONLY); if(!(buffer = malloc(sizeof(char)*fsz + 1))){
fsz = lseek(fdin,0,SEEK_END); printf("Error: Failed to allocate memory.");
lseek(fdin,0,SEEK_SET); return 1;
}
if (!(buffer = (char *)calloc(1, fsz+1)))
{ read(fdin,buffer,fsz);
mysql_library_end(); buffer[fsz] = '\0';
printf("Error: Failed to allocate memory.");
return 1;
}
read(fdin,buffer,fsz); i = 0;
int bsz = 4,z=0;
qbuff = (GWBUF **)calloc(bsz, sizeof(GWBUF*)); qbuff = calloc(bsz,sizeof(GWBUF*));
tok = strtok(buffer,"\n"); tok = strtok(buffer,"\n");
i = 0;
while(tok){
while(tok)
{ if(i>=bsz){
GWBUF** tmp = calloc(bsz*2,sizeof(GWBUF*));
if (i>=bsz) if(!tmp){
{ printf("Error: Failed to allocate memory.");
GWBUF** tmp = (GWBUF **)calloc(bsz*2, sizeof(GWBUF*)); return 1;
}
if (!tmp)
{ for(z=0;z<bsz;z++){
printf("Error: Failed to allocate memory."); tmp[z] = qbuff[z];
return 1; }
}
free(qbuff);
for (z=0; z<bsz; z++) qbuff = tmp;
{ bsz *= 2;
tmp[z] = qbuff[z]; }
}
free(qbuff); if(strlen(tok) > 0){
qbuff = tmp; qin = strdup(tok);
bsz *= 2; psize = strlen(qin);
} qbuff[i] = gwbuf_alloc(psize + 6);
*(qbuff[i]->sbuf->data + 0) = (unsigned char)psize;
if (strlen(tok) > 0) *(qbuff[i]->sbuf->data + 1) = (unsigned char)(psize>>8);
{ *(qbuff[i]->sbuf->data + 2) = (unsigned char)(psize>>16);
qin = strdup(tok); *(qbuff[i]->sbuf->data + 4) = 0x03;
psize = strlen(qin); memcpy(qbuff[i]->sbuf->data + 5,qin,psize);
qbuff[i] = gwbuf_alloc(psize + 6); *(qbuff[i]->sbuf->data + 5 + psize) = 0x00;
*(qbuff[i]->sbuf->data + 0) = (unsigned char)psize; tok = strtok(NULL,"\n\0");
*(qbuff[i]->sbuf->data + 1) = (unsigned char)(psize>>8); free(qin);
*(qbuff[i]->sbuf->data + 2) = (unsigned char)(psize>>16); i++;
*(qbuff[i]->sbuf->data + 4) = 0x03; }
memcpy(qbuff[i]->sbuf->data + 5,qin,psize); }
*(qbuff[i]->sbuf->data + 5 + psize) = 0x00;
tok = strtok(NULL,"\n\0"); fdout = open(argv[2],O_TRUNC|O_CREAT|O_WRONLY,S_IRWXU|S_IXGRP|S_IXOTH);
free(qin);
i++; for(i = 0;i<bsz;i++){
} if(qbuff[i]){
} parse_query(qbuff[i]);
fdout = open(argv[2],O_TRUNC|O_CREAT|O_WRONLY,S_IRWXU|S_IXGRP|S_IXOTH); tok = skygw_get_canonical(qbuff[i]);
write(fdout,tok,strlen(tok));
for (i = 0;i<bsz;i++) write(fdout,"\n",1);
{ gwbuf_free(qbuff[i]);
if (qbuff[i]) }
{
parse_query(qbuff[i]); }
tok = skygw_get_canonical(qbuff[i]); free(qbuff);
write(fdout,tok,strlen(tok)); free(buffer);
write(fdout,"\n",1); close(fdin);
gwbuf_free(qbuff[i]); close(fdout);
}
} return 0;
free(qbuff); }
free(buffer);
close(fdin);
close(fdout);
mysql_library_end();
return 0;
}